"use strict";

exports.__esModule = true;
exports.default = void 0;

var _babelRuntimeJsxStyleTransform = require("babel-runtime-jsx-style-transform");

var _tslib = require("tslib");

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

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

var _meetReactComponentOne = require("@alifd/meet-react-component-one");

var _icon = _interopRequireDefault(require("../icon"));

var _utils = require("../utils");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

var ARROW_ICON_MAP = {
  right: 'arrow-right',
  up: 'arrow-up',
  down: 'arrow-down',
  loading: 'loading'
};

var Card = function (props) {
  var _classNames;

  var _props$prefix = props.prefix,
      prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
      _props$showHeadDivide = props.showHeadDivider,
      showHeadDivider = _props$showHeadDivide === void 0 ? true : _props$showHeadDivide,
      media = props.media,
      arrow = props.arrow,
      extra = props.extra,
      title = props.title,
      className = props.className,
      headerClassName = props.headerClassName,
      headerStyle = props.headerStyle,
      bodyClassName = props.bodyClassName,
      footerClassName = props.footerClassName,
      contentHeight = props.contentHeight,
      _props$bodyStyle = props.bodyStyle,
      bodyStyle = _props$bodyStyle === void 0 ? {} : _props$bodyStyle,
      _props$footerStyle = props.footerStyle,
      footerStyle = _props$footerStyle === void 0 ? {} : _props$footerStyle,
      actions = props.actions,
      children = props.children,
      _props$onHeaderClick = props.onHeaderClick,
      onHeaderClick = _props$onHeaderClick === void 0 ? _utils.noop : _props$onHeaderClick,
      _props$onBodyClick = props.onBodyClick,
      onBodyClick = _props$onBodyClick === void 0 ? _utils.noop : _props$onBodyClick,
      others = (0, _tslib.__rest)(props, ["prefix", "showHeadDivider", "media", "arrow", "extra", "title", "className", "headerClassName", "headerStyle", "bodyClassName", "footerClassName", "contentHeight", "bodyStyle", "footerStyle", "actions", "children", "onHeaderClick", "onBodyClick"]);
  var clsPrefix = prefix + "card";
  var clses = {
    card: (0, _classnames.default)(className, clsPrefix),
    header: (0, _classnames.default)(clsPrefix + "-header", headerClassName, (_classNames = {}, _classNames[clsPrefix + "-header--no-divider"] = !showHeadDivider, _classNames)),
    title: clsPrefix + "-title",
    media: clsPrefix + "-media",
    extra: clsPrefix + "-extra",
    arrow: clsPrefix + "-arrow",
    body: (0, _classnames.default)(clsPrefix + "-body", bodyClassName),
    footer: (0, _classnames.default)(clsPrefix + "-footer", footerClassName)
  };
  var _bodyStyle = bodyStyle;

  if ((0, _utils.isNumber)(contentHeight) && contentHeight >= 0) {
    _bodyStyle.height = contentHeight;
  }

  return /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.View, _extends({
    className: clses.card
  }, others), !(0, _utils.isInvalidValue)(title) && !!title ? /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.View, {
    className: clses.header,
    onClick: onHeaderClick,
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)(headerStyle)
  }, media ? /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.View, {
    className: clses.media
  }, media) : null, /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.View, {
    className: clses.title
  }, title), extra ? /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.Text, {
    className: clses.extra
  }, extra) : null, Object.keys(ARROW_ICON_MAP).indexOf(arrow) > -1 ? /*#__PURE__*/(0, _react.createElement)(_icon.default, {
    className: clses.arrow,
    type: ARROW_ICON_MAP[arrow],
    size: "s"
  }) : null) : null, children ? /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.View, {
    className: clses.body,
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)(_bodyStyle),
    onClick: onBodyClick
  }, children) : null, (0, _utils.isValidArray)(actions) ? /*#__PURE__*/(0, _react.createElement)(_meetReactComponentOne.View, {
    className: clses.footer,
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)(footerStyle)
  }, actions) : null);
};

Card.displayName = 'Card';
var _default = Card;
exports.default = _default;