<!-- 交易商管理-交易商管理-交易商管理-登录账户-详情 -->
<template>
    <app-drawer :title="t('investor.manage.user.login.details.title')" width="480" v-model:show="show" :refresh="refresh">
        <app-table-details :data="data" :label-width="140" :cell-props="detailProps">
            <template #loginid>
                {{ `${data?.loginid}(${data?.bindname})` }}
            </template>
        </app-table-details>
        <template #footer>
            <el-button @click="onCancel(false)">{{ t('operation.close') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { decryptAES } from '@/services/crypto'
import { useRequest } from '@/hooks/request'
import { queryUserAuthInfo } from '@/services/api/investor'
import { CellProp } from '@pc/components/base/table-details/types'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTableDetails from '@pc/components/base/table-details/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    selectedItem: {
        type: Object as PropType<Investor.InvestorLoginListRsp>,
        required: true
    },
})

const { global: { t } } = i18n
const show = shallowRef(true)
const refresh = shallowRef(false)

const { data } = useRequest(queryUserAuthInfo, {
    params: {
        loginid: props.selectedItem.loginid
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const detailProps: CellProp[] = [
    { prop: 'loginid', label: 'investor.manage.user.login.details.loginid' },
    { prop: 'authid', label: 'investor.manage.user.login.details.authid', formatValue: (val) => decryptAES(val) },
]

const onCancel = (isRefresh = false) => {
    show.value = false
    refresh.value = isRefresh
}
</script>