<template>
    <div class="page">
        <div class="step">
            <div v-for="item in stepList" :key="item.id" :class="step >= item.id ? 'step-item step-active' : 'step-item'">
                <div v-t="$t(item.name)" class="step-item-content"></div>
            </div>
        </div>

        <div class="form-box">
            <div v-if="step == 1" class="status-box">
                <div class="status">
                    <template v-if="cardInfo.tradeType == '1'">
                        <span v-if="cardInfo.tradeStatus == '2'" v-t="'card.Info.t8'"></span>
                        <span v-else-if="cardInfo.tradeStatus == '3'" v-t="'card.Info.t9'"></span>
                        <span v-else v-t="'card.Info.t5'"></span>
                    </template>

                    <template v-if="cardInfo.tradeType == '2'">
                        <span v-if="cardInfo.tradeStatus == '2'" v-t="'card.Info.t12'"></span>
                        <span v-else-if="cardInfo.tradeStatus == '3'" v-t="'card.Info.t13'"></span>
                        <span v-else v-t="'card.Info.t11'"></span>
                    </template>
                </div>
                <template v-if="cardInfo.tradeType == '1'">
                    <template v-if="cardInfo.tradeStatus == '1'">
                        <p v-t="'card.Info.s31'"></p>
                        <img src="@/assets/images/card/img1.png" alt="" srcset="">
                    </template>
                    <template v-if="cardInfo.tradeStatus == '3'">
                        <p v-t="'card.Info.s32'"></p>
                        <img src="@/assets/images/card/img4.png" alt="" srcset="">
                    </template>
                </template>
                <template v-if="cardInfo.tradeType == '2'">
                    <template v-if="cardInfo.tradeStatus == '1'">
                        <p v-t="'card.Info.s32'"></p>
                        <img src="@/assets/images/card/img1.png" alt="" srcset="">
                    </template>
                    <template v-if="cardInfo.tradeStatus == '2'">
                        <p v-t="'card.Info.s33'"></p>
                        <img src="@/assets/images/card/img3.png" alt="" srcset="">
                    </template>
                </template>
            </div>
            <div v-if="step == 2" class="status-box">
                <div class="status">
                    <span v-if="cardInfo.approveStatus == '2'" v-t="'card.Info.t2'"></span>
                    <span v-else-if="cardInfo.approveStatus == '3'" v-t="'card.Info.t3'"></span>
                    <span v-else v-t="'card.Info.t1'"></span>
                </div>
                <template v-if="cardInfo.approveStatus == '1'">
                    <p v-t="'card.Info.s34'"></p>
                    <img src="@/assets/images/card/img1.png" alt="" srcset="">
                </template>
                <template v-if="cardInfo.approveStatus == '3'">
                    <p v-t="'card.Info.s35'"></p>
                    <img src="@/assets/images/card/img4.png" alt="" srcset="">
                </template>
            </div>
            <div v-if="step == 3" class="status-box">
                <div class="status">
                    <span v-if="cardInfo.status === 'success'" v-t="'card.Info.t6'"></span>
                    <span v-else-if="cardInfo.status === 'fail'" v-t="'card.Info.t7'"></span>
                    <span v-else-if="cardInfo.status === 'processing'" v-t="'card.Info.t5'"></span>
                    <span v-else v-t="'card.Info.t10'"></span>
                </div>

                <template v-if="cardInfo.status == 'success'">
                    <p v-t="'card.Info.s36'"></p>
                    <img src="@/assets/images/card/img5.png" alt="" srcset="">
                    <div class="step-box">
                        <div class="step-item">
                            <div class="ids">1</div>
                            <p v-t="'card.Info.s22'" class="k"></p>
                            <p v-t="'card.Info.s23'" class="v"></p>
                        </div>
                        <div class="step-item">
                            <div class="ids">2</div>
                            <p v-t="'card.Info.s24'" class="k"></p>
                            <p v-t="'card.Info.s25'" class="v"></p>
                        </div>
                        <div class="step-item">
                            <div class="ids">3</div>
                            <p v-t="'card.Info.s26'" class="k"></p>
                            <p v-t="'card.Info.s27'" class="v"></p>
                        </div>
                        <div class="step-item">
                            <div class="ids">4</div>
                            <p v-t="'card.Info.s28'" class="k"></p>
                            <p v-t="'card.Info.s29'" class="v"></p>
                            <p v-t="'card.Info.s30'" class="v"></p>
                        </div>
                    </div>
                    <div v-t="'card.Info.s21'" class="f"></div>
                </template>
                <template v-else-if="cardInfo.status == 'fail'">
                    <p v-t="'card.Info.s37'"></p>
                    <img src="@/assets/images/card/img4.png" alt="" srcset="">
                </template>
                <template v-else>
                    <p v-t="'card.Info.s38'"></p>
                    <img src="@/assets/images/card/img1.png" alt="" srcset="">
                </template>
            </div>
        </div>
        <div v-if="cardInfo.cardName && !props.type" class="card-info1">
            <div class="card-title">{{ cardInfo.cardName }}</div>
            <div class="card-content">{{ cardInfo.cardDesc }}</div>
            <ul class="card-list">
                <li>
                    <span class="label">{{ t(`card.New1.d13`) }}</span>
                    <span>{{ cardInfo.mailingAreaCode }} {{ cardInfo.mailingMobile }}</span>
                </li>
                <li>
                    <span class="label">{{ t('card.New1.d8') }}</span>
                    <span>{{ cardInfo.mailingCountry || '--' }}</span>
                </li>
                <li>
                    <span class="label">{{ t('card.New1.d9') }}</span>
                    <span>{{ cardInfo.mailingTown }}</span>
                </li>
                <li>
                    <span class="label">{{ t('card.New1.d10') }}</span>
                    <span>{{ cardInfo.mailingAddressCn }}</span>
                </li>
                <li>
                    <span class="label">{{ t('card.New1.d11') }}</span>
                    <span>{{ cardInfo.mailingAddress }}</span>
                </li>
                <li>
                    <span class="label">{{ t('card.New1.d12') }}</span>
                    <span>{{ cardInfo.mailingPostCode }}</span>
                </li>
                <li class="one" :class="statusClass(cardInfo.status)">
                    <span class="label">{{ t('apply-record-detail.p7') }}</span>
                    <span>{{ statusMap[cardInfo.status] || t('apply-record-detail.p8') }}</span>
                </li>
            </ul>
        </div>

        <div
            v-if="(cardInfo.tradeStatus == '3' || (cardInfo.tradeStatus == '2' && cardInfo.tradeType == '2')) && cardInfo.applyStatus == 'fail'"
            class="fixed-btn"
        >
            <div class="cwg-button">
                <van-button type="primary" block @click="handleApply(3, cardInfo)">{{ t('cards.p7') }}</van-button>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import useUserStore from '@/stores/use-user-store'

