"use strict";(globalThis.webpackChunk_affine_web=globalThis.webpackChunk_affine_web||[]).push([[6384],{26384:(e,t,a)=>{a.r(t),a.d(t,{Component:()=>F,loader:()=>x});var o=a(36870),i=a(14277),r=a(81427),l=a(21823),s=a(10980),n=a(61569),d=a(98504),u=a(86326),c=a(4194),f=a(21038),p=a(12077),h=a(54906),k=a(69628),g=a(59481),L=a(93965);let b=(0,u.lazy)(()=>Promise.all([a.e(8335),a.e(170),a.e(6351),a.e(9007),a.e(4486),a.e(5670),a.e(6610),a.e(7776),a.e(1389)]).then(a.bind(a,41389)).then(({AllWorkspaceModals:e})=>({default:e}))),x=async()=>null,F=()=>{let[e,t]=(0,u.useState)(!0),[a,x]=(0,u.useState)(!1),F=(0,s.h1)(g.uR),j=(0,n.S)(F.session.status$.map(e=>"authenticated"===e)),w=(0,s.h1)(d.q),y=(0,n.S)(w.list.workspaces$),C=(0,n.S)(w.list.isLoading$),{openPage:m,jumpToPage:v}=(0,k.P)(),[A]=(0,c.ok)(),_=(0,u.useRef)(!1),E=(0,u.useCallback)(()=>{_.current||(_.current=!0,(0,f.R)(w,l.j.AFFINE_CLOUD,"AFFiNE Cloud").then(({meta:e,defaultDocId:t})=>{t?v(e.id,t):m(e.id,L.Tk.ALL)}).catch(e=>console.error("Failed to create cloud workspace",e)))},[v,m,w]);return((0,u.useLayoutEffect)(()=>{if(e&&!C){if("true"===A.get("initCloud")){if(j){if(y.every(e=>e.flavour!==l.j.AFFINE_CLOUD)){E();return}m((y.find(e=>e.flavour===l.j.AFFINE_CLOUD)??y[0]).id,L.Tk.ALL)}}else{if(0===y.length){t(!1);return}let e=localStorage.getItem("last_workspace_id");m((y.find(t=>t.id===e)??y[0]).id,L.Tk.ALL)}}},[E,y,m,A,C,j,e]),(0,u.useEffect)(()=>{r.Ok?.ui.pingAppLayoutReady().catch(console.error)},[]),(0,u.useEffect)(()=>{x(!0),(0,f.I)(w).then(e=>{e&&(e.defaultPageId?v(e.meta.id,e.defaultPageId):m(e.meta.id,L.Tk.ALL))}).catch(e=>{console.error("Failed to create first app data",e)}).finally(()=>{x(!1)})},[v,m,w]),e||a)?(0,o.jsx)(p.q,{}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("div",{style:{position:"fixed",left:"50%",top:"50%"},children:(0,o.jsx)(i.W1,{rootOptions:{open:!0},items:(0,o.jsx)(h.l,{}),noPortal:!0,contentOptions:{style:{width:300,transform:"translate(-50%, -50%)",borderRadius:"8px",boxShadow:"var(--affine-shadow-2)",backgroundColor:"var(--affine-background-overlay-panel-color)",padding:"16px 12px"}},children:(0,o.jsx)("div",{})})}),(0,o.jsx)(b,{})]})}}}]); //# sourceMappingURL=chunk.6384.5a566793.js.map