import { Use as q, coalesce as Q, aria as x, attr as c, html as f, on as D, Value as S, Empty as C, computedOf as w, When as V, dataAttr as R, input as ne, emitValue as F, prop as I, Fragment as N, TextNode as re, emitValueAsNumber as ie, Unless as ae, Ensure as le } from "@tempots/dom";
import { a as z, B as oe, I as B, b as W, c as ce, C as X } from "./translations-BUTBIDsS.js";
const K = /* @__PURE__ */ new Map();
function H(e) {
  const s = K.get(e) ?? 0;
  return K.set(e, s + 1), `${e}-${s}`;
}
const y = {
  /**
   * Creates a loading state.
   * @param previousValue - The previous value.
   * @returns A loading state.
   * @public
   */
  notAsked: { type: "NotAsked" },
  /**
   * Creates a loading state.
   * @param previousValue - The previous value.
   * @returns A loading state.
   * @public
   */
  loading(e = void 0) {
    return { type: "Loading", previousValue: e };
  },
  /**
   * Creates a successful state.
   * @param value - The value.
   * @returns A successful state.
   * @public
   */
  success(e) {
    return { type: "AsyncSuccess", value: e };
  },
  /**
   * Creates a failure state.
   * @param error - The error.
   * @returns A failure state.
   * @public
   */
  failure(e) {
    return { type: "AsyncFailure", error: e };
  },
  /**
   * Checks if the result is a success.
   * @param r - The result.
   * @returns `true` if the result is a success; otherwise, `false`.
   * @public
   */
  isSuccess(e) {
    return e.type === "AsyncSuccess";
  },
  /**
   * Checks if the result is a failure.
   * @param r - The result.
   * @returns `true` if the result is a failure; otherwise, `false`.
   * @public
   */
  isFailure(e) {
    return e.type === "AsyncFailure";
  },
  /**
   * Checks if the result is a not-asked.
   * @param r - The result.
   * @returns `true` if the result is not-asked; otherwise, `false`.
   * @public
   */
  isNotAsked(e) {
    return e.type === "NotAsked";
  },
  /**
   * Checks if the result is a loading.
   * @param r - The result.
   * @returns `true` if the result is loading; otherwise, `false`.
   * @public
   */
  isLoading(e) {
    return e.type === "Loading";
  },
  /**
   * Gets the value if the result is a success; otherwise, returns the alternative value.
   * @param r - The result.
   * @param alt - The alternative value.
   * @returns The value if the result is a success; otherwise, the alternative value.
   * @public
   */
  getOrElse(e, s) {
    return y.isSuccess(e) ? e.value : s;
  },
  /**
   * Gets the value if the result is a success; otherwise, returns the value from the alternative function.
   * @param r - The result.
   * @param altf - The alternative function.
   * @returns The value if the result is a success; otherwise, the value from the alternative
   * @public
   * function.
   */
  getOrElseLazy(e, s) {
    return y.isSuccess(e) ? e.value : s();
  },
  /**
   * Gets the value if the result is a success; otherwise, returns `null`.
   * @param r - The result.
   * @returns The value if the result is a success; otherwise, `null`.
   * @public
   */
  getOrNull(e) {
    return y.isSuccess(e) ? e.value : null;
  },
  /**
   * Gets the value if the result is a success; otherwise, returns `undefined`.
   * @param r - The result.
   * @returns The value if the result is a success; otherwise, `undefined`.
   * @public
   */
  getOrUndefined(e) {
    return y.isSuccess(e) ? e.value : void 0;
  },
  /**
   * Gets the value of a `AsyncResult` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
   * @param r - The `AsyncResult` to get the value from.
   * @returns The value of the `AsyncResult` if it is a `Success`.
   */
  getUnsafe: (e) => {
    if (y.isSuccess(e))
      return e.value;
    throw y.isFailure(e) ? e.error : new Error("Cannot get value from a not-asked or loading result");
  },
  /**
   * Based on the state of the result, it picks the appropriate function to call and returns the result.
   * @param success - The function to call if the result is a success.
   * @param failure - The function to call if the result is a failure.
   * @param loading - The function to call if the result is loading.
   * @param notAsked - The function to call if the result is not-asked.
   * @returns The result of calling the appropriate function based on the state of the result.
   * @public
   */
  match: (e, {
    success: s,
    failure: t,
    loading: n,
    notAsked: r = n
  }) => y.isSuccess(e) ? s(e.value) : y.isFailure(e) ? t(e.error) : y.isNotAsked(e) ? r() : n(e.previousValue),
  /**
   * When the result is a success, it applies the function to the value.
   *
   * @param r - The result.
   * @param apply - The function to apply.
   * @returns The result that was passed in.
   * @public
   */
  whenSuccess: (e, s) => (y.isSuccess(e) && s(e.value), e),
  /**
   * When the result is a failure, it applies the function to the error.
   *
   * @param r - The result.
   * @param apply - The function to apply.
   * @returns The result that was passed in.
   * @public
   */
  whenFailure: (e, s) => (y.isFailure(e) && s(e.error), e),
  /**
   * Compares two results for equality.
   * @param r1 - The first result.
   * @param r2 - The second result.
   * @param options - The options to use for comparison. By default, uses strict equality.
   * @returns `true` if the results are equal, `false` otherwise.
   */
  equals: (e, s, t = {
    valueEquals: (n, r) => n === r,
    errorEquals: (n, r) => n === r
  }) => e.type === "AsyncSuccess" && s.type === "AsyncSuccess" ? t.valueEquals(e.value, s.value) : e.type === "AsyncFailure" && s.type === "AsyncFailure" ? t.errorEquals(e.error, s.error) : e.type === "Loading" && s.type === "Loading" ? t.valueEquals(e.previousValue, s.previousValue) : e.type === "NotAsked" && s.type === "NotAsked",
  /**
   * Combines multiple results into a single result.
   * @param results - The results to combine.
   * @returns A single result that is a success if all the input results are successes, otherwise a failure.
   */
  all: (e) => {
    const s = [];
    for (const t of e)
      if (y.isSuccess(t))
        s.push(t.value);
      else
        return t;
    return y.success(s);
  },
  /**
   * Converts a Promise to an AsyncResult.
   * @param p - The Promise to convert.
   * @returns A Promise that resolves to an AsyncResult.
   */
  ofPromise: async (e) => {
    try {
      const s = await e;
      return y.success(s);
    } catch (s) {
      return y.failure(s instanceof Error ? s : new Error(String(s)));
    }
  }
}, $ = (e, s) => e === s || e !== e && s !== s, _ = {
  /**
   * Creates a valid `Validation`.
   * @returns A `Validation` that is `Valid`.
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  valid: { type: "valid" },
  /**
   * Creates an invalid `Validation`.
   * @param error - The error associated with the invalid value.
   * @returns A `Validation` that is `Invalid`.
   */
  invalid(e) {
    return { type: "invalid", error: e };
  },
  /**
   * Checks if a `Validation` is `Valid`.
   * @param r - The `Validation` to check.
   * @returns `true` if the `Validation` is `Valid`, otherwise `false`.
   */
  isValid(e) {
    return e.type === "valid";
  },
  /**
   * Checks if a `Validation` is `Invalid`.
   * @param r - The `Validation` to check.
   * @returns `true` if the `Validation` is `Invalid`, otherwise `false`.
   */
  isInvalid(e) {
    return e.type === "invalid";
  },
  /**
   * Maps the value of a `Validation` to a new value.
   * @param r - The `Validation` to map.
   * @param valid - The mapping function for a valid value.
   * @param invalid - The mapping function for an invalid value.
   * @returns The mapped value.
   */
  match: (e, s, t) => _.isValid(e) ? s() : t(e.error),
  /**
   * Maps the value of a `Validation` to a new `Validation`.
   * @param validation - The `Validation` to map.
   * @param value - The value to map.
   * @returns A new `Validation` with the mapped value.
   */
  toResult: (e, s) => _.match(
    e,
    () => m.success(s),
    (t) => m.failure(t)
  ),
  /**
   * Execute a function when the `Validation` is valid.
   *
   * @param r - The `Validation` to check.
   * @param apply - The function to execute when the `Validation` is valid.
   * @returns The `Validation` object.
   */
  whenValid: (e, s) => (_.isValid(e) && s(), e),
  /**
   * Execute a function when the `Validation` is invalid.
   *
   * @param r - The `Validation` to check.
   * @param apply - The function to execute when the `Validation` is invalid.
   * @returns The `Validation` object.
   */
  whenInvalid: (e, s) => (_.isInvalid(e) && s(e.error), e)
}, m = {
  /**
   * Creates a successful `Result`.
   * @param value - The value to wrap in a `Success` type.
   * @returns A `Result` that is a `Success`.
   * @public
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  success(e) {
    return { type: "Success", value: e };
  },
  /**
   * Creates a failure `Result`.
   * @param error - The error to wrap in a `Failure` type.
   * @returns A `Result` that is a `Failure`.
   * @public
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  failure(e) {
    return { type: "Failure", error: e };
  },
  /**
   * Maps the value of a `Result` to a new value.
   * @param r - The `Result` to map.
   * @param f - The mapping function.
   * @returns A new `Result` with the mapped value.
   * @public
   */
  map: (e, s) => e.type === "Success" ? m.success(s(e.value)) : e,
  /**
   * Maps the value of a `Result` to a new `Result`.
   * @param r - The `Result` to map.
   * @param f - The mapping function.
   * @returns A new `Result` with the mapped value.
   * @public
   */
  flatMap: (e, s) => e.type === "Success" ? s(e.value) : e,
  /**
   * Converts a `Result` to an `AsyncResult`.
   * @param r - The `Result` to convert.
   * @returns An `AsyncResult` that is equivalent to the input `Result`.
   * @public
   */
  toAsync(e) {
    return m.match(
      e,
      (s) => y.success(s),
      (s) => y.failure(s)
    );
  },
  /**
   * Converts a `Result` to a `Validation`.
   * @param r - The `Result` to convert.
   * @returns A `Validation` that is equivalent to the input `Result`.
   * @public
   */
  toValidation(e) {
    return m.match(
      e,
      () => _.valid,
      (s) => _.invalid(s)
    );
  },
  /**
   * Checks if a `Result` is a success.
   * @param r - The `Result` to check.
   * @returns `true` if the `Result` is a `Success`, `false` otherwise.
   * @public
   */
  isSuccess(e) {
    return e.type === "Success";
  },
  /**
   * Checks if a `Result` is a failure.
   * @param r - The `Result` to check.
   * @returns `true` if the `Result` is a `Failure`, `false` otherwise.
   * @public
   */
  isFailure(e) {
    return e.type === "Failure";
  },
  /**
   * Gets the value of a `Result` if it is a `Success`, otherwise returns the provided default value.
   * @param r - The `Result` to get the value from.
   * @param alt - The default value to return if the `Result` is a `Failure`.
   * @returns The value of the `Result` if it is a `Success`, otherwise the default value.
   * @public
   */
  getOrElse(e, s) {
    return m.isSuccess(e) ? e.value : s;
  },
  /**
   * Gets the value of a `Result` if it is a `Success`, otherwise returns the result of the provided function.
   * @param r - The `Result` to get the value from.
   * @param altf - The function to call if the `Result` is a `Failure`.
   * @returns The value of the `Result` if it is a `Success`, otherwise the result of the function.
   * @public
   */
  getOrElseLazy(e, s) {
    return m.isSuccess(e) ? e.value : s();
  },
  /**
   * Gets the value of a `Result` if it is a `Success`, otherwise returns `null`.
   * @param r - The `Result` to get the value from.
   * @returns The value of the `Result` if it is a `Success`, otherwise `null`.
   * @public
   */
  getOrNull(e) {
    return m.isSuccess(e) ? e.value : null;
  },
  /**
   * Gets the value of a `Result` if it is a `Success`, otherwise returns `undefined`.
   * @param r - The `Result` to get the value from.
   * @returns The value of the `Result` if it is a `Success`, otherwise `undefined`.
   * @public
   */
  getOrUndefined(e) {
    return m.isSuccess(e) ? e.value : void 0;
  },
  /**
   * Gets the value of a `Result` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
   * @param r - The `Result` to get the value from.
   * @returns The value of the `Result` if it is a `Success`.
   */
  getUnsafe: (e) => {
    if (m.isSuccess(e))
      return e.value;
    throw e.error;
  },
  /**
   * Based on the state of the result, it picks the appropriate function to call and returns the result.
   * @param success - The function to call if the result is a success.
   * @param failure - The function to call if the result is a failure.
   * @returns The result of calling the appropriate function based on the state of the result.
   * @public
   */
  match: (e, s, t) => m.isSuccess(e) ? s(e.value) : t(e.error),
  /**
   * Calls the provided function if the result is a success.
   * @param apply - The function to call if the result is a success.
   * @returns A function that takes a `Result` and calls the provided function if the result is a success.
   * @public
   */
  whenSuccess: (e, s) => (m.isSuccess(e) && s(e.value), e),
  whenFailure: (e, s) => (m.isFailure(e) && s(e.error), e),
  /**
   * Combines two results into a single result.
   * @param r1 - The first result.
   * @param r2 - The second result.
   * @param combineV - The function to combine two values.
   * @param combineE - The function to combine two errors.
   * @returns The combined result.
   * @public
   */
  combine: (e, s, t, n) => m.match(
    e,
    (r) => m.match(
      s,
      (i) => m.success(t(r, i)),
      (i) => m.failure(i)
    ),
    (r) => m.match(
      s,
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      (i) => m.failure(r),
      (i) => m.failure(n(r, i))
    )
  ),
  /**
   * Compares two results for equality.
   * @param r1 - The first result.
   * @param r2 - The second result.
   * @param options - The options to use for comparison. By default, uses strict equality.
   * @returns `true` if the results are equal, `false` otherwise.
   */
  equals: (e, s, t = {
    valueEquals: (n, r) => n === r,
    errorEquals: (n, r) => n === r
  }) => e.type === "Success" && s.type === "Success" ? t.valueEquals(e.value, s.value) : e.type === "Failure" && s.type === "Failure" ? t.errorEquals(e.error, s.error) : !1,
  /**
   * Combines multiple results into a single result.
   * @param results - The results to combine.
   * @returns A single result that is a success if all the input results are successes, otherwise a failure.
   */
  all: (e) => {
    const s = [];
    for (const t of e)
      if (m.isSuccess(t))
        s.push(t.value);
      else
        return t;
    return m.success(s);
  }
};
function ue({
  size: e = "sm",
  icon: s = "line-md:close",
  disabled: t,
  roundedness: n = "full",
  color: r = "base",
  onClick: i,
  label: l
}, ...a) {
  return q(z, (o) => {
    const p = Q(l, o.$.closeModal);
    return oe(
      {
        variant: "text",
        size: e,
        roundedness: n,
        disabled: t,
        color: r,
        onClick: i
      },
      c.title(p),
      x.label(p),
      ...a,
      B({ icon: s, size: e ?? "sm" })
    );
  });
}
function U(e) {
  return `bc-label bc-label--${e}`;
}
const Oe = (...e) => f.span(c.class(U("emphasis")), ...e), he = (...e) => f.span(c.class(U("default")), ...e), de = (...e) => f.span(c.class(U("muted")), ...e), Me = (...e) => f.span(c.class(U("danger")), ...e), Fe = (e) => {
  const {
    value: s,
    onBlur: t,
    onChange: n,
    placeholder: r,
    disabled: i,
    id: l,
    checkedIcon: a,
    uncheckedIcon: o,
    iconSize: p = "lg"
  } = e, h = l ?? H("checkbox"), b = `${h}-label`, k = () => {
    if (S.get(i ?? !1)) return;
    const u = S.get(s);
    n?.(!u);
  }, g = (u) => {
    S.get(i ?? !1) || (u.key === " " || u.key === "Enter") && (u.preventDefault(), k());
  };
  return W(
    {
      baseContainer: !0,
      growInput: !1,
      ...e,
      input: f.span(
        c.class("bc-checkbox-input"),
        f.span(
          c.class("bc-checkbox-input__checkbox"),
          c.class(
            S.map(
              s,
              (u) => u ? "bc-checkbox-input__checkbox--checked" : "bc-checkbox-input__checkbox--unchecked"
            )
          ),
          c.class(
            S.map(
              i ?? !1,
              (u) => u ? "bc-checkbox-input__checkbox--disabled" : ""
            )
          ),
          c.id(h),
          c.role("checkbox"),
          c.tabindex(
            S.map(
              i ?? !1,
              (u) => u ? -1 : 0
            )
          ),
          x.checked(s),
          x.disabled(i),
          r != null ? x.labelledby(b) : C,
          D.keydown(g),
          t != null ? D.blur(t) : C,
          B({
            icon: w(
              s,
              a,
              o
            )(
              (u, d, v) => u ? d ?? "akar-icons/check-box-fill" : v ?? "akar-icons/box"
            ),
            accessibility: "decorative",
            size: p
          })
        ),
        r != null ? f.label(
          c.class("bc-checkbox-input__label"),
          c.id(b),
          c.for(h),
          de(r)
        ) : C
      )
    },
    D.click(k)
  );
}, pe = f.span(
  c.class("bc-input-wrapper__required"),
  " *"
);
function fe(e) {
  const s = ["bc-input-wrapper"];
  return e !== "vertical" && s.push(`bc-input-wrapper--${e}`), s.join(" ");
}
function be(e, s) {
  const t = ["bc-input-wrapper__label-text"];
  return e ? t.push("bc-input-wrapper__label-text--error") : s ? t.push("bc-input-wrapper__label-text--disabled") : t.push("bc-input-wrapper__label-text--default"), t.join(" ");
}
function me(e, s) {
  if (e === "horizontal-fixed" && s != null)
    return `--input-wrapper-label-width: ${s}`;
}
const Y = ({
  fullWidth: e = !1,
  required: s,
  label: t,
  labelChildren: n,
  context: r,
  description: i,
  content: l,
  error: a,
  labelFor: o,
  hasError: p,
  disabled: h,
  layout: b,
  labelWidth: k
}, ...g) => {
  const u = p ?? a != null, d = h ?? !1, v = b ?? "vertical", T = H("input-wrapper"), A = i ? `${T}-description` : void 0, P = a != null ? `${T}-error` : void 0, L = w(v)((E) => E !== "vertical"), te = w(
    v,
    k ?? void 0
  )((E, M) => me(E, M));
  return f.div(
    c.class(S.map(v, (E) => fe(E))),
    c.class(
      S.map(
        e,
        (E) => E ? "bc-input-wrapper--full-width" : ""
      )
    ),
    c.style(te),
    t != null || r != null ? f.div(
      c.class("bc-input-wrapper__header"),
      f.div(
        c.class("bc-input-wrapper__label-section"),
        f.label(
          c.class("bc-input-wrapper__label"),
          o != null ? c.for(o) : C,
          f.span(
            c.class(
              w(
                u,
                d
              )(
                (E, M) => be(
                  E ?? !1,
                  M ?? !1
                )
              )
            ),
            t
          ),
          t != null && s ? pe : C
        ),
        // Show description under label when horizontal
        V(
          w(
            L,
            i
          )((E, M) => E && M != null),
          () => f.div(
            c.class(
              "bc-input-wrapper__description bc-input-wrapper__description--under-label"
            ),
            c.id(A),
            i
          )
        )
      ),
      r != null ? he(r) : C,
      n
    ) : C,
    f.div(
      c.class("bc-input-wrapper__content"),
      // Add data attributes to help inputs inherit accessibility information
      [A, P].filter(Boolean).length > 0 ? R.describedby(
        [A, P].filter(Boolean).join(" ")
      ) : C,
      s ? R.required("true") : C,
      V(u, () => R.invalid("true")),
      l
    ),
    // Show description at bottom only when not horizontal
    V(
      w(L, i)((E, M) => !E && M != null),
      () => f.div(
        c.class("bc-input-wrapper__description"),
        c.id(A),
        i
      )
    ),
    V(
      u,
      () => f.div(
        c.class("bc-input-wrapper__error"),
        c.id(P),
        x.live("polite"),
        // Announce errors to screen readers
        c.role("alert"),
        // Mark as alert for immediate attention
        a
      )
    ),
    ...g
  );
};
function $e(...e) {
  return f.div(c.class("bc-stack"), ...e);
}
const xe = (e) => {
  const s = {
    name: "email",
    autocomplete: "email",
    ...e
  }, {
    value: t,
    before: n,
    onBlur: r,
    onChange: i,
    onInput: l,
    placeholder: a
  } = s, o = n ?? ce({
    icon: "line-md:email",
    size: e.size,
    color: "neutral"
  });
  return q(
    z,
    (p) => W({
      ...e,
      before: o,
      input: ne.email(
        X(s),
        c.placeholder(Q(a, p.$.emailPlaceholderText)),
        c.value(t),
        c.class("bc-input"),
        r != null ? D.blur(F(r)) : C,
        i != null ? D.change(F(i)) : C,
        l != null ? D.input(F(l)) : C
      )
    })
  );
}, Ne = (e) => {
  const {
    value: s,
    onBlur: t,
    onChange: n,
    onInput: r,
    before: i,
    after: l,
    hasError: a,
    disabled: o,
    autocomplete: p,
    placeholder: h,
    ...b
  } = e, k = {
    name: "password",
    disabled: o,
    ...b
  }, g = I(!0), u = w(
    g,
    p
  )((d, v) => d ? v ?? "current-password" : "off");
  return q(z, (d) => {
    const v = w(
      d.$.passwordPlaceholderText,
      g,
      h
    )((A, P, L) => P ? "•••••••••••••••" : L ?? A), T = f.button(
      c.type("button"),
      c.class("bc-input-container__password-toggle"),
      x.label(d.$.togglePasswordVisibility),
      D.click(() => g.update((A) => !A)),
      V(
        g,
        () => B({ icon: "line-md:watch" }),
        () => B({ icon: "line-md:watch-off" })
      )
    );
    return W({
      before: i,
      disabled: o,
      hasError: a,
      input: f.input(
        X({
          ...k,
          autocomplete: u,
          placeholder: v
        }),
        V(
          g,
          () => N(c.type("password")),
          () => N(c.type("text"))
        ),
        c.class("bc-input"),
        c.value(s),
        t != null ? D.blur(F(t)) : C,
        n != null ? D.change(F(n)) : C,
        r != null ? D.input(F(r)) : C
      ),
      after: l != null ? N(T, l) : T
    });
  });
}, ge = (
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  (e, s) => () => {
    e.markTouched(), s?.();
  }
), G = (e, s) => (t) => {
  e.change(t), s?.(t);
};
function Z(e, s) {
  const { controller: t, onBlur: n, onChange: r, id: i, triggerOn: l, ...a } = s;
  return e({
    id: i ?? t.name,
    disabled: t.disabled,
    value: t.signal,
    hasError: t.errorVisible,
    name: t.name,
    ...a,
    onInput: l === "input" ? G(t, r) : void 0,
    onChange: l !== "input" ? G(t, r) : void 0,
    onBlur: ge(t, n)
  });
}
function Pe(e, { id: s, labelFor: t, ...n }, ...r) {
  const i = s ?? n.controller.name ?? H("control"), l = t ?? i;
  return Y(
    {
      ...n,
      hasError: n.controller.errorVisible,
      error: re(n.controller.error.map((a) => a ?? "")),
      labelFor: l,
      content: Z(
        (a) => e({ ...a, id: i }),
        n
      )
    },
    ...r
  );
}
function ve(e, s) {
  const { toInput: t, fromInput: n, controller: r, ...i } = s, l = r.transform(t, n);
  return Z(e, {
    ...i,
    controller: l
  });
}
function Be(e, {
  id: s,
  labelFor: t,
  ...n
}, ...r) {
  const i = s ?? n.controller.name ?? H("control");
  return Y(
    {
      ...n,
      labelFor: t ?? i,
      content: ve(e, {
        ...n,
        id: i
      })
    },
    ...r
  );
}
function Le(e) {
  return e.split(".").map((t) => {
    const n = t.match(/^\[(\d+)\]$/);
    return n ? Number(n[1]) : t;
  });
}
function ye(e) {
  return typeof e == "number" ? `[${e}]` : `.${e}`;
}
function we(e) {
  if (e.length === 0) return "";
  const [s, ...t] = e;
  return [
    typeof s == "number" ? `[${s}]` : s,
    ...t.map(ye)
  ].join("");
}
function j(e) {
  return function(t) {
    if (t.type === "valid") return t;
    let n = t.error;
    for (const r of e)
      if (n = n?.dependencies?.[r], n == null) return _.valid;
    return _.invalid(n);
  };
}
class O {
  path;
  change;
  signal;
  status;
  error;
  hasError;
  touched;
  errorVisible;
  dirty;
  dependencyErrors;
  #e = {
    disabled: I(!1),
    touched: I(!1)
  };
  #t;
  #s = I(void 0);
  parent;
  disabled;
  #n = [];
  disabledOrHasErrors;
  constructor(s, t, n, r, i, l = $) {
    this.path = s, this.change = t, this.signal = n, this.status = r, this.#t = l, this.#s.set(n.value), this.error = r.map(
      (a) => a?.type === "invalid" ? a.error?.message : void 0
    ), this.hasError = this.error.map((a) => a != null), this.touched = this.#e.touched, i.validationMode ? this.errorVisible = w(
      this.hasError,
      this.touched,
      i.validationMode
    )((a, o, p) => p === "continuous" ? !!a : !!a && !!o) : this.errorVisible = w(
      this.hasError,
      this.touched
    )((a, o) => !!a && !!o), this.dirty = w(
      this.signal,
      this.#s
    )((a, o) => !this.#t(a, o)), this.dependencyErrors = r.map(
      (a) => a?.type === "invalid" ? a.error?.dependencies : void 0
    ), this.parent = i, this.disabled = w(
      this.#e.disabled,
      i.disabled
    )((a, o) => a || o), this.disabledOrHasErrors = w(
      this.disabled,
      this.hasError
    )((a, o) => a || o), this.onDispose(() => {
      this.#e.disabled.dispose(), this.#e.touched.dispose(), this.disabled.dispose(), this.error.dispose(), this.errorVisible.dispose(), this.dirty.dispose(), this.#s.dispose(), this.dependencyErrors.dispose(), this.disabledOrHasErrors.dispose();
    });
  }
  get name() {
    return we(this.path);
  }
  onDispose = (s) => {
    this.#n.push(s);
  };
  dispose = () => {
    for (const s of this.#n)
      try {
        s();
      } catch (t) {
        console.error("Error in dispose callback:", t);
      }
    this.#n.length = 0;
  };
  setDisabled = (s) => {
    this.#e.disabled.set(s);
  };
  disable = () => this.setDisabled(!0);
  enable = () => this.setDisabled(!1);
  markTouched = () => {
    this.#e.touched.set(!0);
  };
  resetTouched = () => {
    this.#e.touched.set(!1);
  };
  markPristine = () => {
    this.#s.set(this.signal.value);
  };
  reset = () => {
    this.change(this.#s.value);
  };
  array = (s = $) => new Se(
    this.path,
    this.change,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    this.signal,
    this.status,
    this.parent,
    s
  );
  object = (s = $) => new ke(
    this.path,
    this.change,
    this.signal,
    this.status,
    this.parent,
    s
  );
  transform = (s, t, n = [], r = $) => new O(
    [...this.path, ...n],
    (i) => this.change(t(i)),
    this.signal.map(s, r),
    this.status.map(j(n)),
    this.parent,
    r
  );
  asyncTransform = (s, t, n, r = [], i = $) => new O(
    [...this.path, ...r],
    (l) => {
      t(l).then((a) => this.change(a));
    },
    this.signal.mapAsync(s, n, void 0, i),
    this.status.map(j(r)),
    this.parent,
    i
  );
}
class ke extends O {
  #e = /* @__PURE__ */ new Map();
  #t = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #n = I(!1);
  touchedDeep = this.#n;
  #i = /* @__PURE__ */ new Map();
  #r = /* @__PURE__ */ new Map();
  #l = I(!1);
  dirtyDeep = this.#l;
  #c;
  #u;
  #o = () => {
    let s = !1;
    for (const t of this.#t.values())
      if (t) {
        s = !0;
        break;
      }
    this.#n.set(this.touched.value || s);
  };
  constructor(s, t, n, r, i, l) {
    super(
      s,
      t,
      n.map((o) => o ?? {}, l),
      r,
      i,
      l
    ), this.#c = this.touched.on(() => {
      this.#o();
    }), this.#u = this.dirty.on(() => {
      this.#a();
    });
    const a = this.signal.on(() => this.#a());
    this.onDispose(() => {
      for (const o of this.#e.values())
        o.dispose();
      this.#e.clear();
      for (const o of this.#s.values()) o();
      this.#s.clear(), this.#t.clear(), this.#n.dispose();
      for (const o of this.#r.values()) o();
      this.#r.clear(), this.#i.clear(), this.#l.dispose(), this.#c(), this.#u(), a();
    });
  }
  field = (s) => {
    if (this.#e.has(s))
      return this.#e.get(s);
    const t = async (l) => {
      this.change({
        ...this.signal.value,
        [s]: l
      });
    }, n = new O(
      [...this.path, s],
      t,
      this.signal.map((l) => l[s]),
      this.status.map(j([s])),
      {
        disabled: this.disabled,
        // propagate validationMode to children if present
        validationMode: this.parent.validationMode
      }
    );
    this.#e.set(s, n);
    const r = n.touched.on((l) => {
      this.#t.set(s, l), this.#o();
    });
    this.#s.set(s, r);
    const i = n.dirty.on((l) => {
      this.#i.set(s, l), this.#a();
    });
    return this.#r.set(s, i), n;
  };
  markAllTouched = () => {
    this.markTouched();
    const s = this.signal.value;
    for (const t of Object.keys(s))
      this.field(t).markTouched();
    for (const t of this.#e.values())
      t.markTouched();
  };
  markAllPristine = () => {
    this.markPristine();
    const s = this.signal.value;
    for (const t of Object.keys(s))
      this.field(t).markPristine?.();
    for (const t of this.#e.values())
      t.markPristine?.();
  };
  #a = () => {
    let s = !1;
    for (const t of this.#i.values())
      if (t) {
        s = !0;
        break;
      }
    this.#l.set(this.dirty.value || s);
  };
}
class Se extends O {
  #e = new Array();
  length;
  #t = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #n = I(!1);
  touchedDeep = this.#n;
  #i = /* @__PURE__ */ new Map();
  #r = /* @__PURE__ */ new Map();
  #l = I(!1);
  dirtyDeep = this.#l;
  #c;
  #u;
  #o = () => {
    let s = !1;
    for (const t of this.#t.values())
      if (t) {
        s = !0;
        break;
      }
    this.#n.set(this.touched.value || s);
  };
  constructor(s, t, n, r, i, l) {
    const a = n.map((h) => h ?? [], l);
    super(s, t, a, r, i, l);
    const o = a.on((h) => {
      const b = this.#e.length - h.length;
      b > 0 && (this.#e.splice(h.length, b).forEach((k, g) => {
        const u = h.length + g;
        k.dispose(), this.#s.get(u)?.(), this.#s.delete(u), this.#t.delete(u), this.#r.get(u)?.(), this.#r.delete(u), this.#i.delete(u);
      }), this.#o(), this.#a());
    });
    this.length = a.map((h) => h.length), this.#c = this.touched.on(() => {
      this.#o();
    }), this.#u = this.dirty.on(() => {
      this.#a();
    });
    const p = this.signal.on(() => this.#a());
    this.onDispose(() => {
      for (const h of this.#e)
        h.dispose();
      this.length.dispose(), this.#e.length = 0, o(), a.dispose();
      for (const h of this.#s.values()) h();
      this.#s.clear(), this.#t.clear(), this.#n.dispose();
      for (const h of this.#r.values()) h();
      this.#r.clear(), this.#i.clear(), this.#l.dispose(), this.#c(), this.#u(), p();
    });
  }
  item = (s) => {
    if (this.#e[s])
      return this.#e[s];
    const t = async (l) => {
      const a = this.signal.value.slice();
      a[s] = l, this.change(a);
    }, n = new O(
      [...this.path, s],
      t,
      this.signal.map((l) => l[s]),
      this.status.map(j([s])),
      {
        disabled: this.disabled,
        validationMode: this.parent.validationMode
      }
    );
    this.#e[s] = n;
    const r = n.touched.on((l) => {
      this.#t.set(s, l), this.#o();
    });
    this.#s.set(s, r);
    const i = n.dirty.on((l) => {
      this.#i.set(s, l), this.#a();
    });
    return this.#r.set(s, i), n;
  };
  push = (...s) => {
    this.change([...this.signal.value, ...s]);
  };
  pop = () => {
    this.splice(this.signal.value.length - 1, 1);
  };
  shift = () => {
    this.splice(0, 1);
  };
  unshift = (...s) => {
    this.change([...s, ...this.signal.value]);
  };
  removeAt = (s) => {
    this.splice(s, 1);
  };
  splice = (s, t) => {
    const n = this.signal.value.slice();
    n.splice(s, t), this.change(n);
  };
  move = (s, t, n = 1) => {
    if (n < 1 || s === t) return;
    const r = this.signal.value.slice(), i = r.splice(s, n);
    r.splice(t, 0, ...i), this.change(r);
  };
  markAllTouched = () => {
    this.markTouched();
    const s = this.signal.value.length;
    for (let t = 0; t < s; t++)
      this.item(t).markTouched();
  };
  markAllPristine = () => {
    this.markPristine();
    const s = this.signal.value.length;
    for (let t = 0; t < s; t++)
      this.item(t).markPristine?.();
  };
  #a = () => {
    let s = !1;
    for (const t of this.#i.values())
      if (t) {
        s = !0;
        break;
      }
    this.#l.set(this.dirty.value || s);
  };
}
function Ce(e) {
  function s(t) {
    return typeof t == "number" ? t : t.toString();
  }
  return e.map(
    (t) => typeof t == "object" && t.key != null ? s(t.key) : s(t)
  );
}
function _e(e) {
  const s = e.filter((r) => r.path == null || r.path.length === 0).map((r) => r.message), t = e.filter((r) => r.path != null && r.path.length > 0).reduce((r, i) => {
    const l = Ce(i.path), a = l.pop();
    let o = r;
    for (const p of l)
      o.dependencies == null && (o.dependencies = {}), o.dependencies[p] == null && (o.dependencies[p] = {}), o = o.dependencies[p];
    return o.dependencies == null && (o.dependencies = {}), o.dependencies[a] = { message: i.message }, r;
  }, {}), n = s.join(`
`);
  return {
    ...t,
    message: n != "" ? n : void 0
  };
}
function De({
  initialValue: e,
  onChange: s,
  validate: t,
  equals: n,
  validationMode: r,
  validateDebounceMs: i
}) {
  const l = S.deriveProp(e), a = I(_.valid), o = I(!1), p = I(r ?? "touchedOrSubmit"), h = (d) => {
    a.set(d);
  };
  let b;
  const k = async (d) => {
    if (t != null) {
      const v = await t(d);
      h(v);
    }
  }, g = async (d) => {
    l.set(d), s?.(d);
    const v = p.value;
    if (t != null) {
      if (v === "onSubmit")
        return;
      const T = i ?? 0;
      T > 0 ? (b && clearTimeout(b), b = setTimeout(() => {
        k(d);
      }, T)) : await k(d);
    }
  }, u = new O(
    [],
    g,
    l,
    a,
    {
      disabled: o,
      validationMode: p
    },
    n ?? $
  );
  return u.onDispose(() => {
    o.dispose(), l.dispose(), a.dispose(), p.dispose(), b && clearTimeout(b);
  }), { controller: u, setStatus: h };
}
function ee(e) {
  return N(c.disabled(e.disabled), c.name(e.name));
}
function je(e, {
  triggerOn: s = "change"
} = {}) {
  return N(
    ee(e),
    c.value(e.signal),
    (s === "input" ? D.input : D.change)(F(e.change))
  );
}
function qe(e, {
  triggerOn: s = "change"
} = {}) {
  return N(
    ee(e),
    c.valueAsNumber(e.signal),
    (s === "input" ? D.input : D.change)(
      ie(e.change)
    )
  );
}
function J(e) {
  return e.issues != null ? _.invalid(_e(e.issues)) : _.valid;
}
async function ze({
  task: e,
  errorMessage: s,
  errorPath: t = ["root"],
  validation: n
}) {
  try {
    const r = await e();
    return n != null ? n(r) : _.valid;
  } catch (r) {
    const i = s ?? (r instanceof Error ? r.message : "Operation failed");
    return t.length === 1 && t[0] === "root" ? _.invalid({
      message: i
    }) : _.invalid({
      dependencies: se(t, i)
    });
  }
}
function se(e, s) {
  if (e.length === 1)
    return {
      [e[0]]: { message: s }
    };
  const [t, ...n] = e;
  return {
    [t]: {
      dependencies: se(n, s)
    }
  };
}
function He({
  initialValue: e = {},
  schema: s,
  onSubmit: t = async () => _.valid,
  validationMode: n,
  validateDebounceMs: r
}) {
  const { controller: i, setStatus: l } = De({
    initialValue: e,
    validationMode: n ?? "touchedOrSubmit",
    validateDebounceMs: r,
    validate: (n ?? "touchedOrSubmit") === "onSubmit" || s == null ? void 0 : async (h) => J(
      await s["~standard"].validate(h)
    )
  }), a = I(!1), o = i.object();
  return o.onDispose(a.dispose), {
    controller: o,
    setStatus: l,
    submit: async (h) => {
      if (a.set(!0), h?.preventDefault(), o.markAllTouched(), (n ?? "touchedOrSubmit") === "onSubmit") {
        const k = o.signal.value, g = s?.["~standard"].validate;
        if (g == null) {
          a.set(!1);
          return;
        }
        const u = J(await g(k));
        if (l(u), u.type === "invalid") {
          a.set(!1);
          return;
        }
      }
      const b = await t(o.signal.value);
      a.set(!1), b.type === "invalid" && l(b);
    },
    submitting: a
  };
}
function Ee(e) {
  switch (e) {
    case "success":
      return "material-symbols:check-circle-outline";
    case "warning":
      return "material-symbols:warning-outline";
    case "danger":
      return "material-symbols:error-outline";
    case "info":
    default:
      return "material-symbols:info-outline";
  }
}
function Ie(e) {
  switch (e) {
    case "success":
      return "success";
    case "warning":
      return "warning";
    case "danger":
      return "danger";
    case "info":
    default:
      return "info";
  }
}
function Te(e, s, t, n) {
  const r = [
    "bc-notice",
    `bc-notice--${e}`,
    `bc-notice--tone-${s}`
  ];
  return t && r.push("bc-notice--dismissible"), n && n.length > 0 && r.push(n), r.join(" ");
}
function Ue({
  variant: e = "info",
  tone: s = "subtle",
  role: t,
  title: n,
  icon: r,
  closable: i = !1,
  onDismiss: l,
  class: a
}, ...o) {
  const p = I(!0);
  return V(p, () => {
    const h = S.map(
      i,
      (u) => !!u || l != null
    ), b = S.map(e, (u) => u ?? "info"), k = S.map(s, (u) => u ?? "subtle"), g = w(
      t,
      b
    )(
      (u, d) => u ?? (d === "danger" ? "alert" : "status")
    );
    return q(
      z,
      (u) => f.div(
        c.class(
          w(
            b,
            k,
            h,
            a
          )((d, v, T, A) => Te(d, v, T, A))
        ),
        // Accessibility role mapping (always defined)
        c.role(S.map(g, (d) => d)),
        ae(
          S.map(r, (d) => d === !1),
          () => f.div(
            c.class("bc-notice__icon"),
            B({
              icon: w(
                r,
                b
              )(
                (d, v) => d === void 0 ? Ee(v) : String(d)
              ),
              size: "md",
              color: S.map(b, Ie)
            })
          )
        ),
        f.div(
          c.class("bc-notice__body"),
          le(
            n,
            (d) => f.div(c.class("bc-notice__title"), d)
          ),
          f.div(c.class("bc-notice__content"), ...o)
        ),
        V(
          h,
          () => ue({
            size: "xs",
            label: u.$.closeModal,
            onClick: () => {
              p.set(!1), l?.();
            }
          })
        )
      )
    );
  });
}
export {
  Se as A,
  Z as B,
  ue as C,
  Me as D,
  xe as E,
  Y as I,
  he as L,
  Be as M,
  Ue as N,
  $ as O,
  Ne as P,
  pe as R,
  $e as S,
  _ as a,
  Fe as b,
  Pe as c,
  G as d,
  O as e,
  j as f,
  ve as g,
  we as h,
  ke as i,
  Ce as j,
  _e as k,
  De as l,
  ge as m,
  ee as n,
  je as o,
  Le as p,
  qe as q,
  J as r,
  H as s,
  ze as t,
  He as u,
  Oe as v,
  ye as w,
  de as x
};
