import _extends from "@babel/runtime/helpers/extends";
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.array.concat.js";
import * as React from 'react';
import { Button, Header, Paragraph } from '@megafon/ui-core';
import { cnCreate, convert, filterDataAttrs, breakpoints, titleConvertConfig, textConvertConfig } from '@megafon/ui-helpers';
import "./PromoBannerSlide.css";
export var 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 = cnCreate('mfui-9-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", _extends({
      className: cn('buttons-wrapper')
    }, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.buttonsWrapper)), !!button && /*#__PURE__*/React.createElement(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(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", _extends({
      media: "(min-width: ".concat(breakpoints.DESKTOP_SMALL_START, "px)"),
      srcSet: desktopSrcSet
    }, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.desktopImageSource))), /*#__PURE__*/React.createElement("source", _extends({
      media: "(min-width: ".concat(breakpoints.MOBILE_BIG_START, "px)"),
      srcSet: tabletSrcSet
    }, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.tabletImageSource))), /*#__PURE__*/React.createElement("img", _extends({
      className: cn('image'),
      src: mobileSrc,
      srcSet: mobileSrcSet,
      alt: alt || ''
    }, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.image))));
  };
  return /*#__PURE__*/React.createElement("div", _extends({
    className: cn({
      background: background
    }, [classes === null || classes === void 0 ? void 0 : classes.root, className])
  }, 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(Header, {
    className: cn('title'),
    as: "h2",
    color: textColor
  }, typeof title === 'string' ? convert(title, titleConvertConfig) : title), /*#__PURE__*/React.createElement(Paragraph, {
    className: cn('description'),
    hasMargin: false,
    color: textColor
  }, typeof description === 'string' ? convert(description, textConvertConfig) : description)), renderButtons(), renderImage()));
};
export default PromoBannerSlide;