import { Value as p, prop as ot, computedOf as D, html as _, attr as u, svg as et, svgAttr as Y, on as $, Empty as A, When as W, Fragment as E, aria as N, emitValue as tt, Use as ct, input as it, emitValueAsNullableDate as nt, emitValueAsNullableDateTime as st, style as lt, Repeat as gt, emit as dt, emitValueAsNumber as B } from "@tempots/dom";
import { F as ht, $ as mt, N as X, T as ft, U as bt, a as yt } from "./deep-merge-Bsqkvp9-.js";
import { C as V, b as U, a as wt, c as Q, T as xt, L as $t, d as rt, e as Mt } from "./translations-BEMKy6-W.js";
import { AutoSelect as It, ElementRect as _t } from "@tempots/ui";
import { E as kt, P as Tt } from "./notice-C0Brmeyi.js";
import { s as Ct } from "./use-form-DMiCxK26.js";
function ut(t) {
  if (typeof t != "string") return !1;
  const e = t.startsWith("#") ? t.slice(1) : t;
  return /^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(e);
}
function Ft(t) {
  if (typeof t != "string") return !1;
  const e = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i, s = t.match(e);
  if (!s) return !1;
  const [, n, a, r] = s, o = parseInt(n, 10), c = parseInt(a, 10), i = parseInt(r, 10);
  return o >= 0 && o <= 255 && c >= 0 && c <= 255 && i >= 0 && i <= 255;
}
function At(t) {
  if (typeof t != "string") return !1;
  const e = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+)\s*\)$/i, s = t.match(e);
  if (!s) return !1;
  const [, n, a, r, o] = s, c = parseInt(n, 10), i = parseInt(a, 10), l = parseInt(r, 10), g = parseFloat(o);
  return c >= 0 && c <= 255 && i >= 0 && i <= 255 && l >= 0 && l <= 255 && g >= 0 && g <= 1;
}
function vt(t) {
  if (typeof t != "string") return !1;
  const e = /^hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)$/i, s = t.match(e);
  if (!s) return !1;
  const [, n, a, r] = s, o = parseInt(n, 10), c = parseInt(a, 10), i = parseInt(r, 10);
  return o >= 0 && o <= 360 && c >= 0 && c <= 100 && i >= 0 && i <= 100;
}
function ce(t) {
  return ut(t) || Ft(t) || At(t) || vt(t);
}
function St(t) {
  if (!ut(t)) return null;
  let e = t.startsWith("#") ? t.slice(1) : t;
  return e.length === 3 && (e = e.split("").map((s) => s + s).join("")), `#${e.toLowerCase()}`;
}
function J(t, e, s) {
  const n = (a) => {
    const r = Math.round(Math.max(0, Math.min(255, a))).toString(16);
    return r.length === 1 ? "0" + r : r;
  };
  return `#${n(t)}${n(e)}${n(s)}`;
}
function H(t) {
  const e = St(t);
  if (!e) return null;
  const s = /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);
  return s ? {
    r: parseInt(s[1], 16),
    g: parseInt(s[2], 16),
    b: parseInt(s[3], 16)
  } : null;
}
function ie(t, e) {
  const s = H(t), n = H(e);
  if (!s || !n) return null;
  const a = (l, g, m) => {
    const [b, d, w] = [l, g, m].map((x) => (x = x / 255, x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4)));
    return 0.2126 * b + 0.7152 * d + 0.0722 * w;
  }, r = a(s.r, s.g, s.b), o = a(n.r, n.g, n.b), c = Math.max(r, o), i = Math.min(r, o);
  return (c + 0.05) / (i + 0.05);
}
function Rt(t) {
  if (!t) return [0, 0, 0, 1];
  const s = t.trim().match(
    /^#?([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/
  );
  if (s) {
    const l = s[1];
    if (l.length === 8) {
      const g = parseInt(l.slice(0, 2), 16), m = parseInt(l.slice(2, 4), 16), b = parseInt(l.slice(4, 6), 16), d = parseInt(l.slice(6, 8), 16) / 255;
      return [g, m, b, d];
    }
    if (l.length === 6)
      return [
        parseInt(l.slice(0, 2), 16),
        parseInt(l.slice(2, 4), 16),
        parseInt(l.slice(4, 6), 16),
        1
      ];
    if (l.length === 4) {
      const g = parseInt(l[0] + l[0], 16), m = parseInt(l[1] + l[1], 16), b = parseInt(l[2] + l[2], 16), d = parseInt(l[3] + l[3], 16) / 255;
      return [g, m, b, d];
    }
    if (l.length === 3) {
      const g = parseInt(l[0] + l[0], 16), m = parseInt(l[1] + l[1], 16), b = parseInt(l[2] + l[2], 16);
      return [g, m, b, 1];
    }
  }
  const n = t.match(
    /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+)\s*\)$/i
  );
  if (n)
    return [
      parseInt(n[1], 10),
      parseInt(n[2], 10),
      parseInt(n[3], 10),
      parseFloat(n[4])
    ];
  const a = t.match(
    /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i
  );
  if (a)
    return [parseInt(a[1], 10), parseInt(a[2], 10), parseInt(a[3], 10), 1];
  const r = t.match(
    /^hsla?\(\s*([+-]?[\d.]+)(?:deg)?\s*[ ,]?\s*([\d.]+)%\s*[ ,]?\s*([\d.]+)%\s*(?:[/,]\s*(\d?(?:\.\d+)?))?\s*\)$/i
  );
  if (r) {
    const l = parseFloat(r[1]), g = parseFloat(r[2]), m = parseFloat(r[3]), b = r[4] != null ? parseFloat(r[4]) : 1, [d, w, x] = pt(l, g / 100, m / 100);
    return [d, w, x, b];
  }
  const o = t.match(
    /^hwb\(\s*([+-]?[\d.]+)(?:deg)?\s*[, ]\s*([\d.]+)%\s*[, ]\s*([\d.]+)%\s*(?:[/]\s*(\d?(?:\.\d+)?))?\s*\)$/i
  );
  if (o) {
    const l = parseFloat(o[1]), g = parseFloat(o[2]) / 100, m = parseFloat(o[3]) / 100, b = o[4] != null ? parseFloat(o[4]) : 1, [d, w, x] = Lt(l, g, m);
    return [d, w, x, b];
  }
  const c = t.match(
    /^oklch\(\s*([+-]?[\d.]+%?)\s+([\d.]+)\s+([+-]?[\d.]+)(?:deg)?(?:\s*\/\s*(\d?(?:\.\d+)?))?\s*\)$/i
  );
  if (c) {
    const l = c[1], g = parseFloat(c[2]), m = parseFloat(c[3]), b = c[4] != null ? parseFloat(c[4]) : 1, d = l.endsWith("%") ? Math.max(0, Math.min(1, parseFloat(l) / 100)) : Math.max(0, Math.min(1, parseFloat(l))), [w, x, y] = Et(d, g, m);
    return [w, x, y, b];
  }
  const i = H(t);
  return i ? [i.r, i.g, i.b, 1] : [0, 0, 0, 1];
}
function Nt(t, e, s, n) {
  return `rgba(${Math.round(t)}, ${Math.round(e)}, ${Math.round(s)}, ${Math.max(
    0,
    Math.min(1, Math.round(n * 100) / 100)
  )})`;
}
function Dt(t) {
  let e = t + 1831565813;
  return function() {
    return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), ((e ^ e >>> 14) >>> 0) / 4294967296;
  };
}
function pt(t, e, s) {
  t = (t % 360 + 360) % 360;
  const n = (1 - Math.abs(2 * s - 1)) * e, a = n * (1 - Math.abs(t / 60 % 2 - 1)), r = s - n / 2;
  let o = 0, c = 0, i = 0;
  return 0 <= t && t < 60 ? [o, c, i] = [n, a, 0] : 60 <= t && t < 120 ? [o, c, i] = [a, n, 0] : 120 <= t && t < 180 ? [o, c, i] = [0, n, a] : 180 <= t && t < 240 ? [o, c, i] = [0, a, n] : 240 <= t && t < 300 ? [o, c, i] = [a, 0, n] : [o, c, i] = [n, 0, a], [
    Math.round((o + r) * 255),
    Math.round((c + r) * 255),
    Math.round((i + r) * 255)
  ];
}
function Lt(t, e, s) {
  t = (t % 360 + 360) % 360;
  const n = e + s;
  n > 1 && (e /= n, s /= n);
  const [a, r, o] = pt(t, 1, 0.5).map((m) => m / 255), c = 1 - e - s, i = a * c + e, l = r * c + e, g = o * c + e;
  return [Math.round(i * 255), Math.round(l * 255), Math.round(g * 255)];
}
function Z(t, e, s) {
  t /= 255, e /= 255, s /= 255;
  const n = Math.max(t, e, s), a = Math.min(t, e, s);
  let r = 0, o = 0;
  const c = (n + a) / 2, i = n - a;
  if (i !== 0) {
    switch (o = c > 0.5 ? i / (2 - n - a) : i / (n + a), n) {
      case t:
        r = (e - s) / i + (e < s ? 6 : 0);
        break;
      case e:
        r = (s - t) / i + 2;
        break;
      default:
        r = (t - e) / i + 4;
    }
    r *= 60;
  }
  return [Math.round(r), Math.round(o * 100), Math.round(c * 100)];
}
function Bt(t, e, s) {
  const [n] = Z(t, e, s), a = t / 255, r = e / 255, o = s / 255, c = Math.min(a, r, o), i = 1 - Math.max(a, r, o);
  return [n, Math.round(c * 100), Math.round(i * 100)];
}
function G(t) {
  const e = t / 255;
  return e <= 0.04045 ? e / 12.92 : Math.pow((e + 0.055) / 1.055, 2.4);
}
function K(t) {
  const e = t <= 31308e-7 ? 12.92 * t : 1.055 * Math.pow(t, 0.4166666666666667) - 0.055;
  return Math.round(Math.max(0, Math.min(1, e)) * 255);
}
function Et(t, e, s) {
  const n = s * Math.PI / 180, a = Math.cos(n) * e, r = Math.sin(n) * e, o = t + 0.3963377774 * a + 0.2158037573 * r, c = t - 0.1055613458 * a - 0.0638541728 * r, i = t - 0.0894841775 * a - 1.291485548 * r, l = o * o * o, g = c * c * c, m = i * i * i, b = 4.0767416621 * l - 3.3077115913 * g + 0.2309699292 * m, d = -1.2684380046 * l + 2.6097574011 * g - 0.3413193965 * m, w = -0.0041960863 * l - 0.7034186147 * g + 1.707614701 * m;
  return [K(b), K(d), K(w)];
}
function Vt(t, e, s) {
  const n = G(t), a = G(e), r = G(s), o = 0.4122214708 * n + 0.5363325363 * a + 0.0514459929 * r, c = 0.2119034982 * n + 0.6806995451 * a + 0.1073969566 * r, i = 0.0883024619 * n + 0.2817188376 * a + 0.6299787005 * r, l = Math.cbrt(o), g = Math.cbrt(c), m = Math.cbrt(i), b = 0.2104542553 * l + 0.793617785 * g - 0.0040720468 * m, d = 1.9779984951 * l - 2.428592205 * g + 0.4505937099 * m, w = 0.0259040371 * l + 0.7827717662 * g - 0.808675766 * m, x = Math.sqrt(d * d + w * w);
  let y = Math.atan2(w, d) * 180 / Math.PI;
  return y < 0 && (y += 360), [b, x, y];
}
function P(t, e, s, n, a, r) {
  switch (a) {
    case "hex":
      if (r) {
        const o = (i) => i.toString(16).padStart(2, "0"), c = Math.max(0, Math.min(255, Math.round(n * 255)));
        return `#${o(t)}${o(e)}${o(s)}${o(c)}`;
      }
      return J(t, e, s);
    case "rgb":
      return `rgb(${t}, ${e}, ${s})`;
    case "rgba":
      return `rgba(${t}, ${e}, ${s}, ${Math.round(n * 100) / 100})`;
    case "hsl": {
      const [o, c, i] = Z(t, e, s);
      return `hsl(${o}, ${c}%, ${i}%)`;
    }
    case "hsla": {
      const [o, c, i] = Z(t, e, s);
      return `hsla(${o}, ${c}%, ${i}%, ${Math.round(n * 100) / 100})`;
    }
    case "hwb": {
      const [o, c, i] = Bt(t, e, s);
      return n < 1 ? `hwb(${o} ${c}% ${i}% / ${Math.round(n * 100) / 100})` : `hwb(${o} ${c}% ${i}%)`;
    }
    case "oklch": {
      const [o, c, i] = Vt(t, e, s), l = (Math.round(o * 1e3) / 1e3).toFixed(3), g = (Math.round(c * 1e3) / 1e3).toFixed(3), m = (Math.round(i * 10) / 10).toFixed(1), b = Math.round(n * 100) / 100;
      return r || n < 1 ? `oklch(${l} ${g} ${m} / ${b})` : `oklch(${l} ${g} ${m})`;
    }
  }
}
function j(t, e) {
  return e ? t === "rgb" ? "rgba" : t === "hsl" ? "hsla" : t : t === "rgba" ? "rgb" : t === "hsla" ? "hsl" : t;
}
async function Ut(t) {
  return new Promise((e, s) => {
    const n = new FileReader();
    n.readAsDataURL(t), n.onload = () => {
      const a = n.result;
      e(a.split(",")[1]);
    }, n.onerror = (a) => s(a);
  });
}
function Ot(t) {
  return Promise.all(t.map(Ut));
}
function Pt(t) {
  if (t.length >= 4) {
    if (t[0] === 137 && t[1] === 80 && t[2] === 78 && t[3] === 71)
      return "image/png";
    if (t[0] === 255 && t[1] === 216) return "image/jpeg";
    if (t[0] === 71 && t[1] === 73 && t[2] === 70)
      return "image/gif";
    if (t[0] === 82 && t[1] === 73 && t[2] === 70 && t[3] === 70 && t.length >= 12 && t[8] === 87 && t[9] === 69 && t[10] === 66 && t[11] === 80)
      return "image/webp";
  }
  try {
    if (new TextDecoder("utf-8").decode(t.slice(0, 256)).includes("<svg")) return "image/svg+xml";
  } catch {
  }
  return "application/octet-stream";
}
function jt(t) {
  const e = mt(t ?? ""), s = e.length, n = new Uint8Array(s);
  for (let a = 0; a < s; a++) n[a] = e.charCodeAt(a);
  return n;
}
function Wt(t) {
  const {
    value: e,
    onChange: s,
    onInput: n,
    ...a
  } = t, r = /* @__PURE__ */ new Map(), o = p.toSignal(e).map((g) => g.map((m, b) => {
    const d = r.get(m), w = jt(m ?? ""), x = d?.type || Pt(w), y = d?.name ?? `file-${b}`, I = w.buffer.slice(
      w.byteOffset,
      w.byteOffset + w.byteLength
    ), f = new Blob([I], { type: x });
    return new File([f], y, { type: x });
  })), c = (g) => (m) => {
    g && Ot(m).then((b) => {
      for (const [d, w] of b.entries())
        r.set(w, { name: m[d].name, type: m[d].type });
      g(b);
    });
  }, i = c(s), l = c(n);
  return ht({
    ...a,
    value: o,
    onChange: i,
    onInput: l
  });
}
function le(t) {
  const {
    value: e,
    onInput: s,
    onChange: n,
    ...a
  } = t;
  return Wt({
    ...a,
    maxFiles: 1,
    value: p.map(e, (r) => r == null ? [] : [r]),
    onChange: (r) => {
      n?.(r[0]);
    },
    onInput: (r) => {
      s?.(r[0]);
    }
  });
}
function Ht(t, e) {
  const [s, n, a] = t, r = s << 16 ^ n << 8 ^ a, o = Dt(r), c = 6 + Math.floor(o() * 5), i = 0.18 + o() * 0.06, l = [];
  for (let d = 0; d < c; d++) {
    const w = d / c * Math.PI * 2, x = e * (1 + (o() * 2 - 1) * i), y = Math.cos(w) * x, I = Math.sin(w) * x;
    l.push({ x: y, y: I });
  }
  const g = (l[0].x + l[c - 1].x) / 2, m = (l[0].y + l[c - 1].y) / 2;
  let b = `M ${g.toFixed(3)} ${m.toFixed(3)}`;
  for (let d = 0; d < c; d++) {
    const w = l[d], x = l[(d + 1) % c], y = (w.x + x.x) / 2, I = (w.y + x.y) / 2;
    b += ` Q ${w.x.toFixed(3)} ${w.y.toFixed(3)} ${y.toFixed(3)} ${I.toFixed(3)}`;
  }
  return b += " Z", b;
}
const ue = (t) => {
  const { value: e, onBlur: s, onChange: n, onInput: a, displayValue: r, size: o, withAlpha: c } = t, i = p.map(o ?? 32, (h) => h), l = p.map(e, (h) => Rt(h ?? "#000000")), g = p.map(
    l,
    ([h, M, T]) => [h, M, T]
  ), m = p.map(l, ([, , , h]) => h), b = ot(p.get(m) ?? 1), d = p.map(c ?? !1, (h) => h), w = p.map(
    t.colorTextFormat ?? "rgb",
    (h) => h
  ), x = D(
    g,
    b,
    w,
    d
  )(
    ([h, M, T], v, S, R) => P(h, M, T, v ?? 1, j(S, R), R)
  ), y = p.map(
    t.colorTextFormat ?? "hex",
    (h) => h
  ), I = p.map(i, (h) => `${-h / 2} ${-h / 2} ${h} ${h}`), f = D(
    g,
    i
  )((h, M) => Ht(h, M / 2)), F = D(
    g,
    b,
    d
  )(
    ([h, M, T], v, S) => S || v < 1 ? Nt(h, M, T, v) : J(h, M, T)
  ), C = _.div(
    u.class("bc-color-swatch-input__control"),
    u.class(
      p.map(
        d,
        (h) => h ? "bc-color-swatch-input__control--alpha" : ""
      )
    ),
    u.style(
      D(i)((h) => `min-width:${h + 2}px;height:${h + 2}px`)
    ),
    // The SVG blob preview
    et.svg(
      u.class("bc-color-swatch-input__svg"),
      Y.viewBox(I),
      et.path(Y.d(f), Y.fill(F))
    ),
    // Invisible native input overlays the blob for picker and accessibility
    _.input(
      u.type("color"),
      V(t),
      // Native color input needs hex without alpha
      u.value(p.map(g, ([h, M, T]) => J(h, M, T))),
      u.class(
        "bc-input bc-color-swatch-input bc-color-swatch-input__native"
      ),
      s != null ? $.blur(s) : A,
      n != null ? $.change((h) => {
        const M = h.target.value;
        if (!n) return;
        const { r: T, g: v, b: S } = H(M) ?? { r: 0, g: 0, b: 0 }, R = p.get(b) ?? 1, L = j(
          p.get(y),
          p.get(d)
        ), z = P(T, v, S, R, L, p.get(d));
        n(z);
      }) : A,
      a != null ? $.input((h) => {
        const M = h.target.value;
        if (!a) return;
        const { r: T, g: v, b: S } = H(M) ?? { r: 0, g: 0, b: 0 }, R = p.get(b) ?? 1, L = j(
          p.get(y),
          p.get(d)
        ), z = P(T, v, S, R, L, p.get(d));
        a(z);
      }) : A
    )
  ), k = W(
    d,
    () => _.input(
      u.type("range"),
      u.class("bc-color-swatch-input__alpha"),
      u.min(0),
      u.max(1),
      u.step(0.01),
      u.value(p.map(b, (h) => String(h ?? 1))),
      u.disabled(t.disabled),
      $.input((h) => {
        const M = parseFloat(h.target.value);
        b.set(M);
        const [T, v, S] = p.get(g), R = j(
          p.get(y),
          p.get(d)
        ), L = P(T, v, S, M, R, p.get(d));
        a?.(L);
      }),
      $.change((h) => {
        const M = parseFloat(h.target.value);
        b.set(M);
        const [T, v, S] = p.get(g), R = j(
          p.get(y),
          p.get(d)
        ), L = P(T, v, S, M, R, p.get(d));
        n?.(L);
      })
    )
  );
  return U({
    baseContainer: !0,
    ...t,
    // ensure our control does not try to grow
    growInput: !1,
    input: C,
    // If caller provided an `after`, append RGB before it
    after: E(
      W(
        r ?? !1,
        () => _.span(u.class("bc-color-swatch-input__rgb"), x)
      ),
      k,
      t.after
    )
  });
};
function Xt(t, e, s) {
  const n = ["bc-card"];
  return t !== "default" && n.push(`bc-card--${t}`), e !== "md" && n.push(`bc-card--padding-${e}`), s !== "lg" && n.push(`bc-card--rounded-${s}`), n.join(" ");
}
function pe({ variant: t = "default", size: e = "md", roundedness: s = "lg" } = {}, ...n) {
  return _.div(
    u.class(
      D(
        t,
        e,
        s
      )(
        (a, r, o) => Xt(
          a ?? "default",
          r ?? "md",
          o ?? "lg"
        )
      )
    ),
    ...n
  );
}
const ge = ({
  startEditing: t,
  value: e,
  onChange: s,
  placeholder: n,
  disabled: a
}) => {
  const r = p.deriveProp(t ?? !1), o = ot(!1), c = p.map(a ?? !1, (i) => i);
  return _.div(
    u.class("bc-editable-text"),
    u.class(
      p.map(
        c,
        (i) => i ? "bc-editable-text--disabled" : ""
      )
    ),
    N.disabled(c),
    W(
      r,
      () => _.input(
        u.placeholder(n),
        u.value(e),
        u.class("bc-editable-text__input"),
        It(),
        $.keydown((i) => {
          i.key === "Enter" ? r.set(!1) : i.key === "Escape" && (o.set(!0), r.set(!1));
        }),
        $.blur(
          tt((i) => {
            if (r.set(!1), o.value) {
              o.set(!1);
              return;
            }
            s(i);
          })
        )
      ),
      () => _.span(
        $.click(() => {
          p.get(c) || r.set(!0);
        }),
        u.class("bc-editable-text__display"),
        W(
          p.map(e, (i) => i != null && i.trim() !== ""),
          () => _.span(u.class("bc-editable-text__text"), e),
          () => _.span(
            u.class("bc-editable-text__placeholder"),
            n
          )
        ),
        W(
          p.map(c, (i) => !i),
          () => _.button(
            u.type("button"),
            u.class("bc-editable-text__edit-button"),
            ct(wt, (i) => N.label(i.$.editLabel)),
            $.click(() => r.set(!0)),
            Q({ icon: "line-md/pencil", color: "neutral" })
          )
        )
      )
    )
  );
}, de = (t) => {
  const { value: e, onBlur: s, onChange: n, onInput: a, after: r, disabled: o } = t, c = X(e, o, n ?? a);
  return U({
    ...t,
    input: it.date(
      V(t),
      u.valueAsDate(e),
      u.class("bc-input"),
      s != null ? $.blur(tt(s)) : A,
      n != null ? $.change(nt(n)) : A,
      a != null ? $.input(nt(a)) : A
    ),
    after: r != null ? E(c, r) : c
  });
}, zt = (t) => {
  const e = t.getFullYear(), s = t.getMonth() + 1, n = t.getDate(), a = t.getHours(), r = t.getMinutes(), o = t.getSeconds();
  return `${e}-${s.toString().padStart(2, "0")}-${n.toString().padStart(2, "0")}T${a.toString().padStart(2, "0")}:${r.toString().padStart(2, "0")}:${o.toString().padStart(2, "0")}`;
}, he = (t) => {
  const { value: e, onBlur: s, onChange: n, onInput: a, after: r, disabled: o } = t, c = p.map(e, (l) => l != null ? zt(l) : null), i = X(e, o, n ?? a);
  return U({
    ...t,
    input: it["datetime-local"](
      V(t),
      u.value(p.map(c, (l) => l ?? null)),
      u.class("bc-input"),
      s != null ? $.blur(tt(s)) : A,
      n != null ? $.change(st(n)) : A,
      a != null ? $.input(st(a)) : A
    ),
    after: r != null ? E(i, r) : i
  });
}, at = (t) => typeof t == "string" && t.trim() === "" ? null : t, Yt = (t) => t ?? "";
function O(t) {
  return (e) => {
    const { value: s, onBlur: n, onChange: a, onInput: r, after: o, disabled: c, ...i } = e, l = X(s, c, a ?? r);
    return t({
      ...i,
      disabled: c,
      value: p.map(s, Yt),
      onChange: a != null ? (g) => a(at(g)) : void 0,
      onInput: r != null ? (g) => r(at(g)) : void 0,
      onBlur: n,
      after: o != null ? E(l, o) : l
    });
  };
}
const me = O(kt), fe = O(xt), be = O(Tt), ye = O(
  ft
), we = ({
  value: t,
  onChange: e,
  onInput: s,
  onBlur: n,
  offLabel: a,
  onLabel: r,
  disabled: o = !1,
  size: c = "md",
  id: i,
  color: l = "primary",
  tabIndex: g = 0
}) => {
  const m = i ?? Ct("switch");
  function b(y, I) {
    const f = [
      "bc-switch",
      `bc-switch--size-${I}`,
      `bc-switch--${I}`
    ];
    return y && f.push("bc-switch--disabled"), f.join(" ");
  }
  function d(y) {
    const I = y ?? "primary", f = /* @__PURE__ */ new Map(), F = rt(I, "solid", "light"), C = rt(I, "solid", "dark");
    return f.set("--switch-track-on-bg", F.backgroundColor), f.set("--switch-track-on-label", F.textColor), f.set("--switch-track-on-bg-dark", C.backgroundColor), f.set("--switch-track-on-label-dark", C.textColor), f.set(
      "--switch-track-on-border-dark",
      Mt(I, "dark")
    ), Array.from(f.entries()).map(([k, h]) => `${k}: ${h}`).join("; ");
  }
  const w = () => {
    p.get(o) || (e?.(!p.get(t)), s?.(!p.get(t)));
  }, x = (y) => {
    p.get(o) || (y.key === " " || y.key === "Enter") && (y.preventDefault(), w());
  };
  return _.div(
    u.class(
      D(
        o ?? !1,
        c
      )(
        (y, I) => b(y ?? !1, I ?? "md")
      )
    ),
    u.style(
      D(l)(
        (y) => d(y)
      )
    ),
    u.id(m),
    u.role("switch"),
    u.tabindex(
      D(
        o ?? !1,
        g
      )((y, I) => y ? -1 : I ?? 0)
    ),
    N.checked(t),
    N.disabled(o),
    $.click(w),
    $.keydown(x),
    n != null ? $.blur(n) : null,
    _.div(
      u.class("bc-switch__track"),
      u.class(
        p.map(
          t,
          (y) => y ? "bc-switch__track--on" : "bc-switch__track--off"
        )
      ),
      a != null ? _.div(
        N.hidden(!0),
        u.class("bc-switch__track-label bc-switch__track-label--off"),
        u.class(
          p.map(
            t,
            (y) => y ? "bc-switch__track-label--hidden" : "bc-switch__track-label--visible"
          )
        ),
        a
      ) : null,
      r != null ? _.div(
        u.class("bc-switch__track-label bc-switch__track-label--on"),
        u.class(
          p.map(
            t,
            (y) => y ? "bc-switch__track-label--visible" : "bc-switch__track-label--hidden"
          )
        ),
        r
      ) : null,
      _t(
        (y) => ct(
          $t,
          ({ direction: I }) => _.div(
            u.class("bc-switch__thumb"),
            u.class(
              p.map(
                t,
                (f) => f ? "bc-switch__thumb--on" : "bc-switch__thumb--off"
              )
            ),
            lt.transform(
              D(
                t,
                y,
                c,
                I
              )((f, { width: F }, C, k) => {
                const h = (() => {
                  switch (C) {
                    case "xs":
                      return 5;
                    case "sm":
                      return 5.5;
                    case "md":
                      return 6;
                    case "lg":
                      return 7;
                    case "xl":
                      return 8;
                  }
                })(), M = k === "rtl" ? `calc((var(--spacing-base) * ${h}) - ${F}px)` : `calc(${F}px - (var(--spacing-base) * ${h}))`;
                return f ? `translateX(${M})` : "translateX(0)";
              })
            )
          )
        )
      )
    )
  );
}, xe = O(bt), Gt = "line-md:star-alt-filled", Kt = "line-md:star-alt", qt = (t) => {
  const {
    value: e,
    onChange: s,
    disabled: n,
    max: a = 5,
    fullColor: r = "yellow",
    emptyColor: o = "neutral",
    fullIcon: c = Gt,
    emptyIcon: i = Kt,
    size: l = "md",
    onBlur: g,
    rounding: m = 1
  } = t, b = () => {
    const f = p.get(m);
    return f > 0 ? f : 1;
  }, d = (f) => Math.min(Math.max(f, 0), p.get(a)), w = (f, F) => {
    if (p.get(n ?? !1)) return;
    const k = f.currentTarget.getBoundingClientRect(), h = (f.clientX - k.left) / k.width, M = F - 1 + h, T = b(), v = Math.ceil(M / T) * T, S = d(v);
    s?.(S);
  }, x = (f) => {
    if (p.get(n ?? !1)) return;
    const F = b(), C = p.get(e) ?? 0;
    let k;
    switch (f.key) {
      case "ArrowRight":
      case "ArrowUp":
        k = d(C + F);
        break;
      case "ArrowLeft":
      case "ArrowDown":
        k = d(C - F);
        break;
      case "Home":
        k = 0;
        break;
      case "End":
        k = p.get(a);
        break;
      default:
        return;
    }
    f.preventDefault(), s?.(k);
  }, y = p.map(l, (f) => `bc-icon--${f}`), I = ({ index: f, counter: F }) => _.span(
    u.class("bc-rating-input__icon-container"),
    u.class(y),
    Q(
      {
        icon: i,
        size: l,
        color: o,
        tone: "soft"
      },
      u.class("bc-rating-input__icon-empty")
    ),
    _.span(
      u.class("bc-rating-input__icon-clipper"),
      u.class(y),
      lt.width(
        p.map(e, (C) => {
          const k = Math.floor(C);
          return k > f ? "100%" : k < f ? "0%" : `${(C - f) * 100}%`;
        })
      ),
      Q(
        {
          icon: c,
          size: l,
          color: r,
          tone: "soft"
        },
        u.class("bc-rating-input__icon-full")
      )
    ),
    $.click(
      dt((C) => w(C, F), {
        preventDefault: !0,
        stopPropagation: !0
      })
    )
  );
  return U({
    baseContainer: !0,
    growInput: !1,
    focusableSelector: '[role="slider"]',
    ...t,
    input: _.div(
      // Common input attributes (id, required, invalid, custom classes, etc.)
      V(t),
      u.class("bc-rating-input"),
      // ARIA slider semantics
      u.role("slider"),
      u.tabindex(p.map(n ?? !1, (f) => f ? -1 : 0)),
      N.disabled(n ?? !1),
      N.valuemin(0),
      N.valuemax(p.map(a, (f) => f ?? 0)),
      N.valuenow(p.map(e, (f) => f ?? 0)),
      N.valuetext(
        D(
          e,
          a
        )((f, F) => {
          const C = f ?? 0, k = F ?? 0;
          return `${String(C)} / ${String(k)}`;
        })
      ),
      // Keyboard & focus handlers
      $.keydown(x),
      g != null ? $.blur(g) : null,
      gt(a, I)
    )
  });
}, $e = (t) => {
  const { value: e, onChange: s, onInput: n, onBlur: a, after: r, disabled: o, ...c } = t, i = X(e, o, s ?? n);
  return qt({
    ...c,
    // Map null -> 0 for display so the control shows as empty when null
    value: p.map(e, (l) => l ?? 0),
    // Pass through numeric changes; clear button will call onChange(null)
    onChange: s,
    onInput: n,
    onBlur: a,
    after: r != null ? E(i, r) : i
  });
}, Me = (t) => {
  const { value: e, step: s, min: n, max: a, onBlur: r, onChange: o, onInput: c } = t;
  return U({
    ...t,
    // Make sure clicks anywhere focus the range input
    focusableSelector: 'input[type="range"]',
    input: _.input(
      u.type("range"),
      V(t),
      u.min(n),
      u.max(a),
      u.step(s),
      // Using value as number to keep it in sync
      u.valueAsNumber(e),
      u.class("bc-input bc-slider-input"),
      r != null ? $.blur(B(r)) : A,
      o != null ? $.change(B(o)) : A,
      c != null ? $.input(B(c)) : A
    )
  });
}, Ie = (t) => {
  const { value: e, step: s, min: n, max: a, onBlur: r, onChange: o, onInput: c } = t, i = p.map(e, (g) => {
    if (g != null) return g;
    const m = n != null ? p.get(n) : void 0;
    return typeof m == "number" ? m : 0;
  }), l = X(
    e,
    t.disabled,
    o ?? c
  );
  return U(
    {
      ...t,
      focusableSelector: 'input[type="range"]',
      after: l,
      input: _.input(
        u.type("range"),
        V(t),
        u.min(n),
        u.max(a),
        u.step(s),
        u.valueAsNumber(i),
        u.class("bc-input bc-slider-input"),
        r != null ? $.blur(B(r)) : A,
        o != null ? $.change(
          B((g) => {
            o(g);
          })
        ) : A,
        c != null ? $.input(
          B((g) => {
            c(g);
          })
        ) : A
      )
    },
    // Ensure container grows input naturally
    E()
  );
}, _e = O(yt), q = ["description", "comment", "notes", "text"];
function Qt(t) {
  if (typeof t == "boolean") return q;
  const e = t["x:ui"];
  return e && Array.isArray(e.textAreaTriggers) ? [...q, ...e.textAreaTriggers] : q;
}
function Jt(t) {
  if (typeof t == "boolean") return;
  const e = t["x:ui"];
  if (e != null && (typeof e == "string" || typeof e == "object" && e !== null))
    return e;
}
function Zt(t, e) {
  if (typeof t == "boolean") return;
  const s = Jt(t);
  if (typeof s == "object" && typeof s.widget == "string")
    return {
      widget: s.widget,
      source: "explicit-widget",
      options: s
    };
  const n = typeof s == "string" ? s : typeof s == "object" && typeof s.format == "string" ? s.format : void 0;
  if (n)
    return {
      widget: n,
      source: "explicit-format",
      options: typeof s == "object" ? s : void 0
    };
  if (typeof t.format == "string")
    return {
      widget: {
        datetime: "date-time",
        base64: "binary",
        bytes: "binary",
        iri: "uri",
        "iri-reference": "uri-reference",
        "idn-hostname": "hostname"
      }[t.format] || t.format,
      source: "schema-format"
    };
  if (t.contentMediaType === "text/markdown")
    return {
      widget: "markdown",
      source: "schema-media"
    };
  if (t.contentMediaType != null || t.contentEncoding === "base64")
    return {
      widget: "binary",
      source: "schema-media",
      options: {
        mediaType: t.contentMediaType,
        encoding: t.contentEncoding
      }
    };
  if (t.enum != null)
    return {
      widget: "enum",
      source: "constraints"
    };
  if (t.const != null)
    return {
      widget: "const",
      source: "constraints"
    };
  if ((t.type === "number" || t.type === "integer" || Array.isArray(t.type) && t.type.some((r) => r === "number" || r === "integer")) && t.minimum != null && t.maximum != null)
    return t.maximum - t.minimum <= 5 && t.minimum >= 0 && t.minimum <= 1 && (t.multipleOf == null || t.multipleOf >= 1) ? {
      widget: "rating",
      source: "constraints",
      options: { max: t.maximum }
    } : {
      widget: "slider",
      source: "constraints",
      options: {
        min: t.minimum,
        max: t.maximum,
        step: t.multipleOf
      }
    };
  if (t.type === "string") {
    if (t.minLength != null && t.minLength > 20 || t.maxLength != null && t.maxLength > 100)
      return {
        widget: "textarea",
        source: "heuristics"
      };
    if (e) {
      const r = e.toLowerCase();
      if (r.includes("password") || r.includes("secret"))
        return { widget: "password", source: "heuristics" };
      if (r.includes("email"))
        return { widget: "email", source: "heuristics" };
      if (r.includes("url") || r.includes("link"))
        return { widget: "url", source: "heuristics" };
      if (r.includes("color"))
        return { widget: "color", source: "heuristics" };
      if (Qt(t).some(
        (c) => r.includes(c.toLowerCase())
      ))
        return { widget: "textarea", source: "heuristics" };
    }
  }
}
class te {
  widgets = /* @__PURE__ */ new Map();
  typeMapping = /* @__PURE__ */ new Map();
  // JSON Schema type -> widget names
  /**
   * Register a custom widget
   */
  register(e, s) {
    if (this.widgets.set(e, s), s.supportedTypes)
      for (const n of s.supportedTypes)
        this.typeMapping.has(n) || this.typeMapping.set(n, []), this.typeMapping.get(n).push(e), this.typeMapping.get(n).sort((a, r) => {
          const o = this.widgets.get(a)?.priority || 0;
          return (this.widgets.get(r)?.priority || 0) - o;
        });
  }
  /**
   * Unregister a widget
   */
  unregister(e) {
    const s = this.widgets.get(e);
    if (s && (this.widgets.delete(e), s.supportedTypes))
      for (const n of s.supportedTypes) {
        const a = this.typeMapping.get(n);
        if (a) {
          const r = a.indexOf(e);
          r >= 0 && a.splice(r, 1), a.length === 0 && this.typeMapping.delete(n);
        }
      }
  }
  /**
   * Get a registered widget
   */
  get(e) {
    return this.widgets.get(e);
  }
  /**
   * Get all registered widgets
   */
  getAll() {
    return new Map(this.widgets);
  }
  /**
   * Get widgets that support a specific JSON Schema type
   */
  getForType(e) {
    return (this.typeMapping.get(e) || []).map((n) => this.widgets.get(n)).filter(Boolean);
  }
  /**
   * Find the best widget for a schema context
   */
  findBestWidget(e) {
    const s = Zt(e.definition, e.name);
    if (s?.widget) {
      const a = this.widgets.get(s.widget);
      if (a)
        return { name: s.widget, registration: a, resolved: s };
    }
    const n = [];
    for (const [a, r] of this.widgets.entries())
      if (r.matcher)
        try {
          r.matcher(e) && n.push({
            name: a,
            registration: r,
            priority: r.priority ?? 0
          });
        } catch (o) {
          console.warn(`Error in matcher for widget "${a}":`, o);
        }
    if (n.length > 0) {
      n.sort((r, o) => o.priority - r.priority);
      const a = n[0];
      return {
        name: a.name,
        registration: a.registration,
        resolved: { widget: a.name, source: "heuristics" }
      };
    }
    if (typeof e.definition == "object" && e.definition.type) {
      const a = Array.isArray(e.definition.type) ? e.definition.type[0] : e.definition.type, r = this.getForType(a);
      if (r.length > 0) {
        const o = this.typeMapping.get(a)[0];
        return {
          name: o,
          registration: r[0],
          resolved: { widget: o, source: "type-fallback" }
        };
      }
    }
    return null;
  }
}
const ke = new te();
function Te(t, e, s) {
  return {
    factory: e,
    matcher: (n) => {
      const r = n.definition["x:ui"];
      return r === t || typeof r == "object" && r !== null && r.widget === t;
    },
    displayName: s?.displayName ?? t,
    priority: s?.priority ?? 100,
    // High priority for explicit matches
    ...s
  };
}
function Ce(t, e, s) {
  return {
    factory: e,
    matcher: (n) => n.definition.format === t,
    displayName: s?.displayName ?? `${t} widget`,
    priority: s?.priority ?? 75,
    ...s
  };
}
function Fe(t, e, s, n) {
  return {
    factory: s,
    matcher: (a) => {
      const r = a.definition;
      return r.type === t && r.format === e;
    },
    displayName: n?.displayName ?? `${t}:${e} widget`,
    priority: n?.priority ?? 80,
    ...n
  };
}
function Ae(t) {
  const e = t?.logPrefix ?? "WIDGET_DIAG", s = t?.filterFn ?? (() => !0);
  return {
    factory: () => null,
    displayName: "Diagnostic Widget (never matches)",
    priority: -1e3,
    // Very low priority, should never actually match
    matcher: (n) => {
      if (!s(n)) return !1;
      const a = n.definition, r = {
        name: n.name,
        path: n.path.map(String),
        type: a?.type,
        hasRegistry: n.widgetRegistry !== void 0,
        definition: a
      };
      return console.log(
        `[${e}] name="${r.name ?? "ROOT"}" path=[${r.path.join(", ")}] type="${r.type ?? "unknown"}" hasRegistry=${r.hasRegistry}`
      ), t?.onProcess?.(r), !1;
    }
  };
}
export {
  ie as A,
  le as B,
  ue as C,
  Rt as D,
  ge as E,
  Nt as F,
  Dt as G,
  pt as H,
  Lt as I,
  Z as J,
  Bt as K,
  G as L,
  K as M,
  de as N,
  Et as O,
  Vt as P,
  P as Q,
  qt as R,
  we as S,
  j as T,
  ke as U,
  Zt as V,
  Jt as W,
  te as X,
  Ae as Y,
  ut as a,
  St as b,
  Ce as c,
  Fe as d,
  at as e,
  Te as f,
  Ut as g,
  Wt as h,
  ce as i,
  he as j,
  me as k,
  be as l,
  ye as m,
  Yt as n,
  fe as o,
  xe as p,
  $e as q,
  Me as r,
  Ie as s,
  _e as t,
  pe as u,
  Ft as v,
  At as w,
  vt as x,
  J as y,
  H as z
};
