<!-- 交易商管理-交易商管理-交易商管理-资金账户-详情 -->
<template>
    <app-drawer :title="t('investor.manage.user.account.details.title')" width="900" v-model:show="show" :refresh="refresh">
        <app-table-details :data="selectedItem" :label-width="140" :cell-props="detailProps" :column="2" />
        <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 { useEnum } from '@/hooks/enum'
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.ShowAccountRsp>,
        required: true
    },
})

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

const mainaccounttypeEnum = useEnum('mainaccounttype') // 账户类型
const tradestatusEnum = useEnum('traderstatus') // 交易状态
const flagEnum = useEnum('flag') // 变动标志

const detailProps: CellProp[] = [
    { prop: 'accountid', label: 'investor.manage.user.account.details.accountid' },
    { prop: 'accountname', label: 'investor.manage.user.account.details.accountname' },
    { prop: 'ismain', label: 'investor.manage.user.account.details.ismain', formatValue: (val) => mainaccounttypeEnum.getEnumTypeName(val) },
    { prop: 'parentaccountid', label: 'investor.manage.user.account.details.parentaccountid', show: props.selectedItem.ismain === 0 },
    { prop: 'relateduserid', label: 'investor.manage.user.account.details.relateduserid' },
    { prop: 'changeflag', label: 'investor.manage.user.account.details.changeflag', formatValue: (val) => flagEnum.getEnumTypeName(val) },
    { prop: 'tradestatus', label: 'investor.manage.user.account.details.tradestatus', formatValue: (val) => tradestatusEnum.getEnumTypeName(val) },
    { prop: 'currentbalance', label: 'investor.manage.user.account.details.currentbalance' },
    { prop: 'freezemargin', label: 'investor.manage.user.account.details.freezemargin' },
    { prop: 'usedmargin', label: 'investor.manage.user.account.details.usedmargin' },
    { prop: 'freezecharge', label: 'investor.manage.user.account.details.freezecharge' },
    { prop: 'outamountfreeze', label: 'investor.manage.user.account.details.outamountfreeze' },
    { prop: 'outthreshold', label: 'investor.manage.user.account.details.outthreshold' },
]

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