import{aa as C,ab as u}from"./_applist-tangy-colts-beg-36.js";import{_ as n}from"./main-tangy-colts-beg.js";import{s as h}from"./machine.-tangy-colts-beg-869.js";import{f as c,h as s,a as m,c as r,d}from"./mailchim-tangy-colts-beg-692.js";import"./lodash-tangy-colts-beg-516.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(l,e){return this.cache.has(l)?this.cache.get(l):(this.cache.set(l,e),e)}};const A=C(({helpers:l})=>({states:{components:[{componentName:l.componentName.webhook,extraComponents:[r(l),{allowClear:!0,componentName:l.componentName.select,helperText:n("Choose the list to which you want to add a webhook."),id:"select-audience",label:n("Select Audience List"),onChange:"HANDLE_SELECT_AUDIENCE",onRefetch:"REFETCH_AUDIENCE_LIST",options:[],path:"select-audience",render:"IF_CONNECTION_SELECTED",value:void 0},{componentName:l.componentName.select,helperText:n("Select the type of Mailchimp Event that should trigger the webhook."),id:"select-webhook-event",label:n("Select Webhook Event"),mode:"multiple",onChange:"HANDLE_WEBHOOK_EVENT",options:[{label:n("SUBSCRIBE"),value:"subscribe"},{label:n("UNSUBSCRIBE"),value:"unsubscribe"},{label:n("PROFILE UPDATE"),value:"profile"},{label:n("CLEANED"),value:"cleaned"},{label:n("EMAIL_UPDATE"),value:"upemail"},{label:n("CAMPAIGN"),value:"campaign"}],render:"IF_AUDIENCE_LIST_SELECTED",value:void 0},{componentName:l.componentName.select,helperText:n("Select the Source of the event that should trigger the webhook."),id:"select-webhook-source",label:n("Select Webhook Source"),mode:"multiple",onChange:"HANDLE_WEBHOOK_SOURCE",options:[{label:n("USER"),value:"user"},{label:n("ADMIN"),value:"admin"},{label:n("API"),value:"api"}],render:"IF_AUDIENCE_LIST_SELECTED",showSearch:!1,value:void 0}],fieldType:"config",id:"webhook-id",label:n("Webhook"),onSave:"CLEAR_WEBHOOK_FORM_VALUES",onValidate:"HANDLE_VALIDATION",onWebhookChange:"SET_WEBHOOK",render:!0},{componentName:l.componentName.note,fieldType:"config",id:"note-id",note:[],render:!1}]},actions:{IF_AUDIENCE_LIST_SELECTED:({$:e})=>{var t,o;return u((t=e.getComponent("connection-id"))==null?void 0:t.value)&&((o=e.getComponent("select-audience"))==null?void 0:o.value)},SET_WEBHOOK:async({$:e,e:t})=>{s("webhookId")({$:e,e:t.id}),await c(e)},SET_CONNECTION:async({$:e,e:t})=>{s("connectionId")({$:e,e:t}),await c(e)},HANDLE_VALIDATION:({$:e})=>{var t,o,i,E;if(!((t=e.getComponent("connection-id"))!=null&&t.value))return e.setComponent("connection-id",a=>{e.util.isConnectionComponent(a)&&(a.status="error",a.invalidMessage="Please select a connection")}),!1;if(!((o=e.getComponent("select-audience"))!=null&&o.value))return e.setComponent("select-audience",a=>{e.util.isSelectComponent(a)&&(a.status="error",a.invalidMessage="Please select Audience List")}),!1;if(!((i=e.getComponent("select-webhook-event"))!=null&&i.value))return e.setComponent("select-webhook-event",a=>{e.util.isSelectComponent(a)&&(a.status="error",a.invalidMessage="Please select a Webhook Event")}),!1;if(!((E=e.getComponent("select-webhook-source"))!=null&&E.value))return e.setComponent("select-webhook-source",a=>{e.util.isSelectComponent(a)&&(a.status="error",a.invalidMessage="Please select a Webhook Source")}),!1},CLEAR_WEBHOOK_FORM_VALUES:async({$:e,e:t})=>{await d(e,t.url),e.setComponent("connection-id",o=>{e.util.isConnectionComponent(o)&&(o.value=void 0)}),e.setComponent("select-audience",o=>{e.util.isSelectComponent(o)&&(o.value=void 0)}),e.setComponent("select-webhook-event",o=>{e.util.isSelectComponent(o)&&(o.value=void 0)}),e.setComponent("select-webhook-source",o=>{e.util.isSelectComponent(o)&&(o.value=void 0)})},CONNECTION_ADD_CHANGE:m,HANDLE_SELECT_AUDIENCE:s("audienceList"),HANDLE_WEBHOOK_EVENT:s("webhookEvents"),HANDLE_WEBHOOK_SOURCE:s("webhookSources"),IF_CONNECTION_SELECTED:({$:e})=>{var t;return u((t=e.getComponent("connection-id"))==null?void 0:t.value)},REFETCH_AUDIENCE_LIST:async({$:e})=>await c(e),ON_MACHINE_LOAD:async({$:e})=>{var o;h(e,[{db:"webhookId",id:"webhook-id"}]),(o=e.db)!=null&&o.connectionId&&await c(e);const t=e.thisNode.machineSlug;e.setComponent("select-webhook-event",i=>{i.value=t}),e.setDb(i=>{i.webhookEvents=[t]})}}}));export{A as default};
