<template>
  <div class="knowledge-view">
    <header class="page-header">
      <h1>知识库</h1>
      <p>城市生命线领域知识库，包含政策法规、技术标准、案例分析等</p>
    </header>

    <div class="search-section">
      <el-input
        v-model="searchText"
        placeholder="搜索知识库..."
        size="large"
        :prefix-icon="Search"
      />
    </div>

    <div class="knowledge-categories">
      <div
        v-for="category in categories"
        :key="category.id"
        class="category-card"
      >
        <div class="card-icon" :style="{ background: category.color }">
          <el-icon><component :is="category.icon" /></el-icon>
        </div>
        <div class="card-content">
          <h3>{{ category.name }}</h3>
          <p>{{ category.description }}</p>
          <span class="doc-count">{{ category.count }} 篇文档</span>
        </div>
      </div>
    </div>

    <div class="recent-docs">
      <h2>最近浏览</h2>
      <div class="doc-list">
        <div v-for="doc in recentDocs" :key="doc.id" class="doc-item">
          <el-icon><Document /></el-icon>
          <div class="doc-info">
            <span class="doc-title">{{ doc.title }}</span>
            <span class="doc-time">{{ doc.time }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  Search,
  Document,
  Reading,
  Files,
  DataAnalysis,
  Warning
} from '@element-plus/icons-vue'

const searchText = ref('')

const categories = [
  { id: 1, name: '政策法规', description: '国家及地方相关政策法规文件', count: 128, color: '#7c3aed', icon: 'Reading' },
  { id: 2, name: '技术标准', description: '行业技术标准与规范', count: 86, color: '#10b981', icon: 'Files' },
  { id: 3, name: '案例分析', description: '典型案例分析与经验总结', count: 54, color: '#f59e0b', icon: 'DataAnalysis' },
  { id: 4, name: '应急管理', description: '应急预案与处置流程', count: 42, color: '#ef4444', icon: 'Warning' }
]

const recentDocs = [
  { id: 1, title: '城市供水管网安全运行管理规范', time: '2小时前' },
  { id: 2, title: '燃气管道安全检测技术标准', time: '昨天' },
  { id: 3, title: '城市内涝应急处置预案模板', time: '3天前' }
]
</script>

<style lang="scss" scoped>
.knowledge-view {
  padding: 32px 48px;
  height: 100%;
  overflow-y: auto;
}

.page-header {
  margin-bottom: 32px;
  
  h1 {
    font-size: 24px;
    color: #1f2937;
    margin-bottom: 8px;
  }
  
  p {
    color: #6b7280;
    font-size: 14px;
  }
}

.search-section {
  margin-bottom: 32px;
  max-width: 600px;
}

.knowledge-categories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
  
  .category-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 24px;
    display: flex;
    gap: 16px;
    cursor: pointer;
    transition: all 0.2s;
    
    &:hover {
      border-color: #7c3aed;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }
    
    .card-icon {
      width: 48px;
      height: 48px;
      border-radius: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      font-size: 24px;
      flex-shrink: 0;
    }
    
    .card-content {
      h3 {
        font-size: 16px;
        color: #1f2937;
        margin-bottom: 4px;
      }
      
      p {
        font-size: 13px;
        color: #6b7280;
        margin-bottom: 8px;
      }
      
      .doc-count {
        font-size: 12px;
        color: #7c3aed;
      }
    }
  }
}

.recent-docs {
  h2 {
    font-size: 18px;
    color: #1f2937;
    margin-bottom: 16px;
  }
  
  .doc-list {
    .doc-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 16px;
      background: #fff;
      border: 1px solid #e5e7eb;
      border-radius: 8px;
      margin-bottom: 8px;
      cursor: pointer;
      
      &:hover {
        background: #f9fafb;
      }
      
      .el-icon {
        color: #6b7280;
        font-size: 20px;
      }
      
      .doc-info {
        display: flex;
        justify-content: space-between;
        flex: 1;
        
        .doc-title {
          color: #374151;
        }
        
        .doc-time {
          color: #9ca3af;
          font-size: 12px;
        }
      }
    }
  }
}
</style>
