<template>
<el-dialog v-model="dialogVisible" width="850" class="dialog-box"
    align-center
    destroy-on-close
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :show-close="false">
    <template #header="{ close, titleId, titleClass }">
        <div class="msg-header" >
            <svg-icon icon-class="finance" class="header-icon" />
            <div class="header-title">{{ t('finance.choose') }}</div>
            <div class="header-close" >
            <el-icon color="rgba(196, 196, 196, 1)" @click="close" ><Close /></el-icon>
            </div>
        </div>
    </template>
    <div class="msg-body" >
        <el-row>
            <el-form ref="postRef" autocapitalize="off" size="large" label-position="top" style="user-select: none;width: 100%;" >
                <div style="font-size: 18px;font-weight: 700;color: rgba(51, 51, 51, 1);margin-bottom: 20px;" >{{ t('finance.types') }}</div>
                <el-col :span="24">
                    <el-form-item >
                        <div style="display: flex;justify-content: space-between;width: 100%;">
                            <div class="identity-type" :class="[bankType=='B1'?'identity-type-active': '' ]" @click="selectType('B1')" >
                                <svg-icon icon-class="bank1" style="width: 41px;margin-right: 16px;" />
                                <span>{{ t('finance.b1') }}</span>
                            </div>
                            <div class="identity-type" :class="[ bankType=='B2' ? 'identity-type-active': '']" @click="selectType('B2')" >
                                <svg-icon icon-class="bank2" style="width: 41px;margin-right: 16px;" />
                                <span>{{ t('finance.b2') }}</span>
                            </div>
                            <div class="identity-type" :class="[ bankType=='B3' ? 'identity-type-active': '']" @click="selectType('B3')" >
                                <svg-icon icon-class="alipay" style="width: 41px;margin-right: 16px;" />
                                <span>{{ t('finance.b3') }}</span>
                            </div>
                        </div>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item >
                        <el-button class="send-btn" @click="openAdd" style="width: 100%;" type="primary">{{ t('form.next') }}</el-button>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
    </div>
</el-dialog>
</template>

<script setup >
import { useLocale } from 'element-plus'
import { ref, defineModel, watch } from 'vue';

const { t } = useLocale()
const dialogVisible = defineModel("show")
const emit = defineEmits(['close'])
const bankType = ref('B1')

function selectType(type) {
    bankType.value = type
}

function close() {
    dialogVisible.value = false
}

function openAdd() {
    close()
    emit('close', bankType.value)
}

watch(dialogVisible, (n, o) => {
    if(!n) {
        bankType.value = 'B1'
    }
})
</script>

<style lang="scss" scoped>
.dialog-box {
    border-radius: 16px;
    padding: 0;

    .el-dialog__header {
        margin-right: 0;
        padding: 0;
        overflow: hidden;
    }

    .el-dialog__body {
        box-sizing: border-box;
        padding: 16px 22px;
        min-height: 250px;
    }

    .msg-header {
        border-radius: 16px 16px 0 0;
        width: 100%;
        height: 50px;
        position: relative;
        overflow: hidden;
        background-color: #0F3675;
        display: flex;
        align-items: center;
        color: #fff;

        .header-icon {
            width: 25px;
            height: 28px;
            margin-left: 22px;
            margin-right: 14px;
        }

        .header-title {
            font-size: 26px;
            font-weight: 700;
        }

        .header-close {
            cursor: pointer;
            position: absolute;
            bottom: 0;
            right: 20px;
            font-size: 32px;
        }
    }

    .msg-body {
        background-color: #ffffff;
        padding: 20px 40px 0;
    }
}

.send-btn {
    margin-left: auto;
    height: 50px;
    font-size: 20px;
    flex-grow: 1;
    flex-shrink: 0;
}


.identity-type {
    width: 218px;
    height: 97px;
    border-radius: 1px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(229, 229, 229, 1);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: 700;
    color: rgba(51, 51, 51, 1);
}

.identity-type-active {
    box-shadow: 0px 2px 9px  rgba(0, 0, 0, 0.25);
}
</style>