"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"] = exports.BackgroundColor = 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");
require("core-js/modules/es.array.concat.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 BackgroundColor = exports.BackgroundColor = {
  DARK_VIOLET: 'dark-violet',
  LIGHT_VIOLET: 'light-violet',
  GREEN_20: 'green-20',
  PURPLE_20: 'purple-20',
  NIGHT_20: 'night-20',
  FLAMINGO_20: 'flamingo-20',
  BERRY_20: 'berry-20',
  GRADIENT_PURPLE_1: 'gradient-purple-1',
  GRADIENT_PURPLE_2: 'gradient-purple-2',
  GRADIENT_PURPLE_3: 'gradient-purple-3',
  GRADIENT_PURPLE_4: 'gradient-purple-4'
};
var getThemeSettings = function getThemeSettings(bgColor) {
  switch (bgColor) {
    case BackgroundColor.DARK_VIOLET:
    case BackgroundColor.LIGHT_VIOLET:
      return {
        buttonColor: 'green',
        textColor: 'inherit'
      };
    case BackgroundColor.GRADIENT_PURPLE_1:
    case BackgroundColor.GRADIENT_PURPLE_2:
    case BackgroundColor.GRADIENT_PURPLE_3:
    case BackgroundColor.GRADIENT_PURPLE_4:
      return {
        buttonColor: 'white',
        textColor: 'white'
      };
    default:
      return {
        buttonColor: 'green',
        textColor: 'default'
      };
  }
};
var cn = (0, _uiHelpers.cnCreate)('mfui-promo-banner-slide');
var PromoBannerSlide = function PromoBannerSlide(_ref) {
  var className = _ref.className,
    title = _ref.title,
    description = _ref.description,
    button = _ref.button,
    extraButton = _ref.extraButton,
    image = _ref.image,
    _ref$background = _ref.background,
    background = _ref$background === void 0 ? 'dark-violet' : _ref$background,
    classes = _ref.classes,
    dataAttrs = _ref.dataAttrs,
    rootRef = _ref.rootRef;
  var _getThemeSettings = getThemeSettings(background),
    buttonColor = _getThemeSettings.buttonColor,
    textColor = _getThemeSettings.textColor;
  var renderButtons = function renderButtons() {
    if (!button && !extraButton) {
      return null;
    }
    return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
      className: cn('buttons-wrapper')
    }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.buttonsWrapper)), !!button && /*#__PURE__*/React.createElement(_uiCore.Button, {
      theme: buttonColor,
      href: button.href,
      target: button.target,
      icon: button.icon,
      rel: button.rel,
      classes: {
        root: classes === null || classes === void 0 ? void 0 : classes.button
      },
      dataAttrs: {
        root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button
      },
      onClick: button.onClick
    }, button.title), !!extraButton && /*#__PURE__*/React.createElement(_uiCore.Button, {
      theme: buttonColor,
      href: extraButton.href,
      target: extraButton.target,
      icon: extraButton.icon,
      rel: extraButton.rel,
      type: "outline",
      classes: {
        root: classes === null || classes === void 0 ? void 0 : classes.extraButton
      },
      dataAttrs: {
        root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.extraButton
      },
      onClick: extraButton.onClick
    }, extraButton.title));
  };
  var renderImage = function renderImage() {
    var desktopSrc = image.desktopSrc,
      desktopSrc2x = image.desktopSrc2x,
      tabletSrc = image.tabletSrc,
      tabletSrc2x = image.tabletSrc2x,
      mobileSrc = image.mobileSrc,
      mobileSrc2x = image.mobileSrc2x,
      alt = image.alt;
    var desktopSrcSet = desktopSrc2x ? "".concat(desktopSrc, ", ").concat(desktopSrc2x, " 2x") : desktopSrc;
    var tabletSrcSet = tabletSrc2x ? "".concat(tabletSrc, ", ").concat(tabletSrc2x, " 2x") : tabletSrc;
    var mobileSrcSet = mobileSrc2x ? "".concat(mobileSrc, ", ").concat(mobileSrc2x, " 2x") : mobileSrc;
    return /*#__PURE__*/React.createElement("picture", {
      className: cn('picture')
    }, /*#__PURE__*/React.createElement("source", (0, _extends2["default"])({
      media: "(min-width: ".concat(_uiHelpers.breakpoints.DESKTOP_SMALL_START, "px)"),
      srcSet: desktopSrcSet
    }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.desktopImageSource))), /*#__PURE__*/React.createElement("source", (0, _extends2["default"])({
      media: "(min-width: ".concat(_uiHelpers.breakpoints.MOBILE_BIG_START, "px)"),
      srcSet: tabletSrcSet
    }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.tabletImageSource))), /*#__PURE__*/React.createElement("img", (0, _extends2["default"])({
      className: cn('image'),
      src: mobileSrc,
      srcSet: mobileSrcSet,
      alt: alt || ''
    }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.image))));
  };
  return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: cn({
      background: background
    }, [classes === null || classes === void 0 ? void 0 : classes.root, className])
  }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    ref: rootRef
  }), /*#__PURE__*/React.createElement("div", {
    className: cn('container')
  }, /*#__PURE__*/React.createElement("div", {
    className: cn('content')
  }, /*#__PURE__*/React.createElement(_uiCore.Header, {
    className: cn('title'),
    as: "h2",
    color: textColor
  }, typeof title === 'string' ? (0, _uiHelpers.convert)(title, _uiHelpers.titleConvertConfig) : title), /*#__PURE__*/React.createElement(_uiCore.Paragraph, {
    className: cn('description'),
    hasMargin: false,
    color: textColor
  }, typeof description === 'string' ? (0, _uiHelpers.convert)(description, _uiHelpers.textConvertConfig) : description)), renderButtons(), renderImage()));
};
var _default = exports["default"] = PromoBannerSlide;