import FormMessage from "@/components/form-message";
import { requestPasswordReset } from "@/features/auth/actions";
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";
import Link from "next/link";

/**
 * [비밀번호 찾기 페이지]
 *
 * 사용자가 이메일을 입력하면 비밀번호 재설정 링크를 이메일로 발송합니다.
 * 로그인/회원가입 페이지와 동일한 디자인 시스템 사용
 *
 * @param searchParams - URL 쿼리 파라미터 (에러 메시지 전달용)
 */
export default async function ForgotPasswordPage({
  searchParams,
}: {
  searchParams: Promise<{ message: string }>;
}) {
  // URL에서 메시지 파라미터 추출
  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">
              가입하신 이메일 주소를 입력하시면
              <br />
              비밀번호 재설정 링크를 보내드립니다.
            </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"
                  autoComplete="email"
                  required
                  className="h-11 transition-all duration-200"
                />
              </div>

              {/* ========== 재설정 링크 발송 버튼 ========== */}
              <Button
                formAction={requestPasswordReset}
                className="h-11 w-full bg-gradient-to-r from-indigo-600 to-purple-600 font-semibold text-white shadow-lg transition-all hover:from-indigo-700 hover:to-purple-700 hover:shadow-xl"
              >
                재설정 링크 보내기
              </Button>
            </form>

            {/* ========== 로그인 페이지로 돌아가기 ========== */}
            <div className="text-center">
              <Link
                href="/login"
                className="text-sm font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400 dark:hover:text-indigo-300"
              >
                ← 로그인 페이지로 돌아가기
              </Link>
            </div>
          </CardContent>
        </Card>
      </div>
    </div>
  );
}
