<template>
    <view class="container">
        <!-- 自定义头部 -->
        <view class="custom-header">
            <view class="header-left" @click="navBack">
                <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);"></image>
            </view>
            <text class="header-title">履约者等级权益</text>
            <view class="header-right"></view>
        </view>
        <view class="header-placeholder"></view>

        <!-- 等级 Switcher -->
        <view class="swiper-container">
            <swiper 
                class="level-swiper" 
                previous-margin="80rpx" 
                next-margin="80rpx" 
                :current="currentIndex"
                @change="swiperChange">
                <swiper-item v-for="(level, index) in levels" :key="index" @click="changeLevel(index)">
                    <view class="level-card" :class="'level-card-' + (index + 1)" :style="{transform: currentIndex === index ? 'scale(1)' : 'scale(0.9)'}">
                        <view class="card-content">
                            <view class="card-header">
                                <view class="level-badge">{{ level.id }}</view>
                                <view class="current-badge" v-if="level.isCurrent">当前等级</view>
                            </view>
                            <text class="level-name">{{ level.name }}</text>
                            <text class="level-score">{{ level.score }}</text>
                            <!-- Crown graphic overlay -->
                            <image class="crown-overlay" src="/static/icons/crown.svg" mode="aspectFit"></image>
                        </view>
                    </view>
                </swiper-item>
            </swiper>
            <!-- 自定义指示点 -->
            <view class="swiper-dots">
                <view 
                    class="dot" 
                    v-for="(item, index) in levels" 
                    :key="index"
                    :class="{ active: currentIndex === index }">
                </view>
            </view>
        </view>

        <!-- 权益标题 -->
        <view class="benefits-title-row">
            <text class="benefits-title">{{ currentLevel.id }} 专属权益</text>
            <text class="benefits-count">({{ currentLevel.benefits.length }})</text>
        </view>

        <!-- 权益列表 -->
        <view class="benefits-grid">
            <view 
                class="benefit-item" 
                v-for="(benefit, index) in currentLevel.benefits" 
                :key="index"
                @click="showBenefitDetail(benefit)">
                <view class="benefit-icon-wrapper">
                    <image class="benefit-icon" :src="benefit.icon" mode="aspectFit" v-if="benefit.icon"></image>
                    <view class="benefit-icon-placeholder" v-else>{{ benefit.name[0] }}</view>
                </view>
                <text class="benefit-name">{{ benefit.name }}</text>
            </view>
        </view>

        <!-- 权益详情弹窗 -->
        <view class="popup-mask" :class="{ 'show': isPopupShow }" @click="closePopup" @touchmove.stop.prevent>
            <view class="popup-modal" @click.stop>
                <view class="popup-icon-wrapper">
                     <image class="benefit-icon-large" :src="currentBenefit.icon" mode="aspectFit" v-if="currentBenefit && currentBenefit.icon"></image>
                     <view class="benefit-icon-placeholder-large" v-else>{{ currentBenefit ? currentBenefit.name[0] : '' }}</view>
                </view>
                <text class="popup-title">{{ currentBenefit ? currentBenefit.name : '' }}</text>
                <text class="popup-desc">{{ currentBenefit ? currentBenefit.desc : '' }}</text>
                <button class="popup-btn" @click="closePopup">我知道了</button>
            </view>
        </view>

    </view>
</template>

<script>
export default {
    data() {
        return {
            currentIndex: 2, // 默认选中 L3
            levels: [
                { 
                    id: 'L1', 
                    name: '青铜履约者', 
                    score: '需成长值 0', 
                    isCurrent: false,
                    benefits: [
                        { name: '新手任务', desc: '完成新手任务可获得额外奖励', icon: '/static/icons/reward.svg' }
                    ]
                },
                { 
                    id: 'L2', 
                    name: '白银履约者', 
                    score: '需成长值 200', 
                    isCurrent: false,
                    benefits: [
                         { name: '新手任务', desc: '完成新手任务可获得额外奖励', icon: '/static/icons/reward.svg' },
                        { name: '优先派单', desc: '系统将优先为您派送附近的优质订单', icon: '' }
                    ]
                },
                { 
                    id: 'L3', 
                    name: '黄金履约者', 
                    score: '需成长值 500', 
                    isCurrent: true,
                    benefits: [
                        { name: '极速提现', desc: '提现申请 2 小时内极速到账，无需等待。', icon: '' },
                        { name: '晋升奖励', desc: '晋升等级可获得现金红包奖励。', icon: '/static/icons/reward.svg' },
                        { name: '优先派单', desc: '系统将优先为您派送附近的优质订单。', icon: '' }
                    ]
                },
                { 
                    id: 'L4', 
                    name: '钻石履约者', 
                    score: '需成长值 2000', 
                    isCurrent: false,
                    benefits: [
                        { name: '专属客服', desc: '享受 7x24 小时专属客服通道。', icon: '/static/icons/service.svg' },
                        { name: '生日礼包', desc: '生日当天获赠专属礼包。', icon: '/static/icons/reward.svg' },
                        { name: '装备免费换', desc: '每年可免费更换一套履约装备。', icon: '' },
                        { name: '医疗互助', desc: '享受平台提供的医疗互助保障。', icon: '' }
                    ]
                }
            ],
            isPopupShow: false,
            currentBenefit: null
        }
    },
    computed: {
        currentLevel() {
            return this.levels[this.currentIndex];
        }
    },
    methods: {
        navBack() {
             uni.navigateBack({
                delta: 1
            });
        },
        swiperChange(e) {
            this.currentIndex = e.detail.current;
        },
        changeLevel(index) {
            this.currentIndex = index;
        },
        showBenefitDetail(benefit) {
            this.currentBenefit = benefit;
            this.isPopupShow = true;
        },
        closePopup() {
            this.isPopupShow = false;
        }
    }
}
</script>

