"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const shared_esmBundler = require("../../../../../@vue/shared/dist/shared.esm-bundler.js");
const index = require("../../../hooks/use-namespace/index.js");
const token = require("./token.js");
const index$1 = require("../../../../node_modules/@vueuse/core/index.js");
const Vue = require("vue");
const castArray = require("../../../../../lodash-es/castArray.js");
var option_group_vue_vue_type_script_lang_default = Vue.defineComponent({
  name: "ElOptionGroup",
  componentName: "ElOptionGroup",
  props: {
    label: String,
    disabled: Boolean
  },
  setup(props) {
    const ns = index.useNamespace("select");
    const groupRef = Vue.ref();
    const instance = Vue.getCurrentInstance();
    const children = Vue.ref([]);
    Vue.provide(token.selectGroupKey, Vue.reactive({ ...Vue.toRefs(props) }));
    const visible = Vue.computed(() => children.value.some((option) => option.visible === true));
    const isOption = (node) => {
      var _a;
      return node.type.name === "ElOption" && !!((_a = node.component) == null ? void 0 : _a.proxy);
    };
    const flattedChildren = (node) => {
      const nodes = castArray.default(node);
      const children2 = [];
      nodes.forEach((child) => {
        var _a;
        if (!Vue.isVNode(child)) return;
        if (isOption(child)) children2.push(child.component.proxy);
        else if (shared_esmBundler.isArray(child.children) && child.children.length) children2.push(...flattedChildren(child.children));
        else if ((_a = child.component) == null ? void 0 : _a.subTree) children2.push(...flattedChildren(child.component.subTree));
      });
      return children2;
    };
    const updateChildren = () => {
      children.value = flattedChildren(instance.subTree);
    };
    Vue.onMounted(() => {
      updateChildren();
    });
    index$1.useMutationObserver(groupRef, updateChildren, {
      attributes: true,
      subtree: true,
      childList: true
    });
    return {
      groupRef,
      visible,
      ns
    };
  }
});
exports.default = option_group_vue_vue_type_script_lang_default;
