var $=Object.defineProperty;var F=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var m=(e,o,t)=>o in e?$(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,s=(e,o)=>{for(var t in o||(o={}))b.call(o,t)&&m(e,t,o[t]);if(F)for(var t of F(o))w.call(o,t)&&m(e,t,o[t]);return e};import{_ as n,z as p,b as _}from"./main.2.8.10.js";const k=(e,o,t)=>{const r=s({},o),{name:c}=e.target;e.target.value!==""?r[c]=e.target.value:delete r[c],t(s({},r))},v=e=>!((e?e.filter(t=>!t.formField||!t.googleContactsFormField):[]).length>0),z=(e,o,t,r,c,d)=>{if(!e.clientId||!e.clientSecret){c({clientId:e.clientId?"":n("Client Id can't be empty","bit-integrations"),clientSecret:e.clientSecret?"":n("Client Secret can't be empty","bit-integrations")});return}r(!0);const a=`https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/contacts&access_type=offline&prompt=consent&response_type=code&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(`${d.api}/redirect`)}&client_id=${e.clientId}`,g=window.open(a,"googleContacts","width=400,height=609,toolbar=off"),I=setInterval(()=>{if(g.closed){clearInterval(I);let i={},h=!1;const f=localStorage.getItem("__googleContacts");if(f&&(h=!0,i=JSON.parse(f),localStorage.removeItem("__googleContacts")),!i.code||i.error||!i||!h){const u=i.error?`Cause: ${i.error}`:"";p.error(`${n("Authorization Failed","bit-integrations")} ${u}. ${n("please try again","bit-integrations")}`),r(!1)}else{const u=s({},e);u.accountServer=i["accounts-server"],C(i,u,o,t,r,d)}}},500)},C=(e,o,t,r,c,d)=>{const l=s({},e);l.clientId=o.clientId,l.clientSecret=o.clientSecret,l.redirectURI=`${d.api}/redirect`,_(l,"googleContacts_authorization").then(a=>{if(a&&a.success){const g=s({},o);g.tokenDetails=a.data,t(g),r(!0),p.success(n("Authorized Successfully","bit-integrations"))}else a&&a.data&&a.data.data||!a.success&&typeof a.data=="string"?p.error(`${n("Authorization failed Cause:","bit-integrations")}${a.data.data||a.data}. ${n("please try again","bit-integrations")}`):p.error(n("Authorization failed. please try again","bit-integrations"));c(!1)})},R=e=>{const o=e==null?void 0:e.default.filter(t=>t.required===!0);return o.length>0?o.map(t=>({formField:"",googleContactsFormField:t.key})):[{formField:"",googleContactsFormField:""}]};export{z as a,v as c,R as g,k as h};
