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