"use client";

import { ThemeProvider as NextThemesProvider } from "next-themes";
import type * as React from "react";

// React 19.2 logs "Encountered a script tag while rendering React component"
// for the no-flash init <script> that next-themes renders through the client
// tree. False positive: the script runs from the SSR HTML; only the client
// re-render copy never executes, by design. Dev-only noise — filtered until
// next-themes ships a useServerInsertedHTML-based release.
// https://github.com/shadcn-ui/ui/issues/10104
// https://github.com/pacocoursey/next-themes/issues/387
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
  const consoleError = console.error;
  console.error = (...args: Parameters<typeof console.error>) => {
    if (
      typeof args[0] === "string" &&
      args[0].includes(
        "Encountered a script tag while rendering React component",
      )
    ) {
      return;
    }
    consoleError(...args);
  };
}

export function ThemeProvider({
  children,
  ...props
}: React.ComponentProps<typeof NextThemesProvider>) {
  return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
}
