<template>
    <div class="page kyc-page" v-if="form.cardNo">
        <div class="kyc-form">
            <remit-input v-model:value="form.cardNo" fkey="cardNo" :readonly="true" :label="t('card-activation.cardNo')" />
            <remit-input
                v-model:value="form.activePhoto"
                type="upload"
                :required="true"
                fkey="activePhoto"
                :label="t('card-activation.activePhoto')"
                :rules="[{ required: true, message: t('card-activation.activePhoto') }]"
                @change="handleChange"
            />

            <div class="kyc-button">
                <van-button type="primary" block @click="handleNext1">{{ t('card-activation.submit') }}</van-button>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { ucardApi } from '@/api/ucard'
import { showToast } from 'vant'
const route = useRoute()
const { t } = useI18n()
const router = useRouter()
const form = ref({})

const { id } = route.query as { id: string }
const formData = ref<typeof form.value>({ id } as any)
const getCardInfo = async () => {
    if (!id) return
    try {
        const res = await ucardApi.cardSingle({ id })
        if (res.code === 200 && res.data) {
            form.value = res.data
        }
    } catch (error) {
        showToast(t('common.error'))
    }
}

const handleNext1 = async () => {
    formData.value = { ...form.value, ...formData.value }
    if (!formData.value.activePhoto) {
        showToast(t('card-activation.activePhotoRequired'))
        return
    }

    try {
        const res = await ucardApi.ucardActivate(formData.value)
        if (res.code === 200) {
            showToast(t('card-activation.submitRequired'))
            router.back()
        } else {
            showToast(res.msg)
        }
    } catch (error) {
        showToast('error')
    }
}

onMounted(() => {
    getCardInfo()
})
const handleChange = (value: any) => {
    formData.value = { ...formData.value, [value.key]: value.value }
}
</script>