const props = defineProps({
    id: String,
    type: String,
})
const userStore = useUserStore()
const applyList = computed(() => userStore.applyCard)
const { t } = useI18n()
const cardInfo = ref({})
const showCardNo = ref<{ [key: string]: boolean }>({})
const isFlipping = ref<{ [key: string]: boolean }>({})
const isShowBtn = ref(false)
const dateRange = ref<[string, string] | undefined>(undefined)
dateRange.value = ['', '']
const stepList = [
    { id: 1, name: 'card.Info.s39', status: 'finish' },
    { id: 2, name: 'card.Info.s40', status: 'process' },
    { id: 3, name: 'card.Info.s41', status: 'wait' },
]
const step = ref(1)
async function getKycList() {
    const b = applyList.value.filter((i) => {
        return i.kycStatus == null
    })
    if (b.length != 0) {
        isShowBtn.value = true
    }
    else {
        isShowBtn.value = false
    }
    const filtered = applyList.value
    if (props.id) {
        let a = {
            status: 'success',
            tradeStatus: 2,
            approveStatus: 2,
            tradeType: 1,
        }
        a = applyList.value.filter(item => item.id == props.id)[0]
        if (a?.tradeStatus == 1)
            step.value = 1
        if (a?.tradeStatus == 2 && a.tradeType == 1)
            step.value = 2
        if (a?.approveStatus == 2)
            step.value = 3
        cardInfo.value = a
    }

    console.log(props, cardInfo.value, applyList.value, props.id, filtered[0], 198)
}
const statusMap: Record<string, string> = {
    success: t('apply-record-detail.p6'),
    fail: t('apply-record-detail.p9'),
    processing: t('apply-record-detail.p8'),
    wait_process: t('apply-record-detail.p8'),
    cancel: t('apply-record-detail.p8'),
}
function statusClass(status: string) {
    switch (status) {
        case 'success':
            return 'one'
        case 'fail':
            return 'error'
        case 'cancel':
            return 'error'
        default:
            return 'default'
    }
}

function toggleCardNo(cardId: string, event: MouseEvent) {
    event.stopPropagation()
    isFlipping.value[cardId] = !isFlipping.value[cardId]
    showCardNo.value[cardId] = !showCardNo.value[cardId]
}

onMounted(async () => {
    applyList.value.forEach((card) => {
        showCardNo.value[card.id] = false
        isFlipping.value[card.id] = false
    })
    getKycList()
})
</script>

