1import{j as e}from"./ui-COXWRdUa.js";import{r as a,c as s,L as t}from"./vendor-C6kxpFEM.js";import{aJ as r,C as n,m as i,av as l,n as o,ak as c,d as m,ap as d,am as x,B as h,a8 as u,aK as g,r as j}from"./index-DRM4XvH1.js";import{C as f}from"./checkbox-CqigAroD.js";import{A as p,a as b}from"./alert--FAOL8z9.js";import{S as v}from"./shield-alert-C9SupmCe.js";import{C as y}from"./circle-alert-B_G0VfyF.js";import"./index-CPlxMcEQ.js";function N(){const[N,w]=a.useState(""),[k,S]=a.useState(""),[C,F]=a.useState(!1),[P,E]=a.useState(""),[T,I]=a.useState(!1),[A,q]=a.useState(!1),[B,D]=a.useState(null),{signIn:L}=r(),R=s(),U=e=>{e.message.includes("Invalid login credentials")?E("Invalid email or password. Please try again."):e.message.includes("Email not confirmed")?E("Please verify your email before logging in."):e.message.includes("Failed to fetch")||e.message.includes("NetworkError")?E("Unable to connect to the server. Please check your internet connection and try again."):e.message.includes("Too many")?(q(!0),E(e.message)):E(e.message)};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-100 to-slate-200 p-4",children:e.jsxs(n,{className:"w-full max-w-md
1shadow-xl border-0",children:[e.jsxs(i,{className:"text-center pb-2",children:[e.jsx("div",{className:"mx-auto mb-4",children:e.jsx("img",{src:l,alt:"USA Ninja Challenge",className:"h-20 w-auto"})}),e.jsx(o,{className:"text-2xl font-bold text-[#1a365d]",children:"Franchisee Portal"}),e.jsx(c,{children:"Sign in to manage your location's content"})]}),e.jsx(m,{children:e.jsxs("form",{onSubmit:async e=>{e.preventDefault(),E(""),D(null),I(!0),q(!1);try{const{data:e,error:a}=await j.functions.invoke("auth-rate-limit",{body:{action:"check",metadata:{actionType:"login"}}});if(!a&&e&&!e.allowed)return q(!0),D(0),E(`Too many login attempts. Please try again in ${e.retryAfterMinutes} minutes.`),void I(!1);const{error:s}=await L(N,k,C);if(s){await j.functions.invoke("auth-rate-limit",{body:{action:"record_attempt",metadata:{actionType:"login"}}}).catch(()=>{});const a=null!=(null==e?void 0:e.remaining)?e.remaining-1:null;return D(a),void U(s)}R("/dashboard")}catch(a){U(a)}finally{I(!1)}},className:"space-y-4",children:[A&&e.jsxs(p,{variant:"destructive",className:"bg-amber-50 border-amber-200",children:[e.jsx(v,{className:"h-4 w-4 text-amber-600"}),e.jsx(b,{className:"text-amber-800",children:P})]}),P&&!A&&e.jsxs(p,{variant:"destructive",children:[e.jsx(y,{className:"h-4 w-4"}),e.jsxs(b,{children:[P,null!==B&&B>0&&e.jsxs("span",{className:"block mt-1 text-xs",children:[B," attempt",1!==B?"s":""," remaining before lockout."]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"email",children:"Email"}),e.jsx(x,{id:"email",type:"email",placeholder:"[email protected]",value:N,onChange:e=>w(e.target.value),required:!0,disabled:T||A})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"password",children:"Password"}),e.jsx(x,{id:"password",type:"password",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",value:k,onChange:e=>S(e.target.value),required:!0,disabled:T||A})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(f,{id:"remember",checked:C,onCheckedChange:e=>F(!0===e),disabled:A}),e.jsx(d,{htmlFor:"remember",className:"text-sm font-normal cursor-pointer",children:"Remember me for 30 days"})]}),e.jsx(t,{to:"/cms/forgot-password",className:"text-sm text-[#00509E] hover:underline",children:"Forgot password?"})]}),e.jsx(h,{type:"submit",className:"w-full bg-[#1a365d] hover:bg-[#1a365d]/90",disabled:T||A,children:T?e.jsxs(e.Fragment,{children:[e.jsx(u,{className:"mr-2 h-4 w-4 animate-spin"}),"Signing in..."]}):A?"Temporarily Locked":"Sign In"})]})}),e.jsxs(g,{className:"flex flex-col gap-4 border-t pt-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground text-center",children:["Don't have an account?"," ",e.jsx(t,{to:"/cms/register",className:"text-[#00509E] hover:underline font-medium",children:"Register here"})]}),e.jsx(t,{to:"/",className:"text-sm text-muted-foreground hover:text-foreground text-center",children:"â Back to main website"})]})]})})}export{N 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.