"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
require("core-js/modules/es.array.concat.js");
require("core-js/modules/es.array.map.js");
require("core-js/modules/es.array.slice.js");
var _react = _interopRequireDefault(require("react"));
var _uiCore = require("@megafon/ui-core");
var _uiHelpers = require("@megafon/ui-helpers");
var _setRelAttribute = require("../../../helpers/setRelAttribute");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var MAX_ICON_ITEMS_COUNT = 4;
var cn = (0, _uiHelpers.cnCreate)('mfui-side-picture-card');
var SidePictureCard = function SidePictureCard(_ref) {
  var background = _ref.background,
    title = _ref.title,
    image = _ref.image,
    _ref$iconItems = _ref.iconItems,
    iconItems = _ref$iconItems === void 0 ? [] : _ref$iconItems,
    button = _ref.button,
    href = _ref.href,
    target = _ref.target,
    rel = _ref.rel,
    _ref$classes = _ref.classes,
    classes = _ref$classes === void 0 ? {} : _ref$classes,
    dataAttrs = _ref.dataAttrs;
  var _ref2 = button || {},
    buttonTitle = _ref2.title,
    buttonHref = _ref2.href,
    buttonTarget = _ref2.target,
    buttonRel = _ref2.rel,
    onButtonClick = _ref2.onClick;
  var isLink = !!href && !buttonHref;
  var ElementType = isLink ? 'a' : 'div';
  var currentRel = (0, _setRelAttribute.setRelAttribute)(rel, target);
  var currentButtonRel = (0, _setRelAttribute.setRelAttribute)(buttonRel, buttonTarget);
  var visibleIconItems = iconItems.slice(0, MAX_ICON_ITEMS_COUNT);
  var items = visibleIconItems.map(function (item, i) {
    var icon = item.icon,
      _item$text = item.text,
      text = _item$text === void 0 ? '' : _item$text,
      _item$info = item.info,
      info = _item$info === void 0 ? '' : _item$info;
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: cn('item'),
      key: "".concat(text || info, "_").concat(i)
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: cn('item-icon')
    }, icon), /*#__PURE__*/_react["default"].createElement("div", {
      className: cn('item-description')
    }, !!text && /*#__PURE__*/_react["default"].createElement("div", {
      className: cn('item-text')
    }, (0, _uiHelpers.convert)(text, {})), !!info && /*#__PURE__*/_react["default"].createElement("div", {
      className: cn('item-info')
    }, (0, _uiHelpers.convert)(info, {}))));
  });
  return /*#__PURE__*/_react["default"].createElement(ElementType, (0, _extends2["default"])({
    className: cn({
      background: background,
      active: isLink
    }, [classes.root])
  }, dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root, {
    href: href,
    target: isLink ? target : undefined,
    rel: isLink ? currentRel : undefined
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('content')
  }, !!title && /*#__PURE__*/_react["default"].createElement(_uiCore.Header, {
    className: cn('title', [classes === null || classes === void 0 ? void 0 : classes.title]),
    dataAttrs: {
      root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.title
    },
    as: "h3"
  }, (0, _uiHelpers.convert)(title, {})), /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('items')
  }, items), !!buttonTitle && /*#__PURE__*/_react["default"].createElement(_uiCore.Button, {
    className: cn('button', [classes.button]),
    dataAttrs: {
      root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button
    },
    href: buttonHref,
    target: buttonTarget,
    rel: currentButtonRel,
    onClick: onButtonClick
  }, buttonTitle)), /*#__PURE__*/_react["default"].createElement("picture", {
    className: cn('picture')
  }, /*#__PURE__*/_react["default"].createElement("source", {
    media: "(min-width: ".concat(_uiHelpers.breakpoints.DESKTOP_MIDDLE_START, "px)"),
    srcSet: image.srcWide
  }), /*#__PURE__*/_react["default"].createElement("img", {
    className: cn('image'),
    src: image.src,
    alt: image.alt || 'image'
  })));
};
var _default = exports["default"] = SidePictureCard;