"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
require("core-js/modules/es.array.map.js");
require("core-js/modules/es.string.link.js");
var React = _interopRequireWildcard(require("react"));
var _uiCore = require("@megafon/ui-core");
var _uiHelpers = require("@megafon/ui-helpers");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var textsConvertConfig = (0, _extends2["default"])((0, _extends2["default"])({}, _uiHelpers.textConvertConfig), {
  ul: {
    component: function component(_ref) {
      var children = _ref.children;
      return /*#__PURE__*/React.createElement("ul", null, children);
    }
  },
  ol: {
    component: function component(_ref2) {
      var children = _ref2.children;
      return /*#__PURE__*/React.createElement("ol", null, children);
    }
  },
  li: {
    component: function component(_ref3) {
      var children = _ref3.children;
      return /*#__PURE__*/React.createElement("li", null, children);
    }
  },
  p: {
    component: function component(_ref4) {
      var children = _ref4.children;
      return /*#__PURE__*/React.createElement("p", null, children);
    }
  }
});
var cn = (0, _uiHelpers.cnCreate)('mfui-card');
var Card = function Card(_ref5) {
  var dataAttrs = _ref5.dataAttrs,
    className = _ref5.className,
    classes = _ref5.classes,
    rootRef = _ref5.rootRef,
    _ref5$isFullHeight = _ref5.isFullHeight,
    isFullHeight = _ref5$isFullHeight === void 0 ? false : _ref5$isFullHeight,
    _ref5$isCenteredText = _ref5.isCenteredText,
    isCenteredText = _ref5$isCenteredText === void 0 ? false : _ref5$isCenteredText,
    link = _ref5.link,
    _ref5$view = _ref5.view,
    view = _ref5$view === void 0 ? 'shadow' : _ref5$view,
    image = _ref5.image,
    icon = _ref5.icon,
    title = _ref5.title,
    markerList = _ref5.markerList,
    textsList = _ref5.textsList,
    featuresList = _ref5.featuresList,
    iconsList = _ref5.iconsList,
    price = _ref5.price,
    button = _ref5.button,
    extraButton = _ref5.extraButton,
    badge = _ref5.badge,
    onClick = _ref5.onClick;
  var isOnlyTitle = !image && !icon && !markerList && !textsList && !featuresList && !iconsList && !price && !button && !extraButton;
  var isLink = (link === null || link === void 0 ? void 0 : link.href) && !button && !extraButton;
  var isBottomImage = (image === null || image === void 0 ? void 0 : image.position) === 'bottom';
  var ElementType = isLink ? 'a' : 'div';
  var renderImage = function renderImage() {
    if (!image) {
      return null;
    }
    var _image$position = image.position,
      position = _image$position === void 0 ? 'top' : _image$position,
      src = image.src,
      alt = image.alt;
    return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.imgBox), {
      className: cn('img-box', {
        position: position
      })
    }), /*#__PURE__*/React.createElement("img", {
      className: cn('img'),
      src: src,
      alt: alt
    }));
  };
  var renderIcon = function renderIcon() {
    if (!icon) {
      return null;
    }
    return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.icon), {
      className: cn('icon')
    }), icon);
  };
  var renderContent = function renderContent() {
    if (markerList) {
      return /*#__PURE__*/React.createElement("ul", {
        className: cn('marker-list')
      }, markerList.map(function (item, i) {
        return /*#__PURE__*/React.createElement("li", {
          className: cn('marker-item'),
          key: i
        }, (0, _uiHelpers.convert)(item.title, {}), !!item.note && /*#__PURE__*/React.createElement("span", {
          className: cn('marker-note')
        }, (0, _uiHelpers.convert)(item.note, {})));
      }));
    }
    if (textsList) {
      return /*#__PURE__*/React.createElement("div", {
        className: cn('texts')
      }, textsList.map(function (item, i) {
        return /*#__PURE__*/React.createElement("div", {
          className: cn('texts-item', {
            center: isCenteredText
          }),
          key: i
        }, !!item.title && /*#__PURE__*/React.createElement("div", {
          className: cn('texts-title')
        }, (0, _uiHelpers.convert)(item.title, textsConvertConfig)), /*#__PURE__*/React.createElement("div", {
          className: cn('texts-desc')
        }, (0, _uiHelpers.convert)(item.desc, textsConvertConfig)));
      }));
    }
    if (featuresList) {
      return /*#__PURE__*/React.createElement("div", {
        className: cn('features')
      }, /*#__PURE__*/React.createElement("ul", {
        className: cn('features-list')
      }, featuresList.items.map(function (item, i) {
        return /*#__PURE__*/React.createElement("li", {
          className: cn('features-item'),
          key: i
        }, /*#__PURE__*/React.createElement("div", {
          className: cn('features-item-title')
        }, /*#__PURE__*/React.createElement("span", {
          className: cn('features-item-text')
        }, item.title)), /*#__PURE__*/React.createElement("div", {
          className: cn('features-item-value')
        }, /*#__PURE__*/React.createElement("span", {
          className: cn('features-item-text')
        }, item.value)));
      })), featuresList.desc);
    }
    if (iconsList) {
      return /*#__PURE__*/React.createElement("div", {
        className: cn('icons')
      }, !!iconsList.desc && /*#__PURE__*/React.createElement("div", {
        className: cn('icons-desc')
      }, iconsList.desc), /*#__PURE__*/React.createElement("div", {
        className: cn('icons-list')
      }, iconsList.items.map(function (item, i) {
        return /*#__PURE__*/React.createElement("div", {
          className: cn('icons-item'),
          key: i
        }, /*#__PURE__*/React.createElement("div", {
          className: cn('icons-item-icon')
        }, item.icon), /*#__PURE__*/React.createElement("div", {
          className: cn('icons-item-text')
        }, item.text));
      })));
    }
    return null;
  };
  var renderPrice = function renderPrice() {
    if (!price) {
      return null;
    }
    return /*#__PURE__*/React.createElement("div", {
      className: cn('price')
    }, !!price.oldValue && /*#__PURE__*/React.createElement("div", {
      className: cn('price-old-value')
    }, price.oldValue), /*#__PURE__*/React.createElement("div", {
      className: cn('price-value')
    }, price.value), !!price.period && /*#__PURE__*/React.createElement("div", {
      className: cn('price-period')
    }, price.period));
  };
  var renderButtons = function renderButtons() {
    if (!button && !extraButton) {
      return null;
    }
    var extraButtonType = (button === null || button === void 0 ? void 0 : button.type) === 'outline' ? 'text' : extraButton === null || extraButton === void 0 ? void 0 : extraButton.type;
    return /*#__PURE__*/React.createElement("div", {
      className: cn('buttons', {
        centered: (button === null || button === void 0 ? void 0 : button.isCentered) || (extraButton === null || extraButton === void 0 ? void 0 : extraButton.isCentered)
      })
    }, !!button && /*#__PURE__*/React.createElement(_uiCore.Button, {
      dataAttrs: {
        root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button
      },
      className: cn('button', [classes === null || classes === void 0 ? void 0 : classes.button]),
      href: button.href,
      target: button.target,
      type: button.type || 'primary',
      theme: button.theme || 'green',
      onClick: button === null || button === void 0 ? void 0 : button.onClick
    }, button.title), !!extraButton && /*#__PURE__*/React.createElement(_uiCore.Button, {
      dataAttrs: {
        root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.extraButton
      },
      className: cn('button', [classes === null || classes === void 0 ? void 0 : classes.extraButton]),
      href: extraButton.href,
      target: extraButton.target,
      type: extraButtonType || 'outline',
      onClick: extraButton === null || extraButton === void 0 ? void 0 : extraButton.onClick
    }, extraButton.title));
  };
  var renderFooter = function renderFooter() {
    if (!price && !button && !extraButton && !image) {
      return null;
    }
    return /*#__PURE__*/React.createElement("div", {
      className: cn('footer')
    }, isBottomImage && renderImage(), renderPrice(), renderButtons());
  };
  return /*#__PURE__*/React.createElement(ElementType, (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    className: cn({
      'only-title': isOnlyTitle,
      view: view,
      link: isLink,
      'full-height': isFullHeight
    }, [className, classes === null || classes === void 0 ? void 0 : classes.root]),
    href: isLink ? link === null || link === void 0 ? void 0 : link.href : undefined,
    target: isLink ? link === null || link === void 0 ? void 0 : link.target : undefined,
    onClick: isLink ? onClick : undefined,
    ref: rootRef
  }), renderIcon(), !isBottomImage && renderImage(), /*#__PURE__*/React.createElement("div", {
    className: cn('header')
  }, /*#__PURE__*/React.createElement(_uiCore.Header, {
    className: cn('title'),
    as: "h3",
    align: title.align
  }, title.text), badge), renderContent(), renderFooter());
};
var _default = exports["default"] = Card;