<template>
	<view class="custom-swiper-wrapper">
		<swiper class="custom-swiper" :current="activeIndex" @change="onSwiperChange" circular :duration="300"
			indicator-dots="false" autoplay="false" display-multiple-items="1" :previous-margin="outerMargin"
			:next-margin="outerMargin" indicator-color="rgba(255, 255, 255, 0.5)" indicator-active-color="#FFEB66">
			<swiper-item v-for="(item, index) in (products||[])" :key="index">
				<view class="item-container">
					<view class="swiper-item" :class="{ 'swiper-item-active': index === currentCenterIndex }">
						<image class="item-image" :src="item.imgUrl" mode="aspectFit"></image>
						<view class="item-text" v-if="index === currentCenterIndex">
							<view class="text-title">{{ item.prizeLevel }}等奖</view>
							<view class="text-desc">{{ item.productName }}</view>
						</view>
					</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		props: {
			products: {
				type: Array,
				default:() => [],
			}
		},
		data() {
			return {
				activeIndex: 0, // 初始激活项索引（建议从1开始，避免循环时偏移）
				outerMargin: '120rpx', // 轮播左右外部间距
				
			};
		},
		computed: {
			currentCenterIndex() {
				if (this.products.length === 0) return 0;
				return this.activeIndex % this.products.length;
			}
		},
		methods: {
			onSwiperChange(e) {
				this.activeIndex = e.detail.current;
			},
		},
	};
</script>

<style scoped>
	.custom-swiper-wrapper {
		width: 100%;
		overflow: hidden;
	}

	.custom-swiper {
		width: 100%;
		height: 500rpx;
	}

	.item-container {
		padding: 0 20rpx;
	}

	.swiper-item {
		width: 100% !important;
		height: 348rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 12rpx 19rpx 2rpx rgba(219, 73, 22, 0.6);
		border-radius: 24rpx;
		border: 4rpx solid #FFCA96;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
		padding: 20rpx 0;
		transition: all 0.3s ease;
	}

	.swiper-item-active {
		transition: all 0.5s ease;
		height: 420rpx;
		z-index: 10;
	}

	.item-image {
		width: 280rpx;
		height: 280rpx;
	}

	.item-text {
		text-align: center;
	}

	.text-title {
		font-weight: 500;
		font-size: 32rpx;
		color: #222222;
		margin: 20rpx 0 10rpx;
	}

	.text-desc {
		font-size: 24rpx;
		color: #757575;
	}
</style>