var S=Object.defineProperty;var v=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var b=(e,t,i)=>t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,d=(e,t)=>{for(var i in t||(t={}))$.call(t,i)&&b(e,i,t[i]);if(v)for(var i of v(t))I.call(t,i)&&b(e,i,t[i]);return e};import{_ as a,z as g,d as _}from"./main.2.8.1.js";const k=(e,t,i)=>{const n=d({},t),{name:c}=e.target;e.target.value!==""?n[c]=e.target.value:delete n[c],i(d({},n))},C=(e,t,i)=>{const n={flowID:e!=null?e:null,clientId:t.clientId,clientSecret:t.clientSecret,tokenDetails:t.tokenDetails},c=_(n,"googleDrive_get_all_folders").then(o=>{if(o&&o.success){const s=d({},t);return o.data.googleDriveFoldersList&&(s.foldersList=o.data.googleDriveFoldersList,s.tokenDetails=o.data.tokenDetails),i(s),a("GoogleDrive Folders List refreshed successfully","bit-integrations")}else return a("Failed to refresh GoogleDrive Folders List. please try again","bit-integrations")});g.promise(c,{success:o=>o,error:a("Error Occurred","bit-integrations"),loading:a("Loading GoogleDrive Folders List...","bit-integrations")})},F=(e,t,i,n,c,o)=>{if(!e.clientId||!e.clientSecret){c({clientId:e.clientId?"":a("Client Id can't be empty","bit-integrations"),clientSecret:e.clientSecret?"":a("Client Secret can't be empty","bit-integrations")});return}n(!0);const r=`https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/drive&access_type=offline&prompt=consent&response_type=code&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(`${o.api}/redirect`)}&client_id=${e.clientId}`,p=window.open(r,"googleDrive","width=400,height=609,toolbar=off"),y=setInterval(()=>{if(p.closed){clearInterval(y);let l={},h=!1;const f=localStorage.getItem("__googleDrive");if(f&&(h=!0,l=JSON.parse(f),localStorage.removeItem("__googleDrive")),!l.code||l.error||!l||!h){const u=l.error?`Cause: ${l.error}`:"";g.error(`${a("Authorization Failed","bit-integrations")} ${u}. ${a("please try again","bit-integrations")}`),n(!1)}else{const u=d({},e);u.accountServer=l["accounts-server"],D(l,u,t,i,n,o)}}},500)},D=(e,t,i,n,c,o)=>{const s=d({},e);s.clientId=t.clientId,s.clientSecret=t.clientSecret,s.redirectURI=`${o.api}/redirect`,_(s,"googleDrive_authorization").then(r=>{if(r&&r.success){const p=d({},t);p.tokenDetails=r.data,i(p),n(!0),g.success(a("Authorized Successfully","bit-integrations"))}else r&&r.data&&r.data.data||!r.success&&typeof r.data=="string"?g.error(`${a("Authorization failed Cause:","bit-integrations")}${r.data.data||r.data}. ${a("please try again","bit-integrations")}`):g.error(a("Authorization failed. please try again","bit-integrations"));c(!1)})};export{F as a,C as g,k as h};
