import { Use as X, coalesce as Y, aria as F, attr as o, html as f, on as I, Value as E, Empty as T, computedOf as w, When as x, dataAttr as j, TextNode as Z, prop as S, Fragment as q, emitValue as ee, emitValueAsNumber as se } from "@tempots/dom";
import { a as te, B as ne, c as R, b as re } from "./translations-DQxouiBG.js";
const H = /* @__PURE__ */ new Map();
function N(e) {
  const s = H.get(e) ?? 0;
  return H.set(e, s + 1), `${e}-${s}`;
}
const b = {
  /**
   * 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 b.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 b.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 b.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 b.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 (b.isSuccess(e))
      return e.value;
    throw b.isFailure(e) ? e.error : new Error("Cannot get value from a not-asked or loading result");
  },
  /**
   * Based on the state of the result, it picks the appropriate function to call and returns the result.
   * @param success - The function to call if the result is a success.
   * @param failure - The function to call if the result is a failure.
   * @param loading - The function to call if the result is loading.
   * @param notAsked - The function to call if the result is not-asked.
   * @returns The result of calling the appropriate function based on the state of the result.
   * @public
   */
  match: (e, {
    success: s,
    failure: t,
    loading: n,
    notAsked: r = n
  }) => b.isSuccess(e) ? s(e.value) : b.isFailure(e) ? t(e.error) : b.isNotAsked(e) ? r() : n(e.previousValue),
  /**
   * When the result is a success, it applies the function to the value.
   *
   * @param r - The result.
   * @param apply - The function to apply.
   * @returns The result that was passed in.
   * @public
   */
  whenSuccess: (e, s) => (b.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) => (b.isFailure(e) && s(e.error), e),
  /**
   * Compares two results for equality.
   * @param r1 - The first result.
   * @param r2 - The second result.
   * @param options - The options to use for comparison. By default, uses strict equality.
   * @returns `true` if the results are equal, `false` otherwise.
   */
  equals: (e, s, t = {
    valueEquals: (n, r) => n === r,
    errorEquals: (n, r) => n === r
  }) => e.type === "AsyncSuccess" && s.type === "AsyncSuccess" ? t.valueEquals(e.value, s.value) : e.type === "AsyncFailure" && s.type === "AsyncFailure" ? t.errorEquals(e.error, s.error) : e.type === "Loading" && s.type === "Loading" ? t.valueEquals(e.previousValue, s.previousValue) : e.type === "NotAsked" && s.type === "NotAsked",
  /**
   * Combines multiple results into a single result.
   * @param results - The results to combine.
   * @returns A single result that is a success if all the input results are successes, otherwise a failure.
   */
  all: (e) => {
    const s = [];
    for (const t of e)
      if (b.isSuccess(t))
        s.push(t.value);
      else
        return t;
    return b.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 b.success(s);
    } catch (s) {
      return b.failure(s instanceof Error ? s : new Error(String(s)));
    }
  }
}, V = (e, s) => e === s || e !== e && s !== s, g = {
  /**
   * 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) => g.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) => g.match(
    e,
    () => d.success(s),
    (t) => d.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) => (g.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) => (g.isInvalid(e) && s(e.error), e)
}, d = {
  /**
   * 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" ? d.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 d.match(
      e,
      (s) => b.success(s),
      (s) => b.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 d.match(
      e,
      () => g.valid,
      (s) => g.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 d.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 d.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 d.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 d.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 (d.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) => d.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) => (d.isSuccess(e) && s(e.value), e),
  whenFailure: (e, s) => (d.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) => d.match(
    e,
    (r) => d.match(
      s,
      (i) => d.success(t(r, i)),
      (i) => d.failure(i)
    ),
    (r) => d.match(
      s,
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      (i) => d.failure(r),
      (i) => d.failure(n(r, i))
    )
  ),
  /**
   * Compares two results for equality.
   * @param r1 - The first result.
   * @param r2 - The second result.
   * @param options - The options to use for comparison. By default, uses strict equality.
   * @returns `true` if the results are equal, `false` otherwise.
   */
  equals: (e, s, t = {
    valueEquals: (n, r) => n === r,
    errorEquals: (n, r) => n === r
  }) => e.type === "Success" && s.type === "Success" ? t.valueEquals(e.value, s.value) : e.type === "Failure" && s.type === "Failure" ? t.errorEquals(e.error, s.error) : !1,
  /**
   * Combines multiple results into a single result.
   * @param results - The results to combine.
   * @returns A single result that is a success if all the input results are successes, otherwise a failure.
   */
  all: (e) => {
    const s = [];
    for (const t of e)
      if (d.isSuccess(t))
        s.push(t.value);
      else
        return t;
    return d.success(s);
  }
};
function Se({
  size: e = "sm",
  icon: s = "line-md:close",
  disabled: t,
  roundedness: n = "full",
  color: r = "base",
  onClick: i,
  label: l
}, ...a) {
  return X(te, (c) => {
    const p = Y(l, c.$.closeModal);
    return ne(
      {
        variant: "text",
        size: e,
        roundedness: n,
        disabled: t,
        color: r,
        onClick: i
      },
      o.title(p),
      F.label(p),
      ...a,
      R({ icon: s, size: e ?? "sm" })
    );
  });
}
function $(e) {
  return `bc-label bc-label--${e}`;
}
const De = (...e) => f.span(o.class($("emphasis")), ...e), ie = (...e) => f.span(o.class($("default")), ...e), ae = (...e) => f.span(o.class($("muted")), ...e), Ce = (...e) => f.span(o.class($("danger")), ...e), Ee = (e) => {
  const {
    value: s,
    onBlur: t,
    onChange: n,
    placeholder: r,
    disabled: i,
    id: l,
    checkedIcon: a,
    uncheckedIcon: c,
    iconSize: p = "lg"
  } = e, u = l ?? N("checkbox"), m = `${u}-label`, k = () => {
    if (E.get(i ?? !1)) return;
    const h = E.get(s);
    n?.(!h);
  }, D = (h) => {
    E.get(i ?? !1) || (h.key === " " || h.key === "Enter") && (h.preventDefault(), k());
  };
  return re(
    {
      baseContainer: !0,
      growInput: !1,
      ...e,
      input: f.span(
        o.class("bc-checkbox-input"),
        f.span(
          o.class("bc-checkbox-input__checkbox"),
          o.class(
            E.map(
              s,
              (h) => h ? "bc-checkbox-input__checkbox--checked" : "bc-checkbox-input__checkbox--unchecked"
            )
          ),
          o.class(
            E.map(
              i ?? !1,
              (h) => h ? "bc-checkbox-input__checkbox--disabled" : ""
            )
          ),
          o.id(u),
          o.role("checkbox"),
          o.tabindex(
            E.map(
              i ?? !1,
              (h) => h ? -1 : 0
            )
          ),
          F.checked(s),
          F.disabled(i),
          r != null ? F.labelledby(m) : T,
          I.keydown(D),
          t != null ? I.blur(t) : T,
          R({
            icon: w(
              s,
              a,
              c
            )(
              (h, v, C) => h ? v ?? "akar-icons/check-box-fill" : C ?? "akar-icons/box"
            ),
            accessibility: "decorative",
            size: p
          })
        ),
        r != null ? f.label(
          o.class("bc-checkbox-input__label"),
          o.id(m),
          o.for(u),
          ae(r)
        ) : T
      )
    },
    I.click(k)
  );
}, le = f.span(
  o.class("bc-input-wrapper__required"),
  " *"
);
function ce(e) {
  const s = ["bc-input-wrapper"];
  return e !== "vertical" && s.push(`bc-input-wrapper--${e}`), s.join(" ");
}
function oe(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 ue(e, s) {
  if (e === "horizontal-fixed" && s != null)
    return `--input-wrapper-label-width: ${s}`;
}
const W = ({
  fullWidth: e = !1,
  required: s,
  label: t,
  labelChildren: n,
  context: r,
  description: i,
  content: l,
  error: a,
  labelFor: c,
  hasError: p,
  disabled: u,
  layout: m,
  labelWidth: k
}, ...D) => {
  const h = p ?? a != null, v = u ?? !1, C = m ?? "vertical", M = N("input-wrapper"), O = i ? `${M}-description` : void 0, B = a != null ? `${M}-error` : void 0, P = w(C)((y) => y !== "vertical"), Q = w(
    C,
    k ?? void 0
  )((y, A) => ue(y, A));
  return f.div(
    o.class(E.map(C, (y) => ce(y))),
    o.class(
      E.map(
        e,
        (y) => y ? "bc-input-wrapper--full-width" : ""
      )
    ),
    o.style(Q),
    t != null || r != 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) : T,
          f.span(
            o.class(
              w(
                h,
                v
              )(
                (y, A) => oe(
                  y ?? !1,
                  A ?? !1
                )
              )
            ),
            t
          ),
          t != null && s ? le : T
        ),
        // Show description under label when horizontal
        x(
          w(
            P,
            i
          )((y, A) => y && A != null),
          () => f.div(
            o.class(
              "bc-input-wrapper__description bc-input-wrapper__description--under-label"
            ),
            o.id(O),
            i
          )
        )
      ),
      r != null ? ie(r) : T,
      n
    ) : T,
    f.div(
      o.class("bc-input-wrapper__content"),
      // Add data attributes to help inputs inherit accessibility information
      [O, B].filter(Boolean).length > 0 ? j.describedby(
        [O, B].filter(Boolean).join(" ")
      ) : T,
      s ? j.required("true") : T,
      x(h, () => j.invalid("true")),
      l
    ),
    // Show description at bottom only when not horizontal
    x(
      w(P, i)((y, A) => !y && A != null),
      () => f.div(
        o.class("bc-input-wrapper__description"),
        o.id(O),
        i
      )
    ),
    x(
      h,
      () => f.div(
        o.class("bc-input-wrapper__error"),
        o.id(B),
        F.live("polite"),
        // Announce errors to screen readers
        o.role("alert"),
        // Mark as alert for immediate attention
        a
      )
    ),
    ...D
  );
};
function Te(...e) {
  return f.div(o.class("bc-stack"), ...e);
}
const he = (
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  (e, s) => () => {
    e.markTouched(), s?.();
  }
), z = (e, s) => (t) => {
  e.change(t), s?.(t);
};
function K(e, s) {
  const { controller: t, onBlur: n, onChange: r, id: i, triggerOn: l, ...a } = s;
  return e({
    id: i ?? t.name,
    disabled: t.disabled,
    value: t.signal,
    hasError: t.errorVisible,
    name: t.name,
    ...a,
    onInput: l === "input" ? z(t, r) : void 0,
    onChange: l !== "input" ? z(t, r) : void 0,
    onBlur: he(t, n)
  });
}
function _e(e, { id: s, labelFor: t, ...n }, ...r) {
  const i = s ?? n.controller.name ?? N("control"), l = t ?? i;
  return W(
    {
      ...n,
      hasError: n.controller.errorVisible,
      error: Z(n.controller.error.map((a) => a ?? "")),
      labelFor: l,
      content: K(
        (a) => e({ ...a, id: i }),
        n
      )
    },
    ...r
  );
}
function de(e, s) {
  const { toInput: t, fromInput: n, controller: r, ...i } = s, l = r.transform(t, n);
  return K(e, {
    ...i,
    controller: l
  });
}
function Ae(e, {
  id: s,
  labelFor: t,
  ...n
}, ...r) {
  const i = s ?? n.controller.name ?? N("control");
  return W(
    {
      ...n,
      labelFor: t ?? i,
      content: de(e, {
        ...n,
        id: i
      })
    },
    ...r
  );
}
function Ie(e) {
  return e.split(".").map((t) => {
    const n = t.match(/^\[(\d+)\]$/);
    return n ? Number(n[1]) : t;
  });
}
function pe(e) {
  return typeof e == "number" ? `[${e}]` : `.${e}`;
}
function fe(e) {
  if (e.length === 0) return "";
  const [s, ...t] = e;
  return [
    typeof s == "number" ? `[${s}]` : s,
    ...t.map(pe)
  ].join("");
}
function L(e) {
  return function(t) {
    if (t.type === "valid") return t;
    let n = t.error;
    for (const r of e)
      if (n = n?.dependencies?.[r], n == null) return g.valid;
    return g.invalid(n);
  };
}
class _ {
  path;
  change;
  signal;
  status;
  error;
  hasError;
  touched;
  errorVisible;
  dirty;
  dependencyErrors;
  #e = {
    disabled: S(!1),
    touched: S(!1)
  };
  #t;
  #s = S(void 0);
  parent;
  disabled;
  #n = [];
  disabledOrHasErrors;
  constructor(s, t, n, r, i, l = V) {
    this.path = s, this.change = t, this.signal = n, this.status = r, this.#t = l, this.#s.set(n.value), this.error = r.map(
      (a) => a?.type === "invalid" ? a.error?.message : void 0
    ), this.hasError = this.error.map((a) => a != null), this.touched = this.#e.touched, i.validationMode ? this.errorVisible = w(
      this.hasError,
      this.touched,
      i.validationMode
    )((a, c, p) => p === "eager" ? !!a : !!a && !!c) : this.errorVisible = w(
      this.hasError,
      this.touched
    )((a, c) => !!a && !!c), this.dirty = w(
      this.signal,
      this.#s
    )((a, c) => !this.#t(a, c)), this.dependencyErrors = r.map(
      (a) => a?.type === "invalid" ? a.error?.dependencies : void 0
    ), this.parent = i, this.disabled = w(
      this.#e.disabled,
      i.disabled
    )((a, c) => a || c), this.disabledOrHasErrors = w(
      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 fe(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 = V) => new me(
    this.path,
    this.change,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    this.signal,
    this.status,
    this.parent,
    s
  );
  object = (s = V) => new be(
    this.path,
    this.change,
    this.signal,
    this.status,
    this.parent,
    s
  );
  transform = (s, t, n = [], r = V) => new _(
    [...this.path, ...n],
    (i) => this.change(t(i)),
    this.signal.map(s, r),
    this.status.map(L(n)),
    this.parent,
    r
  );
  asyncTransform = (s, t, n, r = [], i = V) => new _(
    [...this.path, ...r],
    (l) => {
      t(l).then((a) => this.change(a));
    },
    this.signal.mapAsync(s, n, void 0, i),
    this.status.map(L(r)),
    this.parent,
    i
  );
}
class be extends _ {
  #e = /* @__PURE__ */ new Map();
  #t = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #n = S(!1);
  touchedDeep = this.#n;
  #i = /* @__PURE__ */ new Map();
  #r = /* @__PURE__ */ new Map();
  #l = S(!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, r, i, l) {
    super(
      s,
      t,
      n.map((c) => c ?? {}, l),
      r,
      i,
      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.#r.values()) c();
      this.#r.clear(), this.#i.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 _(
      [...this.path, s],
      t,
      this.signal.map((l) => l[s]),
      this.status.map(L([s])),
      {
        disabled: this.disabled,
        // propagate validationMode to children if present
        validationMode: this.parent.validationMode
      }
    );
    this.#e.set(s, n);
    const r = n.touched.on((l) => {
      this.#t.set(s, l), this.#c();
    });
    this.#s.set(s, r);
    const i = n.dirty.on((l) => {
      this.#i.set(s, l), this.#a();
    });
    return this.#r.set(s, i), n;
  };
  markAllTouched = () => {
    this.markTouched();
    const s = this.signal.value;
    for (const t of Object.keys(s))
      this.field(t).markTouched();
    for (const t of this.#e.values())
      t.markTouched();
  };
  markAllPristine = () => {
    this.markPristine();
    const s = this.signal.value;
    for (const t of Object.keys(s))
      this.field(t).markPristine?.();
    for (const t of this.#e.values())
      t.markPristine?.();
  };
  #a = () => {
    let s = !1;
    for (const t of this.#i.values())
      if (t) {
        s = !0;
        break;
      }
    this.#l.set(this.dirty.value || s);
  };
}
class me extends _ {
  #e = new Array();
  length;
  #t = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #n = S(!1);
  touchedDeep = this.#n;
  #i = /* @__PURE__ */ new Map();
  #r = /* @__PURE__ */ new Map();
  #l = S(!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, r, i, l) {
    const a = n.map((u) => u ?? [], l);
    super(s, t, a, r, i, l);
    const c = a.on((u) => {
      const m = this.#e.length - u.length;
      m > 0 && (this.#e.splice(u.length, m).forEach((k, D) => {
        const h = u.length + D;
        k.dispose(), this.#s.get(h)?.(), this.#s.delete(h), this.#t.delete(h), this.#r.get(h)?.(), this.#r.delete(h), this.#i.delete(h);
      }), this.#c(), this.#a());
    });
    this.length = a.map((u) => u.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 u of this.#e)
        u.dispose();
      this.length.dispose(), this.#e.length = 0, c(), a.dispose();
      for (const u of this.#s.values()) u();
      this.#s.clear(), this.#t.clear(), this.#n.dispose();
      for (const u of this.#r.values()) u();
      this.#r.clear(), this.#i.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 _(
      [...this.path, s],
      t,
      this.signal.map((l) => l[s]),
      this.status.map(L([s])),
      {
        disabled: this.disabled,
        validationMode: this.parent.validationMode
      }
    );
    this.#e[s] = n;
    const r = n.touched.on((l) => {
      this.#t.set(s, l), this.#c();
    });
    this.#s.set(s, r);
    const i = n.dirty.on((l) => {
      this.#i.set(s, l), this.#a();
    });
    return this.#r.set(s, i), n;
  };
  push = (...s) => {
    this.change([...this.signal.value, ...s]);
  };
  pop = () => {
    this.splice(this.signal.value.length - 1, 1);
  };
  shift = () => {
    this.splice(0, 1);
  };
  unshift = (...s) => {
    this.change([...s, ...this.signal.value]);
  };
  removeAt = (s) => {
    this.splice(s, 1);
  };
  splice = (s, t) => {
    const n = this.signal.value.slice();
    n.splice(s, t), this.change(n);
  };
  move = (s, t, n = 1) => {
    if (n < 1 || s === t) return;
    const r = this.signal.value.slice(), i = r.splice(s, n);
    r.splice(t, 0, ...i), this.change(r);
  };
  markAllTouched = () => {
    this.markTouched();
    const s = this.signal.value.length;
    for (let t = 0; t < s; t++)
      this.item(t).markTouched();
  };
  markAllPristine = () => {
    this.markPristine();
    const s = this.signal.value.length;
    for (let t = 0; t < s; t++)
      this.item(t).markPristine?.();
  };
  #a = () => {
    let s = !1;
    for (const t of this.#i.values())
      if (t) {
        s = !0;
        break;
      }
    this.#l.set(this.dirty.value || s);
  };
}
function ge(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 ve(e) {
  const s = e.filter((r) => r.path == null || r.path.length === 0).map((r) => r.message), t = e.filter((r) => r.path != null && r.path.length > 0).reduce((r, i) => {
    const l = ge(i.path), a = l.pop();
    let c = r;
    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: i.message }, r;
  }, {}), n = s.join(`
`);
  return {
    ...t,
    message: n != "" ? n : void 0
  };
}
function ye({
  initialValue: e,
  onChange: s,
  validate: t,
  equals: n,
  validationMode: r,
  validateDebounceMs: i
}) {
  const l = E.deriveProp(e), a = S(g.valid), c = S(!1), p = S(r ?? "onTouched"), u = (v) => {
    a.set(v);
  };
  let m;
  const k = async (v) => {
    if (t != null) {
      const C = await t(v);
      u(C);
    }
  }, D = async (v) => {
    l.set(v), s?.(v);
    const C = p.value;
    if (t != null) {
      if (C === "onSubmit")
        return;
      const M = i ?? 0;
      M > 0 ? (m && clearTimeout(m), m = setTimeout(() => {
        k(v);
      }, M)) : await k(v);
    }
  }, h = new _(
    [],
    D,
    l,
    a,
    {
      disabled: c,
      validationMode: p
    },
    n ?? V
  );
  return h.onDispose(() => {
    c.dispose(), l.dispose(), a.dispose(), p.dispose(), m && clearTimeout(m);
  }), { controller: h, setStatus: u };
}
function G(e) {
  return q(o.disabled(e.disabled), o.name(e.name));
}
function Ve(e, {
  triggerOn: s = "change"
} = {}) {
  return q(
    G(e),
    o.value(e.signal),
    (s === "input" ? I.input : I.change)(ee(e.change))
  );
}
function Me(e, {
  triggerOn: s = "change"
} = {}) {
  return q(
    G(e),
    o.valueAsNumber(e.signal),
    (s === "input" ? I.input : I.change)(
      se(e.change)
    )
  );
}
function U(e) {
  return e.issues != null ? g.invalid(ve(e.issues)) : g.valid;
}
async function Fe({
  task: e,
  errorMessage: s,
  errorPath: t = ["root"],
  validation: n
}) {
  try {
    const r = await e();
    return n != null ? n(r) : g.valid;
  } catch (r) {
    const i = s ?? (r instanceof Error ? r.message : "Operation failed");
    return t.length === 1 && t[0] === "root" ? g.invalid({
      message: i
    }) : g.invalid({
      dependencies: J(t, i)
    });
  }
}
function J(e, s) {
  if (e.length === 1)
    return {
      [e[0]]: { message: s }
    };
  const [t, ...n] = e;
  return {
    [t]: {
      dependencies: J(n, s)
    }
  };
}
function Oe({
  initialValue: e = {},
  schema: s,
  onSubmit: t = async () => g.valid,
  validationMode: n,
  validateDebounceMs: r
}) {
  const { controller: i, setStatus: l } = ye({
    initialValue: e,
    validationMode: n ?? "onTouched",
    validateDebounceMs: r,
    validate: (n ?? "onTouched") === "onSubmit" || s == null ? void 0 : async (u) => U(
      await s["~standard"].validate(u)
    )
  }), a = S(!1), c = i.object();
  return c.onDispose(a.dispose), {
    controller: c,
    setStatus: l,
    submit: async (u) => {
      if (a.set(!0), u?.preventDefault(), c.markAllTouched(), s != null) {
        const k = c.signal.value, D = U(
          await s["~standard"].validate(k)
        );
        if (l(D), D.type === "invalid") {
          a.set(!1);
          return;
        }
      }
      const m = await t(c.signal.value);
      a.set(!1), m.type === "invalid" && l(m);
    },
    submitting: a
  };
}
export {
  me as A,
  K as B,
  Se as C,
  Ce as D,
  De as E,
  W as I,
  ie as L,
  ae as M,
  V as O,
  le as R,
  Te as S,
  g as a,
  Ee as b,
  _e as c,
  z as d,
  _ as e,
  L as f,
  be as g,
  ye as h,
  de as i,
  Ae as j,
  fe as k,
  ge as l,
  he as m,
  ve as n,
  G as o,
  Ie as p,
  Ve as q,
  Me as r,
  N as s,
  Fe as t,
  Oe as u,
  U as v,
  pe as w
};
