var k=Object.defineProperty,F=Object.defineProperties;var S=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var m=(e,r,i)=>r in e?k(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,c=(e,r)=>{for(var i in r||(r={}))q.call(r,i)&&m(e,i,r[i]);if(y)for(var i of y(r))w.call(r,i)&&m(e,i,r[i]);return e},h=(e,r)=>F(e,S(r));import{_ as t,b as f}from"./main.2.9.0.js";const I=[{key:"given_name",label:t("First Name","bit-integrations"),required:!0},{key:"middle_name",label:t("Middle Name","bit-integrations"),required:!1},{key:"family_name",label:t("Last Name","bit-integrations"),required:!1},{key:"job_title",label:t("Job Title","bit-integrations"),required:!1},{key:"email_addresses",label:t("Email Addresses","bit-integrations"),required:!0},{key:"phone_numbers",label:t("Phone Numbers","bit-integrations"),required:!1},{key:"billing_country_code",label:t("Billing Country Code","bit-integrations"),required:!1},{key:"billing_locality",label:t("Billing Country","bit-integrations"),required:!1},{key:"billing_first_address_street",label:t("Billing Address Street (Line 1)","bit-integrations"),required:!1},{key:"billing_second_address_street",label:t("Billing Address Street (Line 2)","bit-integrations"),required:!1},{key:"billing_zip_code",label:t("Billing Zip Code","bit-integrations"),required:!1},{key:"shipping_country_code",label:t("Shipping Country Code","bit-integrations"),required:!1},{key:"shipping_locality",label:t("Shipping Country","bit-integrations"),required:!1},{key:"shipping_first_address_street",label:t("Shipping Address Street (Line 1)","bit-integrations"),required:!1},{key:"shipping_second_address_street",label:t("Shipping Address Street (Line 2)","bit-integrations"),required:!1},{key:"shipping_zip_code",label:t("Shipping Zip Code","bit-integrations"),required:!1},{key:"anniversary",label:t("Anniversary","bit-integrations"),required:!1},{key:"birthday",label:t("Birthday","bit-integrations"),required:!1},{key:"fax_numbers",label:t("Fax Numbers","bit-integrations"),required:!1}],z=(e,r,i,a,n,o,d,l,s)=>{let g=c({},r);g[e.target.name]=e.target.value,i(c({},g))},N=(e,r,i,a,n,o,d)=>{if(!e.clientId||!e.clientSecret){i({clientId:e.clientId?"":t("Client Id can't be empty","bit-integrations"),clientSecret:e.clientSecret?"":t("Secret key can't be empty","bit-integrations")});return}n(!0);const l=`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(`${d.api}/redirect`)}&client_id=${e.clientId}`,s=window.open(l,"keap","width=400,height=609,toolbar=off"),g=setInterval(()=>{if(s.closed){clearInterval(g);let u={},p=!1;const _=localStorage.getItem("__keap");if(_&&(p=!0,u=JSON.parse(_),localStorage.removeItem("__keap")),!u.code||u.error||!u||!p){const b=u.error?`Cause: ${u.error}`:"";o({show:!0,msg:`${t("Authorization failed","bit-integrations")} ${b}. ${t("please try again","bit-integrations")}`}),n(!1)}else{const b=c({},e);b.accountServer=u["accounts-server"],C(u,b,r,a,n,o,d)}}},500)},C=(e,r,i,a,n,o,d)=>{const l=c({},e);l.clientId=r.clientId,l.clientSecret=r.clientSecret,l.redirectURI=`${d.api}/redirect`,f(l,"keap_generate_token").then(s=>s).then(s=>{if(s&&s.success){const g=c({},r);g.tokenDetails=s.data,i(g),a(!0),o({show:!0,msg:t("Authorized Successfully","bit-integrations")})}else s&&s.data&&s.data.data||!s.success&&typeof s.data=="string"?o({show:!0,msg:`${t("Authorization failed Cause:","bit-integrations")}${s.data.data||s.data}. ${t("please try again","bit-integrations")}`}):o({show:!0,msg:t("Authorization failed. please try again","bit-integrations")});n(!1)})},R=e=>!((e.field_map?e.field_map.filter(i=>!i.formField&&!i.keapField):[]).length>0),A=e=>{const i=[...e==null?void 0:e.contactFields,...e==null?void 0:e.customFields].filter(a=>a.required===!0);return i.length>0?i.map(a=>({formField:"",keapField:a.key})):[{formField:"",keapField:""}]},B=(e,r,i)=>{i(h(c({},i),{tags:!0}));const a={clientId:e.clientId,clientSecret:e.clientSecret,tokenDetails:e.tokenDetails};f(a,"keap_fetch_all_tags").then(n=>{if(n&&n.success){const o=c({},e);n.data&&(o.tags=n.data),r(o),i(!1),setSnackbar({show:!0,msg:t("Tag Fetched Successfully","bit-integrations")});return}i(h(c({},i),{tags:!1})),setSnackbar({show:!0,msg:t("Tag Couldn't Fetched Successfully","bit-integrations")})})},D=(e,r,i,a,n)=>{a(!0);const o={id:e,clientId:r.clientId,clientSecret:r.clientSecret,tokenDetails:r.tokenDetails};f(o,"keap_fetch_all_custom_fields").then(d=>{if(d&&d.success){const l=c({},r);d.data&&(l.contactFields=I,l.customFields=d.data),l.field_map=A(l),i(l),a(!1),n({show:!0,msg:t("Custom Field Fetched Successfully","bit-integrations")});return}a(!1),n({show:!0,msg:t("Custom Field Couldn't Fetched Successfully","bit-integrations")})})};export{N as a,R as b,I as c,B as g,z as h,D as r};
