(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var a in s)e.o(s,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:s[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,s=window.wp.i18n,a=window.wp.blockEditor,r=window.wp.components,o=window.wp.element,l=window.wp.apiFetch;var n=e.n(l);const c=window.ReactJSXRuntime,i=JSON.parse('{"UU":"psacp/psacp-layout-selector"}');(0,t.registerBlockType)(i.UU,{edit:function({attributes:e,setAttributes:t,isSelected:l}){const{layout_id:i}=e,[u,d]=(0,o.useState)([]),[p,h]=(0,o.useState)(!1),[y,w]=(0,o.useState)(null),_=(0,o.useRef)(null),m=(0,o.useRef)(!1),b=window.PsacpLayoutBlock?.layout_page_url,f=async e=>{h(!0);try{const t=(await n()({path:`/psacp-layout-selector/v1/search-layouts?search=${encodeURIComponent(e)}`})).map(e=>({value:e.id,label:`#${e.id} - ${e.title}`}));if(d(t),i>0){const e=t.find(e=>e.value===i);e&&w(e)}}catch(e){console.error("Error searching posts:",e),d([])}h(!1)};(0,o.useEffect)(()=>{l&&i>0&&!m.current&&(m.current=!0,f(i)),l||(m.current=!1)},[l,i]),(0,o.useEffect)(()=>{l&&i>0&&!m.current&&(m.current=!0,f(i)),l||(m.current=!1)},[l,i]);const x=()=>y&&!u.some(e=>e.value===y.value)?[y,...u]:u;return(0,o.useEffect)(()=>()=>{_.current&&clearTimeout(_.current)},[]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a.InspectorControls,{children:(0,c.jsxs)(r.PanelBody,{title:(0,s.__)("Layout Selection","post-slider-and-carousel"),initialOpen:!0,children:[(0,c.jsx)(r.ComboboxControl,{label:(0,s.__)("Layout","post-slider-and-carousel"),value:i,onChange:e=>{if(e){const t=x().find(t=>t.value===e);t&&w(t)}else w(null);t({layout_id:e||0})},onFilterValueChange:e=>{_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{e&&e.length>0?f(e):d([])},500)},options:x(),help:(0,c.jsxs)(c.Fragment,{children:[(0,s.__)("Select a post slider layout. You can search by layout ID or title. You can create or manage layout from","post-slider-and-carousel")," ",(0,c.jsx)("a",{href:b,target:"_blank",children:(0,s.__)("here","post-slider-and-carousel")}),"."]})}),p&&(0,c.jsx)(r.Spinner,{})]})}),(0,c.jsx)("div",{...(0,a.useBlockProps)(),children:(0,c.jsxs)("div",{className:"psacp-block-preview",children:[(0,c.jsx)("div",{className:"psacp-block-title",children:(0,s.__)("Post Slider and Carousel - Layout","post-slider-and-carousel")}),i>0?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)("p",{className:"psacp-block-shrt-prev",children:['[psacp_tmpl layout_id="',i,'"]']}),(0,c.jsxs)("p",{className:"psacp-block-help-text",children:[(0,s.__)("Post slider layout will be displayed on the frontend. You can create or manage layout from","post-slider-and-carousel")," ",(0,c.jsx)("a",{href:b,target:"_blank",children:(0,s.__)("here","post-slider-and-carousel")}),"."]})]}):(0,c.jsx)("p",{className:"psacp-block-help-text",children:(0,s.__)("Use the sidebar and select a post display layout.","post-slider-and-carousel")})]})})]})}})})();