"use client";

import { Suspense, useEffect } from "react";
import { useSearchParams } from "next/navigation";
import { AuthPanel } from "@/components/auth/AuthPanel";
import { setPostLoginRedirect } from "@/lib/auth";

function LoginInner() {
  const params = useSearchParams();
  const redirectParam = params.get("redirect");

  useEffect(() => {
    if (redirectParam) setPostLoginRedirect(redirectParam);
  }, [redirectParam]);

  return <AuthPanel redirectTo={redirectParam ?? undefined} />;
}

export default function LoginPage() {
  return (
    <Suspense
      fallback={
        <div className="flex min-h-[60vh] items-center justify-center">
          <p className="text-gray-600">در حال بارگذاری...</p>
        </div>
      }
    >
      <LoginInner />
    </Suspense>
  );
}
