"use client";

import type { ReactNode } from "react";

import { I18nHydrationProvider } from "@/components/i18n-hydration-provider";
import { Toaster } from "@/components/ui/sonner";
import { ErrorProvider } from "@/components/error-provider";
import { IframeBridge } from "@/components/iframe-bridge";
import { PlayEffectiveWsListener } from "@/components/play-effective-ws-listener";
import { PlayerBalanceWsListener } from "@/components/player-balance-ws-listener";
import { TokenSilentRefresh } from "@/components/token-silent-refresh";
import "@/i18n";

type ProvidersProps = {
  children: ReactNode;
};

export function Providers({ children }: ProvidersProps): ReactNode {
  return (
    <>
      <I18nHydrationProvider>
      <ErrorProvider>
        {/* iframe 通信桥接 - 支持主站嵌入 */}
        <IframeBridge>
          {children}
          <PlayerBalanceWsListener />
          <PlayEffectiveWsListener />
          {/* Token 静默续签（无 UI） */}
          <TokenSilentRefresh />
        </IframeBridge>
      </ErrorProvider>
      </I18nHydrationProvider>
      <Toaster />
    </>
  );
}
