"use client";

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

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

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

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

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