"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _util = require("../util");

var _innerSlider = _interopRequireDefault(require("./slick/inner-slider"));

var _configProvider = _interopRequireDefault(require("../config-provider"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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; }

/**
 * 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 = _util.obj.pickOthers(['className', 'style', 'slideDirection'], this.props);

      var slideCount = _react["default"].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 = (0, _classnames["default"])(["".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["default"].getContext();

      return _react["default"].createElement(_configProvider["default"], _extends({}, newContext, {
        rtl: false
      }), _react["default"].createElement("div", _extends({
        dir: "ltr",
        className: clazz,
        style: style
      }, _util.obj.pickOthers(_objectSpread({}, Slider.propTypes, {}, _innerSlider["default"].propTypes), sliderProps)), _react["default"].createElement(_innerSlider["default"], _extends({
        ref: function ref(InnerSlider) {
          return _this2.innerSlider = InnerSlider;
        }
      }, sliderProps))));
    }
  }]);

  return Slider;
}(_react.Component);

exports["default"] = Slider;

_defineProperty(Slider, "propTypes", {
  prefix: _propTypes["default"].string,
  rtl: _propTypes["default"].bool,

  /**
   * 自定义传入的样式
   */
  className: _propTypes["default"].any,

  /**
   * 是否使用自适应高度
   */
  adaptiveHeight: _propTypes["default"].bool,

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

  /**
   * 是否显示箭头
   */
  arrows: _propTypes["default"].bool,

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

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

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

  /**
   * 是否自动播放
   */
  autoplay: _propTypes["default"].bool,

  /**
   * 自动播放的速度
   */
  autoplaySpeed: _propTypes["default"].number,

  /**
   * 向后箭头
   */
  nextArrow: _propTypes["default"].element,

  /**
   * 向前箭头
   */
  prevArrow: _propTypes["default"].element,

  /**
   * 是否启用居中模式
   */
  centerMode: _propTypes["default"].bool,

  /**
   * 是否显示导航锚点
   */
  dots: _propTypes["default"].bool,

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

  /**
   * 自定义导航锚点
   */
  dotsRender: _propTypes["default"].func,

  /**
   * 是否可拖拽
   */
  draggable: _propTypes["default"].bool,

  /**
   * 是否使用无穷循环模式
   */
  infinite: _propTypes["default"].bool,

  /**
   * 初始被激活的轮播图
   */
  defaultActiveIndex: _propTypes["default"].number,

  /**
   * 是否启用懒加载
   */
  lazyLoad: _propTypes["default"].bool,
  slide: _propTypes["default"].string,

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

  /**
   * 同时展示的图片数量
   */
  slidesToShow: _propTypes["default"].number,

  /**
   * 同时滑动的图片数量
   */
  slidesToScroll: _propTypes["default"].number,

  /**
   * 轮播速度
   */
  speed: _propTypes["default"].number,

  /**
   * 跳转到指定的轮播图（受控）
   */
  activeIndex: _propTypes["default"].number,

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

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

  /**
   * 自定义传入的class
   */
  style: _propTypes["default"].object,

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

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

  /**
   * 多图轮播时，点击选中后自动居中
   */
  focusOnSelect: _propTypes["default"].bool,
  pauseOnHover: _propTypes["default"].bool,
  // 鼠标经过时停止播放
  swipe: _propTypes["default"].bool,
  swipeToSlide: _propTypes["default"].bool,
  touchMove: _propTypes["default"].bool,
  touchThreshold: _propTypes["default"].number,
  useCSS: _propTypes["default"].bool,
  variableWidth: _propTypes["default"].bool,
  // used
  waitForAnimate: _propTypes["default"].bool,
  edgeEvent: _propTypes["default"].any,
  swipeEvent: _propTypes["default"].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'
});