(()=>{"use strict";const e=window.React,t=window.wp.blocks,n=window.wp.i18n,o=window.wp.hooks,a=["personalizewp-pro/variations-block","personalizewp-pro/variation-fallback","personalizewp-pro/variation"];(0,o.addFilter)("personalizewp.hasPersonalizeControls","personalizewp/indicate-variation-blocks",function(e,t){return"personalizewp-pro/variations-block"===t.name||e}),(0,o.addFilter)("personalizeWP.globallyRestrictedBlockTypes","personalizewp/restrict-variation-blocks",function(e){return[...e,...a]}),(0,o.addFilter)("blocks.registerBlockType","personalizewp/register-variations-context",function(e,t){return a.includes(t)||(e={...e,usesContext:[...e.usesContext,"personalizewp/isVariationContent"]}),e},100),(0,o.addFilter)("personalizeWP.preRenderControls","personalizewp/restrict-personalize-controls-showing",function(e,t){return!t.context["personalizewp/isVariationContent"]&&e});const r=window.wp.blockEditor,i=window.wp.components,l=window.wp.data,s=window.wp.element,c=[["personalizewp-pro/variation",{metadata:{name:(0,n.sprintf)(
// Translators: %d: Variation number being added.
// Translators: %d: Variation number being added.
(0,n.__)("Variation %d","personalizewp"),1)}},[["core/paragraph",{placeholder:(0,n.__)("Add variation content here","personalizewp")}]]],["personalizewp-pro/variation-fallback",{metadata:{name:(0,n.__)("Fallback","personalizewp")},supports:{lock:!1},lock:{move:!0,remove:!0},inserter:!1,multiple:!0,html:!1,renaming:!1},[["core/paragraph",{placeholder:(0,n.__)("Add fallback content here","personalizewp")}]]]],p=JSON.parse('{"UU":"personalizewp-pro/variations-block"}'),d={src:(0,e.createElement)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,e.createElement)("path",{fill:"#e1236c",d:"M22.98 9.12a3 3 0 0 0-.25-.98 3.4 3.4 0 0 0-1.26-1.55 4 4 0 0 0-.91-.43 4 4 0 0 0-1.34-.13 4 4 0 0 0-1.28.39 4 4 0 0 0-.57.37 3 3 0 0 0-.67.75 4 4 0 0 0-.43.92 3 3 0 0 0-.14.66 3 3 0 0 0 0 .63l-1.15-2.01A3.44 3.44 0 0 0 8.56 9.7L7.42 7.73a3.44 3.44 0 1 0-5.96 3.43l2.48 4.32a3.44 3.44 0 0 0 6.41-1.97l1.15 1.98a3.44 3.44 0 0 0 6.06-3.24l.09.06a3.5 3.5 0 0 0 2.58.52 4 4 0 0 0 .95-.34A3.5 3.5 0 0 0 23 9.45z"}))};(0,t.registerBlockType)(p.UU,{icon:d,edit:function(o){const{attributes:a,setAttributes:p,clientId:d,isSelected:w}=o,{variationsBlockId:u}=a,{innerVariationBlocks:k,selectedVariationClientId:m}=(0,l.useSelect)(e=>{const{getBlocks:t,getSelectedBlockClientId:n,hasSelectedInnerBlock:o}=e(r.store),a=t(d),i=n();let l=null;for(const e of a)if(e.clientId===i||o(e.clientId,!0)){l=e.clientId;break}return{innerVariationBlocks:a,selectedVariationClientId:l}},[d]),{__unstableMarkNextChangeAsNotPersistent:v,updateBlockAttributes:b,insertBlock:h,selectBlock:z}=(0,l.useDispatch)(r.store),g=(0,s.useCallback)(e=>{k.forEach(t=>{v(),b(t.clientId,{isActive:t.clientId===e})})},[k,b,v]);(0,s.useEffect)(()=>{u&&""!==u||p({variationsBlockId:d}),k?.length&&g(k[k.length-1].clientId)},[]),(0,s.useEffect)(()=>{const e=k&&k.some(e=>e.attributes.isActive);m?g(m):!e&&k?.length&&g(k[k.length-1].clientId)},[k,m,g]),(0,s.useEffect)(()=>{null!==u&&""!==u||p({variationsBlockId:d})},[d,w]);const B=(0,r.useBlockProps)(),f=(0,r.useInnerBlocksProps)(B,{template:c,renderAppender:!1});return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(r.BlockControls,{group:"block"},(0,e.createElement)(i.Toolbar,{label:(0,n.__)("Variations","personalizewp")},(0,e.createElement)(i.ToolbarGroup,null,k.map(({clientId:t,attributes:n})=>{const{metadata:o,isActive:a}=n;return(0,e.createElement)(i.ToolbarButton,{key:t,label:o.name,isActive:a,onClick:()=>g(t)},o.name)}),(0,e.createElement)(i.ToolbarButton,{icon:"plus",label:(0,n.__)("New Variation","personalizewp"),onClick:()=>(()=>{const e=k.length,o=(0,t.createBlock)("personalizewp-pro/variation",{metadata:{name:(0,n.sprintf)(
// Translators: %d: Variation number being added.
// Translators: %d: Variation number being added.
(0,n.__)("Variation %d","personalizewp"),e)}},[(0,t.createBlock)("core/paragraph",{placeholder:(0,n.__)("Add variation content here","personalizewp")})]);h(o,k.length-1,d),z(o.clientId)})()})))),(0,e.createElement)("div",{...f}))},save:function(t){const n=r.useBlockProps.save(),{className:o,...a}=r.useInnerBlocksProps.save(n);return(0,e.createElement)("pwp-content-variations",{...a})}})})();