import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import "core-js/modules/es.array.is-array.js";
import "core-js/modules/es.array.map.js";
import * as React from 'react';
import { Carousel } from '@megafon/ui-core';
import { cnCreate, breakpoints, filterDataAttrs } from '@megafon/ui-helpers';
import PromoCard from "./components/PromoCard/PromoCard";
var slidesSettings = _defineProperty(_defineProperty(_defineProperty({}, breakpoints.MOBILE_SMALL_START, {
  slidesPerView: 1,
  spaceBetween: 16
}), breakpoints.MOBILE_BIG_START, {
  slidesPerView: 2,
  spaceBetween: 20
}), breakpoints.DESKTOP_SMALL_START, {
  slidesPerView: 3,
  spaceBetween: 20
});
var MIN_ITEMS_COUNT = 2;
var cn = cnCreate('mfui-9-promo-cards');
var PromoCards = function PromoCards(_ref) {
  var items = _ref.items,
    carouselNavTheme = _ref.carouselNavTheme,
    carouselGradientColor = _ref.carouselGradientColor,
    background = _ref.background,
    dataAttrs = _ref.dataAttrs,
    className = _ref.className,
    classes = _ref.classes,
    onCarouselChange = _ref.onCarouselChange,
    rootRef = _ref.rootRef,
    children = _ref.children;
  var itemsLength = (items === null || items === void 0 ? void 0 : items.length) || 0;
  var childrenLength = Array.isArray(children) ? children.length : 0;
  if ((childrenLength || itemsLength) < MIN_ITEMS_COUNT) {
    return null;
  }
  var renderItems = (items || []).map(function (item, i) {
    return /*#__PURE__*/React.createElement(PromoCard, _extends({}, item, {
      className: classes === null || classes === void 0 ? void 0 : classes.card,
      classes: {
        title: classes === null || classes === void 0 ? void 0 : classes.cardTitle
      },
      dataAttrs: {
        root: filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.card, i + 1)
      },
      background: background,
      key: i + item.title
    }));
  });
  return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    className: cn([className, classes === null || classes === void 0 ? void 0 : classes.root]),
    ref: rootRef
  }), /*#__PURE__*/React.createElement(Carousel, {
    slidesSettings: slidesSettings,
    navTheme: carouselNavTheme,
    gradient: true,
    gradientColor: carouselGradientColor,
    onChange: onCarouselChange
  }, childrenLength ? children : renderItems));
};
export default PromoCards;