"use strict";

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

var _tslib = require("tslib");

var _consoleComponents = require("@alicloud/console-components");

var _classnames = _interopRequireDefault(require("classnames"));

var _react = _interopRequireDefault(require("react"));

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

function LPCard(props) {
  var className = props.className,
      style = props.style,
      cardStyle = props.cardStyle,
      children = props.children,
      moreOption = props.moreOption,
      moreMenuPrpos = props.moreMenuPrpos,
      moreProps = props.moreProps,
      filterClassName = props.filterClassName,
      footerClassName = props.footerClassName,
      AuxiliaryInfo = props.AuxiliaryInfo,
      footerAction = props.footerAction,
      filterContent = props.filterContent,
      rest = (0, _tslib.__rest)(props, ["className", "style", "cardStyle", "children", "moreOption", "moreMenuPrpos", "moreProps", "filterClassName", "footerClassName", "AuxiliaryInfo", "footerAction", "filterContent"]);
  var menuArea = null;

  if (moreOption) {
    var menuItem = moreOption.map(function (item, index) {
      var name = item.name,
          rest = (0, _tslib.__rest)(item, ["name"]);
      return /*#__PURE__*/_react["default"].createElement(_consoleComponents.Menu.Item, (0, _tslib.__assign)({
        key: index + name
      }, rest, {
        onClick: function onClick(e) {
          item.onClick && item.onClick(name, item.key, item, e);
        }
      }), name);
    });
    menuArea = /*#__PURE__*/_react["default"].createElement(_consoleComponents.Dropdown, (0, _tslib.__assign)({
      trigger: /*#__PURE__*/_react["default"].createElement(_consoleComponents.Icon, {
        type: "more",
        size: "xs",
        className: "lp-card-more",
        style: {
          color: '#555'
        }
      }),
      triggerType: "click"
    }, moreProps), /*#__PURE__*/_react["default"].createElement(_consoleComponents.Menu, (0, _tslib.__assign)({}, moreMenuPrpos), menuItem));
  }

  var filterContent_ = filterContent ? /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("lp-card-filterArea", filterClassName)
  }, filterContent) : null;

  if (footerAction || AuxiliaryInfo) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "lp-card-containrt",
      style: style
    }, /*#__PURE__*/_react["default"].createElement(_consoleComponents.Card, (0, _tslib.__assign)({
      className: (0, _classnames["default"])("lp-card", className),
      extra: menuArea,
      style: cardStyle
    }, rest), filterContent_, children), /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])("lp-card-footer", footerClassName)
    }, AuxiliaryInfo ? /*#__PURE__*/_react["default"].createElement("div", {
      className: "lp-footer-left"
    }, AuxiliaryInfo) : null, footerAction ? /*#__PURE__*/_react["default"].createElement("div", {
      className: "lp-footer-right"
    }, footerAction) : null));
  } else {
    var style_ = cardStyle || style;
    return /*#__PURE__*/_react["default"].createElement(_consoleComponents.Card, (0, _tslib.__assign)({
      className: (0, _classnames["default"])("lp-card", className),
      extra: menuArea,
      showTitleBullet: false,
      contentHeight: "auto",
      style: style_
    }, rest), filterContent_, children);
  }
}

function Cards(props) {
  var dataSource = props.dataSource;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "lp-cards"
  }, dataSource.map(function (item) {
    var nestRight = item.nestRight,
        nestBottom = item.nestBottom,
        cardProps = (0, _tslib.__rest)(item, ["nestRight", "nestBottom"]);

    if (item.style) {
      if (nestRight) {
        item.style['marginRight'] = 0;
        item.style['marginBottom'] = 16;
      } else if (nestBottom) {
        item.style['marginBottom'] = 0;
        item.style['marginRight'] = 16;
      } else {
        item.style['marginRight'] = 16;
        item.style['marginBottom'] = 16;
      }
    } else {
      item.style = {};

      if (nestRight) {
        item.style['marginRight'] = 0;
        item.style['marginBottom'] = 16;
      } else if (nestBottom) {
        item.style['marginBottom'] = 0;
        item.style['marginRight'] = 16;
      } else {
        item.style['marginRight'] = 16;
        item.style['marginBottom'] = 16;
      }
    }

    return /*#__PURE__*/_react["default"].createElement(LPCard, (0, _tslib.__assign)({}, cardProps));
  }));
}

LPCard.Cards = Cards;
LPCard.Media = _consoleComponents.Card.Media;
LPCard.Header = _consoleComponents.Card.Header;
LPCard.Content = _consoleComponents.Card.Content;
LPCard.Divider = _consoleComponents.Card.Divider;
LPCard.Actions = _consoleComponents.Card.Actions;
var _default = LPCard;
exports["default"] = _default;