<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
        <TableHeader :buttons="['refresh', 'comSearch', 'quickSearch', 'columnDisplay']" :quick-search-placeholder="t('Quick search placeholder', { fields: t('admin.adminWalletRecord.quick Search Fields') })" />
        <Table ref="tableRef"></Table>
    </div>
</template>

<script setup lang="ts">
import { onMounted, provide, useTemplateRef } from 'vue'
import { useI18n } from 'vue-i18n'
import { baTableApi } from '/@/api/common'
import TableHeader from '/@/components/table/header/index.vue'
import Table from '/@/components/table/index.vue'
import baTableClass from '/@/utils/baTable'

defineOptions({
    name: 'admin/adminWalletRecord',
})

const { t } = useI18n()
const tableRef = useTemplateRef('tableRef')

const refTypeReplace = {
    agent_commission_record: t('admin.adminWalletRecord.ref title agent_commission_record'),
    admin_withdraw_order: t('admin.adminWalletRecord.ref title admin_withdraw_order'),
    withdraw_order: t('admin.adminWalletRecord.ref title withdraw_order'),
    deposit_order: t('admin.adminWalletRecord.ref title deposit_order'),
    bet_order: t('admin.adminWalletRecord.ref title bet_order'),
    admin_user_wallet_adjust: t('admin.adminWalletRecord.ref title admin_user_wallet_adjust'),
}

const refTypeTagCustom = {
    agent_commission_record: 'success',
    admin_withdraw_order: 'warning',
    withdraw_order: 'danger',
    deposit_order: 'primary',
    bet_order: 'info',
    admin_user_wallet_adjust: 'warning',
}

const baTable = new baTableClass(
    new baTableApi('/admin/admin.AdminWalletRecord/'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('admin.adminWalletRecord.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
            { label: t('admin.adminWalletRecord.admin_id'), prop: 'admin_id', align: 'center', width: 90, operator: 'RANGE' },
            { label: t('admin.adminWalletRecord.admin_username'), prop: 'admin.username', align: 'center', minWidth: 130, operator: 'LIKE' },
            { label: t('admin.adminWalletRecord.channel_name'), prop: 'channel.name', align: 'center', minWidth: 120, operator: 'LIKE' },
            { label: t('admin.adminWalletRecord.biz_type'), prop: 'biz_type', align: 'center', minWidth: 140, operator: 'LIKE' },
            {
                label: t('admin.adminWalletRecord.direction'),
                prop: 'direction',
                align: 'center',
                width: 100,
                operator: 'eq',
                render: 'tag',
                custom: { 1: 'success', 2: 'warning' },
                replaceValue: { 1: t('admin.adminWalletRecord.direction in'), 2: t('admin.adminWalletRecord.direction out') },
            },
            { label: t('admin.adminWalletRecord.amount'), prop: 'amount', align: 'center', minWidth: 100, operator: 'RANGE' },
            { label: t('admin.adminWalletRecord.balance_before'), prop: 'balance_before', align: 'center', minWidth: 110, operator: 'RANGE' },
            { label: t('admin.adminWalletRecord.balance_after'), prop: 'balance_after', align: 'center', minWidth: 110, operator: 'RANGE' },
            {
                label: t('admin.adminWalletRecord.ref_title'),
                prop: 'ref_type',
                align: 'center',
                minWidth: 150,
                operator: 'eq',
                render: 'tag',
                replaceValue: refTypeReplace,
                custom: refTypeTagCustom,
            },
            { label: t('admin.adminWalletRecord.ref_id'), prop: 'ref_id', align: 'center', minWidth: 100, operator: 'RANGE', show: false },
            { label: t('admin.adminWalletRecord.idempotency_key'), prop: 'idempotency_key', align: 'center', minWidth: 180, operator: 'LIKE' },
            { label: t('admin.adminWalletRecord.operator_admin_username'), prop: 'operatorAdmin.username', align: 'center', minWidth: 130, operator: 'LIKE' },
            { label: t('admin.adminWalletRecord.remark'), prop: 'remark', align: 'center', minWidth: 180, operator: 'LIKE', showOverflowTooltip: true },
            {
                label: t('admin.adminWalletRecord.create_time'),
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                comSearchRender: 'datetime',
                sortable: 'custom',
                width: 160,
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
        ],
    },
    {}
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getData()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

