"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; 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); }

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

var _vue = _interopRequireWildcard(require("vue"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _debounce = _interopRequireDefault(require("lodash/debounce"));

var _propsUtil = _interopRequireWildcard(require("../_util/props-util"));

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

var _warning = _interopRequireDefault(require("../_util/warning"));

var _classNames3 = _interopRequireDefault(require("../_util/classNames"));

var _src = _interopRequireDefault(require("../vc-slick/src"));

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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

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(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

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

var CarouselEffect = _vueTypes.default.oneOf(['scrollx', 'fade']); // Carousel


exports.CarouselEffect = CarouselEffect;
var CarouselProps = {
  effect: CarouselEffect,
  dots: _vueTypes.default.bool,
  vertical: _vueTypes.default.bool,
  autoplay: _vueTypes.default.bool,
  easing: _vueTypes.default.string,
  beforeChange: _vueTypes.default.func,
  afterChange: _vueTypes.default.func,
  // style: PropTypes.React.CSSProperties,
  prefixCls: _vueTypes.default.string,
  accessibility: _vueTypes.default.bool,
  nextArrow: _vueTypes.default.any,
  prevArrow: _vueTypes.default.any,
  pauseOnHover: _vueTypes.default.bool,
  // className: PropTypes.string,
  adaptiveHeight: _vueTypes.default.bool,
  arrows: _vueTypes.default.bool,
  autoplaySpeed: _vueTypes.default.number,
  centerMode: _vueTypes.default.bool,
  centerPadding: _vueTypes.default.string,
  cssEase: _vueTypes.default.string,
  dotsClass: _vueTypes.default.string,
  draggable: _vueTypes.default.bool,
  fade: _vueTypes.default.bool,
  focusOnSelect: _vueTypes.default.bool,
  infinite: _vueTypes.default.bool,
  initialSlide: _vueTypes.default.number,
  lazyLoad: _vueTypes.default.bool,
  rtl: _vueTypes.default.bool,
  slide: _vueTypes.default.string,
  slidesToShow: _vueTypes.default.number,
  slidesToScroll: _vueTypes.default.number,
  speed: _vueTypes.default.number,
  swipe: _vueTypes.default.bool,
  swipeToSlide: _vueTypes.default.bool,
  touchMove: _vueTypes.default.bool,
  touchThreshold: _vueTypes.default.number,
  variableWidth: _vueTypes.default.bool,
  useCSS: _vueTypes.default.bool,
  slickGoTo: _vueTypes.default.number,
  responsive: _vueTypes.default.array,
  dotPosition: _vueTypes.default.oneOf(['top', 'bottom', 'left', 'right'])
};
exports.CarouselProps = CarouselProps;
var Carousel = {
  name: 'ACarousel',
  inheritAttrs: false,
  props: (0, _propsUtil.initDefaultProps)(CarouselProps, {
    dots: true,
    arrows: false,
    draggable: false
  }),
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps)
    };
  },
  beforeMount: function beforeMount() {
    this.onWindowResized = (0, _debounce.default)(this.onWindowResized, 500, {
      leading: false
    });
  },
  mounted: function mounted() {
    if ((0, _propsUtil.default)(this, 'vertical')) {
      (0, _warning.default)(!this.vertical, 'Carousel', '`vertical` is deprecated, please use `dotPosition` instead.');
    }

    var autoplay = this.autoplay;

    if (autoplay) {
      window.addEventListener('resize', this.onWindowResized);
    } // https://github.com/ant-design/ant-design/issues/7191


    this.innerSlider = this.slick && this.slick.innerSlider;
  },
  beforeUnmount: function beforeUnmount() {
    var autoplay = this.autoplay;

    if (autoplay) {
      window.removeEventListener('resize', this.onWindowResized);
      this.onWindowResized.cancel();
    }
  },
  methods: {
    getDotPosition: function getDotPosition() {
      if (this.dotPosition) {
        return this.dotPosition;
      }

      if ((0, _propsUtil.default)(this, 'vertical')) {
        return this.vertical ? 'right' : 'bottom';
      }

      return 'bottom';
    },
    saveSlick: function saveSlick(node) {
      this.slick = node;
    },
    onWindowResized: function onWindowResized() {
      // Fix https://github.com/ant-design/ant-design/issues/2550
      var autoplay = this.autoplay;

      if (autoplay && this.slick && this.slick.innerSlider && this.slick.innerSlider.autoPlay) {
        this.slick.innerSlider.autoPlay();
      }
    },
    next: function next() {
      this.slick.slickNext();
    },
    prev: function prev() {
      this.slick.slickPrev();
    },
    goTo: function goTo(slide) {
      var dontAnimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      this.slick.slickGoTo(slide, dontAnimate);
    }
  },
  render: function render() {
    var _classNames2;

    var props = _objectSpread({}, this.$props);

    var $slots = this.$slots;

    if (props.effect === 'fade') {
      props.fade = true;
    }

    var _this$$attrs = this.$attrs,
        cls = _this$$attrs.class,
        style = _this$$attrs.style,
        restAttrs = _objectWithoutProperties(_this$$attrs, ["class", "style"]);

    var getPrefixCls = this.configProvider.getPrefixCls;
    var className = getPrefixCls('carousel', props.prefixCls);
    var dotsClass = 'slick-dots';
    var dotPosition = this.getDotPosition();
    props.vertical = dotPosition === 'left' || dotPosition === 'right';
    props.dotsClass = (0, _classNames3.default)("".concat(dotsClass), "".concat(dotsClass, "-").concat(dotPosition || 'bottom'), _defineProperty({}, "".concat(props.dotsClass), !!props.dotsClass));
    className = (0, _classNames3.default)((_classNames2 = {}, _defineProperty(_classNames2, cls, !!cls), _defineProperty(_classNames2, className, !!className), _defineProperty(_classNames2, "".concat(className, "-vertical"), props.vertical), _classNames2));

    var SlickCarouselProps = _objectSpread(_objectSpread(_objectSpread({}, props), restAttrs), {}, {
      nextArrow: (0, _propsUtil.getComponent)(this, 'nextArrow'),
      prevArrow: (0, _propsUtil.getComponent)(this, 'prevArrow')
    });

    return _vue.createVNode("div", {
      "class": className,
      "style": style
    }, [_vue.createVNode(_src.default, _vue.mergeProps(SlickCarouselProps, {
      "ref": this.saveSlick
    }), _objectSpread({}, $slots))]);
  }
};
/* istanbul ignore next */

Carousel.install = function (app) {
  app.component(Carousel.name, Carousel);
};

var _default = Carousel;
exports.default = _default;