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