var b=Object.defineProperty,S=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var $=(e,t,i)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,o=(e,t)=>{for(var i in t||(t={}))q.call(t,i)&&$(e,i,t[i]);if(I)for(var i of I(t))R.call(t,i)&&$(e,i,t[i]);return e},h=(e,t)=>S(e,C(t));import{_ as d,b as w,z as m}from"./main.2.8.10.js";import{x as z}from"./Note.DalStCGz.js";const M=(e,t,i,a,r,c,n,l,f)=>{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(h(o({},a),{list:!0}));const c={integId:e,clientId:t.clientId,clientSecret:t.clientSecret,tokenDetails:t.tokenDetails};w(c,"cContact_refresh_list").then(n=>{if(n&&n.success){const l=o({},t);n.data&&(l.lists=n.data.contactList),i(l),r(h(o({},a),{list:!1})),m.success(d("List fetch successfully","bit-integrations"));return}r(h(o({},a),{list:!1})),m.error(d("List fetch failed","bit-integrations"))})},v=(e,t)=>{const i={clientId:e.clientId,clientSecret:e.clientSecret,tokenDetails:e.tokenDetails};w(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)}})},x=(e,t,i,a,r)=>{r(h(o({},a),{tag:!0}));const c={integId:e,clientId:t.clientId,clientSecret:t.clientSecret,tokenDetails:t.tokenDetails};w(c,"cContact_refresh_tags").then(n=>{if(n&&n.success){const l=o({},t);n.data&&(l.tags=n.data.contactTag),i(l),r(h(o({},a),{tag:!1})),m.success(d("Tags fetch successfully","bit-integrations"));return}r(h(o({},a),{tag:!1})),m.error(d("Tags fetch failed","bit-integrations"))})},J=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()},O=(e,t,i,a,r,c,n,l,f,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`,k=window.open(p,e,"width=400,height=609,toolbar=off"),y=setInterval(()=>{if(k.closed){clearInterval(y);let u={},_=!1;const F=localStorage.getItem(`__${e}`);if(F&&(_=!0,u=JSON.parse(F),localStorage.removeItem(`__${e}`),u.code.search("#"))){const[g]=u.code.split("#");u.code=g}if(!u.code||u.error||!u||!_){const g=u.error?`Cause: ${u.error}`:"";f({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,f,s)}}},500)},D=(e,t,i,a,r,c,n,l)=>{const f=o({},t);f.clientId=i.clientId,f.clientSecret=i.clientSecret,f.redirectURI=`${l.api}/redirect`,w(f,`${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=>{const t=e==null?void 0:e.filter(i=>i.required===!0);return t.length>0?t.map(i=>({formField:"",constantContactFormField:i.key})):[{formField:"",constantContactFormField:""}]};export{x as a,O as b,H as c,N as d,G as e,W as g,M as h,J as s};
