(()=>{"use strict";const e=window.React,t=window.lodash,n=window.wp.i18n,s=window.wp.hooks,o=window.wp.element,r=window.wp.components,l=window.wp.blockEditor,a=window.wp.compose,i=window.wp.data,p=window.wp.dom,c=function(s){var l,a;const[c,u]=(0,o.useState)(""),[d,m]=(0,o.useState)([]),{posts:w}=(0,i.useSelect)((e=>{const t={search:c,search_columns:["post_title"]},n=["postType",s.postType,t];if(!isNaN(parseInt(c))){const e=parseInt(c);t.include=[e],delete t.search,delete t.search_columns}return{posts:e("core").getEntityRecords(...n)}}),[c,s.postType]),y=e=>(0,t.unescape)((0,p.safeHTML)(e)),h=Array.isArray(w)?w:[],g=(h.map((e=>e?.id)),h.map((e=>e?.title?.rendered)).map(y),s.value.map((e=>e?.title)).map(y),(0,t.capitalize)(s.postType));return(0,e.createElement)("div",{className:"qlpsp-post-selector"},(0,e.createElement)(r.FormTokenField,{suggestions:null!==(l=h?.map((e=>({title:e?.title?.rendered,id:e?.id}))).map((e=>JSON.stringify(e))))&&void 0!==l?l:[],value:null!==(a=s?.value?.map((e=>JSON.stringify(e))))&&void 0!==a?a:[],__experimentalExpandOnFocus:!0,__experimentalShowHowTo:!1,displayTransform:e=>{try{const t=JSON.parse(e);return t?.title+` (ID: ${t?.id})`}catch(t){return e}},__experimentalRenderItem:({item:t})=>{const n=JSON.parse(t),s=y(n?.title),o=n?.id;return(0,e.createElement)("span",{style:{display:"flex",flexDirection:"row",justifyContent:"space-between"}},(0,e.createElement)("span",null,s),(0,e.createElement)("span",null,"ID: ",o))},onInputChange:u,label:g,placeholder:(0,n.sprintf)((0,n.__)("Select %s","query-loop-post-selector"),s.postType),onChange:e=>{const t=e.map((e=>{const t=JSON.parse(e);return s.value.find((e=>e?.id===t?.id))||t}));s.onChange(t)}}))},u=(0,a.createHigherOrderComponent)((s=>a=>{const i=(0,o.useRef)(!0),p=(0,t.get)(a,"attributes.query.postType","post"),u=(0,t.get)(a,"attributes.query",{}),d=(0,t.get)(u,"qlpspSelectivePosts",[]),m=(0,t.get)(u,"inherit",!1);return(0,o.useEffect)((()=>{i.current?i.current=!1:a.setAttributes({query:{...u,qlpspSelectivePosts:[]}})}),[p,m]),"core/query"!==a.name?(0,e.createElement)(s,{...a}):(0,e.createElement)(e.Fragment,null,(0,e.createElement)(s,{...a}),!m&&(0,e.createElement)(l.InspectorControls,null,(0,e.createElement)(r.PanelBody,{title:(0,n.__)("Selective Posts","query-loop-post-selector")},(0,e.createElement)(c,{postType:p,value:d,onChange:e=>a.setAttributes({query:{...u,qlpspSelectivePosts:e}})}))))}),"withSelectivePostControl");(0,s.addFilter)("editor.BlockEdit","small-plugins/with-query-loop-selective-post-control",u)})();