'use strict';

var jsxRuntime = require('react/jsx-runtime');
var clsx = require('clsx');
var tailwindMerge = require('tailwind-merge');
var React = require('react');

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespace(React);

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/app-line-field-dial-preset.tsx
var appLineFieldPattern = {
  lineField: {
    spacing: 4,
    thickness: 1.2,
    topOpacity: 0.18,
    bottomOpacity: 0.15,
    /** Pinstripe tint matches `--theme-background-sidebar` (warm shell gray). */
    tint: "#F9FAFA",
    blur: 0,
    lift: 0
  },
  surface: {
    showPattern: true,
    glowOpacity: 0.2,
    noiseOpacity: 0.08
  }
};
function hexToRgb(hex) {
  const normalized = hex.replace("#", "");
  const expanded = normalized.length === 3 ? normalized.split("").map((character) => `${character}${character}`).join("") : normalized;
  if (!/^[\da-fA-F]{6}$/.test(expanded)) {
    return { r: 148, g: 163, b: 184 };
  }
  return {
    r: Number.parseInt(expanded.slice(0, 2), 16),
    g: Number.parseInt(expanded.slice(2, 4), 16),
    b: Number.parseInt(expanded.slice(4, 6), 16)
  };
}
var DARK_LINE_ALPHA_SCALE = 0.14;
function flatLightStripeColor(pattern, tint) {
  const a = (pattern.lineField.topOpacity + pattern.lineField.bottomOpacity) / 2;
  return `rgba(${tint.r}, ${tint.g}, ${tint.b}, ${a})`;
}
function flatDarkStripeColor(pattern) {
  const a = (pattern.lineField.topOpacity + pattern.lineField.bottomOpacity) / 2 * DARK_LINE_ALPHA_SCALE;
  return `rgba(255, 255, 255, ${a})`;
}
function GroovedHorizontalStripes({
  pattern,
  tint,
  patternOpacity,
  lift,
  mask,
  isDark
}) {
  const stripeColor = isDark ? flatDarkStripeColor(pattern) : flatLightStripeColor(pattern, tint);
  return /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    {
      className: "absolute inset-0",
      style: {
        transform: lift,
        filter: `blur(${pattern.lineField.blur}px)`,
        backgroundColor: stripeColor,
        opacity: patternOpacity,
        WebkitMaskImage: mask,
        maskImage: mask
      }
    }
  );
}
function LineFieldPatternLayers({
  pattern
}) {
  const tint = hexToRgb(pattern.lineField.tint);
  const lift = `translateY(${pattern.lineField.lift}px)`;
  const mask = `repeating-linear-gradient(to bottom, rgba(0,0,0,1) 0px, rgba(0,0,0,1) ${pattern.lineField.thickness}px, transparent ${pattern.lineField.thickness}px, transparent ${pattern.lineField.spacing}px)`;
  const patternOpacity = pattern.surface.showPattern ? 1 : 0;
  const darkShellLayers = /* @__PURE__ */ jsxRuntime.jsx(
    GroovedHorizontalStripes,
    {
      pattern,
      tint,
      patternOpacity,
      lift,
      mask,
      isDark: true
    }
  );
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      "aria-hidden": true,
      className: "pointer-events-none absolute inset-0 z-0 overflow-hidden",
      suppressHydrationWarning: true,
      children: [
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 dark:hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
          GroovedHorizontalStripes,
          {
            pattern,
            tint,
            patternOpacity,
            lift,
            mask,
            isDark: false
          }
        ) }),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 hidden dark:block", children: darkShellLayers })
      ]
    }
  );
}
function AppShellLineFieldPattern() {
  return /* @__PURE__ */ jsxRuntime.jsx(LineFieldPatternLayers, { pattern: appLineFieldPattern });
}
function SidebarLineFieldPattern() {
  return /* @__PURE__ */ jsxRuntime.jsx(AppShellLineFieldPattern, {});
}
function cn(...inputs) {
  return tailwindMerge.twMerge(clsx.clsx(inputs));
}
function AppGroovedMainColumn({
  children,
  className,
  panelClassName
}) {
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      className: cn(
        "relative isolate flex min-h-0 min-w-0 flex-1 flex-col bg-shell pt-3 pr-3 pb-3 pl-0 dark:bg-background",
        className
      ),
      children: [
        /* @__PURE__ */ jsxRuntime.jsx(AppShellLineFieldPattern, {}),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative z-[1] flex min-h-0 min-w-0 flex-1 flex-col", children: /* @__PURE__ */ jsxRuntime.jsx(
          "div",
          {
            className: cn(
              "app-shell-main-panel flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-[14px] bg-sidebar dark:bg-sidebar",
              panelClassName
            ),
            children
          }
        ) })
      ]
    }
  );
}
var LEGACY_ENABLED_KEY = "toolbox-grooved-panel-enabled";
var STORAGE_KEY = "toolbox-grooved-panel";
var GroovedPanelPreferenceContext = React__namespace.createContext(null);
function readStored() {
  if (typeof window === "undefined") {
    return { enabled: true };
  }
  try {
    const raw = window.localStorage.getItem(STORAGE_KEY);
    if (raw) {
      const parsed = JSON.parse(raw);
      return {
        enabled: parsed.enabled !== false
      };
    }
    const legacy = window.localStorage.getItem(LEGACY_ENABLED_KEY);
    return {
      enabled: legacy !== "false"
    };
  } catch (e) {
    return { enabled: true };
  }
}
function writeStored(enabled) {
  try {
    const payload = { enabled };
    window.localStorage.setItem(STORAGE_KEY, JSON.stringify(payload));
  } catch (e) {
  }
}
function GroovedPanelPreferenceProvider({
  children
}) {
  const [groovedPanelEnabled, setGroovedPanelEnabledState] = React__namespace.useState(true);
  const [hydrated, setHydrated] = React__namespace.useState(false);
  React__namespace.useLayoutEffect(() => {
    const { enabled } = readStored();
    setGroovedPanelEnabledState(enabled);
    setHydrated(true);
  }, []);
  React__namespace.useEffect(() => {
    if (!hydrated) return;
    writeStored(groovedPanelEnabled);
  }, [hydrated, groovedPanelEnabled]);
  React__namespace.useEffect(() => {
    const onStorage = (event) => {
      if (event.key !== STORAGE_KEY || event.newValue == null) return;
      try {
        const parsed = JSON.parse(event.newValue);
        setGroovedPanelEnabledState(parsed.enabled !== false);
      } catch (e) {
      }
    };
    window.addEventListener("storage", onStorage);
    return () => window.removeEventListener("storage", onStorage);
  }, []);
  const setGroovedPanelEnabled = React__namespace.useCallback((value2) => {
    setGroovedPanelEnabledState(value2);
  }, []);
  const value = React__namespace.useMemo(
    () => ({
      groovedPanelEnabled,
      setGroovedPanelEnabled
    }),
    [groovedPanelEnabled, setGroovedPanelEnabled]
  );
  return /* @__PURE__ */ jsxRuntime.jsx(GroovedPanelPreferenceContext.Provider, { value, children });
}
function useGroovedPanelPreference() {
  const ctx = React__namespace.useContext(GroovedPanelPreferenceContext);
  if (ctx == null) {
    throw new Error(
      "useGroovedPanelPreference must be used within GroovedPanelPreferenceProvider"
    );
  }
  return ctx;
}
function AppMainLineFieldPattern() {
  const { groovedPanelEnabled } = useGroovedPanelPreference();
  if (!groovedPanelEnabled) {
    return null;
  }
  return /* @__PURE__ */ jsxRuntime.jsx(LineFieldPatternLayers, { pattern: appLineFieldPattern });
}
var AppThemeContext = React__namespace.createContext(null);
function useTheme() {
  const context = React__namespace.useContext(AppThemeContext);
  if (context == null) {
    throw new Error("useTheme must be used within AppThemeProvider");
  }
  return context;
}
function SimpleInventoryTableShell({
  pagination,
  children,
  className,
  paginationPlacement = "top",
  surface,
  cardBorderClassName = "border-border",
  fitContent = false
}) {
  const cardSurfaceClass = surface === "light" ? "bg-card" : surface === "dark" ? "bg-sidebar" : "bg-card";
  const cardShellClass = cn(
    "flex min-w-0 flex-col overflow-hidden rounded-[var(--radius-sm)] border",
    fitContent ? "w-full shrink-0" : "min-h-0 flex-1",
    cardBorderClassName,
    cardSurfaceClass
  );
  const scrollRegionClass = fitContent ? "min-w-0 overflow-x-auto" : "min-h-0 min-w-0 flex-1 overflow-auto overscroll-contain";
  const cardBody = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col pb-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 min-w-0 flex-1 overflow-auto overscroll-contain", children }) });
  if (paginationPlacement === "bottom") {
    return /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      {
        className: cn(
          "flex w-full min-w-0 flex-col gap-[2px]",
          fitContent ? "shrink-0" : "min-h-0",
          className
        ),
        children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: cardShellClass, children: /* @__PURE__ */ jsxRuntime.jsxs(
          "div",
          {
            className: cn(
              "flex min-w-0 flex-col pb-0",
              fitContent ? "shrink-0" : "min-h-0 flex-1"
            ),
            children: [
              /* @__PURE__ */ jsxRuntime.jsx("div", { className: scrollRegionClass, children }),
              /* @__PURE__ */ jsxRuntime.jsx(
                "div",
                {
                  className: cn(
                    "flex h-10 min-h-10 max-h-10 min-w-0 shrink-0 items-center justify-end border-t border-solid border-border px-2",
                    cardSurfaceClass
                  ),
                  children: pagination
                }
              )
            ]
          }
        ) })
      }
    );
  }
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    {
      className: cn(
        "flex min-h-0 min-w-0 w-full flex-col gap-[2px]",
        className
      ),
      children: [
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex min-w-0 shrink-0 justify-end", children: pagination }),
        /* @__PURE__ */ jsxRuntime.jsx("div", { className: cardShellClass, children: cardBody })
      ]
    }
  );
}
function DesignSystemTableShellNoTabs({
  pagination,
  children,
  className,
  cardBorderClassName,
  fitContent
}) {
  const { resolvedTheme } = useTheme();
  const surface = resolvedTheme === "dark" ? "dark" : "light";
  return /* @__PURE__ */ jsxRuntime.jsx(
    SimpleInventoryTableShell,
    {
      className,
      paginationPlacement: "bottom",
      surface,
      cardBorderClassName,
      fitContent,
      pagination,
      children
    }
  );
}

