import{Bt as e,Ct as t,Et as n,F as r,G as i,H as a,L as o,N as s,Nt as c,Pt as l,T as u,Tt as d,Vt as f,X as p,bt as m,ft as h,mt as g,ot as _,st as v,tt as y,ut as b,v as x,vt as S,z as C}from"../chunks/xY0c-UfG.js";import{r as w}from"../chunks/Bym3iIKr.js";import"../chunks/xihTtKlq.js";import"../chunks/_zekciZc.js";import{n as T}from"../chunks/C9QtJpOb.js";import{i as E}from"../chunks/Ca8AGdcM.js";import{t as D}from"../chunks/Y1ENS0GB.js";import{t as O}from"../chunks/Cvnwo5OO.js";import{t as k}from"../chunks/DDbpVNi02.js";import"../chunks/BV3B8RXJ.js";var A=C(`<a class="cloud-link svelte-1x05zx6"> </a>`),j=C(`<div class="managed-auth svelte-1x05zx6"><p class="svelte-1x05zx6"> </p> <!></div>`),M=C(`<p class="error-msg svelte-1x05zx6"> </p>`),N=C(`<form class="svelte-1x05zx6"><label class="field svelte-1x05zx6"><span class="field-label svelte-1x05zx6">Email</span> <!></label> <label class="field svelte-1x05zx6"><span class="field-label svelte-1x05zx6">Password</span> <!></label> <!> <!></form>`),P=C(`<div class="login-page svelte-1x05zx6"><div class="login-card svelte-1x05zx6"><div class="logo svelte-1x05zx6"><img class="logo-mark svelte-1x05zx6" src="/studiograph-logomark.svg" alt="" width="64" height="64"/> <span class="logo-text svelte-1x05zx6"> </span></div> <!></div></div>`);function F(C,F){l(F,!0);let I=()=>n(T,`$page`,L),[L,R]=d(),z=t(()=>D.workspaceName||`Studiograph`),B=t(()=>D.managedAuthLoginUrl||D.cloudUrl||``),V=t(()=>I().url.searchParams.get(`managedLogout`)===`1`),H=t(()=>{let e=I().url.searchParams.get(`returnTo`);return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`)?`/`:e}),U=m(``),W=m(``),G=m(``),K=m(!1);v(()=>{if(D.managedAuth&&p(B)&&!p(V)){let e=p(B);if(p(H)!==`/`)try{let t=new URL(p(B));t.searchParams.set(`returnTo`,p(H)),e=t.toString()}catch{}window.location.replace(e)}});async function q(e){e.preventDefault();let t=e.currentTarget,n=t.querySelector(`input[type="email"]`).value,r=t.querySelector(`input[type="password"]`).value;S(G,``),S(K,!0);try{if(await D.login(n,r),p(H)!==`/`){try{sessionStorage.removeItem(`oauth_resume_attempt`)}catch{}window.location.href=p(H);return}await E.load(),w(`/`)}catch(e){S(G,e.message||`Invalid credentials`,!0)}finally{S(K,!1)}}var J=P();u(`1x05zx6`,e=>{y(()=>{b.title=`Sign in — ${p(z)??``}`})});var Y=h(J),X=h(Y),Z=g(h(X),2),Q=h(Z,!0);f(Z),f(X);var $=g(X,2),ee=e=>{var t=j(),n=h(t),i=h(n,!0);f(n);var a=g(n,2),c=e=>{var t=A(),n=h(t,!0);f(t),_(()=>{x(t,`href`,p(B)),r(n,p(V)?`Sign in with Studiograph Cloud`:`Continue to Studiograph Cloud`)}),o(e,t)};s(a,e=>{p(B)&&e(c)}),f(t),_(()=>r(i,p(V)?`You are signed out of this managed studio.`:`Redirecting to Studiograph Cloud for sign-in...`)),o(e,t)},te=t=>{var n=N(),c=h(n);k(g(h(c),2),{type:`email`,required:!0,autocomplete:`email`,autofocus:!0,class:`field-input`,get value(){return p(U)},set value(e){S(U,e,!0)}}),f(c);var l=g(c,2);k(g(h(l),2),{type:`password`,required:!0,autocomplete:`current-password`,class:`field-input`,get value(){return p(W)},set value(e){S(W,e,!0)}}),f(l);var u=g(l,2),d=e=>{var t=M(),n=h(t,!0);f(t),_(()=>r(n,p(G))),o(e,t)};s(u,e=>{p(G)&&e(d)}),O(g(u,2),{variant:`accent`,type:`submit`,class:`submit-btn`,get disabled(){return p(K)},children:(t,n)=>{e(),o(t,a(`Sign in`))},$$slots:{default:!0}}),f(n),i(`submit`,n,q),o(t,n)};s($,e=>{D.managedAuth?e(ee):e(te,-1)}),f(Y),f(J),_(()=>r(Q,p(z))),o(C,J),c(),R()}export{F as component};