<template>
    <div class="page">
        <div class="select-card-desc">{{ t('select-card.desc') }}</div>
        <div class="cards-container">
            <van-swipe class="cards-wrapper" :loop="false" :duration="300" @change="(index) => (currentCardIndex = index)">
                <van-swipe-item v-for="(card, index) in cards" :key="index" class="card-box">
                    <img src="../assets/images/select-card-1.png" alt="" srcset="" />
                    <div class="card-info">
                        <div class="card-title">{{ card.cardName }}</div>
                        <div class="card-content">{{ card.cardDesc }}</div>
                        <ul class="card-list">
                            <li>
                                <span class="label">{{ t(`select-card.kycRequire`) }}</span>
                                <span>{{ card.kycRequire ? t('select-card.kycRequiredDesc') : t('select-card.kycRequiredDesc2') }}</span>
                            </li>
                            <li>
                                <span class="label">{{ t('select-card.currency') }}</span>
                                <span>{{ card.rechargeCurrencyInfoList[0].currency }}</span>
                            </li>
                            <li>
                                <span class="label">{{ t('select-card.needPhotoForActiveCard') }}</span>
                                <span>{{
                                    card.needPhotoForActiveCard
                                        ? t('select-card.needPhotoForActiveCardDesc')
                                        : t('select-card.needPhotoForActiveCardDesc2')
                                }}</span>
                            </li>
                            <li>
                                <span class="label">{{ t('select-card.needPhotoForOperateCard') }}</span>
                                <span>{{ card.kycRequire ? t('select-card.kycRequiredDesc') : t('select-card.kycRequiredDesc2') }}</span>
                            </li>
                            <li>
                                <span class="label">{{ t('select-card.status') }}</span>
                                <span>{{ card.status ? t('select-card.statusDesc') : t('select-card.statusDesc2') }}</span>
                            </li>
                            <li class="one">
                                <span class="label">{{ t('select-card.price') }}</span>
                                <span>{{ t('select-card.free') }}</span>
                            </li>
                        </ul>
                    </div>
                </van-swipe-item>
                <div class="swiper-indicators">
                    <div
                        v-for="(card, index) in cards"
                        :key="card.id"
                        class="indicator-dot"
                        :class="{ active: index === currentCardIndex }"
                        @click="currentCardIndex = index"
                    ></div>
                </div>
            </van-swipe>
        </div>
        <div class="fixed-btn">
            <div class="cwg-button">
                <van-button type="primary" block @click="handleSubmit">{{ t('select-card.submit') }}</van-button>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { showToast } from 'vant'
import { useI18n } from 'vue-i18n'
import { ucardApi, CardType } from '@/api/ucard'
const router = useRouter()
const { t } = useI18n()
const cards = ref<CardType[]>([])
const currentCardIndex = ref(0)

const getCardTypes = async () => {
    try {
        const res = await ucardApi.cardKycTypesList({
            page: {
                current: 1,
                row: 100,
            },
        })
        if (res.code === 200 && res.data) {
            let a = res.data.filter((i) => {
                return i.kycStatus == null
            })
            cards.value = a
        }
    } catch (error) {
        showToast(t('common.error'))
    }
}

const handleSubmit = () => {
    const selectedCard = cards.value[currentCardIndex.value]
    router.push({
        path: '/kyc',
        query: {
            cardTypeId: selectedCard.cardTypeId,
            type: selectedCard.type,
        },
    })
}
onMounted(() => {
    getCardTypes()
})
</script>

<style scoped lang="scss">
.page {
    padding-top: 12px;
}
::v-deep {
    .van-swipe__track {
        width: 100% !important;
    }
}
.select-card-content {
    min-height: 100vh;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 12px;
}

.select-card-header {
    font-size: var(--font-size-18);
    color: var(--main-yellow);
    margin-bottom: 12px;
    text-align: center;
}

.select-card-desc {
    color: #474747;
    width: 100%;
    text-align: left;
    font-size: var(--font-size-16);
    line-height: 24px;
}

.cards-container {
    width: 100%;
    position: relative;
    overflow: hidden;
    margin-bottom: 40px;
}

.cards-wrapper {
    display: flex;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: pan-y pinch-zoom;
    will-change: transform;
    justify-content: center;
    position: relative;
    gap: 0px;
    height: 100%;
}

.card-box {
    flex: 0 0 94%;
    border-radius: 20px;
    padding-top: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 3%;
    width: 94% !important;
    transform-style: preserve-3d;
    transition: all 0.3s ease;
    height: 100%;
    box-sizing: border-box;
}
.card-box:active {
    transform: scale(0.98);
}

.card-info {
    width: 100%;
}

.card-chip {
    position: absolute;
    right: 12px;
    top: 16px;
    width: 18px;
    height: 12px;
    background: linear-gradient(145deg, #f5f5f5, #eaeaea);
    border-radius: 3px;
    border: 1px solid #bbb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.card-title {
    margin: 24px 0 12px 0;
    font-weight: 600;
    font-size: 22px;
    line-height: 28px;
    text-align: left;
    color: #1a1a1a;
}

.card-list {
    list-style: none;
    padding: 12px 0;
    margin: 0;
    width: 100%;
    flex: 1;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(140, 145, 143, 0.194);
    border-radius: 10px;
}

.card-list li {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-size-12);
    color: #1a1a1a;
    padding: 12px 24px;
    transition: all 0.3s ease;
    position: relative;
    font-family: 'Roboto';
    font-style: normal;
    font-weight: 600;
    font-size: 14px;
    line-height: 20px;
}

.label {
    width: 200px;
    font-weight: 600;
    font-size: 14px;
    line-height: 20px;
    color: #8e8a8a;
}

.card-list li:hover {
    background: rgba(73, 247, 166, 0.1);
    border-radius: 6px;
}

.card-list li:last-child {
    margin-bottom: 0;
}

.card-list li span:first-child {
    color: #bbb;
}

.card-content {
    font-size: var(--font-size-16);
    color: #474747;
    margin: 0 0 26px 0;
    text-align: left;
    line-height: 24px;
}

:deep(.van-swipe__indicators) {
    top: 220px;
    .van-swipe__indicator {
        width: 9px;
        height: 9px;
        background: #ccc;
    }
    .van-swipe__indicator--active {
        background-color: var(--main-yellow);
    }
}
.card-list {
    .one {
        margin: 12px 24px;
        padding: 12px 0;
        border-top: 1px dashed #beb6b6;
        color: #329644;
        font-family: Roboto;
        font-size: 28px;
        font-style: normal;
        font-weight: 700;
        line-height: 36px;
        align-items: flex-end;
        .label {
            color: #343434;
            font-family: Roboto;
            font-size: 16px;
            font-style: normal;
            font-weight: 600;
            line-height: 24px;
        }
    }
}
</style>
