import { defineComponent, isVNode, createVNode, renderSlot } from 'vue';
import { isPlainObject } from 'lodash-es';
import '../../../utils/index.mjs';
import { Tabs } from '../../tabs/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import { Skeleton } from '../../skeleton/index.mjs';
import useStyle from '../style/index.mjs';
import { cardProps } from './props.mjs';
import { isEmptyElement } from '../../../utils/is.mjs';
import { filterEmptyWithUndefined, flattenChildren } from '../../../utils/vue/props.mjs';
import { devWarning } from '../../../utils/log.mjs';

const {
  TabPane
} = Tabs;
var ACard = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ACard",
  inheritAttrs: false,
  props: cardProps(),
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction,
      size
    } = useConfigInject("card", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const getAction = (actions) => {
      const actionList = actions.map((action, index) => isVNode(action) && !isEmptyElement(action) || !isVNode(action) ? createVNode("li", {
        "style": {
          width: `${100 / actions.length}%`
        },
        "key": `action-${index}`
      }, [createVNode("span", null, [action])]) : null);
      return actionList;
    };
    const triggerTabChange = (key) => {
      var _a;
      (_a = props.onTabChange) == null ? void 0 : _a.call(props, key);
    };
    const isContainGrid = (obj = []) => {
      let containGrid;
      obj.forEach((element) => {
        if (element && isPlainObject(element.type) && element.type.__ANT_CARD_GRID)
          containGrid = true;
      });
      return containGrid;
    };
    return () => {
      var _a, _b, _c, _d, _e, _f;
      const {
        headStyle = {},
        bodyStyle = {},
        loading,
        bordered = true,
        type,
        tabList,
        hoverable,
        activeTabKey,
        defaultActiveTabKey,
        tabBarExtraContent = filterEmptyWithUndefined((_a = slots.tabBarExtraContent) == null ? void 0 : _a.call(slots)),
        title = filterEmptyWithUndefined((_b = slots.title) == null ? void 0 : _b.call(slots)),
        extra = filterEmptyWithUndefined((_c = slots.extra) == null ? void 0 : _c.call(slots)),
        actions = filterEmptyWithUndefined((_d = slots.actions) == null ? void 0 : _d.call(slots)),
        cover = filterEmptyWithUndefined((_e = slots.cover) == null ? void 0 : _e.call(slots))
      } = props;
      const children = flattenChildren((_f = slots.default) == null ? void 0 : _f.call(slots));
      const pre = prefixCls.value;
      const classString = {
        [`${pre}`]: true,
        [hashId.value]: true,
        [`${pre}-loading`]: loading,
        [`${pre}-bordered`]: bordered,
        [`${pre}-hoverable`]: !!hoverable,
        [`${pre}-contain-grid`]: isContainGrid(children),
        [`${pre}-contain-tabs`]: tabList && tabList.length,
        [`${pre}-${size.value}`]: size.value,
        [`${pre}-type-${type}`]: !!type,
        [`${pre}-rtl`]: direction.value === "rtl"
      };
      const loadingBlock = createVNode(Skeleton, {
        "loading": true,
        "active": true,
        "paragraph": {
          rows: 4
        },
        "title": false
      }, {
        default: () => [children]
      });
      const hasActiveTabKey = activeTabKey !== void 0;
      const tabsProps = {
        size: "large",
        [hasActiveTabKey ? "activeKey" : "defaultActiveKey"]: hasActiveTabKey ? activeTabKey : defaultActiveTabKey,
        onChange: triggerTabChange,
        class: `${pre}-head-tabs`
      };
      let head;
      const tabs = tabList && tabList.length ? createVNode(Tabs, tabsProps, {
        default: () => [tabList.map((item) => {
          const {
            tab: temp,
            slots: itemSlots
          } = item;
          const name = itemSlots == null ? void 0 : itemSlots.tab;
          devWarning(!itemSlots, "Card", "tabList slots is deprecated, Please use `customTab` instead.");
          let tab = temp !== void 0 ? temp : slots[name] ? slots[name](item) : null;
          tab = renderSlot(slots, "customTab", item, () => [tab]);
          return createVNode(TabPane, {
            "tab": tab,
            "key": item.key,
            "disabled": item.disabled
          }, null);
        })],
        rightExtra: tabBarExtraContent ? () => tabBarExtraContent : null
      }) : null;
      if (title || extra || tabs) {
        head = createVNode("div", {
          "class": `${pre}-head`,
          "style": headStyle
        }, [createVNode("div", {
          "class": `${pre}-head-wrapper`
        }, [title && createVNode("div", {
          "class": `${pre}-head-title`
        }, [title]), extra && createVNode("div", {
          "class": `${pre}-extra`
        }, [extra])]), tabs]);
      }
      const coverDom = cover ? createVNode("div", {
        "class": `${pre}-cover`
      }, [cover]) : null;
      const body = createVNode("div", {
        "class": `${pre}-body`,
        "style": bodyStyle
      }, [loading ? loadingBlock : children]);
      const actionDom = actions && actions.length ? createVNode("ul", {
        "class": `${pre}-actions`
      }, [getAction(actions)]) : null;
      return wrapSSR(createVNode("div", {
        "ref": "cardContainerRef",
        ...attrs,
        "class": [classString, attrs.class]
      }, [head, coverDom, children && children.length ? body : null, actionDom]));
    };
  }
});

export { ACard as default };
//# sourceMappingURL=Card.mjs.map
