"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(77906),h=a(62694),b=a(28636),g=a(2103),v=a(88634),_=a(99671),x=a(67268),j=a(82321),f=a(78631),y=a(39833),A=(a(50270),a(86106)),S=a(14687),N=a(2161);function w(){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 k=a(30176),D=a(8092),C=a(96606),I=a(87520);const{lock:L,unlock:T}=(0,I.yf)("I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.","@wordpress/edit-post"),{Tabs:E}=T(C.j),O=n.forwardRef((function(e,t){return(0,A.jsxs)(E.TabList,{ref:t,children:[(0,A.jsx)(E.Tab,{tabId:N.automationSidebarKey,children:(0,x.__)("Automation","mailpoet")}),(0,A.jsx)(E.Tab,{tabId:N.stepSidebarKey,children:(0,x.__)("Step","mailpoet")})]})}));var K=a(78048),F=a(99252),P=a(33352),M=a(90406),J=a(70081);function V({title:e,description:t,icon:a}){return(0,A.jsxs)("div",{className:"block-editor-block-card",children:[(0,A.jsx)(J.W,{icon:a}),(0,A.jsxs)("div",{className:"block-editor-block-card__content",children:[(0,A.jsx)("h2",{className:"block-editor-block-card__title",children:e}),(0,A.jsx)("span",{className:"block-editor-block-card__description",children:t})]})]})}function W(){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,A.jsx)(K.A,{isDismissible:!1,status:"error",children:t}):null}function B(){const{selectedStep:e,selectedStepType:t}=(0,p.A)((e=>({selectedStep:e(N.storeName).getSelectedStep(),selectedStepType:e(N.storeName).getSelectedStepType()})),[]);if(!e)return(0,A.jsx)(F.Ay,{children:"No step selected."});if(!t)return(0,A.jsx)(F.Ay,{children:"Unknown step type."});const a=t.edit;return(0,A.jsxs)("div",{className:"block-editor-block-inspector",children:[(0,A.jsx)(W,{}),(0,A.jsx)(V,{title:t.title(e,"sidebar"),description:t.description(e,"sidebar"),icon:t.icon}),(0,A.jsx)(a,{},e.id),"trigger"===e.type&&(0,A.jsx)(M.qn,{strings:P.t})]})}var G=a(64214),H=a(41221),R=a(33191),U=a(51047);function q(){const e=U.Hooks.applyFilters("mailpoet.automation.settings.render",{});return 0===Object.keys(e).length?null:(0,A.jsx)(F.Ay,{title:(0,x.__)("Automation settings","mailpoet"),initialOpen:!0,children:Object.keys(e).map((t=>(0,A.jsx)(G.A,{children:e[t]},t)))})}function z(){const{automationData:e}=(0,p.A)((e=>({automationData:e(N.storeName).getAutomationData()})),[]),t={year:"numeric",month:"long",day:"numeric"};return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(F.Ay,{title:(0,x.__)("Automation details","mailpoet"),initialOpen:!0,children:[(0,A.jsxs)(G.A,{children:[(0,A.jsx)("strong",{children:"Date added"})," ",new Date(Date.parse(e.created_at)).toLocaleDateString(R.locale.toString(),t)]}),(0,A.jsxs)(G.A,{children:[(0,A.jsx)("strong",{children:"Activated"})," ","active"===e.status&&new Date(Date.parse(e.updated_at)).toLocaleDateString(R.locale.toString(),t),"active"!==e.status&&e.activated_at&&new Date(Date.parse(e.activated_at)).toLocaleDateString(R.locale.toString(),t),"active"!==e.status&&!e.activated_at&&(0,A.jsx)("span",{className:"mailpoet-deactive",children:"Not activated yet."})]}),(0,A.jsxs)(G.A,{children:[(0,A.jsx)("strong",{children:"Author"})," ",e.author.name]}),(0,A.jsx)(G.A,{children:(0,A.jsx)(H.J,{})})]}),(0,A.jsx)(q,{})]})}const{Tabs:Q}=T(C.j),Y=b.A.select({web:!0,native:!1});function X(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)(Q.Context);return(0,A.jsx)(v.WK,{identifier:a,header:(0,A.jsx)(Q.Context.Provider,{value:r,children:(0,A.jsx)(O,{ref:s})}),closeLabel:(0,x.__)("Close settings","mailpoet"),headerClassName:"editor-sidebar__panel-tabs",title:(0,x.__)("Settings","mailpoet"),icon:D.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:Y,showIconLabels:i,...e,children:(0,A.jsxs)(Q.Context.Provider,{value:r,children:[(0,A.jsx)(Q.TabPanel,{tabId:N.automationSidebarKey,children:(0,A.jsx)(z,{})}),(0,A.jsx)(Q.TabPanel,{tabId:N.stepSidebarKey,children:(0,A.jsx)(B,{})})]})})}function Z(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,A.jsx)(Q,{selectedTabId:a,onSelect:t,children:(0,A.jsx)(X,{...e})})}var $=a(44931),ee=a(57450),te=a(43318),ae=a(64882),ie=a(6997),oe=a(83471),se=a(63254),ne=a(30827);function re({onClose:e}){const[t,a]=(0,n.useState)(!1),{activate:i}=(0,S.A)(N.storeName);return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)("div",{className:"mailpoet-automation-activate-panel__header",children:[(0,A.jsx)("div",{className:"mailpoet-automation-activate-panel__header-activate-button",children:(0,A.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,A.jsx)("div",{className:"mailpoet-automation-activate-panel__header-cancel-button",children:(0,A.jsx)(l.Ay,{variant:"secondary",onClick:e,disabled:t,children:(0,x.__)("Cancel","mailpoet")})})]}),t&&(0,A.jsx)("div",{className:"mailpoet-automation-activate-panel__body",children:(0,A.jsx)(oe.Ay,{})}),!t&&(0,A.jsxs)("div",{className:"mailpoet-automation-activate-panel__body",children:[(0,A.jsx)("p",{children:(0,A.jsx)("strong",{children:(0,x.__)("Are you ready to activate?","mailpoet")})}),(0,A.jsx)("p",{children:(0,x.__)("Double-check your settings before activating.","mailpoet")})]})]})}function le({onClose:e}){const{automation:t}=(0,p.A)((e=>({automation:e(N.storeName).getAutomationData()})),[]);return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("div",{className:"mailpoet-automation-activate-panel__header",children:(0,A.jsx)(l.Ay,{icon:se.A,onClick:e,label:(0,x.__)("Close","mailpoet")})}),(0,A.jsxs)("div",{className:"mailpoet-automation-activate-panel__body",children:[(0,A.jsx)("div",{className:"mailpoet-automation-activate-panel__section",children:(0,x.sprintf)((0,x.__)('"%s" is now live.',"mailpoet"),t.name)}),(0,A.jsx)("p",{children:(0,A.jsx)("strong",{children:(0,x.__)("What’s next?","mailpoet")})}),(0,A.jsx)("p",{children:(0,x.__)("View all your automations to track statistics and create new ones.","mailpoet")}),(0,A.jsx)(l.Ay,{variant:"secondary",onClick:()=>{window.location.href=te.U.urls.automationListing},children:(0,x.__)("View all automations","mailpoet")})]})]})}function ce(){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===ne.i.ACTIVE;return(0,A.jsxs)("div",{className:"mailpoet-automation-activate-panel",children:[i&&(0,A.jsx)(le,{onClose:a}),!i&&(0,A.jsx)(re,{onClose:a})]})}var de=a(99558);function me(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 ue(){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",me),()=>window.removeEventListener("beforeunload",me))),[]),(0,n.useEffect)((()=>{b&&("trash"===h.status&&(window.location.href=(0,j.F)(te.U.urls.automationListing,{notice:ae.f.automationHadBeenDeleted,"notice-args":[h.name]})),function(){const e=(0,m.L)(N.storeName).getAutomationData();if(![ne.i.ACTIVE,ne.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 temporarily unavailable. We are working on introducing this functionality.","mailpoet"),{type:"snackbar"})}(),f(!1))}),[h.name,h.status,b]),"trash"===h.status)return null;const S=o()("interface-interface-skeleton",{"is-sidebar-opened":i,"show-icon-labels":s});return(0,A.jsx)(_.Ee,{children:(0,A.jsxs)(r.Kq,{children:[(0,A.jsx)(v.fA,{isActive:e}),(0,A.jsx)(w,{}),(0,A.jsx)(Z,{}),(0,A.jsx)(v.Du,{className:S,drawer:e&&(0,A.jsx)("div",{className:"edit-site-navigation-toggle",children:(0,A.jsx)(l.Ay,{className:"edit-site-navigation-toggle__button has-icon",href:"admin.php?page=mailpoet-automation",children:(0,A.jsx)(c.A,{size:36,icon:g.A})})}),header:(0,A.jsx)(y.Y9,{showInserterToggle:false}),content:(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(k.D,{}),(0,A.jsx)($.G,{context:"edit"})]}),sidebar:(0,A.jsx)(v.WK.Slot,{scope:N.storeName}),secondarySidebar:null}),a&&(0,A.jsx)(ce,{})]})})}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=document.getElementById("mailpoet_automation_editor");t&&((0,f.registerTranslations)(),ie.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,ee.b)(),(0,de.g)(),(0,s.H)(t).render((0,A.jsx)(ue,{})))}))},41669:e=>{e.exports=jQuery}},e=>{e.O(0,[223],(()=>e(e.s=24349))),e.O()}]);