<template>
    <cwg-popup v-model:visible="visible" type="center" :mask-click="false" :showFooters="true"
        :title="t('Custom.Deposit.DigitalAcc')">
        <view class="popup-content">
            <view class="dia-content digital-pay-confirm-body">
                <view class="digital-pay-info">
                    <view class="digital-pay-info__fields">
                        <view class="digital-pay-field">
                            <span class="digital-pay-field__label" v-t="'Custom.Deposit.DigitalName'"></span>
                            <view class="digital-pay-field__value digital-pay-field__value--currency">
                                {{
                                    WireTransferAccount.name + "-" + WireTransferAccount.type
                                }}
                            </view>
                        </view>
                        <view class="digital-pay-field">
                            <span class="digital-pay-field__label" v-t="'Custom.Withdraw.Title6'"></span>
                            <view class="digital-pay-field__value digital-pay-field__value--address">
                                {{ WireTransferAccount.address || "--" }}
                            </view>
                        </view>
                    </view>
                    <view class="digital-pay-info__qr">
                        <view class="digital-pay-info__qr-inner">
                            <image :src="Host05 + WireTransferAccount.url" alt="" mode="widthFix" />
                        </view>
                    </view>
                </view>
                <view class="digital-pay-divider" role="presentation"></view>
                <view class="digital-pay-upload-wrap">
                    <view class="digital-pay-upload__label" v-t="'Custom.Deposit.UploadRemittanceVoucher'">
                    </view>
                    <cwg-file-picker-wrapper v-model="imageUrl" :limit="1" :editable="true" :fileMediatype="'all'"
                        uploadUrl="/common/upload" :baseUrl="Host80" />
                </view>
            </view>
        </view>
        <template #footer>
            <button @click="close">{{ t('Btn.Cancel') }}</button>
            <button type="primary" @click="handleConfirm">{{ t('Btn.Confirm') }}</button>
        </template>
    </cwg-popup>
</template>

<script setup>
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import Config from '@/config/index'
const { Code, Host05, Host04 } = Config
const props = defineProps({
    visible: { type: Boolean, default: false },
    data: { type: Object, default: () => ({ balance: 0, income: 0 }) },
    WireTransferAccount: { type: Object, default: () => ({ name: '', type: '', address: '', url: '' }) },
});
const emit = defineEmits(['update:visible']);

const { t } = useI18n();
const visible = computed({
    get: () => props.visible,
    set: (val) => emit('update:visible', val)
});
const imageUrl = ref('');
const handleConfirm = () => {
    if (!imageUrl.value) {
        uni.showToast({
            title: t('Custom.Deposit.UploadRemittanceVoucher'),
            icon: 'none'
        })
        return
    }
    emit('confirm', imageUrl.value)
    close()
}
const close = () => { visible.value = false; imageUrl.value = ""; };
</script>

<style lang="scss" scoped>
@import "@/uni.scss";

.popup-content {
    padding: px2rpx(20);
    text-align: center;

    .des1 {
        font-size: px2rpx(16);
        line-height: 1.6;
        margin: px2rpx(30) 0 px2rpx(50);
    }

    .myRED {
        color: #f56c6c;
        font-weight: bold;
    }
}

.digital-pay-confirm-body {
    text-align: left;
    padding: 0 0 px2rpx(4);
    box-sizing: border-box;

    .digital-pay-info {
        display: flex;
        align-items: center;
        gap: 24px;
        padding: 8px 0 px2rpx(4);
    }

    .digital-pay-info__fields {
        flex: 1;
        min-width: 0;
    }

    .digital-pay-field {
        margin-bottom: px2rpx(18);

        &:last-child {
            margin-bottom: 0;
        }
    }

    .digital-pay-field__label {
        display: block;
        font-size: px2rpx(14);
        font-weight: bold;
        margin-bottom: px2rpx(8);
        line-height: 1.4;
        color: #323232;
    }

    .digital-pay-field__value {
        font-size: px2rpx(14);  
        line-height: 1.55;
        word-break: break-all;
        overflow-wrap: anywhere;
    }

    .digital-pay-field__value--currency {
        max-width: 100%;
        padding: px2rpx(10) px2rpx(14);
        border-radius: px2rpx(4);
        border: 1px solid #e8e8e8;
        color: #323232;
        box-sizing: border-box;
    }

    .digital-pay-field__value--address {
        padding: 0;
        border: none;
        background: transparent;
        font-size: px2rpx(14);
        color: #323232;
        line-height: 1.6;
    }

    .digital-pay-info__qr {
        flex-shrink: 0;
        align-self: center;
    }

    .digital-pay-info__qr-inner {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: px2rpx(10);
        border: 1px solid #e4e7ed;
        border-radius: px2rpx(6);
        background: #fafafa;
        box-sizing: border-box;

        image {
            display: block;
            width: px2rpx(120);
            height: px2rpx(120);
            object-fit: contain;
        }
    }

    .digital-pay-divider {
        border: none;
        border-top: 1px solid #e4e7ed;
        margin: px2rpx(20) 0 px2rpx(22);
    }

    .digital-pay-upload-wrap {
        margin-top: 0;
    }

    .digital-pay-upload__label {
        font-size: px2rpx(14);
        font-weight: bold;
        margin-bottom: px2rpx(10);
        line-height: 1.4;
        color: #323232;
    }
}

.dialog-digital-pay {
    border-radius: px2rpx(8);
    overflow: hidden;

    .el-dialog__header {
        padding: px2rpx(18) px2rpx(20) px2rpx(8);
    }

    .el-dialog__title {
        font-size: px2rpx(16);
        font-weight: bold;
        color: #323232;
    }

    .el-dialog__body {
        padding: px2rpx(4) px2rpx(28) px2rpx(8);
    }

    .el-dialog__footer {
        padding: px2rpx(8) px2rpx(22);
    }
}
</style>