"use strict";(self.webpackChunkMailPoet3=self.webpackChunkMailPoet3||[]).push([[916],{66609:function(e,n,t){var o=t(52524),i=t.n(o),a=t(45993);const r=window.mailpoet_automation_api,d=`${r.root}/mailpoet/v1/automation`,s=(e,n)=>{const[t,o]=(0,a.useState)({data:void 0,loading:!1,error:void 0});return[(0,a.useCallback)((async t=>{var i;o((e=>({...e,loading:!0})));const a=await((e,n)=>fetch(`${d}/${e}`,n))(e,{...n,...t,headers:{"content-type":"application/json",...null!==(i=null==t?void 0:t.headers)&&void 0!==i?i:{},"x-wp-nonce":r.nonce}});try{const e=await a.json(),n=a.ok?null:{...a,data:e};o((t=>({...t,data:e,error:n})))}catch(e){const n={response:a};o((e=>({...e,error:n})))}finally{o((e=>({...e,loading:!1})))}}),[n,e]),t]},l=e=>e.toString(16).padStart(2,"0"),c=()=>{if(!window.crypto||!window.crypto.getRandomValues)throw new Error("Web Crypto API 'crypto.getRandomValues' is not available");return Array.from(window.crypto.getRandomValues(new Uint8Array(8))).map(l).join("")};var u=t(15451);const p=()=>{const e={id:c(),type:"action",key:"mailpoet:send-welcome-email",args:{welcomeEmailId:1}},n=(t=e.id,{id:c(),type:"action",key:"core:wait",next_step_id:t,args:{seconds:60}});var t;const o=(e=>({id:c(),type:"trigger",key:"mailpoet:segment:subscribed",next_step_id:e}))(n.id);return{name:`Test ${(new Date).toISOString()}`,steps:{[o.id]:o,[n.id]:n,[e.id]:e}}};function m(){var e,n;const[t,{loading:o,error:i}]=s("workflows",{method:"POST"});return(0,u.jsxs)("div",{children:[(0,u.jsx)("button",{type:"button",onClick:()=>t({body:JSON.stringify(p())}),disabled:o,children:"Create testing workflow"}),i&&(0,u.jsx)("div",{children:null!==(e=null==i||null===(n=i.data)||void 0===n?void 0:n.message)&&void 0!==e?e:"An unknown error occurred"})]})}function w(){const{data:e,loading:n,error:t}=((e,n)=>{const[t,o]=s("workflows",void 0);return(0,a.useEffect)((()=>{t()}),[]),o})();return!e||n?(0,u.jsx)("div",{children:"Loading workflows..."}):t?(0,u.jsxs)("div",{children:["Error: ",t]}):(0,u.jsx)("div",{children:e.data.map((e=>(0,u.jsxs)("div",{children:["[",e.id,"] ",e.name," (",e.status,")",(0,u.jsx)("a",{href:`admin.php?page=mailpoet-automation-editor&id=${e.id}`,children:"EDIT"})]},e.id)))})}function v(){var e,n;const[t,{loading:o,error:i}]=s("system/database",{method:"POST"});return(0,u.jsxs)("div",{children:[(0,u.jsx)("button",{type:"button",onClick:()=>t(),disabled:o,children:"Recreate DB schema (data will be lost)"}),i&&(0,u.jsx)("div",{children:null!==(e=null==i||null===(n=i.data)||void 0===n?void 0:n.message)&&void 0!==e?e:"An unknown error occurred"})]})}function h(){var e,n;const[t,{loading:o,error:i}]=s("system/database",{method:"DELETE"});return(0,u.jsxs)("div",{children:[(0,u.jsx)("button",{type:"button",onClick:async()=>{await t(),window.location.href="/wp-admin/admin.php?page=mailpoet-experimental"},disabled:o,children:"Delete DB schema & deactivate feature"}),i&&(0,u.jsx)("div",{children:null!==(e=null==i||null===(n=i.data)||void 0===n?void 0:n.message)&&void 0!==e?e:"An unknown error occurred"})]})}function g(){return(0,u.jsxs)("div",{children:[(0,u.jsx)(m,{}),(0,u.jsx)(v,{}),(0,u.jsx)(h,{}),(0,u.jsx)(w,{})]})}window.addEventListener("DOMContentLoaded",(()=>{const e=document.getElementById("mailpoet_automation");e&&i().render((0,u.jsx)(g,{}),e)}))}},function(e){e.O(0,[351],(function(){return 66609,e(e.s=66609)})),e.O()}]);