import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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 NumbersCard from "./components/NumbersCard/NumbersCard";
import "./NumbersBox.css";
var slidesSettings = _defineProperty(_defineProperty(_defineProperty({}, breakpoints.MOBILE_SMALL_START, {
  slidesPerView: 1,
  spaceBetween: 20
}), breakpoints.MOBILE_BIG_START, {
  slidesPerView: 3,
  spaceBetween: 20
}), breakpoints.DESKTOP_SMALL_START, {
  slidesPerView: 4,
  spaceBetween: 20
});
var MIN_ITEMS_COUNT = 3;
var FOUR_ITEMS = 4;
var MIN_CAROUSEL_ITEMS_COUNT = 5;
var cn = cnCreate('mfui-numbers-box');
var NumbersBox = function NumbersBox(_ref) {
  var items = _ref.items,
    _ref$background = _ref.background,
    background = _ref$background === void 0 ? 'shadow' : _ref$background,
    _ref$titleColor = _ref.titleColor,
    titleColor = _ref$titleColor === void 0 ? 'default' : _ref$titleColor,
    _ref$subtitleSize = _ref.subtitleSize,
    subtitleSize = _ref$subtitleSize === void 0 ? 'medium' : _ref$subtitleSize,
    carouselNavTheme = _ref.carouselNavTheme,
    carouselGradientColor = _ref.carouselGradientColor,
    dataAttrs = _ref.dataAttrs,
    className = _ref.className,
    classes = _ref.classes,
    rootRef = _ref.rootRef;
  if (items.length < MIN_ITEMS_COUNT) {
    return null;
  }
  var showCarousel = items.length >= MIN_CAROUSEL_ITEMS_COUNT;
  var isGridLayout = items.length === FOUR_ITEMS;
  var hasLargeSpacing = background === 'none' && !showCarousel;
  var renderItem = function renderItem(item, index) {
    return /*#__PURE__*/React.createElement(NumbersCard, _extends({}, item, {
      background: background,
      titleColor: titleColor,
      subtitleSize: subtitleSize,
      dataAttrs: {
        root: filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.card, index + 1)
      },
      className: cn('card', [classes === null || classes === void 0 ? void 0 : classes.card]),
      key: index + item.title
    }));
  };
  var renderCarousel = function renderCarousel() {
    return /*#__PURE__*/React.createElement(Carousel, {
      slidesSettings: slidesSettings,
      navTheme: carouselNavTheme,
      gradient: true,
      gradientColor: carouselGradientColor
    }, items.map(renderItem));
  };
  return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    className: cn({
      line: !showCarousel,
      grid: isGridLayout,
      spaced: hasLargeSpacing
    }, [className, classes === null || classes === void 0 ? void 0 : classes.root]),
    ref: rootRef
  }), showCarousel ? renderCarousel() : items.map(renderItem));
};
export default NumbersBox;