"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = _interopRequireWildcard(require("vue"));

var _tabs = _interopRequireDefault(require("../tabs"));

var _row = _interopRequireDefault(require("../row"));

var _col = _interopRequireDefault(require("../col"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _propsUtil = require("../_util/props-util");

var _BaseMixin = _interopRequireDefault(require("../_util/BaseMixin"));

var _configProvider = require("../config-provider");

var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var TabPane = _tabs.default.TabPane;
var _default2 = {
  name: 'ACard',
  mixins: [_BaseMixin.default],
  props: {
    prefixCls: _vueTypes.default.string,
    title: _vueTypes.default.any,
    extra: _vueTypes.default.any,
    bordered: _vueTypes.default.bool.def(true),
    bodyStyle: _vueTypes.default.object,
    headStyle: _vueTypes.default.object,
    loading: _vueTypes.default.bool.def(false),
    hoverable: _vueTypes.default.bool.def(false),
    type: _vueTypes.default.string,
    size: _vueTypes.default.oneOf(['default', 'small']),
    actions: _vueTypes.default.any,
    tabList: _vueTypes.default.array,
    tabBarExtraContent: _vueTypes.default.any,
    activeTabKey: _vueTypes.default.string,
    defaultActiveTabKey: _vueTypes.default.string,
    cover: _vueTypes.default.any,
    onTabChange: _vueTypes.default.func
  },
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps)
    };
  },
  data: function data() {
    return {
      widerPadding: false
    };
  },
  methods: {
    getAction: function getAction(actions) {
      var actionList = actions.map(function (action, index) {
        return (0, _vue.isVNode)(action) && !(0, _propsUtil.isEmptyElement)(action) || !(0, _vue.isVNode)(action) ? _vue.createVNode("li", {
          "style": {
            width: "".concat(100 / actions.length, "%")
          },
          "key": "action-".concat(index)
        }, [_vue.createVNode("span", null, [action])]) : null;
      });
      return actionList;
    },
    triggerTabChange: function triggerTabChange(key) {
      this.$emit('tabChange', key);
    },
    isContainGrid: function isContainGrid() {
      var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var containGrid;
      obj.forEach(function (element) {
        if (element && (0, _isPlainObject.default)(element.type) && element.type.__ANT_CARD_GRID) {
          containGrid = true;
        }
      });
      return containGrid;
    }
  },
  render: function render() {
    var _classString, _tabsProps;

    var _this$$props = this.$props,
        customizePrefixCls = _this$$props.prefixCls,
        _this$$props$headStyl = _this$$props.headStyle,
        headStyle = _this$$props$headStyl === void 0 ? {} : _this$$props$headStyl,
        _this$$props$bodyStyl = _this$$props.bodyStyle,
        bodyStyle = _this$$props$bodyStyl === void 0 ? {} : _this$$props$bodyStyl,
        loading = _this$$props.loading,
        _this$$props$bordered = _this$$props.bordered,
        bordered = _this$$props$bordered === void 0 ? true : _this$$props$bordered,
        _this$$props$size = _this$$props.size,
        size = _this$$props$size === void 0 ? 'default' : _this$$props$size,
        type = _this$$props.type,
        tabList = _this$$props.tabList,
        hoverable = _this$$props.hoverable,
        activeTabKey = _this$$props.activeTabKey,
        defaultActiveTabKey = _this$$props.defaultActiveTabKey;
    var $slots = this.$slots;
    var children = (0, _propsUtil.getSlot)(this);
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('card', customizePrefixCls);
    var tabBarExtraContent = (0, _propsUtil.getComponent)(this, 'tabBarExtraContent');
    var classString = (_classString = {}, _defineProperty(_classString, "".concat(prefixCls), true), _defineProperty(_classString, "".concat(prefixCls, "-loading"), loading), _defineProperty(_classString, "".concat(prefixCls, "-bordered"), bordered), _defineProperty(_classString, "".concat(prefixCls, "-hoverable"), !!hoverable), _defineProperty(_classString, "".concat(prefixCls, "-contain-grid"), this.isContainGrid(children)), _defineProperty(_classString, "".concat(prefixCls, "-contain-tabs"), tabList && tabList.length), _defineProperty(_classString, "".concat(prefixCls, "-").concat(size), size !== 'default'), _defineProperty(_classString, "".concat(prefixCls, "-type-").concat(type), !!type), _classString);
    var loadingBlockStyle = bodyStyle.padding === 0 || bodyStyle.padding === '0px' ? {
      padding: 24
    } : undefined;

    var loadingBlock = _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-loading-content"),
      "style": loadingBlockStyle
    }, [_vue.createVNode(_row.default, {
      "gutter": 8
    }, {
      default: function _default() {
        return [_vue.createVNode(_col.default, {
          "span": 22
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        })];
      }
    }), _vue.createVNode(_row.default, {
      "gutter": 8
    }, {
      default: function _default() {
        return [_vue.createVNode(_col.default, {
          "span": 8
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        }), _vue.createVNode(_col.default, {
          "span": 15
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        })];
      }
    }), _vue.createVNode(_row.default, {
      "gutter": 8
    }, {
      default: function _default() {
        return [_vue.createVNode(_col.default, {
          "span": 6
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        }), _vue.createVNode(_col.default, {
          "span": 18
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        })];
      }
    }), _vue.createVNode(_row.default, {
      "gutter": 8
    }, {
      default: function _default() {
        return [_vue.createVNode(_col.default, {
          "span": 13
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        }), _vue.createVNode(_col.default, {
          "span": 9
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        })];
      }
    }), _vue.createVNode(_row.default, {
      "gutter": 8
    }, {
      default: function _default() {
        return [_vue.createVNode(_col.default, {
          "span": 4
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        }), _vue.createVNode(_col.default, {
          "span": 3
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        }), _vue.createVNode(_col.default, {
          "span": 16
        }, {
          default: function _default() {
            return [_vue.createVNode("div", {
              "class": "".concat(prefixCls, "-loading-block")
            }, null)];
          }
        })];
      }
    })]);

    var hasActiveTabKey = activeTabKey !== undefined;
    var tabsProps = (_tabsProps = {
      size: 'large'
    }, _defineProperty(_tabsProps, hasActiveTabKey ? 'activeKey' : 'defaultActiveKey', hasActiveTabKey ? activeTabKey : defaultActiveTabKey), _defineProperty(_tabsProps, "tabBarExtraContent", tabBarExtraContent), _defineProperty(_tabsProps, "onChange", this.triggerTabChange), _defineProperty(_tabsProps, "class", "".concat(prefixCls, "-head-tabs")), _tabsProps);
    var head;
    var tabs = tabList && tabList.length ? _vue.createVNode(_tabs.default, tabsProps, {
      default: function _default() {
        return [tabList.map(function (item) {
          var temp = item.tab,
              _item$scopedSlots = item.scopedSlots,
              scopedSlots = _item$scopedSlots === void 0 ? {} : _item$scopedSlots,
              _item$slots = item.slots,
              slots = _item$slots === void 0 ? {} : _item$slots;
          var name = slots.tab || scopedSlots.tab;
          var tab = temp !== undefined ? temp : $slots[name] ? $slots[name](item) : null;
          return _vue.createVNode(TabPane, {
            "tab": tab,
            "key": item.key,
            "disabled": item.disabled
          }, null);
        })];
      }
    }) : null;
    var titleDom = (0, _propsUtil.getComponent)(this, 'title');
    var extraDom = (0, _propsUtil.getComponent)(this, 'extra');

    if (titleDom || extraDom || tabs) {
      head = _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-head"),
        "style": headStyle
      }, [_vue.createVNode("div", {
        "class": "".concat(prefixCls, "-head-wrapper")
      }, [titleDom && _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-head-title")
      }, [titleDom]), extraDom && _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-extra")
      }, [extraDom])]), tabs]);
    }

    var cover = (0, _propsUtil.getComponent)(this, 'cover');
    var coverDom = cover ? _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-cover")
    }, [cover]) : null;

    var body = _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-body"),
      "style": bodyStyle
    }, [loading ? loadingBlock : children]);

    var actions = (0, _propsUtil.getComponent)(this, 'actions');
    var actionDom = actions && actions.length ? _vue.createVNode("ul", {
      "class": "".concat(prefixCls, "-actions")
    }, [this.getAction(actions)]) : null;
    return _vue.createVNode("div", {
      "class": classString,
      "ref": "cardContainerRef"
    }, [head, coverDom, children ? body : null, actionDom]);
  }
};
exports.default = _default2;