1import{c as B,r as d,j as e,L as P,I as E,B as w,E as H,S as A,a as T,u as I,D as W,b as $,d as z,e as Y,f as K,h as J,X as O,g as X,A as Z,k as Q,l as V,m as U,n as D,R as C,o as ee,p as te,q as se,C as ae,s as re,t as oe}from"./index-3729243f.js";import{M}from"./mail-01e3ba22.js";import{L as le,E as ie}from"./lock-3cfc180b.js";import{K as ne}from"./key-round-f9589ab8.js";const ce=B("Send",[["path",{d:"m22 2-7 20-4-9-9-4Z",key:"1q3vgg"}],["path",{d:"M22 2 11 13",key:"nzbqef"}]]),de=({isSignUp:t,onSubmit:i,loading:r,onForgotPassword:m})=>{const[s,u]=d.useState(""),[a,p]=d.useState(""),[o,l]=d.useState(!1),y=n=>{n.preventDefault(),i(s,a)};return e.jsxs("form",{onSubmit:y,className:"space-y-5 text-left",children:[e.jsxs("div",{children:[e.jsx(P,{htmlFor:"email",className:"text-[hsl(var(--royaltix-text-secondary))]",children:"Email"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(M,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-[hsl(var(--royaltix-text-muted))]"}),e.jsx(E,{id:"email",type:"email",placeholder:"[email protected]",value:s,onChange:n=>u(n.target.value),required:!0,className:"pl-10 bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] text-[hsl(var(--royaltix-text-primary))] placeholder:text-[hsl(var(--royaltix-text-muted))]"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(P,{htmlFor:"password",className:"text-[hsl(var(--royaltix-text-secondary))]",children:"Password"}),!t&&e.jsx(w,{type:"button",variant:"link",onClick:m,className:"text-xs text-[hsl(var(--royaltix-accent))] hover:text-[hsl(var(--royaltix-accent)_/_0.8)] p-0 h-auto",disabled:r,children:"Forgot Password?"})]}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(le,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-[hsl(var(--royaltix-text-muted))]"}),e.jsx(E,{id:"password",type:o?"text":"password",placeholder:"Minimum 8 characters",value:a,onChange:n=>p(n.target.value),required:!0,className:"pl-10 pr-10 bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] text-[hsl(var(--royaltix-text-primary))] placeholder:text-[hsl(var(--royaltix-text-muted))]"}),e.jsx("button",{type:"button",onClick:()=>l(!o),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[hsl(var(--royaltix-text-muted))] hover:text-[hsl(var(--royaltix-text-primary))]","aria-label":o?"Hide password":"Show password",children:o?e.jsx(ie,{className:"h-5 w-5"}):e.jsx(H,{className:"h-5 w-5"})})]}),t&&e.jsx("p",{className:"text-xs text-[hsl(var(--royaltix-text-muted))] mt-1.5",children:"Minimum 8 characters, include uppercase, lowercase, number, and symbol for strong password."})]}),e.jsx(w,{type:"submit",disabled:r,className:"w-full bg-[hsl(var(--royaltix-primary))] hover:bg-[hsl(var(--royaltix-primary)_/_0.9)] text-[hsl(var(--background))] py-3 text-base font-semibold",children:r?t?"Creating Account...":"Signing In...":t?"Sign Up & Get Started":"Sign In"})]})},ue=({providerName:t,onSignIn:i,loading:r,icon:m})=>{const s=m||A;return e.jsxs(w,{onClick:i,disabled:r,variant:"outline",className:"w-full border-[hsl(var(--royaltix-card-border))] hover:border-[hsl(var(--royaltix-accent))] text-[hsl(var(--royaltix-text-secondary))] hover:text-[hsl(var(--royaltix-text-primary))] py-2.5 text-base",children:[e.jsx(s,{className:"mr-2 h-5 w-5 text-red-500"})," Sign In with ",t]})},me=({open:t,onOpenChange:i})=>{const[r,m]=d.useState(""),[s,u]=d.useState(!1),{toast:a}=T(),{resetPasswordForEmail:p}=I(),o=async l=>{if(l.preventDefault(),!r){a({title:"Email Required",description:"Please enter your email address.",variant:"destructive"});return}u(!0);const{error:y}=await p(r,{redirectTo:`${window.location.origin}/update-password`});y?a({title:"Password Reset Error",description:y.message,variant:"destructive"}):(a({title:"Password Reset Email Sent",description:"If an account exists for this email, a password reset link has been sent. Please check your inbox (and spam folder). The link is valid for a limited time.",className:"bg-blue-600 text-white border-blue-600",duration:7e3}),i(!1),m("")),u(!1)};return e.jsx(W,{open:t,onOpenChange:l=>{l||(m(""),u(!1)),i(l)},children:e.jsxs($,{className:"sm:max-w-md bg-[hsl(var(--royaltix-card-bg))] border-[hsl(var(--royaltix-card-border))] p-0 shadow-xl",children:[e.jsxs(z,{className:"p-6 pb-4 border-b border-[hsl(var(--royaltix-card-border)_/_0.7)] relative",children:[e.jsxs(Y,{className:"text-[hsl(var(--royaltix-text-primary))] flex items-center text-lg font-semibold",children:[e.jsx(ne,{className:"mr-2.5 h-5 w-5 text-[hsl(var(--royaltix-accent))]"})," Reset Your Password"]}),e.jsx(K,{className:"text-[hsl(var(--royaltix-text-muted))] pt-1 text-sm",children:"Enter your email. If an account exists, we'll send a reset link."}),e.jsx(J,{asChild:!0,className:"absolute right-4 top-4",children:e.jsxs(w,{variant:"ghost",size:"icon",className:"text-[hsl(var(--royaltix-text-secondary))] hover:text-[hsl(var(--royaltix-text-primary))] hover:bg-[hsl(var(--royaltix-accent)_/_0.1)] rounded-full",children:[e.jsx(O,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})})]}),e.jsxs("form",{onSubmit:o,className:"space-y-5 p-6",children:[e.jsxs("div",{children:[e.jsx(P,{htmlFor:"forgot-email-dialog",className:"text-[hsl(var(--royaltix-text-secondary))] text-sm",children:"Email Address"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(M,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-[hsl(var(--royaltix-text-muted))]"}),e.jsx(E,{id:"forgot-email-dialog",type:"email",placeholder:"[email protected]",value:r,onChange:l=>m(l.target.value),required:!0,className:"pl-10 bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] text-[hsl(var(--royaltix-text-primary))] placeholder:text-[hsl(var(--royaltix-text-muted))]"})]})]}),e.jsxs(X,{className:"sm:justify-start pt-2 !mt-6",children:[e.jsx(w,{type:"submit",disabled:s,className:"w-full sm:w-auto bg-[hsl(var(--royaltix-primary))] hover:bg-[hsl(var(--royaltix-primary)_/_0.9)] text-[hsl(var(--background))] py-2.5 text-sm font-medium",children:s?"Sending...":e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"mr-2 h-4 w-4"})," Send Reset Link"]})}),e.jsx(w,{type:"button",variant:"outline",onClick:()=>i(!1),className:"w-full sm:w-auto mt-2 sm:mt-0 border-[hsl(var(--royaltix-card-border))] text-[hsl(var(--royaltix-text-secondary))] hover:text-[hsl(var(--royaltix-text-primary))] hover:border-[hsl(var(--royaltix-accent)_/_0.7)] py-2.5 text-sm",children:"Cancel"})]})]})]})})},_=({type:t,title:i,description:r})=>{const m=t==="info"||t==="success"?A:U;let s="destructive",u="text-red-600";return t==="info"||t==="success"?(s="bg-blue-500/10 border-blue-500/30 text-blue-700 dark:text-blue-400",u="text-blue-600"):t==="warning"&&(s="bg-yellow-500/10 border-yellow-500/30 text-yellow-700 dark:text-yellow-400",u="text-yellow-600"),e.jsxs(Z,{variant:s==="destructive"?"destructive":"default",className:`mb-4 text-left ${s}`,children:[e.jsx(m,{className:`h-4 w-4 ${u}`}),e.jsx(Q,{className:s!=="destructive"?"dark:text-inherit":"",children:i}),e.jsx(V,{className:s!=="destructive"?"dark:text-inherit":"",children:r})]})},xe=()=>{const{signInWithGoogle:t,signInWithPassword:i,signUp:r}=I(),m=D(),{toast:s}=T(),[u,a]=d.useState(!1),[p,o]=d.useState(null);return{loading:u,error:p,setError:o,handleGoogleSignIn:async()=>{a(!0),o(null);const{error:n}=await t({options:{redirectTo:`${window.location.origin}/`}});n&&(o(n.message),s({title:"Google Sign-In Error",description:n.message,variant:"destructive"})),a(!1)},handleEmailPasswordAuth:async(n,j,N)=>{a(!0),o(null);try{let b;const g={emailRedirectTo:`${window.location.origin}/`};N?b=await r({email:n,password:j,options:g}):b=await i({email:n,password:j});const{error:h,data:c}=b;if(h){let x=h.message;return h.message.toLowerCase().includes("user already registered")?x="This email is already registered. Please try logging in or use a different email.":h.message.toLowerCase().includes("invalid login credentials")?x="Invalid email or password. Please check your credentials and try again.":h.message.toLowerCase().includes("database error saving new user")?x="A server error occurred while creating your account. Please try again later or contact support if the issue persists.":h.message.toLowerCase().includes("email link sign up disabled")&&(x="Sign up with email link is currently disabled. Please contact support."),o(x),s({title:"Authentication
1Error",description:x,variant:"destructive"}),a(!1),{success:!1,errorMessage:x,errorType:h.message.includes("confirm your email")?"unconfirmed_email":"generic"}}if(N&&(c!=null&&c.user)&&c.user.identities&&c.user.identities.length>0&&!c.session)return s({title:"Confirmation Email Sent!",description:"Please check your email to confirm your account before logging in. The link is valid for 24 hours.",className:"bg-blue-500 text-white border-blue-500",duration:1e4}),a(!1),{success:!0,needsConfirmation:!0};if(c!=null&&c.user&&c.session)return m("/"),s({title:"Successfully Signed In!",description:"Welcome back to Royaltix.io.",className:"bg-green-500 text-white border-green-500"}),a(!1),{success:!0};if(!N&&(c!=null&&c.user)&&!c.session){const x="Your email address has not been confirmed. Please check your inbox for the confirmation link.";return o(x),s({title:"Email Confirmation Required",description:x,variant:"destructive",duration:7e3}),a(!1),{success:!1,needsConfirmation:!0,errorMessage:x,errorType:"unconfirmed_email"}}const S="An unexpected issue occurred during authentication. Please try again.";o(S),s({title:"Authentication Issue",description:S,variant:"destructive"})}catch(b){const g=b.message||"An unexpected error occurred. Please try again.";o(g),s({title:"Error",description:g,variant:"destructive"})}return a(!1),{success:!1,errorMessage:p||"An unknown error occurred."}}}},R=C.memo(()=>e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(ee,{className:"h-12 w-auto text-[hsl(var(--royaltix-accent))]"})}));R.displayName="PageHeader";const F=C.memo(({isSignUp:t})=>e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold text-[hsl(var(--royaltix-text-primary))] mb-2",children:t?"Create Your Account":"Welcome Back!"}),e.jsx("p",{className:"text-sm text-[hsl(var(--royaltix-text-secondary))] mb-6 sm:mb-8",children:t?"Join Royaltix.io to manage your royalties effortlessly.":"Sign in to access your dashboard."})]}));F.displayName="PageTitle";const L=C.memo(()=>e.jsxs("div",{className:"my-6 flex items-center",children:[e.jsx("div",{className:"flex-grow border-t border-[hsl(var(--royaltix-card-border)_/_0.5)]"}),e.jsx("span",{className:"mx-4 text-xs text-[hsl(var(--royaltix-text-muted))] uppercase",children:"Or"}),e.jsx("div",{className:"flex-grow border-t border-[hsl(var(--royaltix-card-border)_/_0.5)]"})]}));L.displayName="DividerWithText";const q=C.memo(({isSignUp:t,onToggle:i,loading:r})=>e.jsxs("p",{className:"text-sm text-[hsl(var(--royaltix-text-secondary))] mt-8",children:[t?"Already have an account?":"Don't have an account?",e.jsx(w,{variant:"link",onClick:i,className:"font-semibold text-[hsl(var(--royaltix-accent))] hover:text-[hsl(var(--royaltix-accent)_/_0.8)] pl-1.5",disabled:r,children:t?"Sign In":"Sign Up"})]}));q.displayName="ToggleAuthMode";const fe=()=>{const{loading:t,error:i,setError:r,handleGoogleSignIn:m,handleEmailPasswordAuth:s}=xe(),{session:u,user:a,setShowDisplayNameModal:p}=I(),o=D(),l=te(),[y,n]=d.useState(!1),j=d.useRef(!1),[N,b]=d.useState(!1),[g,h]=d.useState(null);d.useEffect(()=>{var f;j.current||((f=l==null?void 0:l.state)!=null&&f.signup&&n(!0),j.current=!0)},[l==null?void 0:l.state]),d.useEffect(()=>{var f,k,v;if(u&&a){(f=a.user_metadata)!=null&&f.display_name||p(!0);const G=((v=(k=l.state)==null?void 0:k.from)==null?void 0:v.pathname)||"/";o(G,{replace:!0})}},[u,a,o,l.state,p]);const c=d.useCallback(()=>{n(f=>!f),r(null),h(null)},[r]),S=async(f,k)=>{h(null);const v=await s(f,k,y);v.success&&v.needsConfirmation?(h({type:"info",title:"Confirmation Email Sent",description:"Please check your email to confirm your account. This link is valid for 24 hours. If you don't see it, check your spam folder."}),n(!1)):!v.success&&v.errorType==="unconfirmed_email"?h({type:"warning",title:"Email Confirmation Required",description:"Your email address has not been confirmed. Please check your inbox (and spam folder) for the confirmation link. If you can't find it, you can try signing up again to receive a new link or request a password reset to get a new confirmation."}):!v.success&&v.errorMessage},x=d.useCallback(()=>b(!0),[]);return e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-screen bg-gradient-to-br from-[hsl(var(--royaltix-bg-start))] to-[hsl(var(--royaltix-bg-end))] p-4 sm:p-6 text-center",children:[e.jsx(se.div,{initial:{opacity:0,y:-20}
1,animate:{opacity:1,y:0},transition:{duration:.5},className:"w-full max-w-md",children:e.jsxs(ae,{className:"bg-[hsl(var(--royaltix-card-bg))] border-[hsl(var(--royaltix-card-border))] shadow-2xl",children:[e.jsxs(re,{className:"pt-8 sm:pt-10",children:[e.jsx(R,{}),e.jsx(F,{isSignUp:y})]}),e.jsxs(oe,{className:"px-6 sm:px-8 pb-8 sm:pb-10",children:[i&&!g&&e.jsx(_,{type:"error",title:"Authentication Error",description:i}),g&&e.jsx(_,{type:g.type,title:g.title,description:g.description}),e.jsx(de,{isSignUp:y,onSubmit:S,loading:t,onForgotPassword:x}),e.jsx(L,{}),e.jsx(ue,{providerName:"Google",onSignIn:m,loading:t,icon:A}),e.jsx(q,{isSignUp:y,onToggle:c,loading:t})]})]})}),e.jsx(me,{open:N,onOpenChange:b})]})};export{fe 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.