import { ref, inject, provide, onMounted, unref, onBeforeUnmount } from "vue";
import d from "./collection2.mjs";
import _ from "./collection-item.mjs";
const M = "data-el-collection-item", v = (C) => {
  const l = `El${C}Collection`, s = `${l}Item`, c = Symbol(l), m = Symbol(s), f = {
    ...d,
    name: l,
    setup() {
      const i = ref(null), t = /* @__PURE__ */ new Map();
      provide(c, {
        itemMap: t,
        getItems: () => {
          const o = unref(i);
          if (!o)
            return [];
          const e = Array.from(o.querySelectorAll(`[${M}]`));
          return [...t.values()].sort((N, p) => e.indexOf(N.ref) - e.indexOf(p.ref));
        },
        collectionRef: i
      });
    }
  }, O = {
    ..._,
    name: s,
    setup(i, { attrs: t }) {
      const n = ref(null), o = inject(c, void 0);
      provide(m, {
        collectionItemRef: n
      }), onMounted(() => {
        const e = unref(n);
        e && o.itemMap.set(e, {
          ref: e,
          ...t
        });
      }), onBeforeUnmount(() => {
        const e = unref(n);
        o.itemMap.delete(e);
      });
    }
  };
  return {
    COLLECTION_INJECTION_KEY: c,
    COLLECTION_ITEM_INJECTION_KEY: m,
    ElCollection: f,
    ElCollectionItem: O
  };
};
export {
  M as COLLECTION_ITEM_SIGN,
  v as createCollectionWithScope
};
