import{aa as r,ab as c}from"./_applist-tangy-colts-beg-36.js";import{da as m,_ as o}from"./main-tangy-colts-beg.js";import{s as d}from"./machine.-tangy-colts-beg-869.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 p="https://api.lemlist.com/api",u=async a=>m({headers:{Authorization:["Basic ",{encryption:"base64_encode",value:[":",{encryption:"hmac_decrypt",value:a}]}],"Content-Type":"application/json"},method:"GET",url:`${p}/campaigns`});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 l=async a=>{a.setComponent("campaigns-list-id",n=>{n.loading=!0});const e=await a.getConnection();if(!e)return;const{data:t,status:i}=await u(e.auth_details.password);if(i!=="success"){a.setComponent("campaigns-list-id",n=>{a.util.isSelectComponent(n)&&(n.loading=!1,n.status=i,n.invalidMessage=t)}),console.error("Failed to fetch list");return}if(!Array.isArray(t)){a.setComponent("campaigns-list-id",n=>{a.util.isSelectComponent(n)&&(n.loading=!1,n.status="error",n.invalidMessage=o("Campaigns list not found."))}),console.error("Failed to fetch campaigns list");return}a.setComponent("campaigns-list-id",n=>{a.util.isSelectComponent(n)&&(n.options=t==null?void 0:t.map(s=>({label:s.name,value:s._id})),n.invalidMessage=void 0,n.status=void 0,n.loading=!1)})};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 _=r(({helpers:a})=>({states:{components:[{addConnectionHelpingText:o('You can find credentials from <a target="_blank" class="text-blue-600 underline" rel="noopener noreferrer nofollow" href="https://api.lemlist.com/teams/tea_beEpCu2irsJfn3PJr/settings/integrations#api">Here</a>'),componentName:a.componentName.connection,connectionsTypes:[{encryptKeys:["password"],label:o("Basic auth"),showUsername:!1,type:"basic_auth",verifyConnection:{headers:{Authorization:"","Content-Type":"application/json"},method:"GET",responseKeyMatch:["userIds","name"],url:"https://api.lemlist.com/api/team"}}],fieldType:"config",id:"connection-id",label:o("Select Connection"),onConnectionAddChange:"CONNECTION_ADD_CHANGE",onConnectionChange:"SET_CONNECTION",render:!0,value:void 0},{componentName:a.componentName.select,fieldType:"config",id:"campaigns-list-id",label:o("Campaigns list"),onChange:"SELECT_LIST",onRefetch:"REFETCH_CAMPAIGN_LIST",optionFilterProp:"label",options:[],placeholder:o("Select a list"),render:"IF_CONNECTION_SELECTED",showSearch:!0,value:void 0},{addItemButtonLabel:o("Add Contact Field"),componentName:a.componentName.repeaterField,fieldsMetaData:[{componentName:a.componentName.select,label:o("Field"),name:"lemListField",options:[{label:o("Email"),value:"email"},{label:o("First Name"),value:"firstName"},{label:o("Last Name"),value:"lastName"},{label:o("Company Name"),value:"companyName"},{label:o("Phone number"),value:"phone"},{label:o("Job Title"),value:"jobTitle"},{label:o("Linkedin Url"),value:"linkedinUrl"},{label:o("Ice Breaker"),value:"icebreaker"}],required:!0,style:{width:150},value:""},{componentName:a.componentName.mixInput,label:o("Value"),name:"value",required:!0,value:[],wrapperClassName:"w-100"}],id:"contact-row",label:o("Field Mapping"),onChange:"ON_FIELD_MAP_CHANGE",render:"IF_LIST_SELECTED",value:void 0}]},actions:{SET_CONNECTION:async({$:e,e:t})=>{e.setThisComponent(i=>{i.value=t}),e.setDb(i=>{i.connectionId=t}),await l(e)},IF_CONNECTION_SELECTED:({$:e})=>{var t;return c((t=e.getComponent("connection-id"))==null?void 0:t.value)},IF_LIST_SELECTED:({$:e})=>{var t;return c((t=e.getComponent("campaigns-list-id"))==null?void 0:t.value)},REFETCH_CAMPAIGN_LIST:async({$:e})=>{await l(e)},SELECT_LIST:async({$:e,e:t})=>{e.setThisComponent(i=>{i.value=t}),e.setDb(i=>{i.campaignsListId=t})},CONNECTION_ADD_CHANGE:({$:e,e:t})=>{e.setThisComponent(i=>{e.util.isConnectionComponent(i)&&i.connectionsTypes.forEach(n=>{var s;n.type==="basic_auth"&&((s=n.verifyConnection)!=null&&s.headers)&&t.password&&(n.verifyConnection.headers.Authorization="Basic "+btoa(`:${t.password}`))})})},ON_FIELD_MAP_CHANGE:async({$:e,e:t})=>{e.setThisComponent(i=>{i.value=t}),e.setDb(i=>{i.contactRow=t})},ON_MACHINE_LOAD:async({$:e})=>{d(e,[{db:"connectionId",id:"connection-id"},{db:"campaignsListId",id:"campaigns-list-id"},{db:"contactRow",id:"contact-row"}]),await l(e)}}}));export{_ as default};
