var S=Object.defineProperty,I=Object.defineProperties;var b=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var w=(e,i,t)=>i in e?S(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t,d=(e,i)=>{for(var t in i||(i={}))y.call(i,t)&&w(e,t,i[t]);if(_)for(var t of _(i))$.call(i,t)&&w(e,t,i[t]);return e},f=(e,i)=>I(e,b(i));import{_ as l,d as p}from"./main.2.8.1.js";const z=(e,i,t,a,r,n,o,c,s)=>{let h=d({},i);h[e.target.name]=e.target.value,t(d({},h))},A=(e,i,t,a,r,n,o)=>{if(!e.clientId||!e.clientSecret){t({clientId:e.clientId?"":l("Client Id can't be empty","bit-integrations"),clientSecret:e.clientSecret?"":l("Secret key can't be empty","bit-integrations")});return}r(!0);const c=`https://accounts.infusionsoft.com/app/oauth/authorize?scope=full&access_type=offline&prompt=consent&response_type=code&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(`${o.api}/redirect`)}&client_id=${e.clientId}`,s=window.open(c,"keap","width=400,height=609,toolbar=off"),h=setInterval(()=>{if(s.closed){clearInterval(h);let u={},m=!1;const F=localStorage.getItem("__keap");if(F&&(m=!0,u=JSON.parse(F),localStorage.removeItem("__keap")),!u.code||u.error||!u||!m){const g=u.error?`Cause: ${u.error}`:"";n({show:!0,msg:`${l("Authorization failed","bit-integrations")} ${g}. ${l("please try again","bit-integrations")}`}),r(!1)}else{const g=d({},e);g.accountServer=u["accounts-server"],k(u,g,i,a,r,n,o)}}},500)},k=(e,i,t,a,r,n,o)=>{const c=d({},e);c.clientId=i.clientId,c.clientSecret=i.clientSecret,c.redirectURI=`${o.api}/redirect`,p(c,"keap_generate_token").then(s=>s).then(s=>{if(s&&s.success){const h=d({},i);h.tokenDetails=s.data,t(h),a(!0),n({show:!0,msg:l("Authorized Successfully","bit-integrations")})}else s&&s.data&&s.data.data||!s.success&&typeof s.data=="string"?n({show:!0,msg:`${l("Authorization failed Cause:","bit-integrations")}${s.data.data||s.data}. ${l("please try again","bit-integrations")}`}):n({show:!0,msg:l("Authorization failed. please try again","bit-integrations")});r(!1)})},D=e=>!((e.field_map?e.field_map.filter(t=>!t.formField&&!t.keapField):[]).length>0),C=e=>{const t=[...e==null?void 0:e.contactFields,...e==null?void 0:e.customFields].filter(a=>a.required===!0);return t.length>0?t.map(a=>({formField:"",keapField:a.key})):[{formField:"",keapField:""}]},q=(e,i,t)=>{t(f(d({},t),{tags:!0}));const a={clientId:e.clientId,clientSecret:e.clientSecret,tokenDetails:e.tokenDetails};p(a,"keap_fetch_all_tags").then(r=>{if(r&&r.success){const n=d({},e);r.data&&(n.tags=r.data),i(n),t(!1),setSnackbar({show:!0,msg:l("Tag Fetched Successfully","bit-integrations")});return}t(f(d({},t),{tags:!1})),setSnackbar({show:!0,msg:l("Tag Couldn't Fetched Successfully","bit-integrations")})})},U=(e,i,t,a,r)=>{a(!0);const n={id:e,clientId:i.clientId,clientSecret:i.clientSecret,tokenDetails:i.tokenDetails};p(n,"keap_fetch_all_custom_fields").then(o=>{if(o&&o.success){const c=d({},i);o.data&&(c.customFields=o.data,c.field_map=C(c)),t(c),a(!1),r({show:!0,msg:l("Custom Field Fetched Successfully","bit-integrations")});return}a(!1),r({show:!0,msg:l("Custom Field Couldn't Fetched Successfully","bit-integrations")})})};export{C as a,A as b,D as c,q as g,z as h,U as r};
