(()=>{"use strict";const e=window.wp.blocks,t=window.wp.primitives,n=window.ReactJSXRuntime,o=(0,n.jsx)(t.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,n.jsx)(t.Path,{d:"M18 5.5H6a.5.5 0 00-.5.5v3h13V6a.5.5 0 00-.5-.5zm.5 5H10v8h8a.5.5 0 00.5-.5v-7.5zm-10 0h-3V18a.5.5 0 00.5.5h2.5v-8zM6 4h12a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V6a2 2 0 012-2z"})}),s=JSON.parse('{"UU":"remote-data-blocks/template"}'),i=window.wp.blockEditor,a=window.wp.components,r=window.wp.i18n;var l;null===(l=window.REMOTE_DATA_BLOCKS)||void 0===l||l.rest_url,function(...e){e.filter(Boolean).join(" ")}(undefined,`rdb-${"container".replace(/[^a-zA-Z\d\u00C0-\u00FF]/g,"-").toLowerCase()}`);const c="remote-data/binding",d=window.wp.data,u=window.wp.editor;function b(e){var t;const{postMeta:n,postType:o}=(s=e=>{var t,n;return{postMeta:null!==(t=e("meta"))&&void 0!==t?t:{},postType:null!==(n=e("type"))&&void 0!==n?n:""}},(0,d.useSelect)((e=>{const{getEditedPostAttribute:t}=e(u.store);return s(t)}),[]));var s;if("wp_block"===o){const e=String(null!==(t=n._remote_data_blocks_block_type)&&void 0!==t?t:""),o=function(e){var t,n;return null===(n=null===(t=window.REMOTE_DATA_BLOCKS)||void 0===t?void 0:t.config)||void 0===n?void 0:n[e]}(e);if(o)return{remoteData:{blockName:e,metadata:{},queryInputs:[],queryKey:"Example Query Key",resultId:"",results:[{result:Object.fromEntries(Object.entries(o.availableBindings).map((([e,t])=>[e,{name:t.name,type:t.type,value:t.name}]))),uuid:"Example Entity ID"}]}}}return{remoteData:e["remote-data-blocks/remoteData"]}}const m=window.wp.element,p=(0,m.memo)((function(e){const{blocks:t,isHidden:o=!1,onSelect:s}=e,a=(0,i.__experimentalUseBlockPreview)({blocks:t,props:{}}),r={cursor:"pointer",display:o?"none":void 0,listStyle:"none"};return(0,n.jsx)("li",Object.assign({},a,{onClick:s,onKeyDown:s,role:"button",style:r,tabIndex:0}))}));function v({isActive:e}){const t=(0,i.useInnerBlocksProps)();return e?(0,n.jsx)("li",Object.assign({},t)):null}function w(e){const{getInnerBlocks:t,remoteData:o}=e,[s,a]=(0,m.useState)(0),{setPreviewIndex:r}=(0,d.useDispatch)("remote-data-blocks/store",[]),{clientId:l}=(0,i.useBlockEditContext)();return(0,d.useSelect)((e=>e(i.store).getBlocksByClientId(l)),[l]),(0,n.jsx)("ul",{className:"remote-data-blocks-loop-template",children:o.results.map(((e,i)=>{const l=i===s;return(0,n.jsxs)(m.Fragment,{children:[(0,n.jsx)(v,{isActive:l}),(0,n.jsx)(p,{blocks:t(e,i),isHidden:l,onSelect:()=>function(e){a(e),r(o.resultId,e)}(i)})]},i)}))})}function g(t,n,o,s){var i,a;const r=null===(i=t.innerBlocks)||void 0===i?void 0:i.map((e=>g(e,n,o,s))),l=Object.assign(Object.assign({},t.attributes),{metadata:Object.assign(Object.assign({},t.attributes.metadata),{bindings:Object.assign(Object.assign({},null===(a=t.attributes.metadata)||void 0===a?void 0:a.bindings),Object.fromEntries(j(t.attributes,o).map((([e,t])=>[e,Object.assign(Object.assign({},t),{args:Object.assign(Object.assign({},t.args),{isPreview:!0,previewIndex:s})})]))))})});return(0,e.cloneBlock)(t,l,r)}function j(e,t){var n,o;return Object.entries(null!==(o=null===(n=e.metadata)||void 0===n?void 0:n.bindings)&&void 0!==o?o:{}).filter((([e,n])=>{var o;return n.source===c&&(null===(o=n.args)||void 0===o?void 0:o.block)===t}))}function k(e,t,n){const{getBlocks:o}=(0,d.useSelect)(i.store,[e,[e,t]]);return(s,i)=>o(t).map((t=>g(t,s,null!=n?n:e,i)))}(0,e.registerBlockType)(s.UU,{edit:function(e){const{clientId:t,context:o,name:s}=e,l=(0,i.useBlockProps)(),c=(0,i.useInnerBlocksProps)(),{remoteData:d}=b(o),u=k(s,t,null==d?void 0:d.blockName);return(null==d?void 0:d.blockName)?d.results.length?1===d.results.length?(0,n.jsx)("div",Object.assign({},c)):(0,n.jsx)(w,{getInnerBlocks:u,remoteData:d}):(0,n.jsx)("div",Object.assign({},l)):(0,n.jsx)("div",Object.assign({},l,{children:(0,n.jsx)(a.Placeholder,{label:(0,r.__)("Remote Data Template"),instructions:(0,r.__)("This block only works when placed inside a remote data block container and bound to an attribute. This block will be ignored as currently configured.")})}))},icon:{src:o},save:function(){return(0,n.jsx)(i.InnerBlocks.Content,{})}})})();