import{aa as r,ab as C}from"./_applist-tangy-colts-beg-36.js";import{_ as a}from"./main-tangy-colts-beg.js";import{h as l}from"./machine.-tangy-colts-beg-869.js";import{h as u,c as p}from"./commons.-tangy-colts-beg-737.js";import{h as d}from"./machineh-tangy-colts-beg-921.js";import"./lodash-tangy-colts-beg-516.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(i,e){return this.cache.has(i)?this.cache.get(i):(this.cache.set(i,e),e)}};const f=r(({helpers:i})=>({states:{components:[{componentName:i.componentName.webhook,extraComponents:[p(i),{componentName:i.componentName.input,id:"webhook-name",label:a("Webhook Name"),onChange:"HANDLE_WEBHOOK_NAME",render:"IF_CONNECTION_SELECTED",required:!0,value:void 0},{componentName:i.componentName.input,id:"description",label:a("Description"),onChange:"HANDLE_DESCRIPTION",render:"IF_CONNECTION_SELECTED",required:!0,value:[]},{componentName:i.componentName.select,helperText:a("Select Klaviyo topics to attach to this webhook."),id:"select-webhook-event",label:a("Select Topics"),mode:"multiple",onChange:"HANDLE_SELECTED_TOPICS",options:[{label:a("Email Opened"),value:"event:klaviyo.opened_email"},{label:a("SMS Sent"),value:"event:klaviyo.sent_sms"},{label:a("SMS Received"),value:"event:klaviyo.received_sms"}],render:"IF_CONNECTION_SELECTED",value:void 0}],fieldType:"config",id:"webhook-id",label:a("Webhook"),onSave:"CLEAR_WEBHOOK_FORM_VALUES",onValidate:"HANDLE_VALIDATION",onWebhookChange:"SET_WEBHOOK",render:!0,value:void 0},{componentName:i.componentName.note,fieldType:"config",id:"note-id",note:[],render:!1}]},actions:{CONNECTION_ADD_CHANGE:u,HANDLE_DESCRIPTION:({$:e,e:n})=>l("description")({$:e,e:n.target.value}),HANDLE_SELECTED_TOPICS:l("selectedTopics"),HANDLE_WEBHOOK_NAME:({$:e,e:n})=>l("webhookName")({$:e,e:n.target.value}),IF_CONNECTION_SELECTED:({$:e})=>{var n;return C((n=e.getComponent("connection-id"))==null?void 0:n.value)},SET_CONNECTION:l("connectionId"),SET_WEBHOOK:({$:e,e:n})=>l("webhookId")({$:e,e:n.id}),HANDLE_VALIDATION:({$:e})=>{var n,o,s,c,m;if(!((n=e.getComponent("connection-id"))!=null&&n.value))return e.setComponent("connection-id",t=>{e.util.isConnectionComponent(t)&&(t.status="error",t.invalidMessage="Please select a connection")}),!1;if(((o=e.getComponent("webhook-name"))==null?void 0:o.value)===void 0)return e.setComponent("webhook-name",t=>{e.util.isInputComponent(t)}),!1;if(((s=e.getComponent("description"))==null?void 0:s.value)===void 0)return e.setComponent("description",t=>{e.util.isInputComponent(t)}),!1;if(!((c=e.getComponent("select-webhook-event"))!=null&&c.value)||((m=e.getComponent("select-webhook-event"))==null?void 0:m.value.length)===0)return e.setComponent("select-webhook-event",t=>{e.util.isSelectComponent(t)&&(t.status="error",t.invalidMessage="Please select at least one topic")}),!1},CLEAR_WEBHOOK_FORM_VALUES:async({$:e,e:n})=>{await d(e,n.url),e.setComponent("connection-id",o=>{e.util.isConnectionComponent(o)&&(o.value=void 0)}),e.setComponent("webhook-name",o=>{e.util.isInputComponent(o)&&(o.value=void 0)}),e.setComponent("description",o=>{e.util.isInputComponent(o)&&(o.value=void 0)}),e.setComponent("select-webhook-event",o=>{e.util.isSelectComponent(o)&&(o.value=void 0)})}}}));export{f as default};
