"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.symbol.js");
require("core-js/modules/es.symbol.description.js");
var React = _interopRequireWildcard(require("react"));
var _uiHelpers = require("@megafon/ui-helpers");
var _setRelAttribute = require("../../../../helpers/setRelAttribute");
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 ArrowRight16 = function ArrowRight16(props) {
  return /*#__PURE__*/React.createElement("svg", (0, _extends2["default"])({
    viewBox: "0 0 20 20"
  }, props), /*#__PURE__*/React.createElement("path", {
    d: "M8 13l3-3-3-3 1-1 4 4-4 4z"
  }));
};
var ArrowRight24 = function ArrowRight24(props) {
  return /*#__PURE__*/React.createElement("svg", (0, _extends2["default"])({
    viewBox: "0 0 32 32"
  }, props), /*#__PURE__*/React.createElement("path", {
    d: "M12.5 20.8l4.8-4.8-4.8-4.8 1.6-1.7 6.4 6.5-6.4 6.5z"
  }));
};
var cn = (0, _uiHelpers.cnCreate)('mfui-info-card');
var InfoCard = function InfoCard(_ref) {
  var className = _ref.className,
    title = _ref.title,
    description = _ref.description,
    imgSrc = _ref.imgSrc,
    _ref$imgAlt = _ref.imgAlt,
    imgAlt = _ref$imgAlt === void 0 ? '' : _ref$imgAlt,
    href = _ref.href,
    target = _ref.target,
    rel = _ref.rel,
    download = _ref.download,
    moreInfo = _ref.moreInfo,
    onClick = _ref.onClick,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 'medium' : _ref$size,
    imgPosition = _ref.imgPosition,
    _ref$background = _ref.background,
    background = _ref$background === void 0 ? 'stroke' : _ref$background,
    dataAttrs = _ref.dataAttrs,
    classes = _ref.classes;
  var RootElement = href ? 'a' : 'div';
  var isBigSize = size === 'big';
  var finalImgPosition = size === 'big' ? false : imgPosition;
  var isInvalidBackground = background === 'no' && (imgPosition === 'right-side' || size === 'big');
  var finalBackground = isInvalidBackground ? 'stroke' : background;
  var isLink = !!href;
  var isActive = isLink || !!onClick;
  var renderArrowRight = function renderArrowRight() {
    var ArrowRight = isBigSize ? ArrowRight24 : ArrowRight16;
    return /*#__PURE__*/React.createElement(ArrowRight, (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.moreArrow), {
      className: cn('more-info-arrow')
    }));
  };
  return /*#__PURE__*/React.createElement(RootElement, (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    href: isLink ? href : undefined,
    target: isLink ? target : undefined,
    rel: isLink ? (0, _setRelAttribute.setRelAttribute)(rel, target) : undefined,
    download: isLink ? download : undefined,
    onClick: onClick,
    className: cn({
      size: size,
      position: finalImgPosition,
      background: finalBackground,
      active: isActive,
      'align-center': !moreInfo
    }, [className, classes === null || classes === void 0 ? void 0 : classes.root])
  }), /*#__PURE__*/React.createElement("img", {
    className: cn('image'),
    src: imgSrc,
    alt: imgAlt
  }), /*#__PURE__*/React.createElement("div", {
    className: cn('content')
  }, !!title && /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.title), {
    className: cn('title', [classes === null || classes === void 0 ? void 0 : classes.title])
  }), (0, _uiHelpers.convert)(title, {})), !!description && /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.description), {
    className: cn('description')
  }), (0, _uiHelpers.convert)(description, _uiHelpers.textConvertConfig)), !!moreInfo && /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.moreInfo), {
    className: cn('more-info')
  }), /*#__PURE__*/React.createElement("span", {
    className: cn('more-info-text')
  }, (0, _uiHelpers.convert)(moreInfo, {})), isActive && renderArrowRight())));
};
var _default = exports["default"] = InfoCard;