<template>
  <div class="knowledge-management">
    <div class="action-bar">
      <el-button type="primary" @click="showCreateDialog">+ 新增知识</el-button>
      <el-button @click="handleImport">批量导入</el-button>
      <el-input 
        v-model="searchKeyword" 
        placeholder="搜索知识..."
        style="width: 300px"
        clearable
      />
    </div>

    <el-table :data="knowledgeList" style="width: 100%">
      <el-table-column prop="title" label="标题" min-width="200" />
      <el-table-column prop="category" label="分类" width="120" />
      <el-table-column prop="tags" label="标签" width="200">
        <template #default="{ row }">
          <el-tag v-for="tag in row.tags" :key="tag" size="small" style="margin-right: 4px;">
            {{ tag }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template #default="{ row }">
          <el-switch 
            v-model="row.status" 
            @change="toggleStatus(row)"
          />
        </template>
      </el-table-column>
      <el-table-column prop="updateDate" label="更新时间" width="150" />
      <el-table-column label="操作" width="200" fixed="right">
        <template #default="{ row }">
          <el-button size="small" @click="editKnowledge(row)">编辑</el-button>
          <el-button size="small" type="danger" @click="deleteKnowledge(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { ElButton, ElInput, ElTable, ElTableColumn, ElTag, ElSwitch, ElPagination, ElMessage } from 'element-plus';

const searchKeyword = ref('');
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const knowledgeList = ref<any[]>([]);

onMounted(() => {
  loadKnowledge();
});

function loadKnowledge() {
  // TODO: 加载知识库数据
}

function showCreateDialog() {
  // TODO: 显示创建知识对话框
}

function handleImport() {
  // TODO: 批量导入
  ElMessage.info('批量导入功能开发中');
}

function editKnowledge(row: any) {
  // TODO: 编辑知识
}

function deleteKnowledge(row: any) {
  // TODO: 删除知识
  ElMessage.success('删除成功');
}

function toggleStatus(row: any) {
  // TODO: 切换状态
}

function handleSizeChange(val: number) {
  pageSize.value = val;
  loadKnowledge();
}

function handleCurrentChange(val: number) {
  currentPage.value = val;
  loadKnowledge();
}
</script>

<style lang="scss" scoped>
.knowledge-management {
  padding: 20px;
}

.action-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  align-items: center;
}

.el-table {
  margin-bottom: 20px;
}
</style>

