import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import SvgIcon from '../../components/SvgIcon';

export default function NewChat() {
    const navigate = useNavigate();
    const [knowledgeBases, setKnowledgeBases] = useState([
        {
            id: '1',
            title: '产品开发知识库',
            description: '产品开发流程及规范说明文档',
            documents: 24,
            date: '2025-02-15',
            access: 'full',
        },
        {
            id: '2',
            title: '市场分析知识库',
            description: '2025年Q1市场分析总结',
            documents: 12,
            date: '2025-02-10',
            access: 'read',
        },
        {
            id: '3',
            title: '财务知识库',
            description: '月度财务分析报告',
            documents: 8,
            date: '2025-02-01',
            access: 'none',
        },
        {
            id: '4',
            title: '技术架构知识库',
            description: '系统架构设计文档',
            documents: 15,
            date: '2025-01-20',
            access: 'full',
        },
        {
            id: '5',
            title: '用户研究知识库',
            description: '用户调研和反馈分析',
            documents: 18,
            date: '2025-01-15',
            access: 'read',
        },
    ]);

    const handleSelectKnowledgeBase = (knowledgeBaseId) => {
        // In a real app, you would create a new chat and get its ID from the API
        navigate(`/chat/${knowledgeBaseId}`);
    };

    return (
        <div className='new-chat container py-4'>
            <div className='text-center mb-5'>
                <h2 className='mb-4'>选择知识库开始聊天</h2>
            </div>

            <div className='row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4 justify-content-center'>
                {knowledgeBases.map((kb) =>
                    kb.access === 'full' || kb.access === 'read' ? (
                        <div key={kb.id} className='col'>
                            <div
                                className='card h-100 bg-light border-0 cursor-pointer'
                                onClick={() => handleSelectKnowledgeBase(kb.id)}
                                style={{ cursor: 'pointer' }}
                            >
                                <div className='card-body py-4'>
                                    <p className='card-title h5'>{kb.title}</p>
                                    <p className='card-text text-muted'>{kb.description}</p>
                                </div>
                            </div>
                        </div>
                    ) : null
                )}
            </div>
        </div>
    );
}
