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; }

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-08-13 14:34:13
 * @LastEditTime: 2021-09-08 15:56:04
 * @FilePath: \annar-master\components\card\index.tsx
 */
import * as React from 'react';
import { View } from 'remax/one';
import classNames from 'classnames';
import { getPrefixCls } from '../common';
import { addUnit } from '../_utils';
var prefixCls = getPrefixCls('card');

var Card = function Card(props) {
  var _classNames3;

  var title = props.title,
      description = props.description,
      extra = props.extra,
      extraWidth = props.extraWidth,
      cover = props.cover,
      foot = props.foot,
      _props$direction = props.direction,
      direction = _props$direction === void 0 ? 'vertical' : _props$direction,
      shadow = props.shadow,
      _props$backgroundColo = props.backgroundColor,
      backgroundColor = _props$backgroundColo === void 0 ? "#fff" : _props$backgroundColo,
      style = props.style,
      contentStyle = props.contentStyle,
      children = props.children,
      onTap = props.onTap,
      className = props.className;

  var extraStyle = function extraStyle() {
    if (extraWidth) {
      return {
        width: addUnit(extraWidth)
      };
    }
  };

  var renderTitle = function renderTitle(isHead) {
    return title || description || extra ? /*#__PURE__*/React.createElement(View, {
      className: classNames("".concat(prefixCls, "-head"), _defineProperty({}, "".concat(prefixCls, "-content-head"), !isHead))
    }, /*#__PURE__*/React.createElement(View, null, title ? /*#__PURE__*/React.createElement(View, {
      className: "".concat(prefixCls, "-title")
    }, title) : null, description ? /*#__PURE__*/React.createElement(View, {
      className: "".concat(prefixCls, "-description")
    }, description) : null), /*#__PURE__*/React.createElement(View, {
      className: "".concat(prefixCls, "-extra"),
      style: extraStyle()
    }, extra)) : null;
  };

  var renderHead = function renderHead() {
    if (cover) {
      return /*#__PURE__*/React.createElement(View, {
        className: "".concat(prefixCls, "-cover")
      }, cover);
    }

    return renderTitle(true);
  };

  var renderFoot = function renderFoot() {
    return foot ? /*#__PURE__*/React.createElement(View, {
      className: classNames("".concat(prefixCls, "-foot"), _defineProperty({}, "".concat(prefixCls, "-foot-horizontal"), direction === 'horizontal'))
    }, foot) : null;
  };

  return /*#__PURE__*/React.createElement(View, {
    className: classNames(prefixCls, className, (_classNames3 = {}, _defineProperty(_classNames3, "".concat(prefixCls, "-horizontal"), cover && direction === 'horizontal'), _defineProperty(_classNames3, "".concat(prefixCls, "-shadow"), shadow), _classNames3)),
    style: Object.assign(Object.assign({}, style), {
      backgroundColor: backgroundColor
    }),
    onTap: onTap
  }, renderHead(), /*#__PURE__*/React.createElement(View, {
    className: "".concat(prefixCls, "-content"),
    style: Object.assign({}, contentStyle)
  }, cover ? renderTitle(false) : null, children, direction === 'horizontal' ? renderFoot() : null), direction !== 'horizontal' ? renderFoot() : null);
};

export default Card;