import{aa as h,ab as l}from"./_applist-tangy-colts-beg-36.js";import{aR as r,_ as d}from"./main-tangy-colts-beg.js";import{s as C}from"./machine.-tangy-colts-beg-869.js";import{h as s,a as m,c as u}from"./linecomm-tangy-colts-beg-705.js";import"./lodash-tangy-colts-beg-516.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(o,e){return this.cache.has(o)?this.cache.get(o):(this.cache.set(o,e),e)}};const _=o=>r("pro_line/set-line-webhook",o);globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(o,e){return this.cache.has(o)?this.cache.get(o):(this.cache.set(o,e),e)}};const p=async(o,e)=>{var c;const t=await o.getConnection();if(!t||!((c=t.auth_details)!=null&&c.token))return;const{data:n}=await _({endpoint:e,token:t.auth_details.token});let i="We have attached the webhook to your Line Developer Console.";(!n||Object.keys(n).length!==0)&&(i=n.message),o.setComponent("note-id",a=>{o.util.isNoteComponent(a)&&(a.note=[i],a.render=!0)})};globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(o,e){return this.cache.has(o)?this.cache.get(o):(this.cache.set(o,e),e)}};const A=h(({helpers:o})=>({states:{components:[{componentName:o.componentName.webhook,extraComponents:[u(o)],fieldType:"config",id:"webhook-id",label:d("Webhook"),onSave:"CLEAR_WEBHOOK_FORM_VALUES",onValidate:"HANDLE_VALIDATION",onWebhookChange:"SET_WEBHOOK",render:!0,value:void 0},{componentName:o.componentName.note,fieldType:"config",id:"note-id",note:[],render:!1}]},actions:{CONNECTION_ADD_CHANGE:m,IF_CONNECTION_SELECTED:({$:e})=>{var t;return l((t=e.getComponent("connection-id"))==null?void 0:t.value)},SET_CONNECTION:s("connectionId"),SET_WEBHOOK:({$:e,e:t})=>{s("webhookId")({$:e,e:t.id})},HANDLE_VALIDATION:({$:e})=>{var t;if(!((t=e.getComponent("connection-id"))!=null&&t.value))return e.setComponent("connection-id",n=>{e.util.isConnectionComponent(n)&&(n.status="error",n.invalidMessage="Please select a connection")}),!1},CLEAR_WEBHOOK_FORM_VALUES:async({$:e,e:t})=>{await p(e,t.url),e.setComponent("connection-id",n=>{e.util.isConnectionComponent(n)&&(n.value=void 0)})},ON_MACHINE_LOAD:async({$:e})=>{C(e,[{db:"webhookId",id:"webhook-id"}])}}}));export{A as default};
