import _extends from "@babel/runtime/helpers/extends";
import "core-js/modules/es.array.concat.js";
import * as React from 'react';
import { Button, Grid, GridColumn } from '@megafon/ui-core';
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
import "./PictureBox.css";
var cn = cnCreate('mfui-9-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", _extends({}, 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", _extends({}, 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", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.buttonsWrapper), {
      className: cn('button-wrapper')
    }), !!button && /*#__PURE__*/React.createElement(Button, {
      href: button.href,
      target: button.target,
      rel: button.rel,
      icon: button.icon,
      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(Button, {
      href: extraButton.href,
      target: extraButton.target,
      rel: extraButton.rel,
      icon: extraButton.icon,
      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", _extends({
    className: cn({
      align: imageAlign,
      mask: pictureMask
    }, [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(Grid, {
    guttersLeft: "medium"
  }, /*#__PURE__*/React.createElement(GridColumn, {
    all: "7",
    tablet: "12",
    mobile: "12",
    orderWide: imageOrder,
    orderDesktop: imageOrder
  }, renderImg()), /*#__PURE__*/React.createElement(GridColumn, {
    all: "5",
    tablet: "12",
    mobile: "12",
    flex: true
  }, /*#__PURE__*/React.createElement("div", {
    className: cn('content')
  }, children, renderButtons()))));
};
export default PictureBox;