import { defineComponent, createVNode } from 'vue';
import '../../../utils/index.mjs';
import { tabsProps } from './props.mjs';
import InternalTabs from './InternalTabs.mjs';
import { isValidElement } from '../../../utils/is.mjs';
import { camelize } from '../../../utils/lang/camelize.mjs';
import { initDefaultProps } from '../../../utils/vue/initDefaultProps.mjs';
import { flattenChildren } from '../../../utils/vue/props.mjs';
import { omit } from '../../../utils/lang/omit.mjs';

function parseTabList(children) {
  return children.map((node) => {
    if (isValidElement(node)) {
      const props = {
        ...node.props || {}
      };
      for (const [k, v] of Object.entries(props)) {
        delete props[k];
        props[camelize(k)] = v;
      }
      const slots = node.children || {};
      const key = node.key !== void 0 ? node.key : void 0;
      const {
        tab = slots.tab,
        disabled,
        forceRender,
        closable,
        animated,
        active,
        destroyInactiveTabPane
      } = props;
      return {
        key,
        ...props,
        node,
        closeIcon: slots.closeIcon,
        tab,
        disabled: disabled === "" || disabled,
        forceRender: forceRender === "" || forceRender,
        closable: closable === "" || closable,
        animated: animated === "" || animated,
        active: active === "" || active,
        destroyInactiveTabPane: destroyInactiveTabPane === "" || destroyInactiveTabPane
      };
    }
    return null;
  }).filter((tab) => tab);
}
var ATabs = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATabs",
  inheritAttrs: false,
  props: initDefaultProps(tabsProps(), {
    tabPosition: "top",
    animated: {
      inkBar: true,
      tabPane: false
    }
  }),
  slots: Object,
  // emits: ['tabClick', 'tabScroll', 'change', 'update:activeKey'],
  setup(props, {
    attrs,
    slots,
    emit
  }) {
    const handleChange = (key) => {
      emit("update:activeKey", key);
      emit("change", key);
    };
    return () => {
      var _a;
      const tabs = parseTabList(flattenChildren((_a = slots.default) == null ? void 0 : _a.call(slots)));
      return createVNode(InternalTabs, {
        ...omit(props, ["onUpdate:activeKey", "onChange"]),
        ...attrs,
        "onChange": handleChange,
        "tabs": tabs
      }, slots);
    };
  }
});

export { ATabs as default };
//# sourceMappingURL=Tabs.mjs.map
