import { Value as i, Use as H, computedOf as S, html as k, attr as o, on as T, aria as F, Fragment as B, input as R, Empty as N, emitValue as x } from "@tempots/dom";
import { F as X, M as A, N as j, W as $, d as Y } from "./deep-merge-Bsqkvp9-.js";
import { a as q, c as M, b as G, C as L } from "./translations-BEMKy6-W.js";
import { S as Q } from "./use-form-DMiCxK26.js";
const en = (n) => {
  const {
    value: t,
    onInput: p,
    onChange: r,
    ...l
  } = n;
  return X({
    ...l,
    maxFiles: 1,
    value: i.map(t, (u) => u == null ? [] : [u]),
    onChange: (u) => {
      r?.(u[0]);
    },
    onInput: (u) => {
      p?.(u[0]);
    }
  });
}, W = (n) => {
  try {
    return BigInt(n);
  } catch {
    return null;
  }
}, ln = (n) => {
  const { value: t, step: p, min: r, max: l, onChange: u, onInput: f, after: I } = n, h = (b) => {
    const a = r != null ? i.get(r) : void 0, c = l != null ? i.get(l) : void 0;
    return a != null && b < a ? a : c != null && b > c ? c : b;
  }, g = p != null ? H(q, (b) => {
    const a = S(
      t,
      r
    )((s, e) => e == null ? !0 : (s ?? 0n) > e), c = S(
      t,
      l
    )((s, e) => e == null ? !0 : (s ?? 0n) < e), V = (s, e) => {
      const d = i.get(t) ?? 0n, v = i.get(p), z = e?.shiftKey ? 10n : 1n, y = d + v * z * s, C = r != null ? i.get(r) : void 0, D = l != null ? i.get(l) : void 0;
      if (s < 0n && C != null && y < C || s > 0n && D != null && y > D) return;
      const P = h(y);
      P !== d && u && u(P);
    };
    return Q(
      o.class("bc-number-input-steppers"),
      k.button(
        o.type("button"),
        o.class(
          "bc-button bc-number-input-steppers-button bc-number-input-steppers-button--increment"
        ),
        o.disabled(
          S(
            c,
            n.disabled ?? !1
          )((s, e) => !s || e)
        ),
        T.click((s) => V(1n, s)),
        F.label(b.$.incrementValue),
        M({ icon: "line-md:plus", size: "xs" })
      ),
      k.button(
        o.type("button"),
        o.class(
          "bc-button bc-number-input-steppers-button bc-number-input-steppers-button--decrement"
        ),
        o.disabled(
          S(
            a,
            n.disabled ?? !1
          )((s, e) => !s || e)
        ),
        T.click((s) => V(-1n, s)),
        F.label(b.$.decrementValue),
        M({ icon: "line-md:minus", size: "xs" })
      )
    );
  }) : null, m = I != null && g != null ? B(g, I) : I ?? g, O = u ? (b) => {
    const a = W(b);
    a != null && u(h(a));
  } : void 0, w = f ? (b) => {
    const a = W(b);
    a != null && f(h(a));
  } : void 0;
  return A({
    ...n,
    value: i.map(t, (b) => b.toString()),
    onChange: O,
    onInput: w,
    after: m,
    mask: null,
    allowMode: "digits",
    class: "bc-number-input"
  });
}, E = (n) => {
  if (n == null || n === "") return null;
  try {
    return BigInt(n);
  } catch {
    return null;
  }
}, un = (n) => {
  const { value: t, step: p, min: r, max: l, onChange: u, onInput: f, after: I } = n, h = (a) => {
    const c = r != null ? i.get(r) : void 0, V = l != null ? i.get(l) : void 0;
    return c != null && a < c ? c : V != null && a > V ? V : a;
  }, g = p != null ? H(q, (a) => {
    const c = S(
      t,
      r
    )((e, d) => {
      const v = e ?? 0n;
      return d == null ? !0 : v > d;
    }), V = S(
      t,
      l
    )((e, d) => {
      const v = e ?? 0n;
      return d == null ? !0 : v < d;
    }), s = (e, d) => {
      const v = i.get(t) ?? 0n, z = i.get(p), y = d?.shiftKey ? 10n : 1n, C = v + z * y * e, D = r != null ? i.get(r) : void 0, P = l != null ? i.get(l) : void 0;
      if (e < 0n && D != null && C < D || e > 0n && P != null && C > P) return;
      const U = h(C);
      U !== v && u && u(U);
    };
    return Q(
      o.class("bc-number-input-steppers"),
      o.type("button"),
      k.button(
        o.class(
          "bc-button bc-number-input-steppers-button bc-number-input-steppers-button--increment"
        ),
        o.disabled(
          S(
            V,
            n.disabled ?? !1
          )((e, d) => !e || d)
        ),
        T.click((e) => s(1n, e)),
        F.label(a.$.incrementValue),
        M({ icon: "line-md:plus", size: "xs" })
      ),
      k.button(
        o.type("button"),
        o.class(
          "bc-button bc-number-input-steppers-button bc-number-input-steppers-button--decrement"
        ),
        o.disabled(
          S(
            c,
            n.disabled ?? !1
          )((e, d) => !e || d)
        ),
        T.click((e) => s(-1n, e)),
        F.label(a.$.decrementValue),
        M({ icon: "line-md:minus", size: "xs" })
      )
    );
  }) : null, m = j(
    t,
    n.disabled,
    u ?? f
  ), O = I != null && g != null ? B(g, m, I) : I != null ? B(m, I) : g != null ? B(g, m) : m, w = u ? (a) => {
    const c = E(a);
    u(c === null ? null : h(c));
  } : void 0, b = f ? (a) => {
    const c = E(a);
    f(c === null ? null : h(c));
  } : void 0;
  return A({
    ...n,
    value: i.map(t, (a) => a == null ? "" : a.toString()),
    onChange: w,
    onInput: b,
    after: O,
    mask: null,
    allowMode: "digits",
    class: "bc-number-input"
  });
};
function J(n) {
  return (t) => {
    const { value: p, onBlur: r, onChange: l } = t;
    return $(
      (u) => G({
        ...t,
        input: R[n.inputType](
          L(t),
          o.value(i.map(p, n.valueToString)),
          o.class("bc-input"),
          r != null ? T.blur(x(r)) : N,
          l != null ? T.change(x((f) => l(n.parseValue(u, f)))) : N
        )
      })
    );
  };
}
function K(n) {
  return (t) => {
    const { value: p, onBlur: r, onChange: l, onInput: u, after: f, disabled: I } = t, h = j(p, I, l ?? u);
    return $(
      (g) => G({
        ...t,
        input: R[n.inputType](
          L(t),
          o.value(
            i.map(p, (m) => m == null ? "" : n.valueToString(m))
          ),
          o.class("bc-input"),
          r != null ? T.blur(x(r)) : N,
          l != null ? T.change(
            x(
              (m) => l(m === "" ? null : n.parseValue(g, m))
            )
          ) : N,
          u != null ? T.input(
            x(
              (m) => u(m === "" ? null : n.parseValue(g, m))
            )
          ) : N
        ),
        after: f != null ? B(h, f) : h
      })
    );
  };
}
const an = J({
  inputType: "date",
  valueToString: (n) => n.toString(),
  parseValue: (n, t) => n.PlainDate.from(t)
}), rn = K({
  inputType: "date",
  valueToString: (n) => n.toString(),
  parseValue: (n, t) => n.PlainDate.from(t)
}), sn = J({
  inputType: "time",
  valueToString: (n) => n.toString(),
  parseValue: (n, t) => n.PlainTime.from(t)
}), on = K({
  inputType: "time",
  valueToString: (n) => n.toString(),
  parseValue: (n, t) => n.PlainTime.from(t)
}), cn = J({
  inputType: "datetime-local",
  valueToString: (n) => n.toJSON(),
  parseValue: (n, t) => n.PlainDateTime.from(t)
}), pn = K({
  inputType: "datetime-local",
  valueToString: (n) => n.toJSON(),
  parseValue: (n, t) => n.PlainDateTime.from(t)
}), mn = (n) => {
  const { value: t, onChange: p } = n;
  return $(
    (r) => A({
      ...n,
      value: i.map(t, (l) => l.toString()),
      onChange: p ? (l) => p(r.Duration.from(l)) : void 0,
      onInput: void 0,
      ...Y(r.Duration.from),
      placeholder: "P0DT0H0M0S"
    })
  );
};
export {
  ln as B,
  mn as D,
  en as F,
  un as N,
  sn as P,
  on as a,
  pn as b,
  cn as c,
  rn as d,
  an as e,
  J as f,
  K as g
};
