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 {
  ChunkTokenNumberItem,
  DelimiterItem,
  LayoutRecognizeItem,
  AutoKeywordsItem,
  AutoQuestionsItem,
  HtmlForExcelItem,
  UseRaptorItem,
  RaptorPromptItem,
  RaptorMaxTokenItem,
  RaptorThresholdItem,
  RaptorMaxClusterItem,
  RaptorRandomSeedItem,
  UseGraphragItem,
  EntityTypesItem,
  GraphragMethodItem,
  EntityNormalizeItem,
  CommunityReportItem,
  RaptorConfigItems,
  KnowledgeGraphConfigItems,
} from './common-items';
import { ParseType } from '@/constants/knowledge';

export function ManualConfiguration({ 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 }}>
                {/* 版面识别 */}
                <LayoutRecognizeItem />
                {/* 自动关键词提取 */}
                <AutoKeywordsItem />
                {/* 自动问题提取 */}
                <AutoQuestionsItem />
              </Box>
            </AccordionDetails>
          </Accordion>
        )}

        {/* 第二部分：RAPTOR策略 */}
        <Accordion>
          <AccordionSummary expandIcon={<ExpandMoreIcon />}>
            <Typography variant="h6">{t('knowledge.config.raptorStrategy')}</Typography>
          </AccordionSummary>
          <AccordionDetails>
            <RaptorConfigItems />
          </AccordionDetails>
        </Accordion>

        {/* 第三部分：Knowledge Graph 知识图谱 */}
        <Accordion>
          <AccordionSummary expandIcon={<ExpandMoreIcon />}>
            <Typography variant="h6">{t('knowledge.config.knowledgeGraph')}</Typography>
          </AccordionSummary>
          <AccordionDetails>
            <KnowledgeGraphConfigItems /> 
          </AccordionDetails>
        </Accordion>
      </MainContainer>
    </ConfigurationFormContainer>
  );
}