(()=>{"use strict";const e=window.React,t=window.wp.i18n,a=window.wp.element,n=window.wp.plugins,l=window.wp.editPost,i=window.wp.data,o=window.wp.blocks,r=window.wp.components,s=window.wp.notices,c="gutenify",u=window?.[`_${c}_vars`]?window[`_${c}_vars`]:{},{is_pro_activated:p,pro_account_url:_,pro_license_status:d,title:m,prefix:w,slug:g,authorWebSite:S,authorDemoWebSite:b,authorWebSiteProPage:k,defaultTheme:y,authorWebSiteSupport:f,plugin_directory_url:v,brand_color:h,plugin_main_version:C,documentationsURL:E,pro_title:B,active_blocks:P,plugin_main_camel_case_name:T}=u,M=(u?.siteUrl?u.siteUrl:u.site_url,(0,t.sprintf)("Want to enjoy all feature of blocks? Checkout %1$s%2$s%3$s.",'<a href="'+k+'" target="_blank">',B,"</a>"),{pluginMainSlug:"gutenify",pluginMainCamelCaseName:T,pluginMainFunctionPrefix:"gutenify"}),{pluginMainSlug:$}=M;(0,n.registerPlugin)(`${$}-save-template-option`,{render:()=>{const n=(0,i.useSelect)((e=>e("core/block-editor").getSelectedBlock()),[]),[c,u]=(0,a.useState)(!1),[p,_]=(0,a.useState)(""),[d,m]=(0,a.useState)(!1),{saveEntityRecord:w}=(0,i.useDispatch)("core"),{createSuccessNotice:g,createErrorNotice:S}=(0,i.useDispatch)(s.store),b=(0,o.getBlockTypes)().map((e=>e.name));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(l.PluginBlockSettingsMenuItem,{allowedBlocks:b,icon:"open-folder",label:(0,t.__)("Save template"),onClick:()=>{u(!0)}}),c&&(0,e.createElement)(r.Modal,{title:(0,t.__)("Save Template"),onRequestClose:()=>u(!1)},(0,e.createElement)(r.Card,{isBorderless:!0},(0,e.createElement)(r.CardBody,null,(0,e.createElement)(r.TextControl,{value:p,onChange:e=>{_(e),m(!1)},label:(0,t.__)("Title"),className:d?"gutenify-field-error":""})),(0,e.createElement)(r.CardFooter,null,(0,e.createElement)(r.Button,{variant:"secondary",onClick:()=>{u(!1)}},(0,t.__)("Cancel")),(0,e.createElement)(r.Button,{variant:"primary",onClick:()=>{if(""===p)return S((0,t.__)("Please enter template title."),{type:"snackbar"}),m(!0),!1;m(!1);const e=(0,o.serialize)(n);w("postType","gutenify_template",{title:p,content:e,status:"publish"}).then((()=>{g((0,t.__)("Saved template."),{type:"snackbar"}),u(!1)})).catch((()=>{g((0,t.__)("There was error saving template."),{type:"snackbar"})}))}},(0,t.__)("Save"))))))}})})();