function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { obj } from '../util';
import InnerSlider from './slick/inner-slider';
import ConfigProvider from '../config-provider';
/**
 * Slider
 */

var Slider =
/*#__PURE__*/
function (_Component) {
  _inherits(Slider, _Component);

  function Slider() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, Slider);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Slider)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_this), "resize", function () {
      // export api
      _this.innerSlider.onWindowResized();
    });

    return _this;
  }

  _createClass(Slider, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          prefix = _this$props.prefix,
          arrowPosition = _this$props.arrowPosition,
          slideDirection = _this$props.slideDirection,
          style = _this$props.style,
          className = _this$props.className,
          children = _this$props.children;
      var sliderProps = obj.pickOthers(['className', 'style', 'slideDirection'], this.props);
      var slideCount = React.Children.count(children);

      if (slideCount === 0) {
        // 没有 item 时不显示 slider
        return null;
      } else if (slideCount === 1) {
        // 单个 item 时不显示箭头和控制器
        sliderProps.arrows = false;
        sliderProps.autoplay = false;
        sliderProps.draggable = false;
      }

      var clazz = classNames(["".concat(prefix, "slick"), "".concat(prefix, "slick-").concat(arrowPosition), "".concat(prefix, "slick-").concat(slideDirection)], className);

      if (slideDirection === 'ver') {
        // 向下传递时使用 vertical 属性
        sliderProps.vertical = true;
        sliderProps.verticalSwiping = true;
      }

      var newContext = ConfigProvider.getContext();
      return React.createElement(ConfigProvider, _extends({}, newContext, {
        rtl: false
      }), React.createElement("div", _extends({
        dir: "ltr",
        className: clazz,
        style: style
      }, obj.pickOthers(_objectSpread({}, Slider.propTypes, {}, InnerSlider.propTypes), sliderProps)), React.createElement(InnerSlider, _extends({
        ref: function ref(InnerSlider) {
          return _this2.innerSlider = InnerSlider;
        }
      }, sliderProps))));
    }
  }]);

  return Slider;
}(Component);

_defineProperty(Slider, "propTypes", {
  prefix: PropTypes.string,
  rtl: PropTypes.bool,

  /**
   * 自定义传入的样式
   */
  className: PropTypes.any,

  /**
   * 是否使用自适应高度
   */
  adaptiveHeight: PropTypes.bool,

  /**
   * 动效类型，默认是'slide'
   */
  animation: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),

  /**
   * 是否显示箭头
   */
  arrows: PropTypes.bool,

  /**
   * 导航箭头大小 可选值: 'medium', 'large'
   */
  arrowSize: PropTypes.oneOf(['medium', 'large']),

  /**
   * 导航箭头位置 可选值: 'inner', 'outer'
   */
  arrowPosition: PropTypes.oneOf(['inner', 'outer']),

  /**
   * 导航箭头的方向 可选值: 'hoz', 'ver'
   */
  arrowDirection: PropTypes.oneOf(['hoz', 'ver']),

  /**
   * 是否自动播放
   */
  autoplay: PropTypes.bool,

  /**
   * 自动播放的速度
   */
  autoplaySpeed: PropTypes.number,

  /**
   * 向后箭头
   */
  nextArrow: PropTypes.element,

  /**
   * 向前箭头
   */
  prevArrow: PropTypes.element,

  /**
   * 是否启用居中模式
   */
  centerMode: PropTypes.bool,

  /**
   * 是否显示导航锚点
   */
  dots: PropTypes.bool,

  /**
   * 导航锚点位置
   */
  dotsDirection: PropTypes.oneOf(['hoz', 'ver']),
  dotsClass: PropTypes.string,

  /**
   * 自定义导航锚点
   */
  dotsRender: PropTypes.func,

  /**
   * 是否可拖拽
   */
  draggable: PropTypes.bool,

  /**
   * 是否使用无穷循环模式
   */
  infinite: PropTypes.bool,

  /**
   * 初始被激活的轮播图
   */
  defaultActiveIndex: PropTypes.number,

  /**
   * 是否启用懒加载
   */
  lazyLoad: PropTypes.bool,
  slide: PropTypes.string,

  /**
   * 轮播方向
   */
  slideDirection: PropTypes.oneOf(['hoz', 'ver']),

  /**
   * 同时展示的图片数量
   */
  slidesToShow: PropTypes.number,

  /**
   * 同时滑动的图片数量
   */
  slidesToScroll: PropTypes.number,

  /**
   * 轮播速度
   */
  speed: PropTypes.number,

  /**
   * 跳转到指定的轮播图（受控）
   */
  activeIndex: PropTypes.number,

  /**
   * 锚点导航触发方式
   */
  triggerType: PropTypes.oneOf(['click', 'hover']),

  /**
   * 轮播切换的回调函数
   * @param {Number} index 幻灯片的索引
   */
  onChange: PropTypes.func,
  onBeforeChange: PropTypes.func,
  // 兼容 0.x onBeforeChange
  children: PropTypes.any,

  /**
   * 自定义传入的class
   */
  style: PropTypes.object,

  /**
   * Side padding when in center mode (px or %); 展示部分为center，pading会产生前后预览
   */
  centerPadding: PropTypes.string,

  /**
   * CSS3 Animation Easing,默认‘ease’
   */
  cssEase: PropTypes.string,
  // used
  edgeFriction: PropTypes.number,
  // 非无限轮播滑动到边缘时的阻力

  /**
   * 多图轮播时，点击选中后自动居中
   */
  focusOnSelect: PropTypes.bool,
  pauseOnHover: PropTypes.bool,
  // 鼠标经过时停止播放
  swipe: PropTypes.bool,
  swipeToSlide: PropTypes.bool,
  touchMove: PropTypes.bool,
  touchThreshold: PropTypes.number,
  useCSS: PropTypes.bool,
  variableWidth: PropTypes.bool,
  // used
  waitForAnimate: PropTypes.bool,
  edgeEvent: PropTypes.any,
  swipeEvent: PropTypes.any
});

_defineProperty(Slider, "defaultProps", {
  prefix: 'next-',
  animation: 'slide',
  arrowSize: 'medium',
  arrowPosition: 'inner',
  vertical: false,
  verticalSwiping: true,
  dots: true,
  dotsDirection: 'hoz',
  arrows: true,
  arrowDirection: 'hoz',
  infinite: true,
  autoplay: false,
  autoplaySpeed: 3000,
  speed: 500,
  adaptiveHeight: false,
  centerMode: false,
  centerPadding: '50px',
  // Side padding when in center mode (px or %); 展示部分为center，pading会产生前后预览
  cssEase: 'ease',
  draggable: true,
  edgeFriction: 0.35,
  focusOnSelect: false,
  defaultActiveIndex: 0,
  lazyLoad: false,
  pauseOnHover: false,
  rtl: false,
  slide: 'div',
  slideDirection: 'hoz',
  slidesToShow: 1,
  slidesToScroll: 1,
  swipe: true,
  swipeToSlide: false,
  // Allow users to drag or swipe directly to a slide irrespective of slidesToScroll
  touchMove: true,
  // 移动端touch
  touchThreshold: 5,
  useCSS: true,
  variableWidth: false,
  waitForAnimate: true,
  onChange: function onChange() {},
  onBeforeChange: function onBeforeChange() {},
  edgeEvent: null,
  swipeEvent: null,
  nextArrow: null,
  // nextArrow, prevArrow are react components
  prevArrow: null,
  style: null,
  dotsRender: null,
  triggerType: 'click'
});

export { Slider as default };