<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('operation.userNoticeRead.quick Search Fields') })"
        ></TableHeader>

        <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: 'operation/userNoticeRead',
})

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

const baTable = new baTableClass(
    new baTableApi('/admin/operation.UserNoticeRead/'),
    {
        pk: 'id',
        column: [
            { label: t('operation.userNoticeRead.id'), prop: 'id', align: 'center', width: 100, operator: 'RANGE', sortable: 'custom' },
            { label: t('operation.userNoticeRead.user_id'), prop: 'user_id', align: 'center', width: 100, operator: 'RANGE', show: false },
            {
                label: t('operation.userNoticeRead.username'),
                prop: 'user.username',
                align: 'center',
                minWidth: 120,
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tags',
            },
            { label: t('operation.userNoticeRead.notice_id'), prop: 'notice_id', align: 'center', width: 100, operator: 'RANGE', show: false },
            {
                label: t('operation.userNoticeRead.notice_title'),
                prop: 'operationNotice.title',
                align: 'center',
                minWidth: 180,
                operator: 'LIKE',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tags',
            },
            {
                label: t('operation.userNoticeRead.read_at'),
                prop: 'read_at',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                comSearchRender: 'datetime',
                width: 170,
                sortable: 'custom',
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
            {
                label: t('operation.userNoticeRead.confirmed'),
                prop: 'confirmed',
                align: 'center',
                width: 100,
                operator: 'eq',
                render: 'tag',
                effect: 'dark',
                custom: { 0: 'info', 1: 'success' },
                replaceValue: {
                    '0': t('operation.userNoticeRead.confirmed 0'),
                    '1': t('operation.userNoticeRead.confirmed 1'),
                },
            },
            {
                label: t('operation.userNoticeRead.create_time'),
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                comSearchRender: 'datetime',
                width: 170,
                sortable: 'custom',
                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>

<style scoped lang="scss"></style>
