"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, KeyRound } from "lucide-react";

export default function ResetPasswordPage() {
  const [password, setPassword] = useState("");
  const [confirm, setConfirm] = useState("");
  const [loading, setLoading] = useState(false);

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    if (!password) {
      toast.error("Enter a new password.");
      return;
    }
    if (password !== confirm) {
      toast.error("Passwords do not match.");
      return;
    }
    setLoading(true);
    await new Promise((r) => setTimeout(r, 800));
    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">Set new password</h2>
          <p className="text-xs text-muted-foreground">Choose a new password for your account.</p>
        </div>
        <div className="space-y-3">
          <div className="space-y-1.5">
            <label className="text-xs font-medium text-foreground">New password</label>
            <Input type="password" placeholder="••••••••" value={password} onChange={(e) => setPassword(e.target.value)} className="h-9 text-xs" autoComplete="new-password" />
          </div>
          <div className="space-y-1.5">
            <label className="text-xs font-medium text-foreground">Confirm password</label>
            <Input type="password" placeholder="••••••••" value={confirm} onChange={(e) => setConfirm(e.target.value)} className="h-9 text-xs" autoComplete="new-password" />
          </div>
        </div>
        <Button type="submit" disabled={loading} className="w-full h-9 text-xs">
          {loading ? <Loader2 className="h-3 w-3 animate-spin mr-1.5" /> : <KeyRound className="h-3 w-3 mr-1.5" />}
          {loading ? "Updating…" : "Update password"}
        </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>
  );
}
