var A=Object.defineProperty;var p=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var I=(e,t,a)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,i=(e,t)=>{for(var a in t||(t={}))$.call(t,a)&&I(e,a,t[a]);if(p)for(var a of p(t))w.call(t,a)&&I(e,a,t[a]);return e};import{_ as r,by as R,$ as _,c as y}from"./main-40.js";function M(e,t,a,u,d,c,h,n,o){const l=i({},t);if(h){const m=i({},n);m[e.target.name]="",o(i({},m))}l[e.target.name]=e.target.value,a(i({},l))}const S=(e,t,a,u,d,c)=>{if(!e.dataCenter||!e.clientId||!e.clientSecret){a({dataCenter:e.dataCenter?"":r("Data center cann't be empty"),clientId:e.clientId?"":r("Client ID cann't be empty"),clientSecret:e.clientSecret?"":r("Secret key cann't be empty")});return}const h=R(_);d(!0);const n="ZohoMail.accounts.Read,ZohoMail.messages.CREATE,ZohoMail.messages.UPDATE,ZohoMail.Attachments.CREATE,ZohoMail.Attachments.READ,ZohoMail.Attachments.UPDATE",o=`https://accounts.zoho.${e.dataCenter}/oauth/v2/auth?scope=${n}&response_type=code&client_id=${e.clientId}&prompt=Consent&access_type=offline&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(h.zohoRedirectURL)}`,l=window.open(o,"zohoMail","width=400,height=609,toolbar=off"),m=setInterval(()=>{if(l.closed){clearInterval(m);let s={},f=!1;const g=localStorage.getItem("__bitforms_zohoMail");if(g&&(f=!0,s=JSON.parse(g),localStorage.removeItem("__bitforms_zohoMail")),!s.code||s.error||!s||!f){const C=s.error?`Cause: ${s.error}`:"";c({show:!0,msg:`${r("Authorization failed")} ${C}. ${r("please try again")}`}),d(!1)}else{const C=i({},e);C.accountServer=s["accounts-server"],z(s,C,t,u,d,c)}}},500)},z=(e,t,a,u,d,c)=>{const h=R(_),n=i({},e);n.dataCenter=t.dataCenter,n.clientId=t.clientId,n.clientSecret=t.clientSecret,n.redirectURI=encodeURIComponent(h.zohoRedirectURL),y(n,"bitforms_zmail_generate_token").then(o=>o).then(o=>{if(o&&o.success){const l=i({},t);l.tokenDetails=o.data,a(l),u(!0),c({show:!0,msg:r("Authorized Successfully")})}else o&&o.data&&o.data.data||!o.success&&typeof o.data=="string"?c({show:!0,msg:`${r("Authorization failed Cause:")}${o.data.data||o.data}. ${r("please try again")}`}):c({show:!0,msg:r("Authorization failed. please try again")});d(!1)})};export{S as a,M as h};