<style scoped lang="scss">
.kyc-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #232323 0%, #2a2a2a 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 12px;
}
.kyc-header {
    width: 100%;
    text-align: center;
    margin-bottom: 24px;
    h2 {
        font-size: var(--font-size-18);
        color: var(--main-yellow);
        margin-bottom: 8px;
    }
    p {
        color: #bbb;
        font-size: var(--font-size-12);
        line-height: 1.5;
    }
}
.kyc-form {
    width: 100%;
    max-width: 350px;
    border-radius: 20px;
    padding: 28px 18px 18px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.form-item {
    margin-bottom: 0;
    ::v-deep {
        .van-field {
            background: #181818;
            border-radius: 12px;
            padding: 12px 16px;
            transition: all 0.3s ease;

            &:focus-within {
                background: #1f1f1f;
            }

            .van-field__label {
                color: #bbb;
                font-size: var(--font-size-14);
                width: 80px;
            }

            .van-field__control {
                color: #fff;
                font-size: var(--font-size-14);
                min-height: 20px;
                line-height: 20px;

                &::placeholder {
                    color: #666;
                    font-size: var(--font-size-14);
                }

                &::-webkit-input-placeholder {
                    color: #666;
                }

                &::-moz-placeholder {
                    color: #666;
                    opacity: 1;
                }
            }

            .van-field__right-icon {
                color: var(--main-yellow);
                margin-left: 8px;
            }

            .van-field__error-message {
                color: #ff4d4f;
                font-size: var(--font-size-12);
                margin-top: 4px;
            }
        }
    }
}
.kyc-button {
    margin-top: 18px;
    ::v-deep {
        .van-button {
            height: 44px;
            border-radius: 24px;
            background: var(--main-yellow);
            border: none;
            color: #232323;
            font-size: var(--font-size-16);
            font-weight: bold;

            &:active {
                opacity: 0.9;
            }
        }
    }
}
.apply-card-steps {
    width: 100%;
    max-width: 350px;
    margin-bottom: 32px;

    .steps-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 12px;
    }

    .step {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;

        .step-circle {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: var(--action-bg, #181818);
            border: 2px solid #444;
            color: #444;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: var(--font-size-16);
            font-weight: bold;
            transition: all 0.3s ease;
        }

        .step-label {
            font-size: var(--font-size-14);
            color: #444;
            transition: all 0.3s ease;
        }

        &.active {
            .step-circle {
                background: var(--main-yellow);
                border-color: var(--main-yellow);
                color: #232323;
            }

            .step-label {
                color: var(--main-yellow);
            }
        }
    }

    .step-dash {
        flex: 1;
        height: 2px;
        margin: 0 8px;
        position: relative;
        top: -16px;
        transition: all 0.3s ease;
        background-image: linear-gradient(to right, #444 50%, transparent 50%);
        background-size: 8px 2px;
        background-repeat: repeat-x;

        &.active {
            background-image: linear-gradient(to right, var(--main-yellow) 50%, transparent 50%);
        }
    }
}

.phone-input {
    display: flex;
    align-items: center;
    background: #181818;
    border-radius: 12px;
    padding: 0 16px;
    height: 44px;
    transition: all 0.3s ease;

    &:focus-within {
        background: #1f1f1f;
    }

    .phone-code {
        width: 20%;
        ::v-deep .van-cell {
            &::after {
                border-bottom: 0;
            }
            .van-icon {
                font-size: var(--font-size-14);
                line-height: 20px;
            }
        }
        ::v-deep {
            .van-field {
                background: transparent;
                padding-left: 0;
                padding-right: 0;

                .van-field__control {
                    color: var(--white);
                    text-align: center;
                    padding: 0;
                }
            }
        }
    }
    .phone-code-active {
        ::v-deep .van-cell {
            .van-icon {
                color: var(--white);
            }
        }
    }

    .phone-divider {
        width: 1px;
        height: 20px;
        background: #333;
        margin: 0 12px;
        transition: all 0.3s ease;
    }

    .phone-number {
        flex: 1;
        ::v-deep {
            .van-field {
                background: transparent;
                padding-left: 10px;

                .van-field__control {
                    color: #fff;
                    text-align: left;
                    padding: 0;

                    &::placeholder {
                        color: #666;
                        text-align: left;
                    }
                }
            }
        }
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 0.2;
    }
}

::v-deep {
    .van-picker {
        background: #181818;

        .van-picker__toolbar {
            background: #181818;
            border-bottom: 1px solid #333;
            height: 44px;
            padding: 0 16px;

            .van-picker__title {
                color: #fff;
                font-size: var(--font-size-16);
                font-weight: 500;
            }

            .van-picker__cancel,
            .van-picker__confirm {
                color: var(--main-yellow);
                font-size: var(--font-size-14);
                padding: 0 8px;
                height: 28px;
                line-height: 28px;
                border-radius: 14px;
                transition: all 0.3s ease;

                &:active {
                    opacity: 0.8;
                    background: rgba(255, 193, 7, 0.1);
                }
            }
        }

        .van-picker-column {
            color: #fff;

            .van-picker-column__item {
                color: #fff;
                font-size: var(--font-size-14);
                padding: 0 16px;
                height: 44px;
                line-height: 44px;
                transition: all 0.3s ease;

                &--selected {
                    color: var(--main-yellow);
                    font-weight: 500;
                    font-size: var(--font-size-16);
                }

                &:active {
                    background: rgba(255, 255, 255, 0.05);
                }
            }

            .van-picker-column__wrapper {
                &::after {
                    border-color: #333;
                }
            }
        }

        .van-picker__mask {
            background-image: linear-gradient(180deg, rgba(24, 24, 24, 0.9), rgba(24, 24, 24, 0.4)),
                linear-gradient(0deg, rgba(24, 24, 24, 0.9), rgba(24, 24, 24, 0.4));
        }

        .van-picker__indicator {
            height: 44px;
            background: rgba(255, 193, 7, 0.05);
            border-top: 1px solid rgba(255, 193, 7, 0.1);
            border-bottom: 1px solid rgba(255, 193, 7, 0.1);
        }
    }
}
</style>
