"use client";
import * as React from 'react';
import { jsx } from 'react/jsx-runtime';

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));

// src/chrome/grooved-panel-dark-appearance.tsx
var DEFAULT_GROOVED_PANEL_DARK_APPEARANCE = {
  gradientStartHex: "#1E1F1C",
  gradientEndHex: "#1E1E21",
  grooveLineHex: "#29292e",
  grooveOpacity: 0.98,
  sheenColorHex: "#292929",
  sheenOpacity: 0,
  topVignetteOpacity: 0.15,
  topCrushExtended: 0.5,
  brushGrooveIntensity: 0,
  brushBaseGradientDepth: 5
};
function clampOpacity(value) {
  if (!Number.isFinite(value)) return 0;
  return Math.min(1, Math.max(0, value));
}
function clampGrooveDial(value, fallback) {
  if (!Number.isFinite(value)) return fallback;
  return Math.min(200, Math.max(0, value));
}
function mergeGroovedPanelDarkAppearance(incoming, base) {
  var _a, _b, _c, _d, _e, _f;
  const merged = __spreadValues(__spreadValues({}, base), incoming != null ? incoming : {});
  return __spreadProps(__spreadValues({}, merged), {
    grooveOpacity: clampOpacity(
      (_a = merged.grooveOpacity) != null ? _a : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.grooveOpacity
    ),
    sheenOpacity: clampOpacity(
      (_b = merged.sheenOpacity) != null ? _b : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.sheenOpacity
    ),
    topVignetteOpacity: clampOpacity(
      (_c = merged.topVignetteOpacity) != null ? _c : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.topVignetteOpacity
    ),
    topCrushExtended: clampOpacity(
      (_d = merged.topCrushExtended) != null ? _d : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.topCrushExtended
    ),
    brushGrooveIntensity: clampGrooveDial(
      (_e = merged.brushGrooveIntensity) != null ? _e : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.brushGrooveIntensity,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.brushGrooveIntensity
    ),
    brushBaseGradientDepth: clampGrooveDial(
      (_f = merged.brushBaseGradientDepth) != null ? _f : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.brushBaseGradientDepth,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.brushBaseGradientDepth
    )
  });
}
var GROOVED_PANEL_DARK_APPEARANCE_TWEAK_STORAGE_KEY = "toolbox-grooved-dark-appearance-tweak";
function readStoredPartial() {
  if (typeof window === "undefined") {
    return {};
  }
  try {
    const raw = window.localStorage.getItem(
      GROOVED_PANEL_DARK_APPEARANCE_TWEAK_STORAGE_KEY
    );
    if (!raw) {
      return {};
    }
    const parsed = JSON.parse(raw);
    if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
      return {};
    }
    return parsed;
  } catch (e) {
    return {};
  }
}
function writeStoredPartial(partial) {
  if (typeof window === "undefined") {
    return;
  }
  try {
    if (Object.keys(partial).length === 0) {
      window.localStorage.removeItem(GROOVED_PANEL_DARK_APPEARANCE_TWEAK_STORAGE_KEY);
    } else {
      window.localStorage.setItem(
        GROOVED_PANEL_DARK_APPEARANCE_TWEAK_STORAGE_KEY,
        JSON.stringify(partial)
      );
    }
  } catch (e) {
  }
}
var GroovedPanelDarkAppearanceTweakContext = React.createContext(null);
function GroovedPanelDarkAppearanceTweakProvider({
  children
}) {
  const [partial, setPartial] = React.useState(
    {}
  );
  React.useLayoutEffect(() => {
    setPartial(readStoredPartial());
  }, []);
  const merged = React.useMemo(
    () => mergeGroovedPanelDarkAppearance(
      partial,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE
    ),
    [partial]
  );
  const updateField = React.useCallback(
    (key, value2) => {
      setPartial((prev) => {
        const next = __spreadProps(__spreadValues({}, prev), { [key]: value2 });
        writeStoredPartial(next);
        return next;
      });
    },
    []
  );
  const reset = React.useCallback(() => {
    writeStoredPartial({});
    setPartial({});
  }, []);
  const value = React.useMemo(
    () => ({ merged, partial, updateField, reset }),
    [merged, partial, updateField, reset]
  );
  return /* @__PURE__ */ jsx(GroovedPanelDarkAppearanceTweakContext.Provider, { value, children });
}
function useGroovedPanelDarkAppearanceEffective() {
  const ctx = React.useContext(GroovedPanelDarkAppearanceTweakContext);
  if (!ctx) {
    return DEFAULT_GROOVED_PANEL_DARK_APPEARANCE;
  }
  return ctx.merged;
}
function useGroovedPanelDarkAppearanceTweakControls() {
  return React.useContext(GroovedPanelDarkAppearanceTweakContext);
}

export { GROOVED_PANEL_DARK_APPEARANCE_TWEAK_STORAGE_KEY, GroovedPanelDarkAppearanceTweakProvider, useGroovedPanelDarkAppearanceEffective, useGroovedPanelDarkAppearanceTweakControls };
//# sourceMappingURL=grooved-panel-dark-appearance-tweak.js.map
//# sourceMappingURL=grooved-panel-dark-appearance-tweak.js.map