'use strict';

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

var vue = require('vue');
var isPlainObject = require('lodash-es/isPlainObject');
require('../tabs/index.js');
var index = require('../_util/vue-types/index.js');
var index$2 = require('../_util/props-util/index.js');
require('../hooks/index.js');
var devWarning = require('../vc-util/devWarning.js');
require('../skeleton/index.js');
var index$1 = require('./style/index.js');
var Tabs = require('../tabs/src/Tabs.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var Skeleton = require('../skeleton/Skeleton.js');

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
const {
  TabPane
} = Tabs.default;
const cardProps = () => ({
  prefixCls: String,
  title: index.default.any,
  extra: index.default.any,
  bordered: {
    type: Boolean,
    default: true
  },
  bodyStyle: {
    type: Object,
    default: void 0
  },
  headStyle: {
    type: Object,
    default: void 0
  },
  loading: {
    type: Boolean,
    default: false
  },
  hoverable: {
    type: Boolean,
    default: false
  },
  type: {
    type: String
  },
  size: {
    type: String
  },
  actions: index.default.any,
  tabList: {
    type: Array
  },
  tabBarExtraContent: index.default.any,
  activeTabKey: String,
  defaultActiveTabKey: String,
  cover: index.default.any,
  onTabChange: {
    type: Function
  }
});
const Card = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ACard",
  inheritAttrs: false,
  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) && !index$2.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 && 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 = index$2.filterEmptyWithUndefined((_a = slots.tabBarExtraContent) == null ? void 0 : _a.call(slots)),
        title = index$2.filterEmptyWithUndefined((_b = slots.title) == null ? void 0 : _b.call(slots)),
        extra = index$2.filterEmptyWithUndefined((_c = slots.extra) == null ? void 0 : _c.call(slots)),
        actions = index$2.filterEmptyWithUndefined((_d = slots.actions) == null ? void 0 : _d.call(slots)),
        cover = index$2.filterEmptyWithUndefined((_e = slots.cover) == null ? void 0 : _e.call(slots))
      } = props;
      const children = index$2.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(Skeleton.default, {
        "loading": true,
        "active": true,
        "paragraph": {
          rows: 4
        },
        "title": false
      }, _isSlot(children) ? children : {
        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(Tabs.default, tabsProps, {
        default: () => [tabList.map((item) => {
          const {
            tab: temp,
            slots: itemSlots
          } = item;
          const name = itemSlots == null ? void 0 : itemSlots.tab;
          devWarning.default(!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", vue.mergeProps({
        "ref": "cardContainerRef"
      }, attrs, {
        "class": [classString, attrs.class]
      }), [head, coverDom, children && children.length ? body : null, actionDom]));
    };
  }
});

exports.cardProps = cardProps;
exports.default = Card;
//# sourceMappingURL=Card.js.map