// 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 normalizeGrooveHex(input, fallback) {
  const t = input.trim().replace(/^#/, "");
  if (/^[0-9A-Fa-f]{6}$/.test(t)) return `#${t}`;
  if (/^[0-9A-Fa-f]{3}$/.test(t)) {
    return `#${t[0]}${t[0]}${t[1]}${t[1]}${t[2]}${t[2]}`;
  }
  return fallback;
}
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
    )
  });
}
function normalizeAppearanceForCanvas(a) {
  var _a, _b, _c, _d, _e, _f;
  return {
    gradientStartHex: normalizeGrooveHex(
      a.gradientStartHex,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.gradientStartHex
    ),
    gradientEndHex: normalizeGrooveHex(
      a.gradientEndHex,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.gradientEndHex
    ),
    grooveLineHex: normalizeGrooveHex(
      a.grooveLineHex,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.grooveLineHex
    ),
    grooveOpacity: clampOpacity(
      (_a = a.grooveOpacity) != null ? _a : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.grooveOpacity
    ),
    sheenColorHex: normalizeGrooveHex(
      a.sheenColorHex,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.sheenColorHex
    ),
    sheenOpacity: clampOpacity(
      (_b = a.sheenOpacity) != null ? _b : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.sheenOpacity
    ),
    topVignetteOpacity: clampOpacity(
      (_c = a.topVignetteOpacity) != null ? _c : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.topVignetteOpacity
    ),
    topCrushExtended: clampOpacity(
      (_d = a.topCrushExtended) != null ? _d : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.topCrushExtended
    ),
    brushGrooveIntensity: clampGrooveDial(
      (_e = a.brushGrooveIntensity) != null ? _e : DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.brushGrooveIntensity,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE.brushGrooveIntensity
    ),
    brushBaseGradientDepth: clampGrooveDial(
      (_f = a.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__namespace.createContext(null);
function GroovedPanelDarkAppearanceTweakProvider({
  children
}) {
  const [partial, setPartial] = React__namespace.useState(
    {}
  );
  React__namespace.useLayoutEffect(() => {
    setPartial(readStoredPartial());
  }, []);
  const merged = React__namespace.useMemo(
    () => mergeGroovedPanelDarkAppearance(
      partial,
      DEFAULT_GROOVED_PANEL_DARK_APPEARANCE
    ),
    [partial]
  );
  const updateField = React__namespace.useCallback(
    (key, value2) => {
      setPartial((prev) => {
        const next = __spreadProps(__spreadValues({}, prev), { [key]: value2 });
        writeStoredPartial(next);
        return next;
      });
    },
    []
  );
  const reset = React__namespace.useCallback(() => {
    writeStoredPartial({});
    setPartial({});
  }, []);
  const value = React__namespace.useMemo(
    () => ({ merged, partial, updateField, reset }),
    [merged, partial, updateField, reset]
  );
  return /* @__PURE__ */ jsxRuntime.jsx(GroovedPanelDarkAppearanceTweakContext.Provider, { value, children });
}
function useGroovedPanelDarkAppearanceEffective() {
  const ctx = React__namespace.useContext(GroovedPanelDarkAppearanceTweakContext);
  if (!ctx) {
    return DEFAULT_GROOVED_PANEL_DARK_APPEARANCE;
  }
  return ctx.merged;
}
function useGroovedPanelDarkAppearanceTweakControls() {
  return React__namespace.useContext(GroovedPanelDarkAppearanceTweakContext);
}

// src/chrome/grooved-panel-preset.tsx
var GROOVED_PANEL_LIGHT_BRUSH = {
  grooveIntensity: 25,
  groovePitchPx: 4,
  grooveLineThicknessPx: 2,
  panelGradientTopHex: "#f7f7f7",
  /** Design-system `neutral-100` — pairs with `neutral-50` top stop. */
  panelGradientBottomHex: "#fafafa",
  baseGradientDepth: 0,
  darkMetal: "carbon",
  lightPanelBase: "whiteGroove",
  showScrews: false
};
var GROOVED_PANEL_DARK_BRUSH = {
  /** Slightly below max so brushed grooves stay atmospheric, not chalky. */
  grooveIntensity: 78,
  groovePitchPx: 4,
  grooveLineThicknessPx: 2,
  baseGradientDepth: 88,
  darkMetal: "brushed",
  lightPanelBase: "metal",
  showScrews: false
};

exports.AppGroovedMainColumn = AppGroovedMainColumn;
exports.AppMainLineFieldPattern = AppMainLineFieldPattern;
exports.AppShellLineFieldPattern = AppShellLineFieldPattern;
exports.DEFAULT_GROOVED_PANEL_DARK_APPEARANCE = DEFAULT_GROOVED_PANEL_DARK_APPEARANCE;
exports.DesignSystemTableShellNoTabs = DesignSystemTableShellNoTabs;
exports.GROOVED_PANEL_DARK_APPEARANCE_TWEAK_STORAGE_KEY = GROOVED_PANEL_DARK_APPEARANCE_TWEAK_STORAGE_KEY;
exports.GROOVED_PANEL_DARK_BRUSH = GROOVED_PANEL_DARK_BRUSH;
exports.GROOVED_PANEL_LIGHT_BRUSH = GROOVED_PANEL_LIGHT_BRUSH;
exports.GroovedPanelDarkAppearanceTweakProvider = GroovedPanelDarkAppearanceTweakProvider;
exports.GroovedPanelPreferenceProvider = GroovedPanelPreferenceProvider;
exports.LineFieldPatternLayers = LineFieldPatternLayers;
exports.SidebarLineFieldPattern = SidebarLineFieldPattern;
exports.SimpleInventoryTableShell = SimpleInventoryTableShell;
exports.appLineFieldPattern = appLineFieldPattern;
exports.clampGrooveDial = clampGrooveDial;
exports.clampOpacity = clampOpacity;
exports.mergeGroovedPanelDarkAppearance = mergeGroovedPanelDarkAppearance;
exports.normalizeAppearanceForCanvas = normalizeAppearanceForCanvas;
exports.normalizeGrooveHex = normalizeGrooveHex;
exports.useGroovedPanelDarkAppearanceEffective = useGroovedPanelDarkAppearanceEffective;
exports.useGroovedPanelDarkAppearanceTweakControls = useGroovedPanelDarkAppearanceTweakControls;
exports.useGroovedPanelPreference = useGroovedPanelPreference;
//# sourceMappingURL=index.cjs.map
//# sourceMappingURL=index.cjs.map