import React, { useEffect, useState } from "react";
import { useC3Profile } from "./c3-profile-provider";
import { GlobalTheme } from "@carbon/react";
const THEMES = {
    light: "g10",
    dark: "g100",
};
export const getSystemTheme = () => window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
export const resolveTheme = (theme) => theme === "system" ? getSystemTheme() : theme;
const getCarbonTheme = (theme) => THEMES[resolveTheme(theme)];
export const setCarbonThemeAttribute = (theme) => document.documentElement.setAttribute("data-carbon-theme", theme);
export const CarbonThemeProvider = ({ children }) => {
    const { resolvedTheme } = useC3Profile();
    const [carbonTheme, setCarbonTheme] = useState(getCarbonTheme(resolvedTheme));
    const updateCarbonTheme = (newTheme) => {
        setCarbonTheme(newTheme);
        setCarbonThemeAttribute(newTheme);
    };
    useEffect(() => {
        updateCarbonTheme(getCarbonTheme(resolvedTheme));
    }, [resolvedTheme]);
    return React.createElement(GlobalTheme, { theme: carbonTheme }, children);
};
