import { Value as s, 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 z, N as j, W as A, d as Y } from "./deep-merge-BRqRzEQs.js";
import { B as q, I as M } from "./translations-BGblCUBj.js";
import { S as G } from "./stack-BJgsPJ9A.js";
import { I as L } from "./input-container-DhUiLmXE.js";
import { C as Q } from "./text-input-BZmAB3_o.js";
const un = (n) => {
  const {
    value: t,
    onInput: m,
    onChange: r,
    ...u
  } = n;
  return X({
    ...u,
    maxFiles: 1,
    value: s.map(t, (a) => a == null ? [] : [a]),
    onChange: (a) => {
      r?.(a[0]);
    },
    onInput: (a) => {
      m?.(a[0]);
    }
  });
}, W = (n) => {
  try {
    return BigInt(n);
  } catch {
    return null;
  }
}, an = (n) => {
  const { value: t, step: m, min: r, max: u, onChange: a, onInput: f, after: I } = n, h = (p) => {
    const e = r != null ? s.get(r) : void 0, c = u != null ? s.get(u) : void 0;
    return e != null && p < e ? e : c != null && p > c ? c : p;
  }, g = m != null ? H(q, (p) => {
    const e = S(
      t,
      r
    )((i, l) => l == null ? !0 : (i ?? 0n) > l), c = S(
      t,
      u
    )((i, l) => l == null ? !0 : (i ?? 0n) < l), V = (i, l) => {
      const d = s.get(t) ?? 0n, v = s.get(m), w = l?.shiftKey ? 10n : 1n, y = d + v * w * i, C = r != null ? s.get(r) : void 0, D = u != null ? s.get(u) : void 0;
      if (i < 0n && C != null && y < C || i > 0n && D != null && y > D) return;
      const P = h(y);
      P !== d && a && a(P);
    };
    return G(
      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
          )((i, l) => !i || l)
        ),
        T.click((i) => V(1n, i)),
        F.label(p.$.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(
            e,
            n.disabled ?? !1
          )((i, l) => !i || l)
        ),
        T.click((i) => V(-1n, i)),
        F.label(p.$.decrementValue),
        M({ icon: "line-md:minus", size: "xs" })
      )
    );
  }) : null, b = I != null && g != null ? B(g, I) : I ?? g, O = a ? (p) => {
    const e = W(p);
    e != null && a(h(e));
  } : void 0, $ = f ? (p) => {
    const e = W(p);
    e != null && f(h(e));
  } : void 0;
  return z({
    ...n,
    value: s.map(t, (p) => p.toString()),
    onChange: O,
    onInput: $,
    after: b,
    mask: null,
    allowMode: "digits",
    classes: {
      ...n.classes,
      input: n.classes?.input ? s.map(n.classes.input, (p) => `bc-number-input ${p}`) : "bc-number-input"
    }
  });
}, E = (n) => {
  if (n == null || n === "") return null;
  try {
    return BigInt(n);
  } catch {
    return null;
  }
}, rn = (n) => {
  const { value: t, step: m, min: r, max: u, onChange: a, onInput: f, after: I } = n, h = (e) => {
    const c = r != null ? s.get(r) : void 0, V = u != null ? s.get(u) : void 0;
    return c != null && e < c ? c : V != null && e > V ? V : e;
  }, g = m != null ? H(q, (e) => {
    const c = S(
      t,
      r
    )((l, d) => {
      const v = l ?? 0n;
      return d == null ? !0 : v > d;
    }), V = S(
      t,
      u
    )((l, d) => {
      const v = l ?? 0n;
      return d == null ? !0 : v < d;
    }), i = (l, d) => {
      const v = s.get(t) ?? 0n, w = s.get(m), y = d?.shiftKey ? 10n : 1n, C = v + w * y * l, D = r != null ? s.get(r) : void 0, P = u != null ? s.get(u) : void 0;
      if (l < 0n && D != null && C < D || l > 0n && P != null && C > P) return;
      const U = h(C);
      U !== v && a && a(U);
    };
    return G(
      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
          )((l, d) => !l || d)
        ),
        T.click((l) => i(1n, l)),
        F.label(e.$.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
          )((l, d) => !l || d)
        ),
        T.click((l) => i(-1n, l)),
        F.label(e.$.decrementValue),
        M({ icon: "line-md:minus", size: "xs" })
      )
    );
  }) : null, b = j(
    t,
    n.disabled,
    a ?? f
  ), O = I != null && g != null ? B(g, b, I) : I != null ? B(b, I) : g != null ? B(g, b) : b, $ = a ? (e) => {
    const c = E(e);
    a(c === null ? null : h(c));
  } : void 0, p = f ? (e) => {
    const c = E(e);
    f(c === null ? null : h(c));
  } : void 0;
  return z({
    ...n,
    value: s.map(t, (e) => e == null ? "" : e.toString()),
    onChange: $,
    onInput: p,
    after: O,
    mask: null,
    allowMode: "digits",
    classes: {
      ...n.classes,
      input: n.classes?.input ? s.map(n.classes.input, (e) => `bc-number-input ${e}`) : "bc-number-input"
    }
  });
};
function J(n) {
  return (t) => {
    const { value: m, onBlur: r, onChange: u } = t;
    return A(
      (a) => L({
        ...t,
        input: R[n.inputType](
          Q(t),
          o.value(s.map(m, n.valueToString)),
          o.class("bc-input"),
          r != null ? T.blur(x(r)) : N,
          u != null ? T.change(x((f) => u(n.parseValue(a, f)))) : N
        )
      })
    );
  };
}
function K(n) {
  return (t) => {
    const { value: m, onBlur: r, onChange: u, onInput: a, after: f, disabled: I } = t, h = j(m, I, u ?? a);
    return A(
      (g) => L({
        ...t,
        input: R[n.inputType](
          Q(t),
          o.value(
            s.map(m, (b) => b == null ? "" : n.valueToString(b))
          ),
          o.class("bc-input"),
          r != null ? T.blur(x(r)) : N,
          u != null ? T.change(
            x(
              (b) => u(b === "" ? null : n.parseValue(g, b))
            )
          ) : N,
          a != null ? T.input(
            x(
              (b) => a(b === "" ? null : n.parseValue(g, b))
            )
          ) : N
        ),
        after: f != null ? B(h, f) : h
      })
    );
  };
}
const sn = J({
  inputType: "date",
  valueToString: (n) => n.toString(),
  parseValue: (n, t) => n.PlainDate.from(t)
}), on = K({
  inputType: "date",
  valueToString: (n) => n.toString(),
  parseValue: (n, t) => n.PlainDate.from(t)
}), cn = J({
  inputType: "time",
  valueToString: (n) => n.toString(),
  parseValue: (n, t) => n.PlainTime.from(t)
}), pn = K({
  inputType: "time",
  valueToString: (n) => n.toString(),
  parseValue: (n, t) => n.PlainTime.from(t)
}), mn = J({
  inputType: "datetime-local",
  valueToString: (n) => n.toJSON(),
  parseValue: (n, t) => n.PlainDateTime.from(t)
}), bn = K({
  inputType: "datetime-local",
  valueToString: (n) => n.toJSON(),
  parseValue: (n, t) => n.PlainDateTime.from(t)
}), dn = (n) => {
  const { value: t, onChange: m } = n;
  return A(
    (r) => z({
      ...n,
      value: s.map(t, (u) => u.toString()),
      onChange: m ? (u) => m(r.Duration.from(u)) : void 0,
      onInput: void 0,
      ...Y(r.Duration.from),
      placeholder: "P0DT0H0M0S"
    })
  );
};
export {
  an as B,
  dn as D,
  un as F,
  rn as N,
  cn as P,
  pn as a,
  bn as b,
  mn as c,
  on as d,
  sn as e,
  J as f,
  K as g
};
