import { g as je, B as mt, N as H, a as fe, b as yt, C as gt, c as ht, d as bt, e as vt, f as wt, h as St, i as At, S as jt, j as Ot, R as kt, k as Ct, E as Te, W as Pt } from "../widget-customization-DFr3ycD7.js";
import { o as Ir, m as Nr, n as Rr, l as Vr } from "../widget-customization-DFr3ycD7.js";
import { c as Me, m as ve, g as We, a as $e, r as Le, e as It, f as Oe, b as Nt, S as Rt, h as we, i as Vt, A as Et } from "../oneof-branch-detection-BED_n2MT.js";
import { n as Fr, l as Tr, k as Mr, o as Wr, p as $r, q as Lr, j as Br } from "../oneof-branch-detection-BED_n2MT.js";
import { attr as j, Value as O, Fragment as ce, Empty as U, WithElement as Be, Use as K, html as I, When as oe, computedOf as M, prop as X, style as De, Ensure as xe, MapSignal as re, Async as Ft, OnDispose as Tt } from "@tempots/dom";
import { _ as _e } from "../string-DYyMxBl-.js";
import { S as Mt, b as Wt, N as Ue, t as te, W as $t, c as Lt, e as Q, T as Bt, U as Dt, f as pe, g as xt, M as ae, h as _t, G as Ut, L as Kt, i as qt, j as Jt } from "../deep-merge-BRqRzEQs.js";
import { S as _, L as ee, M as zt, i as $ } from "../stack-BJgsPJ9A.js";
import { I as ie, b as A, M as de, a as ke, C as Ke, f as Ht, A as Gt, g as Xt } from "../use-form-BSvvERhX.js";
import { r as V } from "../utils-DEbsp9Q9.js";
import { T as Yt } from "../text-input-BZmAB3_o.js";
import { P as Zt, E as Qt, N as qe } from "../notice-BmkckDsD.js";
import { B as q } from "../translations-BGblCUBj.js";
import { l as Je } from "../colors-BmLYKmoH.js";
import { B as ze } from "../input-container-DhUiLmXE.js";
function en(e) {
  if (!e || typeof e != "object") return !1;
  const t = e;
  return !!(e.if || t.dependentRequired || t.dependentSchemas || e.dependencies);
}
function tn(e, t, n, r = []) {
  if (!n)
    return null;
  try {
    if (Me(n, e)(t)) {
      const a = e.title || "disallowed schema";
      return {
        path: r,
        message: `Value matches ${a}`,
        notSchema: e
      };
    }
    return null;
  } catch {
    return null;
  }
}
function nn(e, t, n, r = []) {
  const i = [], s = [], a = He(e, t, n);
  a && i.push(a);
  const o = Array.isArray(e.required) ? [...e.required] : [];
  if (typeof t == "object" && t != null && !Array.isArray(t)) {
    const p = t, c = e.dependentRequired;
    if (c) {
      for (const [f, d] of Object.entries(c))
        if (Object.prototype.hasOwnProperty.call(p, f))
          for (const v of d) o.push(v);
    }
    const h = e.dependencies;
    if (h) {
      for (const [f, d] of Object.entries(h))
        if (Object.prototype.hasOwnProperty.call(p, f))
          if (Array.isArray(d))
            for (const v of d) o.push(v);
          else typeof d == "object" && d && i.push(d);
    }
    const b = e.dependentSchemas;
    if (b)
      for (const [f, d] of Object.entries(b))
        Object.prototype.hasOwnProperty.call(p, f) && i.push(d);
  }
  const l = [e, ...i], { mergedSchema: u, conflicts: m } = ve(
    l,
    r
  );
  if (o.length > 0) {
    const p = /* @__PURE__ */ new Set([...u.required ?? [], ...o]);
    u.required = [...p];
  }
  return s.push(...m), { effective: u, conflicts: s };
}
function He(e, t, n) {
  if (!n || !e.if || typeof e.if != "object") return null;
  try {
    if (Me(n, e.if)(t)) {
      const s = e.then;
      if (s && typeof s == "object")
        return s;
    } else {
      const s = e.else;
      if (s && typeof s == "object")
        return s;
    }
  } catch {
  }
  return null;
}
function G(e, t, n) {
  const r = /* @__PURE__ */ new Set();
  if (!t || typeof t != "object")
    return r;
  if (e.properties && Object.keys(e.properties).forEach((a) => {
    a in t && r.add(a);
  }), e.patternProperties && Object.keys(t).forEach((a) => {
    Object.keys(e.patternProperties).forEach((o) => {
      try {
        new RegExp(o).test(a) && r.add(a);
      } catch {
      }
    });
  }), e.additionalProperties === !0 || e.additionalProperties && typeof e.additionalProperties == "object") {
    const a = /* @__PURE__ */ new Set();
    e.properties && Object.keys(e.properties).forEach((o) => {
      o in t && a.add(o);
    }), e.patternProperties && Object.keys(t).forEach((o) => {
      Object.keys(e.patternProperties).forEach((l) => {
        try {
          new RegExp(l).test(o) && a.add(o);
        } catch {
        }
      });
    }), Object.keys(t).forEach((o) => {
      a.has(o) || r.add(o);
    });
  }
  e.allOf && e.allOf.forEach((a) => {
    typeof a == "object" && G(a, t, n).forEach((l) => r.add(l));
  });
  const i = He(e, t, n);
  i && G(i, t, n).forEach((o) => r.add(o));
  const s = e.dependentSchemas;
  return s && Object.keys(s).forEach((a) => {
    if (a in t) {
      const o = s[a];
      typeof o == "object" && G(
        o,
        t,
        n
      ).forEach((u) => r.add(u));
    }
  }), e.dependencies && Object.keys(e.dependencies).forEach((a) => {
    if (a in t) {
      const o = e.dependencies[a];
      typeof o == "object" && !Array.isArray(o) && G(o, t, n).forEach((u) => r.add(u));
    }
  }), r;
}
function L({
  ctx: e
}) {
  const { examples: t, default: n } = e;
  let { description: r } = e;
  r == null && t != null && n != null && (Array.isArray(t) ? r = `example: ${t[0]}` : r = `example: ${t}`);
  const i = [];
  if (e.isDeprecated && i.push("deprecated"), e.isReadOnly && !e.shouldIgnoreReadOnly && i.push("read-only"), e.isWriteOnly && !e.shouldShowWriteOnly && i.push("write-only"), i.length > 0) {
    const s = `(${i.join(", ")})`;
    r = r ? `${r} ${s}` : s;
  }
  return {
    label: e.suppressLabel ? void 0 : e.widgetLabel,
    description: r,
    required: e.isPropertyRequired,
    layout: e.horizontal ? "horizontal" : "vertical"
  };
}
function ne(e, t) {
  if (e.default != null)
    return t(e.default);
  if (Array.isArray(e.examples))
    return t(e.examples[0]);
  if (e.examples != null)
    return t(e.examples);
}
function Ge(e) {
  return e == null ? 1 : Math.round(e);
}
function Se(e) {
  return e.isWriteOnly && !e.shouldShowWriteOnly;
}
function Ae(e) {
  return e.isReadOnly && !e.shouldIgnoreReadOnly || e.isDeprecated;
}
function E({
  ctx: e,
  controller: t,
  resolved: n
}) {
  const r = n?.widget, i = {
    controller: t,
    ctx: e,
    options: n?.options,
    setStatus: e.setStatus,
    formValue: e.formValue,
    validationMode: e.validationMode,
    submitting: e.submitting
  };
  if (r != null && e.widgetRegistry) {
    const a = e.widgetRegistry.get(r);
    if (a)
      return a.factory(i);
  }
  if (r != null) {
    const a = je.get(r);
    if (a)
      return a.factory(i);
  }
  if (e.widgetRegistry) {
    const a = e.widgetRegistry.findBestWidget(e);
    if (a)
      return a.registration.factory(i);
  }
  const s = je.findBestWidget(e);
  return s ? s.registration.factory(i) : null;
}
function Xe(e) {
  const {
    options: t,
    selected: n,
    onChange: r,
    mode: i = "auto",
    size: s = "sm",
    keyFor: a = (m) => String(m),
    parseKey: o = (m) => m
  } = e, l = t.length;
  if ((i === "auto" ? l <= 3 ? "segmented" : "select" : i) === "segmented") {
    const m = Object.fromEntries(
      t.map((p) => [a(p.value), p.label])
    );
    return Mt({
      options: m,
      value: O.map(n, (p) => a(p)),
      onChange: (p) => r(o(p)),
      size: s
    });
  }
  return Wt({
    options: t.map((m) => ({
      type: "value",
      value: m.value,
      label: m.label
    })),
    value: n,
    onChange: r
  });
}
function Ye({
  ctx: e,
  showSelector: t,
  selector: n,
  inner: r
}) {
  return e.isRoot ? t ? _(j.class("bc-stack--gap-2"), n, r) : r : ie({
    ...L({ ctx: e }),
    content: t ? _(
      j.class("bc-stack--gap-2 bc-stack--align-start"),
      n,
      r
    ) : r
  });
}
function rn(e, t) {
  if (e === null) return t.includes("null") ? "null" : null;
  switch (typeof e) {
    case "string":
      return t.includes("string") ? "string" : null;
    case "number":
      return Number.isInteger(e) && t.includes("integer") ? "integer" : t.includes("number") ? "number" : null;
    case "boolean":
      return t.includes("boolean") ? "boolean" : null;
    case "object":
      return Array.isArray(e) ? t.includes("array") ? "array" : null : t.includes("object") ? "object" : null;
    default:
      return null;
  }
}
function sn(e, t) {
  try {
    switch (t) {
      case "string":
        return e == null ? { ok: !0, value: void 0 } : { ok: !0, value: String(e) };
      case "number": {
        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 "integer":
        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 "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":
        return Array.isArray(e) ? { ok: !0, value: e } : { ok: !1 };
      case "object":
        return e != null && typeof e == "object" && !Array.isArray(e) ? { ok: !0, value: e } : { ok: !1 };
      case "null":
        return { ok: !0, value: null };
    }
  } catch {
    return { ok: !1 };
  }
}
function an(e) {
  switch (e) {
    case "null":
      return null;
    case "array":
      return [];
    case "object":
      return {};
    default:
      return;
  }
}
function on(e) {
  if (typeof e == "boolean") return {};
  const t = e["x:ui"];
  if (t != null && typeof t == "object" && !Array.isArray(t)) {
    const n = t;
    return {
      unionDefault: typeof n.unionDefault == "string" ? n.unionDefault : void 0,
      confirmBranchChange: !!n.confirmBranchChange,
      selector: n.selector === "segmented" || n.selector === "select" ? n.selector : void 0
    };
  }
  return {};
}
function ln(e) {
  const { definition: t } = e;
  if (typeof t == "boolean") return;
  const n = {
    pattern: t.pattern,
    minLength: t.minLength,
    maxLength: t.maxLength
  }, r = V(t, e.name), i = r?.widget;
  if (i != null)
    switch (i) {
      case "binary":
        return { ...n, format: "binary", ...r?.options };
      case "date":
        return { ...n, format: "date" };
      case "date-time":
        return { ...n, format: "date-time" };
      case "email":
        return { ...n, format: "email" };
      case "markdown":
        return { ...n, format: "markdown" };
      case "password":
        return { ...n, format: "password" };
      case "textarea":
        return { ...n, format: "textarea" };
      case "time":
        return { ...n, format: "time" };
      case "uuid":
        return { format: "uuid" };
      case "url":
        return { ...n, format: "url" };
      case "uri":
        return { ...n, format: "uri" };
      case "uri-reference":
        return { ...n, format: "uri-reference" };
      case "hostname":
        return { ...n, format: "hostname" };
      case "ipv4":
        return { ...n, format: "ipv4" };
      case "ipv6":
        return { ...n, format: "ipv6" };
      case "regex":
        return { ...n, format: "regex" };
      case "duration":
        return { ...n, format: "duration" };
      case "color":
        return { ...n, format: "color" };
    }
}
const un = (e) => {
  const { value: t, onBlur: n, onChange: r, onInput: i, after: s, disabled: a, ...o } = e, l = Ue(t, a, r ?? i);
  return mt({
    ...o,
    value: O.map(t, (u) => u ?? void 0),
    onChange: r != null ? (u) => r(u ?? null) : void 0,
    onInput: i != null ? (u) => i(u ?? null) : void 0,
    onBlur: n,
    after: s != null ? ce(l, s) : l
  });
};
function Ce({
  ctx: e,
  options: t,
  controller: n
}) {
  const r = ln(e), i = !e.isNullable, s = () => i ? te(n) : n;
  switch (r?.format) {
    case "email":
      return A(St, {
        ...t,
        controller: s()
      });
    case "date":
      return de(wt, {
        ...t,
        controller: s(),
        toInput: (a) => a == null ? null : new Date(a),
        fromInput: (a) => a?.toISOString().split("T")[0] ?? null
      });
    case "date-time":
      return de(vt, {
        ...t,
        controller: s(),
        toInput: (a) => a == null ? null : new Date(a),
        fromInput: (a) => a?.toISOString() ?? null
      });
    case "time":
      return A(H, {
        ...t,
        controller: s(),
        placeholder: "HH:MM:SS"
      });
    case "password":
      return A(bt, {
        ...t,
        controller: s()
      });
    case "binary": {
      const { definition: a } = e, o = typeof a == "object" ? a["x:ui"] : void 0;
      return r.mediaType && (r.mediaType.startsWith("image/") || r.mediaType.startsWith("video/") || r.mediaType.startsWith("audio/") || r.mediaType === "application/pdf" || o?.preferFileUpload === !0) ? A(un, {
        ...t,
        controller: s(),
        mode: "input",
        accept: r.mediaType || "*/*",
        maxFileSize: (typeof o?.maxBytes == "number" ? o.maxBytes : void 0) || (typeof o?.maxFileSize == "number" ? o.maxFileSize : void 0),
        showFileList: !0
      }) : A(fe, {
        ...t,
        controller: s(),
        placeholder: "Paste base64-encoded data",
        rows: 3
      });
    }
    case "uri":
    case "url":
      return A(ht, {
        ...t,
        controller: s(),
        placeholder: "https://example.com"
      });
    case "uri-reference":
      return A(H, {
        ...t,
        controller: s(),
        placeholder: "Enter URL..."
      });
    case "hostname":
      return A(H, {
        ...t,
        controller: s(),
        placeholder: "example.com"
      });
    case "ipv4":
      return A(H, {
        ...t,
        controller: s(),
        placeholder: "192.168.1.1"
      });
    case "ipv6":
      return A(H, {
        ...t,
        controller: s(),
        placeholder: "2001:db8::1"
      });
    case "regex":
      return A(fe, {
        ...t,
        controller: s(),
        placeholder: "^[a-zA-Z0-9]+$",
        rows: 3
      });
    case "duration":
      return $t(
        ({ Duration: a }) => de(Lt, {
          ...t,
          controller: s(),
          toInput: (o) => o == null ? null : a.from(o),
          fromInput: (o) => o?.toString?.() ?? null
        })
      );
    case "color":
      return A(gt, {
        ...t,
        controller: n,
        displayValue: !0
      });
    case "uuid":
      return A(yt, {
        ...t,
        controller: s()
      });
    case "textarea":
      return A(fe, {
        ...t,
        controller: s()
      });
    default:
      return A(H, {
        ...t,
        controller: s()
      });
  }
}
function me({
  ctx: e,
  controller: t
}) {
  if (Se(e))
    return U;
  const n = V(e.definition, e.name), r = n?.widget, i = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (i)
    return i;
  const s = {
    ...L({ ctx: e }),
    placeholder: ne(e.definition, String),
    disabled: Ae(e)
  };
  if ((e.isNullable || e.isOptional) && !e.shouldShowPresenceToggle)
    return Ce({ ctx: e, options: s, controller: t });
  if (r != null && [
    "url",
    "uri",
    "uri-reference",
    "hostname",
    "ipv4",
    "ipv6",
    "regex",
    "duration",
    "binary",
    "markdown",
    "time",
    "color"
  ].includes(r))
    return Ce({ ctx: e, options: s, controller: t });
  switch (r) {
    case "email":
      return A(Qt, {
        ...s,
        controller: Q(t)
      });
    case "password":
      return A(Zt, {
        ...s,
        controller: Q(t)
      });
    case "uuid":
      return A(Dt, {
        ...s,
        controller: Q(t)
      });
    case "textarea":
      return A(Bt, {
        ...s,
        controller: Q(t)
      });
    default:
      return A(Yt, {
        ...s,
        controller: Q(t)
      });
  }
}
function cn(e) {
  const t = V(e.definition, e.name);
  if (t?.widget === "slider")
    return { widget: "slider", options: t.options };
  if (t?.widget === "rating")
    return { widget: "rating", options: t.options };
  const n = e.definition, r = typeof n == "object" ? n["x:ui"] : void 0;
  return r?.displayFormat === "currency" ? {
    widget: "currency",
    options: {
      currency: typeof r?.currency == "string" ? r.currency : "USD"
    }
  } : r?.displayFormat === "percent" ? { widget: "percent" } : { widget: "number" };
}
function le({
  ctx: e,
  controller: t
}) {
  if (Se(e))
    return U;
  const n = e.definition, r = cn(e), i = V(e.definition, e.name), s = E({
    ctx: e,
    controller: t,
    resolved: i
  });
  if (s)
    return s;
  const a = {
    ...L({ ctx: e }),
    placeholder: ne(e.definition, String),
    min: n.minimum,
    max: n.maximum,
    step: n.multipleOf,
    disabled: Ae(e)
  }, o = (e.isNullable || e.isOptional) && !e.shouldShowPresenceToggle, l = o && !e.isNullable;
  switch (r.widget) {
    case "rating":
      const u = (typeof r.options?.max == "number" ? r.options.max : n.maximum) || 5;
      return o ? A(Ot, {
        ...a,
        max: u,
        controller: l ? te(
          t
        ) : t
      }) : A(kt, {
        ...a,
        max: u,
        controller: t
      });
    case "slider":
      return o ? A(At, {
        ...a,
        controller: l ? te(
          t
        ) : t
      }) : A(jt, {
        ...a,
        controller: t
      });
    case "currency":
      const m = typeof r.options?.currency == "string" ? r.options.currency : "USD";
      return o ? A(ae, {
        ...a,
        mask: Pe(m),
        controller: t
      }) : A(ae, {
        ...a,
        mask: Pe(m),
        controller: t
      });
    case "percent":
      return o ? A(ae, {
        ...a,
        mask: Ie(),
        controller: t
      }) : A(ae, {
        ...a,
        mask: Ie(),
        controller: t
      });
    default:
      return o ? A(pe, {
        ...a,
        controller: l ? te(
          t
        ) : t
      }) : A(xt, {
        ...a,
        controller: t
      });
  }
}
function Pe(e) {
  return `${fn(e)} 000,000.00`;
}
function Ie() {
  return "000.00%";
}
function fn(e) {
  return {
    USD: "$",
    EUR: "€",
    GBP: "£",
    JPY: "¥",
    CAD: "C$",
    AUD: "A$"
  }[e.toUpperCase()] || e;
}
function ye({
  ctx: e,
  controller: t
}) {
  return le({
    ctx: e.with({
      definition: {
        ...e.definition,
        multipleOf: Ge(
          e.definition.multipleOf
        )
      }
    }),
    controller: t
  });
}
function ge({
  ctx: e,
  controller: t
}) {
  if (Se(e))
    return U;
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const i = {
    ...L({ ctx: e }),
    disabled: Ae(e)
  }, s = A(ke, {
    ...i,
    controller: t
  });
  if (!e.isNullable && (!e.isOptional || e.shouldShowPresenceToggle))
    return s;
  const a = !e.isNullable;
  return A(ke, {
    ...i,
    controller: t,
    after: Ue(
      t.signal,
      t.disabled,
      () => t.change(a ? void 0 : null)
    )
  });
}
function Ze({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  return r || Be(() => {
    t.change(null);
  });
}
function dn({
  conflicts: e
}) {
  return e.length === 0 ? U : K(
    q,
    (t) => qe(
      {
        variant: "warning",
        tone: "prominent",
        title: t.value.schemaConflictsDetected,
        class: "bc-schema-conflicts-banner"
      },
      I.ul(
        j.style("margin: 0; padding-left: 1.25rem; list-style-type: disc;"),
        ...e.map(
          (n) => I.li(
            j.style("margin-bottom: 0.25rem;"),
            n.message,
            n.path.length > 0 ? I.code(
              j.style(
                "margin-left: 0.5rem; font-size: 0.75rem; opacity: 0.7;"
              ),
              ` (${n.path.join(".")})`
            ) : null
          )
        )
      )
    )
  );
}
function pn({
  violations: e
}) {
  return e.length === 0 ? U : K(
    q,
    (t) => qe(
      {
        variant: "danger",
        tone: "prominent",
        title: t.value.schemaViolationsDetected,
        class: "bc-not-violations-banner"
      },
      I.ul(
        j.style("margin: 0; padding-left: 1.25rem; list-style-type: disc;"),
        ...e.map(
          (n) => I.li(
            j.style("margin-bottom: 0.25rem;"),
            n.message,
            n.path.length > 0 ? I.code(
              j.style(
                "margin-left: 0.5rem; font-size: 0.75rem; opacity: 0.7;"
              ),
              ` (${n.path.join(".")})`
            ) : null
          )
        )
      )
    )
  );
}
function mn({
  ctx: e,
  controller: t,
  content: n
}) {
  const r = O.map(t.signal, (a) => a !== void 0), i = e.widgetLabel ?? "Property", s = (a) => {
    if (a) {
      const o = e.default;
      if (o !== void 0)
        t.change(o);
      else {
        const l = e.definition;
        l.type === "string" ? t.change("") : l.type === "number" || l.type === "integer" ? t.change(0) : l.type === "boolean" ? t.change(!1) : l.type === "array" ? t.change([]) : l.type === "object" ? t.change({}) : t.change(null);
      }
    } else
      t.change(void 0);
  };
  return _(
    I.div(
      j.class("bc-presence-toggle"),
      ie({
        layout: "horizontal",
        label: `Include ${i}`,
        content: Ct({
          value: r,
          onChange: s,
          size: "xs"
        })
      })
    ),
    oe(r, () => n)
  );
}
function N(e, t, n) {
  const r = e.schemaConflicts.length > 0, i = e.notViolations.length > 0, s = e.shouldShowPresenceToggle && n != null;
  let a = t;
  return s && n != null && (a = mn({ ctx: e, controller: n, content: t })), !r && !i ? a : _(
    j.class("bc-stack--gap-2"),
    i ? pn({ violations: e.notViolations }) : null,
    r ? dn({ conflicts: e.schemaConflicts }) : null,
    a
  );
}
function Qe(e) {
  if (typeof e == "boolean") return;
  const t = e["x:ui"];
  if (!t || !t.visibleIf) return;
  const n = t.visibleIf;
  if (typeof n == "string" || typeof n == "object" && n !== null)
    return n;
}
function yn(e) {
  if (e.startsWith("!"))
    return {
      field: e.slice(1),
      operator: "falsy"
    };
  if (e.includes("!=")) {
    const [t, n] = e.split("!=", 2);
    return {
      field: t.trim(),
      operator: "notEquals",
      value: Ne(n.trim())
    };
  }
  if (e.includes("=")) {
    const [t, n] = e.split("=", 2);
    return {
      field: t.trim(),
      operator: "equals",
      value: Ne(n.trim())
    };
  }
  return {
    field: e.trim(),
    operator: "truthy"
  };
}
function Ne(e) {
  if (e.startsWith('"') && e.endsWith('"') || e.startsWith("'") && e.endsWith("'"))
    return e.slice(1, -1);
  if (e === "true") return !0;
  if (e === "false") return !1;
  if (e === "null") return null;
  if (e !== "undefined")
    return /^-?\d+(\.\d+)?$/.test(e) ? parseFloat(e) : e;
}
function gn(e, t) {
  if (e == null || typeof e != "object")
    return;
  const n = t.split(".");
  let r = e;
  for (const i of n) {
    if (r == null || typeof r != "object")
      return;
    if (Array.isArray(r)) {
      const s = parseInt(i, 10);
      if (!isNaN(s))
        r = r[s];
      else
        return;
    } else
      r = r[i];
  }
  return r;
}
function he(e, t) {
  const n = gn(t, e.field);
  switch (e.operator) {
    case "equals":
      return n === e.value;
    case "notEquals":
      return n !== e.value;
    case "truthy":
      return !!n;
    case "falsy":
      return !n;
    case "contains":
      return typeof n == "string" && typeof e.value == "string" || Array.isArray(n) ? n.includes(e.value) : !1;
    case "notContains":
      return typeof n == "string" && typeof e.value == "string" || Array.isArray(n) ? !n.includes(e.value) : !0;
    case "greaterThan":
      return typeof n == "number" && typeof e.value == "number" && n > e.value;
    case "lessThan":
      return typeof n == "number" && typeof e.value == "number" && n < e.value;
    case "greaterThanOrEqual":
      return typeof n == "number" && typeof e.value == "number" && n >= e.value;
    case "lessThanOrEqual":
      return typeof n == "number" && typeof e.value == "number" && n <= e.value;
    case "in":
      return Array.isArray(e.values) && e.values.includes(n);
    case "notIn":
      return !Array.isArray(e.values) || !e.values.includes(n);
    default:
      return !1;
  }
}
function et(e, t) {
  const n = e.conditions.map((r) => "operator" in r && ["and", "or", "not"].includes(r.operator) ? et(r, t) : he(r, t));
  switch (e.operator) {
    case "and":
      return n.every(Boolean);
    case "or":
      return n.some(Boolean);
    case "not":
      return !n[0];
    default:
      return !1;
  }
}
function hn(e, t) {
  try {
    if (typeof e == "string") {
      const n = yn(e);
      return he(n, t);
    }
    return "operator" in e && ["and", "or", "not"].includes(e.operator) ? et(e, t) : he(e, t);
  } catch (n) {
    return console.warn("Error evaluating visibility condition:", n), !0;
  }
}
function bn(e, t) {
  return M(t)(
    (n) => hn(e, n)
  );
}
const Re = {
  behavior: "hide",
  clearOnHide: !1
};
function vn({
  ctx: e,
  controller: t,
  children: n,
  options: r = Re
}) {
  const i = Qe(e.definition);
  if (!i)
    return n;
  const s = { ...Re, ...r }, a = wn(t), o = bn(i, a);
  switch (s.clearOnHide && o.on((l) => {
    !l && t.signal.value !== void 0 && t.change(void 0);
  }), s.behavior) {
    case "unmount":
      return oe(o, () => n);
    case "hide":
    default:
      return n;
  }
}
function wn(e) {
  return e.signal;
}
function Sn({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const s = e.definition.enum ?? [], a = (e.isNullable || e.isOptional) && !s.includes(null), o = !e.isNullable;
  return K(q, (l) => {
    const u = s.map((p) => ({
      type: "value",
      value: p,
      label: String(p)
    }));
    a && u.unshift({
      type: "value",
      value: null,
      // We use null as the sentinel value internally
      label: O.get(l.$.selectNone)
    });
    const m = a && o ? te(
      t
    ) : t;
    return _t({
      ...L({ ctx: e }),
      options: u,
      controller: m,
      // Custom equality to handle null/undefined comparison
      equality: (p, c) => p == null && c == null ? !0 : p === c
    });
  });
}
function An({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const i = e.definition;
  return ce(
    Be(() => {
      O.get(t.signal) !== i.const && t.change(i.const);
    }),
    Ut(zt(e.widgetLabel, ": "), ee(String(i.const)))
  );
}
function tt(e, t, n) {
  const {
    controller: r,
    effCtx: i,
    patternProps: s,
    apSchema: a,
    canRemove: o,
    lockKeyAfterSet: l,
    validatePropertyName: u
  } = n, m = r.field(e), p = X(e), c = X(null);
  let h = a;
  if (t) {
    const v = Object.keys(s).find((g) => {
      try {
        return new RegExp(g).test(e);
      } catch {
        return !1;
      }
    });
    if (v) {
      const g = s[v];
      g !== !1 && typeof g == "object" && (h = g);
    }
  }
  const b = (v) => {
    const g = (v ?? "").trim();
    if (!g || g === e || Object.prototype.hasOwnProperty.call(
      O.get(r.signal) ?? {},
      g
    ))
      return;
    const y = u(g);
    if (!y.ok) {
      c.set(y.message);
      return;
    }
    c.set(null);
    const w = { ...O.get(r.signal) ?? {} }, S = w[e];
    delete w[e], w[g] = S, r.change(w);
  }, f = K(
    q,
    (v) => Ke({
      size: "xs",
      label: v.$.removeItem,
      disabled: !o(
        Object.keys(O.get(r.signal) ?? {}).length
      ),
      onClick: () => {
        const g = Object.keys(O.get(r.signal) ?? {}).length;
        if (!o(g)) return;
        const y = { ...O.get(r.signal) ?? {} };
        delete y[e], r.change(y);
      }
    })
  ), d = O.map(
    m.signal,
    (v) => l && v != null
  );
  return I.div(
    j.class("bc-object-helpers__row"),
    De.gridTemplateColumns("2fr 3fr min-content"),
    ie({
      content: Te({
        value: p,
        onChange: b,
        disabled: M(
          r.disabled,
          d
        )((v, g) => v || g)
      }),
      error: xe(
        c,
        (v) => I.div(j.class("bc-object-helpers__error"), v)
      ),
      description: Object.keys(s).length > 0 ? I.div(
        j.class("bc-object-helpers__description"),
        "Allowed patterns: ",
        Object.keys(s).join(", ")
      ) : null
    }),
    I.div(
      D({
        ctx: i.with({ definition: h, suppressLabel: !0 }).append(e),
        controller: m
      })
    ),
    I.div(j.class("bc-object-helpers__remove"), f)
  );
}
function nt(e, t, n) {
  const {
    controller: r,
    effCtx: i,
    patternProps: s,
    apSchema: a,
    unevaluatedProps: o,
    canRemove: l,
    lockKeyAfterSet: u,
    validatePropertyName: m
  } = n, p = r.field(e), c = X(e), h = X(null);
  let b;
  if (o && typeof o == "object")
    b = o;
  else if (t) {
    const g = Object.keys(s).find((y) => {
      try {
        return new RegExp(y).test(e);
      } catch {
        return !1;
      }
    });
    if (g) {
      const y = s[g];
      y !== !1 && typeof y == "object" ? b = y : b = a;
    } else
      b = a;
  } else
    b = a;
  const f = (g) => {
    const y = (g ?? "").trim();
    if (!y || y === e || Object.prototype.hasOwnProperty.call(
      O.get(r.signal) ?? {},
      y
    ))
      return;
    const w = m(y);
    if (!w.ok) {
      h.set(w.message);
      return;
    }
    h.set(null);
    const S = { ...O.get(r.signal) ?? {} }, C = S[e];
    delete S[e], S[y] = C, r.change(S);
  }, d = K(
    q,
    (g) => Ke({
      size: "xs",
      label: g.$.removeItem,
      disabled: !l(
        Object.keys(O.get(r.signal) ?? {}).length
      ),
      onClick: () => {
        const y = Object.keys(O.get(r.signal) ?? {}).length;
        if (!l(y)) return;
        const w = { ...O.get(r.signal) ?? {} };
        delete w[e], r.change(w);
      }
    })
  ), v = O.map(
    p.signal,
    (g) => u && g != null
  );
  return I.div(
    j.class("bc-object-helpers__row"),
    De.gridTemplateColumns("2fr 3fr min-content"),
    ie({
      content: Te({
        value: c,
        onChange: f,
        disabled: M(
          r.disabled,
          v
        )((g, y) => g || y)
      }),
      error: xe(
        h,
        (g) => I.div(j.class("bc-object-helpers__error"), g)
      ),
      description: I.div(
        j.class("bc-object-helpers__description"),
        o === !1 ? "Unevaluated property (not allowed by schema)" : "Unevaluated property",
        Object.keys(s).length > 0 ? I.span(
          " • Allowed patterns: ",
          Object.keys(s).join(", ")
        ) : null
      )
    }),
    I.div(
      D({
        ctx: i.with({ definition: b, suppressLabel: !0 }).append(e),
        controller: p
      })
    ),
    I.div(j.class("bc-object-helpers__remove"), d)
  );
}
function rt(e) {
  const t = e.properties ?? {}, n = new Set(Object.keys(t)), r = e.additionalProperties ?? !0, i = r !== !1, s = r === !0 || r === void 0 ? {} : r, a = e.minProperties ?? 0, o = e.maxProperties ?? 1 / 0, l = e.unevaluatedProperties;
  let u = !0, m = null;
  l === !1 ? (u = !1, m = "No unevaluated properties are allowed by schema") : l && typeof l == "object" && (u = !0);
  const p = e.patternProperties ?? {}, c = Object.keys(p).filter(Boolean).map((d) => {
    try {
      return new RegExp(d);
    } catch {
      return null;
    }
  }).filter((d) => d != null), h = e.propertyNames, b = e["x:ui"], f = !!(b && typeof b == "object" && b.lockKeyAfterSet);
  return {
    knownProps: t,
    knownKeys: n,
    ap: r,
    apAllowed: i,
    apSchema: s,
    minProps: a,
    maxProps: o,
    unevaluatedProps: l,
    canAddUnevaluated: u,
    unevaluatedTooltip: m,
    patternProps: p,
    patternList: c,
    propertyNamesDef: h,
    lockKeyAfterSet: f
  };
}
function it(e, t) {
  const { knownKeys: n, apAllowed: r, patternList: i, patternProps: s, propertyNamesDef: a } = e;
  return (o) => {
    const l = (o ?? "").trim();
    if (l === "") return { ok: !1, message: "Key cannot be empty" };
    if (a === !1)
      return { ok: !1, message: "No property names are allowed by schema" };
    if (a && typeof a == "object" && t)
      try {
        const u = t.compile(a);
        if (!u(l))
          return { ok: !1, message: u.errors?.[0]?.message ?? "Invalid property name" };
      } catch {
      }
    if (!r && !n.has(l)) {
      if (i.length === 0)
        return { ok: !1, message: "Only declared properties are allowed" };
      if (!i.some((m) => m.test(l)))
        return {
          ok: !1,
          message: `Key must match one of: ${Object.keys(s).join(", ")}`
        };
    }
    return { ok: !0 };
  };
}
function st(e) {
  const { minProps: t, apSchema: n, unevaluatedProps: r } = e;
  return { canRemove: (o) => o > t, makeDefaultFor: (o) => {
    const l = ne(o, (m) => m);
    if (l !== void 0) return l;
    const u = o.type;
    if (u === "string") return "";
    if (u === "number" || u === "integer") return 0;
    if (u === "boolean") return !1;
    if (u === "array") return [];
    if (u === "object") return {};
  }, getValueSchemaForNew: () => r && typeof r == "object" ? r : n };
}
function jn({
  ctx: e,
  controller: t,
  config: n,
  effective: r
}) {
  const i = Je(n.knownProps).filter(
    ([, o]) => o !== !1
  ), s = i.map(([o]) => o);
  return { children: i.map(([o, l]) => {
    const u = o, m = t.field(u);
    return D({
      ctx: e.with({
        definition: l,
        isPropertyRequired: Array.isArray(r.required) ? r.required.includes(u) : e.hasRequiredProperty(u),
        suppressLabel: !1
      }).append(u),
      controller: m
    });
  }), names: s };
}
function On({
  controller: e,
  config: t,
  validatePropertyName: n,
  helpers: r
}) {
  if (!t.apAllowed) return null;
  const i = (s, a) => {
    const o = s, l = (m) => a.has(m) ? !1 : n(m).ok;
    if (l(o)) return o;
    let u = 1;
    for (; a.has(o + u) || !l(o + u); ) u++;
    return o + u;
  };
  return K(
    q,
    (s) => ze(
      {
        variant: "outline",
        disabled: O.map(
          e.signal,
          (a) => !t.canAddUnevaluated || Object.keys(a ?? {}).length >= t.maxProps
        ),
        onClick: () => {
          const a = O.get(e.signal) ?? {}, o = Object.keys(a);
          if (!t.canAddUnevaluated || o.length >= t.maxProps)
            return;
          const l = new Set(o), u = i("property", l);
          if (!n(u).ok) return;
          const p = r.getValueSchemaForNew(), c = r.makeDefaultFor(p), h = { ...a, [u]: c };
          e.change(h);
        }
      },
      j.title(t.unevaluatedTooltip),
      s.$.addLabel
    )
  );
}
function at({
  ctx: e,
  containerLayout: t,
  content: n
}) {
  return !e.suppressLabel && e.name != null && (!t || !["fieldset", "group"].includes(t.format || "")) ? ie({
    ...L({ ctx: e }),
    content: n
  }) : n;
}
function kn({
  ctx: e,
  controller: t,
  baseDef: n
}) {
  const r = rt(n), i = it(r, e.ajv), s = st(r), { children: a, names: o } = jn({
    ctx: e,
    controller: t,
    config: r,
    effective: n
  }), l = re(t.signal, (h) => {
    const f = Object.keys(h ?? {}).filter((y) => !r.knownKeys.has(y));
    if (f.length === 0)
      return U;
    const d = G(
      n,
      h ?? {},
      e.ajv
    ), v = f.filter((y) => !d.has(y)), g = f.filter(
      (y) => d.has(y)
    );
    return ce(
      ...g.map((y) => {
        const w = r.patternList.some((S) => S.test(y));
        return tt(y, w, {
          controller: t,
          effCtx: e,
          patternProps: r.patternProps,
          apSchema: r.apSchema,
          canRemove: s.canRemove,
          lockKeyAfterSet: r.lockKeyAfterSet,
          validatePropertyName: i
        });
      }),
      ...v.map((y) => {
        const w = r.patternList.some((S) => S.test(y));
        return nt(y, w, {
          controller: t,
          effCtx: e,
          patternProps: r.patternProps,
          apSchema: r.apSchema,
          unevaluatedProps: r.unevaluatedProps,
          canRemove: s.canRemove,
          lockKeyAfterSet: r.lockKeyAfterSet,
          validatePropertyName: i
        });
      })
    );
  }), u = On({
    controller: t,
    config: r,
    validatePropertyName: i,
    helpers: s
  }), m = We(e), p = [...a, l, u].filter(
    Boolean
  ), c = $e(
    m,
    e,
    p,
    o
  );
  return at({ ctx: e, containerLayout: m, content: c });
}
function Cn({
  ctx: e,
  controller: t,
  baseDef: n
}) {
  return re(t.signal, (r) => {
    const { effective: i, conflicts: s } = nn(
      n,
      r,
      e.ajv,
      e.path
    ), a = e.with({
      definition: i,
      schemaConflicts: [...e.schemaConflicts, ...s]
    }), o = rt(i), l = it(o, e.ajv), u = st(o), m = Object.keys(r ?? {}), p = m.filter((k) => !o.knownKeys.has(k)), c = G(
      i,
      r ?? {},
      e.ajv
    ), h = p.filter((k) => !c.has(k)), b = p.filter(
      (k) => c.has(k)
    ), f = o.apAllowed && o.canAddUnevaluated && m.length < o.maxProps, d = (k, F) => {
      const P = k, x = (z) => F.has(z) ? !1 : l(z).ok;
      if (x(P)) return P;
      let B = 1;
      for (; F.has(P + B) || !x(P + B); ) B++;
      return P + B;
    }, v = K(
      q,
      (k) => ze(
        {
          variant: "outline",
          disabled: !f,
          onClick: () => {
            if (!f) return;
            const F = new Set(
              Object.keys(O.get(t.signal) ?? {})
            ), P = d("property", F);
            if (!l(P).ok) return;
            const B = u.getValueSchemaForNew(), z = u.makeDefaultFor(B), se = {
              ...O.get(t.signal) ?? {},
              [P]: z
            };
            t.change(se);
          }
        },
        j.title(o.unevaluatedTooltip),
        k.$.addLabel
      )
    ), g = We(a), y = Je(o.knownProps).filter(
      ([, k]) => k !== !1
    ), S = [
      ...y.map(([k]) => k),
      ...b,
      ...h
    ], C = [
      // Known properties
      // eslint-disable-next-line tempots/no-renderable-signal-map
      ...y.map(([k, F]) => {
        const P = k, x = t.field(P);
        return D({
          ctx: a.with({
            definition: F,
            isPropertyRequired: Array.isArray(i.required) ? i.required.includes(P) : a.hasRequiredProperty(P),
            suppressLabel: !1
          }).append(P),
          controller: x
        });
      }),
      // Evaluated additional keys
      ...b.map((k) => {
        const F = o.patternList.some((P) => P.test(k));
        return tt(k, F, {
          controller: t,
          effCtx: a,
          patternProps: o.patternProps,
          apSchema: o.apSchema,
          canRemove: u.canRemove,
          lockKeyAfterSet: o.lockKeyAfterSet,
          validatePropertyName: l
        });
      }),
      // Unevaluated keys
      ...h.map((k) => {
        const F = o.patternList.some((P) => P.test(k));
        return nt(k, F, {
          controller: t,
          effCtx: a,
          patternProps: o.patternProps,
          apSchema: o.apSchema,
          unevaluatedProps: o.unevaluatedProps,
          canRemove: u.canRemove,
          lockKeyAfterSet: o.lockKeyAfterSet,
          validatePropertyName: l
        });
      }),
      // Add affordance
      o.apAllowed ? v : null
    ].filter(Boolean), J = $e(
      g,
      a,
      C,
      S
    );
    return at({ ctx: a, containerLayout: g, content: J });
  });
}
function ot({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const i = e.definition;
  return en(i) ? Cn({ ctx: e, controller: t, baseDef: i }) : kn({ ctx: e, controller: t, baseDef: i });
}
function Pn(e) {
  if (typeof e == "boolean")
    return { discriminator: null, type: null };
  if (e.discriminator && typeof e.discriminator == "object") {
    const n = e.discriminator;
    if (typeof n.propertyName == "string")
      return {
        discriminator: {
          propertyName: n.propertyName,
          mapping: n.mapping || {}
        },
        type: "openapi"
      };
  }
  const t = e["x:ui"];
  return t?.discriminatorKey && typeof t.discriminatorKey == "string" ? {
    discriminator: {
      key: t.discriminatorKey,
      mapping: t.discriminatorMapping || {}
    },
    type: "beatui"
  } : { discriminator: null, type: null };
}
function In(e, t, n) {
  if (!t.discriminator || !n || typeof n != "object")
    return null;
  const { discriminator: r, type: i } = t;
  if (i === "openapi") {
    const s = r, a = n[s.propertyName];
    if (a == null)
      return null;
    if (s.mapping && s.mapping[a]) {
      const o = s.mapping[a];
      return Nn(e, o);
    }
    return Ve(
      e,
      s.propertyName,
      a
    );
  }
  if (i === "beatui") {
    const s = r, a = n[s.key];
    if (a == null)
      return null;
    if (s.mapping && s.mapping[a] != null) {
      const o = s.mapping[a];
      return o >= 0 && o < e.length ? o : null;
    }
    return Ve(
      e,
      s.key,
      a
    );
  }
  return null;
}
function Nn(e, t) {
  for (let n = 0; n < e.length; n++) {
    const r = e[n];
    if (typeof r == "object" && r.$ref === t)
      return n;
  }
  return null;
}
function Ve(e, t, n) {
  for (let r = 0; r < e.length; r++) {
    const i = e[r];
    if (typeof i != "object") continue;
    const s = i.properties;
    if (s && s[t]) {
      const a = s[t];
      if (typeof a == "object" && a.const === n || typeof a == "object" && Array.isArray(a.enum) && a.enum.length === 1 && a.enum[0] === n)
        return r;
    }
    if (i.const === n)
      return r;
  }
  return null;
}
function Rn({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const i = e.definition.anyOf;
  return lt({ ctx: e, controller: t, kind: "anyOf", variants: i });
}
function Vn({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const i = e.definition.oneOf;
  return lt({ ctx: e, controller: t, kind: "oneOf", variants: i });
}
function jr({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const s = e.definition.allOf.filter((u) => typeof u == "object").map((u) => Le(u, e.schema, e.ajv)), { mergedSchema: a, conflicts: o } = ve(s, e.path), l = e.with({
    definition: a,
    schemaConflicts: [...e.schemaConflicts, ...o]
  });
  return D({
    ctx: l,
    controller: t
  });
}
function lt({
  ctx: e,
  controller: t,
  kind: n,
  variants: r
}) {
  const i = r.map((f, d) => It(f, d, `${n} ${d + 1}`)), s = typeof e.definition == "boolean" ? { discriminator: null, type: null } : Pn(e.definition), a = M(
    t.signal,
    e.ajv
  )((f, d) => {
    if (n === "oneOf") {
      if (s.discriminator) {
        const v = In(
          r,
          s,
          f
        );
        if (v !== null)
          return v;
      }
      return Oe(e, f, d);
    }
    return Oe(e, f, d);
  }), o = O.get(a), l = X(o >= 0 ? o : 0);
  t.onDispose(l.dispose);
  let u = !1;
  const m = a.on((f) => {
    !u && f >= 0 && l.set(f);
  });
  t.onDispose(m);
  const p = r.length, c = (f) => {
    u = !0, l.set(f);
  }, h = p > 1 ? Xe({
    options: r.map((f, d) => ({
      value: d,
      label: i[d]
    })),
    selected: l,
    onChange: c
    // auto mode chooses segmented for <=3
  }) : "", b = re(l, (f) => D({
    ctx: e.with({
      definition: r[O.get(f)],
      // Suppress inner labels only when combinator is nested (non-root)
      suppressLabel: !e.isRoot
    }),
    controller: t
  }));
  return Ye({
    ctx: e,
    showSelector: p > 1,
    selector: h,
    inner: b
  });
}
function D({
  ctx: e,
  controller: t
}) {
  const n = typeof e.definition == "boolean" ? {} : e.definition;
  let r = n?.$ref ? Nt(n, e.schema) : n, i = e.with({ definition: r });
  if (r?.allOf != null) {
    const a = r.allOf.filter(
      (o) => typeof o == "object" && o !== null
    );
    if (a.length > 0) {
      const o = a.map(
        (c) => Le(c, e.schema, e.ajv)
      ), { mergedSchema: l, conflicts: u } = ve(o, e.path), { allOf: m, ...p } = r;
      r = { ...p, ...l }, i = e.with({
        definition: r,
        schemaConflicts: [...e.schemaConflicts, ...u]
      });
    }
  }
  let s = [...i.notViolations];
  if (r?.not != null && typeof r.not == "object") {
    const a = O.get(t.signal), o = tn(
      r.not,
      a,
      i.ajv,
      i.path
    );
    o && (s = [...s, o], i = i.with({ notViolations: s }));
  }
  if (r == null)
    return R(
      i,
      t,
      N(
        i,
        ue({
          ctx: i,
          controller: t
        }),
        t
      )
    );
  if (r.enum != null)
    return R(
      i,
      t,
      N(
        i,
        Sn({
          ctx: i,
          controller: t
        }),
        t
      )
    );
  if (r.const != null)
    return R(
      i,
      t,
      N(
        i,
        An({
          ctx: i,
          controller: t
        }),
        t
      )
    );
  if (r.anyOf != null)
    return R(
      i,
      t,
      N(
        i,
        Rn({
          ctx: i,
          controller: t
        }),
        t
      )
    );
  if (r.oneOf != null)
    return R(
      i,
      t,
      N(
        i,
        Vn({
          ctx: i,
          controller: t
        }),
        t
      )
    );
  if (r?.type == null)
    return N(
      i,
      ue({
        ctx: i,
        controller: t
      }),
      t
    );
  if (Array.isArray(r.type)) {
    const o = r.type.filter((l) => l !== "null");
    if (o.length === 1 && ["string", "number", "integer", "boolean"].includes(o[0]))
      switch (o[0]) {
        case "number":
          return N(
            i,
            le({
              ctx: i,
              controller: t
            }),
            t
          );
        case "integer":
          return N(
            i,
            ye({
              ctx: i,
              controller: t
            }),
            t
          );
        case "string":
          return N(
            i,
            me({
              ctx: i,
              controller: t
            }),
            t
          );
        case "boolean":
          return N(
            i,
            ge({
              ctx: i,
              controller: t
            }),
            t
          );
      }
    return R(
      i,
      t,
      N(
        i,
        ct({
          ctx: i,
          controller: t
        }),
        t
      )
    );
  }
  switch (r.type) {
    case "number":
      return R(
        i,
        t,
        N(
          i,
          le({
            ctx: i,
            controller: t
          }),
          t
        )
      );
    case "integer":
      return R(
        i,
        t,
        N(
          i,
          ye({
            ctx: i,
            controller: t
          }),
          t
        )
      );
    case "string":
      return R(
        i,
        t,
        N(
          i,
          me({
            ctx: i,
            controller: t
          }),
          t
        )
      );
    case "boolean":
      return R(
        i,
        t,
        N(
          i,
          ge({
            ctx: i,
            controller: t
          }),
          t
        )
      );
    case "array":
      return R(
        i,
        t,
        N(
          i,
          ut({
            ctx: i,
            controller: t instanceof Gt ? t : t.array()
          }),
          t
        )
      );
    case "object": {
      const a = ot({
        ctx: i,
        controller: t instanceof Ht ? t : t.object()
      });
      return i.isRoot ? R(
        i,
        t,
        N(i, a, t)
      ) : R(
        i,
        t,
        N(
          i,
          I.div(j.class("bc-json-schema-object"), a),
          t
        )
      );
    }
    case "null":
      return R(
        i,
        t,
        N(
          i,
          Ze({
            ctx: i,
            controller: t
          }),
          t
        )
      );
    default:
      return console.warn("Unknown type", r.type), R(
        i,
        t,
        N(
          i,
          I.div(j.class("bc-json-schema-unknown"), "Unknown"),
          t
        )
      );
  }
}
function En({
  schema: e,
  controller: t,
  ajv: n,
  widgetRegistry: r,
  setStatus: i,
  formValue: s,
  validationMode: a,
  submitting: o
}) {
  const l = new Rt({
    schema: e,
    definition: e,
    horizontal: !1,
    isPropertyRequired: !1,
    path: [],
    ajv: n,
    widgetRegistry: r,
    setStatus: i,
    formValue: s,
    validationMode: a,
    submitting: o
  });
  return e === !0 ? ue({ ctx: l, controller: t }) : e === !1 ? U : D({ ctx: l, controller: t });
}
function R(e, t, n) {
  return Qe(e.definition) ? vn({
    ctx: e,
    controller: t,
    children: n,
    options: {
      behavior: "hide",
      // Default to hide behavior
      clearOnHide: !1
      // Don't clear values by default
    }
  }) : n;
}
function Fn(e) {
  return e.prefixItems != null ? {
    isTuple: !0,
    prefixItems: e.prefixItems,
    additionalItemsSchema: Array.isArray(e.items) ? !0 : e.items ?? !0,
    tupleLabels: Ee(e)
  } : Array.isArray(e.items) ? {
    isTuple: !0,
    prefixItems: e.items,
    additionalItemsSchema: e.additionalItems ?? !0,
    tupleLabels: Ee(e)
  } : {
    isTuple: !1,
    prefixItems: [],
    additionalItemsSchema: e.items ?? !0
  };
}
function Ee(e) {
  if (typeof e == "boolean") return;
  const t = e["x:ui"];
  return Array.isArray(t?.tupleLabels) ? t.tupleLabels : void 0;
}
function ut({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const i = e.definition, s = Fn(i), a = M(t.signal)((c) => {
    const h = c?.length ?? 0;
    return !(i.maxItems != null && h >= i.maxItems || s.isTuple && h >= s.prefixItems.length && s.additionalItemsSchema === !1);
  }), o = M(t.signal)((c) => {
    const h = c?.length ?? 0;
    return i.minItems == null || h > i.minItems;
  }), l = M(t.signal)((c) => {
    if (!i.uniqueItems || !c) return /* @__PURE__ */ new Set();
    const h = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Set();
    for (let f = 0; f < c.length; f++) {
      const d = JSON.stringify(c[f]);
      h.has(d) ? (b.add(h.get(d)), b.add(f)) : h.set(d, f);
    }
    return b;
  }), u = M(t.signal)((c) => {
    if (!i.contains || !c)
      return { matchingIndices: /* @__PURE__ */ new Set(), count: 0, isValid: !0 };
    const h = /* @__PURE__ */ new Set();
    let b = 0;
    if (e.ajv)
      try {
        const g = e.ajv.compile(i.contains);
        for (let y = 0; y < c.length; y++)
          g(c[y]) && (h.add(y), b++);
      } catch {
      }
    else {
      const g = i.contains, y = (w) => {
        if (typeof g == "boolean") return g;
        if (typeof g != "object" || g == null) return !1;
        const S = g, C = S.type;
        if (C === "integer" || C === "number")
          return !(typeof w != "number" || !Number.isFinite(w) || C === "integer" && !Number.isInteger(w) || typeof S.minimum == "number" && w < S.minimum || typeof S.exclusiveMinimum == "number" && w <= S.exclusiveMinimum || typeof S.maximum == "number" && w > S.maximum || typeof S.exclusiveMaximum == "number" && w >= S.exclusiveMaximum || typeof S.multipleOf == "number" && w % S.multipleOf !== 0);
        if (C === "string") {
          if (typeof w != "string" || typeof S.minLength == "number" && w.length < S.minLength || typeof S.maxLength == "number" && w.length > S.maxLength)
            return !1;
          if (typeof S.pattern == "string")
            try {
              if (!new RegExp(S.pattern).test(w)) return !1;
            } catch {
            }
          return !0;
        }
        return !1;
      };
      for (let w = 0; w < c.length; w++)
        y(c[w]) && (h.add(w), b++);
    }
    const f = i.minContains ?? (i.contains ? 1 : 0), d = i.maxContains, v = b >= f && (d == null || b <= d);
    return { matchingIndices: h, count: b, isValid: v, minContains: f, maxContains: d };
  }), m = i.contains ? u.map((c) => {
    const h = typeof i.contains == "object" && i.contains.title ? i.contains.title : "required pattern";
    if (!c.isValid) {
      if (c.count < (c.minContains ?? 0))
        return `Must contain at least ${c.minContains ?? 0} item(s) matching ${h} (currently ${c.count})`;
      if (c.maxContains != null && c.count > c.maxContains)
        return `Must contain at most ${c.maxContains} item(s) matching ${h} (currently ${c.count})`;
    }
    return `Contains ${c.count} item(s) matching ${h}`;
  }) : null, p = Kt({
    ...L({ ctx: e }),
    createItem: () => {
      const c = t.signal.value?.length ?? 0;
      if (s.isTuple && c < s.prefixItems.length) {
        const h = s.prefixItems[c];
        return ne(h, () => {
        });
      } else
        return ne(
          s.additionalItemsSchema,
          () => {
          }
        );
    },
    controller: t,
    // Always render add/remove controls but disable them when constraints forbid actions
    showAdd: !0,
    addDisabled: M(a)((c) => !c),
    showRemove: !0,
    removeDisabled: M(o)((c) => !c),
    element: (c) => {
      const h = c.item, b = c.position.index;
      let f, d;
      s.isTuple && b < s.prefixItems.length ? (f = s.prefixItems[b], s.tupleLabels?.[b] ? d = s.tupleLabels[b] : typeof f == "object" && f.title ? d = f.title : d = `Item ${b + 1}`) : (f = s.additionalItemsSchema, s.isTuple && (d = `Additional Item ${b - s.prefixItems.length + 1}`));
      const v = D({
        ctx: e.with({ definition: f }).append(b),
        controller: h
      }), g = l.map((C) => C.has(b)), y = u.map(
        (C) => C.matchingIndices.has(b)
      );
      let w = v;
      d && s.isTuple && (w = _(
        j.class("bc-stack--gap-1"),
        ee(j.class("bc-array-control__item-label"), d),
        w
      ));
      const S = [];
      return i.uniqueItems && S.push(
        oe(
          g,
          () => ee(
            j.class(
              "bc-array-control__indicator bc-array-control__indicator--error"
            ),
            "⚠️ Duplicate value"
          )
        )
      ), i.contains && S.push(
        oe(
          y,
          () => ee(
            j.class(
              "bc-array-control__indicator bc-array-control__indicator--success"
            ),
            "✓ Matches required pattern"
          )
        )
      ), S.length > 0 ? _(j.class("bc-stack--gap-1"), w, ...S) : w;
    }
  });
  return i.contains && m ? _(
    j.class("bc-stack--gap-2"),
    p,
    re(
      M(
        u,
        m
      )((c, h) => ({
        info: c,
        summary: h
      })),
      ({ info: c, summary: h }) => ee(
        j.class(
          c.isValid ? "bc-array-control__summary bc-array-control__summary--success" : "bc-array-control__summary bc-array-control__summary--error"
        ),
        h
      )
    )
  ) : p;
}
function Tn(e) {
  return e.map((t) => ({
    key: t,
    label: _e(t),
    detect: (n) => rn(n, [t]) === t,
    convert: (n) => sn(n, t),
    defaultValue: () => an(t)
  }));
}
function ct({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  if (r)
    return r;
  const i = e.definition;
  let s = i.type ?? [];
  const a = on(i), o = s.includes("null"), l = s.filter(
    (f) => f !== "null" && (f === "string" || f === "number" || f === "integer" || f === "boolean")
  ), u = o && l.length === s.length - 1;
  u && (s = l);
  const m = Tn(s), p = new qt(
    t.path,
    t.change,
    t.signal,
    t.status,
    { disabled: t.disabled },
    m
  );
  t.onDispose(() => p.dispose());
  const c = (f) => Xe({
    options: s.map((d) => ({ value: d, label: _e(d) })),
    selected: p.activeBranch,
    onChange: f,
    mode: a.selector ?? "auto"
  }), h = (f) => {
    p.switchToBranch(f, a.confirmBranchChange);
  }, b = re(p.activeBranch, (f) => {
    const d = O.get(f), v = p.getBranchController(d);
    if (u && (d === "number" || d === "integer")) {
      const y = i;
      return A(pe, {
        // Suppress inner labels only when union is nested (non-root)
        ...L({
          ctx: e.with({ suppressLabel: !e.isRoot })
        }),
        controller: v,
        min: y.minimum,
        max: y.maximum,
        step: d === "integer" ? Ge(y.multipleOf) : y.multipleOf
      });
    }
    const g = e.with({
      definition: { ...i, type: d },
      // Suppress inner labels only when union is nested (non-root)
      suppressLabel: !e.isRoot
    });
    switch (d) {
      case "string":
        return me({
          ctx: g,
          controller: v
        });
      case "number":
        return le({
          ctx: g,
          controller: v
        });
      case "integer":
        return ye({
          ctx: g,
          controller: v
        });
      case "boolean":
        return ge({
          ctx: g,
          controller: v
        });
      case "null":
        return Ze({
          ctx: g,
          controller: v
        });
      case "array": {
        const y = v.array();
        return ut({
          ctx: g,
          controller: y
        });
      }
      case "object": {
        const y = v.object();
        return ot({
          ctx: g,
          controller: y
        });
      }
      default:
        return A(pe, {
          ...L({ ctx: g }),
          controller: v
        });
    }
  });
  return Ye({
    ctx: e,
    showSelector: s.length > 1,
    selector: c(h),
    inner: b
  });
}
function ue({
  ctx: e,
  controller: t
}) {
  const n = V(e.definition, e.name), r = E({
    ctx: e,
    controller: t,
    resolved: n
  });
  return r || (e.definition === !0 ? ue({
    ctx: e.with({
      definition: {
        type: ["string", "number", "object", "array", "boolean", "null"]
      }
    }),
    controller: t
  }) : ct({
    ctx: e.with({
      definition: {
        ...e.definition,
        type: ["string", "number", "object", "array", "boolean", "null"]
      }
    }),
    controller: t
  }));
}
function Mn(e) {
  if (typeof e == "boolean") return [];
  const t = e["x:ui"];
  return !t || !Array.isArray(t.crossField) ? [] : t.crossField.filter(
    (n) => typeof n == "object" && n != null && typeof n.id == "string" && Array.isArray(n.fields) && typeof n.validate == "function"
  );
}
function Wn(e, t, n = !1) {
  const r = [], i = [...t].sort(
    (s, a) => (a.priority || 0) - (s.priority || 0)
  );
  for (const s of i)
    if (!(s.onSubmitOnly && !n))
      try {
        const a = {};
        for (const l of s.fields)
          a[l] = $n(e, l);
        const o = s.validate(a, e);
        if (!o.valid) {
          const l = s.targets || s.fields;
          if (o.fieldErrors)
            for (const [u, m] of Object.entries(o.fieldErrors))
              r.push({
                instancePath: `/${u}`,
                schemaPath: `#/x:ui/crossField/${s.id}`,
                keyword: "crossField",
                params: {
                  ruleId: s.id,
                  fields: s.fields,
                  context: o.context
                },
                message: m
              });
          else {
            const u = o.message || s.message || "Cross-field validation failed";
            for (const m of l)
              r.push({
                instancePath: `/${m}`,
                schemaPath: `#/x:ui/crossField/${s.id}`,
                keyword: "crossField",
                params: {
                  ruleId: s.id,
                  fields: s.fields,
                  context: o.context
                },
                message: u
              });
          }
        }
      } catch (a) {
        console.warn(`Error in cross-field validation rule ${s.id}:`, a);
        const o = s.targets?.[0] || s.fields[0];
        r.push({
          instancePath: `/${o}`,
          schemaPath: `#/x:ui/crossField/${s.id}`,
          keyword: "crossField",
          params: { ruleId: s.id, fields: s.fields },
          message: "Cross-field validation error"
        });
      }
  return r.length > 0 ? we(r) : $.valid;
}
function $n(e, t) {
  if (e == null || typeof e != "object")
    return;
  const n = t.split(".");
  let r = e;
  for (const i of n) {
    if (r == null || typeof r != "object")
      return;
    if (Array.isArray(r)) {
      const s = parseInt(i, 10);
      if (!isNaN(s))
        r = r[s];
      else
        return;
    } else
      r = r[i];
  }
  return r;
}
function Ln(e) {
  if (typeof e == "boolean") return;
  const t = e["x:ui"];
  if (!t) return;
  const n = {};
  Array.isArray(t.when) && (n.when = t.when.filter(
    (i) => typeof i == "object" && i != null && "watch" in i && "condition" in i
  )), Array.isArray(t.crossField) && (n.crossField = t.crossField.filter(
    (i) => typeof i == "object" && i != null && Array.isArray(i.fields) && typeof i.validate == "function"
  ));
  const r = Mn(e);
  return r.length > 0 && (n.crossFieldRules = r), Array.isArray(t.async) && (n.async = t.async.filter(
    (i) => typeof i == "object" && i != null && typeof i.validate == "function"
  )), Object.keys(n).length > 0 ? n : void 0;
}
function be(e, t) {
  if (!e.startsWith("$."))
    throw new Error(`Invalid JSONPath: ${e}. Must start with '$.'.`);
  const n = e.slice(2).split(/[.[\]]/).filter(Boolean);
  let r = t;
  for (const i of n) {
    if (r == null) return;
    if (typeof r == "object" && !Array.isArray(r))
      r = r[i];
    else if (Array.isArray(r)) {
      const s = parseInt(i, 10);
      if (!isNaN(s))
        r = r[s];
      else
        return;
    } else
      return;
  }
  return r;
}
function Bn(e, t) {
  try {
    if (typeof e.condition == "function") {
      const r = (Array.isArray(e.watch) ? e.watch : [e.watch]).map(
        (i) => be(i, t)
      );
      return e.condition(
        r.length === 1 ? r[0] : r,
        t
      );
    }
    return typeof e.condition == "string" ? !!be(e.condition, t) : !1;
  } catch (n) {
    return console.warn("Error evaluating conditional validation:", n), !1;
  }
}
function Dn(e, t, n, r) {
  const i = [];
  if (r && !r(e) && r.errors && i.push(...r.errors), n.when) {
    for (const s of n.when)
      if (Bn(s, t) ? s.then : s.else, s.validate)
        try {
          const o = s.validate(e, t);
          o && i.push({
            instancePath: "",
            schemaPath: "#/x:ui/when",
            keyword: "conditional",
            params: {},
            message: o
          });
        } catch (o) {
          console.warn("Error in conditional validation:", o);
        }
  }
  if (n.crossField)
    for (const s of n.crossField)
      try {
        const a = {};
        for (const l of s.fields)
          a[l] = be(`$.${l}`, t);
        const o = s.validate(a, t);
        if (o) {
          const l = s.target || s.fields[0];
          i.push({
            instancePath: `/${l}`,
            schemaPath: "#/x:ui/crossField",
            keyword: "crossField",
            params: { fields: s.fields },
            message: s.message || o
          });
        }
      } catch (a) {
        console.warn("Error in cross-field validation:", a);
      }
  if (n.crossFieldRules && n.crossFieldRules.length > 0) {
    const s = Wn(
      t,
      n.crossFieldRules
    );
    if (s.type === "invalid") {
      const a = xn(s);
      i.push(...a);
    }
  }
  return i.length > 0 ? we(i) : $.valid;
}
function xn(e) {
  if (e.type === "valid") return [];
  const t = [];
  function n(r, i = "") {
    if (r.message && t.push({
      instancePath: i,
      schemaPath: "#/crossField",
      keyword: "crossField",
      params: {},
      message: r.message
    }), r.dependencies)
      for (const [s, a] of Object.entries(r.dependencies)) {
        const o = i ? `${i}/${s}` : `/${s}`;
        n(a, o);
      }
  }
  return n(e.error), t;
}
function _n(e, t) {
  const n = /* @__PURE__ */ new Set();
  if (e.when)
    for (const r of e.when)
      (Array.isArray(r.watch) ? r.watch : [r.watch]).forEach((s) => n.add(s));
  if (e.crossField)
    for (const r of e.crossField)
      r.fields.forEach((i) => n.add(i));
  return {
    watchedPaths: Array.from(n),
    shouldRevalidate: (r) => Array.from(n).some((i) => r.startsWith(i) || i.startsWith(r))
  };
}
function Un(e) {
  if (typeof e == "boolean") return [];
  const t = e["x:ui"];
  return !t || !Array.isArray(t.async) ? [] : t.async.filter(
    (n) => typeof n == "object" && n != null && typeof n.id == "string" && typeof n.field == "string" && typeof n.validate == "function"
  );
}
class Kn {
  timeouts = /* @__PURE__ */ new Map();
  validationStates = /* @__PURE__ */ new Map();
  abortControllers = /* @__PURE__ */ new Map();
  /**
   * Create or get validation state signal for a field
   */
  getValidationState(t) {
    return this.validationStates.has(t) || this.validationStates.set(
      t,
      X({
        isValidating: !1,
        result: $.valid,
        lastValidatedValue: void 0,
        lastValidatedAt: 0
      })
    ), this.validationStates.get(t);
  }
  /**
   * Validate a field with debouncing
   */
  async validateField(t, n, r, i = !1) {
    const s = `${t.field}_${t.id}`, a = this.getValidationState(s), o = this.timeouts.get(s);
    o !== void 0 && clearTimeout(o);
    const l = this.abortControllers.get(s);
    if (l && l.abort(), !i && a.value.lastValidatedValue === n)
      return;
    if (t.minLength && typeof n == "string" && n.length < t.minLength) {
      a.set({
        ...a.value,
        result: $.valid,
        isValidating: !1
      });
      return;
    }
    const u = setTimeout(
      async () => {
        const m = new AbortController();
        this.abortControllers.set(s, m), a.set({
          ...a.value,
          isValidating: !0,
          result: t.loadingMessage ? $.invalid({ message: t.loadingMessage }) : a.value.result
        });
        try {
          const p = await t.validate(n, r);
          if (m.signal.aborted)
            return;
          const c = p.valid ? $.valid : $.invalid({
            message: p.message || "Async validation failed",
            context: p.context
          });
          a.set({
            isValidating: !1,
            result: c,
            lastValidatedValue: n,
            lastValidatedAt: Date.now()
          });
        } catch (p) {
          if (m.signal.aborted)
            return;
          const c = p instanceof Error ? p.message : "Async validation error";
          a.set({
            isValidating: !1,
            result: $.invalid({ message: c }),
            lastValidatedValue: n,
            lastValidatedAt: Date.now()
          });
        } finally {
          this.abortControllers.delete(s), this.timeouts.delete(s);
        }
      },
      i ? 0 : t.debounce || 300
    );
    this.timeouts.set(s, u);
  }
  /**
   * Cancel all pending validations
   */
  cancelAll() {
    for (const t of this.timeouts.values())
      clearTimeout(t);
    this.timeouts.clear();
    for (const t of this.abortControllers.values())
      t.abort();
    this.abortControllers.clear();
  }
  /**
   * Get current validation results for all fields
   */
  getAllValidationResults() {
    const t = {};
    for (const [n, r] of this.validationStates.entries()) {
      const i = r.value;
      !i.isValidating && i.result.type === "invalid" && (t[n] = i.result);
    }
    return t;
  }
  /**
   * Check if any validations are currently running
   */
  isValidating() {
    for (const t of this.validationStates.values())
      if (t.value.isValidating)
        return !0;
    return !1;
  }
  /**
   * Dispose of all resources
   */
  dispose() {
    this.cancelAll();
    for (const t of this.validationStates.values())
      t.dispose();
    this.validationStates.clear();
  }
}
function Y(e) {
  if (typeof e != "boolean")
    return qn(e);
}
function qn(e) {
  if (e.default !== void 0)
    return e.default;
  if (Array.isArray(e.examples) && e.examples.length > 0)
    return e.examples[0];
  if (e.const !== void 0)
    return e.const;
  if (Array.isArray(e.enum) && e.enum.length > 0)
    return e.enum[0];
  if (Zn(e))
    return null;
  if (e.allOf && Array.isArray(e.allOf))
    return Jn(e.allOf);
  const t = e.oneOf ?? e.anyOf;
  if (t && Array.isArray(t))
    for (const n of t) {
      const r = Y(n);
      if (r !== void 0)
        return r;
    }
  return zn(e);
}
function Jn(e) {
  const t = {};
  let n = !1;
  for (const r of e) {
    const i = Y(r);
    i !== void 0 && typeof i == "object" && i !== null && (Object.assign(t, i), n = !0);
  }
  return n ? t : void 0;
}
function zn(e) {
  switch (Qn(e)) {
    case "object":
      return Hn(e);
    case "array":
      return Gn(e);
    case "string":
      return Xn(e);
    case "number":
    case "integer":
      return Yn(e);
    case "boolean":
      return !1;
    case "null":
      return null;
    default:
      return;
  }
}
function Hn(e) {
  if (!e.properties)
    return {};
  const t = new Set(e.required ?? []), n = {};
  let r = !1;
  for (const [i, s] of Object.entries(e.properties)) {
    if (!t.has(i) || typeof s == "boolean")
      continue;
    const a = Y(s);
    a !== void 0 && (n[i] = a, r = !0);
  }
  return r ? n : {};
}
function Gn(e) {
  const t = e.minItems ?? 0;
  if (t === 0)
    return [];
  const n = e.items;
  if (!n || typeof n == "boolean")
    return Array(t).fill(null);
  if (Array.isArray(n))
    return n.slice(0, t).map((i) => Y(i) ?? null);
  const r = Y(n);
  return Array(t).fill(r ?? null);
}
function Xn(e) {
  switch (e.format) {
    case "date":
      return er();
    case "date-time":
      return tr();
    case "time":
      return "00:00:00";
    default:
      return "";
  }
}
function Yn(e) {
  const t = e.type === "integer";
  let n = e.minimum, r = e.maximum;
  if (e.exclusiveMinimum !== void 0) {
    const a = typeof e.exclusiveMinimum == "number" ? e.exclusiveMinimum : e.exclusiveMinimum ? n ?? 0 : void 0;
    a !== void 0 && (n = t ? a + 1 : a + Fe(e));
  }
  if (e.exclusiveMaximum !== void 0) {
    const a = typeof e.exclusiveMaximum == "number" ? e.exclusiveMaximum : e.exclusiveMaximum ? r ?? 0 : void 0;
    a !== void 0 && (r = t ? a - 1 : a - Fe(e));
  }
  let i;
  n !== void 0 && r !== void 0 ? i = (n + r) / 2 : n !== void 0 ? i = n : r !== void 0 ? i = 0 <= r ? 0 : r : i = 0;
  const s = e.multipleOf;
  return s !== void 0 && s > 0 && (i = Math.round(i / s) * s, n !== void 0 && i < n && (i = Math.ceil(n / s) * s), r !== void 0 && i > r && (i = Math.floor(r / s) * s)), t && (i = Math.round(i)), i;
}
function Fe(e) {
  return e.multipleOf !== void 0 ? e.multipleOf : 1e-3;
}
function Zn(e) {
  return Array.isArray(e.type) ? e.type.includes("null") : !1;
}
function Qn(e) {
  if (typeof e.type == "string")
    return e.type;
  if (Array.isArray(e.type))
    return e.type.find((t) => t !== "null");
  if (e.properties !== void 0)
    return "object";
  if (e.items !== void 0)
    return "array";
}
function er() {
  return (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
}
function tr() {
  return (/* @__PURE__ */ new Date()).toISOString();
}
function nr(e) {
  const t = globalThis.structuredClone;
  return typeof t == "function" ? t(e) : JSON.parse(JSON.stringify(e));
}
function rr(e, t) {
  try {
    return JSON.stringify(e) === JSON.stringify(t);
  } catch {
    return e === t;
  }
}
function ir(e) {
  const t = new Pt();
  for (let n = 0; n < e.length; n++) {
    const r = e[n], i = r.displayName ?? `custom-widget-${n}`;
    t.register(i, {
      factory: r.factory,
      displayName: r.displayName ?? `Custom Widget ${n + 1}`,
      description: r.description,
      supportedTypes: r.supportedTypes,
      priority: r.priority ?? 50,
      canFallback: !0,
      matcher: r.matcher
    });
  }
  return t;
}
function Or({
  schema: e,
  initialValue: t,
  externalSchemas: n,
  refResolver: r,
  sanitizeAdditional: i,
  validationMode: s,
  validateDebounceMs: a,
  customWidgets: o,
  applySchemaDefaults: l = !0,
  submitting: u
}, m) {
  const p = t !== void 0 ? O.get(t) : void 0, c = Y(e);
  let h;
  return t === void 0 ? h = c ?? {} : l ? h = Jt(
    c,
    p
  ) : h = p, Ft(
    Vt(e, {
      externalSchemas: n,
      refResolver: r,
      sanitizeAdditional: i
    }),
    (b) => {
      if (b.ok) {
        const { ajv: f, validate: d } = b.value, v = Ln(e), g = Un(e), y = g.length > 0 ? new Kn() : null, w = s ?? "onTouched", S = (T) => {
          const W = d(T);
          let Z;
          return W ? Z = $.valid : Z = we(
            d.errors ?? []
          ), v ? Dn(
            T,
            T,
            // formData is the same as value for root-level validation
            v,
            d
          ) : Z;
        }, { controller: C, setStatus: J } = Xt({
          initialValue: h,
          validationMode: w,
          validateDebounceMs: a,
          validate: w === "onSubmit" ? void 0 : S
        }), k = v ? _n(v) : null, F = i !== !1;
        let P = !1;
        const x = F ? C.signal.on((T) => {
          if (P) return;
          const W = nr(T);
          d(W) && !rr(W, T) && (P = !0, C.change(W), P = !1);
        }) : () => {
        }, B = k ? C.signal.on((T, W) => {
          W != null && JSON.stringify(T) !== JSON.stringify(W) && setTimeout(() => {
            const pt = C.status.value;
            J(pt);
          }, 10);
        }) : () => {
        }, z = y && g.length > 0 ? C.signal.on((T) => {
          for (const W of g)
            y.validateField(W, T, T);
        }) : () => {
        }, se = () => {
          x(), B(), z(), y?.dispose(), C.dispose();
        }, ft = o ? ir(o) : void 0, dt = ce(
          Tt(se),
          En({
            schema: e,
            controller: C,
            ajv: f,
            widgetRegistry: ft,
            setStatus: J,
            formValue: C.signal,
            validationMode: w,
            submitting: u
          })
        );
        return m({ Form: dt, controller: C, setStatus: J });
      }
      return I.div(j.class("bc-json-schema-form__error"), b.error);
    }
  );
}
function kr(e, t) {
  const r = (t?.ajv ?? new Et({ allErrors: !0 })).compile(e);
  return {
    "~standard": {
      version: 1,
      vendor: "ajv",
      validate: (i) => r(i) ? { value: i } : { issues: sr(r.errors ?? []) },
      types: void 0
    }
  };
}
function sr(e) {
  return e.map((t) => ({
    message: ar(t),
    path: or(t)
  }));
}
function ar(e) {
  return e.message ?? `${e.keyword} validation failed`;
}
function or(e) {
  const t = lr(e.instancePath || "");
  if (e.keyword === "required") {
    const n = e.params.missingProperty;
    if (n != null) return [...t, n];
  }
  if (e.keyword === "additionalProperties") {
    const n = e.params.additionalProperty;
    if (n != null) return [...t, n];
  }
  if (e.keyword === "unevaluatedProperties") {
    const n = e.params.unevaluatedProperty;
    if (n != null) return [...t, n];
  }
  return t.length > 0 ? t : void 0;
}
function lr(e) {
  return e ? e.split("/").slice(1).map((n) => n.replace(/~1/g, "/").replace(/~0/g, "~")).map((n) => ur(n) ? Number(n) : n) : [];
}
function ur(e) {
  return /^\d+$/.test(e);
}
export {
  jr as JSONSchemaAllOf,
  ue as JSONSchemaAny,
  Rn as JSONSchemaAnyOf,
  ut as JSONSchemaArray,
  ge as JSONSchemaBoolean,
  An as JSONSchemaConst,
  En as JSONSchemaControl,
  Sn as JSONSchemaEnum,
  Or as JSONSchemaForm,
  D as JSONSchemaGenericControl,
  ye as JSONSchemaInteger,
  Ze as JSONSchemaNull,
  le as JSONSchemaNumber,
  ot as JSONSchemaObject,
  Vn as JSONSchemaOneOf,
  me as JSONSchemaString,
  ct as JSONSchemaUnion,
  Rt as SchemaContext,
  we as ajvErrorsToControllerValidation,
  Fr as ajvErrorsToDependencies,
  Tr as buildMessage,
  Mr as buildPath,
  Wr as clearCaches,
  $r as clearCachesForAjv,
  Me as compileWithCache,
  nn as composeEffectiveObjectSchema,
  kr as createAJVStandardSchema,
  Ir as createDiagnosticWidget,
  He as evaluateIfThenElseOverlay,
  tn as evaluateNotViolation,
  Y as extractSchemaDefaults,
  Nr as forFormat,
  Rr as forTypeAndFormat,
  Vr as forXUI,
  Vt as getAjvForSchema,
  Lr as getCacheStats,
  G as getEvaluatedProperties,
  en as hasConditionalFeatures,
  Br as jsonPointerToSegments,
  ve as mergeAllOf
};
