import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import "core-js/modules/es.array.concat.js";
import "core-js/modules/es.array.map.js";
import * as React from 'react';
import { Carousel, Grid, GridColumn } from '@megafon/ui-core';
import { breakpoints, cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
import SidePictureCard from "./components/SidePictureCard";
var slidesSettings = _defineProperty(_defineProperty({}, breakpoints.MOBILE_SMALL_START, {
  slidesPerView: 1,
  spaceBetween: 16
}), breakpoints.MOBILE_BIG_START, {
  slidesPerView: 2,
  spaceBetween: 20
});
var MIN_ITEMS_COUNT = 2;
var cn = cnCreate('mfui-9-side-picture-cards');
var SidePictureCards = function SidePictureCards(_ref) {
  var items = _ref.items,
    _ref$background = _ref.background,
    background = _ref$background === void 0 ? 'gray' : _ref$background,
    _ref$hasCarousel = _ref.hasCarousel,
    hasCarousel = _ref$hasCarousel === void 0 ? false : _ref$hasCarousel,
    className = _ref.className,
    _ref$classes = _ref.classes,
    classes = _ref$classes === void 0 ? {} : _ref$classes,
    dataAttrs = _ref.dataAttrs,
    onCarouselChange = _ref.onCarouselChange,
    rootRef = _ref.rootRef;
  if (items.length < MIN_ITEMS_COUNT) {
    return null;
  }
  var renderItem = function renderItem(item, index) {
    return /*#__PURE__*/React.createElement(SidePictureCard, _extends({}, item, {
      background: background,
      key: "".concat(item === null || item === void 0 ? void 0 : item.title, "_").concat(index),
      classes: {
        root: classes.item,
        title: classes.itemTitle
      },
      dataAttrs: {
        root: _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.item, index + 1))
      }
    }));
  };
  var renderContent = function renderContent() {
    if (hasCarousel) {
      return /*#__PURE__*/React.createElement(Carousel, {
        slidesSettings: slidesSettings,
        onChange: onCarouselChange
      }, items.map(renderItem));
    }
    return /*#__PURE__*/React.createElement(Grid, {
      guttersLeft: "medium",
      guttersBottom: "medium"
    }, items.map(function (item, i) {
      return /*#__PURE__*/React.createElement(GridColumn, {
        all: "6",
        mobile: "12",
        key: "".concat(item === null || item === void 0 ? void 0 : item.title, "_").concat(i)
      }, renderItem(item, i));
    }));
  };
  return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    className: cn([className, classes.root]),
    ref: rootRef
  }), renderContent());
};
export default SidePictureCards;