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

export default function RegisterPage() {
  const [name, setName] = useState("");
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");
  const [confirm, setConfirm] = useState("");
  const [loading, setLoading] = useState(false);

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    if (!email || !password) {
      toast.error("Fill in all required fields.");
      return;
    }
    if (password !== confirm) {
      toast.error("Passwords do not match.");
      return;
    }
    setLoading(true);
    await new Promise((r) => setTimeout(r, 800));
    toast.info("Registration 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">Create account</h2>
          <p className="text-xs text-muted-foreground">Sign up for a new Athena Studio account.</p>
        </div>
        <div className="space-y-3">
          <div className="space-y-1.5">
            <label className="text-xs font-medium text-foreground">Full name</label>
            <Input placeholder="Jane Doe" value={name} onChange={(e) => setName(e.target.value)} className="h-9 text-xs" autoComplete="name" />
          </div>
          <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 className="space-y-1.5">
            <label className="text-xs font-medium text-foreground">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" /> : <UserPlus className="h-3 w-3 mr-1.5" />}
          {loading ? "Creating account…" : "Create account"}
        </Button>
      </div>
      <p className="text-center text-xs text-muted-foreground">
        Already have an account?{" "}
        <Link href="/auth/login" className="text-primary hover:underline">Sign in</Link>
      </p>
    </form>
  );
}
