import{aa as d,ab as r}from"./_applist-tangy-colts-beg-36.js";import{da as p,_ as a}from"./main-tangy-colts-beg.js";import{s as m}from"./machine.-tangy-colts-beg-869.js";import"./lodash-tangy-colts-beg-516.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,e){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,e),e)}};const C="https://api.encharge.io/v1",u=async t=>p({headers:{Accept:"application/json","X-Encharge-Token":{encryption:"hmac_decrypt",value:t}},method:"GET",url:`${C}/fields`}),g=async t=>p({headers:{Accept:"application/json","X-Encharge-Token":{encryption:"hmac_decrypt",value:t}},method:"GET",url:`${C}/tags-management`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,e){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,e),e)}};const h=async t=>{t.setComponent("contact-row",n=>{n.loading=!0});const e=await t.getConnection();if(!e){t.setComponent("contact-row",n=>{n.loading=!1});return}const{data:o}=await u(e.auth_details.value);t.setComponent("contact-row",n=>{var i;if(!t.util.isRepeaterFieldComponent(n))return;const c=n.fieldsMetaData[0];c.options=(i=o==null?void 0:o.items)==null?void 0:i.map(s=>({label:s.title||s.name.charAt(0).toUpperCase()+s.name.slice(1),value:s.name})),n.loading=!1})},l=async t=>{t.setComponent("tag-list",n=>{n.loading=!0});const e=await t.getConnection();if(!e){t.setComponent("tag-list",n=>{n.loading=!1});return}const{data:o}=await g(e.auth_details.value);t.setComponent("tag-list",n=>{var c;t.util.isSelectComponent(n)&&(n.options=(c=o==null?void 0:o.tags)==null?void 0:c.map(i=>({label:i.tag,value:i.tag})),n.loading=!1)})};globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,e){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,e),e)}};const f=d(({helpers:t})=>({states:{components:[{addConnectionHelpingText:a('You can find credentials from <a target="_blank" class="text-blue-600 underline" rel="noopener noreferrer nofollow" href="https://app.encharge.io/account/info">Here</a>'),componentName:t.componentName.connection,connectionsTypes:[{encryptKeys:["value"],label:a("API Key"),showKey:!1,type:"api_key",verifyConnection:{headers:{Accept:"application/json","X-Encharge-Token":""},method:"GET",responseKeyMatch:["accountId","name","site","peopleCount"],url:"https://api.encharge.io/v1/accounts/info"}}],fieldType:"config",id:"connection-id",label:a("Select Connection"),onConnectionAddChange:"CONNECTION_ADD_CHANGE",onConnectionChange:"SET_CONNECTION",render:!0,value:void 0},{componentName:t.componentName.select,fieldType:"config",helperText:a("Write and hit Enter for separate tag"),id:"tag-list",label:a("Add Tags"),mode:"tags",onChange:"SELECT_LIST",onRefetch:"REFETCH_TAGS",optionFilterProp:"label",options:[],placeholder:a("Select a list"),render:"IF_CONNECTION_SELECTED",showSearch:!0,value:void 0},{addItemButtonLabel:a("Add Contact Field"),componentName:t.componentName.repeaterField,fieldsMetaData:[{componentName:t.componentName.select,label:a("Column"),name:"enchargeField",options:[],required:!0,style:{width:150},value:""},{componentName:t.componentName.mixInput,label:a("Value"),name:"value",required:!0,value:[],wrapperClassName:"w-100"}],id:"contact-row",label:a("Field Mapping"),onChange:"ON_FIELD_MAP_CHANGE",render:"IF_CONNECTION_SELECTED",value:void 0}]},actions:{SET_CONNECTION:async({$:e,e:o})=>{e.setThisComponent(n=>{n.value=o}),e.setDb(n=>{n.connectionId=o}),await Promise.all([h(e),l(e)])},IF_CONNECTION_SELECTED:({$:e})=>{var o;return r((o=e.getComponent("connection-id"))==null?void 0:o.value)},IF_LIST_SELECTED:({$:e})=>{var o;return r((o=e.getComponent("tag-list"))==null?void 0:o.value)},SELECT_LIST:async({$:e,e:o})=>{e.setThisComponent(n=>{n.value=o}),e.setDb(n=>{n.tagList=o})},CONNECTION_ADD_CHANGE:({$:e,e:o})=>{e.setThisComponent(n=>{e.util.isConnectionComponent(n)&&n.connectionsTypes.forEach(c=>{var i;c.type==="api_key"&&((i=c.verifyConnection)!=null&&i.headers)&&(c.verifyConnection.headers["X-Encharge-Token"]=o.value)})})},REFETCH_TAGS:({$:e})=>l(e),ON_FIELD_MAP_CHANGE:async({$:e,e:o})=>{e.setThisComponent(n=>{n.value=o}),e.setDb(n=>{n.contactRow=o})},ON_MACHINE_LOAD:async({$:e})=>{m(e,[{db:"connectionId",id:"connection-id"},{db:"tagList",id:"tag-list"},{db:"contactRow",id:"contact-row"}]),await Promise.all([h(e),l(e)])}}}));export{f as default};
