/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var components_swiper_props = require('./props.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("swiper");
var swiperItemProps = {
  index: {
    type: Number
  },
  currentIndex: {
    type: Number
  },
  isSwitching: {
    type: Boolean,
    "default": false
  },
  getWrapAttribute: {
    type: Function
  },
  swiperItemLength: {
    type: Number,
    "default": 0
  }
};
var CARD_SCALE = 210 / 332;
var itemWidth = 0.415;
var _SwiperItem = utils_mixins["default"](classPrefixMixins).extend({
  name: "LSwiperItem",
  props: _objectSpread(_objectSpread({}, components_swiper_props["default"]), swiperItemProps),
  computed: {
    active: function active() {
      return this.index === this.currentIndex;
    },
    disposeIndex: function disposeIndex() {
      if (this.type !== "card") return 0;

      if (this.currentIndex === 0 && this.index === this.swiperItemLength - 1) {
        return -1;
      }

      if (this.currentIndex === this.swiperItemLength - 1 && this.index === 0) {
        return this.swiperItemLength;
      }

      if (this.index < this.currentIndex - 1 && this.currentIndex - this.index >= this.swiperItemLength / 2) {
        return this.swiperItemLength + 1;
      }

      if (this.index > this.currentIndex + 1 && this.index - this.currentIndex >= this.swiperItemLength / 2) {
        return -2;
      }

      return this.index;
    },
    translateX: function translateX() {
      if (this.type !== "card") return 0;
      var wrapWidth = this.getWrapAttribute("offsetWidth");
      var translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index;
      var inStage = Math.abs(translateIndex - this.currentIndex) <= 1;

      if (inStage) {
        return wrapWidth * ((translateIndex - this.currentIndex) * (1 - itemWidth * CARD_SCALE) - itemWidth + 1) / 2;
      }

      if (translateIndex < this.currentIndex) {
        return -itemWidth * (1 + CARD_SCALE) * wrapWidth / 2;
      }

      return (2 + itemWidth * (CARD_SCALE - 1)) * wrapWidth / 2;
    },
    zIndex: function zIndex() {
      if (this.type !== "card") return 0;
      var translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index;
      var isActivity = translateIndex === this.currentIndex;
      var inStage = Math.round(Math.abs(translateIndex - this.currentIndex)) <= 1;

      if (isActivity) {
        return 2;
      }

      if (inStage) {
        return 1;
      }

      return 0;
    },
    itemStyle: function itemStyle() {
      if (this.animation === "fade") {
        return {
          opacity: this.active ? 1 : 0,
          transition: this.isSwitching ? "opacity ".concat(this.duration / 1e3, "s") : ""
        };
      }

      if (this.type === "card") {
        var translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index;
        var isActivity = translateIndex === this.currentIndex;
        return {
          transform: "translateX(".concat(this.translateX, "px) scale(").concat(isActivity ? 1 : CARD_SCALE, ")"),
          transition: "transform ".concat(this.duration / 1e3, "s ease"),
          zIndex: this.zIndex
        };
      }

      return {};
    }
  },
  render: function render() {
    var _ref, _this$$scopedSlots$de, _this$$scopedSlots;

    var h = arguments[0];
    return h("div", {
      "class": ["".concat(this.classPrefix, "-swiper__container__item"), (_ref = {}, _defineProperty__default["default"](_ref, "".concat(this.classPrefix, "-swiper__card"), this.type === "card"), _defineProperty__default["default"](_ref, "".concat(this.classPrefix, "-is-active"), this.type === "card" && this.active), _defineProperty__default["default"](_ref, "".concat(this.classPrefix, "-swiper__fade"), this.animation === "fade"), _ref)],
      "style": this.itemStyle
    }, [((_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots)["default"]) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, {})) || []]);
  }
});

exports["default"] = _SwiperItem;
//# sourceMappingURL=swiper-item.js.map
