<template>
  <view class="tab-swiper-wrapper">
    <swiper 
      class="tab-swiper"
      :style="{ height: height || '400rpx' }"
      :indicator-dots="false"
      :autoplay="false"
      :current="current"
      @change="handleChange"
      :previous-margin="previousMargin"
      :next-margin="nextMargin"
    >
      <swiper-item v-for="(item, index) in items" :key="index">
        <view class="tab-swiper-item">
          <slot :item="item" :index="index"></slot>
        </view>
      </swiper-item>
    </swiper>
  </view>
</template>

<script setup lang="ts">
const props = defineProps<{
  items: any[]
  current?: number
  previousMargin?: string
  nextMargin?: string
  height?: string
}>()

const emit = defineEmits(['change', 'update:current'])

// 处理 swiper 切换事件
const handleChange = (e: any) => {
  emit('change', e.detail.current)
  emit('update:current', e.detail.current)
}
</script>

<style lang="scss">
.tab-swiper-wrapper {
  width: 750rpx;
  margin-left: -70rpx;
  display: block;
  box-sizing: border-box;
}

.tab-swiper {
  width: 750rpx;
  display: block;
}

.tab-swiper-item {
  width: 100%;
  height: fit-content;
  box-sizing: border-box;
  padding: 0 10rpx;
}
</style>
