File "automation_editor.js"

Full Path: /home/warrior1/public_html/wp-content-20241001222009/plugins/mailpoet/assets/dist/js/automation_editor.js
File size: 50.57 KB
MIME-type: text/plain
Charset: utf-8

"use strict";(self.webpackChunkMailPoet3=self.webpackChunkMailPoet3||[]).push([[392],{86272:function(e,t,a){var o=a(65443),s=a.n(o),i=a(64151),r=a(49231),l=a(33851),n=a(52278),c=a(3610),d=a(90057),m=a(87834),p=a(33140),u=(0,r.createElement)(p.Wj,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24"},(0,r.createElement)(p.y$,{d:"M20 10c0-5.51-4.49-10-10-10C4.48 0 0 4.49 0 10c0 5.52 4.48 10 10 10 5.51 0 10-4.48 10-10zM7.78 15.37L4.37 6.22c.55-.02 1.17-.08 1.17-.08.5-.06.44-1.13-.06-1.11 0 0-1.45.11-2.37.11-.18 0-.37 0-.58-.01C4.12 2.69 6.87 1.11 10 1.11c2.33 0 4.45.87 6.05 2.34-.68-.11-1.65.39-1.65 1.58 0 .74.45 1.36.9 2.1.35.61.55 1.36.55 2.46 0 1.49-1.4 5-1.4 5l-3.03-8.37c.54-.02.82-.17.82-.17.5-.05.44-1.25-.06-1.22 0 0-1.44.12-2.38.12-.87 0-2.33-.12-2.33-.12-.5-.03-.56 1.2-.06 1.22l.92.08 1.26 3.41zM17.41 10c.24-.64.74-1.87.43-4.25.7 1.29 1.05 2.71 1.05 4.25 0 3.29-1.73 6.24-4.4 7.78.97-2.59 1.94-5.2 2.92-7.78zM6.1 18.09C3.12 16.65 1.11 13.53 1.11 10c0-1.3.23-2.48.72-3.59C3.25 10.3 4.67 14.2 6.1 18.09zm4.03-6.63l2.58 6.98c-.86.29-1.76.45-2.71.45-.79 0-1.57-.11-2.29-.33.81-2.38 1.62-4.74 2.42-7.1z"})),h=a(98005),_=a(353),g=a(95393),x=a(67911),v=a(54600),f=a(85479),j=a(38104),b=a(30337),w=a(17921),N=a(14676),k=a(34380),y=a(82435),S=a(76767),Z=a(41325),C=a(20264);const A=w.Z;function D(e){let{children:t}=e;const{workflowName:a,workflowStatus:o,showIconLabels:s}=(0,m.Z)((e=>({workflowName:e(S.storeName).getWorkflowData().name,workflowStatus:e(S.storeName).getWorkflowData().status,showIconLabels:e(S.storeName).isFeatureActive("showIconLabels")})),[]),i=(0,r.useRef)();let l="mailpoet-automation-editor-chip-gray";return o===Z.x.ACTIVE?l="mailpoet-automation-editor-chip-success":[Z.x.INACTIVE,Z.x.DEACTIVATING].includes(o)&&(l="mailpoet-automation-editor-chip-danger"),(0,C.jsx)("div",{className:"edit-site-document-actions has-secondary-label",children:(0,C.jsx)("div",{ref:i,className:"edit-site-document-actions__title-wrapper",children:t&&(0,C.jsx)(A,{popoverProps:{anchorRef:i.current},position:"bottom center",renderToggle:e=>{let{isOpen:t,onToggle:i}=e;return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)("a",{className:"mailpoet-automation-editor-dropdown-toggle-link",href:"#",onClick:i,children:[(0,C.jsxs)(N.Z,{size:"body",className:"edit-site-document-actions__title",as:"h1",children:[(0,C.jsx)(k.Z,{as:"span",children:(0,b.__)("Editing workflow: ","mailpoet")}),a]}),(0,C.jsxs)(N.Z,{size:"body",className:`edit-site-document-actions__secondary-item ${l}`,children:[o===Z.x.ACTIVE&&(0,b.__)("Active","mailpoet"),o===Z.x.INACTIVE&&(0,b.__)("Inactive","mailpoet"),o===Z.x.DEACTIVATING&&(0,b.__)("Deactivating","mailpoet"),o===Z.x.DRAFT&&(0,b.__)("Draft","mailpoet")]})]}),(0,C.jsx)(n.Z,{className:"edit-site-document-actions__get-info",icon:y.Z,"aria-expanded":t,"aria-haspopup":"true",onClick:i,label:(0,b.__)("Change workflow name","mailpoet"),children:s&&(0,b.__)("Rename","mailpoet")})]})},contentClassName:"edit-site-document-actions__info-dropdown",renderContent:t})})})}var I=a(88565),T=a(15596),E=a(73763);function F(e){let{size:t="medium",children:a}=e;return(0,C.jsx)("div",{className:s()({"mailpoet-automation-chip":!0,"chip-small":"small"===t,"chip-medium":"medium"===t,"chip-large":"large"===t}),children:a})}function W(e){let{foreground:t,background:a,...o}=e;return(0,C.jsx)("div",{className:"mailpoet-automation-colored-icon",style:{width:o.width,height:o.height,backgroundColor:a,fill:t},children:(0,C.jsx)(c.Z,{...o})})}const L=d.Z,M=(0,r.createContext)(void 0);function P(e){let{stepId:t}=e;const a=(0,r.useContext)(M),{steps:o,workflowData:s}=(0,m.Z)((e=>({steps:e(S.storeName).getSteps(),workflowData:e(S.storeName).getWorkflowData()})),[]),{openSidebar:i,selectStep:l}=(0,f.Z)(S.storeName),n=s.steps[t],c=o.find((e=>{let{key:t}=e;return t===n.key}));return(0,C.jsxs)(I.A,{className:"mailpoet-automation-step-error",role:"listitem",state:a,onClick:()=>{i(S.stepSidebarKey),l(n)},children:[(0,C.jsx)(W,{icon:c.icon,foreground:c.foreground,background:c.background,width:"23px",height:"23px"}),c.title]})}function V(){const[e,t]=(0,r.useState)(!1),a=(0,T.u)({orientation:"vertical",shift:!0}),{errors:o,workflowData:s}=(0,m.Z)((e=>({errors:e(S.storeName).getErrors(),workflowData:e(S.storeName).getWorkflowData()})),[]),i=(0,r.useMemo)((()=>{if(!o)return[];const e=new Map,t=s.steps.root.next_steps.map((e=>{let{id:t}=e;return t}));for(;t.length>0;){const r=t.shift();var a,i;e.has(r)||(e.set(r,o.steps[r]),null===(a=s.steps[r])||void 0===a||null===(i=a.next_steps)||void 0===i||i.forEach((e=>t.push(e.id))))}return[...e.values()].filter((e=>!!e))}),[o,s]),l=i.length>0;return(0,r.useEffect)((()=>{l&&t(!0)}),[l]),0===i.length?null:(0,C.jsxs)("div",{children:[(0,C.jsx)(n.Z,{variant:"link",onClick:()=>t((e=>void 0!==e&&!e)),onMouseDown:()=>t((e=>e?void 0:e)),style:{textDecoration:"none",borderRadius:99999},children:(0,C.jsxs)(F,{children:[i.length," issues"]})}),e&&(0,C.jsx)(L,{offset:10,placement:"bottom-end",onClose:()=>t((e=>void 0===e&&void 0)),children:(0,C.jsx)(M.Provider,{value:a,children:(0,C.jsxs)(E.b,{state:a,role:"list","aria-label":(0,b.__)("Workflow errors","mailpoet"),className:"mailpoet-automation-errors",children:[(0,C.jsx)("div",{className:"mailpoet-automation-errors-header",children:(0,b.__)("The following steps are not fully set:","mailpoet")}),i.map((e=>(0,C.jsx)(P,{stepId:e.step_id},e.step_id)))]})})})]})}var R=a(9487),O=a(96097);function H(){const{isInserterOpened:e,showIconLabels:t}=(0,m.Z)((e=>({isInserterOpened:e(S.storeName).isInserterSidebarOpened(),showIconLabels:e(S.storeName).isFeatureActive("showIconLabels")})),[]),{toggleInserterSidebar:a}=(0,f.Z)(S.storeName);return(0,C.jsx)(R.Z,{as:n.Z,className:"edit-site-header-toolbar__inserter-toggle",variant:"primary",isPressed:e,onMouseDown:e=>e.preventDefault(),onClick:a,icon:O.Z,label:(0,b.__)("Toggle step inserter","mailpoet"),showTooltip:!t,children:t&&(e?(0,b.__)("Close","mailpoet"):(0,b.__)("Add","mailpoet"))})}var K=a(53703),z=a(73435),B=a(83830),U=a(62271),$=a(45538),G=a(21602);function Y(e){let{scope:t,name:a,label:o,info:s,messageActivated:i,messageDeactivated:l,shortcut:n}=e;const c=(0,m.Z)((e=>!!e(G.h).get(t,a)),[a]),{toggle:d}=(0,f.Z)(G.h);return(0,r.createElement)(z.Z,{icon:c&&U.Z,isSelected:c,onClick:()=>{d(t,a),(()=>{if(c){const e=l||(0,b.sprintf)((0,b.__)("Preference deactivated - %s"),o);(0,$.D)(e)}else{const e=i||(0,b.sprintf)((0,b.__)("Preference activated - %s"),o);(0,$.D)(e)}})()},role:"menuitemcheckbox",info:s,shortcut:n},o)}var q=a(62668);function J(){return(0,C.jsx)(h.Eo,{className:"edit-site-more-menu",popoverProps:{className:"edit-site-more-menu__content"},children:()=>(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(K.Z,{label:(0,b._x)("View","noun","mailpoet"),children:(0,C.jsx)(Y,{scope:S.storeName,name:"fullscreenMode",label:(0,b.__)("Fullscreen mode","mailpoet"),info:(0,b.__)("Work without distraction","mailpoet"),messageActivated:(0,b.__)("Fullscreen mode activated","mailpoet"),messageDeactivated:(0,b.__)("Fullscreen mode deactivated","mailpoet"),shortcut:B.displayShortcut.secondary("f")})}),(0,C.jsx)(K.Z,{children:(0,C.jsx)(z.Z,{onClick:()=>{window.location.href=q.x.urls.automationListing},children:(0,b.__)("View all automations","mailpoet")})})]})})}var Q=a(77333);function X(e){let{onClose:t}=e;const[a,o]=(0,r.useState)(!1);return(0,C.jsxs)(Q.Z,{className:"mailpoet-automatoin-deactivate-modal",title:(0,b.__)("Stop automatoin for all subscribers?","mailpoet"),onRequestClose:t,children:[(0,C.jsx)("p",{children:(0,b.__)("Are you sure you want to deactivate now? This would stop this automation for all subscribers immediately.","mailpoet")}),(0,C.jsx)(n.Z,{isBusy:a,variant:"primary",onClick:()=>{o(!0),(0,j.dispatch)(S.storeName).deactivate(!0)},children:(0,b.__)("Deactivate now","mailpoet")}),(0,C.jsx)(n.Z,{disabled:a,variant:"tertiary",onClick:t,children:(0,b.__)("Cancel","mailpoet")})]})}function ee(e){let{onClose:t}=e;const{workflowName:a}=(0,m.Z)((e=>({workflowName:e(S.storeName).getWorkflowData().name})),[]),[o,s]=(0,r.useState)(Z.x.DEACTIVATING),[i,l]=(0,r.useState)(!1),c=(0,b.sprintf)((0,b.__)('Deactivate the "%s" automation?',"mailpoet"),a);return(0,C.jsxs)(Q.Z,{className:"mailpoet-automatoin-deactivate-modal",title:c,onRequestClose:t,children:[(0,b.__)("Some subscribers entered but have not finished the flow. Let's decide what to do in this case.","mailpoet"),(0,C.jsxs)("ul",{className:"mailpoet-automation-options",children:[(0,C.jsx)("li",{children:(0,C.jsxs)("label",{className:o===Z.x.DEACTIVATING?"mailpoet-automation-option active":"mailpoet-automation-option",children:[(0,C.jsx)("span",{children:(0,C.jsx)("input",{type:"radio",disabled:i,name:"deactivation-method",checked:o===Z.x.DEACTIVATING,onChange:()=>s(Z.x.DEACTIVATING)})}),(0,C.jsxs)("span",{children:[(0,C.jsx)("strong",{children:(0,b.__)("Let entered subscribers finish the flow","mailpoet")}),(0,b.__)("New subscribers won't enter, but recently entered could proceed.","mailpoet")]})]})}),(0,C.jsx)("li",{children:(0,C.jsxs)("label",{className:o===Z.x.INACTIVE?"mailpoet-automation-option active":"mailpoet-automation-option",children:[(0,C.jsx)("span",{children:(0,C.jsx)("input",{type:"radio",disabled:i,name:"deactivation-method",checked:o===Z.x.INACTIVE,onChange:()=>s(Z.x.INACTIVE)})}),(0,C.jsxs)("span",{children:[(0,C.jsx)("strong",{children:(0,b.__)("Stop automation for all subscribers","mailpoet")}),(0,b.__)("Automation will be deactivated for all the subscribers immediately.","mailpoet")]})]})})]}),(0,C.jsx)(n.Z,{isBusy:i,variant:"primary",onClick:()=>{l(!0),(0,j.dispatch)(S.storeName).deactivate(o!==Z.x.DEACTIVATING)},children:(0,b.__)("Deactivate automation","mailpoet")}),(0,C.jsx)(n.Z,{disabled:i,variant:"tertiary",onClick:t,children:(0,b.__)("Cancel","mailpoet")})]})}function te(e){let{onClick:t,label:a}=e;const{errors:o}=(0,m.Z)((e=>({errors:e(S.storeName).getErrors()})),[]);return(0,C.jsx)(n.Z,{variant:"primary",className:"editor-post-publish-button",onClick:t,disabled:!!o,children:a})}function ae(){const{save:e}=(0,f.Z)(S.storeName);return(0,C.jsx)(n.Z,{variant:"primary",className:"editor-post-publish-button",onClick:e,children:(0,b.__)("Update","mailpoet")})}function oe(){const{save:e}=(0,f.Z)(S.storeName);return(0,C.jsx)(n.Z,{variant:"tertiary",onClick:e,children:(0,b.__)("Save draft","mailpoet")})}function se(){const[e,t]=(0,r.useState)(!1),[a,o]=(0,r.useState)(!1),{hasUsersInProgress:s}=(0,m.Z)((e=>({hasUsersInProgress:e(S.storeName).getWorkflowData().stats.totals.in_progress>0})),[]);return(0,C.jsxs)(C.Fragment,{children:[e&&(0,C.jsx)(ee,{onClose:()=>{t(!1)}}),(0,C.jsx)(n.Z,{isBusy:a,variant:"tertiary",onClick:()=>{s?t(!0):(o(!0),(0,j.dispatch)(S.storeName).deactivate())},children:(0,b.__)("Deactivate","mailpoet")})]})}function ie(){const[e,t]=(0,r.useState)(!1),[a,o]=(0,r.useState)(!1),{hasUsersInProgress:s}=(0,m.Z)((e=>({hasUsersInProgress:e(S.storeName).getWorkflowData().stats.totals.in_progress>0})),[]);return(0,C.jsxs)(C.Fragment,{children:[e&&(0,C.jsx)(X,{onClose:()=>{t(!1)}}),(0,C.jsx)(n.Z,{isBusy:a,variant:"tertiary",onClick:()=>{s?t(!0):(o(!0),(0,j.dispatch)(S.storeName).deactivate())},children:(0,b.__)("Deactivate now","mailpoet")})]})}function re(e){let{showInserterToggle:t,toggleActivatePanel:a}=e;const{setWorkflowName:o}=(0,f.Z)(S.storeName),{workflowName:s,workflowStatus:i}=(0,m.Z)((e=>({workflowName:e(S.storeName).getWorkflowData().name,workflowStatus:e(S.storeName).getWorkflowData().status})),[]);return(0,C.jsxs)("div",{className:"edit-site-header",children:[(0,C.jsx)("div",{className:"edit-site-header_start",children:(0,C.jsx)(x.Z,{className:"edit-site-header__toolbar",orientation:"horizontal",role:"toolbar",children:t&&(0,C.jsx)(H,{})})}),(0,C.jsx)("div",{className:"edit-site-header_center",children:(0,C.jsx)(D,{children:()=>(0,C.jsxs)("div",{className:"mailpoet-automation-editor-dropdown-name-edit",children:[(0,C.jsx)("div",{className:"mailpoet-automation-editor-dropdown-name-edit-title",children:(0,b.__)("Automation name","mailpoet")}),(0,C.jsx)(v.Z,{value:s,onChange:e=>o(e),help:(0,b.__)('Give the automation a name that indicates its purpose. E.g. "Abandoned cart recovery"',"mailpoet")})]})})}),(0,C.jsx)("div",{className:"edit-site-header_end",children:(0,C.jsxs)("div",{className:"edit-site-header__actions",children:[(0,C.jsx)(V,{}),i===Z.x.DRAFT&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(oe,{}),(0,C.jsx)(te,{onClick:a,label:(0,b.__)("Activate","mailpoet")})]}),i===Z.x.ACTIVE&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(se,{}),(0,C.jsx)(ae,{})]}),i===Z.x.DEACTIVATING&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(ie,{}),(0,C.jsx)(te,{onClick:a,label:(0,b.__)("Update & Activate","mailpoet")})]}),i===Z.x.INACTIVE&&(0,C.jsx)(te,{onClick:a,label:(0,b.__)("Update & Activate","mailpoet")}),(0,C.jsx)(h.Ox.Slot,{scope:S.storeName}),(0,C.jsx)(J,{})]})})]})}var le=a(2637),ne=a(47842),ce=a(1779);function de(e){let{icon:t}=e;return(0,C.jsx)("span",{className:"block-editor-block-icon",children:(0,C.jsx)(c.Z,{icon:t})})}function me(e){let{item:t}=e;const{title:a,icon:o,description:s}=t;return(0,C.jsx)("div",{className:"block-editor-inserter__preview-container",children:(0,C.jsxs)("div",{className:"block-editor-block-card",children:[(0,C.jsx)(de,{icon:o}),(0,C.jsxs)("div",{className:"block-editor-block-card__content",children:[(0,C.jsx)("h2",{className:"block-editor-block-card__title",children:a}),(0,C.jsx)("span",{className:"block-editor-block-card__description",children:s})]})]})})}const pe=(0,r.createContext)(void 0),ue=(0,r.forwardRef)(((e,t)=>{let{isFirst:a,children:o,...s}=e;const i=(0,r.useContext)(pe);return(0,C.jsx)(I.A,{ref:t,state:i,role:"option",focusable:!0,...s,children:e=>{const t={...e,tabIndex:a?0:e.tabIndex};return(0,C.jsx)(n.Z,{...t,children:o})}})})),he=()=>{const{platform:e}=window.navigator;return-1!==e.indexOf("Mac")||["iPad","iPhone"].includes(e)},_e=(0,r.memo)((e=>{let{className:t,isFirst:a,item:o,onSelect:i,onHover:l,isDraggable:n,...c}=e;const d=(0,r.useRef)(!1);return(0,C.jsx)("div",{className:"block-editor-block-types-list__list-item",children:(0,C.jsxs)(ue,{isFirst:a,className:s()("block-editor-block-types-list__item",t),disabled:o.isDisabled,onClick:e=>{e.preventDefault(),i(o,he()?e.metaKey:e.ctrlKey),l(null)},onKeyDown:e=>{const{keyCode:t}=e;t===B.ENTER&&(e.preventDefault(),i(o,he()?e.metaKey:e.ctrlKey),l(null))},onFocus:()=>{d.current||l(o)},onMouseEnter:()=>{d.current||l(o)},onMouseLeave:()=>l(null),onBlur:()=>l(null),...c,children:[(0,C.jsx)("span",{className:"block-editor-block-types-list__item-icon",children:(0,C.jsx)(de,{icon:o.icon})}),(0,C.jsx)("span",{className:"block-editor-block-types-list__item-title",children:o.title})]})})})),ge=(0,r.forwardRef)(((e,t)=>{const[a,o]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{a&&(0,$.D)((0,b.__)("Use left and right arrow keys to move through steps","mailpoet"))}),[a]),(0,C.jsx)("div",{ref:t,role:"listbox","aria-orientation":"horizontal",onFocus:()=>{o(!0)},onBlur:e=>{!e.currentTarget.contains(e.relatedTarget)&&o(!1)},...e})}));var xe=a(17750);const ve=(0,r.forwardRef)(((e,t)=>{const a=(0,r.useContext)(pe);return(0,C.jsx)(xe.E,{state:a,role:"presentation",ref:t,...e})})),fe=(e,t)=>{const a=[];for(let o=0,s=e.length;o<s;o+=t)a.push(e.slice(o,o+t));return a};function je(e){let{items:t,onSelect:a,onHover:o,label:s,isDraggable:i=!0,children:r}=e;return(0,C.jsxs)(ge,{className:"block-editor-block-types-list","aria-label":s,children:[fe(t,3).map(((e,t)=>(0,C.jsx)(ve,{children:e.map(((e,s)=>{return(0,C.jsx)(_e,{item:e,className:(r=e.key,`editor-block-list-item-${r.replace(/\//,"-")}`),onSelect:a,onHover:o,isDraggable:i,isFirst:0===t&&0===s},e.key);var r}))},t))),r]})}function be(e){let{children:t}=e;const a=(0,T.u)({shift:!0,wrap:"horizontal"});return(0,C.jsx)(pe.Provider,{value:a,children:t})}const we=(0,r.forwardRef)(((e,t)=>{let{onInsert:a}=e;const[o,s]=(0,r.useState)(""),[i,l]=(0,r.useState)(null),{steps:n,type:c}=(0,m.Z)((e=>({steps:e(S.storeName).getSteps(),type:e(S.storeName).getInserterPopover().type})),[]),d=(0,r.useMemo)((()=>"triggers"===c?[{type:"triggers",title:void 0,label:(0,b._x)("Triggers","automation steps","mailpoet"),items:n.filter((e=>{let{group:t}=e;return"triggers"===t}))}]:[{type:"actions",title:(0,b._x)("Actions","automation steps","mailpoet"),label:(0,b._x)("Actions","automation steps","mailpoet"),items:n.filter((e=>{let{group:t}=e;return"actions"===t}))},{type:"logical",title:(0,b._x)("Logical","automation steps","mailpoet"),label:(0,b._x)("Logical","automation steps","mailpoet"),items:n.filter((e=>{let{group:t}=e;return"logical"===t}))}]),[n,c]),p=(0,r.useCallback)((e=>{l(e)}),[l]),u=(0,r.useRef)();(0,r.useImperativeHandle)(t,(()=>({focusSearch:()=>{var e;null===(e=u.current)||void 0===e||e.focus()}})));const h=(0,r.useMemo)((()=>d.map((e=>{return{...e,items:(t=o,a=e.items,a.filter((e=>e.title.toLowerCase().includes(t.trim().toLowerCase()))))};var t,a}))),[o,d]);return(0,C.jsxs)("div",{className:"block-editor-inserter__menu",children:[(0,C.jsx)("div",{className:"block-editor-inserter__main-area",children:(0,C.jsxs)("div",{className:"block-editor-inserter__content",children:[(0,C.jsx)(le.Z,{className:"block-editor-inserter__search",onChange:e=>{i&&l(null),s(e)},value:o,label:(0,b.__)("Search for automation steps","mailpoet"),placeholder:(0,b.__)("Search","mailpoet"),ref:u}),(0,C.jsx)("div",{className:"block-editor-inserter__block-list",children:(0,C.jsxs)(be,{children:[h.map((e=>e.items.length>0&&(0,C.jsxs)(r.Fragment,{children:[e.title&&(0,C.jsx)("div",{className:"block-editor-inserter__panel-header",children:(0,C.jsx)("h2",{className:"block-editor-inserter__panel-title",children:(0,C.jsx)("div",{children:e.title})})}),(0,C.jsx)("div",{className:"block-editor-inserter__panel-content",children:(0,C.jsx)(je,{items:e.items,onHover:p,onSelect:e=>a(e),label:e.label})})]},e.type))),0===h.reduce(((e,t)=>{let{items:a}=t;return e+a.length}),0)&&(0,C.jsxs)("div",{className:"block-editor-inserter__no-results",children:[(0,C.jsx)(ne.Z,{className:"block-editor-inserter__no-results-icon",icon:ce.Z}),(0,C.jsx)("p",{children:(0,b.__)("No results found.","mailpoet")})]})]})})]})}),i&&(0,C.jsx)(me,{item:i})]})}));function Ne(){const{isSidebarOpened:e,selectedStep:t}=(0,m.Z)((e=>({isSidebarOpened:e(S.storeName).isSidebarOpened,selectedStep:e(S.storeName).getSelectedStep}))),{openSidebar:a,closeSidebar:o,toggleFeature:s}=(0,f.Z)(S.storeName),{registerShortcut:i}=(0,f.Z)(_.h);return(0,r.useEffect)((()=>{i({name:"mailpoet/automation-editor/toggle-fullscreen",category:"global",description:(0,b.__)("Toggle fullscreen mode.","mailpoet"),keyCombination:{modifier:"secondary",character:"f"}}),i({name:"mailpoet/automation-editor/toggle-sidebar",category:"global",description:(0,b.__)("Show or hide the settings sidebar.","mailpoet"),keyCombination:{modifier:"primaryShift",character:","}})}),[i]),(0,_.bx)("mailpoet/automation-editor/toggle-fullscreen",(()=>{s("fullscreenMode")})),(0,_.bx)("mailpoet/automation-editor/toggle-sidebar",(s=>{if(s.preventDefault(),e())o();else{const e=t()?S.stepSidebarKey:S.workflowSidebarKey;a(e)}})),null}var ke=a(81535),ye=a(24683),Se=a(18439);function Ze(){const{notices:e}=(0,m.Z)((e=>({notices:e(Se.h).getNotices()})),[]),{removeNotice:t}=(0,f.Z)(Se.h),a=e.filter((e=>{let{isDismissible:t,type:a}=e;return t&&"default"===a})),o=e.filter((e=>{let{isDismissible:t,type:a}=e;return!t&&"default"===a})),s=e.filter((e=>{let{type:t}=e;return"snackbar"===t}));return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(ke.Z,{notices:o,className:"mailpoet-automation-editor-notices__notice-list"}),(0,C.jsx)(ke.Z,{notices:a,className:"mailpoet-automation-editor-notices__notice-list",onRemove:t}),(0,C.jsx)(ye.Z,{notices:s,className:"mailpoet-automation-editor-notices__snackbar-list",onRemove:t})]})}var Ce=a(12518),Ae=(0,r.createElement)(p.Wj,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.y$,{fillRule:"evenodd",d:"M10.289 4.836A1 1 0 0111.275 4h1.306a1 1 0 01.987.836l.244 1.466c.787.26 1.503.679 2.108 1.218l1.393-.522a1 1 0 011.216.437l.653 1.13a1 1 0 01-.23 1.273l-1.148.944a6.025 6.025 0 010 2.435l1.149.946a1 1 0 01.23 1.272l-.653 1.13a1 1 0 01-1.216.437l-1.394-.522c-.605.54-1.32.958-2.108 1.218l-.244 1.466a1 1 0 01-.987.836h-1.306a1 1 0 01-.986-.836l-.244-1.466a5.995 5.995 0 01-2.108-1.218l-1.394.522a1 1 0 01-1.217-.436l-.653-1.131a1 1 0 01.23-1.272l1.149-.946a6.026 6.026 0 010-2.435l-1.148-.944a1 1 0 01-.23-1.272l.653-1.131a1 1 0 011.217-.437l1.393.522a5.994 5.994 0 012.108-1.218l.244-1.466zM14.929 12a3 3 0 11-6 0 3 3 0 016 0z",clipRule:"evenodd"}));function De(e){let{sidebarKey:t}=e;const{openSidebar:a}=(0,f.Z)(S.storeName),[o,s]=t===S.workflowSidebarKey?[(0,b.__)("Workflow (selected)","mailpoet"),"is-active"]:["Workflow",""],[i,r]=t===S.stepSidebarKey?[(0,b.__)("Step (selected)","mailpoet"),"is-active"]:["Step",""];return(0,C.jsxs)("ul",{children:[(0,C.jsx)("li",{children:(0,C.jsx)(n.Z,{onClick:()=>a(S.workflowSidebarKey),className:`edit-site-sidebar__panel-tab ${s}`,"aria-label":o,"data-label":(0,b.__)("Workflow","mailpoet"),children:(0,b.__)("Workflow","mailpoet")})}),(0,C.jsx)("li",{children:(0,C.jsx)(n.Z,{onClick:()=>a(S.stepSidebarKey),className:`edit-site-sidebar__panel-tab ${r}`,"aria-label":i,"data-label":(0,b.__)("Step","mailpoet"),children:(0,b.__)("Step","mailpoet")})})]})}var Ie=a(21840);function Te(e){let{title:t,description:a,icon:o}=e;return(0,C.jsxs)("div",{className:"block-editor-block-card",children:[(0,C.jsx)(de,{icon:o}),(0,C.jsxs)("div",{className:"block-editor-block-card__content",children:[(0,C.jsx)("h2",{className:"block-editor-block-card__title",children:t}),(0,C.jsx)("span",{className:"block-editor-block-card__description",children:a})]})]})}function Ee(){const{selectedStep:e,selectedStepType:t}=(0,m.Z)((e=>({selectedStep:e(S.storeName).getSelectedStep(),selectedStepType:e(S.storeName).getSelectedStepType()})),[]);if(!e)return(0,C.jsx)(Ie.Z,{children:"No step selected."});if(!t)return(0,C.jsx)(Ie.Z,{children:"Unknown step type."});const a=t.edit;return(0,C.jsxs)("div",{className:"block-editor-block-inspector",children:[(0,C.jsx)(Te,{title:t.title,description:t.description,icon:t.icon}),(0,C.jsx)(a,{}),(0,C.jsxs)(Ie.Z,{title:(0,b.__)("Debug info","mailpoet"),initialOpen:!1,children:[(0,C.jsxs)("div",{children:[(0,C.jsx)("strong",{children:"ID:"})," ",e.id]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("strong",{children:"Type:"})," ",e.type]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("strong",{children:"Key:"})," ",e.key]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("strong",{children:"Args:"})," ",JSON.stringify(e.args)]})]})]})}var Fe=a(11345),We=a(8363);function Le(){const[e,t]=(0,r.useState)(!1),{workflow:a}=(0,m.Z)((e=>({workflow:e(S.storeName).getWorkflowData()})),[]),{trash:o}=(0,f.Z)(S.storeName);return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(We.Z,{isOpen:e,title:(0,b.__)("Delete workflow","mailpoet"),confirmButtonText:(0,b.__)("Yes, delete","mailpoet"),onConfirm:async()=>{o((()=>{t(!1)}))},onCancel:()=>t(!1),__experimentalHideHeader:!1,children:[(0,b.sprintf)((0,b.__)('You are about to delete the "%s" workflow.',"mailpoet"),a.name),(0,C.jsx)("br",{}),(0,b.__)(" This will stop it for all subscribers immediately.","mailpoet")]}),(0,C.jsx)(n.Z,{variant:"secondary",isDestructive:!0,onClick:()=>t(!0),children:(0,b.__)("Move to Trash","mailpoet")})]})}function Me(){const{workflowData:e}=(0,m.Z)((e=>({workflowData:e(S.storeName).getWorkflowData()})),[]),t={year:"numeric",month:"long",day:"numeric"};return(0,C.jsxs)(Ie.Z,{title:(0,b.__)("Automation details","mailpoet"),initialOpen:!0,children:[(0,C.jsxs)(Fe.Z,{children:[(0,C.jsx)("strong",{children:"Date added"})," ",new Date(Date.parse(e.created_at)).toLocaleDateString(void 0,t)]}),(0,C.jsxs)(Fe.Z,{children:[(0,C.jsx)("strong",{children:"Activated"})," ","active"===e.status&&new Date(Date.parse(e.updated_at)).toLocaleDateString(void 0,t),"active"!==e.status&&e.activated_at&&new Date(Date.parse(e.activated_at)).toLocaleDateString(void 0,t),"active"!==e.status&&!e.activated_at&&(0,C.jsx)("span",{className:"mailpoet-deactive",children:"Not activated yet."})]}),(0,C.jsxs)(Fe.Z,{children:[(0,C.jsx)("strong",{children:"Author"})," ",e.author.name]}),(0,C.jsx)(Fe.Z,{children:(0,C.jsx)(Le,{})})]})}const Pe=Ce.Z.select({web:!0,native:!1});function Ve(e){const{keyboardShortcut:t,sidebarKey:a,showIconLabels:o,workflowName:s}=(0,m.Z)((e=>({keyboardShortcut:e(_.h).getShortcutRepresentation("mailpoet/automation-editor/toggle-sidebar"),sidebarKey:e(h.h).getActiveComplementaryArea(S.storeName)??S.workflowSidebarKey,showIconLabels:e(S.storeName).isFeatureActive("showIconLabels"),workflowName:e(S.storeName).getWorkflowData().name})),[]);return(0,C.jsxs)(h.Vi,{identifier:a,header:(0,C.jsx)(De,{sidebarKey:a}),closeLabel:(0,b.__)("Close settings","mailpoet"),headerClassName:"edit-site-sidebar__panel-tabs",title:(0,b.__)("Settings","mailpoet"),icon:Ae,className:"edit-site-sidebar mailpoet-automation-sidebar",panelClassName:"edit-site-sidebar",smallScreenTitle:s||(0,b.__)("(no title)","mailpoet"),scope:S.storeName,toggleShortcut:t,isActiveByDefault:Pe,showIconLabels:o,...e,children:[a===S.workflowSidebarKey&&(0,C.jsx)(Me,{}),a===S.stepSidebarKey&&(0,C.jsx)(Ee,{})]})}var Re=a(34517);const Oe=(0,r.createContext)(void 0);function He(){return(0,C.jsx)("div",{className:"mailpoet-automation-editor-empty-workflow",children:(0,b.__)("No workflow data.","mailpoet")})}function Ke(e){let{onClick:t,previousStepId:a}=e;const o=(0,r.useContext)(Oe);return(0,C.jsx)(I.A,{state:o,role:"treeitem",className:"mailpoet-automation-editor-add-step-button",focusable:!0,"data-previous-step-id":a,onClick:e=>{e.stopPropagation();const a=e.target.closest("button");t(a)},children:(0,C.jsx)(ne.Z,{icon:O.Z,size:16})})}function ze(e){let{previousStepId:t}=e;const{setInserterPopover:a}=(0,j.dispatch)(S.storeName);return(0,C.jsx)("div",{className:"mailpoet-automation-editor-separator",children:(0,C.jsx)(Ke,{onClick:e=>a({anchor:e,type:"steps"}),previousStepId:t})})}var Be=a(78869),Ue=(0,r.createElement)(p.Wj,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.y$,{fillRule:"evenodd",d:"M8.95 11.25H4v1.5h4.95v4.5H13V18c0 1.1.9 2 2 2h3c1.1 0 2-.9 2-2v-3c0-1.1-.9-2-2-2h-3c-1.1 0-2 .9-2 2v.75h-2.55v-7.5H13V9c0 1.1.9 2 2 2h3c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3c-1.1 0-2 .9-2 2v.75H8.95v4.5ZM14.5 15v3c0 .3.2.5.5.5h3c.3 0 .5-.2.5-.5v-3c0-.3-.2-.5-.5-.5h-3c-.3 0-.5.2-.5.5Zm0-6V6c0-.3.2-.5.5-.5h3c.3 0 .5.2.5.5v3c0 .3-.2.5-.5.5h-3c-.3 0-.5-.2-.5-.5Z",clipRule:"evenodd"})),$e=a(83115),Ge=a(62006),Ye=(0,r.createElement)(p.Wj,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.y$,{d:"M20 5h-5.7c0-1.3-1-2.3-2.3-2.3S9.7 3.7 9.7 5H4v2h1.5v.3l1.7 11.1c.1 1 1 1.7 2 1.7h5.7c1 0 1.8-.7 2-1.7l1.7-11.1V7H20V5zm-3.2 2l-1.7 11.1c0 .1-.1.2-.3.2H9.1c-.1 0-.3-.1-.3-.2L7.2 7h9.6z"})),qe=a(33357);function Je(e){let{step:t}=e;const[a,o]=(0,r.useState)(!1),s=(0,r.useCallback)((e=>{Re.Hooks.applyFilters("mailpoet.automation.workflow.delete_step_callback",(()=>{o(!0)}))(e)}),[]);return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"mailpoet-automation-step-more-menu",children:(0,C.jsx)($e.Z,{label:(0,b.__)("More","mailpoet"),icon:Ge.Z,controls:[{title:(0,b.__)("Delete step","mailpoet"),icon:Ye,onClick:()=>s(t)}],popoverProps:{position:"bottom right"},toggleProps:{isSmall:!0}})}),a&&(0,C.jsx)(qe.Z,{onRequestClose:()=>{o(!1)},tracking:{utm_medium:"upsell_modal",utm_campaign:"remove_automation_step"},children:(0,b.__)("You cannot remove a step from the automation.","mailpoet")})]})}function Qe(e){let{step:t,isSelected:a}=e;const{stepType:o,error:i}=(0,m.Z)((e=>({stepType:e(S.storeName).getStepType(t.key),error:e(S.storeName).getStepError(t.id)})),[t]),{openSidebar:l,selectStep:n}=(0,f.Z)(S.storeName),c=(0,r.useContext)(Oe),{batch:d}=(0,Be.Z)(),p=`step-${t.id}`,u=o??(e=>{const t="trigger"===e.type;return{title:t?(0,b.__)("Unknown trigger","mailpoet"):(0,b.__)("Unknown step","mailpoet"),subtitle:()=>t?(0,b.__)("Trigger type not registered","mailpoet"):(0,b.__)("Step type not registered","mailpoet"),description:t?(0,b.__)("Unknown trigger","mailpoet"):(0,b.__)("Unknown step","mailpoet"),group:"trigger"===e.type?"triggers":"actions",key:e.key,foreground:"#8c8f94",background:"#dcdcde",edit:()=>null,icon:()=>Ue}})(t);return(0,C.jsxs)("div",{className:"mailpoet-automation-editor-step-wrapper",children:[(0,C.jsx)(Je,{step:t}),(0,C.jsxs)(I.A,{state:c,role:"treeitem",className:s()({"mailpoet-automation-editor-step":!0,"is-selected-step":a,"is-unknown-step":!o}),id:p,focusable:!0,onClick:()=>d((()=>{l(S.stepSidebarKey),n(t)})),children:[(0,C.jsx)("div",{className:"mailpoet-automation-editor-step-icon",children:(0,C.jsx)(W,{icon:u.icon,foreground:u.foreground,background:u.background,width:"23px",height:"23px"})}),(0,C.jsxs)("div",{children:[(0,C.jsx)("label",{htmlFor:p,className:"mailpoet-automation-editor-step-title",children:"trigger"!==t.type?u.title:(0,b._x)("Trigger","noun","mailpoet")}),(0,C.jsx)("div",{className:"mailpoet-automation-editor-step-subtitle",children:"trigger"!==t.type?u.subtitle(t):u.title})]}),i&&(0,C.jsx)("div",{className:"mailpoet-automation-editor-step-footer",children:(0,C.jsx)("div",{className:"mailpoet-automation-editor-step-error",children:(0,C.jsx)(F,{size:"small",children:(0,b.__)("Not set","mailpoet")})})})]},t.id)]})}function Xe(){const e=(0,r.useRef)(),[t,a]=(0,r.useState)(!1),{inserterPopover:o}=(0,m.Z)((e=>({inserterPopover:e(S.storeName).getInserterPopover()})),[]),{setInserterPopover:s}=(0,f.Z)(S.storeName),i=(0,r.useCallback)((e=>{Re.Hooks.applyFilters("mailpoet.automation.workflow.add_step_callback",(()=>{a(!0)}))(e)}),[]);return o?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(d.Z,{ref:e,anchorRect:o.anchor.getBoundingClientRect(),onClose:()=>{t||s(void 0)},children:(0,C.jsx)(we,{onInsert:i})}),t&&(0,C.jsx)(qe.Z,{onRequestClose:()=>{var t;a(!1),null===(t=e.current)||void 0===t||t.focus()},tracking:{utm_medium:"upsell_modal",utm_campaign:"add_automation_step"},children:(0,b.__)("You cannot add a new step to the automation.","mailpoet")})]}):null}function et(e){let{step:t}=e;const a=(0,r.useContext)(Oe),{setInserterPopover:o}=(0,f.Z)(S.storeName);return(0,C.jsxs)(I.A,{state:a,role:"treeitem",className:"mailpoet-automation-workflow-add-trigger","data-previous-step-id":t.id,focusable:!0,onClick:e=>{e.stopPropagation(),o({anchor:e.target.closest("button"),type:"triggers"})},children:[(0,C.jsx)(ne.Z,{icon:O.Z,size:16}),(0,b.__)("Add trigger","mailpoet")]})}var tt=a(24775);function at(){const{workflow:e}=(0,m.Z)((e=>({workflow:e(S.storeName).getWorkflowData()})),[]);return(0,C.jsx)("div",{className:"mailpoet-automation-editor-stats",children:(0,C.jsx)(tt.g,{items:[{key:"entered",label:(0,b._x)("Total Entered","automation stats","mailpoet"),value:e.stats.totals.entered},{key:"processing",label:(0,b._x)("Total Processing","automation stats","mailpoet"),value:e.stats.totals.in_progress},{key:"exited",label:(0,b._x)("Total Exited","automation stats","mailpoet"),value:e.stats.totals.exited}]})})}function ot(){const{workflowData:e,selectedStep:t}=(0,m.Z)((e=>({workflowData:e(S.storeName).getWorkflowData(),selectedStep:e(S.storeName).getSelectedStep()})),[]),a=(0,T.u)({orientation:"vertical",wrap:"horizontal",shift:!0}),o=(null==e?void 0:e.steps)??void 0,s=(0,r.useMemo)((()=>{const e=[o.root];for(;;){const t=e[e.length-1];if(!t||0===t.next_steps.length)break;e.push(o[t.next_steps[0].id])}return e.slice(1)}),[o]),i=(0,r.useMemo)((()=>Re.Hooks.applyFilters("mailpoet.automation.workflow.render_step",(e=>"root"===e.type?(0,C.jsx)(et,{step:e}):(0,C.jsx)(Qe,{step:e,isSelected:t&&e.id===t.id})))),[t]),l=(0,r.useMemo)((()=>Re.Hooks.applyFilters("mailpoet.automation.workflow.render_step_separator",(e=>(0,C.jsx)(ze,{previousStepId:e.id})))),[]);return e?(0,C.jsx)(Oe.Provider,{value:a,children:(0,C.jsxs)(E.b,{state:a,role:"tree","aria-label":(0,b.__)("Workflow","mailpoet"),"aria-orientation":"vertical",className:"mailpoet-automation-editor-workflow",children:[(0,C.jsxs)("div",{className:"mailpoet-automation-editor-workflow-wrapper",children:[(0,C.jsx)(at,{}),0===o.root.next_steps.length?(0,C.jsxs)(C.Fragment,{children:[i(o.root),l(o.root)]}):o.root.next_steps.map((e=>{var t;let{id:a}=e;return"trigger"!==(null===(t=o[a])||void 0===t?void 0:t.type)&&(0,C.jsxs)(r.Fragment,{children:[i(o.root),l(o.root)]},`root-${a}`)})),s.map((e=>(0,C.jsxs)(r.Fragment,{children:[i(e),l(e)]},e.id))),(0,C.jsx)(ne.Z,{className:"mailpoet-automation-editor-workflow-end",icon:U.Z}),(0,C.jsx)("div",{})]}),(0,C.jsx)(Xe,{})]})}):(0,C.jsx)(He,{})}var st=a(12374),it=a(9090),rt=a(6258),lt=a(97873);function nt(e){let{title:t,children:a}=e;return(0,C.jsxs)("h2",{className:"components-panel__body-title mailpoet-automation-panel-plain-body-title",children:[(0,C.jsx)("div",{className:"mailpoet-automation-panel-plain-body-title-text",children:t}),a]})}function ct(e){return(0,C.jsx)("div",{className:"mailpoet-automation-panel-plain-body-title-action",children:(0,C.jsx)(n.Z,{...e})})}const dt=[{label:(0,b.__)("Hours","mailpoet"),subtitle:e=>(0,b.sprintf)((0,b._n)("Wait for %d hour","Wait for %d hours",e,"mailpoet"),e),value:"HOURS"},{label:(0,b.__)("Days","mailpoet"),subtitle:e=>(0,b.sprintf)((0,b._n)("Wait for %d day","Wait for %d days",e,"mailpoet"),e),value:"DAYS"},{label:(0,b.__)("Weeks","mailpoet"),subtitle:e=>(0,b.sprintf)((0,b._n)("Wait for %d week","Wait for %d weeks",e,"mailpoet"),e),value:"WEEKS"}],mt={key:"core:delay",group:"actions",title:(0,b._x)("Delay","noun","mailpoet"),foreground:"#7F54B3",background:"#f7edf7",description:(0,b.__)("Wait some time before proceeding with the steps below","mailpoet"),subtitle:e=>{return e.args.delay&&e.args.delay_type?(t=e.args.delay_type,a=e.args.delay,dt.reduce(((e,o)=>o.value!==t?e:o.subtitle(a)),"")):(0,b.__)("Not set up yet.","mailpoet");var t,a},icon:function(){return(0,C.jsx)("svg",{viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",children:(0,C.jsx)("path",{d:"M9.79683 0.666656C4.6635 0.666656 0.463501 4.86666 0.463501 9.99999C0.463501 15.1333 4.6635 19.3333 9.79683 19.3333C14.9302 19.3333 19.1302 15.1333 19.1302 9.99999C19.1302 4.86666 14.9302 0.666656 9.79683 0.666656ZM9.79683 17.4667C5.68083 17.4667 2.33017 14.116 2.33017 9.99999C2.33017 5.88399 5.68083 2.53332 9.79683 2.53332C13.9128 2.53332 17.2635 5.88399 17.2635 9.99999C17.2635 14.116 13.9128 17.4667 9.79683 17.4667ZM10.2635 5.33332H8.8635V10.9333L13.7168 13.92L14.4635 12.7067L10.2635 10.1867V5.33332Z"})})},edit:function(){const{selectedStep:e,errors:t}=(0,m.Z)((e=>({selectedStep:e(S.storeName).getSelectedStep(),errors:e(S.storeName).getStepError(e(S.storeName).getSelectedStep().id)})),[]),a=(null==t?void 0:t.fields)??{},o=(null==a?void 0:a.delay)??"",s=(null==a?void 0:a.delay_type)??"",i=`delay-number-${e.id}`;return(0,C.jsxs)(Ie.Z,{opened:!0,children:[(0,C.jsx)("label",{htmlFor:i,children:(0,C.jsx)(nt,{title:(0,b.__)("Wait for","mailpoet")})}),(0,C.jsxs)(it.Z,{align:"top",children:[(0,C.jsx)(rt.Z,{style:{flex:"1 1 0"},className:o?"mailpoet-automation-field__error":"",children:(0,C.jsx)(v.Z,{id:i,help:o,type:"number",placeholder:(0,b.__)("Number","mailpoet"),value:e.args.delay??"",onChange:t=>{const a=0===t.length||parseInt(t,10)<1?1:parseInt(t,10);(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"delay",a)}})}),(0,C.jsx)(rt.Z,{style:{flex:"1 1 0"},className:s?"mailpoet-automation-field__error":"",children:(0,C.jsx)(lt.Z,{label:"",help:s,value:e.args.delay_type??"HOURS",options:dt,onChange:t=>(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"delay_type",t)})})]})]})}};var pt=a(52405);function ut(){return(0,C.jsxs)("span",{className:"mailpoet-shortcode-selector",children:["You can use"," ",(0,C.jsx)("a",{href:"https://kb.mailpoet.com/article/215-personalize-newsletter-with-shortcodes",target:"_blank",rel:"noopener noreferrer","data-beacon-article":"59d662ef042863379ddc6faa",children:(0,b.__)("MailPoet shortcodes","mailpoet")})]})}var ht=a(9578);function _t(e){let{currentName:t,defaultName:a,update:o}=e;return(0,C.jsx)(w.Z,{className:"mailpoet-step-name-dropdown",contentClassName:"mailpoet-step-name-popover",position:"bottom left",renderToggle:e=>{let{isOpen:o,onToggle:s}=e;return(0,C.jsx)(nt,{title:t.length>0?t:a,children:(0,C.jsx)(ct,{onClick:s,"aria-expanded":o,"aria-label":(0,b.__)("Edit step name","mailpoet"),children:(0,C.jsx)(ne.Z,{icon:ht.Z,size:16})})})},renderContent:()=>(0,C.jsx)(v.Z,{label:(0,b.__)("Step name","mailpoet"),className:"mailpoet-step-name-input",placeholder:a,value:t,onChange:o,help:(0,b.__)('Give the automation step a name that indicates its purpose. E.g "Abandoned cart recovery". This name will be displayed only to you and not to the clients.',"mailpoet")})})}function gt(e){let{centered:t,variant:a,...o}=e;return(0,C.jsx)(n.Z,{className:s()(["sidebar-primary"===a?"mailpoet-automation-button-sidebar-primary":"",t?"mailpoet-automation-button-centered":""]),variant:"sidebar-primary"===a?"primary":a,...o})}const xt={};function vt(){var e;const[t,a]=(0,r.useState)(!1),[o,s]=(0,r.useState)(!1),{selectedStep:i,workflowId:l,workflowSaved:n,errors:c}=(0,m.Z)((e=>({selectedStep:e(S.storeName).getSelectedStep(),workflowId:e(S.storeName).getWorkflowData().id,workflowSaved:e(S.storeName).getWorkflowSaved(),errors:e(S.storeName).getStepError(e(S.storeName).getSelectedStep().id)})),[]),d=null==i||null===(e=i.args)||void 0===e?void 0:e.email_id,p=i.id,u=(null==c?void 0:c.fields)??{},h=(null==u?void 0:u.email_id)??"",_=(0,r.useCallback)((async()=>{a(!0);const e=await q.x.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"create",data:{type:"automation",subject:"",options:{workflowId:l,workflowStepId:p}}});(0,j.dispatch)(S.storeName).updateStepArgs(p,"email_id",parseInt(e.data.id,10)),(0,j.dispatch)(S.storeName).save()}),[l,p]);return(0,r.useEffect)((()=>{t&&d&&n&&(window.location.href=`admin.php?page=mailpoet-newsletters#/template/${d}`)}),[d,n,t]),!d||t?(0,C.jsxs)("div",{className:h?"mailpoet-automation-field__error":"",children:[(0,C.jsx)(gt,{variant:"sidebar-primary",centered:!0,icon:O.Z,onClick:_,isBusy:t,disabled:t,children:(0,b.__)("Design email","mailpoet")}),h&&(0,C.jsx)("span",{className:"mailpoet-automation-field-message",children:(0,b.__)("You need to design an email before you can activate the workflow","mailpoet")})]}):(0,C.jsxs)("div",{className:"mailpoet-automation-email-buttons",children:[(0,C.jsx)(gt,{variant:"sidebar-primary",centered:!0,href:`?page=mailpoet-newsletter-editor&id=${i.args.email_id}`,children:(0,b.__)("Edit content","mailpoet")}),(0,C.jsx)(gt,{variant:"secondary",centered:!0,isBusy:o,disabled:o,onClick:async()=>{s(!0);const e=await(async e=>{var t;if(xt[e]&&xt[e].length>0)return xt[e];const a=await q.x.Ajax.post({api_version:window.mailpoet_api_version,endpoint:"newsletters",action:"get",data:{id:e}});return xt[e]=(null==a||null===(t=a.meta)||void 0===t?void 0:t.preview_url)??"",xt[e]})(d);window.open(e,"_blank"),s(!1)},children:(0,b.__)("Preview","mailpoet")})]})}function ft(e){return(0,C.jsx)(pt.Z,{...e,onChange:t=>e.onChange(t.replaceAll(/(\r?\n)+/g," ")),onKeyDown:t=>{"Enter"===t.key&&t.preventDefault(),e.onKeyDown&&e.onKeyDown(t)}})}function jt(){const{selectedStep:e,selectedStepType:t,errors:a}=(0,m.Z)((e=>({selectedStep:e(S.storeName).getSelectedStep(),selectedStepType:e(S.storeName).getSelectedStepType(),errors:e(S.storeName).getStepError(e(S.storeName).getSelectedStep().id)})),[]),o=(null==a?void 0:a.fields)??{},s=(null==o?void 0:o.sender_name)??"",i=(null==o?void 0:o.sender_address)??"",r=(null==o?void 0:o.subject)??"";return(0,C.jsxs)(Ie.Z,{opened:!0,children:[(0,C.jsx)(_t,{currentName:e.args.name??"",defaultName:t.title,update:t=>{(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"name",t)}}),(0,C.jsx)(v.Z,{className:s?"mailpoet-automation-field__error":"",help:s,label:(0,b.__)('"From" name',"mailpoet"),placeholder:(0,b.__)("John Doe","mailpoet"),value:e.args.sender_name??"",onChange:t=>(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"sender_name",t)}),(0,C.jsx)(v.Z,{className:i?"mailpoet-automation-field__error":"",help:i,type:"email",label:(0,b.__)('"From" email address',"mailpoet"),placeholder:(0,b.__)("you@domain.com","mailpoet"),value:e.args.sender_address??"",onChange:t=>(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"sender_address",t)}),(0,C.jsx)(ft,{className:r?"mailpoet-automation-field__error":"",label:(0,b.__)("Subject","mailpoet"),placeholder:(0,b.__)("Type in subject…","mailpoet"),value:e.args.subject??"",onChange:t=>(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"subject",t),help:(0,C.jsxs)(C.Fragment,{children:[`${r} `,(0,C.jsx)(ut,{})]})}),(0,C.jsx)(ft,{label:(0,b.__)("Preheader","mailpoet"),placeholder:(0,b.__)("Type in preheader…","mailpoet"),value:e.args.preheader??"",onChange:t=>(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"preheader",t),help:(0,C.jsx)(ut,{})}),(0,C.jsx)("div",{className:"mailpoet-automation-email-content-separator"}),(0,C.jsx)(nt,{title:(0,b.__)("Email","mailpoet")}),(0,C.jsx)(vt,{})]})}var bt=a(58897);function wt(){var e;const{selectedStep:t}=(0,m.Z)((e=>({selectedStep:e(S.storeName).getSelectedStep()})),[]),a=void 0!==(null===(e=t.args)||void 0===e?void 0:e.ga_campaign),o=Re.Hooks.applyFilters("mailpoet.automation.send_email.google_analytics_panel",(0,C.jsx)(qe.Z,{onRequestClose:()=>(0,j.dispatch)(S.storeName).updateStepArgs(t.id,"ga_campaign",void 0),children:(0,b.__)("Google Analytics tracking is not available in the free version of the MailPoet plugin.","mailpoet")}));return(0,C.jsxs)(Ie.Z,{title:(0,b.__)("Google analytics","mailpoet"),initialOpen:!1,children:[(0,C.jsx)(bt.Z,{label:(0,b.__)("Enable custom GA tracking","mailpoet"),checked:a,onChange:e=>(0,j.dispatch)(S.storeName).updateStepArgs(t.id,"ga_campaign",e?"":void 0)}),a&&o]})}function Nt(){const{selectedStep:e,errors:t}=(0,m.Z)((e=>({selectedStep:e(S.storeName).getSelectedStep(),errors:e(S.storeName).getStepError(e(S.storeName).getSelectedStep().id)})),[]),a=e.args.reply_to_name,o=e.args.reply_to_address,s=void 0!==a||void 0!==o,i=(null==t?void 0:t.fields)??{},r=(null==i?void 0:i.reply_to_name)??"",l=(null==i?void 0:i.reply_to_address)??"";return(0,C.jsxs)(Ie.Z,{title:(0,b.__)("Reply to","mailpoet"),initialOpen:!1,children:[(0,C.jsx)(bt.Z,{label:(0,b.__)("Use different email address for getting replies to the email","mailpoet"),checked:s,onChange:t=>{(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"reply_to_name",t?"":void 0),(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"reply_to_address",t?"":void 0)}}),s&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(v.Z,{className:r?"mailpoet-automation-field__error":"",help:r,label:(0,b.__)('"Reply to" name',"mailpoet"),placeholder:(0,b.__)("John Doe","mailpoet"),value:a??"",onChange:t=>(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"reply_to_name",t)}),(0,C.jsx)(v.Z,{className:l?"mailpoet-automation-field__error":"",help:l,type:"email",label:(0,b.__)('"Reply to" email address',"mailpoet"),placeholder:(0,b.__)("you@domain.com","mailpoet"),value:o??"",onChange:t=>(0,j.dispatch)(S.storeName).updateStepArgs(e.id,"reply_to_address",t)})]})]})}const kt={key:"mailpoet:send-email",group:"actions",title:(0,b.__)("Send email","mailpoet"),description:(0,b.__)("An email will be sent to subscriber","mailpoet"),subtitle:e=>e.args.name??(0,b.__)("Send email","mailpoet"),foreground:"#996800",background:"#FCF9E8",icon:function(){return(0,C.jsx)("svg",{viewBox:"0 0 16 12",xmlns:"http://www.w3.org/2000/svg",children:(0,C.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M2.73578 1.5L8 6.01219L13.2642 1.5H2.73578ZM14.5 2.41638L8.48809 7.56944L8 7.98781L7.51191 7.56944L1.5 2.41638V10C1.5 10.2761 1.72386 10.5 2 10.5H14C14.2761 10.5 14.5 10.2761 14.5 10V2.41638ZM0 2C0 0.89543 0.89543 0 2 0H14C15.1046 0 16 0.895431 16 2V10C16 11.1046 15.1046 12 14 12H2C0.895431 12 0 11.1046 0 10V2Z"})})},edit:function(){return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(jt,{}),(0,C.jsx)(Nt,{}),(0,C.jsx)(wt,{})]})}};var yt=(0,r.createElement)(p.Wj,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(p.y$,{fillRule:"evenodd",d:"M7.25 16.437a6.5 6.5 0 1 1 9.5 0V16A2.75 2.75 0 0 0 14 13.25h-4A2.75 2.75 0 0 0 7.25 16v.437Zm1.5 1.193a6.47 6.47 0 0 0 3.25.87 6.47 6.47 0 0 0 3.25-.87V16c0-.69-.56-1.25-1.25-1.25h-4c-.69 0-1.25.56-1.25 1.25v1.63ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z",clipRule:"evenodd"}));const St=window.mailpoet_segments;var Zt=a(65283);function Ct(e){let{label:t,value:a,suggestions:o,placeholder:s,onChange:i,...r}=e;return(0,C.jsx)(Zt.Z,{label:t,value:a.map((e=>e.name)),suggestions:o.map((e=>e.name)),__experimentalExpandOnFocus:!0,__experimentalAutoSelectFirstMatch:!0,placeholder:s,onChange:e=>{const t=e.map((e=>o.find((t=>t.name.toLowerCase()===e.toLowerCase()))??null)).filter((e=>null!==e));i(t)},...r})}function At(){var e;const{selectedStep:t}=(0,m.Z)((e=>({selectedStep:e(S.storeName).getSelectedStep()})),[]),a=null!==(e=t.args)&&void 0!==e&&e.segment_ids?t.args.segment_ids:[],o=St.filter((e=>"default"===e.type)),s=o.filter((e=>a.includes(e.id)));return(0,C.jsxs)(Ie.Z,{opened:!0,children:[(0,C.jsx)(nt,{title:(0,b.__)("Trigger settings","mailpoet")}),(0,C.jsx)(Ct,{label:(0,b.__)("When someone subscribers to the following list(s):","mailpoet"),placeholder:(0,b.__)("Any list","mailpoet"),value:s,suggestions:o,onChange:e=>{(0,j.dispatch)(S.storeName).updateStepArgs(t.id,"segment_ids",e.map((e=>e.id)))}})]})}function Dt(){return(0,C.jsx)(At,{})}const It={key:"mailpoet:someone-subscribes",group:"triggers",title:(0,b.__)("Someone subscribes","mailpoet"),foreground:"#2271b1",background:"#f0f6fc",description:(0,b.__)("Starts the automation when a new subscriber is added to MailPoet.","mailpoet"),subtitle:()=>(0,b._x)("Trigger","noun","mailpoet"),icon:()=>(0,C.jsx)("div",{style:{width:"100%",height:"100%",scale:"1.4"},children:yt}),edit:()=>(0,C.jsx)(Dt,{})},Tt=Object.keys(window.mailpoet_user_roles).map((e=>({id:e,name:window.mailpoet_user_roles[e]})));function Et(){var e;const{selectedStep:t}=(0,m.Z)((e=>({selectedStep:e(S.storeName).getSelectedStep()})),[]),a=null!==(e=t.args)&&void 0!==e&&e.roles?t.args.roles:[],o=Tt.filter((e=>a.includes(e.id)));return(0,C.jsxs)(Ie.Z,{opened:!0,children:[(0,C.jsx)(nt,{title:(0,b.__)("Trigger settings","mailpoet")}),(0,C.jsx)(Ct,{label:(0,b.__)("When WordPress user role is:","mailpoet"),value:o,suggestions:Tt,placeholder:(0,b.__)("Any user role","mailpoet"),onChange:e=>{(0,j.dispatch)(S.storeName).updateStepArgs(t.id,"roles",e.map((e=>e.id)))}})]})}function Ft(){return(0,C.jsx)(Et,{})}const Wt={key:"mailpoet:wp-user-registered",group:"triggers",title:(0,b.__)("WordPress user registers","mailpoet"),foreground:"#2271b1",background:"#f0f6fc",description:(0,b.__)("Starts the automation when a new user registered in WordPress.","mailpoet"),subtitle:()=>(0,b._x)("Trigger","noun","mailpoet"),icon:()=>(0,C.jsx)("div",{style:{width:"100%",height:"100%",scale:"1.12"},children:u}),edit:()=>(0,C.jsx)(Ft,{})};var Lt=a(53397),Mt=a(34206),Pt=a(3386),Vt=a(62355);function Rt(e){let{onClose:t}=e;const[a,o]=(0,r.useState)(!1),{activate:s}=(0,f.Z)(S.storeName);return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)("div",{className:"mailpoet-automation-activate-panel__header",children:[(0,C.jsx)("div",{className:"mailpoet-automation-activate-panel__header-activate-button",children:(0,C.jsxs)(n.Z,{variant:"primary",disabled:a,isBusy:a,autoFocus:!a,onClick:()=>{o(!0),s()},children:[a&&(0,b.__)("Activating…","mailpoet"),!a&&(0,b.__)("Activate","mailpoet")]})}),(0,C.jsx)("div",{className:"mailpoet-automation-activate-panel__header-cancel-button",children:(0,C.jsx)(n.Z,{variant:"secondary",onClick:t,disabled:a,children:(0,b.__)("Cancel","mailpoet")})})]}),a&&(0,C.jsx)("div",{className:"mailpoet-automation-activate-panel__body",children:(0,C.jsx)(Pt.ZP,{})}),!a&&(0,C.jsxs)("div",{className:"mailpoet-automation-activate-panel__body",children:[(0,C.jsx)("p",{children:(0,C.jsx)("strong",{children:(0,b.__)("Are you ready to activate?","mailpoet")})}),(0,C.jsx)("p",{children:(0,b.__)("Double-check your settings before activating.","mailpoet")})]})]})}function Ot(e){let{onClose:t}=e;const{workflow:a}=(0,m.Z)((e=>({workflow:e(S.storeName).getWorkflowData()})),[]);return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"mailpoet-automation-activate-panel__header",children:(0,C.jsx)(n.Z,{icon:Vt.Z,onClick:t,label:(0,b.__)("Close","mailpoet")})}),(0,C.jsxs)("div",{className:"mailpoet-automation-activate-panel__body",children:[(0,C.jsx)("div",{className:"mailpoet-automation-activate-panel__section",children:(0,b.sprintf)((0,b.__)('"%s" is now live.',"mailpoet"),a.name)}),(0,C.jsx)("p",{children:(0,C.jsx)("strong",{children:(0,b.__)("What’s next?","mailpoet")})}),(0,C.jsx)("p",{children:(0,b.__)("View all your automations to track statistics and create new ones.","mailpoet")}),(0,C.jsx)(n.Z,{variant:"secondary",onClick:()=>{window.location.href=q.x.urls.automationListing},children:(0,b.__)("View all automations","mailpoet")})]})]})}function Ht(e){let{onClose:t}=e;const{workflow:a,errors:o}=(0,m.Z)((e=>({errors:e(S.storeName).getErrors(),workflow:e(S.storeName).getWorkflowData()})),[]);if((0,r.useEffect)((()=>{o&&t()}),[o,t]),o)return null;const s=a.status===Z.x.ACTIVE;return(0,C.jsxs)("div",{className:"mailpoet-automation-activate-panel",children:[s&&(0,C.jsx)(Ot,{onClose:t}),!s&&(0,C.jsx)(Rt,{onClose:t})]})}var Kt=a(20035);function zt(){const{isFullscreenActive:e,isInserterOpened:t,isSidebarOpened:a,showIconLabels:o,workflow:i}=(0,m.Z)((e=>({isFullscreenActive:e(S.storeName).isFeatureActive("fullscreenMode"),isInserterOpened:e(S.storeName).isInserterSidebarOpened(),isSidebarOpened:e(S.storeName).isSidebarOpened(),showIconLabels:e(S.storeName).isFeatureActive("showIconLabels"),workflow:e(S.storeName).getWorkflowData()})),[]),[p,x]=(0,r.useState)(!1),v=s()("interface-interface-skeleton",{"is-sidebar-opened":a,"show-icon-labels":o});if("trash"===i.status)return window.location.href=(0,g.f)(q.x.urls.automationListing,{[Lt.E.workflowHadBeenDeleted]:i.id}),null;const f=()=>{x(!p)};return(0,C.jsx)(_.vn,{children:(0,C.jsxs)(l.zt,{children:[(0,C.jsx)(h.x4,{isActive:e}),(0,C.jsx)(Ne,{}),(0,C.jsx)(Ve,{}),(0,C.jsx)(h.v4,{className:v,drawer:e&&(0,C.jsx)("div",{className:"edit-site-navigation-toggle",children:(0,C.jsx)(n.Z,{className:"edit-site-navigation-toggle__button has-icon",href:"admin.php?page=mailpoet-automation",children:(0,C.jsx)(c.Z,{size:36,icon:u})})}),header:(0,C.jsx)(re,{showInserterToggle:!1,toggleActivatePanel:f}),content:(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(Ze,{}),(0,C.jsx)(ot,{})]}),sidebar:(0,C.jsx)(h.Vi.Slot,{scope:S.storeName}),secondarySidebar:null}),p&&(0,C.jsx)(Ht,{onClose:f}),(0,C.jsx)(d.Z.Slot,{})]})})}window.addEventListener("DOMContentLoaded",(()=>{(0,S.createStore)();const e=document.getElementById("mailpoet_automation_editor");e&&((0,Kt.P)(),Mt.default.use((async(e,t)=>{try{return await t(e)}catch(e){var a;const t=e,o=null===(a=t.data)||void 0===a?void 0:a.status;if("mailpoet_automation_workflow_not_valid"===t.code)return void(0,j.dispatch)(S.storeName).setErrors({steps:t.data.errors});if(o&&o>=400&&o<500){const e=t.message;return void(0,j.dispatch)(Se.h).createErrorNotice(e??(0,b.__)("An unknown error occurred.","mailpoet"),{explicitDismiss:!0})}throw(0,j.dispatch)(Se.h).createErrorNotice((0,b.__)("An unknown error occurred.","mailpoet"),{explicitDismiss:!0}),e}})),(0,st.qN)(),(0,S.registerStepType)(mt),(0,S.registerStepType)(kt),(0,S.registerStepType)(Wt),(0,S.registerStepType)(It),i.render((0,C.jsx)(zt,{}),e))}))},65311:function(e){e.exports=jQuery}},function(e){e.O(0,[351],(function(){return 86272,e(e.s=86272)})),e.O()}]);