import { defineComponent, withDirectives, cloneVNode } from "vue";
import { isArray } from "../_utils/is.mjs";
import { useReiszeObserverDirective } from "../hooks/use-element-resize.mjs";
import "../_utils/global.mjs";
import { isElement, isComponent } from "../_utils/vue-utils.mjs";
const bindEvent = (child, vResizeObserver) => {
  if (isElement(child) || isComponent(child)) {
    return withDirectives(cloneVNode(child), [[vResizeObserver]]);
  } else if (isArray(child.children)) {
    child.children = child.children.map((item) => {
      return bindEvent(item, vResizeObserver);
    });
    return child;
  } else {
    return child;
  }
};
const OResizeObserver = defineComponent({
  name: "OResizeObserver",
  emits: ["resize"],
  setup(_props, { emit, slots }) {
    const { vResizeObserver } = useReiszeObserverDirective((entry, isFirst) => {
      emit("resize", entry, isFirst);
    });
    return () => {
      var _a;
      const children = (_a = slots.default) == null ? void 0 : _a.call(slots);
      return children == null ? void 0 : children.map((item) => {
        return bindEvent(item, vResizeObserver);
      });
    };
  }
});
export {
  OResizeObserver as default
};
