import { jsx as I } from "react/jsx-runtime";
import { useFieldArray as j } from "react-hook-form";
import { useCallback as a } from "react";
import k from "../../../box/Box.js";
import { c as B } from "../../../../index-BtlgVD4m.js";
const D = ({
  name: o,
  control: f,
  children: v,
  defaultValue: i,
  min: c,
  max: r,
  disabled: y = !1
}) => {
  const { fields: e, append: l, prepend: p, remove: h, swap: A, move: C, insert: g, update: $, replace: w } = j({
    control: f,
    name: o
  }), S = a(
    (n, t) => {
      const s = n ?? i, d = Array.isArray(s) ? s.length : 1;
      if (r && e.length + d > r) {
        console.warn(`Cannot add more than ${r} items to ${String(o)}`);
        return;
      }
      s !== void 0 && l(s, t);
    },
    [l, i, e.length, r, o]
  ), m = a(
    (n) => {
      const t = n ?? i, s = Array.isArray(t) ? t.length : 1;
      if (r && e.length + s > r) {
        console.warn(`Cannot add more than ${r} items to ${String(o)}`);
        return;
      }
      t !== void 0 && p(t);
    },
    [p, i, e.length, r, o]
  ), u = a(
    (n) => {
      const t = Array.isArray(n) ? n.length : 1;
      if (c && e.length - t < c) {
        console.warn(`Cannot remove below ${c} items from ${String(o)}`);
        return;
      }
      n !== void 0 && h(n);
    },
    [h, e.length, c, o]
  ), b = a(
    (n, t, s) => {
      const d = t ?? i, F = Array.isArray(d) ? d.length : 1;
      if (r && e.length + F > r) {
        console.warn(`Cannot add more than ${r} items to ${String(o)}`);
        return;
      }
      d !== void 0 && g(n, d, s);
    },
    [g, i, e.length, r, o]
  );
  return /* @__PURE__ */ I(k, { className: B("flex flex-col gap-[var(--spacing-4)]", y && "pointer-events-none opacity-50"), children: v({
    fields: e,
    append: S,
    prepend: m,
    remove: u,
    swap: A,
    move: C,
    insert: b,
    update: $,
    replace: w
  }) });
};
export {
  D as default
};
//# sourceMappingURL=FieldArrayInner.js.map
