var S=Object.defineProperty,b=Object.defineProperties;var q=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var y=(e,t,i)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,o=(e,t)=>{for(var i in t||(t={}))C.call(t,i)&&y(e,i,t[i]);if(I)for(var i of I(t))R.call(t,i)&&y(e,i,t[i]);return e},f=(e,t)=>b(e,q(t));import{_ as d,d as m,z as F}from"./main.2.8.1.js";import{y as z}from"./Note.BeM7sN-p.js";const M=(e,t,i,a,r,c,n,l,h)=>{let s=o({},t);s[e.target.name]=e.target.value,e.target.name==="source_type"&&(s=A(s,i)),i(o({},s))},N=e=>!((e!=null&&e.address_field?e.address_field.filter(i=>!i.formField&&i.constantContactAddressField&&i.required):[]).length>0),A=(e,t)=>{const i=z(e);return i.field_map=[{formField:"",constantContactFormField:""}],v(e,t),i},W=(e,t,i,a,r)=>{r(f(o({},a),{list:!0}));const c={integId:e,clientId:t.clientId,clientSecret:t.clientSecret,tokenDetails:t.tokenDetails};m(c,"cContact_refresh_list").then(n=>{if(n&&n.success){const l=o({},t);n.data&&(l.lists=n.data.contactList),i(l),r(f(o({},a),{list:!1})),F.success(d("List fetch successfully","bit-integrations"));return}r(f(o({},a),{list:!1})),F.error(d("List fetch failed","bit-integrations"))})},v=(e,t)=>{const i={clientId:e.clientId,clientSecret:e.clientSecret,tokenDetails:e.tokenDetails};m(i,"cContact_custom_fields").then(a=>{if(a&&a.success){const r=o({},e);if(a.data){const c=r.default.constantContactFields.concat(a.data.customFields);r.default.constantContactFields=c}t(r)}})},J=(e,t,i,a,r)=>{r(f(o({},a),{tag:!0}));const c={integId:e,clientId:t.clientId,clientSecret:t.clientSecret,tokenDetails:t.tokenDetails};m(c,"cContact_refresh_tags").then(n=>{if(n&&n.success){const l=o({},t);n.data&&(l.tags=n.data.contactTag),i(l),r(f(o({},a),{tag:!1})),F.success(d("Tags fetch successfully","bit-integrations"));return}r(f(o({},a),{tag:!1})),F.error(d("Tags fetch failed","bit-integrations"))})},O=e=>{const t={},a=window.location.href.replace(`${window.opener.location.href}`,"").split("&");a&&a.forEach(r=>{const c=r.split("=");c[1]&&(t[c[0]]=c[1])}),localStorage.setItem(`__${e}`,JSON.stringify(t)),window.close()},x=(e,t,i,a,r,c,n,l,h,s)=>{if(!a.clientId){c({clientId:a.clientId?"":d("Client Id can't be empty","bit-integrations"),clientSecret:a.clientSecret?"":d("Secret key can't be empty","bit-integrations")});return}l(!0);const p=`https://authz.constantcontact.com/oauth2/default/v1/authorize?scope=${i}&response_type=code&client_id=${a.clientId}&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(`${s.api}`)}/redirect`,$=window.open(p,e,"width=400,height=609,toolbar=off"),k=setInterval(()=>{if($.closed){clearInterval(k);let u={},w=!1;const _=localStorage.getItem(`__${e}`);if(_&&(w=!0,u=JSON.parse(_),localStorage.removeItem(`__${e}`),u.code.search("#"))){const[g]=u.code.split("#");u.code=g}if(!u.code||u.error||!u||!w){const g=u.error?`Cause: ${u.error}`:"";h({show:!0,msg:`${d("Authorization failed","bit-integrations")} ${g}. ${d("please try again","bit-integrations")}`}),l(!1)}else{const g=o({},a);g.accountServer=u["accounts-server"],D(t,u,g,r,n,l,h,s)}}},500)},D=(e,t,i,a,r,c,n,l)=>{const h=o({},t);h.clientId=i.clientId,h.clientSecret=i.clientSecret,h.redirectURI=`${l.api}/redirect`,m(h,`${e}_generate_token`).then(s=>s).then(s=>{if(s&&s.success){const p=o({},i);p.tokenDetails=s.data,a(p),r(!0),n({show:!0,msg:d("Authorized Successfully","bit-integrations")})}else s&&s.data&&s.data.data||!s.success&&typeof s.data=="string"?n({show:!0,msg:`${d("Authorization failed Cause:","bit-integrations")}${s.data.data||s.data}. ${d("please try again","bit-integrations")}`}):n({show:!0,msg:d("Authorization failed. please try again","bit-integrations")});c(!1)})},G=e=>!((e.field_map?e.field_map.filter(i=>!i.formField&&!i.constantContactFormField):[]).length>0),H=e=>{var i;const t=(i=e==null?void 0:e.default)==null?void 0:i.constantContactFields.filter(a=>a.required===!0);return t.length>0?t.map(a=>({formField:"",constantContactFormField:a.key})):[{formField:"",constantContactFormField:""}]};export{W as a,J as b,x as c,N as d,G as e,H as g,M as h,O as s};
