import{o as e,r as t,t as n}from"./jsx-runtime-Bypl69v7.js";import{I as r,a as i,t as a,w as o}from"./index-BMtPAEHs.js";import{a as s,t as c}from"./button-CYVyx32W.js";import{t as l}from"./card-G-t986iA.js";import{t as u}from"./activity-Bc-_WW8j.js";import{t as d}from"./eye-DQg-cChu.js";import{t as f}from"./input-Blqy6hlU.js";import{t as p}from"./label-DMknkB96.js";import{i as m,r as h,t as g}from"./tabs-rCHw_sc3.js";var _=s(`eye-off`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),v=e(t()),y=n();function b(){let e=r(),[t,n]=(0,v.useState)(`signin`),[s,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(``),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,A]=(0,v.useState)(!1);async function j(n){n.preventDefault(),A(!0);try{if(t===`signin`){let{error:e}=await o.auth.signInWithPassword({email:s,password:x});if(e)throw e;i.success(`Signed in`)}else{let{data:e,error:t}=await o.auth.signUp({email:s,password:x,options:{emailRedirectTo:window.location.origin,data:{full_name:D||T,nickname:D}}});if(t)throw t;e.user&&D&&await o.from(`profiles`).update({full_name:D}).eq(`id`,e.user.id),i.success(`Account created`)}a(),e.navigate({to:`/dashboard`,replace:!0})}catch(e){i.error(e.message??`Auth failed`)}finally{A(!1)}}return(0,y.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-6`,children:(0,y.jsxs)(l,{className:`w-full max-w-md p-8`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,y.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-primary/15 flex items-center justify-center`,children:(0,y.jsx)(u,{className:`w-5 h-5 text-primary`})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h1`,{className:`font-display text-xl font-semibold leading-tight`,children:`Performance Tracker`}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Sign in to your workspace`})]})]}),(0,y.jsxs)(g,{value:t,onValueChange:e=>n(e),children:[(0,y.jsxs)(h,{className:`grid grid-cols-2 w-full`,children:[(0,y.jsx)(m,{value:`signin`,children:`Sign in`}),(0,y.jsx)(m,{value:`signup`,children:`Create account`})]}),(0,y.jsxs)(`form`,{onSubmit:j,className:`space-y-4 mt-6`,children:[t===`signup`&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsx)(p,{htmlFor:`name`,children:`Full name`}),(0,y.jsx)(f,{id:`name`,value:T,onChange:e=>E(e.target.value),required:!0})]}),(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(p,{htmlFor:`nickname`,children:[`Nickname `,(0,y.jsx)(`span`,{className:`text-muted-foreground`,children:`(shown on your profile)`})]}),(0,y.jsx)(f,{id:`nickname`,value:D,onChange:e=>O(e.target.value),placeholder:`e.g. Alex`,required:!0})]})]}),(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsx)(p,{htmlFor:`email`,children:`Email`}),(0,y.jsx)(f,{id:`email`,type:`email`,value:s,onChange:e=>b(e.target.value),required:!0,autoComplete:`email`})]}),(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsx)(p,{htmlFor:`password`,children:`Password`}),(0,y.jsxs)(`div`,{className:`relative`,children:[(0,y.jsx)(f,{id:`password`,type:C?`text`:`password`,value:x,onChange:e=>S(e.target.value),required:!0,minLength:6,autoComplete:t===`signin`?`current-password`:`new-password`,className:`pr-10`}),(0,y.jsx)(`button`,{type:`button`,onClick:()=>w(e=>!e),"aria-label":C?`Hide password`:`Show password`,className:`absolute inset-y-0 right-0 flex items-center px-3 text-muted-foreground hover:text-foreground`,children:C?(0,y.jsx)(_,{className:`w-4 h-4`}):(0,y.jsx)(d,{className:`w-4 h-4`})})]})]}),(0,y.jsx)(c,{type:`submit`,disabled:k,className:`w-full`,children:k?`Please wait…`:t===`signin`?`Sign in`:`Create account`}),t===`signup`&&(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:`The first account created becomes the administrator.`})]})]}),(0,y.jsx)(`p`,{className:`text-xs text-muted-foreground text-center mt-6`,children:`Explore the calculation guide from Settings after signing in.`})]})})}export{b as component};