import * as e from "react";
import w from "../../../../../../../../../_virtual/index9.js";
import { Provider as G } from "../../../../../../../@radix-ui_react-tooltip@1.1.1_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react_7ac623185c9269a12c8508884ea7ba21/node_modules/@radix-ui/react-tooltip/dist/index.js";
import { DirectionProvider as b } from "../../../../../../../@radix-ui_react-direction@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-direction/dist/index.js";
import { Slot as N } from "../../../../../../../@radix-ui_react-slot@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-slot/dist/index.js";
import { getMatchingGrayColor as D } from "../helpers/get-matching-gray-color.js";
import { themePropDefs as a } from "./theme.props.js";
const g = () => {
}, S = e.createContext(void 0);
function J() {
  const o = e.useContext(S);
  if (o === void 0) throw new Error("`useThemeContext` must be used within a `Theme`");
  return o;
}
const I = e.forwardRef((o, c) => e.useContext(S) === void 0 ? e.createElement(G, { delayDuration: 200 }, e.createElement(b, { dir: "ltr" }, e.createElement(T, { ...o, ref: c }))) : e.createElement(P, { ...o, ref: c }));
I.displayName = "Theme";
const T = e.forwardRef((o, c) => {
  const { appearance: r = a.appearance.default, accentColor: i = a.accentColor.default, grayColor: l = a.grayColor.default, panelBackground: s = a.panelBackground.default, radius: n = a.radius.default, scaling: t = a.scaling.default, hasBackground: d = a.hasBackground.default, ...C } = o, [f, u] = e.useState(r);
  e.useEffect(() => u(r), [r]);
  const [y, p] = e.useState(i);
  e.useEffect(() => p(i), [i]);
  const [B, h] = e.useState(l);
  e.useEffect(() => h(l), [l]);
  const [E, m] = e.useState(s);
  e.useEffect(() => m(s), [s]);
  const [v, x] = e.useState(n);
  e.useEffect(() => x(n), [n]);
  const [k, R] = e.useState(t);
  return e.useEffect(() => R(t), [t]), e.createElement(P, { ...C, ref: c, isRoot: !0, hasBackground: d, appearance: f, accentColor: y, grayColor: B, panelBackground: E, radius: v, scaling: k, onAppearanceChange: u, onAccentColorChange: p, onGrayColorChange: h, onPanelBackgroundChange: m, onRadiusChange: x, onScalingChange: R });
});
T.displayName = "ThemeRoot";
const P = e.forwardRef((o, c) => {
  const r = e.useContext(S), { asChild: i, isRoot: l, hasBackground: s, appearance: n = r?.appearance ?? a.appearance.default, accentColor: t = r?.accentColor ?? a.accentColor.default, grayColor: d = r?.resolvedGrayColor ?? a.grayColor.default, panelBackground: C = r?.panelBackground ?? a.panelBackground.default, radius: f = r?.radius ?? a.radius.default, scaling: u = r?.scaling ?? a.scaling.default, onAppearanceChange: y = g, onAccentColorChange: p = g, onGrayColorChange: B = g, onPanelBackgroundChange: h = g, onRadiusChange: E = g, onScalingChange: m = g, ...v } = o, x = i ? N : "div", k = d === "auto" ? D(t) : d, R = o.appearance === "light" || o.appearance === "dark", A = s === void 0 ? l || R : s;
  return e.createElement(S.Provider, { value: e.useMemo(() => ({ appearance: n, accentColor: t, grayColor: d, resolvedGrayColor: k, panelBackground: C, radius: f, scaling: u, onAppearanceChange: y, onAccentColorChange: p, onGrayColorChange: B, onPanelBackgroundChange: h, onRadiusChange: E, onScalingChange: m }), [n, t, d, k, C, f, u, y, p, B, h, E, m]) }, e.createElement(x, { "data-is-root-theme": l ? "true" : "false", "data-accent-color": t, "data-gray-color": k, "data-has-background": A ? "true" : "false", "data-panel-background": C, "data-radius": f, "data-scaling": u, ref: c, ...v, className: w("radix-themes", { light: n === "light", dark: n === "dark" }, v.className) }));
});
P.displayName = "ThemeImpl";
export {
  I as Theme,
  S as ThemeContext,
  J as useThemeContext
};
//# sourceMappingURL=theme.js.map
