import { Use as q, coalesce as G, aria as V, attr as c, on as M, html as m, Value as C, Empty as T, computedOf as y, When as A, dataAttr as P, TextNode as J, prop as k, Fragment as $, emitValue as Q, emitValueAsNumber as X } from "@tempots/dom";
import { B as Y, I as z } from "./translations-BGblCUBj.js";
import { B as Z, I as ee } from "./input-container-DhUiLmXE.js";
import { M as te, L as se, i as g } from "./stack-BJgsPJ9A.js";
import { s as j } from "./session-id-3KiilioY.js";
const E = (s, e) => s === e || s !== s && e !== e;
function we({
  size: s = "sm",
  icon: e = "line-md:close",
  disabled: t,
  roundedness: n = "full",
  color: i = "base",
  onClick: a,
  label: o
}, ...r) {
  return q(Y, (l) => {
    const d = G(o, l.$.closeModal);
    return Z(
      {
        variant: "text",
        size: s,
        roundedness: n,
        disabled: t,
        color: i,
        onClick: a
      },
      c.title(d),
      V.label(d),
      ...r,
      z({ icon: e, size: s ?? "sm" })
    );
  });
}
const De = (s) => {
  const {
    value: e,
    onBlur: t,
    onChange: n,
    placeholder: i,
    disabled: a,
    id: o,
    checkedIcon: r,
    uncheckedIcon: l,
    iconSize: d = "lg"
  } = s, h = o ?? j("checkbox"), p = `${h}-label`, v = () => {
    if (C.get(a ?? !1)) return;
    const u = C.get(e);
    n?.(!u);
  }, w = (u) => {
    C.get(a ?? !1) || (u.key === " " || u.key === "Enter") && (u.preventDefault(), v());
  };
  return ee(
    {
      baseContainer: !0,
      growInput: !1,
      ...s,
      input: m.span(
        c.class("bc-checkbox-input"),
        m.span(
          c.class("bc-checkbox-input__checkbox"),
          c.class(
            C.map(
              e,
              (u) => u ? "bc-checkbox-input__checkbox--checked" : "bc-checkbox-input__checkbox--unchecked"
            )
          ),
          c.class(
            C.map(
              a ?? !1,
              (u) => u ? "bc-checkbox-input__checkbox--disabled" : ""
            )
          ),
          c.id(h),
          c.role("checkbox"),
          c.tabindex(
            C.map(
              a ?? !1,
              (u) => u ? -1 : 0
            )
          ),
          V.checked(e),
          V.disabled(a),
          i != null ? V.labelledby(p) : T,
          M.keydown(w),
          t != null ? M.blur(t) : T,
          z({
            icon: y(
              e,
              r,
              l
            )(
              (u, f, D) => u ? f ?? "akar-icons/check-box-fill" : D ?? "akar-icons/box"
            ),
            accessibility: "decorative",
            size: d
          })
        ),
        i != null ? m.label(
          c.class("bc-checkbox-input__label"),
          c.id(p),
          c.for(h),
          te(i)
        ) : T
      )
    },
    M.click(v)
  );
}, ne = m.span(
  c.class("bc-input-wrapper__required"),
  " *"
);
function ie(s) {
  const e = ["bc-input-wrapper"];
  return s !== "vertical" && e.push(`bc-input-wrapper--${s}`), e.join(" ");
}
function re(s, e) {
  const t = ["bc-input-wrapper__label-text"];
  return s ? t.push("bc-input-wrapper__label-text--error") : e ? t.push("bc-input-wrapper__label-text--disabled") : t.push("bc-input-wrapper__label-text--default"), t.join(" ");
}
function ae(s, e) {
  if (s === "horizontal-fixed" && e != null)
    return `--input-wrapper-label-width: ${e}`;
}
const L = ({
  fullWidth: s = !1,
  required: e,
  label: t,
  labelChildren: n,
  context: i,
  description: a,
  content: o,
  error: r,
  labelFor: l,
  hasError: d,
  disabled: h,
  layout: p,
  labelWidth: v
}, ...w) => {
  const u = d ?? r != null, f = h ?? !1, D = p ?? "vertical", S = j("input-wrapper"), x = a ? `${S}-description` : void 0, O = r != null ? `${S}-error` : void 0, H = y(D)((b) => b !== "vertical"), K = y(
    D,
    v ?? void 0
  )((b, I) => ae(b, I));
  return m.div(
    c.class(C.map(D, (b) => ie(b))),
    c.class(
      C.map(
        s,
        (b) => b ? "bc-input-wrapper--full-width" : ""
      )
    ),
    c.style(K),
    t != null || i != null ? m.div(
      c.class("bc-input-wrapper__header"),
      m.div(
        c.class("bc-input-wrapper__label-section"),
        m.label(
          c.class("bc-input-wrapper__label"),
          l != null ? c.for(l) : T,
          m.span(
            c.class(
              y(
                u,
                f
              )(
                (b, I) => re(
                  b ?? !1,
                  I ?? !1
                )
              )
            ),
            t
          ),
          t != null && e ? ne : T
        ),
        // Show description under label when horizontal
        A(
          y(
            H,
            a
          )((b, I) => b && I != null),
          () => m.div(
            c.class(
              "bc-input-wrapper__description bc-input-wrapper__description--under-label"
            ),
            c.id(x),
            a
          )
        )
      ),
      i != null ? se(i) : T,
      n
    ) : T,
    m.div(
      c.class("bc-input-wrapper__content"),
      // Add data attributes to help inputs inherit accessibility information
      [x, O].filter(Boolean).length > 0 ? P.describedby(
        [x, O].filter(Boolean).join(" ")
      ) : T,
      e ? P.required("true") : T,
      A(u, () => P.invalid("true")),
      o
    ),
    // Show description at bottom only when not horizontal
    A(
      y(H, a)((b, I) => !b && I != null),
      () => m.div(
        c.class("bc-input-wrapper__description"),
        c.id(x),
        a
      )
    ),
    A(
      u,
      () => m.div(
        c.class("bc-input-wrapper__error"),
        c.id(O),
        V.live("polite"),
        // Announce errors to screen readers
        c.role("alert"),
        // Mark as alert for immediate attention
        r
      )
    ),
    ...w
  );
}, oe = (
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  ((s, e) => () => {
    s.markTouched(), e?.();
  })
), F = (s, e) => (t) => {
  s.change(t), e?.(t);
};
function W(s, e) {
  const { controller: t, onBlur: n, onChange: i, id: a, triggerOn: o, ...r } = e;
  return s({
    id: a ?? t.name,
    disabled: t.disabled,
    value: t.signal,
    hasError: t.errorVisible,
    name: t.name,
    ...r,
    onInput: o === "input" ? F(t, i) : void 0,
    onChange: o !== "input" ? F(t, i) : void 0,
    onBlur: oe(t, n)
  });
}
function Ce(s, { id: e, labelFor: t, ...n }, ...i) {
  const a = e ?? n.controller.name ?? j("control"), o = t ?? a;
  return L(
    {
      ...n,
      hasError: n.controller.errorVisible,
      error: J(n.controller.error.map((r) => r ?? "")),
      labelFor: o,
      content: W(
        (r) => s({ ...r, id: a }),
        n
      )
    },
    ...i
  );
}
function le(s, e) {
  const { toInput: t, fromInput: n, controller: i, ...a } = e, o = i.transform(t, n);
  return W(s, {
    ...a,
    controller: o
  });
}
function Te(s, {
  id: e,
  labelFor: t,
  ...n
}, ...i) {
  const a = e ?? n.controller.name ?? j("control");
  return L(
    {
      ...n,
      labelFor: t ?? a,
      content: le(s, {
        ...n,
        id: a
      })
    },
    ...i
  );
}
function _e(s) {
  return s.split(".").map((t) => {
    const n = t.match(/^\[(\d+)\]$/);
    return n ? Number(n[1]) : t;
  });
}
function ce(s) {
  return typeof s == "number" ? `[${s}]` : `.${s}`;
}
function he(s) {
  if (s.length === 0) return "";
  const [e, ...t] = s;
  return [
    typeof e == "number" ? `[${e}]` : e,
    ...t.map(ce)
  ].join("");
}
const Ie = {
  /** A valid validation result */
  valid: g.valid,
  /**
   * Create an invalid validation with a message
   */
  invalid(s) {
    return g.invalid({ message: s });
  },
  /**
   * Create an invalid validation with field-specific errors.
   * Values can be error messages (strings) or full ControllerError objects.
   */
  invalidFields(s) {
    const e = {};
    for (const [t, n] of Object.entries(s))
      e[t] = typeof n == "string" ? { message: n } : n;
    return g.invalid({ dependencies: e });
  },
  /**
   * Create an invalid validation from a ControllerError object
   */
  fromError(s) {
    return g.invalid(s);
  }
};
function B(s) {
  return function(t) {
    if (t.type === "valid") return t;
    let n = t.error;
    for (const i of s)
      if (n = n?.dependencies?.[i], n == null) return g.valid;
    return g.invalid(n);
  };
}
class _ {
  /** The path segments identifying this controller's position in the form hierarchy (e.g., ['user', 'email']). */
  path;
  /** Callback to propagate value changes up to the parent form. */
  change;
  /** Reactive signal containing the current field value. */
  signal;
  /** Reactive signal containing the current validation state (valid, pending, or invalid with errors). */
  status;
  /** Reactive signal containing the current error message string, or undefined if valid. */
  error;
  /** Reactive signal indicating whether this field has any errors. */
  hasError;
  /** Reactive signal tracking whether the user has interacted with this field. */
  touched;
  /** Reactive signal indicating whether errors should be shown (respects validation mode and touched state). */
  errorVisible;
  /** Reactive signal tracking whether the current value differs from the baseline. */
  dirty;
  /** Reactive signal containing nested field errors for child controllers. */
  dependencyErrors;
  #e = {
    disabled: k(!1),
    touched: k(!1)
  };
  #s;
  #t = k(void 0);
  /** Parent controller context providing disabled state and optional validation mode. */
  parent;
  /** Reactive signal indicating whether this field is disabled (combines local and parent disabled state). */
  disabled;
  #n = [];
  /** Reactive signal indicating whether this field is disabled OR has errors (useful for submit button state). */
  disabledOrHasErrors;
  /**
   * Creates a new Controller instance.
   *
   * @param path - Field path segments in the form hierarchy
   * @param change - Callback to propagate value changes
   * @param signal - Reactive signal holding the field value
   * @param status - Reactive signal holding validation state
   * @param parent - Parent context with disabled state and optional validation mode
   * @param equals - Equality function for dirty tracking (defaults to strictEqual)
   */
  constructor(e, t, n, i, a, o = E) {
    this.path = e, this.change = t, this.signal = n, this.status = i, this.#s = o, this.#t.set(n.value), this.error = i.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 = y(
      this.hasError,
      this.touched,
      a.validationMode
    )((r, l, d) => d === "eager" ? !!r : !!r && !!l) : this.errorVisible = y(
      this.hasError,
      this.touched
    )((r, l) => !!r && !!l), this.dirty = y(
      this.signal,
      this.#t
    )((r, l) => !this.#s(r, l)), this.dependencyErrors = i.map(
      (r) => r?.type === "invalid" ? r.error?.dependencies : void 0
    ), this.parent = a, this.disabled = y(
      this.#e.disabled,
      a.disabled
    )((r, l) => r || l), this.disabledOrHasErrors = y(
      this.disabled,
      this.hasError
    )((r, l) => r || l), this.onDispose(() => {
      this.#e.disabled.dispose(), this.#e.touched.dispose(), this.disabled.dispose(), this.error.dispose(), this.errorVisible.dispose(), this.dirty.dispose(), this.#t.dispose(), this.dependencyErrors.dispose(), this.disabledOrHasErrors.dispose();
    });
  }
  /**
   * Returns the field name as a dot-separated string (e.g., "user.email").
   */
  get name() {
    return he(this.path);
  }
  /**
   * Registers a callback to be executed when this controller is disposed.
   *
   * @param callback - Function to execute on disposal
   */
  onDispose = (e) => {
    this.#n.push(e);
  };
  /**
   * Disposes all internal resources and registered callbacks.
   * Should be called when the controller is no longer needed to prevent memory leaks.
   */
  dispose = () => {
    for (const e of this.#n)
      try {
        e();
      } catch (t) {
        console.error("Error in dispose callback:", t);
      }
    this.#n.length = 0;
  };
  /**
   * Sets the disabled state for this field.
   *
   * @param disabled - Whether the field should be disabled
   */
  setDisabled = (e) => {
    this.#e.disabled.set(e);
  };
  /**
   * Disables this field.
   */
  disable = () => this.setDisabled(!0);
  /**
   * Enables this field.
   */
  enable = () => this.setDisabled(!1);
  /**
   * Marks this field as touched (user has interacted with it).
   */
  markTouched = () => {
    this.#e.touched.set(!0);
  };
  /**
   * Resets the touched state to false.
   */
  resetTouched = () => {
    this.#e.touched.set(!1);
  };
  /**
   * Marks the current value as the new baseline for dirty tracking.
   */
  markPristine = () => {
    this.#t.set(this.signal.value);
  };
  /**
   * Resets the field value to the baseline value.
   */
  reset = () => {
    this.change(this.#t.value);
  };
  /**
   * Casts this controller to an ArrayController for managing array values.
   *
   * @param equals - Equality function for array comparison (defaults to strictEqual)
   * @returns An ArrayController instance
   */
  array = (e = E) => new de(
    this.path,
    this.change,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    this.signal,
    this.status,
    this.parent,
    e
  );
  /**
   * Casts this controller to an ObjectController for managing object values with field access.
   *
   * @param equals - Equality function for object comparison (defaults to strictEqual)
   * @returns An ObjectController instance
   */
  object = (e = E) => new ue(
    this.path,
    this.change,
    this.signal,
    this.status,
    this.parent,
    e
  );
  /**
   * Creates a transformed controller that maps values bidirectionally.
   * Useful for converting between internal and display representations.
   *
   * @template Out - The transformed value type
   * @param transform - Function to convert from T to Out
   * @param untransform - Function to convert from Out back to T
   * @param subpath - Optional path segments to append
   * @param equals - Equality function for the transformed type
   * @returns A new Controller instance managing the transformed value
   *
   * @example
   * ```typescript
   * // Transform number to string for text input
   * const stringController = numberController.transform(
   *   (n) => n.toString(),
   *   (s) => parseFloat(s) || 0
   * )
   * ```
   */
  transform = (e, t, n = [], i = E) => new _(
    [...this.path, ...n],
    (a) => this.change(t(a)),
    this.signal.map(e, i),
    this.status.map(B(n)),
    this.parent,
    i
  );
  /**
   * Creates a transformed controller with async bidirectional mapping.
   * Useful for async operations like fetching related data or formatting.
   *
   * @template Out - The transformed value type
   * @param transform - Async function to convert from T to Out
   * @param untransform - Async function to convert from Out back to T
   * @param alt - Fallback value while async transform is pending
   * @param subpath - Optional path segments to append
   * @param equals - Equality function for the transformed type
   * @returns A new Controller instance managing the async-transformed value
   */
  asyncTransform = (e, t, n, i = [], a = E) => new _(
    [...this.path, ...i],
    (o) => {
      t(o).then((r) => this.change(r));
    },
    this.signal.mapAsync(e, n, void 0, a),
    this.status.map(B(i)),
    this.parent,
    a
  );
}
class ue extends _ {
  #e = /* @__PURE__ */ new Map();
  #s = /* @__PURE__ */ new Map();
  #t = /* @__PURE__ */ new Map();
  #n = k(!1);
  /** Reactive signal indicating whether this field or any child field is touched. */
  touchedDeep = this.#n;
  #r = /* @__PURE__ */ new Map();
  #i = /* @__PURE__ */ new Map();
  #o = k(!1);
  /** Reactive signal indicating whether this field or any child field is dirty. */
  dirtyDeep = this.#o;
  #c;
  #h;
  #l = () => {
    let e = !1;
    for (const t of this.#s.values())
      if (t) {
        e = !0;
        break;
      }
    this.#n.set(this.touched.value || e);
  };
  constructor(e, t, n, i, a, o) {
    super(
      e,
      t,
      n.map((l) => l ?? {}, o),
      i,
      a,
      o
    ), this.#c = this.touched.on(() => {
      this.#l();
    }), this.#h = this.dirty.on(() => {
      this.#a();
    });
    const r = this.signal.on(() => this.#a());
    this.onDispose(() => {
      for (const l of this.#e.values())
        l.dispose();
      this.#e.clear();
      for (const l of this.#t.values()) l();
      this.#t.clear(), this.#s.clear(), this.#n.dispose();
      for (const l of this.#i.values()) l();
      this.#i.clear(), this.#r.clear(), this.#o.dispose(), this.#c(), this.#h(), r();
    });
  }
  /**
   * Gets or creates a controller for a specific field in the object.
   * Controllers are cached and reused for the same field name.
   *
   * @template K - The field key type
   * @param field - The field name to access
   * @returns A Controller instance for the specified field
   *
   * @example
   * ```typescript
   * const emailController = userController.field('email')
   * const nameController = userController.field('name')
   * ```
   */
  field = (e) => {
    if (this.#e.has(e))
      return this.#e.get(e);
    const t = async (o) => {
      this.change({
        ...this.signal.value,
        [e]: o
      });
    }, n = new _(
      [...this.path, e],
      t,
      this.signal.map((o) => o[e]),
      this.status.map(B([e])),
      {
        disabled: this.disabled,
        // propagate validationMode to children if present
        validationMode: this.parent.validationMode
      }
    );
    this.#e.set(e, n);
    const i = n.touched.on((o) => {
      this.#s.set(e, o), this.#l();
    });
    this.#t.set(e, i);
    const a = n.dirty.on((o) => {
      this.#r.set(e, o), this.#a();
    });
    return this.#i.set(e, a), n;
  };
  /**
   * Marks this field and all child fields as touched recursively.
   * Useful for showing all validation errors when a form is submitted.
   */
  markAllTouched = () => {
    this.markTouched();
    const e = this.signal.value;
    for (const t of Object.keys(e))
      this.field(t).markTouched();
    for (const t of this.#e.values())
      t.markTouched();
  };
  /**
   * Marks this field and all child fields as pristine (resets baseline) recursively.
   */
  markAllPristine = () => {
    this.markPristine();
    const e = this.signal.value;
    for (const t of Object.keys(e))
      this.field(t).markPristine?.();
    for (const t of this.#e.values())
      t.markPristine?.();
  };
  #a = () => {
    let e = !1;
    for (const t of this.#r.values())
      if (t) {
        e = !0;
        break;
      }
    this.#o.set(this.dirty.value || e);
  };
}
class de extends _ {
  #e = new Array();
  /** Reactive signal containing the current array length. */
  length;
  #s = /* @__PURE__ */ new Map();
  #t = /* @__PURE__ */ new Map();
  #n = k(!1);
  /** Reactive signal indicating whether this array or any item is touched. */
  touchedDeep = this.#n;
  #r = /* @__PURE__ */ new Map();
  #i = /* @__PURE__ */ new Map();
  #o = k(!1);
  /** Reactive signal indicating whether this array or any item is dirty. */
  dirtyDeep = this.#o;
  #c;
  #h;
  #l = () => {
    let e = !1;
    for (const t of this.#s.values())
      if (t) {
        e = !0;
        break;
      }
    this.#n.set(this.touched.value || e);
  };
  constructor(e, t, n, i, a, o) {
    const r = n.map((h) => h ?? [], o);
    super(e, t, r, i, a, o);
    const l = r.on((h) => {
      const p = this.#e.length - h.length;
      p > 0 && (this.#e.splice(h.length, p).forEach((v, w) => {
        const u = h.length + w;
        v.dispose(), this.#t.get(u)?.(), this.#t.delete(u), this.#s.delete(u), this.#i.get(u)?.(), this.#i.delete(u), this.#r.delete(u);
      }), this.#l(), this.#a());
    });
    this.length = r.map((h) => h.length), this.#c = this.touched.on(() => {
      this.#l();
    }), this.#h = this.dirty.on(() => {
      this.#a();
    });
    const d = this.signal.on(() => this.#a());
    this.onDispose(() => {
      for (const h of this.#e)
        h.dispose();
      this.length.dispose(), this.#e.length = 0, l(), r.dispose();
      for (const h of this.#t.values()) h();
      this.#t.clear(), this.#s.clear(), this.#n.dispose();
      for (const h of this.#i.values()) h();
      this.#i.clear(), this.#r.clear(), this.#o.dispose(), this.#c(), this.#h(), d();
    });
  }
  /**
   * Gets or creates a controller for a specific array item by index.
   * Controllers are cached and reused for the same index.
   *
   * @param index - The zero-based index of the item
   * @returns A Controller instance for the specified item
   *
   * @example
   * ```typescript
   * const firstTaskController = tasksController.item(0)
   * const secondTaskController = tasksController.item(1)
   * ```
   */
  item = (e) => {
    if (this.#e[e])
      return this.#e[e];
    const t = async (o) => {
      const r = this.signal.value.slice();
      r[e] = o, this.change(r);
    }, n = new _(
      [...this.path, e],
      t,
      this.signal.map((o) => o[e]),
      this.status.map(B([e])),
      {
        disabled: this.disabled,
        validationMode: this.parent.validationMode
      }
    );
    this.#e[e] = n;
    const i = n.touched.on((o) => {
      this.#s.set(e, o), this.#l();
    });
    this.#t.set(e, i);
    const a = n.dirty.on((o) => {
      this.#r.set(e, o), this.#a();
    });
    return this.#i.set(e, a), n;
  };
  /**
   * Appends one or more items to the end of the array.
   *
   * @param value - Items to append
   */
  push = (...e) => {
    this.change([...this.signal.value, ...e]);
  };
  /**
   * Removes the last item from the array.
   */
  pop = () => {
    this.splice(this.signal.value.length - 1, 1);
  };
  /**
   * Removes the first item from the array.
   */
  shift = () => {
    this.splice(0, 1);
  };
  /**
   * Inserts one or more items at the beginning of the array.
   *
   * @param value - Items to prepend
   */
  unshift = (...e) => {
    this.change([...e, ...this.signal.value]);
  };
  /**
   * Removes the item at the specified index.
   *
   * @param index - Zero-based index of the item to remove
   */
  removeAt = (e) => {
    this.splice(e, 1);
  };
  /**
   * Removes items from the array starting at the specified index.
   *
   * @param start - Zero-based index to start removing items
   * @param deleteCount - Number of items to remove (optional)
   */
  splice = (e, t) => {
    const n = this.signal.value.slice();
    n.splice(e, t), this.change(n);
  };
  /**
   * Moves one or more items from one index to another within the array.
   *
   * @param from - Source index to move from
   * @param to - Destination index to move to
   * @param length - Number of items to move (defaults to 1)
   *
   * @example
   * ```typescript
   * controller.move(0, 2) // Move first item to third position
   * controller.move(2, 0, 2) // Move items at index 2-3 to the beginning
   * ```
   */
  move = (e, t, n = 1) => {
    if (n < 1 || e === t) return;
    const i = this.signal.value.slice(), a = i.splice(e, n);
    i.splice(t, 0, ...a), this.change(i);
  };
  /**
   * Marks this array and all item controllers as touched recursively.
   * Useful for showing all validation errors when a form is submitted.
   */
  markAllTouched = () => {
    this.markTouched();
    const e = this.signal.value.length;
    for (let t = 0; t < e; t++)
      this.item(t).markTouched();
  };
  /**
   * Marks this array and all item controllers as pristine (resets baseline) recursively.
   */
  markAllPristine = () => {
    this.markPristine();
    const e = this.signal.value.length;
    for (let t = 0; t < e; t++)
      this.item(t).markPristine?.();
  };
  #a = () => {
    let e = !1;
    for (const t of this.#r.values())
      if (t) {
        e = !0;
        break;
      }
    this.#o.set(this.dirty.value || e);
  };
}
function pe(s) {
  function e(t) {
    return typeof t == "number" ? t : t.toString();
  }
  return s.map(
    (t) => typeof t == "object" && t.key != null ? e(t.key) : e(t)
  );
}
function fe(s) {
  const e = s.filter((i) => i.path == null || i.path.length === 0).map((i) => i.message), t = s.filter((i) => i.path != null && i.path.length > 0).reduce((i, a) => {
    const o = pe(a.path), r = o.pop();
    let l = i;
    for (const d of o)
      l.dependencies == null && (l.dependencies = {}), l.dependencies[d] == null && (l.dependencies[d] = {}), l = l.dependencies[d];
    return l.dependencies == null && (l.dependencies = {}), l.dependencies[r] = { message: a.message }, i;
  }, {}), n = e.join(`
`);
  return {
    ...t,
    message: n != "" ? n : void 0
  };
}
function be({
  initialValue: s,
  onChange: e,
  validate: t,
  equals: n,
  validationMode: i,
  validateDebounceMs: a
}) {
  const o = C.deriveProp(s), r = k(g.valid), l = k(!1), d = k(i ?? "onTouched"), h = (f) => {
    r.set(f);
  };
  let p;
  const v = async (f) => {
    if (t != null) {
      const D = await t(f);
      h(D);
    }
  }, w = async (f) => {
    o.set(f), e?.(f);
    const D = d.value;
    if (t != null) {
      if (D === "onSubmit")
        return;
      const S = a ?? 0;
      S > 0 ? (p && clearTimeout(p), p = setTimeout(() => {
        v(f);
      }, S)) : await v(f);
    }
  }, u = new _(
    [],
    w,
    o,
    r,
    {
      disabled: l,
      validationMode: d
    },
    n ?? E
  );
  return u.onDispose(() => {
    l.dispose(), o.dispose(), r.dispose(), d.dispose(), p && clearTimeout(p);
  }), { controller: u, setStatus: h };
}
function R(s) {
  return $(c.disabled(s.disabled), c.name(s.name));
}
function Me(s, {
  triggerOn: e = "change"
} = {}) {
  return $(
    R(s),
    c.value(s.signal),
    (e === "input" ? M.input : M.change)(Q(s.change))
  );
}
function Ee(s, {
  triggerOn: e = "change"
} = {}) {
  return $(
    R(s),
    c.valueAsNumber(s.signal),
    (e === "input" ? M.input : M.change)(
      X(s.change)
    )
  );
}
function N(s) {
  return s.issues != null ? g.invalid(fe(s.issues)) : g.valid;
}
async function Se({
  task: s,
  errorMessage: e,
  errorPath: t = ["root"],
  validation: n
}) {
  try {
    const i = await s();
    return n != null ? n(i) : g.valid;
  } catch (i) {
    const a = e ?? (i instanceof Error ? i.message : "Operation failed");
    return t.length === 1 && t[0] === "root" ? g.invalid({
      message: a
    }) : g.invalid({
      dependencies: U(t, a)
    });
  }
}
function U(s, e) {
  if (s.length === 1)
    return {
      [s[0]]: { message: e }
    };
  const [t, ...n] = s;
  return {
    [t]: {
      dependencies: U(n, e)
    }
  };
}
function Ve({
  initialValue: s = {},
  schema: e,
  onSubmit: t = async () => g.valid,
  validationMode: n,
  validateDebounceMs: i
}) {
  const { controller: a, setStatus: o } = be({
    initialValue: s,
    validationMode: n ?? "onTouched",
    validateDebounceMs: i,
    validate: (n ?? "onTouched") === "onSubmit" || e == null ? void 0 : async (h) => N(
      await e["~standard"].validate(h)
    )
  }), r = k(!1), l = a.object();
  return l.onDispose(r.dispose), {
    controller: l,
    setStatus: o,
    submit: async (h) => {
      if (r.set(!0), h?.preventDefault(), l.markAllTouched(), e != null) {
        const v = l.signal.value, w = N(
          await e["~standard"].validate(v)
        );
        if (o(w), w.type === "invalid") {
          r.set(!1);
          return;
        }
      }
      const p = await t(l.signal.value);
      r.set(!1), p.type === "invalid" && o(p);
    },
    submitting: r
  };
}
export {
  de as A,
  W as B,
  we as C,
  L as I,
  Te as M,
  E as O,
  ne as R,
  De as a,
  Ce as b,
  F as c,
  _ as d,
  B as e,
  ue as f,
  be as g,
  le as h,
  he as i,
  Ie as j,
  pe as k,
  fe as l,
  oe as m,
  R as n,
  Me as o,
  _e as p,
  Ee as q,
  N as s,
  Se as t,
  Ve as u,
  ce as w
};
