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); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useRef, useEffect } from 'react';
import { Image } from 'antd';
import { Swiper, Navigation, Pagination, Autoplay } from 'swiper';
import 'swiper/swiper-bundle.css';
import Iconfont from "../iconfont";
import classNames from 'classnames';
import "./index.less";
var PisellImageCarousels = function PisellImageCarousels(_ref) {
  var _ref$dataSource = _ref.dataSource,
    dataSource = _ref$dataSource === void 0 ? [] : _ref$dataSource,
    _ref$width = _ref.width,
    width = _ref$width === void 0 ? 640 : _ref$width,
    _ref$height = _ref.height,
    height = _ref$height === void 0 ? 400 : _ref$height,
    _ref$showArrows = _ref.showArrows,
    showArrows = _ref$showArrows === void 0 ? true : _ref$showArrows,
    _ref$showDots = _ref.showDots,
    showDots = _ref$showDots === void 0 ? true : _ref$showDots,
    _ref$autoplay = _ref.autoplay,
    autoplay = _ref$autoplay === void 0 ? true : _ref$autoplay,
    _ref$interval = _ref.interval,
    interval = _ref$interval === void 0 ? 3000 : _ref$interval,
    _ref$borderRadius = _ref.borderRadius,
    borderRadius = _ref$borderRadius === void 0 ? 8 : _ref$borderRadius,
    _ref$loop = _ref.loop,
    loop = _ref$loop === void 0 ? true : _ref$loop,
    className = _ref.className,
    style = _ref.style;
  var swiperRef = useRef(null);
  var swiperInstance = useRef(null);
  useEffect(function () {
    if (swiperRef.current) {
      swiperInstance.current = new Swiper(swiperRef.current, {
        modules: [Navigation, Pagination, Autoplay],
        slidesPerView: 1,
        spaceBetween: 0,
        loop: loop,
        // 导航箭头
        navigation: showArrows ? {
          nextEl: '.pisell-carousel-next',
          prevEl: '.pisell-carousel-prev'
        } : false,
        // 分页点
        pagination: showDots ? {
          el: '.pisell-carousel-pagination',
          clickable: true
        } : false,
        // 自动播放
        autoplay: autoplay ? {
          delay: interval,
          disableOnInteraction: false
        } : false
      });
    }
    return function () {
      if (swiperInstance.current) {
        swiperInstance.current.destroy();
      }
    };
  }, [showArrows, showDots, autoplay, interval, loop]);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames('pisell-image-carousel', className),
    style: _objectSpread({
      width: width,
      height: height
    }, style)
  }, /*#__PURE__*/React.createElement("div", {
    className: "swiper",
    ref: swiperRef
  }, /*#__PURE__*/React.createElement("div", {
    className: "swiper-wrapper"
  }, dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (item, index) {
    return /*#__PURE__*/React.createElement("div", {
      key: index,
      className: "swiper-slide"
    }, /*#__PURE__*/React.createElement(Image, {
      preview: false,
      src: item,
      width: width,
      height: height,
      loading: "lazy",
      style: {
        borderRadius: "".concat(borderRadius, "px")
      }
    }));
  })), showArrows && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "pisell-carousel-prev"
  }, /*#__PURE__*/React.createElement("span", {
    className: "carousel-arrow"
  }, /*#__PURE__*/React.createElement(Iconfont, {
    type: "pisell2-chevron-left"
  }))), /*#__PURE__*/React.createElement("div", {
    className: "pisell-carousel-next"
  }, /*#__PURE__*/React.createElement("span", {
    className: "carousel-arrow"
  }, /*#__PURE__*/React.createElement(Iconfont, {
    type: "pisell2-chevron-right"
  })))), showDots && /*#__PURE__*/React.createElement("div", {
    className: "pisell-carousel-pagination"
  })));
};
export default PisellImageCarousels;