import { defineComponent as _, computed as f, unref as s, renderSlot as k } from "vue";
import { isArray as K } from "lodash-unified";
import { useInjectForm as g } from "../context.mjs";
import h from "../hooks/use-regist-form.mjs";
const b = /* @__PURE__ */ _({
  name: "ApFormList",
  __name: "index",
  props: {
    name: {},
    initialValue: {},
    transform: { type: [Function, Object] }
  },
  setup(p) {
    let o = 1;
    const u = [], n = p, { model: i, updateModel: l } = g();
    h(n);
    const a = f(() => n.name ? K(n.name) ? n.name.reduce((e, t) => e?.[t], s(i)) : i?.value[n.name] : null);
    function d(e = void 0) {
      const t = s(a) ? [...s(a), e] : [e], r = o;
      return u.push(r), o += 1, l?.(n.name, t), r;
    }
    function y(e) {
      let t = s(a) || [];
      t = [...t.slice(0, e), ...t.slice(e + 1)], u.splice(e, 1), l?.(n.name, t);
    }
    function v() {
      return c.value.map((e) => e.key);
    }
    const F = {
      add: d,
      remove: y,
      getFieldKeys: v
    }, c = f(() => (s(a) || []).map((t, r) => {
      let m = u[r];
      return typeof m > "u" && (u[r] = o, m = o, o += 1), {
        key: m,
        fieldName: r,
        name: [n.name, r].flat(),
        value: t
      };
    }));
    return (e, t) => k(e.$slots, "default", {
      fields: c.value,
      actions: F
    });
  }
});
export {
  b as default
};
