"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([[574],{24349:(e,t,a)=>{var i=a(3698),o=a.n(i),s=a(79124),n=a(7378),r=a(16221),l=a(66248),c=a(56973),d=a(74679),m=a(8301),u=a(75379),p=a(57257),h=a(62694),b=a(28636),g=a(2103),v=a(60697),_=a(99671),x=a(67268),j=a(82321),f=a(27029),y=a(81448),A=a(39833),w=(a(50270),a(86106)),S=a(14687),N=a(2161);function k(){const{isSidebarOpened:e,selectedStep:t,savedState:a}=(0,p.A)((e=>({isSidebarOpened:e(N.storeName).isSidebarOpened,selectedStep:e(N.storeName).getSelectedStep,savedState:e(N.storeName).getSavedState()}))),{openSidebar:i,closeSidebar:o,save:s,toggleFeature:r}=(0,S.A)(N.storeName),{registerShortcut:l}=(0,S.A)(_.M_);return(0,n.useEffect)((()=>{l({name:"mailpoet/automation-editor/toggle-fullscreen",category:"global",description:(0,x.__)("Toggle fullscreen mode.","mailpoet"),keyCombination:{modifier:"secondary",character:"f"}}),l({name:"mailpoet/automation-editor/toggle-sidebar",category:"global",description:(0,x.__)("Show or hide the settings sidebar.","mailpoet"),keyCombination:{modifier:"primaryShift",character:","}}),l({name:"mailpoet/automation-editor/save",category:"global",description:(0,x.__)("Save your changes.","mailpoet"),keyCombination:{modifier:"primary",character:"s"}})}),[l]),(0,_.wk)("mailpoet/automation-editor/toggle-fullscreen",(()=>{r("fullscreenMode")})),(0,_.wk)("mailpoet/automation-editor/toggle-sidebar",(a=>{if(a.preventDefault(),e())o();else{const e=t()?N.stepSidebarKey:N.automationSidebarKey;i(e)}})),(0,_.wk)("mailpoet/automation-editor/save",(e=>{e.preventDefault(),"unsaved"===a&&s()})),null}var D=a(30176),C=a(8092),I=a(96606),L=a(87520);const{lock:T,unlock:E}=(0,L.yf)("I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.","@wordpress/edit-post"),{Tabs:O}=E(I.j),K=n.forwardRef((function(e,t){return(0,w.jsxs)(O.TabList,{ref:t,children:[(0,w.jsx)(O.Tab,{tabId:N.automationSidebarKey,children:(0,x.__)("Automation","mailpoet")}),(0,w.jsx)(O.Tab,{tabId:N.stepSidebarKey,children:(0,x.__)("Step","mailpoet")})]})}));var F=a(78048),M=a(99252),J=a(33352),P=a(90406),V=a(70081);function W({title:e,description:t,icon:a}){return(0,w.jsxs)("div",{className:"block-editor-block-card",children:[(0,w.jsx)(V.W,{icon:a}),(0,w.jsxs)("div",{className:"block-editor-block-card__content",children:[(0,w.jsx)("h2",{className:"block-editor-block-card__title",children:e}),(0,w.jsx)("span",{className:"block-editor-block-card__description",children:t})]})]})}function B(){const{errors:e}=(0,p.A)((e=>({errors:e(N.storeName).getStepError(e(N.storeName).getSelectedStep().id)})),[]);if(!e||!e?.fields)return null;const t=e.fields?.general;return t?(0,w.jsx)(F.A,{isDismissible:!1,status:"error",children:t}):null}function R(){const{selectedStep:e,selectedStepType:t}=(0,p.A)((e=>({selectedStep:e(N.storeName).getSelectedStep(),selectedStepType:e(N.storeName).getSelectedStepType()})),[]);if(!e)return(0,w.jsx)(M.Ay,{children:"No step selected."});if(!t)return(0,w.jsx)(M.Ay,{children:"Unknown step type."});const a=t.edit;return(0,w.jsxs)("div",{className:"block-editor-block-inspector",children:[(0,w.jsx)(B,{}),(0,w.jsx)(W,{title:t.title(e,"sidebar"),description:t.description(e,"sidebar"),icon:t.icon}),(0,w.jsx)(a,{},e.id),"trigger"===e.type&&(0,w.jsx)(P.qn,{strings:J.t})]})}var G=a(64214),U=a(41221),q=a(33191),H=a(51047);function z(){const e=H.Hooks.applyFilters("mailpoet.automation.settings.render",{});return 0===Object.keys(e).length?null:(0,w.jsx)(M.Ay,{title:(0,x.__)("Automation settings","mailpoet"),initialOpen:!0,children:Object.keys(e).map((t=>(0,w.jsx)(G.A,{children:e[t]},t)))})}function Q(){const{automationData:e}=(0,p.A)((e=>({automationData:e(N.storeName).getAutomationData()})),[]),t={year:"numeric",month:"long",day:"numeric"};return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(M.Ay,{title:(0,x.__)("Automation details","mailpoet"),initialOpen:!0,children:[(0,w.jsxs)(G.A,{children:[(0,w.jsx)("strong",{children:"Date added"})," ",new Date(Date.parse(e.created_at)).toLocaleDateString(q.locale.toString(),t)]}),(0,w.jsxs)(G.A,{children:[(0,w.jsx)("strong",{children:"Activated"})," ","active"===e.status&&new Date(Date.parse(e.updated_at)).toLocaleDateString(q.locale.toString(),t),"active"!==e.status&&e.activated_at&&new Date(Date.parse(e.activated_at)).toLocaleDateString(q.locale.toString(),t),"active"!==e.status&&!e.activated_at&&(0,w.jsx)("span",{className:"mailpoet-deactive",children:"Not activated yet."})]}),(0,w.jsxs)(G.A,{children:[(0,w.jsx)("strong",{children:"Author"})," ",e.author.name]}),(0,w.jsx)(G.A,{children:(0,w.jsx)(U.J,{})})]}),(0,w.jsx)(z,{})]})}const{Tabs:Y}=E(I.j),X=b.A.select({web:!0,native:!1});function Z(e){const{keyboardShortcut:t,sidebarKey:a,showIconLabels:i,automationName:o}=(0,p.A)((e=>({keyboardShortcut:e(_.M_).getShortcutRepresentation("mailpoet/automation-editor/toggle-sidebar"),sidebarKey:e(v.M_).getActiveComplementaryArea(N.storeName)??N.automationSidebarKey,showIconLabels:e(N.storeName).isFeatureActive("showIconLabels"),automationName:e(N.storeName).getAutomationData().name})),[]),s=(0,n.useRef)(null),r=(0,n.useContext)(Y.Context);return(0,w.jsx)(v.WK,{identifier:a,header:(0,w.jsx)(Y.Context.Provider,{value:r,children:(0,w.jsx)(K,{ref:s})}),closeLabel:(0,x.__)("Close settings","mailpoet"),headerClassName:"editor-sidebar__panel-tabs",title:(0,x.__)("Settings","mailpoet"),icon:C.A,className:"edit-site-sidebar mailpoet-automation-sidebar",panelClassName:"edit-site-sidebar",smallScreenTitle:o||(0,x.__)("(no title)","mailpoet"),scope:N.storeName,toggleShortcut:t,isActiveByDefault:X,showIconLabels:i,...e,children:(0,w.jsxs)(Y.Context.Provider,{value:r,children:[(0,w.jsx)(Y.TabPanel,{tabId:N.automationSidebarKey,children:(0,w.jsx)(Q,{})}),(0,w.jsx)(Y.TabPanel,{tabId:N.stepSidebarKey,children:(0,w.jsx)(R,{})})]})})}function $(e){const{openSidebar:t}=(0,S.A)(N.storeName),{sidebarKey:a}=(0,p.A)((e=>({sidebarKey:e(v.M_).getActiveComplementaryArea(N.storeName)??N.automationSidebarKey})),[]);return(0,w.jsx)(Y,{selectedTabId:a,onSelect:t,children:(0,w.jsx)(Z,{...e})})}var ee=a(44931),te=a(57450),ae=a(43318),ie=a(64882),oe=a(6997),se=a(83471),ne=a(63254),re=a(30827);function le({onClose:e}){const[t,a]=(0,n.useState)(!1),{activate:i}=(0,S.A)(N.storeName);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{className:"mailpoet-automation-activate-panel__header",children:[(0,w.jsx)("div",{className:"mailpoet-automation-activate-panel__header-activate-button",children:(0,w.jsxs)(l.Ay,{variant:"primary",disabled:t,isBusy:t,autoFocus:!t,onClick:()=>{a(!0),i()},children:[t&&(0,x.__)("Activating…","mailpoet"),!t&&(0,x.__)("Activate","mailpoet")]})}),(0,w.jsx)("div",{className:"mailpoet-automation-activate-panel__header-cancel-button",children:(0,w.jsx)(l.Ay,{variant:"secondary",onClick:e,disabled:t,children:(0,x.__)("Cancel","mailpoet")})})]}),t&&(0,w.jsx)("div",{className:"mailpoet-automation-activate-panel__body",children:(0,w.jsx)(se.Ay,{})}),!t&&(0,w.jsxs)("div",{className:"mailpoet-automation-activate-panel__body",children:[(0,w.jsx)("p",{children:(0,w.jsx)("strong",{children:(0,x.__)("Are you ready to activate?","mailpoet")})}),(0,w.jsx)("p",{children:(0,x.__)("Double-check your settings before activating.","mailpoet")})]})]})}function ce({onClose:e}){const{automation:t}=(0,p.A)((e=>({automation:e(N.storeName).getAutomationData()})),[]);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)("div",{className:"mailpoet-automation-activate-panel__header",children:(0,w.jsx)(l.Ay,{icon:ne.A,onClick:e,label:(0,x.__)("Close","mailpoet")})}),(0,w.jsxs)("div",{className:"mailpoet-automation-activate-panel__body",children:[(0,w.jsx)("div",{className:"mailpoet-automation-activate-panel__section",children:(0,x.sprintf)((0,x.__)('"%s" is now live.',"mailpoet"),t.name)}),(0,w.jsx)("p",{children:(0,w.jsx)("strong",{children:(0,x.__)("What’s next?","mailpoet")})}),(0,w.jsx)("p",{children:(0,x.__)("View all your automations to track statistics and create new ones.","mailpoet")}),(0,w.jsx)(l.Ay,{variant:"secondary",onClick:()=>{window.parent&&window.parent!==window?window.parent.postMessage({type:"mailpoet-navigate-to-automation-listing"},window.location.origin):window.location.href=ae.U.urls.automationListing},children:(0,x.__)("View all automations","mailpoet")})]})]})}function de(){const{automation:e,errors:t}=(0,p.A)((e=>({errors:e(N.storeName).getErrors(),automation:e(N.storeName).getAutomationData()})),[]),{closeActivationPanel:a}=(0,S.A)(N.storeName);if((0,n.useEffect)((()=>{t&&a()}),[t,a]),t)return null;const i=e.status===re.i.ACTIVE;return(0,w.jsxs)("div",{className:"mailpoet-automation-activate-panel",children:[i&&(0,w.jsx)(ce,{onClose:a}),!i&&(0,w.jsx)(le,{onClose:a})]})}var me=a(90078);function ue(e){return"saved"!==(0,m.L)(N.storeName).getSavedState()?(e.returnValue=(0,x.__)("There are unsaved changes that will be lost. Do you want to continue?","mailpoet"),e.returnValue):""}function pe(){const{isFullscreenActive:e,isInserterOpened:t,isActivationPanelOpened:a,isSidebarOpened:i,showIconLabels:s,automation:h}=(0,p.A)((e=>({isFullscreenActive:e(N.storeName).isFeatureActive("fullscreenMode"),isInserterOpened:e(N.storeName).isInserterSidebarOpened(),isSidebarOpened:e(N.storeName).isSidebarOpened(),isActivationPanelOpened:e(N.storeName).isActivationPanelOpened(),showIconLabels:e(N.storeName).isFeatureActive("showIconLabels"),automation:e(N.storeName).getAutomationData()})),[]),[b,f]=(0,n.useState)(!0);if((0,n.useEffect)((()=>(window.addEventListener("beforeunload",ue),()=>window.removeEventListener("beforeunload",ue))),[]),(0,n.useEffect)((()=>{b&&("trash"===h.status&&(window.location.href=(0,j.F)(ae.U.urls.automationListing,{notice:ie.f.automationHadBeenDeleted,"notice-args":[h.name]})),function(){const e=(0,m.L)(N.storeName).getAutomationData();if(![re.i.ACTIVE,re.i.DEACTIVATING].includes(e.status))return;if(0===e.stats.totals.in_progress)return;const{createNotice:t}=(0,u.J)(d.store);t("success",(0,x.__)("Editing an active automation is currently unavailable.","mailpoet"),{type:"snackbar"})}(),f(!1))}),[h.name,h.status,b]),"trash"===h.status)return null;const y=o()("interface-interface-skeleton",{"is-sidebar-opened":i,"show-icon-labels":s});return(0,w.jsx)(_.Ee,{children:(0,w.jsxs)(r.Kq,{children:[(0,w.jsx)(v.fA,{isActive:e}),(0,w.jsx)(k,{}),(0,w.jsx)($,{}),(0,w.jsx)(v.Du,{className:y,drawer:e&&(0,w.jsx)("div",{className:"edit-site-navigation-toggle",children:(0,w.jsx)(l.Ay,{className:"edit-site-navigation-toggle__button has-icon",href:"admin.php?page=mailpoet-automation",children:(0,w.jsx)(c.A,{size:36,icon:g.A})})}),header:(0,w.jsx)(A.Y9,{showInserterToggle:false}),content:(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(D.D,{}),(0,w.jsx)(ee.G,{context:"edit"})]}),sidebar:(0,w.jsx)(v.WK.Slot,{scope:N.storeName}),secondarySidebar:null}),a&&(0,w.jsx)(de,{})]})})}window.addEventListener("DOMContentLoaded",(()=>{if((0,x.setLocaleData)(window.wp.i18n.getLocaleData()),void 0!==window.wp.date.getSettings){const e=window.wp;(0,h.setSettings)(e.date.getSettings())}else{const e=window.wp;(0,h.setSettings)(e.date.__experimentalGetSettings())}(0,N.createStore)();const e=b.A.select({web:!0,native:!1});(0,u.J)(v.M_).enableComplementaryArea(N.storeName,e?N.automationSidebarKey:void 0);const t=(0,f.d)(window.location.href,"fullscreen");("true"===t||"1"===t)&&((0,u.J)("core/preferences").set(N.storeName,"fullscreenMode",!0),(0,u.J)(N.storeName).setFullscreenForced(!0));const a=document.getElementById("mailpoet_automation_editor");a&&((0,y.registerTranslations)(),oe.default.use((async(e,t)=>{try{return await t(e)}catch(t){if(e.signal?.aborted)return;const a=t,i=a.data?.status;if("mailpoet_automation_not_valid"===a.code)return void(0,u.J)(N.storeName).setErrors({steps:a.data.errors});if(i&&i>=400&&i<500){const e=a.message;return(0,u.J)(d.store).createErrorNotice(e??(0,x.__)("An unknown error occurred.","mailpoet"),{explicitDismiss:!0}),void(0,u.J)(N.storeName).setErrors({steps:[]})}throw(0,u.J)(d.store).createErrorNotice((0,x.__)("An unknown error occurred.","mailpoet"),{explicitDismiss:!0}),t}})),(0,te.b)(),(0,me.g)(),(0,s.createRoot)(a).render((0,w.jsx)(pe,{})))}))},41669:e=>{e.exports=jQuery}},e=>{e.O(0,[223],(()=>e(e.s=24349))),e.O()}]);