<template>
    <div class="kb-document">
        <el-card class="!border-none" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item class="w-[180px]" label="领域">
                    <el-select v-model="queryParams.domain" clearable placeholder="全部">
                        <el-option label="资讯" value="article" />
                        <el-option label="帖子" value="post" />
                        <el-option label="彩票" value="lottery" />
                    </el-select>
                </el-form-item>
                <el-form-item class="w-[180px]" label="子类型">
                    <el-select v-model="queryParams.subtype" clearable placeholder="全部">
                        <el-option label="article" value="article" />
                        <el-option label="post" value="post" />
                        <el-option label="draw_result" value="draw_result" />
                        <el-option label="ai_history" value="ai_history" />
                    </el-select>
                </el-form-item>
                <el-form-item class="w-[180px]" label="状态">
                    <el-select v-model="queryParams.is_active" clearable placeholder="全部">
                        <el-option label="启用" :value="1" />
                        <el-option label="停用" :value="0" />
                    </el-select>
                </el-form-item>
                <el-form-item class="w-[220px]" label="关键词">
                    <el-input v-model="queryParams.title" placeholder="标题或关键词" clearable @keyup.enter="resetPage" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="ID" prop="id" min-width="80" />
                <el-table-column label="领域" prop="domain" min-width="100" />
                <el-table-column label="子类型" prop="subtype" min-width="110" />
                <el-table-column label="来源ID" prop="source_id" min-width="100" />
                <el-table-column label="标题" prop="title" min-width="260" show-overflow-tooltip />
                <el-table-column label="关键词" prop="keywords" min-width="220" show-overflow-tooltip />
                <el-table-column label="状态" min-width="80">
                    <template #default="{ row }">
                        <el-tag :type="row.is_active ? 'success' : 'info'">{{ row.is_active ? '启用' : '停用' }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="源更新时间" prop="source_updated_at_text" min-width="160" />
                <el-table-column label="更新时间" prop="update_time_text" min-width="160" />
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup name="kbDocument">
import { kbDocumentLists } from '@/api/ai'
import { usePaging } from '@/hooks/usePaging'

const queryParams = reactive({ domain: '', subtype: '', is_active: '', title: '' })
const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: kbDocumentLists,
    params: queryParams
})

getLists()
</script>
