import { _ as J, g as Ke, t as Z, N as Je, b as pe, c as de, U as Ze, e as He, a as Xe, T as Ye, L as fe, f as me, h as Qe, G as et, i as tt, S as nt, j as rt } from "../deep-merge-Bsqkvp9-.js";
import { html as p, attr as m, Fragment as H, MapSignal as U, Value as I, computedOf as w, prop as it, WithElement as st, OnDispose as at } from "@tempots/dom";
import { b, a as ne, I as B, S as V, L as ye, d as ut, M as ot, f as re, A as G, g as ct, i as ie } from "../use-form-DMiCxK26.js";
import { T as lt, B as E } from "../translations-BEMKy6-W.js";
import { N as pt, B as dt, D as ft, a as mt, P as yt, b as gt, c as ht, d as bt, e as vt, F as xt } from "../duration-input-DcZf0Dyd.js";
import { l as $t } from "../colors-DPo9GEJR.js";
function It(e) {
  return e === "int64" || e === "int128" || e === "uint64" || e === "uint128";
}
function P(e) {
  return e === "int8" || e === "int16" || e === "int32" || e === "int64" || e === "int128" || e === "uint8" || e === "uint16" || e === "uint32" || e === "uint64" || e === "uint128";
}
function X(e) {
  return e === "float" || e === "double" || e === "decimal";
}
function wt(e) {
  return P(e) || X(e);
}
function Y(e) {
  return e === "date" || e === "datetime" || e === "time" || e === "duration";
}
function Tt(e) {
  return e === "string" || e === "boolean" || e === "null" || wt(e) || Y(e) || e === "uuid" || e === "uri" || e === "binary";
}
function ur(e) {
  return e === "object" || e === "array" || e === "set" || e === "map" || e === "tuple" || e === "choice" || e === "any";
}
function C(e) {
  return typeof e == "object" && e !== null && "$ref" in e;
}
function jt(e) {
  return typeof e == "object" && e !== null && !("type" in e) && !("$ref" in e) && !("enum" in e) && !("const" in e);
}
function At(e) {
  return typeof e == "object" && e !== null && ("type" in e || "$ref" in e || "enum" in e || "const" in e);
}
function k(e) {
  return e.type === "object" && "properties" in e;
}
function ge(e) {
  return e.type === "array" && "items" in e;
}
function he(e) {
  return e.type === "set" && "items" in e;
}
function be(e) {
  return e.type === "map" && "values" in e;
}
function ve(e) {
  return e.type === "tuple" && "tuple" in e;
}
function xe(e) {
  return e.type === "choice" && "choices" in e;
}
function Mt(e) {
  return "enum" in e && Array.isArray(e.enum);
}
function Dt(e) {
  return "const" in e;
}
function se(e) {
  return e === void 0 ? null : typeof e == "string" || Array.isArray(e) ? e : (C(e), null);
}
function St(e) {
  return e === void 0 ? !1 : e === "null" ? !0 : Array.isArray(e) ? e.includes("null") : !1;
}
function Q(e) {
  return typeof e == "string" ? e === "null" ? [] : [e] : Array.isArray(e) ? e.filter((t) => t !== "null") : [];
}
const W = {
  int8: { min: -128n, max: 127n },
  int16: { min: -32768n, max: 32767n },
  int32: { min: -2147483648n, max: 2147483647n },
  int64: { min: -9223372036854775808n, max: 9223372036854775807n },
  int128: {
    min: -170141183460469231731687303715884105728n,
    max: 170141183460469231731687303715884105727n
  },
  uint8: { min: 0n, max: 255n },
  uint16: { min: 0n, max: 65535n },
  uint32: { min: 0n, max: 4294967295n },
  uint64: { min: 0n, max: 18446744073709551615n },
  uint128: { min: 0n, max: 340282366920938463463374607431768211455n }
};
function Ot(e) {
  return e.startsWith("#/") ? e.slice(2).split("/") : e.includes("/") ? e.split("/") : ["definitions", e];
}
function Ct(e, t) {
  let n = e;
  for (const r of t) {
    if (n == null || typeof n != "object")
      return;
    n = n[r];
  }
  return n;
}
function N(e, t) {
  const n = Ot(e), r = Ct(t, n);
  if (r == null) {
    console.warn(`Failed to resolve $ref: ${e}`);
    return;
  }
  if (At(r))
    return r;
  if (jt(r)) {
    console.warn(`$ref "${e}" points to a namespace, not a type definition`);
    return;
  }
}
function or(e, t) {
  return N(e.$ref, t);
}
class Rt {
  schema;
  visited = /* @__PURE__ */ new Set();
  constructor(t) {
    this.schema = t;
  }
  /**
   * Resolve a reference, tracking visited refs to prevent infinite loops
   */
  resolve(t) {
    if (this.visited.has(t)) {
      console.warn(`Circular reference detected: ${t}`);
      return;
    }
    this.visited.add(t);
    try {
      const n = N(t, this.schema);
      if (n?.type && C(n.type)) {
        const r = this.resolve(n.type.$ref);
        if (r) {
          const { type: s, ...a } = n;
          return { ...r, ...a };
        }
      }
      return n;
    } finally {
      this.visited.delete(t);
    }
  }
  /**
   * Resolve a type definition, handling any $ref in its type specifier
   */
  resolveDefinition(t) {
    if (t.type && C(t.type)) {
      const n = this.resolve(t.type.$ref);
      if (n) {
        const { type: r, ...s } = t;
        return { ...n, ...s };
      }
    }
    return t;
  }
  /**
   * Reset the visited tracking (use between independent resolution calls)
   */
  reset() {
    this.visited.clear();
  }
}
function ee(e) {
  return new Rt(e);
}
class te {
  schema;
  definition;
  path;
  readOnly;
  locale;
  widgetRegistry;
  isPropertyRequired;
  suppressLabel;
  refResolver;
  constructor(t) {
    this.schema = t.schema, this.definition = t.definition, this.path = t.path, this.readOnly = t.readOnly ?? !1, this.locale = t.locale, this.widgetRegistry = t.widgetRegistry, this.isPropertyRequired = t.isPropertyRequired ?? !1, this.suppressLabel = t.suppressLabel ?? !1, this.refResolver = t.refResolver ?? ee(t.schema);
  }
  /**
   * Create a new context with updated fields
   */
  with(t) {
    return new te({
      schema: this.schema,
      definition: t.definition ?? this.definition,
      path: t.path ?? this.path,
      readOnly: t.readOnly ?? this.readOnly,
      locale: t.locale ?? this.locale,
      widgetRegistry: t.widgetRegistry ?? this.widgetRegistry,
      isPropertyRequired: t.isPropertyRequired ?? this.isPropertyRequired,
      suppressLabel: t.suppressLabel ?? this.suppressLabel,
      refResolver: this.refResolver
    });
  }
  /**
   * Create a child context by appending to the path
   */
  append(t) {
    return this.with({ path: [...this.path, t] });
  }
  /**
   * Check if this is the root context
   */
  get isRoot() {
    return this.path.length === 0;
  }
  /**
   * Get the property name (last segment of path)
   */
  get name() {
    const t = this.path[this.path.length - 1];
    return typeof t == "string" ? t : void 0;
  }
  /**
   * Get the widget name (dot-separated path)
   */
  get widgetName() {
    return this.path.map(String).join(".");
  }
  /**
   * Get the resolved type(s) from the definition
   */
  get resolvedType() {
    const t = this.definition.type;
    if (!t) return null;
    if (C(t)) {
      const n = this.refResolver.resolve(t.$ref);
      return n?.type ? se(n.type) : null;
    }
    return se(t);
  }
  /**
   * Get the primary type (first non-null type)
   */
  get primaryType() {
    const t = this.resolvedType;
    return t ? typeof t == "string" ? t === "null" ? null : t : Q(t)[0] ?? null : null;
  }
  /**
   * Check if this type is nullable
   */
  get isNullable() {
    return St(this.definition.type);
  }
  /**
   * Check if this is a required field
   */
  get isRequired() {
    return this.isPropertyRequired;
  }
  /**
   * Check if this is an optional field (can be absent)
   */
  get isOptional() {
    return !this.isPropertyRequired;
  }
  /**
   * Check if this field is deprecated
   */
  get isDeprecated() {
    return this.definition.deprecated === !0;
  }
  /**
   * Check if this type is abstract
   */
  get isAbstract() {
    return this.definition.abstract === !0;
  }
  /**
   * Check if this is a primitive type
   */
  get isPrimitive() {
    const t = this.primaryType;
    return t != null && Tt(t);
  }
  /**
   * Get the description from the definition
   */
  get description() {
    return this.definition.description;
  }
  /**
   * Get examples from the definition
   */
  get examples() {
    return this.definition.examples;
  }
  /**
   * Get the default value from the definition
   */
  get defaultValue() {
    return this.definition.default;
  }
  /**
   * Get the unit for numeric values
   */
  get unit() {
    return this.definition.unit;
  }
  /**
   * Get the currency for monetary values
   */
  get currency() {
    return this.definition.currency;
  }
  /**
   * Get the label for this field
   *
   * Resolution order:
   * 1. Locale-specific altname (if locale is set)
   * 2. Definition name
   * 3. Humanized path name
   */
  get label() {
    if (this.locale && this.definition.altnames) {
      const n = `lang:${this.locale}`, r = this.definition.altnames[n];
      if (r) return r;
    }
    if (this.definition.name)
      return this.definition.name;
    const t = this.name;
    return t ? J(Ke(t)) : "";
  }
  /**
   * Get altnames from the definition
   */
  get altnames() {
    return this.definition.altnames;
  }
  /**
   * Get the JSON path string (for validation error matching)
   */
  get jsonPath() {
    return this.path.length === 0 ? "" : "/" + this.path.map(String).join("/");
  }
  /**
   * Resolve a $ref using the shared resolver
   */
  resolveRef(t) {
    return this.refResolver.resolve(t);
  }
  /**
   * Check if this definition has an enum constraint
   */
  get hasEnum() {
    return "enum" in this.definition && Array.isArray(this.definition.enum);
  }
  /**
   * Get enum values if present
   */
  get enumValues() {
    if ("enum" in this.definition)
      return this.definition.enum;
  }
  /**
   * Check if this definition has a const constraint
   */
  get hasConst() {
    return "const" in this.definition;
  }
  /**
   * Get const value if present
   */
  get constValue() {
    if ("const" in this.definition)
      return this.definition.const;
  }
  /**
   * Get string format if defined (for string types)
   */
  get format() {
    if ("format" in this.definition)
      return this.definition.format;
  }
}
function kt(e, t) {
  let n;
  const r = ee(e);
  if (e.$root) {
    const s = r.resolve(e.$root);
    s ? n = s : (console.warn(`Failed to resolve $root: ${e.$root}`), n = e);
  } else e.type || e.properties ? n = e : n = { type: "any" };
  return new te({
    schema: e,
    definition: n,
    path: [],
    readOnly: t?.readOnly,
    locale: t?.locale,
    widgetRegistry: t?.widgetRegistry,
    refResolver: r
  });
}
function $e(e, t, n) {
  const r = [], s = [];
  if (!e.$extends)
    return { merged: e, inheritanceChain: r, errors: s };
  const a = Array.isArray(e.$extends) ? e.$extends : [e.$extends], u = /* @__PURE__ */ new Set(), i = (l, y = 0) => {
    if (y > 100)
      return s.push({
        path: l.join(" -> "),
        message: "Maximum inheritance depth exceeded"
      }), [];
    const h = [];
    for (const f of l) {
      if (u.has(f)) {
        s.push({
          path: f,
          message: `Circular inheritance detected: ${f}`
        });
        continue;
      }
      u.add(f), r.push(f);
      const g = N(f, t);
      if (!g) {
        s.push({
          path: f,
          message: `Failed to resolve base type: ${f}`
        });
        continue;
      }
      if (g.$extends) {
        const d = Array.isArray(g.$extends) ? g.$extends : [g.$extends], v = i(d, y + 1);
        h.push(...v);
      }
      h.push(g), u.delete(f);
    }
    return h;
  }, o = i(a);
  return { merged: Nt(o, e), inheritanceChain: r, errors: s };
}
function Nt(e, t) {
  if (e.length === 0)
    return t;
  let n = { ...e[0] };
  for (let a = 1; a < e.length; a++)
    n = ae(n, e[a]);
  n = ae(n, t);
  const { $extends: r, ...s } = n;
  return s;
}
function ae(e, t) {
  return k(e) && k(t) ? qt(e, t) : { ...e, ...t };
}
function qt(e, t) {
  const n = {
    ...e.properties ?? {},
    ...t.properties ?? {}
  }, r = ue(e.required), s = ue(t.required), a = Pt([...r, ...s]), u = {
    ...e,
    ...t,
    type: "object",
    properties: n
  };
  return a.length > 0 && (u.required = a), u;
}
function ue(e) {
  return e ? e.length === 0 ? [] : Array.isArray(e[0]) ? e.flat() : e : [];
}
function Pt(e) {
  return [...new Set(e)];
}
function cr(e) {
  const t = ee(e);
  return {
    resolve: (n) => (t.reset(), $e(n, e))
  };
}
function Ft() {
  return p.span(
    m.class("bc-json-structure-deprecated-badge"),
    m.style(
      "font-size: var(--font-size-xs); color: var(--color-warning-500, #d97706); background: var(--color-warning-100, #fef3c7); padding: 0.125em 0.5em; border-radius: var(--radius-sm); margin-inline-start: 0.5em; font-weight: normal;"
    ),
    "(deprecated)"
  );
}
function T(e, t) {
  return !e || !t ? e ?? "" : p.span(e, Ft());
}
function Lt(e) {
  const t = e.examples?.[0] != null ? String(e.examples[0]) : void 0;
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated,
    placeholder: t
  };
}
function Ie({
  ctx: e,
  controller: t
}) {
  const n = Lt(e);
  return b(lt, {
    ...n,
    controller: Z(t)
  });
}
function Vt(e) {
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated
  };
}
function we({
  ctx: e,
  controller: t
}) {
  const n = Vt(e), r = b(ne, {
    ...n,
    controller: t
  });
  return e.isNullable ? b(ne, {
    ...n,
    controller: t,
    after: Je(
      t.signal,
      t.disabled,
      (s) => t.change(s)
    )
  }) : r;
}
function Et(e, t) {
  const n = W[t], r = Te(e, n.min), s = je(e, n.max), a = e.examples?.[0] != null ? String(e.examples[0]) : void 0;
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated,
    // Convert to numbers for NumberInput
    min: typeof r == "bigint" ? Number(r) : r,
    max: typeof s == "bigint" ? Number(s) : s,
    step: 1,
    placeholder: a
  };
}
function Ut(e, t) {
  const n = W[t], r = Te(e, n.min), s = je(e, n.max), a = e.examples?.[0] != null ? String(e.examples[0]) : void 0;
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated,
    // Ensure bigint for BigintInput
    min: typeof r == "number" ? BigInt(r) : r,
    max: typeof s == "number" ? BigInt(s) : s,
    placeholder: a
  };
}
function Te(e, t) {
  const n = e.definition;
  if (n.minimum !== void 0) {
    const r = typeof n.minimum == "string" ? BigInt(n.minimum) : n.minimum;
    return typeof r == "bigint" ? r > t ? r : t : BigInt(r) > t ? r : Number(t);
  }
  if (n.exclusiveMinimum !== void 0) {
    const r = typeof n.exclusiveMinimum == "string" ? BigInt(n.exclusiveMinimum) : n.exclusiveMinimum, s = typeof r == "bigint" ? r + 1n : r + 1;
    return typeof s == "bigint" ? s > t ? s : t : BigInt(s) > t ? s : Number(t);
  }
  return t >= BigInt(Number.MIN_SAFE_INTEGER) && t <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(t) : t;
}
function je(e, t) {
  const n = e.definition;
  if (n.maximum !== void 0) {
    const r = typeof n.maximum == "string" ? BigInt(n.maximum) : n.maximum;
    return typeof r == "bigint" ? r < t ? r : t : BigInt(r) < t ? r : Number(t);
  }
  if (n.exclusiveMaximum !== void 0) {
    const r = typeof n.exclusiveMaximum == "string" ? BigInt(n.exclusiveMaximum) : n.exclusiveMaximum, s = typeof r == "bigint" ? r - 1n : r - 1;
    return typeof s == "bigint" ? s < t ? s : t : BigInt(s) < t ? s : Number(t);
  }
  return t >= BigInt(Number.MIN_SAFE_INTEGER) && t <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(t) : t;
}
function Ae({
  ctx: e,
  controller: t,
  intType: n
}) {
  if (It(n)) {
    const s = Ut(e, n);
    return e.isNullable ? b(pt, {
      ...s,
      controller: t
    }) : b(dt, {
      ...s,
      controller: t
    });
  }
  const r = Et(e, n);
  return e.isNullable ? b(pe, {
    ...r,
    controller: t
  }) : b(de, {
    ...r,
    controller: t
  });
}
function Bt(e, t) {
  const n = e.definition;
  let r;
  n.multipleOf !== void 0 ? r = n.multipleOf : t === "decimal" && n.scale !== void 0 ? r = Math.pow(10, -n.scale) : r = void 0;
  const s = n.minimum !== void 0 ? typeof n.minimum == "string" ? parseFloat(n.minimum) : n.minimum : void 0, a = n.maximum !== void 0 ? typeof n.maximum == "string" ? parseFloat(n.maximum) : n.maximum : void 0, u = n.exclusiveMinimum !== void 0 ? typeof n.exclusiveMinimum == "string" ? parseFloat(n.exclusiveMinimum) : n.exclusiveMinimum : void 0, i = n.exclusiveMaximum !== void 0 ? typeof n.exclusiveMaximum == "string" ? parseFloat(n.exclusiveMaximum) : n.exclusiveMaximum : void 0;
  let o = e.description;
  if (u !== void 0 || i !== void 0) {
    const l = [];
    u !== void 0 && l.push(`> ${u}`), i !== void 0 && l.push(`< ${i}`);
    const y = `Valid range: ${l.join(" and ")}`;
    o = o ? `${o} (${y})` : y;
  }
  const c = e.examples?.[0] != null ? String(e.examples[0]) : void 0;
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: o,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated,
    min: s ?? u,
    max: a ?? i,
    step: r,
    placeholder: c
  };
}
function Me({
  ctx: e,
  controller: t,
  floatType: n
}) {
  const r = Bt(e, n);
  return e.isNullable ? b(pe, {
    ...r,
    controller: t
  }) : b(de, {
    ...r,
    controller: t
  });
}
function Wt(e) {
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated,
    placeholder: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  };
}
function De({
  ctx: e,
  controller: t
}) {
  const n = Wt(e);
  return b(Ze, {
    ...n,
    controller: Z(t)
  });
}
function _t(e) {
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated
  };
}
function Se({
  ctx: e,
  controller: t,
  temporalType: n
}) {
  const r = _t(e);
  switch (n) {
    case "date":
      return e.isNullable ? b(bt, {
        ...r,
        controller: t
      }) : b(vt, {
        ...r,
        controller: t
      });
    case "datetime":
      return e.isNullable ? b(gt, {
        ...r,
        controller: t
      }) : b(ht, {
        ...r,
        controller: t
      });
    case "time":
      return e.isNullable ? b(mt, {
        ...r,
        controller: t
      }) : b(yt, {
        ...r,
        controller: t
      });
    case "duration":
      return e.isNullable ? b(He, {
        ...r,
        controller: t
      }) : b(ft, {
        ...r,
        controller: t
      });
    default:
      return console.warn(`Unknown temporal type: ${n}`), H();
  }
}
function zt(e) {
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated,
    placeholder: "https://example.com"
  };
}
function Oe({
  ctx: e,
  controller: t
}) {
  const n = zt(e);
  return b(Xe, {
    ...n,
    controller: Z(t)
  });
}
function Gt(e) {
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated
  };
}
function Ce({
  ctx: e,
  controller: t
}) {
  const n = Gt(e);
  return b(xt, {
    ...n,
    controller: t
  });
}
function Kt(e) {
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated,
    placeholder: "Enter JSON value"
  };
}
function Jt(e) {
  return e.transform(
    // To input: serialize value to JSON string
    (t) => t === void 0 ? void 0 : JSON.stringify(t, null, 2),
    // From input: parse JSON string back to value
    (t) => {
      if (!(t === void 0 || t.trim() === ""))
        try {
          return JSON.parse(t);
        } catch {
          return t;
        }
    }
  );
}
function K({
  ctx: e,
  controller: t
}) {
  const n = Kt(e);
  return b(Ye, {
    ...n,
    controller: Jt(t)
  });
}
function Zt(e) {
  return {
    label: e.suppressLabel ? void 0 : e.label,
    description: e.description,
    required: e.isRequired
  };
}
function Ht(e, t) {
  return !t || t.length === 0 ? !1 : typeof t[0] == "string" ? t.includes(e) : Array.isArray(t[0]) ? t.some((n) => n.includes(e)) : !1;
}
function Xt(e) {
  if (e.default !== void 0)
    return e.default;
  if (e.examples && e.examples.length > 0)
    return e.examples[0];
  if (!e.type) return;
  const t = Array.isArray(e.type) ? e.type[0] : e.type;
  if (!(typeof t == "object" && "$ref" in t))
    switch (t) {
      case "string":
        return "";
      case "boolean":
        return !1;
      case "null":
        return null;
      case "object":
        return {};
      case "array":
      case "set":
        return [];
      case "map":
        return {};
      case "any":
        return;
      default:
        return t === "int8" || t === "int16" || t === "int32" || t === "int64" || t === "uint8" || t === "uint16" || t === "uint32" || t === "uint64" || t === "float" || t === "double" || t === "decimal" ? 0 : void 0;
    }
}
function Yt(e, t = "property") {
  if (!e.has(t)) return t;
  let n = 1;
  for (; e.has(`${t}${n}`); )
    n++;
  return `${t}${n}`;
}
function Re({
  ctx: e,
  controller: t
}) {
  const n = e.definition;
  return n.type !== "object" || !("properties" in n) ? (console.warn("StructureObjectControl requires an ObjectTypeDefinition"), p.div("Invalid object definition")) : U(t.signal, (r) => {
    const s = n.properties, a = n.required, u = n.additionalProperties, i = u !== !1, o = typeof u == "object" && u !== null ? u : { type: "any" }, c = n.minProperties ?? 0, l = n.maxProperties ?? 1 / 0, y = $t(s), h = new Set(
      y.map(([x]) => x)
    ), f = Object.keys(r ?? {}), g = f.filter((x) => !h.has(x)), d = i && f.length < l && !e.readOnly, v = f.length > c && !e.readOnly, $ = y.map(([x, O]) => {
      const D = x, z = t.field(D), Ge = Ht(D, a);
      return j({
        ctx: e.with({
          definition: O,
          isPropertyRequired: Ge,
          suppressLabel: !1
        }).append(D),
        controller: z
      });
    }), A = g.map((x) => {
      const O = t.field(x);
      return p.div(
        m.class("bc-json-structure-additional-property"),
        p.div(
          m.class("bc-json-structure-additional-property-header"),
          p.strong(`${x}:`),
          E(
            {
              variant: "text",
              size: "xs",
              onClick: () => {
                const D = { ...I.get(t.signal) ?? {} };
                delete D[x], t.change(D);
              },
              disabled: !v
            },
            "Remove"
          )
        ),
        p.div(
          m.class("bc-json-structure-additional-property-value"),
          j({
            ctx: e.with({
              definition: o,
              isPropertyRequired: !1,
              suppressLabel: !0
            }).append(x),
            controller: O
          })
        )
      );
    }), q = d ? E(
      {
        variant: "outline",
        size: "sm",
        onClick: () => {
          const x = I.get(t.signal) ?? {}, O = new Set(Object.keys(x)), D = Yt(O), z = Xt(o);
          t.change({
            ...x,
            [D]: z
          });
        }
      },
      "Add Property"
    ) : null, S = p.div(
      m.class("bc-json-structure-object-fields"),
      ...$,
      ...A,
      q
    ), R = p.div(
      m.class("bc-json-structure-object"),
      S
    );
    return !e.suppressLabel && e.name ? B({
      ...Zt(e),
      content: R
    }) : R;
  });
}
function Qt(e) {
  return {
    label: e.suppressLabel ? void 0 : e.label,
    description: e.description,
    required: e.isRequired
  };
}
function en(e) {
  if (e.default !== void 0)
    return e.default;
  if (e.examples && e.examples.length > 0)
    return e.examples[0];
  if (!e.type) return;
  const t = Array.isArray(e.type) ? e.type[0] : e.type;
  if (!(typeof t == "object" && "$ref" in t))
    switch (t) {
      case "string":
        return "";
      case "boolean":
        return !1;
      case "null":
        return null;
      case "object":
        return {};
      case "array":
      case "set":
        return [];
      case "map":
        return {};
      case "any":
        return;
      default:
        return t === "int8" || t === "int16" || t === "int32" || t === "int64" || t === "int128" || t === "uint8" || t === "uint16" || t === "uint32" || t === "uint64" || t === "uint128" || t === "float" || t === "double" || t === "decimal" ? 0 : void 0;
    }
}
function ke({
  ctx: e,
  controller: t
}) {
  const n = e.definition;
  if (n.type !== "array" || !("items" in n))
    return console.warn("StructureArrayControl requires an ArrayTypeDefinition"), p.div("Invalid array definition");
  const r = n.items, s = n.minItems ?? 0, a = n.maxItems ?? 1 / 0, u = w(t.signal)((o) => (o?.length ?? 0) < a), i = w(t.signal)((o) => (o?.length ?? 0) > s);
  return fe({
    ...Qt(e),
    controller: t,
    createItem: () => en(r),
    showAdd: !0,
    addDisabled: w(u)((o) => !o || e.readOnly),
    showRemove: !0,
    removeDisabled: w(i)((o) => !o || e.readOnly),
    element: (o) => {
      const c = o.position.index, l = o.item;
      return j({
        ctx: e.with({
          definition: r,
          suppressLabel: !0
        }).append(c),
        controller: l
      });
    }
  });
}
function tn(e) {
  return {
    label: e.suppressLabel ? void 0 : e.label,
    description: e.description,
    required: e.isRequired
  };
}
function nn(e) {
  if (e.default !== void 0)
    return e.default;
  if (e.examples && e.examples.length > 0)
    return e.examples[0];
  if (!e.type) return;
  const t = Array.isArray(e.type) ? e.type[0] : e.type;
  if (!(typeof t == "object" && "$ref" in t))
    switch (t) {
      case "string":
        return "";
      case "boolean":
        return !1;
      case "null":
        return null;
      case "object":
        return {};
      case "array":
      case "set":
        return [];
      case "map":
        return {};
      case "any":
        return;
      default:
        return t === "int8" || t === "int16" || t === "int32" || t === "int64" || t === "int128" || t === "uint8" || t === "uint16" || t === "uint32" || t === "uint64" || t === "uint128" || t === "float" || t === "double" || t === "decimal" ? 0 : void 0;
    }
}
function Ne({
  ctx: e,
  controller: t
}) {
  const n = e.definition;
  if (n.type !== "set" || !("items" in n))
    return console.warn("StructureSetControl requires a SetTypeDefinition"), p.div("Invalid set definition");
  const r = n.items, s = n.minItems ?? 0, a = n.maxItems ?? 1 / 0, u = w(t.signal)((c) => (c?.length ?? 0) < a), i = w(t.signal)((c) => (c?.length ?? 0) > s), o = w(t.signal)((c) => {
    if (!c || c.length === 0) return /* @__PURE__ */ new Set();
    const l = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Set();
    for (let h = 0; h < c.length; h++) {
      const f = JSON.stringify(c[h]);
      l.has(f) ? (y.add(l.get(f)), y.add(h)) : l.set(f, h);
    }
    return y;
  });
  return fe({
    ...tn(e),
    controller: t,
    createItem: () => nn(r),
    showAdd: !0,
    addDisabled: w(u)((c) => !c || e.readOnly),
    showRemove: !0,
    removeDisabled: w(i)((c) => !c || e.readOnly),
    element: (c) => {
      const l = c.position.index, y = c.item, h = o.map((g) => g.has(l)), f = j({
        ctx: e.with({
          definition: r,
          suppressLabel: !0
        }).append(l),
        controller: y
      });
      return h.map((g) => g ? V(
        m.class("bc-stack--gap-1"),
        f,
        ye(
          m.class("bc-json-structure-set-error"),
          "⚠️ Duplicate value - sets must contain unique items"
        )
      ) : f);
    }
  });
}
function rn(e) {
  return {
    label: e.suppressLabel ? void 0 : e.label,
    description: e.description,
    required: e.isRequired
  };
}
function sn(e) {
  if (e.default !== void 0)
    return e.default;
  if (e.examples && e.examples.length > 0)
    return e.examples[0];
  if (!e.type) return;
  const t = Array.isArray(e.type) ? e.type[0] : e.type;
  if (!(typeof t == "object" && "$ref" in t))
    switch (t) {
      case "string":
        return "";
      case "boolean":
        return !1;
      case "null":
        return null;
      case "object":
        return {};
      case "array":
      case "set":
        return [];
      case "map":
        return {};
      case "any":
        return;
      default:
        return t === "int8" || t === "int16" || t === "int32" || t === "int64" || t === "int128" || t === "uint8" || t === "uint16" || t === "uint32" || t === "uint64" || t === "uint128" || t === "float" || t === "double" || t === "decimal" ? 0 : void 0;
    }
}
function an(e, t = "key") {
  if (!e.has(t)) return t;
  let n = 1;
  for (; e.has(`${t}${n}`); )
    n++;
  return `${t}${n}`;
}
function qe({
  ctx: e,
  controller: t
}) {
  const n = e.definition;
  if (n.type !== "map" || !("values" in n))
    return console.warn("StructureMapControl requires a MapTypeDefinition"), p.div("Invalid map definition");
  const r = n.values, s = n.minProperties ?? 0, a = n.maxProperties ?? 1 / 0;
  return U(t.signal, (u) => {
    const i = Object.keys(u ?? {}), o = i.length, c = o < a && !e.readOnly, l = o > s && !e.readOnly, y = i.map((d) => {
      const v = t.field(d);
      return p.div(
        m.class("bc-json-structure-map-entry"),
        p.div(
          m.class("bc-json-structure-map-entry-header"),
          p.strong(m.class("bc-json-structure-map-entry-key"), `${d}:`),
          E(
            {
              variant: "text",
              size: "xs",
              onClick: () => {
                const $ = { ...I.get(t.signal) ?? {} };
                delete $[d], t.change($);
              },
              disabled: !l
            },
            "Remove"
          )
        ),
        p.div(
          m.class("bc-json-structure-map-entry-value"),
          j({
            ctx: e.with({
              definition: r,
              suppressLabel: !0
            }).append(d),
            controller: v
          })
        )
      );
    }), h = c ? E(
      {
        variant: "outline",
        size: "sm",
        onClick: () => {
          const d = I.get(t.signal) ?? {}, v = new Set(Object.keys(d)), $ = an(v), A = sn(r);
          t.change({
            ...d,
            [$]: A
          });
        }
      },
      "Add Entry"
    ) : null, f = p.div(
      m.class("bc-json-structure-map-entries"),
      ...y,
      h
    ), g = p.div(
      m.class("bc-json-structure-map"),
      f
    );
    return !e.suppressLabel && e.name ? B({
      ...rn(e),
      content: g
    }) : g;
  });
}
function un(e) {
  return {
    label: e.suppressLabel ? void 0 : e.label,
    description: e.description,
    required: e.isRequired
  };
}
function on(e) {
  if (e.default !== void 0)
    return e.default;
  if (e.examples && e.examples.length > 0)
    return e.examples[0];
  if (!e.type) return;
  const t = Array.isArray(e.type) ? e.type[0] : e.type;
  if (!(typeof t == "object" && "$ref" in t))
    switch (t) {
      case "string":
        return "";
      case "boolean":
        return !1;
      case "null":
        return null;
      case "object":
        return {};
      case "array":
      case "set":
        return [];
      case "map":
        return {};
      case "any":
        return;
      default:
        return t === "int8" || t === "int16" || t === "int32" || t === "int64" || t === "int128" || t === "uint8" || t === "uint16" || t === "uint32" || t === "uint64" || t === "uint128" || t === "float" || t === "double" || t === "decimal" ? 0 : void 0;
    }
}
function Pe({
  ctx: e,
  controller: t
}) {
  const n = e.definition;
  if (n.type !== "tuple" || !("tuple" in n) || !("properties" in n))
    return console.warn("StructureTupleControl requires a TupleTypeDefinition"), p.div("Invalid tuple definition");
  const r = n.tuple, s = n.properties, a = t.signal.value;
  if (!Array.isArray(a) || a.length !== r.length) {
    const i = r.map((o) => {
      const c = s[o];
      return c ? on(c) : void 0;
    });
    t.change(i);
  }
  const u = un(e);
  return p.div(
    m.class("bc-json-structure-tuple"),
    // Optional label and description
    u.label && p.label(
      m.class("bc-json-structure-tuple-label"),
      u.label,
      u.required && p.span(m.class("bc-required-indicator"), "*")
    ),
    u.description && p.div(
      m.class("bc-json-structure-tuple-description"),
      u.description
    ),
    // Render tuple elements
    p.div(
      m.class("bc-json-structure-tuple-elements"),
      ...r.map((i, o) => {
        const c = s[i];
        if (!c)
          return console.warn(
            `Tuple element "${i}" at index ${o} not found in properties`
          ), p.div(
            m.class("bc-json-structure-tuple-element"),
            p.span(`Missing definition for "${i}"`)
          );
        const l = t.item(o), y = c.name || i;
        return p.div(
          m.class("bc-json-structure-tuple-element"),
          // Element position indicator and label
          p.div(
            m.class("bc-json-structure-tuple-element-header"),
            p.span(
              m.class("bc-json-structure-tuple-position"),
              `[${o}]`
            ),
            p.span(
              m.class("bc-json-structure-tuple-element-name"),
              y
            )
          ),
          // Element control
          p.div(
            m.class("bc-json-structure-tuple-element-control"),
            j({
              ctx: e.with({
                definition: c,
                suppressLabel: !0
                // Label already shown in header
              }).append(o),
              controller: l
            })
          )
        );
      })
    )
  );
}
function cn({
  options: e,
  selected: t,
  onChange: n,
  disabled: r
}) {
  return me({
    options: e.map((s) => ({
      type: "value",
      value: s.value,
      label: s.label
    })),
    value: t,
    onChange: n,
    disabled: r
  });
}
function ln({
  ctx: e,
  selector: t,
  inner: n
}) {
  const r = V(
    m.class("bc-stack--gap-2 bc-stack--align-start"),
    t,
    n
  );
  return e.isRoot ? r : B({
    label: e.suppressLabel ? void 0 : e.label,
    description: e.description,
    required: e.isRequired,
    content: r
  });
}
function pn(e, t, n) {
  if (!e || typeof e != "object")
    return null;
  const r = e;
  if (n && n in r) {
    const a = r[n];
    if (typeof a == "string" && a in t)
      return a;
  }
  const s = Object.keys(r);
  if (s.length === 1) {
    const a = s[0];
    if (a in t)
      return a;
  }
  return null;
}
function dn(e, t, n) {
  if (!e || typeof e != "object")
    return;
  const r = e;
  if (n && n in r) {
    const { [n]: s, ...a } = r;
    return a;
  }
  if (t in r)
    return r[t];
}
function oe(e, t, n) {
  return n ? e && typeof e == "object" ? {
    [n]: t,
    ...e
  } : {
    [n]: t
  } : {
    [t]: e
  };
}
function fn(e) {
  if (e.default !== void 0)
    return e.default;
  if (e.examples && e.examples.length > 0)
    return e.examples[0];
  const t = Array.isArray(e.type) ? e.type[0] : e.type;
  if (!(!t || typeof t == "object"))
    switch (t) {
      case "string":
        return "";
      case "boolean":
        return !1;
      case "null":
        return null;
      case "object":
        return {};
      case "array":
      case "set":
        return [];
      case "map":
        return {};
      default:
        return;
    }
}
function Fe({
  ctx: e,
  controller: t
}) {
  const n = e.definition;
  if (!n.choices || typeof n.choices != "object")
    return console.warn("StructureChoiceControl requires choices property"), p.div(
      m.class("bc-json-structure-error"),
      "Invalid choice definition: missing choices"
    );
  const r = n.choices, s = n.selector, a = Object.keys(r);
  if (a.length === 0)
    return p.div(
      m.class("bc-json-structure-error"),
      "Choice type has no variants defined"
    );
  const u = a.map((d) => {
    const $ = r[d].name || d;
    return { value: d, label: $ };
  }), i = w(t.signal)((d) => pn(d, r, s)), o = I.get(i) || a[0], c = it(o);
  t.onDispose(c.dispose);
  let l = !1;
  const y = i.on((d) => {
    !l && d !== null && c.set(d);
  });
  t.onDispose(y);
  const f = cn({
    options: u,
    selected: c,
    onChange: (d) => {
      l = !0, c.set(d);
      const v = r[d];
      if (v) {
        const $ = fn(v), A = oe($, d, s);
        t.change(A);
      }
    },
    disabled: e.readOnly || e.isDeprecated
  }), g = U(c, (d) => {
    const v = r[I.get(d)];
    if (!v)
      return p.div(
        m.class("bc-json-structure-error"),
        `Choice variant not found: ${I.get(d)}`
      );
    const $ = w(t.signal)(
      (S) => dn(S, I.get(d), s)
    ), A = (S) => {
      const R = oe(
        S,
        I.get(d),
        s
      );
      t.change(R);
    }, q = new ut(
      [...t.path, I.get(d)],
      A,
      $,
      t.status,
      {
        disabled: t.disabled
      },
      void 0
      // Use default equality
    );
    return t.onDispose(() => q.dispose()), j({
      ctx: e.with({
        definition: v,
        suppressLabel: !0
        // Choice selector acts as the label
      }).append(I.get(d)),
      controller: q
    });
  });
  return ln({
    ctx: e,
    selector: f,
    inner: g
  });
}
function mn(e) {
  return {
    label: e.suppressLabel ? void 0 : T(e.label, e.isDeprecated),
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated
  };
}
function Le({
  ctx: e,
  controller: t
}) {
  const n = mn(e);
  return Qe({
    ...n,
    options: (e.enumValues ?? []).map((r) => ({
      type: "value",
      value: r,
      label: String(r)
    })),
    controller: t
  });
}
function Ve({
  ctx: e,
  controller: t
}) {
  return H(
    st(() => {
      I.get(t.signal) !== e.constValue && t.change(e.constValue);
    }),
    et(ot(e.label, ": "), ye(String(e.constValue)))
  );
}
function yn(e) {
  return {
    label: e.suppressLabel ? void 0 : e.label,
    description: e.description,
    required: e.isRequired,
    disabled: e.readOnly || e.isDeprecated
  };
}
function gn(e, t) {
  if (e === null) return t.includes("null") ? "null" : null;
  if (e === void 0)
    return t.includes("string") ? "string" : t[0] ?? null;
  switch (typeof e) {
    case "string":
      return t.includes("uuid") ? "uuid" : t.includes("uri") ? "uri" : t.includes("date") ? "date" : t.includes("datetime") ? "datetime" : t.includes("time") ? "time" : t.includes("duration") ? "duration" : t.includes("string") ? "string" : null;
    case "number": {
      if (Number.isInteger(e)) {
        if (t.includes("int32")) return "int32";
        if (t.includes("int64")) return "int64";
        if (t.includes("uint32")) return "uint32";
        if (t.includes("uint64")) return "uint64";
        if (t.includes("int16")) return "int16";
        if (t.includes("int8")) return "int8";
        if (t.includes("uint16")) return "uint16";
        if (t.includes("uint8")) return "uint8";
      }
      return t.includes("double") ? "double" : t.includes("float") ? "float" : t.includes("decimal") ? "decimal" : null;
    }
    case "bigint":
      return t.includes("int128") ? "int128" : t.includes("int64") ? "int64" : t.includes("uint128") ? "uint128" : t.includes("uint64") ? "uint64" : null;
    case "boolean":
      return t.includes("boolean") ? "boolean" : null;
    case "object":
      return e instanceof File || e instanceof Blob ? t.includes("binary") ? "binary" : null : Array.isArray(e) ? t.includes("array") ? "array" : t.includes("set") ? "set" : t.includes("tuple") ? "tuple" : null : t.includes("object") ? "object" : t.includes("map") ? "map" : null;
    default:
      return null;
  }
}
function hn(e, t) {
  try {
    switch (t) {
      case "string":
      case "uuid":
      case "uri":
      case "date":
      case "datetime":
      case "time":
      case "duration":
        return e == null ? { ok: !0, value: void 0 } : { ok: !0, value: String(e) };
      case "int8":
      case "int16":
      case "int32":
      case "uint8":
      case "uint16":
      case "uint32":
        return typeof e == "number" && Number.isInteger(e) ? { ok: !0, value: e } : typeof e == "string" ? /^[-+]?\d+$/.test(e.trim()) ? { ok: !0, value: parseInt(e, 10) } : { ok: !1 } : typeof e == "boolean" ? { ok: !0, value: e ? 1 : 0 } : { ok: !1 };
      case "int64":
      case "int128":
      case "uint64":
      case "uint128": {
        if (typeof e == "bigint") return { ok: !0, value: e };
        if (typeof e == "number" && Number.isInteger(e))
          return { ok: !0, value: BigInt(e) };
        if (typeof e == "string")
          try {
            return { ok: !0, value: BigInt(e.trim()) };
          } catch {
            return { ok: !1 };
          }
        return { ok: !1 };
      }
      case "float":
      case "double":
      case "decimal": {
        if (typeof e == "number") return { ok: !0, value: e };
        if (typeof e == "string") {
          const n = Number(e);
          return Number.isFinite(n) ? { ok: !0, value: n } : { ok: !1 };
        }
        return typeof e == "boolean" ? { ok: !0, value: e ? 1 : 0 } : { ok: !1 };
      }
      case "boolean": {
        if (typeof e == "boolean") return { ok: !0, value: e };
        if (typeof e == "string") {
          const n = e.trim().toLowerCase();
          return n === "true" || n === "1" || n === "yes" ? { ok: !0, value: !0 } : n === "false" || n === "0" || n === "no" ? { ok: !0, value: !1 } : { ok: !1 };
        }
        return typeof e == "number" ? { ok: !0, value: e !== 0 } : { ok: !1 };
      }
      case "array":
      case "set":
      case "tuple":
        return Array.isArray(e) ? { ok: !0, value: e } : { ok: !1 };
      case "object":
      case "map":
        return e != null && typeof e == "object" && !Array.isArray(e) ? { ok: !0, value: e } : { ok: !1 };
      case "binary":
        return e instanceof File || e instanceof Blob ? { ok: !0, value: e } : { ok: !1 };
      case "null":
        return { ok: !0, value: null };
      case "any":
      case "choice":
        return { ok: !0, value: e };
      default:
        return { ok: !1 };
    }
  } catch {
    return { ok: !1 };
  }
}
function bn(e) {
  switch (e) {
    case "null":
      return null;
    case "array":
    case "set":
    case "tuple":
      return [];
    case "object":
    case "map":
      return {};
    case "binary":
      return;
    default:
      return;
  }
}
function vn(e) {
  return e.map((t) => ({
    key: t,
    label: J(t),
    detect: (n) => gn(n, [t]) === t,
    convert: (n) => hn(n, t),
    defaultValue: () => bn(t)
  }));
}
function xn({
  options: e,
  selected: t,
  onChange: n
}) {
  if ((e.length <= 3 ? "segmented" : "select") === "segmented") {
    const a = Object.fromEntries(
      e.map((u) => [u.value, u.label])
    );
    return nt({
      options: a,
      value: t,
      onChange: (u) => n(u),
      size: "sm"
    });
  }
  return me({
    options: e.map((a) => ({
      type: "value",
      value: a.value,
      label: a.label
    })),
    value: t,
    onChange: n
  });
}
function $n({
  ctx: e,
  showSelector: t,
  selector: n,
  inner: r
}) {
  return e.isRoot ? t ? V(m.class("bc-stack--gap-2"), n, r) : r : B({
    ...yn(e),
    content: t ? V(
      m.class("bc-stack--gap-2 bc-stack--align-start"),
      n,
      r
    ) : r
  });
}
function In({
  ctx: e,
  controller: t
}) {
  const n = e.definition, r = n.type;
  let s = [];
  if (Array.isArray(r))
    s = r;
  else
    return console.warn("StructureUnionControl called with non-array type"), j({ ctx: e, controller: t });
  const a = s.includes("null"), u = Q(r), i = a && u.length > 0 ? u : s, o = vn(i), c = new tt(
    t.path,
    t.change,
    t.signal,
    t.status,
    { disabled: t.disabled },
    o
  );
  t.onDispose(() => c.dispose());
  const l = (f) => xn({
    options: i.map((g) => ({ value: g, label: J(g) })),
    selected: c.activeBranch,
    onChange: f
  }), y = (f) => {
    c.switchToBranch(f, !1);
  }, h = U(c.activeBranch, (f) => {
    const g = I.get(f), d = c.getBranchController(g), v = e.with({
      definition: { ...n, type: g },
      // Suppress inner labels only when union is nested (non-root)
      suppressLabel: !e.isRoot
    });
    return j({
      ctx: v,
      controller: d
    });
  });
  return $n({
    ctx: e,
    showSelector: i.length > 1,
    selector: l(y),
    inner: h
  });
}
function j({
  ctx: e,
  controller: t
}) {
  let n = e;
  const r = e.definition;
  if (r.type && C(r.type)) {
    const i = e.resolveRef(r.type.$ref);
    if (i) {
      const { type: o, ...c } = r, l = { ...i, ...c };
      n = e.with({ definition: l });
    }
  }
  if (n.definition.$extends) {
    const { merged: i } = $e(n.definition, e.schema);
    n = n.with({ definition: i });
  }
  const s = n.widgetRegistry;
  if (s) {
    const i = s.findBestWidget(n);
    if (i)
      return i.registration.factory({
        controller: t,
        ctx: n
      });
  }
  if (Mt(n.definition))
    return Le({
      ctx: n,
      controller: t
    });
  if (Dt(n.definition))
    return Ve({
      ctx: n,
      controller: t
    });
  const a = n.resolvedType;
  if (Array.isArray(a) && Q(a).length > 1)
    return In({
      ctx: n,
      controller: t
    });
  const u = n.primaryType;
  if (!u)
    return K({
      ctx: n,
      controller: t
    });
  if (k(n.definition)) {
    const i = t instanceof re ? t : t.object();
    return Re({
      ctx: n,
      controller: i
    });
  }
  if (ge(n.definition)) {
    const i = t instanceof G ? t : t.array();
    return ke({
      ctx: n,
      controller: i
    });
  }
  if (he(n.definition)) {
    const i = t instanceof G ? t : t.array();
    return Ne({
      ctx: n,
      controller: i
    });
  }
  if (be(n.definition)) {
    const i = t instanceof re ? t : t.object();
    return qe({
      ctx: n,
      controller: i
    });
  }
  if (ve(n.definition)) {
    const i = t instanceof G ? t : t.array();
    return Pe({
      ctx: n,
      controller: i
    });
  }
  if (xe(n.definition))
    return Fe({
      ctx: n,
      controller: t
    });
  switch (u) {
    case "string":
      return Ie({
        ctx: n,
        controller: t
      });
    case "boolean":
      return we({
        ctx: n,
        controller: t
      });
    case "uuid":
      return De({
        ctx: n,
        controller: t
      });
    case "uri":
      return Oe({
        ctx: n,
        controller: t
      });
    case "binary":
      return Ce({
        ctx: n,
        controller: t
      });
    case "null":
      return Tn(n);
    case "any":
      return K({
        ctx: n,
        controller: t
      });
    default:
      return P(u) ? Ae({
        ctx: n,
        controller: t,
        intType: u
      }) : X(u) ? Me({
        ctx: n,
        controller: t,
        floatType: u
      }) : Y(u) ? Se({
        ctx: n,
        controller: t,
        temporalType: u
      }) : (console.warn(`Unknown type: ${u}`), jn(n, u));
  }
}
function wn({
  schema: e,
  controller: t,
  widgetRegistry: n,
  readOnly: r,
  locale: s
}) {
  const a = kt(e, {
    widgetRegistry: n,
    readOnly: r,
    locale: s
  });
  return j({ ctx: a, controller: t });
}
function Tn(e) {
  return p.div(
    m.class("bc-json-structure-placeholder"),
    p.span(`[Null: ${e.label}]`),
    p.em("null")
  );
}
function jn(e, t) {
  return p.div(
    m.class("bc-json-structure-unknown"),
    p.span(`Unknown type: ${t}`),
    p.em(`at path: ${e.jsonPath}`)
  );
}
function Ee(e, t) {
  return new An(e, t);
}
class An {
  schema;
  options;
  constructor(t, n) {
    this.schema = t, this.options = n ?? {};
  }
  validate(t) {
    const n = [];
    return this.validateValue(
      t,
      this.schema,
      "",
      n
    ), {
      isValid: n.length === 0,
      errors: n
    };
  }
  validateAt(t, n) {
    return this.validate(t);
  }
  validateValue(t, n, r, s) {
    if (this.options.stopOnFirstError && s.length > 0)
      return;
    if (t === null) {
      const c = n.type;
      if (c === "null" || Array.isArray(c) && c.includes("null")) return;
      s.push({
        path: r,
        type: "type",
        expected: c,
        actual: "null"
      });
      return;
    }
    if ("enum" in n && Array.isArray(n.enum)) {
      n.enum.includes(t) || s.push({
        path: r,
        type: "enum",
        expected: n.enum,
        actual: t
      });
      return;
    }
    if ("const" in n) {
      t !== n.const && s.push({
        path: r,
        type: "const",
        expected: n.const,
        actual: t
      });
      return;
    }
    const a = n.type;
    if (!a) return;
    const i = (Array.isArray(a) ? a : [a]).filter(
      (c) => typeof c == "string"
    );
    !i.some(
      (c) => this.checkType(t, c, n, r, s)
    ) && i.length > 0 && s.push({
      path: r,
      type: "type",
      expected: a,
      actual: typeof t
    });
  }
  checkType(t, n, r, s, a) {
    switch (n) {
      case "string":
        return this.validateString(t, r, s, a);
      case "boolean":
        return typeof t == "boolean";
      case "null":
        return t === null;
      case "object":
        return this.validateObject(t, r, s, a);
      case "array":
        return this.validateArray(t, r, s, a);
      case "set":
        return this.validateSet(t, r, s, a);
      case "map":
        return this.validateMap(t, r, s, a);
      case "tuple":
        return this.validateTuple(t, r, s, a);
      case "choice":
        return this.validateChoice(t, r, s, a);
      case "any":
        return !0;
      default:
        return P(n) ? this.validateInteger(t, n, r, s, a) : X(n) ? this.validateFloat(t, r, s, a) : Y(n) ? this.validateTemporal(t, n, s, a) : n === "uuid" ? this.validateUuid(t, s, a) : n === "uri" ? this.validateUri(t, s, a) : n === "binary" ? this.validateBinary(t, s, a) : !1;
    }
  }
  validateString(t, n, r, s) {
    if (typeof t != "string") return !1;
    const a = n;
    if (a.minLength !== void 0 && t.length < a.minLength && s.push({
      path: r,
      type: "minLength",
      expected: a.minLength,
      actual: t.length
    }), a.maxLength !== void 0 && t.length > a.maxLength && s.push({
      path: r,
      type: "maxLength",
      expected: a.maxLength,
      actual: t.length
    }), a.pattern !== void 0)
      try {
        new RegExp(a.pattern).test(t) || s.push({
          path: r,
          type: "pattern",
          expected: a.pattern,
          actual: t
        });
      } catch {
      }
    return !0;
  }
  validateInteger(t, n, r, s, a) {
    if (typeof t != "number" && typeof t != "bigint") return !1;
    if (typeof t == "number" && !Number.isInteger(t))
      return a.push({ path: s, type: "type", expected: n, actual: "float" }), !1;
    if (P(n)) {
      const u = W[n], i = typeof t == "bigint" ? t : BigInt(Math.round(t));
      (i < u.min || i > u.max) && a.push({
        path: s,
        type: "integer_bounds",
        expected: { min: u.min.toString(), max: u.max.toString() },
        actual: i.toString(),
        context: { type: n }
      });
    }
    return this.validateNumericConstraints(t, r, s, a), !0;
  }
  validateFloat(t, n, r, s) {
    return typeof t != "number" ? !1 : (this.validateNumericConstraints(t, n, r, s), !0);
  }
  validateNumericConstraints(t, n, r, s) {
    const a = n, u = typeof t == "bigint" ? Number(t) : t;
    if (a.minimum !== void 0) {
      const i = typeof a.minimum == "string" ? Number(a.minimum) : a.minimum;
      u < i && s.push({ path: r, type: "minimum", expected: i, actual: u });
    }
    if (a.maximum !== void 0) {
      const i = typeof a.maximum == "string" ? Number(a.maximum) : a.maximum;
      u > i && s.push({ path: r, type: "maximum", expected: i, actual: u });
    }
    if (a.exclusiveMinimum !== void 0) {
      const i = typeof a.exclusiveMinimum == "string" ? Number(a.exclusiveMinimum) : a.exclusiveMinimum;
      u <= i && s.push({
        path: r,
        type: "exclusiveMinimum",
        expected: i,
        actual: u
      });
    }
    if (a.exclusiveMaximum !== void 0) {
      const i = typeof a.exclusiveMaximum == "string" ? Number(a.exclusiveMaximum) : a.exclusiveMaximum;
      u >= i && s.push({
        path: r,
        type: "exclusiveMaximum",
        expected: i,
        actual: u
      });
    }
    a.multipleOf !== void 0 && typeof t == "number" && t % a.multipleOf !== 0 && s.push({
      path: r,
      type: "multipleOf",
      expected: a.multipleOf,
      actual: t
    });
  }
  validateTemporal(t, n, r, s) {
    if (typeof t != "string") return !1;
    const u = {
      date: /^\d{4}-\d{2}-\d{2}$/,
      datetime: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,
      time: /^\d{2}:\d{2}:\d{2}(\.\d+)?$/,
      duration: /^P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$/
    }[n];
    return u && !u.test(t) ? (s.push({ path: r, type: "format", expected: n, actual: t }), !1) : !0;
  }
  validateUuid(t, n, r) {
    return typeof t != "string" ? !1 : /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t) ? !0 : (r.push({ path: n, type: "format", expected: "uuid", actual: t }), !1);
  }
  validateUri(t, n, r) {
    if (typeof t != "string") return !1;
    try {
      return new URL(t), !0;
    } catch {
      return r.push({ path: n, type: "format", expected: "uri", actual: t }), !1;
    }
  }
  validateBinary(t, n, r) {
    return t instanceof Uint8Array ? !0 : typeof t != "string" ? !1 : /^[A-Za-z0-9+/]*={0,2}$/.test(t) ? !0 : (r.push({ path: n, type: "format", expected: "binary", actual: t }), !1);
  }
  validateObject(t, n, r, s) {
    if (typeof t != "object" || t === null || Array.isArray(t))
      return !1;
    if (!k(n)) return !0;
    const a = t, u = n.required;
    if (u) {
      const i = Array.isArray(u[0]) ? u.flat() : u;
      for (const o of i)
        o in a || s.push({
          path: r ? `${r}/${o}` : `/${o}`,
          type: "required",
          expected: o
        });
    }
    for (const [i, o] of Object.entries(a)) {
      const c = n.properties?.[i];
      if (c) {
        const l = r ? `${r}/${i}` : `/${i}`;
        this.validateValue(o, c, l, s);
      } else if (n.additionalProperties === !1)
        s.push({
          path: r ? `${r}/${i}` : `/${i}`,
          type: "additionalProperties",
          actual: i
        });
      else if (typeof n.additionalProperties == "object") {
        const l = r ? `${r}/${i}` : `/${i}`;
        this.validateValue(
          o,
          n.additionalProperties,
          l,
          s
        );
      }
    }
    return !0;
  }
  validateArray(t, n, r, s) {
    if (!Array.isArray(t)) return !1;
    if (!ge(n)) return !0;
    const a = n;
    a.minItems !== void 0 && t.length < a.minItems && s.push({
      path: r,
      type: "minItems",
      expected: a.minItems,
      actual: t.length
    }), a.maxItems !== void 0 && t.length > a.maxItems && s.push({
      path: r,
      type: "maxItems",
      expected: a.maxItems,
      actual: t.length
    });
    for (let u = 0; u < t.length; u++) {
      const i = `${r}/${u}`;
      this.validateValue(t[u], n.items, i, s);
    }
    return !0;
  }
  validateSet(t, n, r, s) {
    if (!Array.isArray(t)) return !1;
    if (!he(n)) return !0;
    const a = /* @__PURE__ */ new Set();
    for (let u = 0; u < t.length; u++) {
      const i = JSON.stringify(t[u]);
      a.has(i) && s.push({
        path: `${r}/${u}`,
        type: "uniqueItems",
        actual: t[u]
      }), a.add(i);
    }
    return this.validateArray(t, n, r, s);
  }
  validateMap(t, n, r, s) {
    if (typeof t != "object" || t === null || Array.isArray(t))
      return !1;
    if (!be(n)) return !0;
    const a = t;
    for (const [u, i] of Object.entries(a)) {
      const o = `${r}/${u}`;
      this.validateValue(i, n.values, o, s);
    }
    return !0;
  }
  validateTuple(t, n, r, s) {
    if (!Array.isArray(t)) return !1;
    if (!ve(n)) return !0;
    const a = n.tuple.length;
    t.length !== a && s.push({
      path: r,
      type: "tuple_length",
      expected: a,
      actual: t.length
    });
    for (let u = 0; u < n.tuple.length; u++) {
      const i = n.tuple[u], o = n.properties?.[i];
      o && u < t.length && this.validateValue(t[u], o, `${r}/${u}`, s);
    }
    return !0;
  }
  validateChoice(t, n, r, s) {
    if (typeof t != "object" || t === null || Array.isArray(t))
      return !1;
    if (!xe(n)) return !0;
    const a = t, u = Object.keys(n.choices), i = Object.keys(a).find((c) => u.includes(c));
    if (!i)
      return s.push({
        path: r,
        type: "choice",
        expected: u,
        actual: Object.keys(a)
      }), !1;
    const o = n.choices[i];
    return o && this.validateValue(
      a[i],
      o,
      `${r}/${i}`,
      s
    ), !0;
  }
}
function lr(e, t, n) {
  return Ee(e, n).validate(t);
}
function Mn(e, t) {
  const n = Dn(e, t);
  return {
    path: e.path,
    message: n,
    code: e.type
  };
}
function Ue(e, t) {
  return e.map((n) => {
    const r = t?.get(n.path);
    return Mn(n, r);
  });
}
function Dn(e, t) {
  switch (e.type) {
    // Type errors
    case "type":
      return `Expected ${ce(e.expected)}, got ${Sn(e.actual)}`;
    case "type_mismatch":
      return `Value must be of type ${ce(e.expected)}`;
    // String validation
    case "minLength":
      return `Must be at least ${e.expected} characters`;
    case "maxLength":
      return `Must be no more than ${e.expected} characters`;
    case "pattern":
      return On(e, t);
    case "format":
      return Cn(e);
    // Numeric validation
    case "minimum":
      return `Must be at least ${e.expected}`;
    case "maximum":
      return `Must be at most ${e.expected}`;
    case "exclusiveMinimum":
      return `Must be greater than ${e.expected}`;
    case "exclusiveMaximum":
      return `Must be less than ${e.expected}`;
    case "multipleOf":
      return `Must be a multiple of ${e.expected}`;
    case "integer_bounds":
      return Rn(e);
    // Array/Set validation
    case "minItems":
      return `Must have at least ${e.expected} items`;
    case "maxItems":
      return `Must have no more than ${e.expected} items`;
    case "uniqueItems":
      return "All items must be unique";
    case "contains":
      return "Must contain at least one matching item";
    case "minContains":
      return `Must contain at least ${e.expected} matching items`;
    case "maxContains":
      return `Must contain no more than ${e.expected} matching items`;
    // Object validation
    case "required":
      return "This field is required";
    case "minProperties":
      return `Must have at least ${e.expected} properties`;
    case "maxProperties":
      return `Must have no more than ${e.expected} properties`;
    case "additionalProperties":
      return `Unknown property: ${e.actual}`;
    case "dependentRequired":
      return kn(e);
    // Enum/Const validation
    case "enum":
      return Nn(e);
    case "const":
      return `Must be exactly ${JSON.stringify(e.expected)}`;
    // Reference errors
    case "ref_not_found":
      return `Invalid reference: ${e.expected}`;
    case "circular_ref":
      return "Circular reference detected";
    // Generic
    case "invalid":
      return "Invalid value";
    default:
      return e.context?.message ?? `Validation error: ${e.type}`;
  }
}
function ce(e) {
  return typeof e == "string" ? le(e) : Array.isArray(e) ? e.map(le).join(" or ") : String(e);
}
function Sn(e) {
  return e === null ? "null" : e === void 0 ? "undefined" : typeof e;
}
function le(e) {
  return {
    string: "text",
    boolean: "true/false",
    int8: "integer (-128 to 127)",
    int16: "integer (-32768 to 32767)",
    int32: "integer",
    int64: "large integer",
    int128: "very large integer",
    uint8: "positive integer (0 to 255)",
    uint16: "positive integer (0 to 65535)",
    uint32: "positive integer",
    uint64: "large positive integer",
    uint128: "very large positive integer",
    float: "decimal number",
    double: "decimal number",
    decimal: "decimal number",
    date: "date",
    datetime: "date and time",
    time: "time",
    duration: "duration",
    uuid: "UUID",
    uri: "URL",
    binary: "binary data",
    object: "object",
    array: "list",
    set: "unique list",
    map: "key-value pairs",
    tuple: "ordered list",
    choice: "one of multiple options",
    any: "any value",
    null: "empty"
  }[e] ?? e;
}
function On(e, t) {
  const n = t?.description;
  if (n && e.type === "pattern")
    return `Does not match required format: ${n}`;
  const r = e.expected;
  if (r) {
    const a = {
      "^[a-zA-Z]+$": "letters only",
      "^[0-9]+$": "numbers only",
      "^[a-zA-Z0-9]+$": "letters and numbers only",
      "^\\S+$": "no spaces allowed",
      "^[a-z]+$": "lowercase letters only",
      "^[A-Z]+$": "uppercase letters only"
    }[r];
    if (a)
      return `Must be ${a}`;
  }
  return "Does not match required format";
}
function Cn(e) {
  const t = e.expected;
  return {
    email: "Must be a valid email address",
    "date-time": "Must be a valid date and time",
    date: "Must be a valid date",
    time: "Must be a valid time",
    uri: "Must be a valid URL",
    "uri-reference": "Must be a valid URL or relative path",
    uuid: "Must be a valid UUID",
    hostname: "Must be a valid hostname",
    ipv4: "Must be a valid IPv4 address",
    ipv6: "Must be a valid IPv6 address",
    regex: "Must be a valid regular expression",
    "json-pointer": "Must be a valid JSON pointer"
  }[t] ?? `Must be a valid ${t}`;
}
function Rn(e) {
  const t = e.context?.type;
  if (t && P(t)) {
    const n = W[t];
    return `Must be between ${n.min} and ${n.max}`;
  }
  return "Value is out of range for this integer type";
}
function kn(e) {
  const t = e.context?.dependent, n = e.context?.required;
  return t && n?.length ? `When "${t}" is present, "${n.join('", "')}" must also be provided` : "Missing required dependent fields";
}
function Nn(e) {
  const t = e.expected;
  return t && t.length <= 5 ? `Must be one of: ${t.map((r) => JSON.stringify(r)).join(", ")}` : "Invalid value";
}
function pr(e) {
  const t = /* @__PURE__ */ new Map();
  for (const n of e) {
    const r = t.get(n.path) ?? [];
    r.push(n), t.set(n.path, r);
  }
  return t;
}
function dr(e, t) {
  return e.filter((n) => n.path === t);
}
function fr(e, t) {
  return e.some((n) => n.path === t);
}
function mr(e, t) {
  const n = t === "" ? "/" : `${t}/`;
  return e.filter((r) => r.path.startsWith(n));
}
class _ {
  registrations = /* @__PURE__ */ new Map();
  parent;
  constructor(t) {
    this.parent = t ?? null;
  }
  register(t, n) {
    this.registrations.set(t, n);
  }
  unregister(t) {
    this.registrations.delete(t);
  }
  get(t) {
    return this.registrations.get(t) ?? this.parent?.get(t);
  }
  has(t) {
    return this.registrations.has(t) || (this.parent?.has(t) ?? !1);
  }
  names() {
    const t = this.parent?.names() ?? [], n = Array.from(this.registrations.keys());
    return [.../* @__PURE__ */ new Set([...t, ...n])];
  }
  getForType(t) {
    const n = [];
    this.parent && n.push(...this.parent.getForType(t));
    for (const r of this.registrations.values())
      r.supportedTypes?.includes(t) && n.push(r);
    return n;
  }
  getForFormat(t) {
    const n = [];
    this.parent && n.push(...this.parent.getForFormat(t));
    for (const r of this.registrations.values())
      r.supportedFormats?.includes(t) && n.push(r);
    return n;
  }
  findBestWidget(t) {
    const n = [];
    for (const s of this.names()) {
      const a = this.get(s);
      if (!a) continue;
      const u = this.scoreWidget(a, t);
      u > 0 && n.push({ name: s, registration: a, score: u });
    }
    if (n.length === 0)
      return null;
    n.sort((s, a) => a.score !== s.score ? a.score - s.score : (a.registration.priority ?? 0) - (s.registration.priority ?? 0));
    const r = n[0];
    return { name: r.name, registration: r.registration };
  }
  /**
   * Score how well a widget matches the context
   */
  scoreWidget(t, n) {
    let r = 0;
    if (t.matcher)
      if (t.matcher(n))
        r += 100;
      else
        return 0;
    const s = n.primaryType;
    s && t.supportedTypes?.includes(s) && (r += 50);
    const a = n.format;
    return a && t.supportedFormats?.includes(a) && (r += 30), r += t.priority ?? 0, r;
  }
  createChild() {
    return new _(this);
  }
}
let L = null;
function F() {
  return L || (L = new _()), L;
}
function yr(e) {
  L = e;
}
function gr(e) {
  return new _(e);
}
function hr(e, t, n) {
  return {
    name: `type:${e}`,
    registration: {
      factory: t,
      displayName: n?.displayName ?? `${e} widget`,
      description: n?.description,
      supportedTypes: [e],
      priority: n?.priority ?? 0,
      canFallback: n?.canFallback ?? !1
    }
  };
}
function br(e, t, n) {
  return {
    name: `format:${e}`,
    registration: {
      factory: t,
      displayName: n?.displayName ?? `${e} widget`,
      description: n?.description,
      supportedFormats: [e],
      priority: n?.priority ?? 10,
      // Format widgets have higher priority than type widgets
      canFallback: n?.canFallback ?? !1
    }
  };
}
function vr(e, t, n, r) {
  return {
    name: `type:${e}:format:${t}`,
    registration: {
      factory: n,
      displayName: r?.displayName ?? `${e}/${t} widget`,
      description: r?.description,
      supportedTypes: [e],
      supportedFormats: [t],
      priority: r?.priority ?? 20,
      // Type+format widgets have highest priority
      canFallback: r?.canFallback ?? !1
    }
  };
}
function xr(e, t, n, r) {
  return {
    name: e,
    registration: {
      factory: n,
      displayName: r?.displayName ?? e,
      description: r?.description,
      matcher: t,
      priority: r?.priority ?? 50,
      // Custom matchers have very high priority
      canFallback: r?.canFallback ?? !1
    }
  };
}
function qn(e, t) {
  if (t) {
    const r = t.findBestWidget(e);
    if (r)
      return r;
  }
  return F().findBestWidget(e);
}
function $r(e) {
  const t = e.definition, n = {};
  if (typeof t == "object" && "x:ui" in t) {
    const r = t["x:ui"];
    r.widget && typeof r.widget == "object" && (n.options = r.widget), typeof r.priority == "number" && (n.priority = r.priority);
  }
  if (typeof t == "object" && "widget" in t) {
    const r = t.widget;
    typeof r == "object" && r !== null && (n.options = {
      ...n.options ?? {},
      ...r
    });
  }
  return Object.keys(n).length > 0 ? n : void 0;
}
function Be(e) {
  const t = e.definition;
  if (typeof t == "object" && "x:ui" in t) {
    const n = t["x:ui"];
    if (typeof n.widget == "string")
      return n.widget;
  }
  if (typeof t == "object" && "widget" in t) {
    const n = t.widget;
    if (n && typeof n.type == "string")
      return n.type;
  }
}
function Ir(e) {
  return Be(e) !== void 0;
}
function wr(e, t) {
  const n = Be(e);
  if (n) {
    if (t) {
      const a = t.get(n);
      if (a)
        return { name: n, registration: a };
    }
    const s = F().get(n);
    if (s)
      return { name: n, registration: s };
    console.warn(
      `Widget "${n}" specified in definition but not found in registry`,
      { path: e.jsonPath }
    );
  }
  return qn(e, t);
}
function Tr(e, t, n) {
  return {
    ...e,
    ...t,
    ...n
  };
}
function Pn(e = F()) {
  e.register("string", {
    factory: ({ controller: i, ctx: o }) => Ie({
      ctx: o,
      controller: i
    }),
    displayName: "String",
    description: "Text input for string values",
    supportedTypes: ["string"],
    priority: 0,
    canFallback: !0
  }), e.register("boolean", {
    factory: ({ controller: i, ctx: o }) => we({
      ctx: o,
      controller: i
    }),
    displayName: "Boolean",
    description: "Checkbox for boolean values",
    supportedTypes: ["boolean"],
    priority: 0,
    canFallback: !0
  }), e.register("uuid", {
    factory: ({ controller: i, ctx: o }) => De({
      ctx: o,
      controller: i
    }),
    displayName: "UUID",
    description: "Input for UUID values",
    supportedTypes: ["uuid"],
    priority: 0,
    canFallback: !0
  }), e.register("uri", {
    factory: ({ controller: i, ctx: o }) => Oe({
      ctx: o,
      controller: i
    }),
    displayName: "URI",
    description: "Input for URI/URL values",
    supportedTypes: ["uri"],
    priority: 0,
    canFallback: !0
  }), e.register("binary", {
    factory: ({ controller: i, ctx: o }) => Ce({
      ctx: o,
      controller: i
    }),
    displayName: "Binary",
    description: "File upload for binary data",
    supportedTypes: ["binary"],
    priority: 0,
    canFallback: !0
  }), e.register("any", {
    factory: ({ controller: i, ctx: o }) => K({
      ctx: o,
      controller: i
    }),
    displayName: "Any",
    description: "Generic control for any type",
    supportedTypes: ["any"],
    priority: 0,
    canFallback: !0
  });
  const t = [
    "int8",
    "int16",
    "int32",
    "int64",
    "int128",
    "uint8",
    "uint16",
    "uint32",
    "uint64",
    "uint128"
  ], n = ({ controller: i, ctx: o }) => Ae({
    ctx: o,
    controller: i,
    intType: o.primaryType
  });
  for (const i of t)
    e.register(i, {
      factory: n,
      displayName: i.toUpperCase(),
      description: `Number input for ${i} values`,
      supportedTypes: [i],
      priority: 0,
      canFallback: !0
    });
  const r = ["float", "double", "decimal"], s = ({ controller: i, ctx: o }) => Me({
    ctx: o,
    controller: i,
    floatType: o.primaryType
  });
  for (const i of r)
    e.register(i, {
      factory: s,
      displayName: i.charAt(0).toUpperCase() + i.slice(1),
      description: `Number input for ${i} values`,
      supportedTypes: [i],
      priority: 0,
      canFallback: !0
    });
  const a = ["date", "datetime", "time", "duration"], u = ({ controller: i, ctx: o }) => Se({
    ctx: o,
    controller: i,
    temporalType: o.primaryType
  });
  for (const i of a)
    e.register(i, {
      factory: u,
      displayName: i.charAt(0).toUpperCase() + i.slice(1),
      description: `Input for ${i} values`,
      supportedTypes: [i],
      priority: 0,
      canFallback: !0
    });
  e.register("object", {
    factory: ({ controller: i, ctx: o }) => Re({
      ctx: o,
      controller: i
    }),
    displayName: "Object",
    description: "Form for object values",
    supportedTypes: ["object"],
    priority: 0,
    canFallback: !0
  }), e.register("array", {
    factory: ({ controller: i, ctx: o }) => ke({
      ctx: o,
      controller: i
    }),
    displayName: "Array",
    description: "List control for array values",
    supportedTypes: ["array"],
    priority: 0,
    canFallback: !0
  }), e.register("set", {
    factory: ({ controller: i, ctx: o }) => Ne({
      ctx: o,
      controller: i
    }),
    displayName: "Set",
    description: "Set control for unique values",
    supportedTypes: ["set"],
    priority: 0,
    canFallback: !0
  }), e.register("map", {
    factory: ({ controller: i, ctx: o }) => qe({
      ctx: o,
      controller: i
    }),
    displayName: "Map",
    description: "Map control for key-value pairs",
    supportedTypes: ["map"],
    priority: 0,
    canFallback: !0
  }), e.register("tuple", {
    factory: ({ controller: i, ctx: o }) => Pe({
      ctx: o,
      controller: i
    }),
    displayName: "Tuple",
    description: "Tuple control for fixed-length arrays",
    supportedTypes: ["tuple"],
    priority: 0,
    canFallback: !0
  }), e.register("choice", {
    factory: ({ controller: i, ctx: o }) => Fe({
      ctx: o,
      controller: i
    }),
    displayName: "Choice",
    description: "Choice control for union types",
    supportedTypes: ["choice"],
    priority: 0,
    canFallback: !0
  }), e.register("enum", {
    factory: ({ controller: i, ctx: o }) => Le({
      ctx: o,
      controller: i
    }),
    displayName: "Enum",
    description: "Dropdown for enumerated values",
    priority: 10,
    // Higher priority than base types
    canFallback: !1,
    matcher: (i) => i.hasEnum
  }), e.register("const", {
    factory: ({ controller: i, ctx: o }) => Ve({
      ctx: o,
      controller: i
    }),
    displayName: "Const",
    description: "Display for constant values",
    priority: 20,
    // Highest priority
    canFallback: !1,
    matcher: (i) => i.hasConst
  });
}
function Fn(e = F()) {
  return e.has("string") && e.has("object") && e.has("array");
}
function jr(e = F()) {
  Fn(e) || Pn(e);
}
function Ln(e) {
  let t = e;
  if (e.$root) {
    const n = N(e.$root, e);
    n && (t = n);
  }
  return M(t, e, /* @__PURE__ */ new Set());
}
function M(e, t, n) {
  if (e.type && C(e.type)) {
    const r = e.type.$ref;
    if (n.has(r))
      return;
    n.add(r);
    const s = N(r, t);
    if (s) {
      const a = {
        ...s,
        ...e,
        type: s.type
        // Use resolved type, not the ref
      }, u = M(a, t, n);
      return n.delete(r), u;
    }
    n.delete(r);
    return;
  }
  return e.default !== void 0 ? e.default : Array.isArray(e.examples) && e.examples.length > 0 ? e.examples[0] : "const" in e && e.const !== void 0 ? e.const : "enum" in e && Array.isArray(e.enum) && e.enum.length > 0 ? e.enum[0] : Hn(e) ? null : Vn(e, t, n);
}
function Vn(e, t, n) {
  const r = We(e);
  if (k(e))
    return Un(e, t, n);
  if (r === "choice" && "choices" in e)
    return Bn(e, t, n);
  if (r === "tuple" && "tuple" in e && "properties" in e)
    return Wn(e, t, n);
  if (r === "array")
    return _n(e, t, n);
  if (r === "set")
    return zn(e, t, n);
  if (r === "map")
    return {};
  if (r === "string")
    return Gn(e);
  if (Xn(r))
    return Kn(e);
  if (Yn(r))
    return Jn(e);
  if (r === "boolean")
    return !1;
  if (r === "null")
    return null;
  if (Qn(r))
    return Zn(r);
  if (r === "uuid" || r === "uri" || r === "uri-reference" || r === "binary" || r === "bytes")
    return "";
}
function En(e) {
  if (!e || e.length === 0)
    return /* @__PURE__ */ new Set();
  if (Array.isArray(e[0])) {
    const t = e.flat();
    return new Set(t);
  }
  return new Set(e);
}
function Un(e, t, n) {
  if (!k(e))
    return {};
  const r = En(e.required), s = {};
  for (const [a, u] of Object.entries(e.properties))
    if (r.has(a))
      if (u.type && C(u.type)) {
        const i = u.type.$ref;
        if (n.has(i))
          continue;
        n.add(i);
        const o = N(i, t);
        if (o) {
          const c = {
            ...o,
            ...u,
            type: o.type
          }, l = M(c, t, n);
          l !== void 0 && (s[a] = l);
        }
        n.delete(i);
      } else {
        const i = M(u, t, n);
        i !== void 0 && (s[a] = i);
      }
  return s;
}
function Bn(e, t, n) {
  if (!("choices" in e))
    return;
  const r = e.choices, s = Object.keys(r);
  if (s.length === 0)
    return;
  const a = s[0], u = r[a];
  if ("selector" in e && e.selector) {
    const o = e.selector, c = M(u, t, n);
    return typeof c == "object" && c !== null ? {
      [o]: a,
      ...c
    } : {
      [o]: a
    };
  }
  const i = M(u, t, n);
  return { [a]: i };
}
function Wn(e, t, n) {
  if (!("tuple" in e) || !("properties" in e))
    return {};
  const r = e.tuple, s = e.properties, a = new Set(
    e.required ?? r
  ), u = {};
  for (const i of r) {
    if (!a.has(i))
      continue;
    const o = s[i];
    if (o) {
      const c = M(o, t, n);
      c !== void 0 && (u[i] = c);
    }
  }
  return u;
}
function _n(e, t, n) {
  const r = ("minItems" in e ? e.minItems : 0) ?? 0;
  if (r === 0)
    return [];
  const s = "items" in e ? e.items : void 0;
  if (!s)
    return Array(r).fill(null);
  const a = M(s, t, n);
  return Array(r).fill(a ?? null);
}
function zn(e, t, n) {
  const r = ("minItems" in e ? e.minItems : 0) ?? 0;
  if (r === 0)
    return [];
  const s = "items" in e ? e.items : void 0;
  if (!s)
    return Array(r).fill(null);
  const a = M(s, t, n);
  return Array(r).fill(a ?? null);
}
function Gn(e) {
  switch ("format" in e ? e.format : void 0) {
    case "date":
      return _e();
    case "date-time":
      return ze();
    case "time":
      return "00:00:00";
    case "email":
    case "uri":
    case "uri-reference":
    case "uuid":
    default:
      return "";
  }
}
function Kn(e) {
  const t = We(e), n = t === "int64" || t === "uint64" || t === "int128" || t === "uint128";
  let r = "minimum" in e ? e.minimum : void 0, s = "maximum" in e ? e.maximum : void 0;
  const a = "exclusiveMinimum" in e ? e.exclusiveMinimum : void 0, u = "exclusiveMaximum" in e ? e.exclusiveMaximum : void 0;
  a !== void 0 && (r = a + 1), u !== void 0 && (s = u - 1);
  let i;
  r !== void 0 && s !== void 0 ? i = Math.round((r + s) / 2) : r !== void 0 ? i = r : s !== void 0 ? i = 0 <= s ? 0 : s : i = 0;
  const o = "multipleOf" in e ? e.multipleOf : void 0;
  return o !== void 0 && o > 0 && (i = Math.round(i / o) * o, r !== void 0 && i < r && (i = Math.ceil(r / o) * o), s !== void 0 && i > s && (i = Math.floor(s / o) * o)), n ? BigInt(Math.round(i)) : Math.round(i);
}
function Jn(e) {
  let t = "minimum" in e ? e.minimum : void 0, n = "maximum" in e ? e.maximum : void 0;
  const r = "exclusiveMinimum" in e ? e.exclusiveMinimum : void 0, s = "exclusiveMaximum" in e ? e.exclusiveMaximum : void 0, a = "multipleOf" in e ? e.multipleOf : 1e-3;
  r !== void 0 && (t = r + a), s !== void 0 && (n = s - a);
  let u;
  t !== void 0 && n !== void 0 ? u = (t + n) / 2 : t !== void 0 ? u = t : n !== void 0 ? u = 0 <= n ? 0 : n : u = 0;
  const i = "multipleOf" in e ? e.multipleOf : void 0;
  return i !== void 0 && i > 0 && (u = Math.round(u / i) * i, t !== void 0 && u < t && (u = Math.ceil(t / i) * i), n !== void 0 && u > n && (u = Math.floor(n / i) * i)), u;
}
function Zn(e) {
  switch (e) {
    case "date":
      return _e();
    case "time":
      return "00:00:00";
    case "datetime":
      return ze();
    case "duration":
      return "PT0S";
    default:
      return "";
  }
}
function Hn(e) {
  return Array.isArray(e.type) ? e.type.some(
    (t) => typeof t == "string" ? t === "null" : !1
  ) : !1;
}
function We(e) {
  const t = e.type;
  if (typeof t == "string")
    return t;
  if (Array.isArray(t)) {
    for (const n of t)
      if (typeof n == "string" && n !== "null")
        return n;
  }
}
function Xn(e) {
  return e ? [
    "int8",
    "int16",
    "int32",
    "int64",
    "int128",
    "uint8",
    "uint16",
    "uint32",
    "uint64",
    "uint128"
  ].includes(e) : !1;
}
function Yn(e) {
  return e ? ["float", "double", "decimal"].includes(e) : !1;
}
function Qn(e) {
  return e ? ["date", "time", "datetime", "duration"].includes(e) : !1;
}
function _e() {
  return (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
}
function ze() {
  return (/* @__PURE__ */ new Date()).toISOString();
}
function er(e) {
  if (e.isValid)
    return ie.valid;
  const t = Ue(e.errors), n = /* @__PURE__ */ new Map();
  for (const u of t) {
    const i = n.get(u.path) || [];
    i.push(u), n.set(u.path, i);
  }
  const r = (u, i) => {
    if (u.length === 0)
      return {
        message: i.map((y) => y.message).join("; ")
      };
    const [o, ...c] = u, l = r(c, i);
    return {
      dependencies: {
        [o]: l
      }
    };
  }, s = {}, a = {};
  for (const [u, i] of n.entries())
    if (u === "" || u === "/")
      s.message = i.map((o) => o.message).join("; ");
    else {
      const o = u.split("/").filter((c) => c !== "");
      if (o.length === 1)
        a[o[0]] = {
          message: i.map((c) => c.message).join("; ")
        };
      else {
        const [c, ...l] = o;
        a[c] = r(l, i);
      }
    }
  return Object.keys(a).length > 0 && (s.dependencies = a), ie.invalid(s);
}
function Ar({
  schema: e,
  initialValue: t,
  validationMode: n,
  validateDebounceMs: r,
  widgetRegistry: s,
  readOnly: a,
  locale: u,
  onChange: i,
  onValidate: o,
  applySchemaDefaults: c = !0
}, l) {
  const y = t !== void 0 ? I.get(t) : void 0, h = Ln(e);
  let f;
  t === void 0 ? f = h ?? {} : c ? f = rt(
    h,
    y
  ) : f = y;
  const g = Ee(e), d = n ?? "onTouched", v = (R) => {
    const x = g.validate(R);
    if (o && !x.isValid) {
      const O = Ue(x.errors);
      o(O);
    }
    return er(x);
  }, { controller: $, setStatus: A } = ct({
    initialValue: f,
    validationMode: d,
    validateDebounceMs: r,
    validate: d === "onSubmit" ? void 0 : v,
    onChange: i
  }), S = H(
    at(() => {
      $.dispose();
    }),
    wn({
      schema: e,
      controller: $,
      widgetRegistry: s,
      readOnly: a,
      locale: u
    })
  );
  return l({ Form: S, controller: $, setStatus: A });
}
export {
  _ as DefaultWidgetRegistry,
  W as INTEGER_BOUNDS,
  Ar as JSONStructureForm,
  Rt as RefResolver,
  te as StructureContext,
  wn as StructureControl,
  j as StructureGenericControl,
  cr as createExtendsResolver,
  ee as createRefResolver,
  kt as createStructureContext,
  Ee as createValidator,
  gr as createWidgetRegistry,
  jr as ensureDefaultWidgets,
  Ln as extractStructureDefaults,
  br as forFormat,
  xr as forMatcher,
  hr as forType,
  vr as forTypeAndFormat,
  Mn as formatValidationError,
  Ue as formatValidationErrors,
  mr as getChildErrors,
  dr as getErrorsForPath,
  Be as getExplicitWidgetName,
  F as getGlobalWidgetRegistry,
  Q as getNonNullTypes,
  se as getResolvedType,
  $r as getWidgetOptions,
  pr as groupErrorsByPath,
  Dt as hasConstValue,
  Ir as hasCustomWidget,
  Fn as hasDefaultWidgets,
  Mt as hasEnumValue,
  fr as hasErrorsAtPath,
  ge as isArrayTypeDefinition,
  It as isBigIntType,
  xe as isChoiceTypeDefinition,
  ur as isCompoundType,
  X as isFloatType,
  P as isIntegerType,
  be as isMapTypeDefinition,
  jt as isNamespace,
  St as isNullableType,
  wt as isNumericType,
  k as isObjectTypeDefinition,
  Tt as isPrimitiveType,
  he as isSetTypeDefinition,
  Y as isTemporalType,
  ve as isTupleTypeDefinition,
  At as isTypeDefinition,
  C as isTypeReference,
  Tr as mergeWidgetOptions,
  Ot as parseRefPath,
  Pn as registerDefaultWidgets,
  $e as resolveExtends,
  N as resolveRef,
  or as resolveTypeReference,
  qn as resolveWidget,
  wr as resolveWidgetWithOverride,
  yr as setGlobalWidgetRegistry,
  lr as validate
};
