import { Use as X, coalesce as Y, aria as L, attr as d, html as y, on as V, Value as F, Empty as D, computedOf as S, When as N, dataAttr as B, TextNode as Z, prop as w, Fragment as q, emitValue as ee, emitValueAsNumber as se } from "@tempots/dom";
import { a as te, B as re, c as R, b as ie } from "./translations-BEMKy6-W.js";
const H = /* @__PURE__ */ new Map();
function x(e) {
  const s = H.get(e) ?? 0;
  return H.set(e, s + 1), `${e}-${s}`;
}
const a = {
  /**
   * 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 a.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 a.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 a.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 a.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 (a.isSuccess(e))
      return e.value;
    throw a.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: r,
    notAsked: i = r
  }) => a.isSuccess(e) ? s(e.value) : a.isFailure(e) ? t(e.error) : a.isNotAsked(e) ? i() : r(e.previousValue),
  /**
   * Executes side effects based on the state of the result.
   * Unlike `match`, all handlers are optional, allowing you to react only to specific states.
   * The `else` handler is called when no specific handler is provided for the current state.
   * @param r - The result.
   * @param handlers - An object with optional handlers for each state and an optional `else` fallback.
   * @returns The result that was passed in, allowing for chaining.
   * @public
   */
  effect: (e, s) => {
    switch (e.type) {
      case "AsyncSuccess":
        s.success ? s.success(e.value) : s.else?.();
        break;
      case "AsyncFailure":
        s.failure ? s.failure(e.error) : s.else?.();
        break;
      case "Loading":
        s.loading ? s.loading(e.previousValue) : s.else?.();
        break;
      case "NotAsked":
        s.notAsked ? s.notAsked() : s.else?.();
        break;
    }
    return e;
  },
  /**
   * 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) => (a.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) => (a.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: (r, i) => r === i,
    errorEquals: (r, i) => r === 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 (a.isSuccess(t))
        s.push(t.value);
      else
        return t;
    return a.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 a.success(s);
    } catch (s) {
      return a.failure(s instanceof Error ? s : new Error(String(s)));
    }
  },
  /**
   * Maps the value of a successful `AsyncResult` to a new value using the provided function.
   * For other states (NotAsked, Loading, Failure), the state is preserved.
   * When mapping a Loading state with a previous value, the previous value is also mapped.
   * @param result - The `AsyncResult` to map.
   * @param fn - The mapping function to apply to the success value.
   * @returns A new `AsyncResult` with the mapped value if successful, otherwise the original state.
   * @public
   */
  map: (e, s) => {
    switch (e.type) {
      case "AsyncSuccess":
        return a.success(s(e.value));
      case "NotAsked":
        return a.notAsked;
      case "AsyncFailure":
        return a.failure(e.error);
      case "Loading":
        return a.loading(
          e.previousValue != null ? s(e.previousValue) : void 0
        );
    }
  },
  /**
   * Maps the value of a successful `AsyncResult` to a new `AsyncResult` using the provided function.
   * This is useful for chaining operations that may also fail.
   * @param result - The `AsyncResult` to flat map.
   * @param fn - The mapping function that returns a new `AsyncResult`.
   * @returns The result of the mapping function if successful, otherwise the original state.
   * @public
   */
  flatMap: (e, s) => {
    switch (e.type) {
      case "AsyncSuccess":
        return s(e.value);
      case "NotAsked":
        return a.notAsked;
      case "AsyncFailure":
        return a.failure(e.error);
      case "Loading":
        return a.loading();
    }
  },
  /**
   * Maps the error of a failed `AsyncResult` to a new error using the provided function.
   * For other states, the state is preserved.
   * @param result - The `AsyncResult` to map the error of.
   * @param fn - The mapping function to apply to the error.
   * @returns A new `AsyncResult` with the mapped error if failed, otherwise the original state.
   * @public
   */
  mapError: (e, s) => {
    switch (e.type) {
      case "AsyncSuccess":
        return a.success(e.value);
      case "NotAsked":
        return a.notAsked;
      case "AsyncFailure":
        return a.failure(s(e.error));
      case "Loading":
        return a.loading(e.previousValue);
    }
  },
  /**
   * Maps the error of a failed `AsyncResult` to a new `AsyncResult` using the provided function.
   * This allows recovery from errors by returning a new successful result.
   * @param result - The `AsyncResult` to recover from.
   * @param fn - The recovery function that returns a new `AsyncResult`.
   * @returns The result of the recovery function if failed, otherwise the original state.
   * @public
   */
  flatMapError: (e, s) => {
    switch (e.type) {
      case "AsyncSuccess":
        return a.success(e.value);
      case "NotAsked":
        return a.notAsked;
      case "AsyncFailure":
        return s(e.error);
      case "Loading":
        return a.loading(e.previousValue);
    }
  },
  /**
   * Converts an `AsyncResult` to a `Result`, discarding the loading and not-asked states.
   * Returns `undefined` if the result is not settled (i.e., NotAsked or Loading).
   * @param result - The `AsyncResult` to convert.
   * @returns A `Result` if the `AsyncResult` is settled, otherwise `undefined`.
   * @public
   */
  toResult: (e) => {
    switch (e.type) {
      case "AsyncSuccess":
        return { type: "Success", value: e.value };
      case "AsyncFailure":
        return { type: "Failure", error: e.error };
      case "NotAsked":
      case "Loading":
        return;
    }
  },
  /**
   * Checks if the result is settled (either success or failure).
   * @param r - The result.
   * @returns `true` if the result is settled; otherwise, `false`.
   * @public
   */
  isSettled(e) {
    return e.type === "AsyncSuccess" || e.type === "AsyncFailure";
  },
  /**
   * Recovers from a failure by providing an alternative value.
   * @param result - The `AsyncResult` to recover from.
   * @param fn - The function that provides an alternative value given the error.
   * @returns A successful `AsyncResult` with the alternative value if failed, otherwise the original state.
   * @public
   */
  recover: (e, s) => {
    switch (e.type) {
      case "AsyncSuccess":
        return a.success(e.value);
      case "NotAsked":
        return a.notAsked;
      case "AsyncFailure":
        return a.success(s(e.error));
      case "Loading":
        return a.loading(e.previousValue);
    }
  },
  /**
   * Applies a function wrapped in an `AsyncResult` to a value wrapped in an `AsyncResult`.
   * Useful for applying multiple arguments to a function in a safe way.
   * @param resultFn - The `AsyncResult` containing the function.
   * @param resultVal - The `AsyncResult` containing the value.
   * @returns A new `AsyncResult` with the result of applying the function to the value.
   * @public
   */
  ap: (e, s) => a.isSuccess(e) && a.isSuccess(s) ? a.success(e.value(s.value)) : a.isFailure(e) ? a.failure(e.error) : a.isFailure(s) ? a.failure(s.error) : a.isLoading(e) || a.isLoading(s) ? a.loading() : a.notAsked,
  /**
   * Maps two `AsyncResult` values using a function.
   * @param r1 - The first `AsyncResult`.
   * @param r2 - The second `AsyncResult`.
   * @param fn - The function to apply to both values.
   * @returns A new `AsyncResult` with the result of applying the function to both values.
   * @public
   */
  map2: (e, s, t) => a.isSuccess(e) && a.isSuccess(s) ? a.success(t(e.value, s.value)) : a.isFailure(e) ? a.failure(e.error) : a.isFailure(s) ? a.failure(s.error) : a.isLoading(e) || a.isLoading(s) ? a.loading() : a.notAsked,
  /**
   * Maps three `AsyncResult` values using a function.
   * @param r1 - The first `AsyncResult`.
   * @param r2 - The second `AsyncResult`.
   * @param r3 - The third `AsyncResult`.
   * @param fn - The function to apply to all three values.
   * @returns A new `AsyncResult` with the result of applying the function to all three values.
   * @public
   */
  map3: (e, s, t, r) => a.isSuccess(e) && a.isSuccess(s) && a.isSuccess(t) ? a.success(r(e.value, s.value, t.value)) : a.isFailure(e) ? a.failure(e.error) : a.isFailure(s) ? a.failure(s.error) : a.isFailure(t) ? a.failure(t.error) : a.isLoading(e) || a.isLoading(s) || a.isLoading(t) ? a.loading() : a.notAsked
}, T = (e, s) => e === s || e !== e && s !== s, h = {
  /**
   * 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) => h.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) => h.match(
    e,
    () => c.success(s),
    (t) => c.failure(t)
  ),
  /**
   * Executes side effects based on the state of the validation.
   * Unlike `match`, all handlers are optional, allowing you to react only to specific states.
   * The `else` handler is called when no specific handler is provided for the current state.
   * @param v - The validation.
   * @param handlers - An object with optional handlers for each state and an optional `else` fallback.
   * @returns The validation that was passed in, allowing for chaining.
   * @public
   */
  effect: (e, s) => (e.type === "valid" ? s.valid ? s.valid() : s.else?.() : s.invalid ? s.invalid(e.error) : s.else?.(), e),
  /**
   * 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) => (h.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) => (h.isInvalid(e) && s(e.error), e),
  /**
   * Maps the error of an invalid `Validation` to a new error using the provided function.
   * For valid validations, the validation is preserved unchanged.
   * @param v - The `Validation` to map the error of.
   * @param f - The mapping function to apply to the error.
   * @returns A new `Validation` with the mapped error if invalid, otherwise the original valid.
   * @public
   */
  mapError: (e, s) => e.type === "invalid" ? h.invalid(s(e.error)) : e,
  /**
   * Maps the error of an invalid `Validation` to a new `Validation` using the provided function.
   * This allows recovery from errors by returning a valid validation.
   * @param v - The `Validation` to recover from.
   * @param f - The recovery function that returns a new `Validation`.
   * @returns The result of the recovery function if invalid, otherwise the original valid.
   * @public
   */
  flatMapError: (e, s) => e.type === "invalid" ? s(e.error) : e,
  /**
   * Combines two validations. Both must be valid for the result to be valid.
   * If both are invalid, errors are combined using the provided function.
   * @param v1 - The first validation.
   * @param v2 - The second validation.
   * @param combineErrors - The function to combine two errors.
   * @returns A combined validation.
   * @public
   */
  combine: (e, s, t) => h.isValid(e) && h.isValid(s) ? h.valid : h.isInvalid(e) && h.isInvalid(s) ? h.invalid(t(e.error, s.error)) : h.isInvalid(e) ? e : s,
  /**
   * Combines multiple validations into a single validation.
   * All must be valid for the result to be valid.
   * Returns the first invalid validation if any.
   * @param validations - The validations to combine.
   * @returns A single validation that is valid only if all inputs are valid.
   * @public
   */
  all: (e) => {
    for (const s of e)
      if (h.isInvalid(s))
        return s;
    return h.valid;
  },
  /**
   * Combines multiple validations, accumulating all errors.
   * All must be valid for the result to be valid.
   * If any are invalid, all errors are collected into an array.
   * @param validations - The validations to combine.
   * @returns A validation that is valid only if all inputs are valid, otherwise contains all errors.
   * @public
   */
  allErrors: (e) => {
    const s = [];
    for (const t of e)
      h.isInvalid(t) && s.push(t.error);
    return s.length > 0 ? h.invalid(s) : h.valid;
  },
  /**
   * Compares two validations for equality.
   * @param v1 - The first validation.
   * @param v2 - The second validation.
   * @param errorEquals - Optional custom equality function for errors. Defaults to strict equality.
   * @returns `true` if the validations are equal, `false` otherwise.
   * @public
   */
  equals: (e, s, t = (r, i) => r === i) => e.type === "valid" && s.type === "valid" ? !0 : e.type === "invalid" && s.type === "invalid" ? t(e.error, s.error) : !1,
  /**
   * Recovers from an invalid validation by returning a valid validation.
   * @param v - The `Validation` to recover from.
   * @returns A valid validation regardless of the input.
   * @public
   */
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  recover: (e) => h.valid,
  /**
   * Gets the error if the validation is invalid, otherwise returns undefined.
   * @param v - The validation to get the error from.
   * @returns The error if invalid, otherwise undefined.
   * @public
   */
  getError: (e) => {
    if (h.isInvalid(e))
      return e.error;
  },
  /**
   * Gets the error if the validation is invalid, otherwise returns the default value.
   * @param v - The validation to get the error from.
   * @param defaultError - The default error to return if valid.
   * @returns The error if invalid, otherwise the default error.
   * @public
   */
  getErrorOrElse: (e, s) => h.isInvalid(e) ? e.error : s
}, c = {
  /**
   * 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" ? c.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 c.match(
      e,
      (s) => a.success(s),
      (s) => a.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 c.match(
      e,
      () => h.valid,
      (s) => h.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 c.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 c.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 c.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 c.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 (c.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) => c.isSuccess(e) ? s(e.value) : t(e.error),
  /**
   * Executes side effects based on the state of the result.
   * Unlike `match`, all handlers are optional, allowing you to react only to specific states.
   * The `else` handler is called when no specific handler is provided for the current state.
   * @param r - The result.
   * @param handlers - An object with optional handlers for each state and an optional `else` fallback.
   * @returns The result that was passed in, allowing for chaining.
   * @public
   */
  effect: (e, s) => (e.type === "Success" ? s.success ? s.success(e.value) : s.else?.() : s.failure ? s.failure(e.error) : s.else?.(), e),
  /**
   * 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) => (c.isSuccess(e) && s(e.value), e),
  /**
   * Calls the provided function if the result is a failure.
   * @param apply - The function to call if the result is a failure.
   * @returns The result that was passed in.
   * @public
   */
  whenFailure: (e, s) => (c.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, r) => c.match(
    e,
    (i) => c.match(
      s,
      (n) => c.success(t(i, n)),
      (n) => c.failure(n)
    ),
    (i) => c.match(
      s,
      // eslint-disable-next-line @typescript-eslint/no-unused-vars
      (n) => c.failure(i),
      (n) => c.failure(r(i, n))
    )
  ),
  /**
   * 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: (r, i) => r === i,
    errorEquals: (r, i) => r === 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 (c.isSuccess(t))
        s.push(t.value);
      else
        return t;
    return c.success(s);
  },
  /**
   * Maps the error of a failed `Result` to a new error using the provided function.
   * For success results, the result is preserved unchanged.
   * @param r - The `Result` to map the error of.
   * @param f - The mapping function to apply to the error.
   * @returns A new `Result` with the mapped error if failed, otherwise the original success.
   * @public
   */
  mapError: (e, s) => e.type === "Failure" ? c.failure(s(e.error)) : e,
  /**
   * Maps the error of a failed `Result` to a new `Result` using the provided function.
   * This allows recovery from errors by returning a new successful result.
   * @param r - The `Result` to recover from.
   * @param f - The recovery function that returns a new `Result`.
   * @returns The result of the recovery function if failed, otherwise the original success.
   * @public
   */
  flatMapError: (e, s) => e.type === "Failure" ? s(e.error) : e,
  /**
   * Recovers from a failure by providing an alternative value.
   * @param r - The `Result` to recover from.
   * @param f - The function that provides an alternative value given the error.
   * @returns A successful `Result` with the alternative value if failed, otherwise the original success.
   * @public
   */
  recover: (e, s) => e.type === "Failure" ? { type: "Success", value: s(e.error) } : e,
  /**
   * Applies a function wrapped in a `Result` to a value wrapped in a `Result`.
   * Useful for applying multiple arguments to a function in a safe way.
   * @param resultFn - The `Result` containing the function.
   * @param resultVal - The `Result` containing the value.
   * @returns A new `Result` with the result of applying the function to the value.
   * @public
   */
  ap: (e, s) => c.isSuccess(e) && c.isSuccess(s) ? c.success(e.value(s.value)) : c.isFailure(e) ? c.failure(e.error) : c.failure(s.error),
  /**
   * Maps two `Result` values using a function.
   * @param r1 - The first `Result`.
   * @param r2 - The second `Result`.
   * @param f - The function to apply to both values.
   * @returns A new `Result` with the result of applying the function to both values.
   * @public
   */
  map2: (e, s, t) => c.isSuccess(e) && c.isSuccess(s) ? c.success(t(e.value, s.value)) : c.isFailure(e) ? c.failure(e.error) : c.failure(s.error),
  /**
   * Maps three `Result` values using a function.
   * @param r1 - The first `Result`.
   * @param r2 - The second `Result`.
   * @param r3 - The third `Result`.
   * @param f - The function to apply to all three values.
   * @returns A new `Result` with the result of applying the function to all three values.
   * @public
   */
  map3: (e, s, t, r) => c.isSuccess(e) && c.isSuccess(s) && c.isSuccess(t) ? c.success(r(e.value, s.value, t.value)) : c.isFailure(e) ? c.failure(e.error) : c.isFailure(s) ? c.failure(s.error) : c.failure(t.error),
  /**
   * Converts a Promise to a Result.
   * @param p - The Promise to convert.
   * @returns A Promise that resolves to a Result.
   * @public
   */
  ofPromise: async (e) => {
    try {
      const s = await e;
      return c.success(s);
    } catch (s) {
      return c.failure(s instanceof Error ? s : new Error(String(s)));
    }
  },
  /**
   * Swaps the success and failure values of a Result.
   * A success becomes a failure with the value as the error,
   * and a failure becomes a success with the error as the value.
   * @param r - The Result to swap.
   * @returns A new Result with swapped success and failure.
   * @public
   */
  swap: (e) => c.isSuccess(e) ? c.failure(e.value) : c.success(e.error),
  /**
   * Converts a nullable value to a Result.
   * @param value - The nullable value.
   * @param error - The error to use if the value is null or undefined.
   * @returns A Result containing the value if not null/undefined, otherwise a failure.
   * @public
   */
  fromNullable: (e, s) => e == null ? c.failure(s) : c.success(e),
  /**
   * Converts a nullable value to a Result using a lazy error function.
   * @param value - The nullable value.
   * @param errorFn - The function to call to get the error if the value is null or undefined.
   * @returns A Result containing the value if not null/undefined, otherwise a failure.
   * @public
   */
  fromNullableLazy: (e, s) => e == null ? c.failure(s()) : c.success(e),
  /**
   * Wraps a function that may throw into a function that returns a Result.
   * @param f - The function that may throw.
   * @returns A function that returns a Result instead of throwing.
   * @public
   */
  tryCatch: (e) => {
    try {
      return c.success(e());
    } catch (s) {
      return c.failure(s instanceof Error ? s : new Error(String(s)));
    }
  }
};
function we({
  size: e = "sm",
  icon: s = "line-md:close",
  disabled: t,
  roundedness: r = "full",
  color: i = "base",
  onClick: n,
  label: o
}, ...l) {
  return X(te, (u) => {
    const v = Y(o, u.$.closeModal);
    return re(
      {
        variant: "text",
        size: e,
        roundedness: r,
        disabled: t,
        color: i,
        onClick: n
      },
      d.title(v),
      L.label(v),
      ...l,
      R({ icon: s, size: e ?? "sm" })
    );
  });
}
function $(e) {
  return `bc-label bc-label--${e}`;
}
const Ae = (...e) => y.span(d.class($("emphasis")), ...e), ae = (...e) => y.span(d.class($("default")), ...e), ne = (...e) => y.span(d.class($("muted")), ...e), Ee = (...e) => y.span(d.class($("danger")), ...e), Fe = (e) => {
  const {
    value: s,
    onBlur: t,
    onChange: r,
    placeholder: i,
    disabled: n,
    id: o,
    checkedIcon: l,
    uncheckedIcon: u,
    iconSize: v = "lg"
  } = e, p = o ?? x("checkbox"), g = `${p}-label`, k = () => {
    if (F.get(n ?? !1)) return;
    const f = F.get(s);
    r?.(!f);
  }, A = (f) => {
    F.get(n ?? !1) || (f.key === " " || f.key === "Enter") && (f.preventDefault(), k());
  };
  return ie(
    {
      baseContainer: !0,
      growInput: !1,
      ...e,
      input: y.span(
        d.class("bc-checkbox-input"),
        y.span(
          d.class("bc-checkbox-input__checkbox"),
          d.class(
            F.map(
              s,
              (f) => f ? "bc-checkbox-input__checkbox--checked" : "bc-checkbox-input__checkbox--unchecked"
            )
          ),
          d.class(
            F.map(
              n ?? !1,
              (f) => f ? "bc-checkbox-input__checkbox--disabled" : ""
            )
          ),
          d.id(p),
          d.role("checkbox"),
          d.tabindex(
            F.map(
              n ?? !1,
              (f) => f ? -1 : 0
            )
          ),
          L.checked(s),
          L.disabled(n),
          i != null ? L.labelledby(g) : D,
          V.keydown(A),
          t != null ? V.blur(t) : D,
          R({
            icon: S(
              s,
              l,
              u
            )(
              (f, m, E) => f ? m ?? "akar-icons/check-box-fill" : E ?? "akar-icons/box"
            ),
            accessibility: "decorative",
            size: v
          })
        ),
        i != null ? y.label(
          d.class("bc-checkbox-input__label"),
          d.id(g),
          d.for(p),
          ne(i)
        ) : D
      )
    },
    V.click(k)
  );
}, le = y.span(
  d.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: r,
  context: i,
  description: n,
  content: o,
  error: l,
  labelFor: u,
  hasError: v,
  disabled: p,
  layout: g,
  labelWidth: k
}, ...A) => {
  const f = v ?? l != null, m = p ?? !1, E = g ?? "vertical", _ = x("input-wrapper"), M = n ? `${_}-description` : void 0, j = l != null ? `${_}-error` : void 0, P = S(E)((b) => b !== "vertical"), Q = S(
    E,
    k ?? void 0
  )((b, I) => ue(b, I));
  return y.div(
    d.class(F.map(E, (b) => ce(b))),
    d.class(
      F.map(
        e,
        (b) => b ? "bc-input-wrapper--full-width" : ""
      )
    ),
    d.style(Q),
    t != null || i != null ? y.div(
      d.class("bc-input-wrapper__header"),
      y.div(
        d.class("bc-input-wrapper__label-section"),
        y.label(
          d.class("bc-input-wrapper__label"),
          u != null ? d.for(u) : D,
          y.span(
            d.class(
              S(
                f,
                m
              )(
                (b, I) => oe(
                  b ?? !1,
                  I ?? !1
                )
              )
            ),
            t
          ),
          t != null && s ? le : D
        ),
        // Show description under label when horizontal
        N(
          S(
            P,
            n
          )((b, I) => b && I != null),
          () => y.div(
            d.class(
              "bc-input-wrapper__description bc-input-wrapper__description--under-label"
            ),
            d.id(M),
            n
          )
        )
      ),
      i != null ? ae(i) : D,
      r
    ) : D,
    y.div(
      d.class("bc-input-wrapper__content"),
      // Add data attributes to help inputs inherit accessibility information
      [M, j].filter(Boolean).length > 0 ? B.describedby(
        [M, j].filter(Boolean).join(" ")
      ) : D,
      s ? B.required("true") : D,
      N(f, () => B.invalid("true")),
      o
    ),
    // Show description at bottom only when not horizontal
    N(
      S(P, n)((b, I) => !b && I != null),
      () => y.div(
        d.class("bc-input-wrapper__description"),
        d.id(M),
        n
      )
    ),
    N(
      f,
      () => y.div(
        d.class("bc-input-wrapper__error"),
        d.id(j),
        L.live("polite"),
        // Announce errors to screen readers
        d.role("alert"),
        // Mark as alert for immediate attention
        l
      )
    ),
    ...A
  );
};
function De(...e) {
  return y.div(d.class("bc-stack"), ...e);
}
const de = (
  // 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: r, onChange: i, id: n, triggerOn: o, ...l } = s;
  return e({
    id: n ?? t.name,
    disabled: t.disabled,
    value: t.signal,
    hasError: t.errorVisible,
    name: t.name,
    ...l,
    onInput: o === "input" ? z(t, i) : void 0,
    onChange: o !== "input" ? z(t, i) : void 0,
    onBlur: de(t, r)
  });
}
function Ce(e, { id: s, labelFor: t, ...r }, ...i) {
  const n = s ?? r.controller.name ?? x("control"), o = t ?? n;
  return W(
    {
      ...r,
      hasError: r.controller.errorVisible,
      error: Z(r.controller.error.map((l) => l ?? "")),
      labelFor: o,
      content: K(
        (l) => e({ ...l, id: n }),
        r
      )
    },
    ...i
  );
}
function he(e, s) {
  const { toInput: t, fromInput: r, controller: i, ...n } = s, o = i.transform(t, r);
  return K(e, {
    ...n,
    controller: o
  });
}
function Ie(e, {
  id: s,
  labelFor: t,
  ...r
}, ...i) {
  const n = s ?? r.controller.name ?? x("control");
  return W(
    {
      ...r,
      labelFor: t ?? n,
      content: he(e, {
        ...r,
        id: n
      })
    },
    ...i
  );
}
function Ve(e) {
  return e.split(".").map((t) => {
    const r = t.match(/^\[(\d+)\]$/);
    return r ? Number(r[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("");
}
const Te = {
  /** A valid validation result */
  valid: h.valid,
  /**
   * Create an invalid validation with a message
   */
  invalid(e) {
    return h.invalid({ message: e });
  },
  /**
   * Create an invalid validation with field-specific errors.
   * Values can be error messages (strings) or full ControllerError objects.
   */
  invalidFields(e) {
    const s = {};
    for (const [t, r] of Object.entries(e))
      s[t] = typeof r == "string" ? { message: r } : r;
    return h.invalid({ dependencies: s });
  },
  /**
   * Create an invalid validation from a ControllerError object
   */
  fromError(e) {
    return h.invalid(e);
  }
};
function O(e) {
  return function(t) {
    if (t.type === "valid") return t;
    let r = t.error;
    for (const i of e)
      if (r = r?.dependencies?.[i], r == null) return h.valid;
    return h.invalid(r);
  };
}
class C {
  path;
  change;
  signal;
  status;
  error;
  hasError;
  touched;
  errorVisible;
  dirty;
  dependencyErrors;
  #e = {
    disabled: w(!1),
    touched: w(!1)
  };
  #t;
  #s = w(void 0);
  parent;
  disabled;
  #r = [];
  disabledOrHasErrors;
  constructor(s, t, r, i, n, o = T) {
    this.path = s, this.change = t, this.signal = r, this.status = i, this.#t = o, this.#s.set(r.value), this.error = i.map(
      (l) => l?.type === "invalid" ? l.error?.message : void 0
    ), this.hasError = this.error.map((l) => l != null), this.touched = this.#e.touched, n.validationMode ? this.errorVisible = S(
      this.hasError,
      this.touched,
      n.validationMode
    )((l, u, v) => v === "eager" ? !!l : !!l && !!u) : this.errorVisible = S(
      this.hasError,
      this.touched
    )((l, u) => !!l && !!u), this.dirty = S(
      this.signal,
      this.#s
    )((l, u) => !this.#t(l, u)), this.dependencyErrors = i.map(
      (l) => l?.type === "invalid" ? l.error?.dependencies : void 0
    ), this.parent = n, this.disabled = S(
      this.#e.disabled,
      n.disabled
    )((l, u) => l || u), this.disabledOrHasErrors = S(
      this.disabled,
      this.hasError
    )((l, u) => l || u), 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.#r.push(s);
  };
  dispose = () => {
    for (const s of this.#r)
      try {
        s();
      } catch (t) {
        console.error("Error in dispose callback:", t);
      }
    this.#r.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 = T) => new ye(
    this.path,
    this.change,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    this.signal,
    this.status,
    this.parent,
    s
  );
  object = (s = T) => new ve(
    this.path,
    this.change,
    this.signal,
    this.status,
    this.parent,
    s
  );
  transform = (s, t, r = [], i = T) => new C(
    [...this.path, ...r],
    (n) => this.change(t(n)),
    this.signal.map(s, i),
    this.status.map(O(r)),
    this.parent,
    i
  );
  asyncTransform = (s, t, r, i = [], n = T) => new C(
    [...this.path, ...i],
    (o) => {
      t(o).then((l) => this.change(l));
    },
    this.signal.mapAsync(s, r, void 0, n),
    this.status.map(O(i)),
    this.parent,
    n
  );
}
class ve extends C {
  #e = /* @__PURE__ */ new Map();
  #t = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #r = w(!1);
  touchedDeep = this.#r;
  #a = /* @__PURE__ */ new Map();
  #i = /* @__PURE__ */ new Map();
  #l = w(!1);
  dirtyDeep = this.#l;
  #o;
  #u;
  #c = () => {
    let s = !1;
    for (const t of this.#t.values())
      if (t) {
        s = !0;
        break;
      }
    this.#r.set(this.touched.value || s);
  };
  constructor(s, t, r, i, n, o) {
    super(
      s,
      t,
      r.map((u) => u ?? {}, o),
      i,
      n,
      o
    ), this.#o = this.touched.on(() => {
      this.#c();
    }), this.#u = this.dirty.on(() => {
      this.#n();
    });
    const l = this.signal.on(() => this.#n());
    this.onDispose(() => {
      for (const u of this.#e.values())
        u.dispose();
      this.#e.clear();
      for (const u of this.#s.values()) u();
      this.#s.clear(), this.#t.clear(), this.#r.dispose();
      for (const u of this.#i.values()) u();
      this.#i.clear(), this.#a.clear(), this.#l.dispose(), this.#o(), this.#u(), l();
    });
  }
  field = (s) => {
    if (this.#e.has(s))
      return this.#e.get(s);
    const t = async (o) => {
      this.change({
        ...this.signal.value,
        [s]: o
      });
    }, r = new C(
      [...this.path, s],
      t,
      this.signal.map((o) => o[s]),
      this.status.map(O([s])),
      {
        disabled: this.disabled,
        // propagate validationMode to children if present
        validationMode: this.parent.validationMode
      }
    );
    this.#e.set(s, r);
    const i = r.touched.on((o) => {
      this.#t.set(s, o), this.#c();
    });
    this.#s.set(s, i);
    const n = r.dirty.on((o) => {
      this.#a.set(s, o), this.#n();
    });
    return this.#i.set(s, n), r;
  };
  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?.();
  };
  #n = () => {
    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 C {
  #e = new Array();
  length;
  #t = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #r = w(!1);
  touchedDeep = this.#r;
  #a = /* @__PURE__ */ new Map();
  #i = /* @__PURE__ */ new Map();
  #l = w(!1);
  dirtyDeep = this.#l;
  #o;
  #u;
  #c = () => {
    let s = !1;
    for (const t of this.#t.values())
      if (t) {
        s = !0;
        break;
      }
    this.#r.set(this.touched.value || s);
  };
  constructor(s, t, r, i, n, o) {
    const l = r.map((p) => p ?? [], o);
    super(s, t, l, i, n, o);
    const u = l.on((p) => {
      const g = this.#e.length - p.length;
      g > 0 && (this.#e.splice(p.length, g).forEach((k, A) => {
        const f = p.length + A;
        k.dispose(), this.#s.get(f)?.(), this.#s.delete(f), this.#t.delete(f), this.#i.get(f)?.(), this.#i.delete(f), this.#a.delete(f);
      }), this.#c(), this.#n());
    });
    this.length = l.map((p) => p.length), this.#o = this.touched.on(() => {
      this.#c();
    }), this.#u = this.dirty.on(() => {
      this.#n();
    });
    const v = this.signal.on(() => this.#n());
    this.onDispose(() => {
      for (const p of this.#e)
        p.dispose();
      this.length.dispose(), this.#e.length = 0, u(), l.dispose();
      for (const p of this.#s.values()) p();
      this.#s.clear(), this.#t.clear(), this.#r.dispose();
      for (const p of this.#i.values()) p();
      this.#i.clear(), this.#a.clear(), this.#l.dispose(), this.#o(), this.#u(), v();
    });
  }
  item = (s) => {
    if (this.#e[s])
      return this.#e[s];
    const t = async (o) => {
      const l = this.signal.value.slice();
      l[s] = o, this.change(l);
    }, r = new C(
      [...this.path, s],
      t,
      this.signal.map((o) => o[s]),
      this.status.map(O([s])),
      {
        disabled: this.disabled,
        validationMode: this.parent.validationMode
      }
    );
    this.#e[s] = r;
    const i = r.touched.on((o) => {
      this.#t.set(s, o), this.#c();
    });
    this.#s.set(s, i);
    const n = r.dirty.on((o) => {
      this.#a.set(s, o), this.#n();
    });
    return this.#i.set(s, n), r;
  };
  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 r = this.signal.value.slice();
    r.splice(s, t), this.change(r);
  };
  move = (s, t, r = 1) => {
    if (r < 1 || s === t) return;
    const i = this.signal.value.slice(), n = i.splice(s, r);
    i.splice(t, 0, ...n), 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?.();
  };
  #n = () => {
    let s = !1;
    for (const t of this.#a.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 me(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, n) => {
    const o = ge(n.path), l = o.pop();
    let u = i;
    for (const v of o)
      u.dependencies == null && (u.dependencies = {}), u.dependencies[v] == null && (u.dependencies[v] = {}), u = u.dependencies[v];
    return u.dependencies == null && (u.dependencies = {}), u.dependencies[l] = { message: n.message }, i;
  }, {}), r = s.join(`
`);
  return {
    ...t,
    message: r != "" ? r : void 0
  };
}
function be({
  initialValue: e,
  onChange: s,
  validate: t,
  equals: r,
  validationMode: i,
  validateDebounceMs: n
}) {
  const o = F.deriveProp(e), l = w(h.valid), u = w(!1), v = w(i ?? "onTouched"), p = (m) => {
    l.set(m);
  };
  let g;
  const k = async (m) => {
    if (t != null) {
      const E = await t(m);
      p(E);
    }
  }, A = async (m) => {
    o.set(m), s?.(m);
    const E = v.value;
    if (t != null) {
      if (E === "onSubmit")
        return;
      const _ = n ?? 0;
      _ > 0 ? (g && clearTimeout(g), g = setTimeout(() => {
        k(m);
      }, _)) : await k(m);
    }
  }, f = new C(
    [],
    A,
    o,
    l,
    {
      disabled: u,
      validationMode: v
    },
    r ?? T
  );
  return f.onDispose(() => {
    u.dispose(), o.dispose(), l.dispose(), v.dispose(), g && clearTimeout(g);
  }), { controller: f, setStatus: p };
}
function G(e) {
  return q(d.disabled(e.disabled), d.name(e.name));
}
function _e(e, {
  triggerOn: s = "change"
} = {}) {
  return q(
    G(e),
    d.value(e.signal),
    (s === "input" ? V.input : V.change)(ee(e.change))
  );
}
function Le(e, {
  triggerOn: s = "change"
} = {}) {
  return q(
    G(e),
    d.valueAsNumber(e.signal),
    (s === "input" ? V.input : V.change)(
      se(e.change)
    )
  );
}
function U(e) {
  return e.issues != null ? h.invalid(me(e.issues)) : h.valid;
}
async function Me({
  task: e,
  errorMessage: s,
  errorPath: t = ["root"],
  validation: r
}) {
  try {
    const i = await e();
    return r != null ? r(i) : h.valid;
  } catch (i) {
    const n = s ?? (i instanceof Error ? i.message : "Operation failed");
    return t.length === 1 && t[0] === "root" ? h.invalid({
      message: n
    }) : h.invalid({
      dependencies: J(t, n)
    });
  }
}
function J(e, s) {
  if (e.length === 1)
    return {
      [e[0]]: { message: s }
    };
  const [t, ...r] = e;
  return {
    [t]: {
      dependencies: J(r, s)
    }
  };
}
function Ne({
  initialValue: e = {},
  schema: s,
  onSubmit: t = async () => h.valid,
  validationMode: r,
  validateDebounceMs: i
}) {
  const { controller: n, setStatus: o } = be({
    initialValue: e,
    validationMode: r ?? "onTouched",
    validateDebounceMs: i,
    validate: (r ?? "onTouched") === "onSubmit" || s == null ? void 0 : async (p) => U(
      await s["~standard"].validate(p)
    )
  }), l = w(!1), u = n.object();
  return u.onDispose(l.dispose), {
    controller: u,
    setStatus: o,
    submit: async (p) => {
      if (l.set(!0), p?.preventDefault(), u.markAllTouched(), s != null) {
        const k = u.signal.value, A = U(
          await s["~standard"].validate(k)
        );
        if (o(A), A.type === "invalid") {
          l.set(!1);
          return;
        }
      }
      const g = await t(u.signal.value);
      l.set(!1), g.type === "invalid" && o(g);
    },
    submitting: l
  };
}
export {
  ye as A,
  K as B,
  we as C,
  Ee as D,
  Ae as E,
  W as I,
  ae as L,
  ne as M,
  T as O,
  le as R,
  De as S,
  Fe as a,
  Ce as b,
  z as c,
  C as d,
  O as e,
  ve as f,
  be as g,
  he as h,
  h as i,
  Ie as j,
  fe as k,
  Te as l,
  de as m,
  ge as n,
  me as o,
  Ve as p,
  G as q,
  _e as r,
  x as s,
  Me as t,
  Ne as u,
  Le as v,
  pe as w,
  U as x
};
