<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.adminWallet.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/adminWallet',
})

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

const baTable = new baTableClass(
    new baTableApi('/admin/admin.AdminWallet/'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            {
                label: t('admin.adminWallet.id'),
                prop: 'id',
                align: 'center',
                width: 70,
                operator: 'RANGE',
                sortable: 'custom',
            },
            {
                label: t('admin.adminWallet.admin_id'),
                prop: 'admin_id',
                align: 'center',
                show: false,
                width: 90,
                operator: 'RANGE',
                sortable: false,
            },
            {
                label: t('admin.adminWallet.admin_username'),
                prop: 'admin.username',
                align: 'center',
                minWidth: 140,
                operator: 'LIKE',
                render: 'tag',
                customRenderAttr: {
                    tag: () => ({
                        color: '#e8f3ff',
                        style: { color: '#1677ff', borderColor: '#91caff' },
                    }),
                },
            },
            {
                label: t('admin.adminWallet.channel_name'),
                prop: 'channel_name',
                align: 'center',
                minWidth: 120,
                operator: 'LIKE',
                render: 'tag',
                customRenderAttr: {
                    tag: () => ({
                        color: '#f0f9eb',
                        style: { color: '#67c23a', borderColor: '#b3e19d' },
                    }),
                },
            },
            { label: t('admin.adminWallet.balance'), prop: 'balance', align: 'center', minWidth: 120, operator: 'RANGE' },
            { label: t('admin.adminWallet.frozen_balance'), prop: 'frozen_balance', align: 'center', minWidth: 120, operator: 'RANGE' },
            { label: t('admin.adminWallet.total_income'), prop: 'total_income', align: 'center', minWidth: 120, operator: 'RANGE' },
            { label: t('admin.adminWallet.total_withdraw'), prop: 'total_withdraw', align: 'center', minWidth: 120, operator: 'RANGE' },
            {
                label: t('admin.adminWallet.create_time'),
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                comSearchRender: 'datetime',
                sortable: 'custom',
                width: 160,
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
            {
                label: t('admin.adminWallet.update_time'),
                prop: 'update_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>

