var m=Object.defineProperty,q=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var p=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;var y=(e,t,r)=>t in e?m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,d=(e,t)=>{for(var r in t||(t={}))p.call(t,r)&&y(e,r,t[r]);if(I)for(var r of I(t))n.call(t,r)&&y(e,r,t[r]);return e},o=(e,t)=>q(e,F(t));import{u as k}from"./Note.NSUdvR3c.js";import{z as c,_ as s,b as h}from"./main.2.9.0.js";const f=["create_datasource","create_or_update_contact","delete_contact","create_contact_event"],A=["create_or_update_contact","delete_contact","create_contact_event"],P=["create_or_update_contact","create_contact_event"],T="__custom_field__",v={send_sms:[{key:"from",label:"From",required:!0},{key:"to",label:"To",required:!0},{key:"text",label:"Text",required:!0},{key:"clientId",label:"Client Id",required:!1}],create_lookup:[{key:"to",label:"To",required:!0}],create_datasource:[{key:"name",label:"Name",required:!0},{key:"description",label:"Description",required:!1},{key:"defaultCountry",label:"Default Country",required:!1},{key:"locale",label:"Locale",required:!1},{key:"timezone",label:"Timezone",required:!1}],create_or_update_contact:[{key:"userId",label:"User Id",required:!0},{key:"firstName",label:"First Name",required:!1},{key:"lastName",label:"Last Name",required:!1},{key:"email",label:"Email",required:!1},{key:"phoneMobile",label:"Phone Mobile",required:!1}],delete_contact:[{key:"userId",label:"User Id",required:!0}],create_contact_event:[{key:"userId",label:"User Id",required:!0},{key:"eventId",label:"Event Id",required:!0},{key:"eventType",label:"Event Type",required:!0}]},O=(e,t,r,u,i)=>{const{name:a,value:l}=e.target,_=k(t,b=>{b[a]=l,a==="projectId"&&(b.datasourceId="",b.default&&(b.default.datasources=[]))});r(_),a==="action"&&l!==""&&S(_,r,u,i)},D=e=>{const t=e==null?void 0:e.instasentFields.filter(r=>r.required===!0);return t.length>0?t.map(r=>({formField:"",instasentFormField:r.key})):[{formField:"",instasentFormField:""}]},g=e=>!(f.includes(e==null?void 0:e.action)&&!(e!=null&&e.projectId)||A.includes(e==null?void 0:e.action)&&!(e!=null&&e.datasourceId)||(e!=null&&e.field_map?e.field_map.filter(r=>!r.formField||!r.instasentFormField||r.instasentFormField===T||r.formField==="custom"&&!r.customValue):[]).length>0),j=(e,t,r,u)=>{if(!e.auth_token){c.error(s("API Token can't be empty","bit-integrations"));return}u(o(d({},r),{auth:!0}));const i={auth_token:e.auth_token};h(i,"instasent_authorize").then(a=>{if(u(o(d({},r),{auth:!1})),a&&a.success){t(!0),c.success(s("Authorized Successfully","bit-integrations"));return}c.error(s("Authorized failed","bit-integrations"))})},S=(e,t,r,u)=>{u(o(d({},r),{field:!0}));const i=v[e==null?void 0:e.action]||[];t(a=>k(a,l=>{l.instasentFields=i,l.field_map=D(l)})),u(o(d({},r),{field:!1})),c.success(s("Fields refresh successfully","bit-integrations"))},M=(e,t,r,u)=>{if(!e.auth_token){c.error(s("API Token can't be empty","bit-integrations"));return}if(!e.projectId){c.error(s("Please enter a Project Id first","bit-integrations"));return}u(o(d({},r),{datasource:!0}));const i={auth_token:e.auth_token,projectId:e.projectId};h(i,"refresh_instasent_datasources").then(a=>{if(u(o(d({},r),{datasource:!1})),a&&a.success){t(l=>k(l,_=>{_.default=_.default||{},_.default.datasources=a.data||[]})),c.success(s("Data sources fetched successfully","bit-integrations"));return}c.error(s("Data sources fetch failed","bit-integrations"))})};export{P as A,T as C,v as I,f as a,A as b,g as c,j as d,O as h,S as i,M as r};
