import { j as jsxRuntimeExports } from "../../../../../../_virtual/jsx-runtime.js";
import { createContext, useContext } from "react";
import "../../../../../../node_modules/.pnpm/@formkit_auto-animate@0.8.2/node_modules/@formkit/auto-animate/index.js";
import "../../../../../../node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/react-hot-toast/dist/index.js";
import { tx as D } from "../../../../../style-system/dist/twind.js";
import { VscSymbolArray, VscSymbolBoolean, VscSymbolString } from "../../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.1.1/node_modules/react-icons/vsc/index.js";
import { CiCalendarDate } from "../../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.1.1/node_modules/react-icons/ci/index.js";
import { HiMiniHashtag, HiMiniAtSymbol } from "../../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.1.1/node_modules/react-icons/hi2/index.js";
import { GoRelFilePath, GoNumber } from "../../../../../../node_modules/.pnpm/react-icons@5.5.0_react@19.1.1/node_modules/react-icons/go/index.js";
import { Text as p } from "../../../../../../node_modules/.pnpm/@radix-ui_themes@3.2.1_@types_react-dom@19.1.9_@types_react@19.1.13__@types_react@19.1._832fa1fef691e6e9510ada03948dc85c/node_modules/@radix-ui/themes/dist/esm/components/text.js";
const NestingContext = createContext(0);
const ChoiceContext = createContext({
  onFieldSelect: () => {
  }
});
const typesIconsMap = {
  string: /* @__PURE__ */ jsxRuntimeExports.jsx(VscSymbolString, { className: "text-upstart-600" }),
  number: /* @__PURE__ */ jsxRuntimeExports.jsx(GoNumber, { className: "text-upstart-600" }),
  boolean: /* @__PURE__ */ jsxRuntimeExports.jsx(VscSymbolBoolean, { className: "text-upstart-600" }),
  array: /* @__PURE__ */ jsxRuntimeExports.jsx(VscSymbolArray, { className: "text-upstart-600" }),
  "date-time": /* @__PURE__ */ jsxRuntimeExports.jsx(CiCalendarDate, { className: "text-upstart-600" }),
  date: /* @__PURE__ */ jsxRuntimeExports.jsx(CiCalendarDate, { className: "text-upstart-600" }),
  email: /* @__PURE__ */ jsxRuntimeExports.jsx(HiMiniAtSymbol, { className: "text-upstart-600" }),
  slug: /* @__PURE__ */ jsxRuntimeExports.jsx(GoRelFilePath, { className: "text-upstart-600" }),
  nanoid: /* @__PURE__ */ jsxRuntimeExports.jsx(HiMiniHashtag, { className: "text-upstart-600" })
};
function SchemaEntry({ schema, prefix }) {
  const nestingLevel = useContext(NestingContext);
  const { onFieldSelect } = useContext(ChoiceContext);
  return /* @__PURE__ */ jsxRuntimeExports.jsx(NestingContext.Provider, { value: nestingLevel + 1, children: /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { id: `${schema.name}_level-${nestingLevel}`, className: "mb-1", children: schema.type === "object" ? /* @__PURE__ */ jsxRuntimeExports.jsx(SchemaObject, { schema, prefix }) : /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { className: "flex items-center gap-0.5 w-full shrink-0 flex-nowrap", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(p, { size: "3", children: typesIconsMap[schema.format] || typesIconsMap[schema.type] || /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-500", children: "?" }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(
      p,
      {
        size: "2",
        onClick: () => onFieldSelect(`${prefix}.${schema.name}`),
        className: "hover:bg-upstart-50 cursor-pointer px-1 py-0.5 rounded text-nowrap",
        children: schema.title
      }
    ),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(p, { color: "gray", size: "1", className: "text-nowrap", children: [
      "— ",
      prefix,
      ".",
      schema.name
    ] })
  ] }) }) });
}
function SchemaObject({
  schema: { name, required, properties },
  prefix
}) {
  if (properties)
    return /* @__PURE__ */ jsxRuntimeExports.jsxs("ul", { className: "list-disc", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("li", { className: D({ hidden: !name }), children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: name }) }),
      Object.entries(properties).sort(([p1], [p2]) => p1.localeCompare(p2)).map(([name2, value], i) => /* @__PURE__ */ jsxRuntimeExports.jsx(
        SchemaEntry,
        {
          schema: { ...value, name: name2, optional: required && !required.includes(name2) },
          prefix
        },
        `${name2}-${i}`
      ))
    ] });
  return null;
}
function JSONSchemaView({
  schema,
  prefix,
  onFieldSelect
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ChoiceContext.Provider, { value: { onFieldSelect }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(NestingContext.Provider, { value: 0, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SchemaEntry, { schema: schema.items, prefix }) }) });
}
export {
  JSONSchemaView
};
//# sourceMappingURL=SchemaView.js.map
