1import{u as se,i as ae,r as i,j as r}from"./react-vendor-DvpaPdNC.js";import{j as ie,k as ne,l as y,s as oe,w as K,m as Q,T as ce,r as le,n as ue,o as de,p as ge,G as me,q as he,C as pe,t as fe}from"./index-CC9uFMyS.js";import{r as ve}from"./user-DOUv6FLE.js";import{L as V,o as X}from"./firebase-C-c4J6sC.js";import"./motion-CVWa5O5W.js";const Ne=()=>{var Y;const u=se(),[k]=ae(),{user:n,loading:j,initializationError:C,clearInitializationError:F,reportBlockedSignup:q}=ie(),{isDataReady:N,studios:o,defaultStudioId:O}=ne(),[a,p]=i.useState("initializing"),[R,v]=i.useState(0),[$,B]=i.useState(!1),[d,U]=i.useState("unknown"),x=i.useRef(!1),b=i.useRef(!1),G=i.useRef(!1),L=i.useRef(o.length),m=y.activation.getSession(),_=y.activation.getDeviceClass(),c=oe(k.get("redirect")),P=k.get("template"),D=k.get("page"),M=k.get("request"),z=!!(c||P||D),S=P?"email_template":D?"email_page":c?"auth_redirect":"direct",H=e=>e.includes("/templates")?"templates_page":e.includes("/campaign")?"campaigns_page":e.includes("/assets")?"assets_page":e.includes("/new")?"new_thumbnail_page":"custom_redirect",l=(e,s)=>{G.current||(G.current=!0,y.app.activationRouteResolved({entrySource:S,entrySurface:"initializing",deviceClass:_,wasPrefilled:z,isNewUser:m.isNewUser,activationOutcome:e,resolvedDestination:s}))};i.useEffect(()=>{L.current=o.length},[o.length]);const W=e=>{window.setTimeout(()=>{L.current===0&&(console.error(`[InitializingPage] (NO $) Recovery failed after ${e} path - still no studios`),p("error"),v(100))},15e3)},g=O&&o.some(e=>e.id===O)?O:((Y=o[0])==null?void 0:Y.id)??null;i.useEffect(()=>{if(!n||!g||d!=="unknown")return;if(m.onboardingComplete===!0){U("skip");return}let e=!1;return K(V(X(Q,"users",n.uid,"settings","onboarding")),5e3).then(s=>{if(e)return;const t=s.data();U(s.exists()&&(t==null?void 0:t.completed)===!1?"wizard":"skip")}).catch(()=>{e||U("skip")}),()=>{e=!0}},[n,g,d,m.onboardingComplete]);const I=()=>{const e=k.toString();return`/welcome${e?`?${e}`:""}`},A=e=>{const s=`/studio/${e}`;if(c){const t=c.match(/^\/studio\/([^/]+)/);if(t){const w=t[1];if(o.some(re=>re.id===w))return{path:c,resolvedDestination:"studio_redirect"};const h=c.indexOf("?"),te=h===-1?c:c.slice(0,h),J=h===-1?"":c.slice(h),E=fe(te,w,e,J);return E===`${s}${J}`?{path:E,resolvedDestination:"studio_home"}:{path:E,resolvedDestination:H(E)}}return{path:c,resolvedDestination:H(c)}}if(P)return{path:`/studio/${e}/templates/${P}`,resolvedDestination:"template_detail"};if(D){const t=M?`?request=${M}`:"";switch(D){case"templates":return{path:`/studio/${e}/templates${t}`,resolvedDestination:"templates_page"};case"campaign":return{path:`/studio/${e}/campaigns`,resolvedDestination:"campaigns_page"};case"assets":return{path:`/studio/${e}/assets${t}`,resolvedDestination:"assets_page"};case"sets":return{path:`/studio/${e}/new`,state:{startPath:"ai"},resolvedDestination:"new_thumbnail_page"};case"tools":return{path:`/studio/${e}/new`,state:{startPath:"image"},resolvedDestination:"new_thumbnail_page"};default:return{path:s,resolvedDestination:"studio_home"}}}return{path:s,resolvedDestination:"studio_home"}},T=i.useCallback(async e=>{if(n)try{const s=X(Q,"users",n.uid);let t=null;try{t=(await K(V(s),5e3)).exists()}catch(f){if(!(f instanceof ce))throw f;console.warn("[InitializingPage] (NO $) User doc read timed out - assuming dead transport, using backend recovery")}if(t===!1){p("recovering");try{await le(n)}catch(f){const h=f.message;if(ue(h)){console.warn("[InitializingPage] (NO $) Recovery blocked by signup gate:",h),await q(de(h));return}throw f}W("trigger");return}p("recovering");const w=await ve();w.recovered,w.defaultStudioId,w.repairedPaths,W("callable")}catch(s){console.error("[InitializingPage] (NO $) Recovery check failed:",s),p("error"),v(100),e&&clearInterval(e)}},[n,q]);i.useEffect(()=>{!C||!n||o.length>0||x.current||(console.error("[InitializingPage] (NO $) Setup issue detected from auth bootstrap:",C),F(),x.current=!0,B(!0),p("recovering"),v(95),T())},[T,F,C,o.length,n]),i.useEffect(()=>{if(j||!n||N)return;const e=window.setTimeout(()=>{ge("initializing watchdog")},8e3);return()=>window.clearTimeout(e)},[j,n,N]),i.useEffect(()=>{if(j)return;if(!n){l("login_redirect","login"),u("/login",{replace:!0});return}if(m.isNewUser===!0&&!m.onboardingComplete&&d!=="skip"){b.current||(b.current=!0,y.app.activationFlowStarted({entrySource:S,entrySurface:"initializing",deviceClass:_,wasPrefilled:z,isNewUser:!0})),l("success","onboarding_wizard"),u(I(),{replace:!0});return}if(!b.current&&N&&g&&d!=="unknown"){if(b.current=!0,y.app.activationFlowStarted({entrySource:S,entrySurface:"initializing",deviceClass:_,wasPrefilled:z,isNewUser:m.isNewUser}),d==="wizard"){l("success","onboarding_wizard"),u(I(),{replace:!0});return}const t=A(g);l("success",t.resolvedDestination),u(t.path,{replace:!0,...t.state?{state:t.state}:{}});return}b.current||(b.current=!0,y.app.activationFlowStarted({entrySource:S,entrySurface:"initializing",deviceClass:_,wasPrefilled:z,isNewUser:m.isNewUser}));const e=setInterval(()=>{v(t=>t>=90?t:t+10)},300),s=setTimeout(async()=>
1{if(a==="initializing"&&o.length===0&&!x.current){x.current=!0,B(!0),await T(e);return}else a==="initializing"&&o.length>0&&g&&(p("timeout"),v(100),clearInterval(e),setTimeout(()=>{if(d==="wizard"){l("timeout","onboarding_wizard"),u(I(),{replace:!0});return}const t=A(g);l("timeout",t.resolvedDestination),u(t.path,{replace:!0,...t.state?{state:t.state}:{}})},2e3))},15e3);return N&&g&&d!=="unknown"&&(p("ready"),v(100),clearInterval(e),clearTimeout(s),setTimeout(()=>{if(d==="wizard"){l(x.current?"recovered":"success","onboarding_wizard"),u(I(),{replace:!0});return}const t=A(g);l(x.current?"recovered":"success",t.resolvedDestination),u(t.path,{replace:!0,...t.state?{state:t.state}:{}})},800)),()=>{clearInterval(e),clearTimeout(s)}},[n,j,u,a,N,o,g,d,S,_,z,m.isNewUser,T]),i.useEffect(()=>{a==="timeout"?l("timeout","studio_home"):a==="error"&&l("error","studio_home")},[a]);const Z=()=>{switch(a){case"initializing":return"Setting up your studio...";case"ready":return"You're all set!";case"recovering":return"Finishing setup...";case"timeout":return"Still working on it...";case"error":return"Something went wrong";default:return"Initializing..."}},ee=()=>{switch(a){case"initializing":return"This usually takes a few seconds";case"ready":return"Taking you to your studio now";case"recovering":return $?"We hit a setup issue and are retrying automatically":"Almost there, just a moment";case"timeout":return"Try refreshing if this persists";case"error":return $?"Automatic recovery did not complete. Refresh the page or reach out to [email protected]":"Refresh the page or reach out to [email protected]";default:return""}};return r.jsxs("div",{className:"min-h-screen bg-rh-dark text-fg flex items-center justify-center relative overflow-hidden",children:[r.jsx(me,{}),r.jsxs("div",{className:"w-full max-w-sm relative z-10 p-6",children:[r.jsxs("div",{className:"bg-rh-surface/50 backdrop-blur-xl border border-ink/10 rounded-2xl shadow-2xl overflow-hidden p-8 text-center",children:[r.jsxs("div",{className:"relative w-20 h-20 mx-auto mb-6",children:[r.jsx("div",{className:"absolute inset-0 bg-rh-green/20 rounded-2xl blur-xl animate-pulse"}),r.jsx(he,{size:"lg",rounded:"2xl",className:"relative z-10 !h-20 !w-20 shadow-lg"})]}),r.jsx("h1",{className:"text-xl font-bold text-fg mb-2 animate-fade-in",children:Z()}),r.jsx("p",{className:"text-sm text-rh-text-dark mb-8 animate-fade-in",style:{animationDelay:"0.1s"},children:ee()}),r.jsx("div",{className:"relative h-1.5 bg-rh-surface-2 rounded-full overflow-hidden mb-8",children:r.jsx("div",{className:`absolute top-0 left-0 h-full rounded-full transition-all duration-500 ease-out ${a==="ready"?"bg-rh-green shadow-[0_0_10px_rgba(74,222,128,0.5)]":a==="recovering"?"bg-amber-500 shadow-[0_0_10px_rgba(245,158,11,0.5)] animate-pulse":a==="error"||a==="timeout"?"bg-rh-rose shadow-[0_0_10px_rgba(244,63,94,0.5)]":"bg-rh-green shadow-[0_0_10px_rgba(74,222,128,0.3)]"}`,style:{width:`${a==="recovering"?95:R}%`}})}),r.jsx("div",{className:"space-y-3 text-left",children:[{label:"Connecting your account",threshold:30},{label:"Loading your workspace",threshold:60},{label:"Preparing your studio",threshold:90}].map((e,s)=>r.jsxs("div",{className:`flex items-center gap-3 p-3 rounded-lg border transition-all duration-500 ${R>=e.threshold?"bg-rh-green/5 border-rh-green/20 text-fg":"bg-transparent border-transparent text-rh-text-dark/50"}`,children:[r.jsx("div",{className:`flex items-center justify-center w-5 h-5 rounded-full border text-[10px] font-bold transition-all duration-500 ${R>=e.threshold?"bg-rh-green border-rh-green text-black light:text-white":"bg-transparent border-rh-text-dark/30 text-transparent"}`,children:r.jsx(pe,{className:"w-3 h-3"})}),r.jsx("span",{className:"text-xs font-medium",children:e.label})]},s))}),a==="recovering"&&r.jsx("div",{className:"mt-6 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg animate-fade-in-up",children:r.jsx("p",{className:"text-xs text-amber-500 font-medium",children:$?"We detected a setup issue and are retrying automatically.":"Finishing a few things: this will only take a moment."})}),a==="timeout"&&r.jsx("div",{className:"mt-6 p-3 bg-rh-rose/10 border border-rh-rose/20 rounded-lg animate-fade-in-up",children:r.jsx("p",{className:"text-xs text-rh-rose font-medium",children:"This is taking longer than usual. Try refreshing the page."})}),a==="error"&&r.jsx("div",{className:"mt-6 p-3 bg-rh-rose/10 border border-rh-rose/20 rounded-lg animate-fade-in-up",children:r.jsx("p",{className:"text-xs text-rh-rose font-medium",children:$?"Account setup hit an unexpected issue. Refresh to retry, or email [email protected]":"Setup didn't complete. Refresh to try again, or email [email protected]"})})]}),r.jsx("div",{className:"mt-6 text-center",children:r.jsxs("p",{className:"text-[10px] text-rh-text-dark/40 font-medium uppercase tracking-widest",children:[R,"% Complete"]})})]})]})};export{Ne as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.