<style>
/* ... Header styles keep same ... */
page {
    background-color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
.custom-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 88rpx;
    padding-top: var(--status-bar-height);
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 30rpx;
    padding-right: 30rpx;
    box-sizing: border-box;
    z-index: 100;
}
.header-placeholder {
    height: calc(88rpx + var(--status-bar-height));
}
.back-icon {
    width: 40rpx;
    height: 40rpx;
}
.header-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
}
.header-right {
    width: 40rpx;
}

.swiper-container {
    position: relative;
    padding-bottom: 30rpx;
}
.level-swiper {
    height: 360rpx;
    margin-top: 20rpx;
}
.level-card {
    height: 320rpx; 
    border-radius: 30rpx;
    margin: 0 10rpx;
    transition: transform 0.3s;
    overflow: hidden;
    position: relative;
    box-shadow: 0 10rpx 20rpx rgba(0,0,0,0.1);
}
/* Gradients */
.level-card-1 { background: linear-gradient(135deg, #E0E0E0 0%, #BDBDBD 100%); }
.level-card-2 { background: linear-gradient(135deg, #CFD8DC 0%, #B0BEC5 100%); }
.level-card-3 { background: linear-gradient(135deg, #FFC107 0%, #FF9800 100%); }
.level-card-4 { background: linear-gradient(135deg, #4FC3F7 0%, #039BE5 100%); }

.card-content {
    padding: 30rpx;
    position: relative;
    z-index: 2;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: auto; /* Push content down */
}
.level-badge {
    border: 1px solid rgba(255,255,255,0.6);
    padding: 2rpx 12rpx;
    border-radius: 10rpx;
    font-size: 24rpx;
    color: #fff;
}
.current-badge {
    background-color: rgba(255,255,255,0.9);
    color: #333;
    font-size: 20rpx;
    padding: 4rpx 12rpx;
    border-radius: 20rpx;
    font-weight: bold;
}
.level-name {
    font-size: 44rpx;
    font-weight: bold;
    color: #fff;
    margin-bottom: 10rpx;
    text-shadow: 0 2rpx 4rpx rgba(0,0,0,0.1);
}
.level-score {
    font-size: 24rpx;
    color: rgba(255,255,255,0.8);
    margin-bottom: 20rpx;
}
.crown-overlay {
    position: absolute;
    bottom: -30rpx;
    right: -30rpx;
    width: 260rpx;
    height: 260rpx;
    opacity: 0.1;
    z-index: 1;
}

/* Dots */
.swiper-dots {
    display: flex;
    justify-content: center;
    margin-top: 10rpx;
}
.dot {
    width: 12rpx;
    height: 12rpx;
    background-color: #E0E0E0;
    border-radius: 50%;
    margin: 0 6rpx;
    transition: all 0.3s;
}
.dot.active {
    width: 24rpx;
    background-color: #333;
    border-radius: 6rpx;
}

.benefits-title-row {
    padding: 20rpx 30rpx;
    display: flex;
    align-items: baseline;
}
.benefits-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
}
.benefits-count {
    font-size: 28rpx;
    color: #999;
    margin-left: 10rpx;
}

.benefits-grid {
    display: flex;
    flex-wrap: wrap;
    padding: 0 20rpx;
}
.benefit-item {
    width: 25%; /* 4 items per row */
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30rpx;
}
.benefit-icon-wrapper {
    width: 88rpx;
    height: 88rpx;
    background-color: #F8F8F8; /* Or very light color based on current level? Keep simple for now */
    border-radius: 24rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12rpx;
}
.benefit-icon {
    width: 44rpx;
    height: 44rpx;
}
.benefit-icon-placeholder {
    font-size: 36rpx;
    font-weight: bold;
    color: #FFB300;
} 
.benefit-name {
    font-size: 22rpx; /* Smaller font as requested matching image roughly */
    color: #666;
    text-align: center;
}

/* Modal */
.popup-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5); /* Semi-transparent black */
    z-index: 999;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
}
.popup-mask.show {
    display: flex; /* Show when active */
}
.popup-modal {
    width: 480rpx; /* Narrower width */
    background-color: #fff;
    border-radius: 30rpx;
    padding: 50rpx 40rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 10rpx 40rpx rgba(0,0,0,0.2); /* Drop shadow */
}
.popup-icon-wrapper {
    width: 120rpx;
    height: 120rpx;
    background-color: #FFF8E1; 
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30rpx;
}
.benefit-icon-large {
    width: 60rpx;
    height: 60rpx;
}
.benefit-icon-placeholder-large {
    font-size: 50rpx;
    font-weight: bold;
    color: #FFB300;
}
.popup-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 20rpx;
}
.popup-desc {
    font-size: 26rpx;
    color: #666;
    text-align: center;
    line-height: 1.5;
    margin-bottom: 40rpx;
}
.popup-btn {
    width: 80%;
    height: 72rpx;
    line-height: 72rpx;
    background-color: #212121;
    color: #fff;
    font-size: 28rpx;
    border-radius: 36rpx;
}
</style>
