import{aa as u,ab as d}from"./_applist-tangy-colts-beg-36.js";import{da as p,_ as n}from"./main-tangy-colts-beg.js";import{s as C}from"./machine.-tangy-colts-beg-869.js";import{h as c,a as m,c as _}from"./telegram-tangy-colts-beg-669.js";import"./lodash-tangy-colts-beg-516.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(a,e){return this.cache.has(a)?this.cache.get(a):(this.cache.set(a,e),e)}};const b=(a,e,t)=>{const o={allowed_updates:JSON.stringify(t),url:e};return p({bodyParams:o,headers:{"Content-Type":"application/json"},method:"POST",url:`https://api.telegram.org/bot${a}/setWebhook`})};globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(a,e){return this.cache.has(a)?this.cache.get(a):(this.cache.set(a,e),e)}};const E=async(a,e)=>{var i,h,r;const t=await a.getConnection();if(!t||!((i=t.auth_details)!=null&&i.value))return;const o=(h=a.db)!=null&&h.selectedEvents.includes("all_updates")?[""]:(r=a.db)==null?void 0:r.selectedEvents,{data:l}=await b(t.auth_details.value,e,o);a.setComponent("note-id",s=>{a.util.isNoteComponent(s)&&(s.note=[l==null?void 0:l.description],s.render=!0)})};globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(a,e){return this.cache.has(a)?this.cache.get(a):(this.cache.set(a,e),e)}};const g=(a,e)=>{let t;switch(e){case"allUpdates":{t="all_updates";break}case"watchCallbackQuery":{t="callback_query";break}case"watchChannelPost":{t="channel_post";break}case"watchEditedChannelPost":{t="edited_channel_post";break}case"watchEditedMessage":{t="edited_message";break}case"watchInlineQuery":{t="inline_query";break}case"watchMessage":{t="message";break}case"watchPoll":{t="poll";break}case"watchPreCheckoutQuery":{t="pre_checkout_query";break}case"watchShippingQuery":{t="shipping_query";break}default:{t="all_updates";break}}a.setComponent("select-event",o=>{o.value=t}),a.setDb(o=>{o.selectedEvents=[t]})};globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(a,e){return this.cache.has(a)?this.cache.get(a):(this.cache.set(a,e),e)}};const y=u(({helpers:a})=>({states:{components:[{componentName:a.componentName.webhook,extraComponents:[_(a),{componentName:a.componentName.select,id:"select-event",label:n("Select Event"),mode:"multiple",onChange:"HANDLE_SELECTED_EVENT",options:[{label:n("All Updates"),value:"all_updates"},{label:n("Watch Callback Query"),value:"callback_query"},{label:n("Watch Channel Post"),value:"channel_post"},{label:n("Watch Edited Channel Post"),value:"edited_channel_post"},{label:n("Watch Edited Message"),value:"edited_message"},{label:n("Watch Inline Query"),value:"inline_query"},{label:n("Watch Message"),value:"message"},{label:n("Watch Poll"),value:"poll"},{label:n("Watch Pre-Checkout Query"),value:"pre_checkout_query"},{label:n("Watch Shipping Query"),value:"shipping_query"}],render:"IF_CONNECTION_SELECTED",showSearch:!1,value:void 0},{componentName:a.componentName.note,id:"all-update-note",note:[n('Select the events you want to trigger.To trigger all together, select only "All Updates" from the dropdown.')],render:"IF_CONNECTION_SELECTED"}],fieldType:"config",id:"webhook-id",label:n("Webhook"),onSave:"CLEAR_WEBHOOK_FORM_VALUES",onValidate:"HANDLE_VALIDATION",onWebhookChange:"SET_WEBHOOK",render:!0,value:void 0},{componentName:a.componentName.note,fieldType:"config",id:"note-id",note:[],render:!1}]},actions:{CONNECTION_ADD_CHANGE:m,HANDLE_SELECTED_EVENT:c("selectedEvents"),IF_CONNECTION_SELECTED:({$:e})=>{var t;return d((t=e.getComponent("connection-id"))==null?void 0:t.value)},SET_WEBHOOK:async({$:e,e:t})=>{c("webhookId")({$:e,e:t.id})},SET_CONNECTION:({$:e,e:t})=>{c("connectionId")({$:e,e:t})},HANDLE_VALIDATION:({$:e})=>{var t,o;if(!((t=e.getComponent("connection-id"))!=null&&t.value))return e.setComponent("connection-id",l=>{e.util.isConnectionComponent(l)&&(l.status="error",l.invalidMessage="Please select a connection")}),!1;if(((o=e.getComponent("select-event"))==null?void 0:o.value.length)===0)return e.setComponent("select-event",l=>{e.util.isSelectComponent(l)&&(l.status="error",l.invalidMessage="Please select Events")}),!1},CLEAR_WEBHOOK_FORM_VALUES:async({$:e,e:t})=>{await E(e,t.url),e.setComponent("connection-id",o=>{e.util.isConnectionComponent(o)&&(o.value=void 0)}),e.setComponent("select-event",o=>{e.util.isSelectComponent(o)&&(o.value=void 0)})},ON_MACHINE_LOAD:async({$:e})=>{C(e,[{db:"webhookId",id:"webhook-id"}]);const t=e.thisNode.machineSlug;g(e,t)}}}));export{y as default};
