import { FloatingToolbar, ExpandAction, CopyAction, DownloadAction } from './chunk-KNEQRUBA.mjs';
import { __name } from './chunk-N2XQF2OL.mjs';
import { useState, useRef, useMemo } from 'react';
import { JSONTree } from 'react-json-tree';
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';

var JSON_TREE_THEME = {
  scheme: "djangocfg-dark",
  base00: "transparent",
  base01: "#1a1a1a",
  base02: "#2a2a2a",
  base03: "#6b7280",
  base04: "#9ca3af",
  base05: "#e5e7eb",
  base06: "#f3f4f6",
  base07: "#ffffff",
  base08: "#ef4444",
  // null, undefined
  base09: "#f97316",
  // numbers
  base0A: "#eab308",
  // strings
  base0B: "#22c55e",
  // booleans
  base0C: "#06b6d4",
  // dates, regex
  base0D: "#3b82f6",
  // keys
  base0E: "#a855f7",
  // functions
  base0F: "#f43f5e"
  // deprecations
};
var JsonContent = /* @__PURE__ */ __name(({
  data,
  renderKey,
  title,
  showTitle,
  padding,
  collectionLimit,
  preserveKeyOrder,
  showCollectionInfo,
  maxStringLength,
  fontSize,
  shouldExpandNodeInitially,
  jsonTreeProps = {}
}) => {
  const getItemString = showCollectionInfo ? (nodeType, nodeData) => {
    if (nodeType === "Array") {
      const length = Array.isArray(nodeData) ? nodeData.length : 0;
      return length > 0 ? /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-xs", children: [
        "(",
        length,
        ")"
      ] }) : null;
    }
    if (nodeType === "Object") {
      const keys = nodeData && typeof nodeData === "object" ? Object.keys(nodeData) : [];
      return keys.length > 0 ? /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: `{${keys.length}}` }) : null;
    }
    return null;
  } : () => null;
  const postprocessValue = /* @__PURE__ */ __name((value) => {
    if (typeof value === "string" && value.length > maxStringLength) {
      return value.substring(0, maxStringLength) + "... (truncated)";
    }
    return value;
  }, "postprocessValue");
  const isCustomNode = /* @__PURE__ */ __name((value) => typeof value === "string" && (value.startsWith("http://") || value.startsWith("https://")), "isCustomNode");
  return /* @__PURE__ */ jsxs("div", { className: `overflow-auto h-full ${padding}`, style: fontSize ? { fontSize } : void 0, children: [
    showTitle && title && /* @__PURE__ */ jsx("h6", { className: "text-sm font-semibold text-foreground mb-2", children: title }),
    /* @__PURE__ */ jsx(
      JSONTree,
      {
        data,
        theme: JSON_TREE_THEME,
        invertTheme: false,
        hideRoot: true,
        shouldExpandNodeInitially,
        getItemString,
        postprocessValue,
        isCustomNode,
        collectionLimit,
        sortObjectKeys: !preserveKeyOrder,
        ...jsonTreeProps
      },
      renderKey
    )
  ] });
}, "JsonContent");
function useJsonExpand({
  maxAutoExpandDepth,
  maxAutoExpandArrayItems,
  maxAutoExpandObjectKeys
}) {
  const [expandAll, setExpandAll] = useState(null);
  const [renderKey, setRenderKey] = useState(0);
  const isExpanded = expandAll === true || expandAll === null && maxAutoExpandDepth > 0;
  const toggle = /* @__PURE__ */ __name(() => {
    setExpandAll(isExpanded ? false : true);
    setRenderKey((prev) => prev + 1);
  }, "toggle");
  const shouldExpandNodeInitially = /* @__PURE__ */ __name((_keyPath, nodeData, level) => {
    if (expandAll === true) return true;
    if (expandAll === false) return false;
    if (level <= maxAutoExpandDepth) return true;
    if (Array.isArray(nodeData) && nodeData.length <= maxAutoExpandArrayItems) return true;
    if (nodeData && typeof nodeData === "object" && !Array.isArray(nodeData)) {
      return Object.keys(nodeData).length <= maxAutoExpandObjectKeys;
    }
    return false;
  }, "shouldExpandNodeInitially");
  return { isExpanded, toggle, renderKey, shouldExpandNodeInitially };
}
__name(useJsonExpand, "useJsonExpand");

// src/tools/JsonTree/types.ts
var MODE_PRESETS = {
  full: {
    showExpandControls: true,
    showActionButtons: true,
    showCollectionInfo: true,
    fontSize: "13px"
  },
  compact: {
    showExpandControls: false,
    showActionButtons: false,
    showCollectionInfo: true,
    fontSize: "11px",
    maxAutoExpandDepth: 1
  },
  inline: {
    showExpandControls: false,
    showActionButtons: false,
    showCollectionInfo: false,
    fontSize: "11px",
    maxAutoExpandDepth: 1
  }
};
var JsonTreeComponent = /* @__PURE__ */ __name(({
  title,
  data,
  mode = "full",
  config = {},
  jsonTreeProps = {}
}) => {
  const containerRef = useRef(null);
  const mergedConfig = useMemo(() => ({ ...MODE_PRESETS[mode], ...config }), [mode, config]);
  const {
    maxAutoExpandDepth = 2,
    maxAutoExpandArrayItems = 10,
    maxAutoExpandObjectKeys = 5,
    maxStringLength = 200,
    collectionLimit = 50,
    showCollectionInfo = true,
    showExpandControls = true,
    showActionButtons = true,
    className = "",
    preserveKeyOrder = true,
    fontSize
  } = mergedConfig;
  const { isExpanded, toggle, renderKey, shouldExpandNodeInitially } = useJsonExpand({
    maxAutoExpandDepth,
    maxAutoExpandArrayItems,
    maxAutoExpandObjectKeys
  });
  const jsonString = useMemo(() => JSON.stringify(data, null, 2), [data]);
  const containerClasses = useMemo(() => {
    const base = "relative w-full";
    switch (mode) {
      case "full":
        return `${base} border border-border rounded-sm ${className}`;
      case "compact":
        return `${base} border border-border/50 rounded-md ${className}`;
      default:
        return `${base} ${className}`;
    }
  }, [mode, className]);
  const contentPadding = mode === "full" ? "p-4" : mode === "compact" ? "p-2" : "p-1";
  const showControls = (showExpandControls || showActionButtons) && mode === "full";
  return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: containerClasses, children: [
    showControls && /* @__PURE__ */ jsxs(FloatingToolbar, { containerRef, children: [
      showExpandControls && /* @__PURE__ */ jsx(ExpandAction, { isExpanded, onToggle: toggle }),
      showActionButtons && /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsx(CopyAction, { value: jsonString, title: "Copy JSON" }),
        /* @__PURE__ */ jsx(DownloadAction, { value: jsonString, filename: "data.json", mimeType: "application/json", title: "Download JSON" })
      ] })
    ] }),
    /* @__PURE__ */ jsx(
      JsonContent,
      {
        data,
        renderKey,
        title,
        showTitle: mode === "full",
        padding: contentPadding,
        collectionLimit,
        preserveKeyOrder,
        showCollectionInfo,
        maxStringLength,
        shouldExpandNodeInitially,
        fontSize,
        jsonTreeProps
      }
    )
  ] });
}, "JsonTreeComponent");
var JsonTree_default = JsonTreeComponent;

export { JsonTree_default };
//# sourceMappingURL=chunk-5G5YBFS6.mjs.map
//# sourceMappingURL=chunk-5G5YBFS6.mjs.map