(()=>{"use strict";const e=window.wp.blocks,t=window.wp.primitives,n=window.ReactJSXRuntime;var s=(0,n.jsx)(t.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",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"})});const o=JSON.parse('{"UU":"remote-data-blocks/template"}'),i=window.wp.blockEditor,r=window.wp.components,a=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:s}=(o=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 o(t)}),[]));var o;if("wp_block"===s){const e=String(null!==(t=n._remote_data_blocks_block_type)&&void 0!==t?t:""),s=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(s)return{remoteData:{blockName:e,metadata:{},queryInputs:[],queryKey:"Example Query Key",resultId:"",results:[{result:Object.fromEntries(Object.entries(s.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,v=(0,m.memo)((function(e){const{blocks:t,isHidden:s=!1,onSelect:o}=e,r=(0,i.__experimentalUseBlockPreview)({blocks:t,props:{}}),a={cursor:"pointer",display:s?"none":void 0,listStyle:"none"};return(0,n.jsx)("li",Object.assign({},r,{onClick:o,onKeyDown:o,role:"button",style:a,tabIndex:0}))}));function p({isActive:e}){const t=(0,i.useInnerBlocksProps)();return e?(0,n.jsx)("li",Object.assign({},t)):null}function w(e){const{getInnerBlocks:t,remoteData:s}=e,[o,r]=(0,m.useState)(0),{setPreviewIndex:a}=(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:s.results.map(((e,i)=>{const l=i===o;return(0,n.jsxs)(m.Fragment,{children:[(0,n.jsx)(p,{isActive:l}),(0,n.jsx)(v,{blocks:t(e,i),isHidden:l,onSelect:()=>function(e){r(e),a(s.resultId,e)}(i)})]},i)}))})}function g(t,n,s,o){var i,r;const a=null===(i=t.innerBlocks)||void 0===i?void 0:i.map((e=>g(e,n,s,o))),l=Object.assign(Object.assign({},t.attributes),{metadata:Object.assign(Object.assign({},t.attributes.metadata),{bindings:Object.assign(Object.assign({},null===(r=t.attributes.metadata)||void 0===r?void 0:r.bindings),Object.fromEntries(j(t.attributes,s).map((([e,t])=>[e,Object.assign(Object.assign({},t),{args:Object.assign(Object.assign({},t.args),{isPreview:!0,previewIndex:o})})]))))})});return(0,e.cloneBlock)(t,l,a)}function j(e,t){var n,s;return Object.entries(null!==(s=null===(n=e.metadata)||void 0===n?void 0:n.bindings)&&void 0!==s?s:{}).filter((([e,n])=>{var s;return n.source===c&&(null===(s=n.args)||void 0===s?void 0:s.block)===t}))}function k(e,t,n){const{getBlocks:s}=(0,d.useSelect)(i.store,[e,[e,t]]);return(o,i)=>s(t).map((t=>g(t,o,null!=n?n:e,i)))}(0,e.registerBlockType)(o.UU,{edit:function(e){const{clientId:t,context:s,name:o}=e,l=(0,i.useBlockProps)(),c=(0,i.useInnerBlocksProps)(),{remoteData:d}=b(s),u=k(o,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({},l,{children:(0,n.jsx)("div",Object.assign({},c))})):(0,n.jsx)("div",Object.assign({},l,{children:(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)(r.Placeholder,{label:(0,a.__)("Remote Data Template"),instructions:(0,a.__)("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:s},save:function(){return(0,n.jsx)(i.InnerBlocks.Content,{})}})})();