import React from 'react';
import {
  Box,
  Typography,
  Accordion,
  AccordionSummary,
  AccordionDetails,
  Divider,
} from '@mui/material';
import { ExpandMore as ExpandMoreIcon } from '@mui/icons-material';
import { useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { ConfigurationFormContainer, MainContainer } from './configuration-form-container';
import {
  EmbeddingModelItem,
  AutoKeywordsItem,
  AutoQuestionsItem,
  UseRaptorItem,
  RaptorPromptItem,
  RaptorMaxTokenItem,
  RaptorThresholdItem,
  RaptorMaxClusterItem,
  RaptorRandomSeedItem,
  UseGraphragItem,
  EntityTypesItem,
  GraphragMethodItem,
  EntityNormalizeItem,
  CommunityReportItem,
} from './common-items';
import { ParseType } from '@/constants/knowledge';

export function KnowledgeGraphConfiguration({ parseType = ParseType.BuildIn }: { parseType?: ParseType }) {
  const { formState: { errors } } = useFormContext();
  const { t } = useTranslation();

  return (
    <ConfigurationFormContainer>
      <MainContainer>
        {/* 第一部分：basicConfig 基础配置 */}
        {parseType === ParseType.BuildIn && (
          <Accordion defaultExpanded>
            <AccordionSummary expandIcon={<ExpandMoreIcon />}>
              <Typography variant="h6">{t('knowledge.config.basicConfig')}</Typography>
            </AccordionSummary>
            <AccordionDetails>
              <Divider />

              <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3, mt: 3 }}>
                {/* 嵌入模型 */}
                <EmbeddingModelItem />
                {/* 自动关键词提取 */}
                <AutoKeywordsItem />
                {/* 自动问题提取 */}
                <AutoQuestionsItem />
              </Box>
            </AccordionDetails>
          </Accordion>
        )}

        {/* 第二部分：RAPTOR策略 */}
        <Accordion>
          <AccordionSummary expandIcon={<ExpandMoreIcon />}>
            <Typography variant="h6">{t('knowledge.config.raptorStrategy')}</Typography>
          </AccordionSummary>
          <AccordionDetails>
            <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
              {/* 使用召回增强RAPTOR策略 */}
              <UseRaptorItem />
              {/* 提示词 */}
              <RaptorPromptItem />
              {/* 最大token数 */}
              <RaptorMaxTokenItem />
              {/* 阈值 */}
              <RaptorThresholdItem />
              {/* 最大聚类数 */}
              <RaptorMaxClusterItem />
              {/* 随机种子 */}
              <RaptorRandomSeedItem />
            </Box>
          </AccordionDetails>
        </Accordion>

        {/* 第三部分：Knowledge Graph 知识图谱 */}
        <Accordion>
          <AccordionSummary expandIcon={<ExpandMoreIcon />}>
            <Typography variant="h6">{t('knowledge.config.knowledgeGraph')}</Typography>
          </AccordionSummary>
          <AccordionDetails>
            <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
              {/* 提取知识图谱 */}
              <UseGraphragItem />
              {/* 实体类型 */}
              <EntityTypesItem />
              {/* 方法 */}
              <GraphragMethodItem />
              {/* 实体归一化 */}
              <EntityNormalizeItem />
              {/* 社区报告生成 */}
              <CommunityReportItem />
            </Box>
          </AccordionDetails>
        </Accordion>
      </MainContainer>
    </ConfigurationFormContainer>
  );
}