import { r as reactExports, j as jsxRuntimeExports } from "../_libs/react.mjs";
import { q as parseJsonText, c as cn, k as TooltipProvider, l as Tooltip, m as TooltipTrigger, n as TooltipContent } from "./ProxyViewerContainer--3K3o3Sm.mjs";
import "./router-DVixpJO-.mjs";
import "../_libs/modelcontextprotocol__server.mjs";
import "../_libs/jszip.mjs";
import { C as Check, a as Copy, b as ChevronDown, f as ChevronRight, r as ChevronsDown } from "../_libs/lucide-react.mjs";
import { M as Markdown } from "../_libs/react-markdown.mjs";
import "../_libs/swr.mjs";
import "../_libs/use-sync-external-store.mjs";
import "../_libs/dequal.mjs";
import "../_libs/clsx.mjs";
import "../_libs/tailwind-merge.mjs";
import "../_libs/class-variance-authority.mjs";
import "../_libs/radix-ui__react-dialog.mjs";
import "../_libs/radix-ui__primitive.mjs";
import "../_libs/radix-ui__react-compose-refs.mjs";
import "../_libs/radix-ui__react-context.mjs";
import "../_libs/radix-ui__react-id.mjs";
import "../_libs/@radix-ui/react-use-layout-effect+[...].mjs";
import "../_libs/@radix-ui/react-use-controllable-state+[...].mjs";
import "../_libs/@radix-ui/react-dismissable-layer+[...].mjs";
import "../_libs/radix-ui__react-primitive.mjs";
import "../_libs/react-dom.mjs";
import "util";
import "async_hooks";
import "stream";
import "crypto";
import "../_libs/radix-ui__react-slot.mjs";
import "../_libs/@radix-ui/react-use-callback-ref+[...].mjs";
import "../_libs/@radix-ui/react-use-escape-keydown+[...].mjs";
import "../_libs/radix-ui__react-focus-scope.mjs";
import "../_libs/radix-ui__react-portal.mjs";
import "../_libs/radix-ui__react-presence.mjs";
import "../_libs/radix-ui__react-focus-guards.mjs";
import "../_libs/react-remove-scroll.mjs";
import "tslib";
import "../_libs/react-remove-scroll-bar.mjs";
import "../_libs/react-style-singleton.mjs";
import "../_libs/get-nonce.mjs";
import "../_libs/use-sidecar.mjs";
import "../_libs/use-callback-ref.mjs";
import "../_libs/aria-hidden.mjs";
import "../_libs/diff.mjs";
import "../_libs/tanstack__react-virtual.mjs";
import "../_libs/tanstack__virtual-core.mjs";
import "../_libs/radix-ui__react-select.mjs";
import "../_libs/radix-ui__number.mjs";
import "../_libs/radix-ui__react-collection.mjs";
import "../_libs/radix-ui__react-direction.mjs";
import "../_libs/radix-ui__react-popper.mjs";
import "../_libs/floating-ui__react-dom.mjs";
import "../_libs/floating-ui__dom.mjs";
import "../_libs/floating-ui__core.mjs";
import "../_libs/floating-ui__utils.mjs";
import "../_libs/radix-ui__react-arrow.mjs";
import "../_libs/radix-ui__react-use-size.mjs";
import "../_libs/radix-ui__react-use-previous.mjs";
import "../_libs/@radix-ui/react-visually-hidden+[...].mjs";
import "../_libs/zod.mjs";
import "../_libs/radix-ui__react-tooltip.mjs";
import "../_libs/radix-ui__react-tabs.mjs";
import "../_libs/radix-ui__react-roving-focus.mjs";
import "../_libs/tanstack__react-router.mjs";
import "../_libs/tiny-warning.mjs";
import "../_libs/tanstack__router-core.mjs";
import "../_libs/cookie-es.mjs";
import "../_libs/tanstack__history.mjs";
import "../_libs/tiny-invariant.mjs";
import "../_libs/seroval.mjs";
import "../_libs/seroval-plugins.mjs";
import "node:stream/web";
import "node:stream";
import "../_libs/isbot.mjs";
import "node:fs";
import "node:fs/promises";
import "node:buffer";
import "node:path";
import "../_libs/conf.mjs";
import "node:util";
import "node:process";
import "node:crypto";
import "node:assert";
import "../_libs/dot-prop.mjs";
import "../_libs/env-paths.mjs";
import "node:os";
import "../_libs/atomically.mjs";
import "../_libs/stubborn-fs.mjs";
import "../_libs/stubborn-utils.mjs";
import "../_libs/when-exit.mjs";
import "../_libs/ajv.mjs";
import "../_libs/fast-deep-equal.mjs";
import "../_libs/json-schema-traverse.mjs";
import "../_libs/fast-uri.mjs";
import "../_libs/ajv-formats.mjs";
import "../_libs/debounce-fn.mjs";
import "../_libs/mimic-function.mjs";
import "../_libs/semver.mjs";
import "../_libs/uint8array-extras.mjs";
import "node:child_process";
import "node:worker_threads";
import "../_libs/readable-stream.mjs";
import "events";
import "node:string_decoder";
import "../_libs/process-nextick-args.mjs";
import "../_libs/isarray.mjs";
import "../_libs/safe-buffer.mjs";
import "buffer";
import "../_libs/core-util-is.mjs";
import "../_libs/inherits.mjs";
import "../_libs/util-deprecate.mjs";
import "../_libs/lie.mjs";
import "../_libs/immediate.mjs";
import "../_libs/setimmediate.mjs";
import "../_libs/pako.mjs";
import "../_libs/devlop.mjs";
import "../_libs/unified.mjs";
import "../_libs/bail.mjs";
import "../_libs/extend.mjs";
import "../_libs/is-plain-obj.mjs";
import "../_libs/trough.mjs";
import "../_libs/vfile.mjs";
import "../_libs/vfile-message.mjs";
import "../_libs/unist-util-stringify-position.mjs";
import "node:url";
import "../_libs/remark-parse.mjs";
import "../_libs/mdast-util-from-markdown.mjs";
import "../_libs/micromark-util-decode-numeric-character-reference+[...].mjs";
import "../_libs/micromark-util-decode-string.mjs";
import "../_libs/decode-named-character-reference+[...].mjs";
import "../_libs/character-entities.mjs";
import "../_libs/micromark-util-normalize-identifier+[...].mjs";
import "../_libs/micromark.mjs";
import "../_libs/micromark-util-combine-extensions+[...].mjs";
import "../_libs/micromark-util-chunked.mjs";
import "../_libs/micromark-factory-space.mjs";
import "../_libs/micromark-util-character.mjs";
import "../_libs/micromark-core-commonmark.mjs";
import "../_libs/micromark-util-classify-character+[...].mjs";
import "../_libs/micromark-util-resolve-all.mjs";
import "../_libs/micromark-util-subtokenize.mjs";
import "../_libs/micromark-factory-destination.mjs";
import "../_libs/micromark-factory-label.mjs";
import "../_libs/micromark-factory-title.mjs";
import "../_libs/micromark-factory-whitespace.mjs";
import "../_libs/micromark-util-html-tag-name.mjs";
import "../_libs/mdast-util-to-string.mjs";
import "../_libs/remark-rehype.mjs";
import "../_libs/mdast-util-to-hast.mjs";
import "../_libs/ungap__structured-clone.mjs";
import "../_libs/micromark-util-sanitize-uri.mjs";
import "../_libs/unist-util-position.mjs";
import "../_libs/trim-lines.mjs";
import "../_libs/unist-util-visit.mjs";
import "../_libs/unist-util-visit-parents.mjs";
import "../_libs/unist-util-is.mjs";
import "../_libs/hast-util-to-jsx-runtime.mjs";
import "../_libs/comma-separated-tokens.mjs";
import "../_libs/property-information.mjs";
import "../_libs/space-separated-tokens.mjs";
import "../_libs/style-to-js.mjs";
import "../_libs/style-to-object.mjs";
import "../_libs/inline-style-parser.mjs";
import "../_libs/hast-util-whitespace.mjs";
import "../_libs/estree-util-is-identifier-name.mjs";
import "../_libs/html-url-attributes.mjs";
function classifyValue(value) {
  if (value === null) return "null";
  if (Array.isArray(value)) return "array";
  switch (typeof value) {
    case "string":
      return "string";
    case "number":
      return "number";
    case "boolean":
      return "boolean";
    case "object":
      return "object";
    case "bigint":
    case "symbol":
    case "undefined":
    case "function":
      return "object";
  }
}
function isExpandable(value) {
  return value !== null && (Array.isArray(value) || typeof value === "object");
}
function getEntries(value) {
  if (Array.isArray(value)) {
    return value.map((item, index) => [String(index), item]);
  }
  if (typeof value === "object" && value !== null) {
    return Object.entries(value);
  }
  return [];
}
const STRING_TRUNCATE_LIMIT = 120;
function StringValue({ text }) {
  const [expanded, setExpanded] = reactExports.useState(false);
  const isLong = text.length > STRING_TRUNCATE_LIMIT;
  if (!isLong) {
    return /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-emerald-400 break-all", children: [
      '"',
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "prose prose-sm dark:prose-invert inline max-w-none [&_p]:inline [&_p]:my-0 [&_code]:text-emerald-300 [&_a]:text-emerald-300", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Markdown, { children: text }) }),
      '"'
    ] });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-emerald-400 break-all", children: [
    '"',
    expanded ? /* @__PURE__ */ jsxRuntimeExports.jsx(
      "span",
      {
        className: "cursor-pointer prose prose-sm dark:prose-invert inline max-w-none [&_p]:inline [&_p]:my-0 [&_code]:text-emerald-300 [&_a]:text-emerald-300",
        onClick: (e) => {
          e.stopPropagation();
          setExpanded(false);
        },
        onKeyDown: (e) => {
          if (e.key === "Enter" || e.key === " ") {
            e.stopPropagation();
            setExpanded(false);
          }
        },
        role: "button",
        tabIndex: 0,
        children: /* @__PURE__ */ jsxRuntimeExports.jsx(Markdown, { children: text })
      }
    ) : /* @__PURE__ */ jsxRuntimeExports.jsxs(Tooltip, { delayDuration: 300, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(
        TooltipTrigger,
        {
          onClick: (e) => {
            e.stopPropagation();
            setExpanded(true);
          },
          className: "text-left cursor-pointer",
          children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: text.slice(0, STRING_TRUNCATE_LIMIT) }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-emerald-400/50", children: "…" })
          ]
        }
      ),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(
        TooltipContent,
        {
          side: "bottom",
          className: "max-w-md text-xs p-2 break-words whitespace-pre-wrap",
          children: [
            text.slice(0, 500),
            text.length > 500 ? "…" : ""
          ]
        }
      )
    ] }),
    '"'
  ] });
}
function PrimitiveValue({ value }) {
  if (value === null) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-rose-400 italic", children: "null" });
  }
  switch (typeof value) {
    case "string":
      return /* @__PURE__ */ jsxRuntimeExports.jsx(StringValue, { text: value });
    case "number":
      return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-amber-400", children: value });
    case "boolean":
      return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-blue-400", children: value ? "true" : "false" });
    case "object":
    case "bigint":
    case "symbol":
    case "undefined":
    case "function":
      return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: JSON.stringify(value) });
  }
}
function CopyValueButton({ value }) {
  const [copied, setCopied] = reactExports.useState(false);
  function handleCopy(e) {
    e.stopPropagation();
    void window.navigator.clipboard.writeText(JSON.stringify(value, null, 2)).then(() => {
      setCopied(true);
      setTimeout(() => {
        setCopied(false);
      }, 2e3);
    });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    "button",
    {
      type: "button",
      onClick: handleCopy,
      className: "inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors",
      title: "Copy JSON",
      children: copied ? /* @__PURE__ */ jsxRuntimeExports.jsx(Check, { className: "size-3 text-green-500" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Copy, { className: "size-3" })
    }
  );
}
function CopyButton({ value }) {
  const [copied, setCopied] = reactExports.useState(false);
  function handleCopy(e) {
    e.stopPropagation();
    void window.navigator.clipboard.writeText(JSON.stringify(value, null, 2)).then(() => {
      setCopied(true);
      setTimeout(() => {
        setCopied(false);
      }, 2e3);
    });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    "button",
    {
      type: "button",
      onClick: handleCopy,
      className: "opacity-0 group-hover/row:opacity-100 hover:bg-muted p-0.5 rounded transition-opacity shrink-0",
      title: "Copy to clipboard",
      children: copied ? /* @__PURE__ */ jsxRuntimeExports.jsx(Check, { className: "size-3 text-green-500" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Copy, { className: "size-3 text-muted-foreground" })
    }
  );
}
function ExpandCollapseButton({
  onClick
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    "button",
    {
      type: "button",
      onClick,
      className: "opacity-0 group-hover/row:opacity-100 hover:bg-muted p-0.5 rounded transition-opacity shrink-0",
      title: "Expand all descendants",
      children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronsDown, { className: "size-3.5 text-muted-foreground" })
    }
  );
}
const JsonNode = reactExports.memo(function JsonNode2({
  name,
  value,
  level,
  defaultExpandDepth,
  isArrayItem,
  path,
  expandTargetPath,
  anatomyPaths
}) {
  const isAncestorOfTarget = reactExports.useMemo(() => {
    if (expandTargetPath === null) return false;
    if (path === "") return expandTargetPath.length > 0;
    return expandTargetPath === path || expandTargetPath.startsWith(`${path}/`);
  }, [expandTargetPath, path]);
  const initialExpanded = level < defaultExpandDepth || isAncestorOfTarget && isExpandable(value);
  const [expanded, setExpanded] = reactExports.useState(initialExpanded);
  reactExports.useEffect(() => {
    if (isAncestorOfTarget && isExpandable(value) && !expanded) {
      setExpanded(true);
    }
  }, [expandTargetPath]);
  const [childResetKey, setChildResetKey] = reactExports.useState(0);
  const [childDepthOverride, setChildDepthOverride] = reactExports.useState(null);
  const expandable = isExpandable(value);
  const fullyExpanded = childDepthOverride === Number.POSITIVE_INFINITY;
  const entries = reactExports.useMemo(() => getEntries(value), [value]);
  const hasExpandableChild = reactExports.useMemo(
    () => entries.some(([, child]) => isExpandable(child)),
    [entries]
  );
  const dataType = classifyValue(value);
  const openBracket = dataType === "array" ? "[" : "{";
  const closeBracket = dataType === "array" ? "]" : "}";
  const hasAnatomyPath = anatomyPaths !== null && anatomyPaths.has(path);
  function expandAllDeep() {
    setExpanded(true);
    setChildDepthOverride(Number.POSITIVE_INFINITY);
    setChildResetKey((k) => k + 1);
  }
  function collapseToDefault() {
    setExpanded(false);
    setChildDepthOverride(0);
    setChildResetKey((k) => k + 1);
  }
  function handleRowToggle() {
    if (fullyExpanded) {
      collapseToDefault();
    } else {
      setExpanded(!expanded);
    }
  }
  function handleExpandAll(e) {
    e.stopPropagation();
    expandAllDeep();
  }
  const effectiveChildDepth = childDepthOverride ?? defaultExpandDepth;
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cn(level > 0 && "border-l border-border/50 ml-2"), children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      "div",
      {
        className: cn(
          "flex items-start gap-1 py-0.5 px-1 -ml-1 rounded-sm group/row",
          expandable && "cursor-pointer hover:bg-muted/50"
        ),
        "data-anatomy-path": hasAnatomyPath ? path : void 0,
        onClick: expandable ? handleRowToggle : void 0,
        onKeyDown: expandable ? (e) => {
          if (e.key === "Enter" || e.key === " ") {
            e.preventDefault();
            handleRowToggle();
          }
        } : void 0,
        onDoubleClick: expandable && hasExpandableChild ? () => expandAllDeep() : void 0,
        role: expandable ? "button" : void 0,
        tabIndex: expandable ? 0 : void 0,
        children: [
          expandable ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "w-4 h-5 flex items-center justify-center shrink-0", children: expanded ? /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronDown, { className: "size-3 text-muted-foreground" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "size-3 text-muted-foreground" }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "w-4 shrink-0" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: cn("shrink-0", isArrayItem ? "text-muted-foreground" : "text-cyan-400"), children: isArrayItem ? name : `"${name}"` }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground shrink-0", children: expandable ? "" : ":" }),
          expandable ? /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-muted-foreground", children: [
            openBracket,
            /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-muted-foreground/60 text-xs", children: [
              " ",
              entries.length,
              " ",
              entries.length === 1 ? "item" : "items",
              " ",
              closeBracket
            ] })
          ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "min-w-0", children: /* @__PURE__ */ jsxRuntimeExports.jsx(PrimitiveValue, { value }) }),
          expandable && hasExpandableChild && !fullyExpanded && /* @__PURE__ */ jsxRuntimeExports.jsx(ExpandCollapseButton, { onClick: handleExpandAll }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(CopyButton, { value })
        ]
      }
    ),
    expandable && expanded && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "pl-4", children: [
      entries.map(([key, childValue]) => /* @__PURE__ */ jsxRuntimeExports.jsx(
        JsonNode2,
        {
          name: key,
          value: childValue,
          level: level + 1,
          defaultExpandDepth: effectiveChildDepth,
          isArrayItem: dataType === "array",
          path: path === "" ? `/${key}` : `${path}/${key}`,
          expandTargetPath,
          anatomyPaths
        },
        key
      )),
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground py-0.5 px-1", children: closeBracket })
    ] }, childResetKey)
  ] });
});
function JsonViewer({
  data,
  defaultExpandDepth = 0,
  className,
  showCopy = false,
  bulkDepth: controlledBulkDepth,
  bulkRevision: controlledBulkRevision,
  anatomyPaths = null,
  expandToPath = null
}) {
  const expandable = isExpandable(data);
  const entries = reactExports.useMemo(() => getEntries(data), [data]);
  const bulkDepth = controlledBulkDepth ?? defaultExpandDepth;
  const bulkRevision = controlledBulkRevision ?? 0;
  if (!expandable) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: cn("font-mono text-xs leading-relaxed", className), children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(PrimitiveValue, { value: data }),
      showCopy && /* @__PURE__ */ jsxRuntimeExports.jsx(CopyValueButton, { value: data })
    ] }) }) });
  }
  const dataType = classifyValue(data);
  const isArray = dataType === "array";
  return /* @__PURE__ */ jsxRuntimeExports.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cn("font-mono text-xs leading-relaxed", className), children: [
    showCopy && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mb-2 flex items-center justify-end gap-2", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CopyValueButton, { value: data }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: entries.map(([key, childValue]) => /* @__PURE__ */ jsxRuntimeExports.jsx(
      JsonNode,
      {
        name: key,
        value: childValue,
        level: 0,
        defaultExpandDepth: bulkDepth,
        isArrayItem: isArray,
        path: `/${key}`,
        expandTargetPath: expandToPath,
        anatomyPaths
      },
      key
    )) }, bulkRevision)
  ] }) });
}
const JsonViewerFromString = reactExports.memo(function JsonViewerFromString2({
  text,
  defaultExpandDepth = 0,
  className
}) {
  const parsed = reactExports.useMemo(() => parseJsonText(text), [text]);
  if (parsed.kind === "json") {
    return /* @__PURE__ */ jsxRuntimeExports.jsx(
      JsonViewer,
      {
        data: parsed.data,
        defaultExpandDepth,
        className
      }
    );
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsx("pre", { className: cn("font-mono text-xs whitespace-pre-wrap break-words", className), children: text });
});
export {
  JsonViewer,
  JsonViewerFromString
};
