import{j as g}from"./document_model_editor-B0b9iLkL.js";import{t as c,a as d}from"./index-Zdob0kL_.js";import{a3 as w,M as A,L,aO as T,aP as a,aQ as l,aK as p,s as u,aR as M}from"./reactor_browser-CqcNBhxi.js";import{p as S}from"./design_system_connect-CyoiT4fi.js";import{x,y as O}from"./document_drive-CacD9AxC.js";import"./graphql-AKTCpY7l.js";import"./drive_explorer-C9ZlHrfH.js";import"./sentry_react-cODD7zWc.js";import"./react-DQSxOgtG.js";import"./sentry_browser-B4YoBIIG.js";import"./react/jsx-runtime-DldvXD6N.js";import"./document_model-BhnxVUEi.js";import"./zod-9j67vCAu.js";import"./design_system-D3L2kJJ3.js";import"./tailwind_merge-Dr4f9Rms.js";import"./react-dom-D6zQJsh6.js";import"./react-dom/client-BVPiT_FE.js";import"./graphql_request-BJtmW2JS.js";import"./config-CU-aFfVJ.js";import"./design_system_ui-cfMsqDx9.js";function X(){const m=w()?.type==="addDrive",s=A(),n=L(),i=T(),y=async e=>{try{const o=i?.find(t=>t.id===e.appId),r=await M({id:"",slug:"",global:{name:e.name,icon:null},local:{availableOffline:e.availableOffline,sharingType:e.sharingType.toLowerCase(),listeners:[],triggers:[]}},o?.id);if(c(d("notifications.addDriveSuccess"),{type:"connect-success"}),!r)return;u(r)}catch(o){console.error(o)}},v=async e=>{try{const r=l()?await p(e.url,{sharingType:e.sharingType,availableOffline:e.availableOffline,listeners:[{block:!0,callInfo:{data:e.url,name:"switchboard-push",transmitterType:"SwitchboardPush"},filter:{branch:["main"],documentId:["*"],documentType:["*"],scope:["global"]},label:"Switchboard Sync",listenerId:"1",system:!0}],triggers:[]}):await p(e.url,{});if(c(d("notifications.addDriveSuccess"),{type:"connect-success"}),!r)return;u(r)}catch(o){console.error(o)}};async function f(e){await y(e),a()}async function h(e){await v(e),a()}const D=!!i?.length;return g.jsx(S,{open:m&&D,onAddLocalDrive:f,onAddRemoteDrive:h,requestPublicDrive:async e=>{const r=l()?x:O;try{const t=await n?.getBearerToken?.(e,s?.address,!0,{expiresIn:10});return r(e,{Authorization:`Bearer ${t}`})}catch(t){console.error(t);const b=await n?.getBearerToken?.(e,s?.address,!0,{expiresIn:10});return r(e,{Authorization:`Bearer ${b}`})}},onOpenChange:e=>{if(!e)return a()},appOptions:i?.map(e=>({id:e.id,name:e.name,driveEditor:e.id}))||[]})}export{X as AddDriveModal};
