/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import props from './props.js';
import 'vue';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-def4c2ce.js';

const classPrefixMixins = getClassPrefixMixins("swiper");
const swiperItemProps = {
  index: {
    type: Number
  },
  currentIndex: {
    type: Number
  },
  isSwitching: {
    type: Boolean,
    default: false
  },
  getWrapAttribute: {
    type: Function
  },
  swiperItemLength: {
    type: Number,
    default: 0
  }
};
const CARD_SCALE = 210 / 332;
const itemWidth = 0.415;
var _SwiperItem = mixins(classPrefixMixins).extend({
  name: "LSwiperItem",
  props: {
    ...props,
    ...swiperItemProps
  },
  computed: {
    active() {
      return this.index === this.currentIndex;
    },
    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() {
      if (this.type !== "card") return 0;
      const wrapWidth = this.getWrapAttribute("offsetWidth");
      const translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index;
      const 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() {
      if (this.type !== "card") return 0;
      const translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index;
      const isActivity = translateIndex === this.currentIndex;
      const inStage = Math.round(Math.abs(translateIndex - this.currentIndex)) <= 1;
      if (isActivity) return 2;
      if (inStage) return 1;
      return 0;
    },
    itemStyle() {
      if (this.animation === "fade") {
        return {
          opacity: this.active ? 1 : 0,
          transition: this.isSwitching ? `opacity ${this.duration / 1e3}s` : "",
          zIndex: this.active ? 1 : 0
        };
      }
      if (this.type === "card") {
        const translateIndex = !this.active && this.swiperItemLength > 2 ? this.disposeIndex : this.index;
        const isActivity = translateIndex === this.currentIndex;
        return {
          transform: `translateX(${this.translateX}px) scale(${isActivity ? 1 : CARD_SCALE})`,
          transition: `transform ${this.duration / 1e3}s ease`,
          zIndex: this.zIndex
        };
      }
      return {};
    }
  },
  render() {
    var _this$$scopedSlots$de, _this$$scopedSlots;
    const h = arguments[0];
    return h("div", {
      "class": [`${this.classPrefix}-swiper__container__item`, {
        [`${this.classPrefix}-swiper__card`]: this.type === "card",
        [`${this.classPrefix}-is-active`]: this.type === "card" && this.active,
        [`${this.classPrefix}-swiper__fade`]: this.animation === "fade"
      }],
      "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, {})) || []]);
  }
});

export { _SwiperItem as default };
//# sourceMappingURL=swiper-item.js.map
