var S=Object.defineProperty;var _=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var y=(a,e,i)=>e in a?S(a,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):a[e]=i,p=(a,e)=>{for(var i in e||(e={}))F.call(e,i)&&y(a,i,e[i]);if(_)for(var i of _(e))v.call(e,i)&&y(a,i,e[i]);return a};import{_ as l,z as h,b as m}from"./main.2.8.10.js";import{ai as k}from"./Note.DalStCGz.js";const O=(a,e,i,s,d,r,n=0)=>{let t=p({},e);const{name:o}=a.target;a.target.value!==""?t[o]=a.target.value:delete t[o],t[a.target.name]=a.target.value,a.target.name==="folder"&&(t.folderMap=t.folderMap.slice(0,n),t=w(t,s,i,d,r)),i(p({},t))},w=(a,e,i,s,d)=>{var n,t,o,c,f,u;const r=p({},a);return delete r.teamType,r.folder&&!((t=(n=r.default)==null?void 0:n.folders)!=null&&t[r.folder])?(((u=(f=(c=(o=r.default)==null?void 0:o.teamFolders)==null?void 0:c[r.team])==null?void 0:f[r.folder])==null?void 0:u.type)==="private"&&(r.teamType="private"),$(e,r,i,s,d)):r.folder&&r.folder!==r.folderMap[r.folderMap.length-1]&&r.folderMap.push(r.folder),r},R=(a,e,i,s,d)=>{s(!0);const r={flowID:a!=null?a:null,clientId:e.clientId,clientSecret:e.clientSecret,tokenDetails:e.tokenDetails},n=m(r,"oneDrive_get_all_folders").then(t=>{if(t&&t.success){const o=p({},e);return o.default||(o.default={}),t.data.oneDriveFoldersList&&(o.default.rootFolders=t.data.oneDriveFoldersList,o.tokenDetails=t.data.tokenDetails),i(o),s(!1),l("OneDrive Folders List refreshed successfully","bit-integrations")}else return s(!1),l("OneDrive Folders List refresh failed. please try again","bit-integrations")}).catch(()=>s(!1));h.promise(n,{success:t=>t,error:l("Error Occurred","bit-integrations"),loading:l("Loading OneDrive Folders List...","bit-integrations")})},$=(a,e,i,s,d,r)=>{const n=r?e.folderMap[r]:e.folder;s(!0);const t={formID:a,dataCenter:e.dataCenter,clientId:e.clientId,clientSecret:e.clientSecret,tokenDetails:e.tokenDetails,team:e.team,folder:n,teamType:"teamType"in e?"private":"team"};m(t,"oneDrive_get_single_folder").then(o=>{if(o&&o.success){const c=p({},e);o.data.folders?(c.default.folders||(c.default.folders={}),c.default.folders[n]=k(o.data.folders,"folderName"),c.folderMap.includes(n)||c.folderMap.push(n),d({show:!0,msg:l("Sub Folders refreshed","bitform")})):d({show:!0,msg:l("No Sub Folder Found","bitform")}),o.data.tokenDetails&&(c.tokenDetails=o.data.tokenDetails),i(p({},c))}else d({show:!0,msg:l("Sub Folders refresh failed. please try again","bitform")});s(!1)}).catch(()=>s(!1))},M=(a,e,i,s,d,r)=>{if(!a.clientId||!a.clientSecret){d({clientId:a.clientId?"":l("Client Id can't be empty","bit-integrations"),clientSecret:a.clientSecret?"":l("Client Secret can't be empty","bit-integrations")});return}s(!0);const t=`https://login.live.com/oauth20_authorize.srf?client_id=${a.clientId}&scope=onedrive.readwrite offline_access Files.ReadWrite.All&access_type=offline&prompt=consent&response_type=code&state=${encodeURIComponent(window.location.href)}/redirect&redirect_uri=${encodeURIComponent(`${r.api}/redirect`)}`,o=window.open(t,"oneDrive","width=400,height=609,toolbar=off"),c=setInterval(()=>{if(o.closed){clearInterval(c);let f={},u=!1;const b=localStorage.getItem("__oneDrive");if(b&&(u=!0,f=JSON.parse(b),localStorage.removeItem("__oneDrive")),!f.code||f.error||!f||!u){const g=f.error?`Cause: ${f.error}`:"";h.error(`${l("Authorization Failed","bit-integrations")} ${g}. ${l("please try again","bit-integrations")}`),s(!1)}else{const g=p({},a);g.accountServer=f["accounts-server"],z(f,g,e,i,s,r)}}},500)},z=(a,e,i,s,d,r)=>{const n=p({},a);n.clientId=e.clientId,n.clientSecret=e.clientSecret,n.redirectURI=`${r.api}/redirect`,m(n,"oneDrive_authorization").then(t=>{if(t&&t.success){const o=p({},e);o.tokenDetails=t.data,i(o),s(!0),h.success(l("Authorized Successfully","bit-integrations"))}else t&&t.data&&t.data.data||!t.success&&typeof t.data=="string"?h.error(`${l("Authorization failed Cause:","bit-integrations")}${t.data.data||t.data}. ${l("please try again","bit-integrations")}`):h.error(l("Authorization failed. please try again","bit-integrations"));d(!1)})};export{$ as a,M as b,R as g,O as h};
