'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var lodashEs = require('lodash-es');
require('../../../utils/index.cjs');
var index = require('../../tabs/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index$2 = require('../../skeleton/index.cjs');
var index$1 = require('../style/index.cjs');
var props = require('./props.cjs');
var is = require('../../../utils/is.cjs');
var props$1 = require('../../../utils/vue/props.cjs');
var log = require('../../../utils/log.cjs');

const {
  TabPane
} = index.Tabs;
var ACard = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ACard",
  inheritAttrs: false,
  props: props.cardProps(),
  slots: Object,
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction,
      size
    } = useConfigInject.default("card", props);
    const [wrapSSR, hashId] = index$1.default(prefixCls);
    const getAction = (actions) => {
      const actionList = actions.map((action, index) => vue.isVNode(action) && !is.isEmptyElement(action) || !vue.isVNode(action) ? vue.createVNode("li", {
        "style": {
          width: `${100 / actions.length}%`
        },
        "key": `action-${index}`
      }, [vue.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 && lodashEs.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 = props$1.filterEmptyWithUndefined((_a = slots.tabBarExtraContent) == null ? void 0 : _a.call(slots)),
        title = props$1.filterEmptyWithUndefined((_b = slots.title) == null ? void 0 : _b.call(slots)),
        extra = props$1.filterEmptyWithUndefined((_c = slots.extra) == null ? void 0 : _c.call(slots)),
        actions = props$1.filterEmptyWithUndefined((_d = slots.actions) == null ? void 0 : _d.call(slots)),
        cover = props$1.filterEmptyWithUndefined((_e = slots.cover) == null ? void 0 : _e.call(slots))
      } = props;
      const children = props$1.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 = vue.createVNode(index$2.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 ? vue.createVNode(index.Tabs, tabsProps, {
        default: () => [tabList.map((item) => {
          const {
            tab: temp,
            slots: itemSlots
          } = item;
          const name = itemSlots == null ? void 0 : itemSlots.tab;
          log.devWarning(!itemSlots, "Card", "tabList slots is deprecated, Please use `customTab` instead.");
          let tab = temp !== void 0 ? temp : slots[name] ? slots[name](item) : null;
          tab = vue.renderSlot(slots, "customTab", item, () => [tab]);
          return vue.createVNode(TabPane, {
            "tab": tab,
            "key": item.key,
            "disabled": item.disabled
          }, null);
        })],
        rightExtra: tabBarExtraContent ? () => tabBarExtraContent : null
      }) : null;
      if (title || extra || tabs) {
        head = vue.createVNode("div", {
          "class": `${pre}-head`,
          "style": headStyle
        }, [vue.createVNode("div", {
          "class": `${pre}-head-wrapper`
        }, [title && vue.createVNode("div", {
          "class": `${pre}-head-title`
        }, [title]), extra && vue.createVNode("div", {
          "class": `${pre}-extra`
        }, [extra])]), tabs]);
      }
      const coverDom = cover ? vue.createVNode("div", {
        "class": `${pre}-cover`
      }, [cover]) : null;
      const body = vue.createVNode("div", {
        "class": `${pre}-body`,
        "style": bodyStyle
      }, [loading ? loadingBlock : children]);
      const actionDom = actions && actions.length ? vue.createVNode("ul", {
        "class": `${pre}-actions`
      }, [getAction(actions)]) : null;
      return wrapSSR(vue.createVNode("div", {
        "ref": "cardContainerRef",
        ...attrs,
        "class": [classString, attrs.class]
      }, [head, coverDom, children && children.length ? body : null, actionDom]));
    };
  }
});

exports.default = ACard;
//# sourceMappingURL=Card.cjs.map
