"use client";

import React, { useState } from "react";
import axios from "axios";

export default function ForgotPasswordForm() {
  const [email, setEmail] = useState("");
  const [loading, setLoading] = useState(false);
  const [message, setMessage] = useState("");

  const handleForgot = async (e: React.FormEvent) => {
    e.preventDefault();
    setLoading(true);
    setMessage("");
    try {
      const res = await axios.post("http://localhost:3050/api/auth/forgot-password", { email });
      setMessage("✅ We’ve emailed you a reset code / link. Enter it below.");
    } catch (err: any) {
      console.error(err);
      setMessage("Something went wrong. Try again.");
    } finally {
      setLoading(false);
    }
  };

  return (
    <form onSubmit={handleForgot} className="space-y-5">
      <div>
        <label className="block text-sm font-medium text-white-dark mb-1">
          Email
        </label>
        <input
          type="email"
          required
          value={email}
          onChange={(e) => setEmail(e.target.value)}
          className="form-input ps-10 placeholder:text-white-dark"
          placeholder="you@example.com"
        />
      </div>
     <button
            type="submit"
            disabled={loading}
            className="btn w-full border-0 uppercase shadow-[0_10px_20px_-10px_rgba(232,87,42,0.44)] disabled:cursor-not-allowed disabled:opacity-70 !mt-6 !mb-4 bg-[linear-gradient(135deg,#e8572a_0%,#0f2444_100%)] text-white hover:bg-[linear-gradient(135deg,#0f2444_0%,#e8572a_100%)]"
            >
        {loading ? "Sending..." : "Send Reset Link"}
      </button>
      {message && <p className="mt-2 text-center text-sm font-semibold text-primary">{message}</p>}
    </form>
  );
}
