"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.symbol.js");
require("core-js/modules/es.symbol.description.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 cn = (0, _uiHelpers.cnCreate)('mfui-9-card-on-background');
var CardOnBackground = function CardOnBackground(_ref) {
  var title = _ref.title,
    description = _ref.description,
    imageSrc = _ref.imageSrc,
    _ref$imageAlt = _ref.imageAlt,
    imageAlt = _ref$imageAlt === void 0 ? '' : _ref$imageAlt,
    button = _ref.button,
    extraButton = _ref.extraButton,
    href = _ref.href,
    target = _ref.target,
    rel = _ref.rel,
    headerHeight = _ref.headerHeight,
    headerRef = _ref.headerRef,
    _ref$classes = _ref.classes,
    classes = _ref$classes === void 0 ? {} : _ref$classes,
    dataAttrs = _ref.dataAttrs,
    price = _ref.price,
    promoBadge = _ref.promoBadge;
  var showButtons = !!(button === null || button === void 0 ? void 0 : button.title) || !!(extraButton === null || extraButton === void 0 ? void 0 : extraButton.title);
  var isLink = !!href && !showButtons;
  var ElementType = isLink ? 'a' : 'div';
  var currentRel = (0, _setRelAttribute.setRelAttribute)(rel, target);
  return /*#__PURE__*/_react["default"].createElement(ElementType, (0, _extends2["default"])({
    className: cn({
      active: isLink
    }, [classes.root])
  }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), isLink && {
    href: href,
    target: target,
    rel: currentRel
  }), !!promoBadge && /*#__PURE__*/_react["default"].createElement(_uiCore.PromoBadge, {
    className: cn('badge'),
    color: promoBadge.color,
    dataAttrs: {
      root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.promoBadge
    }
  }, promoBadge.text), /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('content')
  }, /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
    className: cn('header-wrapper')
  }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.header), {
    style: {
      minHeight: headerHeight
    }
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('header'),
    ref: headerRef
  }, /*#__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",
    align: "center"
  }, (0, _uiHelpers.convert)(title, _uiHelpers.titleConvertConfig)), !!description && /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('description')
  }, (0, _uiHelpers.convert)(description, _uiHelpers.textConvertConfig)))), /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('image-wrapper')
  }, /*#__PURE__*/_react["default"].createElement("img", {
    className: cn('image'),
    src: imageSrc,
    alt: imageAlt
  })), !!price && /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.price), {
    className: cn('price')
  }), !!price.oldValue && /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.priceOldValue), {
    className: cn('price-old-value')
  }), price.oldValue), /*#__PURE__*/_react["default"].createElement("span", {
    className: cn('price-value')
  }, price.value), !!price.period && /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.pricePeriod), {
    className: cn('price-period')
  }), price.period)), showButtons && /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('buttons')
  }, !!(button === null || button === void 0 ? void 0 : button.title) && /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('button')
  }, /*#__PURE__*/_react["default"].createElement(_uiCore.Button, {
    className: classes.button,
    dataAttrs: {
      root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button
    },
    theme: "green",
    fullWidth: true,
    href: button.href,
    target: button.target,
    rel: (0, _setRelAttribute.setRelAttribute)(button.rel, button.target),
    onClick: button.onClick
  }, button.title)), !!(extraButton === null || extraButton === void 0 ? void 0 : extraButton.title) && /*#__PURE__*/_react["default"].createElement("div", {
    className: cn('button')
  }, /*#__PURE__*/_react["default"].createElement(_uiCore.Button, {
    className: classes.extraButton,
    dataAttrs: {
      root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.extraButton
    },
    theme: "gray",
    fullWidth: true,
    href: extraButton.href,
    target: extraButton.target,
    rel: (0, _setRelAttribute.setRelAttribute)(extraButton.rel, extraButton.target),
    onClick: extraButton.onClick
  }, extraButton.title)))));
};
var _default = exports["default"] = CardOnBackground;