(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,o=window.wp.data,n=window.wp.plugins,a=window.wp.element,l=window.wp.blocks,i=window.wp.components,c=window.wp.blockEditor,s=window.wp.notices,r=window.wp.coreData,b=window.lodash,d={edit:(0,t.__)("Edit","content-blocks-builder"),editItem:(0,t.__)("Edit %s","content-blocks-builder"),save:(0,t.__)("Save","content-blocks-builder"),cancel:(0,t.__)("Cancel","content-blocks-builder"),delete:(0,t.__)("Delete","content-blocks-builder"),closeModal:(0,t.__)("Close modal","content-blocks-builder"),name:(0,t.__)("Name","content-blocks-builder"),label:(0,t.__)("Label","content-blocks-builder"),block:(0,t.__)("block","content-blocks-builder"),variation:(0,t.__)("variation","content-blocks-builder"),defaultVariation:(0,t.__)("default variation","content-blocks-builder"),pattern:(0,t.__)("pattern","content-blocks-builder"),blocks:(0,t.__)("Blocks","content-blocks-builder"),variations:(0,t.__)("Variations","content-blocks-builder"),patterns:(0,t.__)("Patterns","content-blocks-builder")},u=window.ReactJSXRuntime;function k({modalTitle:e,title:t,titleHelp:o,setIsModalOpen:n,onSubmit:l=b.noop,onCancel:c=b.noop,className:s}){const[r,k]=(0,a.useState)(t),_=()=>{n(!1),k(""),c()};return(0,u.jsx)(i.Modal,{title:e,closeLabel:d.closeModal,onRequestClose:()=>_(),overlayClassName:"reusable-blocks-menu-items__convert-modal",className:s,children:(0,u.jsxs)("form",{onSubmit:e=>{e.preventDefault(),l(r),_()},children:[(0,u.jsx)(i.TextControl,{label:d.name,value:r,onChange:k,help:o,className:"title-input"}),(0,u.jsxs)(i.Flex,{className:"reusable-blocks-menu-items__convert-modal-actions",justify:"flex-end",children:[(0,u.jsx)(i.FlexItem,{children:(0,u.jsx)(i.Button,{variant:"secondary",onClick:()=>_(),children:d.cancel})}),(0,u.jsx)(i.FlexItem,{children:(0,u.jsx)(i.Button,{variant:"primary",type:"submit",disabled:!r,children:d.save})})]})]})})}const _=window.wp.apiFetch;var m=e.n(_);const p=window.wp.url;function v(e){let t=[];return e.forEach(({name:e,attributes:o,innerBlocks:n})=>{t.push([e,o,v(n)])}),t}window.wp.hooks;(0,n.registerPlugin)("boldblocks-create-block-variation",{render:()=>{var e;const{getSelectedBlock:n}=(0,o.useSelect)(e=>e(c.store),[]),{getBlockVariations:b}=(0,o.useSelect)(e=>e(l.store),[]),{createSuccessNotice:_,createErrorNotice:w}=(0,o.useDispatch)(s.store),[h,f]=(0,a.useState)(!1),N=h?n():{},{name:y}=null!=N?N:{},S=y&&null!==(e=b(y))&&void 0!==e?e:[],g=y?`${y} variation ${S.length+1}`:"",x=y?`${y}-variation-${((e=21)=>{let t="",o=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&o[e]];return t})(10)}`:"";if(C="update",j="settings",!(0,o.useSelect)(e=>e(r.store).canUser(C,j),[C,j]))return null;var C,j;const B=(0,t.__)("Create block variation","content-blocks-builder");return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(c.BlockSettingsMenuControls,{children:({selectedClientIds:e})=>1===e?.length?(0,u.jsx)(i.MenuItem,{label:B,icon:"plus-alt2",onClick:()=>f(!0),children:B}):null}),h&&(0,u.jsx)(k,{modalTitle:(0,t.sprintf)((0,t.__)("Create a new variation for the block: '%s'","content-blocks-builder"),y),title:g,setIsModalOpen:f,onSubmit:e=>{(({variationName:e,blockName:o,title:n,description:a="",iconString:i="",block:c,createSuccessNotice:s,createErrorNotice:r,isDefault:b=!1,doneCb:u,finallyCb:k})=>{const _=(0,l.serialize)([c]),w=(({blockName:e,variationName:t,title:o,block:n})=>{const{attributes:a={},innerBlocks:l=[]}=null!=n?n:{};return{blockName:e,variation:{name:t,title:o,attributes:a,innerBlocks:v(l)}}})({blockName:o,variationName:e,title:n,block:c});m()({path:"boldblocks/v1/createVariation",method:"POST",data:{title:n,content:_,status:"publish",meta:{boldblocks_variation_block_name:o,boldblocks_variation_name:e,boldblocks_variation_data:JSON.stringify(w),boldblocks_variation_icon:i,boldblocks_variation_description:a,boldblocks_variation_is_default:b,boldblocks_variation_is_transformable:!0},cbb_variation_nonce:CBBBlocks?.variationNonce}}).then(e=>{const{success:n,data:a,post:i}=e;var c;n?(s(a||(0,t.__)("Your variation has been created successfully!","content-blocks-builder"),{type:"snackbar",actions:[{label:(0,t.sprintf)(d.editItem,d.variation),url:(c=i.id,(0,p.addQueryArgs)(`post.php?post=${c}&action=edit`))}]}),(0,l.registerBlockVariation)(o,w.variation),u&&u(i)):r(a||"Request failed!",{type:"snackbar"})}).catch(({data:e})=>{r(e,{type:"snackbar"})}).finally(()=>{k&&k()})})({title:e,block:N,blockName:y,variationName:x,createSuccessNotice:_,createErrorNotice:w})},className:"cbb-block-modal"})]})}})})();