"use client";

import { useState } from "react";
import Link from "next/link";
import { Button } from "@/app/components/ui/button";
import { Input } from "@/app/components/ui/input";
import { toast } from "sonner";
import { Loader2, Mail } from "lucide-react";

export default function ForgotPasswordPage() {
  const [email, setEmail] = useState("");
  const [loading, setLoading] = useState(false);
  const [sent, setSent] = useState(false);

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    if (!email) {
      toast.error("Enter your email address.");
      return;
    }
    setLoading(true);
    await new Promise((r) => setTimeout(r, 800));
    setSent(true);
    toast.info("Password reset is not yet connected. This is a stub page.");
    setLoading(false);
  };

  return (
    <form onSubmit={handleSubmit} className="space-y-4">
      <div className="rounded-lg border border-border bg-card p-6 space-y-4 shadow-sm">
        <div className="space-y-1">
          <h2 className="text-sm font-semibold text-foreground">
            Reset password
          </h2>
          <p className="text-xs text-muted-foreground">
            Enter your email and we&apos;ll send you a reset link.
          </p>
        </div>
        {sent ? (
          <div className="rounded-lg bg-success-subtle border border-success-border p-4 text-center space-y-1">
            <Mail className="h-5 w-5 text-success mx-auto" />
            <p className="text-xs font-medium text-foreground">
              Check your email
            </p>
            <p className="text-body-sm text-muted-foreground">
              If an account exists for {email}, you will receive a reset link.
            </p>
          </div>
        ) : (
          <div className="space-y-3">
            <div className="space-y-1.5">
              <label className="text-xs font-medium text-foreground">
                Email
              </label>
              <Input
                type="email"
                placeholder="you@example.com"
                value={email}
                onChange={(e) => setEmail(e.target.value)}
                className="h-9 text-xs"
                autoComplete="email"
              />
            </div>
          </div>
        )}
        {!sent && (
          <Button
            type="submit"
            disabled={loading}
            className="w-full h-9 text-xs"
          >
            {loading ? (
              <Loader2 className="h-3 w-3 animate-spin mr-1.5" />
            ) : (
              <Mail className="h-3 w-3 mr-1.5" />
            )}
            {loading ? "Sending…" : "Send reset link"}
          </Button>
        )}
      </div>
      <p className="text-center text-xs text-muted-foreground">
        <Link href="/auth/login" className="text-primary hover:underline">
          Back to sign in
        </Link>
      </p>
    </form>
  );
}
