"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"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
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 cn = (0, _uiHelpers.cnCreate)('mfui-picture-box');
var PictureBox = function PictureBox(_ref) {
  var image = _ref.image,
    button = _ref.button,
    extraButton = _ref.extraButton,
    _ref$pictureMask = _ref.pictureMask,
    pictureMask = _ref$pictureMask === void 0 ? 'none' : _ref$pictureMask,
    dataAttrs = _ref.dataAttrs,
    className = _ref.className,
    classes = _ref.classes,
    rootRef = _ref.rootRef,
    children = _ref.children;
  var imageSrc = image.src,
    imageSrc2x = image.src2x,
    _image$align = image.align,
    imageAlign = _image$align === void 0 ? 'left' : _image$align,
    _image$alt = image.alt,
    imageAlt = _image$alt === void 0 ? '' : _image$alt;
  var imageOrder = imageAlign === 'left' ? '0' : '1';
  var renderImg = function renderImg() {
    var srcSet = imageSrc2x ? "".concat(imageSrc, ", ").concat(imageSrc2x, " 2x") : undefined;
    var img = /*#__PURE__*/React.createElement("img", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.image), {
      className: cn('image'),
      srcSet: srcSet,
      src: imageSrc,
      alt: imageAlt
    }));
    if (pictureMask !== 'none') {
      return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.mask), {
        className: cn('mask')
      }), img);
    }
    return img;
  };
  var renderButtons = function renderButtons() {
    if (!button && !extraButton) {
      return null;
    }
    return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.buttonsWrapper), {
      className: cn('button-wrapper')
    }), !!button && /*#__PURE__*/React.createElement(_uiCore.Button, {
      href: button.href,
      target: button.target,
      rel: button.rel,
      dataAttrs: {
        root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button
      },
      classes: {
        root: classes === null || classes === void 0 ? void 0 : classes.button
      },
      onClick: button.onClick
    }, button.title), !!extraButton && /*#__PURE__*/React.createElement(_uiCore.Button, {
      href: extraButton.href,
      target: extraButton.target,
      rel: extraButton.rel,
      type: "outline",
      dataAttrs: {
        root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.extraButton
      },
      classes: {
        root: classes === null || classes === void 0 ? void 0 : classes.extraButton
      },
      onClick: extraButton.onClick
    }, extraButton.title));
  };
  return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: cn({
      align: imageAlign,
      mask: pictureMask
    }, [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(_uiCore.Grid, {
    guttersLeft: "medium"
  }, /*#__PURE__*/React.createElement(_uiCore.GridColumn, {
    all: "7",
    tablet: "12",
    mobile: "12",
    orderWide: imageOrder,
    orderDesktop: imageOrder
  }, renderImg()), /*#__PURE__*/React.createElement(_uiCore.GridColumn, {
    all: "5",
    tablet: "12",
    mobile: "12",
    flex: true
  }, /*#__PURE__*/React.createElement("div", {
    className: cn('content')
  }, children, renderButtons()))));
};
var _default = exports["default"] = PictureBox;