<!-- 账号管理-资金账户管理-详情 -->
<template>
    <app-drawer :title="t('account.tradingacct.details.title')" width="480" v-model:show="show">
        <app-table-details :data="data" :label-width="120" :cell-props="detailProps" />
        <template #footer>
            <el-button @click="onCancel">{{ t('operation.close') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate } from '@/filters'
import { useEnum } from '@/hooks/enum'
import { useRequest } from '@/hooks/request'
import { tradingAccView } from '@/services/api/account'
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({
    record: {
        type: Object as PropType<Model.TradingAccRsp>,
        required: true
    }
})

const { global: { t } } = i18n

const loginstatusEnum = useEnum('loginstatus') // 账号状态

const show = shallowRef(true)

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

const detailProps: CellProp[] = [
    { prop: 'loginid', label: 'account.tradingacct.details.loginid' },
    { prop: 'loginstatus', label: 'account.tradingacct.details.loginstatus', formatValue: (val) => loginstatusEnum.getEnumTypeName(val) },
    { prop: 'accountIdS', label: 'account.tradingacct.details.accountIdS', formatValue: (val) => val?.join(',') },
    { prop: 'modifytime', label: 'account.tradingacct.details.modifytime', formatValue: (val) => formatDate(val) }
]

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