"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.ImageScaling = exports.ButtonTypes = exports.ButtonTarget = exports.ButtonColor = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
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 ButtonColor = exports.ButtonColor = {
  GREEN: 'green',
  PURPLE: 'purple'
};
var ButtonTypes = exports.ButtonTypes = {
  PRIMARY: 'primary',
  OUTLINE: 'outline'
};
var ButtonTarget = exports.ButtonTarget = {
  SELF: '_self',
  BLANK: '_blank'
};
var ImageScaling = exports.ImageScaling = {
  COVER: 'cover',
  CONTAIN: 'contain'
};
var getMediaStyle = function getMediaStyle(imageUrl) {
  return imageUrl ? {
    backgroundImage: "url(".concat(imageUrl, ")")
  } : undefined;
};
var cn = (0, _uiHelpers.cnCreate)('mfui-button-banner');
var testIdPrefix = 'ButtonBanner';
var ButtonBanner = function ButtonBanner(_ref) {
  var dataAttrs = _ref.dataAttrs,
    className = _ref.className,
    _ref$classes = _ref.classes,
    classes = _ref$classes === void 0 ? {} : _ref$classes,
    rootRef = _ref.rootRef,
    title = _ref.title,
    text = _ref.text,
    _ref$imageUrl = _ref.imageUrl,
    imageUrl = _ref$imageUrl === void 0 ? '' : _ref$imageUrl,
    buttonText = _ref.buttonText,
    buttonUrl = _ref.buttonUrl,
    buttonDownload = _ref.buttonDownload,
    _ref$buttonTarget = _ref.buttonTarget,
    buttonTarget = _ref$buttonTarget === void 0 ? '_self' : _ref$buttonTarget,
    _ref$buttonColor = _ref.buttonColor,
    buttonColor = _ref$buttonColor === void 0 ? 'green' : _ref$buttonColor,
    _ref$buttonType = _ref.buttonType,
    buttonType = _ref$buttonType === void 0 ? 'primary' : _ref$buttonType,
    buttonRel = _ref.buttonRel,
    _ref$imageScaling = _ref.imageScaling,
    imageScaling = _ref$imageScaling === void 0 ? 'cover' : _ref$imageScaling,
    onButtonClick = _ref.onButtonClick;
  var buttonElem = /*#__PURE__*/React.createElement(_uiCore.Button, {
    dataAttrs: {
      root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button
    },
    className: cn('button', [classes.button]),
    href: buttonUrl,
    rel: buttonRel,
    target: buttonTarget,
    theme: buttonColor,
    type: buttonType,
    onClick: onButtonClick,
    download: buttonDownload
  }, buttonText);
  return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    className: cn({
      image: !!imageUrl,
      scaling: imageScaling
    }, [className, classes.root]),
    ref: rootRef
  }), /*#__PURE__*/React.createElement(_uiCore.Grid, {
    guttersLeft: "medium"
  }, /*#__PURE__*/React.createElement(_uiCore.GridColumn, {
    all: "6",
    mobile: "12",
    leftOffsetTablet: "1",
    leftOffsetDesktop: "1",
    leftOffsetWide: "1"
  }, /*#__PURE__*/React.createElement("div", {
    className: cn('content'),
    "data-testid": "".concat(testIdPrefix, "-content")
  }, /*#__PURE__*/React.createElement(_uiCore.Header, {
    className: cn('header'),
    as: "h2"
  }, (0, _uiHelpers.convert)(title, _uiHelpers.titleConvertConfig)), /*#__PURE__*/React.createElement("div", {
    className: cn('text')
  }, typeof text === 'string' ? (0, _uiHelpers.convert)(text, _uiHelpers.textConvertConfig) : text), !!imageUrl && buttonElem)), /*#__PURE__*/React.createElement(_uiCore.GridColumn, {
    all: "5",
    mobile: "12"
  }, /*#__PURE__*/React.createElement("div", {
    className: cn('media'),
    style: getMediaStyle(imageUrl),
    "data-testid": "".concat(testIdPrefix, "-media")
  }, !imageUrl && buttonElem))));
};
var _default = exports["default"] = ButtonBanner;