var R=Object.defineProperty,k=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable;var D=(e,t,s)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,c=(e,t)=>{for(var s in t||(t={}))F.call(t,s)&&D(e,s,t[s]);if(I)for(var s of I(t))g.call(t,s)&&D(e,s,t[s]);return e},z=(e,t)=>k(e,C(t));import{_ as l,by as $,$ as p,c as _}from"./main-40.js";const E=(e,t,s,n,d,i)=>{if(!e.dataCenter||!e.clientId||!e.clientSecret){s({dataCenter:e.dataCenter?"":l("Data center cann't be empty"),clientId:e.clientId?"":l("Client ID cann't be empty"),clientSecret:e.clientSecret?"":l("Secret key cann't be empty")});return}const a=$(p);d(!0);const o="ZohoCampaigns.contact.READ,ZohoCampaigns.contact.CREATE,ZohoCampaigns.contact.UPDATE",r=`https://accounts.zoho.${e.dataCenter}/oauth/v2/auth?scope=${o}&response_type=code&client_id=${e.clientId}&prompt=Consent&access_type=offline&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(a.zohoRedirectURL)}`,f=window.open(r,"zohoCampaigns","width=400,height=609,toolbar=off"),y=setInterval(()=>{if(f.closed){clearInterval(y);let h={},m=!1;const w=localStorage.getItem("__bitforms_zohoCampaigns");if(w&&(m=!0,h=JSON.parse(w),localStorage.removeItem("__bitforms_zohoCampaigns")),!h.code||h.error||!h||!m){const u=h.error?`Cause: ${h.error}`:"";i({show:!0,msg:`${l("Authorization failed")} ${u}. ${l("please try again")}`}),d(!1)}else{const u=c({},e);u.accountServer=h["accounts-server"],b(h,u,t,n,d,i)}}},500)},b=(e,t,s,n,d,i)=>{const a=$(p),o=c({},e);o.dataCenter=t.dataCenter,o.clientId=t.clientId,o.clientSecret=t.clientSecret,o.redirectURI=encodeURIComponent(a.zohoRedirectURL),_(o,"bitforms_zcampaigns_generate_token").then(r=>r).then(r=>{if(r&&r.success){const f=c({},t);f.tokenDetails=r.data,s(f),n(!0),i({show:!0,msg:l("Authorized Successfully")})}else r&&r.data&&r.data.data||!r.success&&typeof r.data=="string"?i({show:!0,msg:`${l("Authorization failed Cause:")}${r.data.data||r.data}. ${l("please try again")}`}):i({show:!0,msg:l("Authorization failed. please try again")});d(!1)})},Z=(e,t,s,n,d,i)=>{let a=c({},s);switch(a[e.target.name]=e.target.value,e.target.name){case"list":a=A(a,t,n,d,i);break}n(c({},a))},A=(e,t,s,n,d)=>{var a,o;const i=c({},e);return i.field_map=[{formField:"",zohoFormField:"Contact Email"}],(o=(a=i==null?void 0:i.default)==null?void 0:a.fields)!=null&&o[i.list]||v(t,i,s,n,d),i},q=(e,t,s,n,d)=>{n(!0);const i={formID:e,id:t.id,dataCenter:t.dataCenter,clientId:t.clientId,clientSecret:t.clientSecret,tokenDetails:t.tokenDetails};_(i,"bitforms_zcampaigns_refresh_lists").then(a=>{if(a&&a.success){const o=c({},t);a.data.lists&&(o.default=z(c({},o.default),{lists:a.data.lists})),a.data.tokenDetails&&(o.tokenDetails=a.data.tokenDetails),d({show:!0,msg:l("Lists refreshed")}),s(c({},o))}else a&&a.data&&a.data.data||!a.success&&typeof a.data=="string"?d({show:!0,msg:`${l("Lists refresh failed Cause:")}${a.data.data||a.data}. ${l("please try again")}`}):d({show:!0,msg:l("Lists refresh failed. please try again")});n(!1)}).catch(()=>n(!1))},v=(e,t,s,n,d)=>{const{list:i}=t;if(!i)return;n(!0);const a={formID:e,list:i,dataCenter:t.dataCenter,clientId:t.clientId,clientSecret:t.clientSecret,tokenDetails:t.tokenDetails};_(a,"bitforms_zcampaigns_refresh_contact_fields").then(o=>{if(o&&o.success){const r=c({},t);o.data.fields?(r.default.fields||(r.default.fields={}),r.default.fields[i]=o.data,o.data.tokenDetails&&(r.tokenDetails=o.data.tokenDetails),d({show:!0,msg:l("Contact Fields refreshed")})):d({show:!0,msg:l("Zoho didn't provide fields names for this list")}),o.data.tokenDetails&&(r.tokenDetails=o.data.tokenDetails),s(c({},r))}else d({show:!0,msg:l("Contact Fields refresh failed. please try again")});n(!1)}).catch(()=>n(!1))},P=e=>!((e!=null&&e.field_map?e.field_map.filter(s=>{var n,d,i;return!s.formField&&s.zohoFormField&&((i=(d=(n=e==null?void 0:e.default)==null?void 0:n.fields)==null?void 0:d[e.list])==null?void 0:i.required.indexOf(s.zohoFormField))!==-1}):[]).length>0);export{v as a,E as b,P as c,Z as h,q as r};
