"use client";

import { type ReactNode } from "react";
import { GraphQLProvider } from "@/providers/graphql-provider";
import { AuthProvider } from "@/providers/auth-provider";
import { ToastProvider } from "@/providers/toast-provider";
import { MswInitializer } from "@/components/msw-initializer";
import { useState } from "react";

/**
 * Login layout - 提供 login 页面所需的 providers
 *
 * login 页面不在 /admin 下，需要独立的 provider 链
 */
export default function LoginLayout({ children }: { children: ReactNode }) {
  const [mswReady, setMswReady] = useState(false);

  return (
    <GraphQLProvider>
      <MswInitializer onReady={() => setMswReady(true)} />
      {mswReady && (
        <AuthProvider>
          <ToastProvider>{children}</ToastProvider>
        </AuthProvider>
      )}
    </GraphQLProvider>
  );
}
