import { isArray, isString, isFunction } from "../../../../../@vue/shared/dist/shared.esm-bundler.mjs";
import { selectKey } from "./token.mjs";
import { defineComponent, inject } from "vue";
import isEqual from "../../../../../lodash-es/isEqual.mjs";
var options_default = defineComponent({
  name: "ElOptions",
  setup(_, { slots }) {
    const select = inject(selectKey);
    let cachedValueList = [];
    return () => {
      var _a, _b;
      const children = (_a = slots.default) == null ? void 0 : _a.call(slots);
      const valueList = [];
      function filterOptions(children2) {
        if (!isArray(children2)) return;
        children2.forEach((item) => {
          var _a2, _b2, _c, _d;
          const name = (_a2 = (item == null ? void 0 : item.type) || {}) == null ? void 0 : _a2.name;
          if (name === "ElOptionGroup") filterOptions(!isString(item.children) && !isArray(item.children) && isFunction((_b2 = item.children) == null ? void 0 : _b2.default) ? (_c = item.children) == null ? void 0 : _c.default() : item.children);
          else if (name === "ElOption") valueList.push((_d = item.props) == null ? void 0 : _d.value);
          else if (isArray(item.children)) filterOptions(item.children);
        });
      }
      if (children.length) filterOptions((_b = children[0]) == null ? void 0 : _b.children);
      if (!isEqual(valueList, cachedValueList)) {
        cachedValueList = valueList;
        if (select) select.states.optionValues = valueList;
      }
      return children;
    };
  }
});
export {
  options_default as default
};
