import { Use as q, coalesce as Q, aria as x, attr as o, html as f, on as E, Value as C, Empty as _, computedOf as k, When as O, dataAttr as R, input as te, emitValue as F, prop as I, Fragment as P, emitValueAsNumber as ne, Unless as ie, Ensure as re } from "@tempots/dom";
import { a as z, B as ae, I as N, b as W, c as le, C as X } from "./translations-g3qGTkzw.js";
const K = /* @__PURE__ */ new Map();
function H(e) {
  const s = K.get(e) ?? 0;
  return K.set(e, s + 1), `${e}-${s}`;
}
const w = {
  /**
   * 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 w.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 w.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 w.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 w.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 (w.isSuccess(e))
      return e.value;
    throw w.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: i = n
  }) => w.isSuccess(e) ? s(e.value) : w.isFailure(e) ? t(e.error) : w.isNotAsked(e) ? i() : 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) => (w.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) => (w.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, i) => n === i,
    errorEquals: (n, i) => n === i
  }) => 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 (w.isSuccess(t))
        s.push(t.value);
      else
        return t;
    return w.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 w.success(s);
    } catch (s) {
      return w.failure(s instanceof Error ? s : new Error(String(s)));
    }
  }
}, $ = (e, s) => e === s || e !== e && s !== s, D = {
  /**
   * 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) => D.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) => D.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) => (D.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) => (D.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) => w.success(s),
      (s) => w.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,
      () => D.valid,
      (s) => D.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,
    (i) => m.match(
      s,
      (r) => m.success(t(i, r)),
      (r) => m.failure(r)
    ),
    (i) => m.match(
      s,
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      (r) => m.failure(i),
      (r) => m.failure(n(i, r))
    )
  ),
  /**
   * 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, i) => n === i,
    errorEquals: (n, i) => n === i
  }) => 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 ce({
  size: e = "sm",
  icon: s = "line-md:close",
  disabled: t,
  roundedness: n = "full",
  color: i = "base",
  onClick: r,
  label: l
}, ...a) {
  return q(z, (c) => {
    const p = Q(l, c.$.closeModal);
    return ae(
      {
        variant: "text",
        size: e,
        roundedness: n,
        disabled: t,
        color: i,
        onClick: r
      },
      o.title(p),
      x.label(p),
      ...a,
      N({ icon: s, size: e ?? "sm" })
    );
  });
}
function U(e) {
  return `bc-label bc-label--${e}`;
}
const Ae = (...e) => f.span(o.class(U("emphasis")), ...e), oe = (...e) => f.span(o.class(U("default")), ...e), ue = (...e) => f.span(o.class(U("muted")), ...e), Ve = (...e) => f.span(o.class(U("danger")), ...e), Oe = (e) => {
  const {
    value: s,
    onBlur: t,
    onChange: n,
    placeholder: i,
    disabled: r,
    id: l,
    checkedIcon: a,
    uncheckedIcon: c,
    iconSize: p = "lg"
  } = e, h = l ?? H("checkbox"), b = `${h}-label`, S = () => {
    if (C.get(r ?? !1)) return;
    const u = C.get(s);
    n?.(!u);
  }, v = (u) => {
    C.get(r ?? !1) || (u.key === " " || u.key === "Enter") && (u.preventDefault(), S());
  };
  return W(
    {
      baseContainer: !0,
      growInput: !1,
      ...e,
      input: f.span(
        o.class("bc-checkbox-input"),
        f.span(
          o.class("bc-checkbox-input__checkbox"),
          o.class(
            C.map(
              s,
              (u) => u ? "bc-checkbox-input__checkbox--checked" : "bc-checkbox-input__checkbox--unchecked"
            )
          ),
          o.class(
            C.map(
              r ?? !1,
              (u) => u ? "bc-checkbox-input__checkbox--disabled" : ""
            )
          ),
          o.id(h),
          o.role("checkbox"),
          o.tabindex(
            C.map(
              r ?? !1,
              (u) => u ? -1 : 0
            )
          ),
          x.checked(s),
          x.disabled(r),
          i != null ? x.labelledby(b) : _,
          E.keydown(v),
          t != null ? E.blur(t) : _,
          N({
            icon: k(
              s,
              a,
              c
            )(
              (u, d, g) => u ? d ?? "akar-icons/check-box-fill" : g ?? "akar-icons/box"
            ),
            accessibility: "decorative",
            size: p
          })
        ),
        i != null ? f.label(
          o.class("bc-checkbox-input__label"),
          o.id(b),
          o.for(h),
          ue(i)
        ) : _
      )
    },
    E.click(S)
  );
}, he = f.span(
  o.class("bc-input-wrapper__required"),
  " *"
);
function de(e) {
  const s = ["bc-input-wrapper"];
  return e !== "vertical" && s.push(`bc-input-wrapper--${e}`), s.join(" ");
}
function pe(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 G(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: i,
  description: r,
  content: l,
  error: a,
  labelFor: c,
  hasError: p,
  disabled: h,
  layout: b,
  labelWidth: S
}, ...v) => {
  const u = p ?? a != null, d = h ?? !1, g = b ?? "vertical", T = H("input-wrapper"), A = r ? `${T}-description` : void 0, B = a != null ? `${T}-error` : void 0, L = k(g)((y) => y !== "vertical");
  return f.div(
    o.class(C.map(g, (y) => de(y))),
    o.class(
      C.map(
        e,
        (y) => y ? "bc-input-wrapper--full-width" : ""
      )
    ),
    O(
      k(
        g,
        S ?? void 0
      )((y, V) => G(y, V) != null),
      () => o.style(
        C.map(
          k(
            g,
            S ?? void 0
          )((y, V) => G(y, V)),
          (y) => y
        )
      )
    ),
    t != null || i != null ? f.div(
      o.class("bc-input-wrapper__header"),
      f.div(
        o.class("bc-input-wrapper__label-section"),
        f.label(
          o.class("bc-input-wrapper__label"),
          c != null ? o.for(c) : _,
          f.span(
            o.class(
              k(
                u,
                d
              )(
                (y, V) => pe(
                  y ?? !1,
                  V ?? !1
                )
              )
            ),
            t
          ),
          t != null && s ? he : _
        ),
        // Show description under label when horizontal
        O(
          k(
            L,
            r
          )((y, V) => y && V != null),
          () => f.div(
            o.class(
              "bc-input-wrapper__description bc-input-wrapper__description--under-label"
            ),
            o.id(A),
            r
          )
        )
      ),
      i != null ? oe(i) : _,
      n
    ) : _,
    f.div(
      o.class("bc-input-wrapper__content"),
      // Add data attributes to help inputs inherit accessibility information
      [A, B].filter(Boolean).length > 0 ? R.describedby(
        [A, B].filter(Boolean).join(" ")
      ) : _,
      s ? R.required("true") : _,
      O(u, () => R.invalid("true")),
      l
    ),
    // Show description at bottom only when not horizontal
    O(
      k(L, r)((y, V) => !y && V != null),
      () => f.div(
        o.class("bc-input-wrapper__description"),
        o.id(A),
        r
      )
    ),
    a != null ? O(
      u,
      () => f.div(
        o.class("bc-input-wrapper__error"),
        o.id(B),
        x.live("polite"),
        // Announce errors to screen readers
        o.role("alert"),
        // Mark as alert for immediate attention
        a
      )
    ) : null,
    ...v
  );
};
function Me(...e) {
  return f.div(o.class("bc-stack"), ...e);
}
const Fe = (e) => {
  const s = {
    name: "email",
    autocomplete: "email",
    ...e
  }, {
    value: t,
    before: n,
    onBlur: i,
    onChange: r,
    onInput: l,
    placeholder: a
  } = s, c = n ?? le({
    icon: "line-md:email",
    size: e.size,
    color: "neutral"
  });
  return q(
    z,
    (p) => W({
      ...e,
      before: c,
      input: te.email(
        X(s),
        o.placeholder(Q(a, p.$.emailPlaceholderText)),
        o.value(t),
        o.class("bc-input"),
        i != null ? E.blur(F(i)) : _,
        r != null ? E.change(F(r)) : _,
        l != null ? E.input(F(l)) : _
      )
    })
  );
}, $e = (e) => {
  const {
    value: s,
    onBlur: t,
    onChange: n,
    onInput: i,
    before: r,
    after: l,
    hasError: a,
    disabled: c,
    autocomplete: p,
    placeholder: h,
    ...b
  } = e, S = {
    name: "password",
    disabled: c,
    ...b
  }, v = I(!0), u = k(
    v,
    p
  )((d, g) => d ? g ?? "current-password" : "off");
  return q(z, (d) => {
    const g = k(
      d.$.passwordPlaceholderText,
      v,
      h
    )((A, B, L) => B ? "•••••••••••••••" : L ?? A), T = f.button(
      o.type("button"),
      o.class("bc-input-container__password-toggle"),
      x.label(d.$.togglePasswordVisibility),
      E.click(() => v.update((A) => !A)),
      O(
        v,
        () => N({ icon: "line-md:watch" }),
        () => N({ icon: "line-md:watch-off" })
      )
    );
    return W({
      before: r,
      disabled: c,
      hasError: a,
      input: f.input(
        X({
          ...S,
          autocomplete: u,
          placeholder: g
        }),
        O(
          v,
          () => P(o.type("password")),
          () => P(o.type("text"))
        ),
        o.class("bc-input"),
        o.value(s),
        t != null ? E.blur(F(t)) : _,
        n != null ? E.change(F(n)) : _,
        i != null ? E.input(F(i)) : _
      ),
      after: l != null ? P(T, l) : T
    });
  });
}, fe = (
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  (e, s) => () => {
    e.markTouched(), s?.();
  }
), be = (e, s) => (t) => {
  e.change(t), s?.(t);
};
function Z(e, s) {
  const { controller: t, onBlur: n, onChange: i, id: r, ...l } = s;
  return e({
    id: r ?? t.name,
    disabled: t.disabled,
    value: t.signal,
    hasError: t.errorVisible,
    name: t.name,
    ...l,
    onChange: be(t, i),
    onBlur: fe(t, n)
  });
}
function xe(e, { id: s, labelFor: t, ...n }, ...i) {
  const r = s ?? n.controller.name ?? H("control");
  return Y(
    {
      ...n,
      labelFor: t ?? r,
      content: Z(
        (a) => e({ ...a, id: r }),
        n
      )
    },
    ...i
  );
}
function me(e, s) {
  const { toInput: t, fromInput: n, controller: i, ...r } = s, l = i.transform(t, n);
  return Z(e, {
    ...r,
    controller: l
  });
}
function Pe(e, {
  id: s,
  labelFor: t,
  ...n
}, ...i) {
  const r = s ?? n.controller.name ?? H("control");
  return Y(
    {
      ...n,
      labelFor: t ?? r,
      content: me(e, {
        ...n,
        id: r
      })
    },
    ...i
  );
}
function Be(e) {
  return e.split(".").map((t) => {
    const n = t.match(/^\[(\d+)\]$/);
    return n ? Number(n[1]) : t;
  });
}
function ge(e) {
  return typeof e == "number" ? `[${e}]` : `.${e}`;
}
function ve(e) {
  if (e.length === 0) return "";
  const [s, ...t] = e;
  return [
    typeof s == "number" ? `[${s}]` : s,
    ...t.map(ge)
  ].join("");
}
function j(e) {
  return function(t) {
    if (t.type === "valid") return t;
    let n = t.error;
    for (const i of e)
      if (n = n?.dependencies?.[i], n == null) return D.valid;
    return D.invalid(n);
  };
}
class M {
  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, i, r, l = $) {
    this.path = s, this.change = t, this.signal = n, this.status = i, this.#t = l, this.#s.set(n.value), this.error = i.map(
      (a) => a?.type === "invalid" ? a.error?.message : void 0
    ), this.hasError = this.error.map((a) => a != null), this.touched = this.#e.touched, r.validationMode ? this.errorVisible = k(
      this.hasError,
      this.touched,
      r.validationMode
    )((a, c, p) => p === "continuous" ? !!a : !!a && !!c) : this.errorVisible = k(
      this.hasError,
      this.touched
    )((a, c) => !!a && !!c), this.dirty = k(
      this.signal,
      this.#s
    )((a, c) => !this.#t(a, c)), this.dependencyErrors = i.map(
      (a) => a?.type === "invalid" ? a.error?.dependencies : void 0
    ), this.parent = r, this.disabled = k(
      this.#e.disabled,
      r.disabled
    )((a, c) => a || c), this.disabledOrHasErrors = k(
      this.disabled,
      this.hasError
    )((a, c) => a || c), 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 ve(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 we(
    this.path,
    this.change,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    this.signal,
    this.status,
    this.parent,
    s
  );
  object = (s = $) => new ye(
    this.path,
    this.change,
    this.signal,
    this.status,
    this.parent,
    s
  );
  transform = (s, t, n = [], i = $) => new M(
    [...this.path, ...n],
    (r) => this.change(t(r)),
    this.signal.map(s, i),
    this.status.map(j(n)),
    this.parent,
    i
  );
  asyncTransform = (s, t, n, i = [], r = $) => new M(
    [...this.path, ...i],
    (l) => {
      t(l).then((a) => this.change(a));
    },
    this.signal.mapAsync(s, n, void 0, r),
    this.status.map(j(i)),
    this.parent,
    r
  );
}
class ye extends M {
  #e = /* @__PURE__ */ new Map();
  #t = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #n = I(!1);
  touchedDeep = this.#n;
  #r = /* @__PURE__ */ new Map();
  #i = /* @__PURE__ */ new Map();
  #l = I(!1);
  dirtyDeep = this.#l;
  #o;
  #u;
  #c = () => {
    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, i, r, l) {
    super(
      s,
      t,
      n.map((c) => c ?? {}, l),
      i,
      r,
      l
    ), this.#o = this.touched.on(() => {
      this.#c();
    }), this.#u = this.dirty.on(() => {
      this.#a();
    });
    const a = this.signal.on(() => this.#a());
    this.onDispose(() => {
      for (const c of this.#e.values())
        c.dispose();
      this.#e.clear();
      for (const c of this.#s.values()) c();
      this.#s.clear(), this.#t.clear(), this.#n.dispose();
      for (const c of this.#i.values()) c();
      this.#i.clear(), this.#r.clear(), this.#l.dispose(), this.#o(), 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 M(
      [...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 i = n.touched.on((l) => {
      this.#t.set(s, l), this.#c();
    });
    this.#s.set(s, i);
    const r = n.dirty.on((l) => {
      this.#r.set(s, l), this.#a();
    });
    return this.#i.set(s, r), 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.#r.values())
      if (t) {
        s = !0;
        break;
      }
    this.#l.set(this.dirty.value || s);
  };
}
class we extends M {
  #e = new Array();
  length;
  #t = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #n = I(!1);
  touchedDeep = this.#n;
  #r = /* @__PURE__ */ new Map();
  #i = /* @__PURE__ */ new Map();
  #l = I(!1);
  dirtyDeep = this.#l;
  #o;
  #u;
  #c = () => {
    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, i, r, l) {
    const a = n.map((h) => h ?? [], l);
    super(s, t, a, i, r, l);
    const c = a.on((h) => {
      const b = this.#e.length - h.length;
      b > 0 && (this.#e.splice(h.length, b).forEach((S, v) => {
        const u = h.length + v;
        S.dispose(), this.#s.get(u)?.(), this.#s.delete(u), this.#t.delete(u), this.#i.get(u)?.(), this.#i.delete(u), this.#r.delete(u);
      }), this.#c(), this.#a());
    });
    this.length = a.map((h) => h.length), this.#o = this.touched.on(() => {
      this.#c();
    }), 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, c(), a.dispose();
      for (const h of this.#s.values()) h();
      this.#s.clear(), this.#t.clear(), this.#n.dispose();
      for (const h of this.#i.values()) h();
      this.#i.clear(), this.#r.clear(), this.#l.dispose(), this.#o(), 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 M(
      [...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 i = n.touched.on((l) => {
      this.#t.set(s, l), this.#c();
    });
    this.#s.set(s, i);
    const r = n.dirty.on((l) => {
      this.#r.set(s, l), this.#a();
    });
    return this.#i.set(s, r), 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 i = this.signal.value.slice(), r = i.splice(s, n);
    i.splice(t, 0, ...r), this.change(i);
  };
  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.#r.values())
      if (t) {
        s = !0;
        break;
      }
    this.#l.set(this.dirty.value || s);
  };
}
function ke(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 Se(e) {
  const s = e.filter((i) => i.path == null || i.path.length === 0).map((i) => i.message), t = e.filter((i) => i.path != null && i.path.length > 0).reduce((i, r) => {
    const l = ke(r.path), a = l.pop();
    let c = i;
    for (const p of l)
      c.dependencies == null && (c.dependencies = {}), c.dependencies[p] == null && (c.dependencies[p] = {}), c = c.dependencies[p];
    return c.dependencies == null && (c.dependencies = {}), c.dependencies[a] = { message: r.message }, i;
  }, {}), n = s.join(`
`);
  return {
    ...t,
    message: n != "" ? n : void 0
  };
}
function Ce({
  initialValue: e,
  onChange: s,
  validate: t,
  equals: n,
  validationMode: i,
  validateDebounceMs: r
}) {
  const l = C.deriveProp(e), a = I(D.valid), c = I(!1), p = I(i ?? "touchedOrSubmit"), h = (d) => {
    a.set(d);
  };
  let b;
  const S = async (d) => {
    if (t != null) {
      const g = await t(d);
      h(g);
    }
  }, v = async (d) => {
    l.set(d), s?.(d);
    const g = p.value;
    if (t != null) {
      if (g === "onSubmit")
        return;
      const T = r ?? 0;
      T > 0 ? (b && clearTimeout(b), b = setTimeout(() => {
        S(d);
      }, T)) : await S(d);
    }
  }, u = new M(
    [],
    v,
    l,
    a,
    {
      disabled: c,
      validationMode: p
    },
    n ?? $
  );
  return u.onDispose(() => {
    c.dispose(), l.dispose(), a.dispose(), p.dispose(), b && clearTimeout(b);
  }), { controller: u, setStatus: h };
}
function ee(e) {
  return P(o.disabled(e.disabled), o.name(e.name));
}
function Ne(e, {
  triggerOn: s = "change"
} = {}) {
  return P(
    ee(e),
    o.value(e.signal),
    (s === "input" ? E.input : E.change)(F(e.change))
  );
}
function Le(e, {
  triggerOn: s = "change"
} = {}) {
  return P(
    ee(e),
    o.valueAsNumber(e.signal),
    (s === "input" ? E.input : E.change)(
      ne(e.change)
    )
  );
}
function J(e) {
  return e.issues != null ? D.invalid(Se(e.issues)) : D.valid;
}
async function je({
  task: e,
  errorMessage: s,
  errorPath: t = ["root"],
  validation: n
}) {
  try {
    const i = await e();
    return n != null ? n(i) : D.valid;
  } catch (i) {
    const r = s ?? (i instanceof Error ? i.message : "Operation failed");
    return t.length === 1 && t[0] === "root" ? D.invalid({
      message: r
    }) : D.invalid({
      dependencies: se(t, r)
    });
  }
}
function se(e, s) {
  if (e.length === 1)
    return {
      [e[0]]: { message: s }
    };
  const [t, ...n] = e;
  return {
    [t]: {
      dependencies: se(n, s)
    }
  };
}
function qe({
  initialValue: e = {},
  schema: s,
  onSubmit: t = async () => D.valid,
  validationMode: n,
  validateDebounceMs: i
}) {
  const { controller: r, setStatus: l } = Ce({
    initialValue: e,
    validationMode: n ?? "touchedOrSubmit",
    validateDebounceMs: i,
    validate: (n ?? "touchedOrSubmit") === "onSubmit" || s == null ? void 0 : async (h) => J(
      await s["~standard"].validate(h)
    )
  }), a = I(!1), c = r.object();
  return c.onDispose(a.dispose), {
    controller: c,
    setStatus: l,
    submit: async (h) => {
      if (a.set(!0), h?.preventDefault(), c.markAllTouched(), (n ?? "touchedOrSubmit") === "onSubmit") {
        const S = c.signal.value, v = s?.["~standard"].validate;
        if (v == null) {
          a.set(!1);
          return;
        }
        const u = J(await v(S));
        if (l(u), u.type === "invalid") {
          a.set(!1);
          return;
        }
      }
      const b = await t(c.signal.value);
      a.set(!1), b.type === "invalid" && l(b);
    },
    submitting: a
  };
}
function _e(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 De(e) {
  switch (e) {
    case "success":
      return "success";
    case "warning":
      return "warning";
    case "danger":
      return "danger";
    case "info":
    default:
      return "info";
  }
}
function Ee(e, s, t, n) {
  const i = [
    "bc-notice",
    `bc-notice--${e}`,
    `bc-notice--tone-${s}`
  ];
  return t && i.push("bc-notice--dismissible"), n && n.length > 0 && i.push(n), i.join(" ");
}
function ze({
  variant: e = "info",
  tone: s = "subtle",
  role: t,
  title: n,
  icon: i,
  closable: r = !1,
  onDismiss: l,
  class: a
}, ...c) {
  const p = I(!0);
  return O(p, () => {
    const h = C.map(
      r,
      (u) => !!u || l != null
    ), b = C.map(e, (u) => u ?? "info"), S = C.map(s, (u) => u ?? "subtle"), v = k(
      t,
      b
    )(
      (u, d) => u ?? (d === "danger" ? "alert" : "status")
    );
    return q(
      z,
      (u) => f.div(
        o.class(
          k(
            b,
            S,
            h,
            a
          )((d, g, T, A) => Ee(d, g, T, A))
        ),
        // Accessibility role mapping (always defined)
        o.role(C.map(v, (d) => d)),
        ie(
          C.map(i, (d) => d === !1),
          () => f.div(
            o.class("bc-notice__icon"),
            N({
              icon: k(
                i,
                b
              )(
                (d, g) => d === void 0 ? _e(g) : String(d)
              ),
              size: "md",
              color: C.map(b, De)
            })
          )
        ),
        f.div(
          o.class("bc-notice__body"),
          re(
            n,
            (d) => f.div(o.class("bc-notice__title"), d)
          ),
          f.div(o.class("bc-notice__content"), ...c)
        ),
        O(
          h,
          () => ce({
            size: "xs",
            label: u.$.closeModal,
            onClick: () => {
              p.set(!1), l?.();
            }
          })
        )
      )
    );
  });
}
export {
  we as A,
  Z as B,
  ce as C,
  Ve as D,
  Fe as E,
  Y as I,
  oe as L,
  Pe as M,
  ze as N,
  $ as O,
  $e as P,
  he as R,
  Me as S,
  D as a,
  Oe as b,
  xe as c,
  be as d,
  M as e,
  j as f,
  me as g,
  ve as h,
  ye as i,
  ke as j,
  Se as k,
  Ce as l,
  fe as m,
  ee as n,
  Ne as o,
  Be as p,
  Le as q,
  J as r,
  H as s,
  je as t,
  qe as u,
  Ae as v,
  ge as w,
  ue as x
};
