(()=>{"use strict";const e=window.wp.components,t=window.wp.data,n=window.wp.element,r=window.wp.editor,l=window.wp.editPost,o=window.wp.i18n,a=window.wp.plugins;var i,u,c,s,d=["children"];function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,l,o,a,i=[],u=!0,c=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=o.call(n)).done)&&(i.push(r.value),i.length!==t);u=!0);}catch(e){c=!0,l=e}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw l}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var m=null!==(i=null===(u=window)||void 0===u||null===(u=u.pltOptions)||void 0===u?void 0:u.panelTitle)&&void 0!==i?i:"Page Links To",w=r.PluginDocumentSettingPanel||function(t){var n=t.children,r=void 0===n?null:n,o=function(e,t){if(null==e)return{};var n,r,l=function(e,t){if(null==e)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(-1!==t.indexOf(r))continue;n[r]=e[r]}return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],-1===t.indexOf(n)&&{}.propertyIsEnumerable.call(e,n)&&(l[n]=e[n])}return l}(t,d);return React.createElement(l.PluginPostStatusInfo,o,React.createElement("div",{style:{display:"flex","flex-direction":"column"}},React.createElement(e.PanelRow,null,React.createElement("h2",{style:{"margin-bottom":0,color:"#191e23"}},m)),r))},g=(0,e.createSlotFill)("PageLinksToSidebar").Slot,b=function(t){var r=t.enabled,l=t.onToggle,a=p((0,n.useState)(r?"custom":"wordpress"),2),i=a[0],u=a[1];return React.createElement(e.RadioControl,{label:(0,o.__)("Point this content to:","page-links-to"),selected:i,options:[{label:(0,o.__)("Its normal WordPress URL","page-links-to"),value:"wordpress"},{label:(0,o.__)("A custom URL","page-links-to"),value:"custom"}],onChange:function(e){u(e),l("custom"===e)}})},v=null!==(c=null===(s=window)||void 0===s||null===(s=s.pltOptions)||void 0===s?void 0:s.supportedPostTypes)&&void 0!==c?c:[];(0,a.registerPlugin)("page-links-to",{render:function(){var r=(0,t.useSelect)(function(e){var t=function(t){return(e("core/editor").getEditedPostAttribute("meta")||[])[t]};return{url:t("_links_to"),newTab:"_blank"===t("_links_to_target"),currentPostType:e("core/editor").getCurrentPostType()}},[]),l=r.url,a=r.newTab,i=r.currentPostType,u=(0,t.useDispatch)("core/editor").editPost;if(i&&!v.includes(i))return null;var c=function(e){u({meta:{_links_to:e}})},s=function(e){u({meta:{_links_to_target:e?"_blank":""}})},d=l||"",f=d.length>0,y=p((0,n.useState)(f),2),h=y[0],P=y[1],R=(0,n.useRef)(""),_=(0,n.useRef)(!1),k=d||R.current;return React.createElement(w,{title:m,name:"PageLinksTo",icon:h?"admin-links":"disabled",className:"plt-panel"},React.createElement(e.PanelRow,null,React.createElement(b,{enabled:h,onToggle:function(e){!e&&h&&(R.current=d,_.current=a),P(e),e?(c(R.current),s(_.current)):(c(null),s(!1))}})),h&&React.createElement(React.Fragment,null,React.createElement(e.PanelRow,null,React.createElement(e.TextControl,{label:(0,o.__)("Links to","page-links-to"),"data-testid":"plt-url",value:k,onChange:c,placeholder:"https://"})),window.pltOptions.supports.newTab&&React.createElement(e.PanelRow,null,React.createElement(e.CheckboxControl,{label:(0,o.__)("Open in new tab","page-links-to"),"data-testid":"plt-newtab",checked:a,onChange:s})),React.createElement(g,null)))}})})();