import Link from "next/link";
import { signup } from "./actions";

export default async function SignupPage({
  searchParams,
}: {
  searchParams?: Promise<{ [key: string]: string | string[] | undefined }>
}) {
  const params = await searchParams;
  const error = params?.error as string | undefined;
  const message = params?.message as string | undefined;

  return (
    <>
      {/* TopAppBar */}
      <header className="bg-[#131313] flex justify-between items-center px-8 h-[72px] w-full docked full-width top-0 z-50">
        <div className="flex items-center gap-4">
          <Link href="/login">
            <span className="material-symbols-outlined text-[#CCFF00] cursor-pointer hover:opacity-80 transition-opacity active:scale-95 duration-200">
              arrow_back
            </span>
          </Link>
          <span className="text-[#CCFF00] font-bold tracking-tight text-2xl uppercase font-headline">
            VivaFit 50+
          </span>
        </div>
      </header>

      <main className="grow flex items-center justify-center px-6 py-12 bg-hero-pattern relative min-h-[calc(100vh-72px)]">
        {/* Signup Card */}
        <div className="w-full max-w-[500px] bg-surface-container-low rounded-[32px] p-8 md:p-12 shadow-2xl backdrop-blur-md bg-opacity-90 border border-white/5">
          <div className="mb-10 text-left">
            <h1 className="font-headline font-bold text-3xl md:text-4xl text-primary leading-tight mb-3">
              Crie Sua Conta
            </h1>
            <p className="font-body text-lg text-on-surface-variant font-medium">
              Comece sua jornada saudável hoje
            </p>
          </div>

          {error && (
            <div className="mb-6 p-4 bg-error-container/20 border border-error/50 rounded-xl text-error text-sm font-bold">
              {error}
            </div>
          )}

          {message && (
            <div className="mb-6 p-4 bg-[#c3f400]/10 border border-[#c3f400]/30 rounded-xl text-[#c3f400] text-sm font-bold">
              {message}
            </div>
          )}

          <form className="space-y-6" action={signup}>
            {/* Name Input */}
            <div className="space-y-2">
              <label
                className="block font-headline font-semibold text-sm uppercase tracking-wider text-on-surface-variant ml-1"
                htmlFor="name"
              >
                Nome
              </label>
              <div className="relative">
                <input
                  className="w-full h-16 bg-surface-container-high border-none rounded-xl px-6 text-lg text-primary focus:ring-2 focus:ring-primary-fixed transition-all placeholder:text-white/20 font-medium"
                  id="name"
                  name="name"
                  placeholder="Seu nome"
                  type="text"
                  required
                />
                <span className="material-symbols-outlined absolute right-5 top-1/2 -translate-y-1/2 text-white/40">
                  person
                </span>
              </div>
            </div>
            
            {/* Email Input */}
            <div className="space-y-2">
              <label
                className="block font-headline font-semibold text-sm uppercase tracking-wider text-on-surface-variant ml-1"
                htmlFor="email"
              >
                E-mail
              </label>
              <div className="relative">
                <input
                  className="w-full h-16 bg-surface-container-high border-none rounded-xl px-6 text-lg text-primary focus:ring-2 focus:ring-primary-fixed transition-all placeholder:text-white/20 font-medium"
                  id="email"
                  name="email"
                  placeholder="seu@email.com"
                  type="email"
                  required
                />
                <span className="material-symbols-outlined absolute right-5 top-1/2 -translate-y-1/2 text-white/40">
                  mail
                </span>
              </div>
            </div>

            {/* Password Input */}
            <div className="space-y-2">
              <label
                className="block font-headline font-semibold text-sm uppercase tracking-wider text-on-surface-variant ml-1"
                htmlFor="password"
              >
                Senha
              </label>
              <div className="relative">
                <input
                  className="w-full h-16 bg-surface-container-high border-none rounded-xl px-6 text-lg text-primary focus:ring-2 focus:ring-primary-fixed transition-all placeholder:text-white/20 font-medium"
                  id="password"
                  name="password"
                  placeholder="••••••••"
                  type="password"
                  required
                  minLength={6}
                />
                <span className="material-symbols-outlined absolute right-5 top-1/2 -translate-y-1/2 text-white/40">
                  lock
                </span>
              </div>
            </div>

            {/* Signup Button */}
            <button
              className="w-full h-[64px] bg-[#CCFF00] text-[#161E00] font-headline font-extrabold text-xl rounded-xl shadow-[0_0_30px_rgba(204,255,0,0.15)] hover:opacity-90 active:scale-[0.98] transition-all flex items-center justify-center gap-3 mt-4"
              type="submit"
            >
              <span>CADASTRAR</span>
              <span className="material-symbols-outlined font-bold">how_to_reg</span>
            </button>
          </form>

          {/* Login Prompt */}
          <div className="mt-8 text-center">
            <p className="text-on-surface-variant font-medium">
              Já tem uma conta?{" "}
              <Link
                href="/login"
                className="text-[#CCFF00] font-bold hover:underline ml-1"
              >
                Faça login
              </Link>
            </p>
          </div>
        </div>
      </main>
    </>
  );
}
