import Link from "next/link";
import { signup } from "@/features/auth/actions";
import FormMessage from "@/components/form-message";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card";

export default async function SignupPage({
  searchParams,
}: {
  searchParams: Promise<{ message: string }>;
}) {
  const { message } = await searchParams;

  return (
    <div className="relative flex min-h-screen items-center justify-center overflow-hidden bg-gradient-to-br from-indigo-50 via-purple-50 to-pink-50 px-4 py-12 dark:from-gray-950 dark:via-indigo-950 dark:to-purple-950">
      {/* 배경 그라데이션 효과 */}
      <div className="absolute inset-0 bg-[radial-gradient(ellipse_at_top_right,_var(--tw-gradient-stops))] from-indigo-200/40 via-purple-200/20 to-transparent dark:from-indigo-900/30 dark:via-purple-900/20" />
      <div className="absolute inset-0 bg-[radial-gradient(ellipse_at_bottom_left,_var(--tw-gradient-stops))] from-pink-200/40 via-purple-200/20 to-transparent dark:from-pink-900/30 dark:via-purple-900/20" />

      {/* 애니메이션 블러 효과 */}
      <div className="absolute left-1/4 top-1/4 h-64 w-64 animate-pulse rounded-full bg-indigo-400/30 blur-3xl dark:bg-indigo-600/20" />
      <div className="absolute bottom-1/4 right-1/4 h-64 w-64 animate-pulse rounded-full bg-purple-400/30 blur-3xl delay-700 dark:bg-purple-600/20" />

      <div className="relative z-10 w-full max-w-md animate-in fade-in slide-in-from-bottom-4 duration-700">
        {/* 메시지 알림 */}
        <FormMessage message={message} />

        <Card className="border-white/20 bg-white/70 shadow-2xl backdrop-blur-xl dark:border-white/10 dark:bg-gray-900/70">
          <CardHeader className="space-y-3 text-center">
            <div className="mx-auto mb-2 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-indigo-500 to-purple-600 shadow-lg">
              <span className="text-4xl">🚀</span>
            </div>
            <CardTitle className="text-3xl font-bold tracking-tight">
              회원가입
            </CardTitle>
            <CardDescription className="text-base">
              몇 가지 정보만 입력하면 바로 시작할 수 있습니다.
            </CardDescription>
          </CardHeader>

          <CardContent className="space-y-6">
            <form className="space-y-5">
              {/* 이메일 입력 */}
              <div className="space-y-2">
                <Label htmlFor="email" className="text-sm font-medium">
                  이메일
                </Label>
                <Input
                  id="email"
                  name="email"
                  type="email"
                  placeholder="your@email.com"
                  required
                  className="h-11 transition-all duration-200"
                />
              </div>

              {/* 비밀번호 입력 */}
              <div className="space-y-2">
                <Label htmlFor="password" className="text-sm font-medium">
                  비밀번호
                </Label>
                {/* pattern: 최소 8자, 대문자, 소문자, 숫자, 특수문자 각 1개 이상 */}
                {/* 참고: HTML pattern에서는 <, >, {, } 등 일부 특수문자 사용 시 브라우저 호환성 문제 발생 */}
                <Input
                  id="password"
                  name="password"
                  type="password"
                  placeholder="••••••••"
                  autoComplete="new-password"
                  required
                  minLength={6}
                  pattern="^(?=.*[0-9])(?=.*[!@#$%^&*]).{6,}$"
                  title="비밀번호는 최소 6자 이상, 숫자와 특수문자를 각각 1개 이상 포함해야 합니다."
                  className="h-11 transition-all duration-200"
                />
                <p className="text-xs text-gray-500 dark:text-gray-400">
                  최소 6자 이상, 숫자, 특수문자 포함 (한글 가능)
                </p>
              </div>

              {/* 회원가입 버튼 */}
              <Button
                formAction={signup}
                type="submit"
                className="h-11 w-full bg-gradient-to-r from-indigo-600 to-purple-600 font-semibold shadow-lg transition-all duration-200 hover:from-indigo-700 hover:to-purple-700 hover:shadow-xl"
                size="lg"
              >
                회원가입 완료
              </Button>

              {/* 로그인 링크 */}
              <p className="text-center text-sm text-gray-600 dark:text-gray-400">
                이미 계정이 있으신가요?{" "}
                <Link
                  href="/login"
                  className="font-semibold text-indigo-600 transition-colors hover:text-indigo-500 dark:text-indigo-400 dark:hover:text-indigo-300"
                >
                  로그인 하러 가기
                </Link>
              </p>
            </form>
          </CardContent>
        </Card>
      </div>
    </div>
  );
}
