'use client';

import { useSession } from 'next-auth/react';

export default function AuthLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const { status } = useSession();

  // Middleware handles redirecting logged-in users away from auth pages.
  // Do NOT add client-side redirect logic here — it races with logout
  // and causes login/logout loops.

  if (status === 'loading') {
    return (
      <div className="min-h-screen flex items-center justify-center bg-gradient-to-b from-[#c4d9d4] to-[#f0f5fc]">
        <div className="text-center">
          <img
            src="/assets/logo.svg"
            alt="RE-Quest"
            className="h-8 mx-auto mb-4"
          />
          <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-[#00293d] mx-auto"></div>
        </div>
      </div>
    );
  }

  return (
    <div className="min-h-screen flex items-center justify-center bg-gradient-to-b from-[#c4d9d4] to-[#f0f5fc] py-12 px-4">
      <div className="w-full max-w-[510px]">
        {/* Logo */}
        <div className="text-center mb-4">
          <img
            src="/assets/logo.svg"
            alt="RE-QuestN"
            className="h-8 mx-auto"
          />
        </div>
        {children}
      </div>
    </div>
  );
}