<style scoped lang="scss">
.page {
    padding: 16px 16px 150px 16px;
    box-sizing: border-box;
    min-height: 100vh;
    background: var(--main-bg);
}
.page1 {
    padding: 16px;
}
.card-wrapper {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.card-info {
    background: url(/src/assets/images/visa.png) no-repeat center center;
    background-size: cover;
    border-radius: 0.426667rem;
    padding: 0.64rem 0.533333rem 0 0.533333rem;
    color: var(--main-yellow);
    box-shadow: 0 0.106667rem 0.533333rem rgba(214, 255, 0, 0.1);
    border: 1px solid rgba(214, 255, 0, 0.2);
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: baseline;
    flex-wrap: wrap;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
    flex-direction: column;

    &.flipping {
        transform: rotateY(180deg);
    }

    .card-b {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        span {
            display: block;
        }
        .valid {
            font-size: var(--font-size-14);
            font-weight: 500;
            color: var(--black);
            text-shadow: 0 0 8px rgba(214, 255, 0, 0.2);
            gap: 8px;
            padding-right: 30px;
            line-height: 20px;
        }
        .lable {
            font-size: var(--font-size-10);
            font-weight: 400;
        }
    }
}

.card-front,
.card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 24px 20px 16px 20px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.card-back {
    transform: rotateY(180deg);
}

.owner {
    font-size: var(--font-size-14);
    line-height: 2;
    margin-bottom: 8px;
    text-shadow: 0 0 10px rgba(214, 255, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 8px;

    i {
        font-size: var(--font-size-18);
        color: var(--main-yellow);
    }
}

.number {
    color: var(--black);
    font-size: var(--font-size-18);
    font-weight: 500;
    line-height: 3;
    letter-spacing: 2px;
    margin: 24px 0;
    text-shadow: 0 0 15px rgba(214, 255, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 8px;
}

.actions {
    display: flex;
    justify-content: space-between;
    margin: 20px 0 16px 0;
}

.action-btn {
    color: var(--white);
    border: none;
    border-radius: 12px;
    padding: 10px 2px;
    font-size: var(--font-size-14);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.3s ease;
    text-align: center;
    color: #1a1a1a;

    .btn-icon {
        width: 46px;
        height: 46px;
        border-radius: 50%;
        background: #ff4766;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    i {
        display: inline-block;
        line-height: 46px;
        width: 22px;
        height: 22px;
        color: var(--black);
        margin-bottom: 4px;
    }
}

.balance-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 30px 0;
    font-size: var(--font-size-14);
}

.balance-content {
    font-size: var(--font-size-20);
    color: var(--white);
    font-weight: bold;
    margin-bottom: 24px;
}

.balance-title {
    font-size: var(--font-size-12);
    color: var(--white);
}

.currency {
    display: flex;
    align-items: center;
    font-size: var(--font-size-14);
    margin-right: 12px;
    color: var(--white);
}

.flag {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-right: 6px;
}

.balance {
    font-size: var(--font-size-14);
    font-weight: bold;
    color: var(--white);
}

.transactions {
    border-radius: 16px;
    margin-bottom: 16px;
    padding: 16px 0;
}
.trans-icon {
    width: 40px;
    height: 40px;
    display: flex;
    background: var(--main-bg);
    box-shadow: 0 4px 12px rgba(214, 255, 0, 0.1);
    border-radius: 8px;
    margin-right: 12px;
    align-items: center;
    justify-content: center;
    .trans-icon-inner {
        width: 36px;
        height: 36px;
        background: rgba(212, 206, 206, 0.24);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    i {
        color: #000;
        width: 18px;
        height: 18px;
        font-size: var(--font-size-16);
        border-radius: 50%;
    }
}

.trans-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    color: var(--white);
    i {
        font-size: var(--font-size-20);
        cursor: pointer;
    }
}
::v-deep .van-calendar {
    background: var(--action-bg);
}
::v-deep .van-calendar__month-mark {
    display: none;
}
::v-deep .van-calendar__header-subtitle {
    color: var(--white);
}
::v-deep .van-calendar__header-title {
    color: var(--white);
}
::v-deep .van-calendar__month-title {
    color: var(--main-yellow);
}

.trans-title {
    font-size: var(--font-size-20);
    color: var(--white);
    font-weight: bold;
}

.date-field {
    width: 200px;

    :deep(.van-field__control) {
        color: var(--white);
    }

    :deep(.van-field__placeholder) {
        color: var(--gray);
    }
}

:deep(.van-popup) {
    background: var(--action-bg);
}

:deep(.van-picker__toolbar) {
    background: var(--action-bg);
    border-bottom: 1px solid var(--border);
}

:deep(.van-picker__title) {
    color: var(--white);
}

:deep(.van-picker__confirm) {
    color: var(--main-yellow);
}

:deep(.van-picker__cancel) {
    color: var(--gray);
}

:deep(.van-picker-column) {
    color: var(--white);
}

:deep(.van-picker-column__item) {
    color: var(--white);
}

:deep(.van-picker-column__item--selected) {
    color: var(--main-yellow);
}

.transaction {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    /* border-bottom: 1px solid var(--border); */
    font-size: var(--font-size-16);
}

.transaction:last-child {
    border-bottom: none;
}

.trans-left {
    width: 200px;
}

.trans-right {
    width: 100px;

    div {
        text-align: right;
    }
}

.trans-type {
    color: var(--white);
    font-size: var(--font-size-14);
    line-height: 2;
}

.trans-desc {
    font-size: var(--font-size-12);
    color: var(--gray);
}

.trans-amount {
    font-size: var(--font-size-14);
    color: var(--white);
    line-height: 2;
}

.trans-date {
    color: var(--gray);
    font-size: var(--font-size-12);
}

.card-swiper {
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
    padding-bottom: 5px;
}

.swiper-container {
    position: relative;
    width: 100%;
    height: 209px;
    touch-action: pan-y pinch-zoom;
    user-select: none;
}

.card-info {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease;
    will-change: transform;
}

.swiper-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 16px;
    gap: 16px;
}

.swiper-btn {
    background: var(--action-bg);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--main-yellow);

    &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

    i {
        font-size: var(--font-size-20);
    }
}

