1import{u as Z,a as y,j as e,L as w,S as ee,B as A,b as P,g as se}from"./index-DxzsxK2X.js";import{f as te,r as n,L as N}from"./vendor-DlcqtHFq.js";import{I as T}from"./input-B37HmIb0.js";import{L as z}from"./label-D9TOb-jn.js";import{C as re,a as ae,b as oe,c as ie,d as ne,e as le}from"./card-DYNxoaby.js";import{S as ce}from"./separator-CnCOCyYp.js";import{s as h}from"./theme-CxAeZeIr.js";import{g as v,a as L,c as H,b as M}from"./guestUpload-D-_RSCqa.js";import{uploadGuestFiles as B,uploadGuestUrl as O,claimShare as de}from"./api-pXK2eK_H.js";import{M as ue}from"./mail-ClEq8WR9.js";const p="https://app.tutoremy.ai";function ve(){const{signIn:q,signInWithGoogle:D,user:f,session:S,loading:x}=Z(),[C]=te(),d=C.get("redirect"),b=C.get("session_expired"),[U,W]=n.useState(""),[k,Y]=n.useState(""),[I,m]=n.useState(""),[u,R]=n.useState(!1),[j,G]=n.useState(!1),[$,V]=n.useState(!1),[J,K]=n.useState(!1),[F,E]=n.useState("");n.useEffect(()=>{if(!x&&f&&S){if(b){y.auth.signOut();return}const a=async(s,l)=>{await P(s);let c=null;try{const t=await v();t.length>0&&(E("Uploading your file..."),c=await B(t,s),console.log("[Login] Auto-redirect upload success, guideId:",c),await H())}catch(t){console.error("[Login] Auto-redirect failed to upload guest files:",t)}if(!c)try{const t=L();t&&(E("Processing your link..."),c=await O(t,s),console.log("[Login] Auto-redirect URL upload success, guideId:",c),M())}catch(t){console.error("[Login] Auto-redirect failed to upload guest URL:",t)}const o=document.createElement("link");o.rel="preconnect",o.href=p,document.head.appendChild(o);let i;c?i=`/processing/${c}`:i=d||"/guides",window.location.href=`${p}/auth-callback#access_token=${s}&refresh_token=${l}&redirect=${encodeURIComponent(i)}`};y.auth.refreshSession().then(({data:s,error:l})=>{if(l||!s.session){y.auth.signOut();return}a(s.session.access_token,s.session.refresh_token)})}},[x,f,S,d,b]),n.useEffect(()=>{v().then(a=>V(a.length>0)).catch(()=>{}),K(!!L())},[]);const Q=async a=>{a.preventDefault(),m(""),R(!0);try{const{session:s}=await q(U,k),l=s.access_token,c=s.refresh_token;await P(l);let o=null;try{const r=await v();console.log("[Login] Guest files found:",r.length),r.length>0&&(o=await B(r,l),console.log("[Login] Upload success, guideId:",o),await H())}catch(r){console.error("[Login] Failed to upload guest files:",r)}if(!o)try{const r=L();console.log("[Login] Guest URL found:",r),r&&(o=await O(r,l),console.log("[Login] URL upload success, guideId:",o),M())}catch(r){console.error("[Login] Failed to upload guest URL:",r)}let i=d;if(i&&i.startsWith("/invite/")){const r=i.replace("/invite/","");try{i=`/guide/${(await de(r,l)).guide_slug}`}catch(_){console.error("[Login] Failed to claim share:",_)}}const t=document.createElement("link");t.rel="preconnect",t.href=p,document.head.appendChild(t);let g=`${p}/auth-callback#access_token=${l}&refresh_token=${c}`;o?g+=`&redirect=${encodeURIComponent(`/processing/${o}`)}`:i&&(g+=`&redirect=${encodeURIComponent(i)}`),console.log("[Login] Redirect URL (sanitized):",g.replace(/access_token=[^&]+/,"AT=***").replace(/refresh_token=[^&]+/,"RT=***")),window.location.href=g}catch(s){m(s.message||"Failed to sign in"),R(!1)}},X=async()=>{m(""),G(!0);try{await D(d||void 0,se()||void 0)}catch(a){m(a.message||"Failed to sign in with Google"),G(!1)}};return x||f?e.jsxs("div",{className:`min-h-screen flex flex-col items-center justify-center gap-3 ${h.authPageBg}`,children:[e.jsx(w,{className:"h-8 w-8 animate-spin text-primary"}),F&&e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:F})]}):e.jsxs("div",{className:`min-h-screen flex items-center justify-center ${h.authPageBg} px-4`,children:[e.jsx(ee,{title:"Sign In",description:"Sign in to your Tutoremy AI account to access your study guides, notes, flashcards, and quizzes.",canonicalUrl:"https://www.tutoremy.ai/login"}),e.jsxs(re,{className:"w-full max-w-md",children:[($||J)&&e.jsx("div",{className:"mx-6 mt-6 rounded-lg bg-primary/10 border border-primary/20 px-4 py-3 text-center",children:e.jsx("p",{className:"text-sm font-semibold text-primary",children:$?"Your file is ready! Sign in to start generating your study guide.":"Your link is ready! Sign in to start generating your study guide."})}),e.jsxs(ae,{className:"text-center",children:[e.jsxs(N,{to:"/",className:"flex items-center justify-center gap-2 mb-4",children:[e.jsx("img",{src:"/tutoremy-icon.png",alt:"Tutoremy AI",className:"h-10 w-10 rounded-lg"}),e.jsx("span",{className:"text-2xl font-bold",children:"Tutoremy AI"})]}),e.jsx(oe,{className:"text-2xl",children:"Welcome back"}),e.jsx(ie,{children:"Sign in to your account to continue"})]}),e.jsxs(ne,{className:"space-y-4",children:[I&&e.jsx("div",{className:`p-3 text-sm ${h.error.text} ${h.error.bg} rounded-lg`,children:I}),e.jsxs(A,{variant:"outline",className:"w-full gap-2",onClick:X,disabled:j||u,children:[j?e.jsx(w,{className:"h-4 w-4 animate-spin"}):e.jsxs("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"currentColor",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"currentColor",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"currentColor",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"currentColor",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),"Continue with Google"]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx(ce,{})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-card px-2 text-muted-foreground",children:"Or continue with email"})})]}),e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"email",children:"Email"}),e.jsx(T,{id:"email",type:"email",placeholder:"[email protected]",value:U,onChange:a=>W(a.target.value),required:!0,disabled:u})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(z,{htmlFor:"password",children:"Password"}),e.jsx(N,{to:"/forgot-password",className:"text-xs text-primary hover:underline",children:"Forgot password?"})]}),e.jsx(T,{id:"password",type:"password",placeholder:"Enter your password",value:k,onChange:a=>Y(a.target.value),required:!0,disabled:u})]}),e.jsxs(A,{type:"submit",className:"w-full gap-2",disabled:u||j,children:[u?e.jsx(w,{className:"h-4 w-4 animate-spin"}):e.jsx(ue,{className:"h-4 w-4"}),"Sign in with Email"]})]})]}),e.jsx(le,{className:"flex justify-center",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Don't have an account?"," ",e.jsx(N,{to:d?`/signup?redirect=${encodeURIComponent(d)}`:"/signup",className:"text-primary hover:underline font-medium",children:"Sign up"})]})})]})]})}export{ve 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.