'use client';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState } from 'react';
import { Shield, ArrowLeft, Loader2, CheckCircle2, AlertTriangle } from 'lucide-react';
import { cmsApi } from '../lib/api.js';
const fieldClass = 'w-full rounded-lg border border-border bg-input-background px-3 py-2.5 text-sm text-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:outline-none';
export function ForgotPassword({ onNavigate }) {
    const [email, setEmail] = useState('');
    const [submitting, setSubmitting] = useState(false);
    const [sent, setSent] = useState(false);
    const [error, setError] = useState('');
    const canSubmit = email.trim() && !submitting;
    const handleSubmit = async (e) => {
        e.preventDefault();
        if (!canSubmit)
            return;
        setError('');
        setSubmitting(true);
        try {
            const result = await cmsApi('/auth/forgot-password', {
                method: 'POST',
                body: JSON.stringify({ email: email.trim() }),
            });
            if (result.error && result.status === 429) {
                setError('Too many requests. Please try again later.');
            }
            else {
                setSent(true);
            }
        }
        catch {
            setError('An unexpected error occurred. Please try again.');
        }
        finally {
            setSubmitting(false);
        }
    };
    return (_jsx("div", { className: "bg-muted flex min-h-screen items-center justify-center px-4", children: _jsxs("div", { className: "w-full max-w-md", children: [_jsxs("div", { className: "mb-8 text-center", children: [_jsx("div", { className: "bg-primary mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-xl", children: _jsx(Shield, { className: "text-primary-foreground h-7 w-7" }) }), _jsx("h1", { className: "text-foreground text-2xl font-medium", children: "Reset Password" }), _jsx("p", { className: "text-muted-foreground mt-2", children: sent
                                ? 'Check your inbox for a reset link'
                                : "Enter your email and we'll send you a reset link" })] }), _jsxs("div", { className: "border-border bg-card space-y-5 rounded-xl border p-6 shadow-sm", children: [sent ? (_jsxs("div", { className: "space-y-4 text-center", children: [_jsx("div", { className: "bg-success/10 mx-auto flex h-12 w-12 items-center justify-center rounded-full", children: _jsx(CheckCircle2, { className: "text-success h-6 w-6" }) }), _jsxs("p", { className: "text-muted-foreground text-sm", children: ["If an account exists for ", _jsx("strong", { children: email }), ", you will receive a password reset email shortly."] }), _jsx("p", { className: "text-muted-foreground text-xs", children: "The link expires in 1 hour. Check your spam folder if you don't see it." }), _jsx("button", { type: "button", onClick: () => onNavigate('/login'), className: "bg-primary text-primary-foreground hover:bg-primary/90 w-full rounded-lg py-2.5 font-medium transition-colors", children: "Back to Sign In" })] })) : (_jsxs("form", { onSubmit: handleSubmit, className: "space-y-5", children: [error && (_jsxs("div", { className: "border-destructive/30 bg-destructive/10 flex items-start gap-3 rounded-lg border p-3", children: [_jsx(AlertTriangle, { className: "text-destructive mt-0.5 h-5 w-5 shrink-0" }), _jsx("p", { className: "text-destructive text-sm", children: error })] })), _jsxs("div", { children: [_jsx("label", { htmlFor: "forgot-email", className: "text-foreground mb-1.5 block text-sm font-medium", children: "Email Address" }), _jsx("input", { id: "forgot-email", type: "email", value: email, onChange: (e) => setEmail(e.target.value), placeholder: "admin@example.com", className: fieldClass, required: true, autoFocus: true, autoComplete: "email" })] }), _jsx("button", { type: "submit", disabled: !canSubmit, className: "bg-primary text-primary-foreground hover:bg-primary/90 flex w-full items-center justify-center gap-2 rounded-lg py-2.5 font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50", children: submitting ? (_jsxs(_Fragment, { children: [_jsx(Loader2, { className: "h-4 w-4 animate-spin" }), "Sending..."] })) : ('Send Reset Link') })] })), !sent && (_jsxs("button", { type: "button", onClick: () => onNavigate('/login'), className: "text-muted-foreground hover:text-foreground flex w-full items-center justify-center gap-2 text-sm transition-colors", children: [_jsx(ArrowLeft, { className: "h-4 w-4" }), "Back to Sign In"] }))] })] }) }));
}
//# sourceMappingURL=ForgotPassword.js.map