.swiper-dots {
    display: flex;
    gap: 8px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--action-bg);
    cursor: pointer;
    transition: all 0.3s ease;

    &.active {
        background: var(--main-yellow);
        transform: scale(1.2);
    }
}

.swiper-indicators {
    display: flex;
    justify-content: center;
    margin-top: 16px;
    gap: 8px;
}

.indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--action-bg);
    cursor: pointer;
    transition: all 0.3s ease;

    &.active {
        background: var(--main-yellow);
        transform: scale(1.2);
    }
}
.flags {
    width: 20px;
    height: 20px;
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 10px;
}

.cwg-btn {
    margin: 36px 0 80px 0;
}

.card-info1 {
    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 {
    display: inline-block;
    font-weight: 600;
    font-size: 14px;
    line-height: 20px;
    color: #8e8a8a;
    width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 10px;
}

.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;
}
.a1 {
    flex: 1;
}
.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;
        }
    }
    .error {
        color: #d32f2f;
    }
    .default {
        color: #009deb;
    }
}

.step {
    display: flex;
    align-items: center;
    padding: 20px 0;
    color: #000;
    .step-item {
        width: 315px;
        position: relative;
        text-align: center;
        margin-right: 20px;
        text-align: left;
        font-size: 16px;
        padding-top: 20px;
        &::after {
            content: '';
            position: absolute;
            top: 0;
            right: 0;
            width: 100%;
            z-index: 1;
            height: 5px;
            position: absolute;
            background: #f1f1f1;
        }
    }
    .step-active {
        font-weight: bold;
        &::after {
            background: #eb3f57;
        }
    }
}
.status-box {
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding: 20px 0;
    .status {
        font-weight: 600;
        font-size: 22px;
        line-height: 28px;
        text-align: left;
        color: #1a1a1a;
    }
    p {
        width: 100%;
        text-align: start;
        color: #6f6f6f;
        font-size: 18px;
        font-weight: 400;
        word-wrap: break-word;
        line-height: 32px;
        padding: 20px 20px 20px 0;
    }

    .a-title {
        color: #333333;
        font-size: 18px;
        font-weight: 500;
        word-wrap: break-word;
        margin-top: 44px;
    }
    .step-box {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        margin-top: 20px;
        .step-item {
            width: 100%;
            padding-left: 60px;
            text-align: center;
            position: relative;
            &::after {
                content: '';
                position: absolute;
                top: 0;
                left: 15px;
                width: 0;
                height: 100%;
                border-left: 1px dashed #ccc;
                z-index: 1;
            }
            &:last-child {
                &::after {
                    display: none;
                }
            }
            .ids {
                position: absolute;
                left: 0;
                top: 0;
                width: 30px;
                height: 30px;
                position: absolute;
                color: #000;
                line-height: 30px;
                background-color: #fff;
                text-align: center;
                border-radius: 9999px;
                border: 1px #ccc dashed;
                z-index: 12;
            }

            .k {
                font-size: 14px;
                color: #333333;
                font-weight: bold;
                padding: 0;
            }
            .v {
                font-size: 14px;
                color: #6f6f6f;
                padding: 0;
            }
        }
    }
    .f {
        margin: 20px 0 0 60px;
        color: #333333;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        word-wrap: break-word;
    }
}
</style>
