/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { defineComponent, computed, createVNode } from 'vue';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import props from './props.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../config-provider/type.mjs';

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(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 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 = defineComponent({
  name: "TSwiperItem",
  props: _objectSpread(_objectSpread({}, props), swiperItemProps),
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var prefix = usePrefixClass();
    var active = computed(function () {
      return props2.index === props2.currentIndex;
    });
    var disposeIndex = computed(function () {
      if (props2.type !== "card") return 0;
      if (props2.currentIndex === 0 && props2.index === props2.swiperItemLength - 1) return -1;
      if (props2.currentIndex === props2.swiperItemLength - 1 && props2.index === 0) return props2.swiperItemLength;
      if (props2.index < props2.currentIndex - 1 && props2.currentIndex - props2.index >= props2.swiperItemLength / 2) return props2.swiperItemLength + 1;
      if (props2.index > props2.currentIndex + 1 && props2.index - props2.currentIndex >= props2.swiperItemLength / 2) return -2;
      return props2.index;
    });
    var translateX = computed(function () {
      if (props2.type !== "card") return 0;
      var wrapWidth = props2.getWrapAttribute("offsetWidth") || 0;
      var translateIndex = !active.value && props2.swiperItemLength > 2 ? disposeIndex.value : props2.index;
      var inStage = Math.abs(translateIndex - props2.currentIndex) <= 1;
      if (inStage) return wrapWidth * ((translateIndex - props2.currentIndex) * (1 - itemWidth * CARD_SCALE) - itemWidth + 1) / 2;
      if (translateIndex < props2.currentIndex) return -itemWidth * (1 + CARD_SCALE) * wrapWidth / 2;
      return (2 + itemWidth * (CARD_SCALE - 1)) * wrapWidth / 2;
    });
    var zIndex = computed(function () {
      if (props2.type !== "card") return 0;
      var translateIndex = !active.value && props2.swiperItemLength > 2 ? disposeIndex.value : props2.index;
      var isActivity = translateIndex === props2.currentIndex;
      var inStage = Math.round(Math.abs(translateIndex - props2.currentIndex)) <= 1;
      if (isActivity) return 2;
      if (inStage) return 1;
      return 0;
    });
    var itemStyle = computed(function () {
      if (props2.animation === "fade") {
        return {
          opacity: active.value ? 1 : 0,
          transition: props2.isSwitching ? "opacity ".concat(props2.duration / 1e3, "s") : "",
          zIndex: active.value ? 1 : 0
        };
      }
      if (props2.type === "card") {
        var translateIndex = !active.value && props2.swiperItemLength > 2 ? disposeIndex.value : props2.index;
        var isActivity = translateIndex === props2.currentIndex;
        return {
          transform: "translateX(".concat(translateX.value, "px) scale(").concat(isActivity ? 1 : CARD_SCALE, ")"),
          transition: "transform ".concat(props2.duration / 1e3, "s ease"),
          zIndex: zIndex.value
        };
      }
      return {};
    });
    return function () {
      var _ref2, _slots$default;
      return createVNode("div", {
        "class": ["".concat(prefix.value, "-swiper__container__item"), (_ref2 = {}, _defineProperty(_ref2, "".concat(prefix.value, "-swiper__card"), props2.type === "card"), _defineProperty(_ref2, "".concat(prefix.value, "-is-active"), props2.type === "card" && active.value), _defineProperty(_ref2, "".concat(prefix.value, "-swiper__fade"), props2.animation === "fade"), _ref2)],
        "style": itemStyle.value
      }, [((_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots, {})) || []]);
    };
  }
});

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