import { Use as F, Value as p, prop as ae, html as v, attr as l, on as $, WithElement as te, Empty as T, aria as G, bind as oe, computedOf as B, style as we, OnDispose as ne, When as U, NotEmpty as Oe, Fragment as E, ForEach as K, coalesce as Fe, Ensure as Ne, OneOfType as Re, Repeat as je, signal as _e, input as le, emitValue as j, emitValueAsNumber as ke, Task as Ce } from "@tempots/dom";
import { l as Pe } from "./colors-DPo9GEJR.js";
import { g as We } from "./timer-Rd2sKnvH.js";
import { ElementRect as Ze } from "@tempots/ui";
import { a as N, b as W, f as $e, c as O, C as Y, I as He, g as ge, h as Ye, B as pe } from "./translations-BEMKy6-W.js";
import { C as ce, m as qe, c as Ge, I as Ae, S as ee, d as fe, O as Q, e as De } from "./use-form-DMiCxK26.js";
class Je extends Error {
  constructor(e = "Missing implementation") {
    super(e), this.name = "MissingImplementationError";
  }
}
const _t = (t) => Xe(t).split("_").join(" "), Xe = (t) => (t = t.replace(/::/g, "/"), t = t.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2"), t = t.replace(/([a-z\d])([A-Z])/g, "$1_$2"), t = t.replace(/-/g, "_"), t.toLowerCase()), kt = (t) => t.substring(0, 1).toUpperCase() + t.substring(1), Ct = (t) => {
  if (typeof Buffer < "u")
    return Buffer.from(t, "base64").toString("utf8");
  if (typeof atob < "u")
    return atob(t);
  throw new Je(
    "No implementation found for base64 decoding"
  );
};
function de({
  onChange: t,
  value: e,
  accept: n = "*/*",
  enableClick: s = !0,
  content: r,
  disabled: g = !1,
  allowMultiple: i
}) {
  return F(N, (m) => {
    const f = p.deriveProp(e ?? []), b = ae(!1), a = (c) => {
      c.preventDefault(), c.stopPropagation(), b.value = !0;
    }, h = (c) => {
      c.preventDefault(), c.stopPropagation(), (!c.currentTarget || !c.currentTarget.contains(c.relatedTarget)) && (b.value = !1);
    }, _ = (c) => {
      c.preventDefault(), c.stopPropagation(), b.value = !1;
      const d = Array.from(c.dataTransfer?.files || []);
      d.length > 0 && (f.value = d, t(d, "dragdrop"));
    }, u = (c) => {
      p.get(s) && c.currentTarget.querySelector(
        'input[type="file"]'
      )?.click();
    };
    let x = null;
    const y = () => {
      if (x == null) return;
      const c = Array.from(x.files ?? []);
      c.length > 0 && (f.value = c, t(c, "click")), x.value = "";
    }, D = (c) => {
      p.get(s) && (c.key === "Enter" || c.key === " ") && (c.preventDefault(), u(c));
    };
    return v.div(
      l.role("button"),
      l.tabindex(
        p.map(s, (c) => c ? 0 : -1)
      ),
      l.style("position: relative;"),
      $.dragover(a),
      $.dragleave(h),
      $.drop(_),
      $.click(u),
      $.keydown(D),
      // Hidden file input
      v.input(
        l.type("file"),
        l.disabled(g),
        l.accept(n),
        l.multiple(i),
        l.style(
          "position: absolute; left: -9999px; opacity: 0; pointer-events: none;"
        ),
        $.change(y),
        te((c) => (x = c, f.on((d) => {
          const I = globalThis.DataTransfer;
          if (I != null) {
            const z = new I();
            d.forEach((V) => z.items.add(V)), c.files = z.files;
          }
        }), T))
      ),
      // Screen reader instructions
      G.label(oe(m.$.dropZoneInstructions)(s)),
      // Content
      r({ files: f, clear: () => f.value = [], change: f.set })
    );
  });
}
function Qe(t, e) {
  return t.length === e.length && t.every((n, s) => n === e[s]);
}
function Ke(t, e) {
  const n = ["bc-segmented-input", `bc-segmented-input--size-${t}`];
  return e && n.push("bc-segmented-input--disabled"), n.join(" ");
}
function $t({
  options: t,
  value: e,
  onChange: n,
  size: s = "md",
  disabled: r = !1
}, ...g) {
  const i = Pe(t).map(([m, f]) => ({
    key: m,
    label: f
  }));
  return te(() => {
    const m = Object.fromEntries(
      i.map((b, a) => [b.key, a])
    ), f = ae(
      i.map(() => ({ left: 0, width: 0 })),
      Qe
    );
    return v.div(
      l.class(
        B(
          s,
          r
        )(
          (b, a) => Ke(b ?? "md", a ?? !1)
        )
      ),
      v.div(
        l.class("bc-segmented-input__container"),
        v.div(
          l.class("bc-segmented-input__indicator"),
          we.width(
            B(
              e,
              f
            )((b, a) => {
              const { width: h } = a[m[b] ?? 0];
              return `${h}px`;
            })
          ),
          we.left(
            B(
              e,
              f
            )((b, a) => {
              const { left: h } = a[m[b] ?? 0];
              return `${h}px`;
            })
          )
        ),
        // clickable buttons
        i.map(({ label: b, key: a }, h) => v.button(
          l.type("button"),
          $.click((_) => {
            _.preventDefault(), p.get(r) || n?.(a);
          }),
          l.disabled(r),
          l.class("bc-segmented-input__segment"),
          l.class(
            p.map(e, (_) => _ === a ? "bc-segmented-input__segment--active" : "bc-segmented-input__segment--inactive")
          ),
          Ze((_) => {
            function u() {
              f.update((y) => {
                const D = [...y];
                return D[h] = {
                  width: _.value.width,
                  left: _.value.localLeft
                }, D;
              });
            }
            const x = We(u);
            return ne(x, _.on(u));
          }),
          b
        ))
      ),
      ...g
    );
  });
}
function et(t) {
  const e = t.type.toLowerCase();
  return e.startsWith("image/") && (e.includes("jpeg") || e.includes("jpg") || e.includes("png") || e.includes("gif") || e.includes("webp") || e.includes("svg"));
}
function tt(t) {
  const e = t.type.toLowerCase();
  return e.startsWith("image/") ? "vscode-icons:file-type-image" : e.startsWith("video/") ? "vscode-icons:file-type-video" : e.startsWith("audio/") ? "vscode-icons:file-type-audio" : e.includes("pdf") ? "vscode-icons:file-type-pdf2" : e.includes("word") || e.includes("document") ? "vscode-icons:file-type-word" : e.includes("excel") || e.includes("spreadsheet") ? "vscode-icons:file-type-excel" : e.includes("powerpoint") || e.includes("presentation") ? "vscode-icons:file-type-powerpoint" : e.includes("zip") || e.includes("archive") ? "vscode-icons:file-type-zip" : e.includes("text") ? "vscode-icons:file-type-text" : e.includes("json") ? "vscode-icons:file-type-json-official" : e.includes("csv") ? "vscode-icons:file-type-csv" : e.includes("xml") ? "vscode-icons:file-type-xml" : e.includes("yaml") ? "vscode-icons:file-type-yaml-official" : "vscode-icons:file-type-binary";
}
function me(t) {
  return U(
    t.map(et),
    () => {
      const e = ae(null);
      return t.on((n) => {
        e.value && URL.revokeObjectURL(e.value);
        const s = URL.createObjectURL(n);
        e.value = s;
      }), v.div(
        ne(() => {
          e.value && URL.revokeObjectURL(e.value);
        }),
        l.class("bc-file-input__thumbnail-container"),
        v.img(
          l.src(e),
          l.alt(t.map((n) => n.name)),
          l.class("bc-file-input__thumbnail")
        )
      );
    },
    () => O({ icon: t.map(tt) })
  );
}
const Dt = (t, ...e) => {
  const {
    value: n = ae([]),
    accept: s = "*/*",
    maxFiles: r,
    maxFileSize: g,
    onChange: i,
    onBlur: m,
    disabled: f,
    hasError: b,
    mode: a = "default",
    showFileList: h = !0,
    ..._
  } = t, u = n, x = p.map(a, (C) => C === "input"), y = p.map(a, (C) => C === "compact"), D = (C) => {
    let o = C;
    if (r != null) {
      const w = p.get(r);
      o = o.slice(0, w);
    }
    if (g) {
      const w = p.get(g);
      o = o.filter((S) => S.size <= w);
    }
    i?.(o);
  }, c = (C) => {
    const w = u.value.filter((S, M) => M !== C);
    i?.(w);
  }, d = () => {
    i?.([]);
  }, I = ({
    files: C,
    clear: o,
    change: w
  }) => F(
    N,
    (S) => v.div(
      l.class("bc-file-input__drop-zone"),
      v.div(
        l.class(
          "bc-file-input__drop-zone-content bc-file-input__drop-zone-content--empty"
        ),
        O({ icon: "mdi:cloud-upload-outline", size: "xl" }),
        v.div(
          l.class("bc-file-input__drop-zone-text"),
          oe(S.$.filesInputInstructions)(
            r,
            g,
            S.$.fileSizeUnits.value
          )
        )
      )
    )
  ), z = ({
    files: C
  }) => F(
    N,
    (o) => v.div(
      l.class("bc-file-input__compact-drop-zone"),
      U(
        C.map((w) => w.length > 0),
        () => v.div(
          l.class("bc-file-input__compact-file-list"),
          K(C, (w, S) => {
            const M = S.index;
            return v.div(
              l.class("bc-file-input__compact-file-item"),
              v.div(
                l.class("bc-file-input__compact-file-icon"),
                me(w)
              ),
              v.div(
                l.class("bc-file-input__compact-file-info"),
                v.div(
                  l.class("bc-file-input__compact-file-name"),
                  l.title(w.$.name),
                  w.$.name
                ),
                v.div(
                  l.class("bc-file-input__compact-file-meta"),
                  B(
                    w.$.size,
                    o.$.fileSizeUnits
                  )((k, A) => $e(k, { units: A })),
                  " • ",
                  B(
                    w.$.type,
                    o.$.unknownType
                  )((k, A) => k || A)
                )
              ),
              ce(
                {
                  size: "sm",
                  label: o.$.removeFile,
                  disabled: f,
                  onClick: () => c(M)
                },
                l.class("bc-file-input__compact-remove-button")
              )
            );
          })
        ),
        () => v.div(
          l.class("bc-file-input__compact-placeholder"),
          O({ icon: "mdi:cloud-upload-outline", size: "lg" }),
          v.div(
            l.class("bc-file-input__compact-placeholder-text"),
            oe(o.$.filesInputInstructions)(
              r,
              g,
              o.$.fileSizeUnits.value
            )
          )
        )
      )
    )
  ), V = ({
    files: C
  }) => F(
    N,
    (o) => v.div(
      l.class("bc-file-input__compact-input"),
      U(
        C.map((w) => w.length > 0),
        () => v.span(
          l.class("bc-file-input__compact-value"),
          K(
            C,
            (w) => v.span(
              l.class("bc-file-input__compact-value-item"),
              me(w),
              v.span(
                l.class("bc-file-input__compact-value-item-name"),
                w.$.name
              )
            )
          )
        ),
        () => v.span(
          l.class("bc-file-input__compact-placeholder"),
          O({ icon: "mdi:cloud-upload-outline", size: "md" }),
          " ",
          oe(o.$.filesInputInstructions)(
            r,
            g,
            o.$.fileSizeUnits.value
          )
        )
      )
    )
  );
  return F(
    N,
    (C) => W(
      {
        baseContainer: p.map(x, (o) => !o),
        disabled: f,
        hasError: b,
        after: U(
          x,
          () => U(
            u.map(({ length: o }) => o > 0),
            () => ce(
              {
                size: "sm",
                label: C.$.clearAllFiles,
                disabled: f,
                onClick: d
              },
              l.class("bc-file-input__compact-clear")
            )
          )
        ),
        ..._,
        input: U(
          x,
          () => v.div(
            l.class("bc-file-input bc-file-input--input"),
            de({
              value: u,
              accept: s,
              enableClick: !0,
              allowMultiple: p.map(r ?? 1 / 0, (o) => o > 1),
              disabled: f,
              onChange: D,
              content: V
            })
          ),
          () => U(
            y,
            () => v.div(
              l.class("bc-file-input bc-file-input--compact"),
              de({
                value: u,
                accept: s,
                enableClick: !0,
                allowMultiple: p.map(r ?? 1 / 0, (o) => o > 1),
                disabled: f,
                onChange: D,
                content: z
              })
            ),
            () => v.div(
              l.class("bc-file-input"),
              de({
                value: u,
                accept: s,
                enableClick: !0,
                allowMultiple: p.map(r ?? 1 / 0, (o) => o > 1),
                disabled: f,
                onChange: D,
                content: I
              }),
              U(
                h,
                () => Oe(
                  u,
                  () => E(
                    v.div(
                      l.class("bc-file-input__file-list"),
                      K(u, (o, w) => {
                        const S = w.index;
                        return v.div(
                          l.class("bc-file-input__file-item"),
                          v.div(
                            l.class("bc-file-input__file-icon"),
                            me(o)
                          ),
                          v.div(
                            l.class("bc-file-input__file-info"),
                            v.div(
                              l.class("bc-file-input__file-name"),
                              l.title(o.$.name),
                              o.$.name
                            ),
                            v.div(
                              l.class("bc-file-input__file-meta"),
                              B(
                                o.$.size,
                                C.$.fileSizeUnits
                              )(
                                (M, k) => $e(M, { units: k })
                              ),
                              " • ",
                              B(
                                o.$.type,
                                C.$.unknownType
                              )((M, k) => M || k)
                            )
                          ),
                          ce(
                            {
                              size: "sm",
                              label: C.$.removeFile,
                              disabled: f,
                              onClick: () => c(S)
                            },
                            l.class("bc-file-input__remove-button")
                          )
                        );
                      })
                    ),
                    U(
                      u.map(({ length: o }) => o > 1),
                      () => v.div(
                        l.class(
                          "bc-file-input__clear-all-button-container"
                        ),
                        v.button(
                          l.type("button"),
                          l.class("bc-file-input__clear-all-button"),
                          l.disabled(f),
                          C.$.clearAllFiles,
                          $.click((o) => {
                            o.preventDefault(), o.stopPropagation(), d();
                          })
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      },
      ...e
    )
  );
}, ve = "$$tts-exp-", nt = (t, e) => te((n) => {
  const s = `${ve}${t}`;
  return ne(p.on(e, (r) => Reflect.set(n, s, r)));
}), It = (t, e) => {
  const n = `${ve}${t}`;
  return (s) => {
    e(Reflect.get(s.target, n));
  };
}, lt = (t, e) => {
  const n = `${ve}${t}`;
  return (s) => {
    const r = s.target, g = r.selectedIndex, i = r.options[g];
    e(Reflect.get(i, n));
  };
};
function re(...t) {
  return v.div(l.class("bc-group"), ...t);
}
const Be = (t, e, n) => Ne(
  t,
  (s) => Re(s, {
    value: (r) => {
      const g = B(
        r,
        n
      )((i, m) => e(i.value, m));
      return v.option(
        l.selected(g),
        nt("value", r.$.value),
        r.$.label
      );
    },
    group: (r) => v.optgroup(
      l.label(r.$.group),
      K(
        r.$.options,
        (g) => Be(
          g,
          e,
          n
        )
      )
    ),
    break: () => v.hr()
  })
), st = (t) => {
  const {
    value: e,
    onBlur: n,
    onChange: s,
    options: r,
    unselectedLabel: g,
    equality: i = (b, a) => b === a,
    after: m
  } = t;
  let f;
  return W(
    {
      ...t,
      after: E(
        He({
          icon: "ph:caret-down-bold",
          color: "neutral",
          size: "sm"
        }),
        m
      ),
      input: v.select(
        te((b) => {
          f = b;
          const a = new MutationObserver((h) => {
            const { removedNodes: _ } = h[0];
            _.length > 0 && (f.selectedIndex = 0);
          });
          return a.observe(b, { childList: !0 }), ne(() => a.disconnect());
        }),
        Y(t),
        l.class("bc-native-select bc-input"),
        F(
          N,
          (b) => v.option(
            l.hidden("hidden"),
            Fe(g, b.$.selectOne)
          )
        ),
        K(r, (b) => Be(b, i, e)),
        n != null ? $.blur(n) : T,
        s != null ? $.change(lt("value", (b) => s(b))) : T
      )
    },
    $.click(() => {
      if (f?.focus(), typeof f?.showPicker == "function")
        try {
          f.showPicker();
        } catch {
        }
    })
  );
};
function rt(t) {
  const { controller: e, onChange: n, onBlur: s, ...r } = t;
  return st({
    ...r,
    value: e.signal,
    onChange: Ge(e, n),
    onBlur: qe(e, s)
  });
}
function zt(t) {
  return Ae({
    ...t,
    content: rt(t)
  });
}
function it(t, e, n) {
  const s = t.length.map((r) => r);
  return E(
    je(
      s,
      (r) => {
        const g = t.item(r.index), i = [];
        return E(
          ne(() => {
            i.forEach((m) => m());
          }),
          e({
            list: t,
            item: g,
            position: r,
            remove: () => t.removeAt(r.index),
            move: (m) => {
              switch (m) {
                case "up":
                  if (r.index === 0) return;
                  t.move(r.index, r.index - 1);
                  break;
                case "down":
                  if (r.index === t.length.value - 1) return;
                  t.move(r.index, r.index + 1);
                  break;
                case "first":
                  t.move(r.index, 0);
                  break;
                case "last":
                  t.move(r.index, t.length.value - 1);
              }
            },
            canMove: (m) => {
              const f = (() => {
                switch (m) {
                  case "up":
                    return _e(r.index > 0);
                  case "down":
                    return t.length.map((b) => r.index < b - 1);
                }
              })();
              return i.push(() => f.dispose()), f;
            },
            cannotMove: (m) => {
              const f = (() => {
                switch (m) {
                  case "up":
                    return _e(r.index === 0);
                  case "down":
                    return t.length.map((b) => r.index === b - 1);
                }
              })();
              return i.push(() => f.dispose()), f;
            }
          })
        );
      },
      n
    )
  );
}
const Ie = {
  9: { pattern: /^[0-9]$/ },
  A: { pattern: /^[A-Za-z]$/, transform: (t) => t.toUpperCase() },
  "*": { pattern: /^.$/ }
}, ot = (t) => t instanceof RegExp;
function Ve(t, e, n) {
  if (t == null) return [];
  const s = n ? { ...Ie, ...e } : e ?? Ie, r = (i, m) => {
    const f = s[m];
    f ? i.push({ type: "pattern", name: m, ...f }) : i.push({ type: "literal", char: m });
  }, g = [];
  if (typeof t == "string") {
    for (const i of t) r(g, i);
    return g;
  }
  for (const i of t)
    if (typeof i == "string")
      if (i.length <= 1) r(g, i);
      else for (const m of i) r(g, m);
    else ot(i) ? g.push({ type: "pattern", pattern: i }) : typeof i == "object" && i && g.push(i);
  return g;
}
function ct(t, e) {
  return (n) => {
    switch (t) {
      case "digits":
        return /[0-9]/.test(n);
      case "letters":
        return /[A-Za-z]/.test(n);
      case "alphanumeric":
        return /[A-Za-z0-9]/.test(n);
      case "custom":
        return e?.(n) ?? !0;
      default:
        return !0;
    }
  };
}
function ze(t, e, n, s, r, g) {
  const i = {
    raw: t,
    previousConformed: e,
    cursor: r ?? t.length,
    completed: !1
  }, m = s.definitions ?? {}, f = typeof n == "function" ? n(t, i) : n, b = Ve(
    f,
    m,
    s.useDefaultDefinitions ?? !0
  ), a = ct(s.allowMode, s.allow), h = /* @__PURE__ */ new Set();
  for (const k of b) k.type === "literal" && h.add(k.char);
  if (s.prefix) for (const k of s.prefix) h.add(k);
  if (s.suffix) for (const k of s.suffix) h.add(k);
  const _ = Array.from(t).filter((k) => a(k) && !h.has(k));
  if (_.length === 0) return { value: "", cursor: 0, completed: !1 };
  const u = [], x = [];
  let y = 0, D = 0, c = 0, d = -1;
  for (const k of b) {
    if (k.type === "literal") {
      u.push(k.char), x.push({ kind: "literal", filled: !0 });
      continue;
    }
    D += k.optional ? 0 : 1;
    const A = _[y];
    if (A == null)
      break;
    if (k.type === "any") {
      c++, u.push(k.transform ? k.transform(A) : A), x.push({ kind: "slot", filled: !0 }), d = x.length - 1, y++;
      continue;
    }
    if (k.type === "pattern")
      if (k.pattern.test(A)) {
        c++;
        const R = k.transform ? k.transform(A) : A;
        u.push(R), x.push({ kind: "slot", filled: !0 }), d = x.length - 1, y++;
      } else {
        y++;
        continue;
      }
  }
  const I = u.join(""), z = (s.prefix ?? "") + I + (s.suffix ?? "");
  let C = (s.prefix ?? "").length;
  if (d >= 0) {
    let k = d + 1;
    if ((g?.policy ?? "smart") !== "sticky")
      for (; k < x.length && x[k].kind === "literal"; ) k++;
    C += k;
  }
  const o = s.completion?.mode === "min" ? (s.completion.minChars ?? 0) <= c : s.completion?.mode === "custom" ? !!s.completion.isComplete?.(z) : D > 0 && c >= D, w = s.pipe?.(z, { ...i, completed: o });
  let S, M = C;
  return w === !1 ? (S = e, M = e.length) : typeof w == "string" ? (S = w, M = w.length) : typeof w == "object" && w ? (S = w.value, M = w.cursor ?? w.value.length) : S = z, { value: S, cursor: M, completed: o };
}
function at(t, e) {
  const n = e?.strategy ?? "none";
  return n === "custom" && e?.unmask ? e.unmask(t) : n === "strip" ? t.replace(/[^A-Za-z0-9]/g, "") : t;
}
const Le = (t) => {
  const {
    value: e,
    onBlur: n,
    onChange: s,
    onInput: r,
    onAccept: g,
    onComplete: i,
    mask: m,
    definitions: f,
    useDefaultDefinitions: b,
    extraLiterals: a,
    prefix: h,
    suffix: _,
    autofix: u,
    pipe: x,
    completion: y,
    unmask: D,
    allowMode: c,
    allow: d,
    placeholder: I,
    placeholderOptions: z
  } = t, V = B(
    e,
    m,
    f,
    b,
    a,
    h,
    _,
    u,
    y,
    D,
    c,
    I,
    z
  )((o, w, S, M, k, A, R, J, X, q, Z, se, P) => w ? ze(o ?? "", "", w, {
    definitions: S ?? {},
    useDefaultDefinitions: M ?? !0,
    extraLiterals: k ?? [],
    autofix: J ?? "none",
    completion: X ?? { mode: "mask" },
    pipe: x ?? ((L) => L),
    unmask: q ?? { strategy: "none" },
    allowMode: Z ?? "all",
    allow: d,
    prefix: A,
    suffix: R
  }).value : o ?? ""), C = (o, w) => {
    const S = o.value ?? "", M = p.get(e) ?? "", k = m != null ? p.get(m) : null, A = f != null ? p.get(f) : void 0, R = b != null ? p.get(b) : void 0, J = a != null ? p.get(a) : void 0, X = u != null ? p.get(u) : void 0, q = y != null ? p.get(y) : void 0, Z = D != null ? p.get(D) : void 0, se = c != null ? p.get(c) : void 0, P = h != null ? p.get(h) : void 0, L = _ != null ? p.get(_) : void 0, {
      value: H,
      cursor: ue,
      completed: xe
    } = k ? ze(
      S,
      M,
      k,
      {
        definitions: A ?? {},
        useDefaultDefinitions: R ?? !0,
        extraLiterals: J ?? [],
        autofix: X ?? "none",
        completion: q ?? { mode: "mask" },
        pipe: x ?? ((Ee) => Ee),
        unmask: Z ?? { strategy: "none" },
        allowMode: se ?? "all",
        allow: d,
        prefix: P,
        suffix: L
      },
      o.selectionStart ?? S.length,
      t.cursor ? p.get(t.cursor) : void 0
    ) : { value: S, cursor: S.length, completed: !0 };
    if (H !== S) {
      o.value = H;
      try {
        o.setSelectionRange(ue, ue);
      } catch {
      }
    }
    const ye = at(H, Z);
    g?.({
      raw: ye,
      conformed: H,
      completed: xe,
      cursor: ue
    }), w === "input" ? r?.(H) : (s?.(H), xe && i?.({ raw: ye, conformed: H }));
  };
  return E(
    W({
      ...t,
      input: le.text(
        Y(t),
        l.value(V),
        l.class("bc-input"),
        n != null ? $.blur(n) : T,
        te(
          (o) => o instanceof HTMLInputElement ? E(
            $.input(() => C(o, "input")),
            $.change(() => C(o, "change")),
            $.keydown((w) => {
              if (w.key !== "Backspace" || !(t.cursor ? p.get(t.cursor)?.backspaceRubberBand ?? !0 : !0)) return;
              const M = o.selectionStart ?? 0, k = o.selectionEnd ?? M;
              if (M !== k || M <= 0) return;
              const A = o.value ?? "", R = m != null ? p.get(m) : null;
              if (!R) return;
              const J = f != null ? p.get(f) : void 0, X = b != null ? p.get(b) : !0, q = h != null ? p.get(h) : void 0, Z = _ != null ? p.get(_) : void 0, se = Ve(
                typeof R == "function" ? R(A, {
                  raw: A,
                  previousConformed: A,
                  cursor: M,
                  completed: !1
                }) : R,
                J ?? {},
                X ?? !0
              ), P = /* @__PURE__ */ new Set();
              for (const L of se)
                L.type === "literal" && P.add(L.char);
              if (q) for (const L of q) P.add(L);
              if (Z) for (const L of Z) P.add(L);
              if (P.has(A[M - 1])) {
                let L = M - 1;
                for (; L >= 0 && P.has(A[L]); ) L--;
                L >= 0 && (w.preventDefault(), w.stopPropagation(), o.value = A.slice(0, L) + A.slice(L + 1), C(o, "input"));
              }
            })
          ) : T
        )
      )
    })
  );
};
function Ue(t, e, n) {
  const s = p.map(t, (i) => i != null), r = B(
    s,
    e ?? !1
  )((i, m) => !i || m), g = ge.clearValue;
  return v.button(
    l.type("button"),
    l.class("bc-input-container__reset"),
    G.label(g),
    l.title(g),
    l.disabled(r),
    O({ icon: "mdi:close", size: "sm" }),
    $.click((i) => {
      i.stopPropagation(), n?.(null);
    })
  );
}
const Tt = (t) => {
  const { value: e, onBlur: n, onChange: s, onInput: r, rows: g } = t;
  return W({
    baseContainer: !0,
    ...t,
    input: v.textarea(
      l.class(
        B(t.size ?? "md")(
          (i) => Ye(
            !1,
            i ?? "md"
          )
        )
      ),
      Y(t),
      l.rows(g ?? 3),
      l.value(e),
      l.class("bc-input"),
      n != null ? $.blur(j(n)) : T,
      s != null ? $.change(j(s)) : T,
      r != null ? $.input(j(r)) : T
    )
  });
}, St = (t) => {
  const { value: e, step: n, min: s, max: r, onBlur: g, onChange: i, onInput: m, after: f } = t, b = (_) => {
    const u = s != null ? p.get(s) : void 0, x = r != null ? p.get(r) : void 0;
    return u != null && _ < u ? u : x != null && _ > x ? x : _;
  }, a = n != null ? F(N, (_) => {
    const u = B(
      e,
      s
    )((c, d) => d == null ? !0 : (c ?? 0) > d), x = B(
      e,
      r
    )((c, d) => d == null ? !0 : (c ?? 0) < d), y = (c) => {
      const d = p.get(e) ?? 0, I = p.get(n), z = c?.shiftKey ? 10 : 1, V = d - I * z, C = s != null ? p.get(s) : void 0;
      if (C != null && V < C)
        return;
      const o = b(V);
      o !== d && i && i(o);
    }, D = (c) => {
      const d = p.get(e) ?? 0, I = p.get(n), z = c?.shiftKey ? 10 : 1, V = d + I * z, C = r != null ? p.get(r) : void 0;
      if (C != null && V > C)
        return;
      const o = b(V);
      o !== d && i && i(o);
    };
    return ee(
      l.class("bc-number-input-steppers"),
      // Increment second
      v.button(
        l.type("button"),
        l.class(
          "bc-button bc-number-input-steppers-button bc-number-input-steppers-button--increment"
        ),
        l.disabled(
          B(
            x,
            t.disabled ?? !1
          )((c, d) => !c || d)
        ),
        $.click((c) => D(c)),
        G.label(_.$.incrementValue),
        O({ icon: "line-md:plus", size: "xs" })
      ),
      // Decrement first (matches tests expecting first button to be decrement)
      v.button(
        l.type("button"),
        l.class(
          "bc-button bc-number-input-steppers-button bc-number-input-steppers-button--decrement"
        ),
        l.disabled(
          B(
            u,
            t.disabled ?? !1
          )((c, d) => !c || d)
        ),
        $.click((c) => y(c)),
        G.label(_.$.decrementValue),
        O({ icon: "line-md:minus", size: "xs" })
      )
    );
  }) : null, h = f != null && a != null ? E(a, f) : f ?? a;
  return W({
    ...t,
    input: le.number(
      s != null ? l.min(s) : T,
      r != null ? l.max(r) : T,
      Y(t),
      l.valueAsNumber(e),
      l.step(n),
      l.class("bc-input bc-number-input"),
      g != null ? $.blur(j(g)) : T,
      i != null ? $.change(ke(i)) : T,
      m != null ? $.input(ke(m)) : T,
      // Add wheel event support when step is defined
      n != null ? $.wheel((_) => {
        _.preventDefault();
        const u = p.get(e) ?? 0, x = p.get(n), y = _.shiftKey ? 10 : 1, D = _.deltaY < 0 ? x * y : -x * y, c = b(u + D);
        c !== u && i && i(c);
      }) : T
    ),
    after: h
  });
}, Te = (t) => {
  if (t == null || t === "") return null;
  const e = Number(t);
  return Number.isNaN(e) ? null : e;
}, Mt = (t) => {
  const { value: e, step: n, min: s, max: r, onBlur: g, onChange: i, onInput: m, after: f } = t, b = (u) => {
    const x = s != null ? p.get(s) : void 0, y = r != null ? p.get(r) : void 0;
    return x != null && u < x ? x : y != null && u > y ? y : u;
  }, a = (() => {
    if (n == null) return null;
    const u = B(
      e,
      s
    )((d, I) => {
      const z = d ?? 0;
      return I == null ? !0 : z > I;
    }), x = B(
      e,
      r
    )((d, I) => {
      const z = d ?? 0;
      return I == null ? !0 : z < I;
    }), y = (d) => {
      const I = p.get(e) ?? 0, z = p.get(n), V = d?.shiftKey ? 10 : 1, C = I - z * V, o = s != null ? p.get(s) : void 0;
      if (o != null && C < o) return;
      const w = b(C);
      w !== I && i && i(w);
    }, D = (d) => {
      const I = p.get(e) ?? 0, z = p.get(n), V = d?.shiftKey ? 10 : 1, C = I + z * V, o = r != null ? p.get(r) : void 0;
      if (o != null && C > o) return;
      const w = b(C);
      w !== I && i && i(w);
    };
    return ((d, I) => ee(
      l.class("bc-number-input-steppers"),
      v.button(
        l.type("button"),
        l.class(
          "bc-button bc-number-input-steppers-button bc-number-input-steppers-button--increment"
        ),
        l.disabled(
          B(
            x,
            t.disabled ?? !1
          )((z, V) => !z || V)
        ),
        $.click((z) => D(z)),
        G.label(d),
        O({ icon: "line-md:plus", size: "xs" })
      ),
      v.button(
        l.type("button"),
        l.class(
          "bc-button bc-number-input-steppers-button bc-number-input-steppers-button--decrement"
        ),
        l.disabled(
          B(
            u,
            t.disabled ?? !1
          )((z, V) => !z || V)
        ),
        $.click((z) => y(z)),
        G.label(I),
        O({ icon: "line-md:minus", size: "xs" })
      )
    ))(
      ge.incrementValue,
      ge.decrementValue
    );
  })(), h = Ue(
    e,
    t.disabled,
    i ?? m
  ), _ = f != null && a != null ? E(a, h, f) : f != null ? E(h, f) : a != null ? E(a, h) : h;
  return W({
    ...t,
    input: le.number(
      // min/max attributes and reactive watchers (no forced correction)
      s != null ? l.min(s) : T,
      r != null ? l.max(r) : T,
      Y(t),
      // Represent null as empty string so the field can be cleared
      l.value(p.map(e, (u) => u == null ? "" : String(u))),
      l.step(n),
      l.class("bc-input bc-number-input"),
      g != null ? $.blur(j(g)) : T,
      i != null ? $.change(
        j((u) => {
          const x = Te(u);
          i(x);
        })
      ) : T,
      m != null ? $.input(
        j((u) => {
          const x = Te(u);
          m(x);
        })
      ) : T,
      // Wheel support when step is defined
      n != null ? $.wheel((u) => {
        u.preventDefault();
        const x = p.get(e) ?? 0, y = p.get(n), D = u.shiftKey ? 10 : 1, c = u.deltaY < 0 ? y * D : -y * D, d = b(x + c);
        d !== x && i && i(d);
      }) : T
    ),
    after: _
  });
}, At = (t) => {
  const e = {
    type: "pattern",
    pattern: /[0-9A-Fa-f]/,
    transform: (s) => s.toLowerCase()
  };
  return Le({
    ...t,
    mask: [
      e,
      e,
      e,
      e,
      e,
      e,
      e,
      e,
      "-",
      e,
      e,
      e,
      e,
      "-",
      e,
      e,
      e,
      e,
      "-",
      e,
      e,
      e,
      e,
      "-",
      e,
      e,
      e,
      e,
      e,
      e,
      e,
      e,
      e,
      e,
      e,
      e
    ],
    // Sensible default placeholder; can be overridden via options.placeholder
    placeholder: t.placeholder ?? "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  });
};
let be = null;
async function he() {
  const t = globalThis;
  return t.Temporal ? t.Temporal : (be || (be = import("./index.esm-ChUrm4xR.js").then((e) => {
    const n = e.Temporal;
    return t.Temporal || (t.Temporal = n), n;
  })), be);
}
const ut = (t, e) => e ? Ce(he, {
  then: t,
  pending: e.pending,
  error: e.error
}) : Ce(he, t), pt = /^P(\d+([YMWD]|$)){0,4}(T(\d+([HMS]|$)){0,3})?$/i, ft = /^P(?:(\d+Y)?(\d+M)?(\d+W)?(\d+D)?)(T(\d+H)?(\d+M)?(\d+S)?)?$/i;
function dt(t) {
  return {
    mask: null,
    allowMode: "custom",
    allow: (e) => /[0-9ptwdhms]/i.test(e),
    pipe: (e) => {
      const n = e.toUpperCase();
      return n.length === 0 ? n : !n.startsWith("P") || !pt.test(n) ? !1 : n;
    },
    completion: {
      mode: "custom",
      isComplete: (e) => {
        const n = e.toUpperCase();
        if (!ft.test(n)) return !1;
        try {
          return t(n), !0;
        } catch {
          return !1;
        }
      }
    }
  };
}
const Se = (t, e) => {
  if (t == null) return null;
  try {
    return t.Duration.from(e);
  } catch {
    return null;
  }
}, Bt = (t) => {
  const { value: e, onChange: n, onInput: s, after: r, disabled: g, onBlur: i } = t, m = () => {
    const a = Ue(e, g, n ?? s);
    return r != null ? E(a, r) : a;
  }, f = t.placeholder != null ? T : l.placeholder("P0DT0H0M0S");
  return ut(
    (a) => Le({
      ...t,
      value: p.map(e, (h) => h?.toString() ?? ""),
      onChange: n ? (h) => n(h === "" ? null : a.Duration.from(h)) : void 0,
      onInput: void 0,
      ...dt(a.Duration.from),
      placeholder: "P0DT0H0M0S",
      after: m()
    }),
    { pending: () => {
      const a = (h) => (_) => {
        const x = _.currentTarget?.value ?? "";
        if (x === "") {
          h(null);
          return;
        }
        const y = globalThis.Temporal, D = Se(y, x);
        if (D != null) {
          h(D);
          return;
        }
        he().then((c) => {
          const d = Se(c, x);
          d != null && h(d);
        }).catch(() => {
        });
      };
      return W({
        ...t,
        input: le.text(
          Y(t),
          l.value(p.map(e, (h) => h?.toString() ?? "")),
          l.class("bc-input"),
          f,
          i != null ? $.blur(() => i()) : T,
          n != null ? $.change(a(n)) : T,
          s != null ? $.input(a(s)) : T
        ),
        after: m()
      });
    } }
  );
}, Vt = (t) => {
  const { value: e, onBlur: n, onChange: s, onInput: r } = t;
  return W({
    ...t,
    input: le.url(
      Y(t),
      l.value(e),
      l.class("bc-input"),
      n != null ? $.blur(j(n)) : T,
      s != null ? $.change(j(s)) : T,
      r != null ? $.input(j(r)) : T
    )
  });
}, mt = (t) => {
  const {
    controller: e,
    element: n,
    separator: s,
    showMove: r = !0,
    showRemove: g = !0,
    showAdd: i = !0,
    createItem: m,
    addLabel: f,
    controlsLayout: b = "aside",
    removeDisabled: a,
    addDisabled: h
  } = t, _ = p.toSignal(b).map((y) => y === "aside"), u = (y) => {
    const D = U(
      r ?? !1,
      () => v.div(
        l.class("bc-group--align-center"),
        l.class(
          _.map(
            (d) => d ? "bc-group--direction-column bc-group--gap-1" : "bc-group--direction-row bc-group--gap-1"
          )
        ),
        pe(
          {
            size: "xs",
            roundedness: "full",
            variant: "text",
            onClick: () => y.move("up"),
            disabled: y.cannotMove("up")
          },
          F(
            N,
            (d) => O({
              size: "xs",
              icon: "line-md:arrow-up",
              title: d.$.incrementValue
            })
          )
        ),
        pe(
          {
            size: "xs",
            roundedness: "full",
            variant: "text",
            onClick: () => y.move("down"),
            disabled: y.cannotMove("down")
          },
          F(
            N,
            (d) => O({
              size: "xs",
              icon: "line-md:arrow-down",
              title: d.$.decrementValue
            })
          )
        )
      )
    ), c = U(
      g,
      () => F(
        N,
        (d) => ce({
          size: "xs",
          // Use a lowercase label to satisfy tests that query with [aria-label*="remove"]
          label: p.map(d.$.removeItem, (I) => I.toLowerCase()),
          color: "danger",
          disabled: a,
          onClick: y.remove
        })
      )
    );
    return (d) => U(
      _,
      () => re(
        l.class("bc-group--gap-1 bc-group--align-center"),
        ee(l.class("bc-stack--grow"), d),
        ee(
          l.class("bc-stack--align-center"),
          U(
            e.signal.map((I) => I.length > 1),
            () => D
          ),
          c
        )
      ),
      () => ee(
        l.class("bc-stack--gap-2"),
        d,
        re(
          l.class("bc-group--gap-2 bc-group--justify-between"),
          U(
            e.signal.map((I) => I.length > 1),
            () => D,
            () => v.div()
          ),
          c
        )
      )
    );
  }, x = U(
    B(i, m)((y, D) => y && D != null),
    () => re(
      l.class(
        "bc-group--gap-2 bc-group--align-center bc-group--justify-center"
      ),
      pe(
        {
          size: "sm",
          variant: "filled",
          onClick: () => e.push(m()),
          disabled: B(
            e.disabled,
            h ?? !1
          )(
            (y, D) => y || D
          )
        },
        F(
          N,
          (y) => re(
            l.class("bc-group--gap-2"),
            O({ icon: "line-md:plus" }),
            f ?? y.$.addLabel
          )
        )
      )
    )
  );
  return E(
    it(
      e,
      (y) => u(y)(n(y)),
      s
    ),
    x
  );
}, Lt = (t, ...e) => {
  const {
    controller: n,
    element: s,
    separator: r,
    showMove: g,
    showRemove: i,
    showAdd: m,
    createItem: f,
    addLabel: b,
    controlsLayout: a,
    removeDisabled: h,
    addDisabled: _,
    ...u
  } = t;
  return Ae(
    {
      ...u,
      content: mt({
        controller: n,
        element: s,
        separator: r,
        showMove: g,
        showRemove: i,
        showAdd: m,
        createItem: f,
        addLabel: b,
        controlsLayout: a,
        removeDisabled: h,
        addDisabled: _
      })
    },
    ...e
  );
};
class Ut extends fe {
  branches;
  activeBranch;
  #t;
  #e = /* @__PURE__ */ new Map();
  constructor(e, n, s, r, g, i, m = Q) {
    super(e, n, s, r, g, m), this.branches = i;
    const f = (a) => {
      for (const h of i)
        if (h.detect(a))
          return h.key;
      return i[0]?.key ?? "unknown";
    };
    this.activeBranch = s.map(f, Q);
    const b = (a) => {
      if (this.#e.has(a))
        return this.#e.get(a);
      const h = i.find((u) => u.key === a);
      if (!h)
        throw new Error(`Unknown branch: ${a}`);
      const _ = new fe(
        [...e, a],
        (u) => {
          this.change(u);
        },
        this.signal.map(
          (u) => h.detect(u) ? u : h.defaultValue(),
          m
        ),
        r.map(De([a])),
        {
          disabled: this.disabled,
          validationMode: this.parent.validationMode
        },
        m
      );
      return this.#e.set(a, _), _;
    };
    this.#t = this.activeBranch.map(
      (a) => b(a),
      Q
    ), this.onDispose(() => {
      for (const a of this.#e.values())
        a.dispose();
      this.#e.clear(), this.activeBranch.dispose(), this.#t.dispose();
    });
  }
  /**
   * Get the controller for the currently active branch
   */
  get activeController() {
    return p.get(this.#t);
  }
  /**
   * Get a controller for a specific branch
   */
  getBranchController(e) {
    const n = this.branches.find((r) => r.key === e);
    if (!n)
      throw new Error(`Unknown branch: ${e}`);
    if (this.#e.has(e))
      return this.#e.get(e);
    const s = new fe(
      [...this.path, e],
      (r) => {
        this.change(r);
      },
      this.signal.map(
        (r) => n.detect(r) ? r : n.defaultValue(),
        Q
      ),
      this.status.map(De([e])),
      {
        disabled: this.disabled,
        validationMode: this.parent.validationMode
      },
      Q
    );
    return this.#e.set(e, s), s;
  }
  /**
   * Switch to a different branch
   */
  switchToBranch(e, n = !1) {
    const s = this.branches.find((i) => i.key === e);
    if (!s)
      throw new Error(`Unknown branch: ${e}`);
    const r = p.get(this.signal);
    if (s.detect(r))
      return !0;
    if (s.convert) {
      const i = s.convert(r);
      if (i.ok)
        return this.change(i.value), !0;
    }
    if (n && typeof window == "object" && typeof window.confirm == "function" && !window.confirm(
      "Changing type will clear the current value. Continue?"
    ))
      return !1;
    const g = s.defaultValue();
    return this.change(g), !0;
  }
  /**
   * Get the current active branch definition
   */
  get activeBranchDefinition() {
    const e = p.get(this.activeBranch);
    return this.branches.find((n) => n.key === e);
  }
}
function Et(t) {
  return t.transform(
    (e) => e ?? null,
    (e) => e ?? void 0
  );
}
function Ot(t) {
  return t.transform(
    (e) => e ?? "",
    (e) => e === "" ? void 0 : e
  );
}
function Ft(t) {
  return t.transform(
    (e) => e ?? void 0,
    (e) => e ?? null
  );
}
function ie(t) {
  return t !== null && typeof t == "object" && !Array.isArray(t) && Object.prototype.toString.call(t) === "[object Object]";
}
function bt(t, e) {
  if (e == null)
    return Me(t);
  if (t == null)
    return e;
  if (ie(t) && ie(e)) {
    const n = { ...e };
    for (const s of Object.keys(t))
      n[s] === void 0 ? n[s] = Me(t[s]) : ie(t[s]) && ie(n[s]) && (n[s] = bt(t[s], n[s]));
    return n;
  }
  return e;
}
function Me(t) {
  return typeof structuredClone == "function" ? structuredClone(t) : JSON.parse(JSON.stringify(t));
}
export {
  Ct as $,
  mt as B,
  nt as E,
  Dt as F,
  re as G,
  Lt as L,
  Le as M,
  Ue as N,
  $t as S,
  Tt as T,
  At as U,
  ut as W,
  kt as _,
  Vt as a,
  Mt as b,
  St as c,
  dt as d,
  Bt as e,
  st as f,
  _t as g,
  zt as h,
  Ut as i,
  bt as j,
  de as k,
  Et as l,
  Ft as m,
  it as n,
  rt as o,
  It as p,
  lt as q,
  he as r,
  Ot as t
};
