import React, {useState} from 'react'; import {ActChapter, ChapterListProps} from '@/lib/types/chapter'; import SelectBox, {SelectBoxProps} from '@/components/form/SelectBox'; import ActChapterItem from './ActChapter'; import InputField from '@/components/form/InputField'; import Collapse from '@/components/ui/Collapse'; import {useTranslations} from '@/lib/i18n'; interface ActChaptersSectionProps { actId: number; chapters: ActChapter[]; mainChapters: ChapterListProps[]; onLinkChapter: (actId: number, chapterId: string) => Promise; onUpdateChapterSummary: (chapterId: string, summary: string) => void; onUnlinkChapter: (chapterInfoId: string, chapterId: string) => Promise; sectionKey: string; isExpanded: boolean; onToggleSection: (sectionKey: string) => void; } export default function ActChaptersSection({ actId, chapters, mainChapters, onLinkChapter, onUpdateChapterSummary, onUnlinkChapter, sectionKey, isExpanded, onToggleSection, }: ActChaptersSectionProps) { const t = useTranslations('actComponent'); const [selectedChapterId, setSelectedChapterId] = useState(''); function mainChaptersData(): SelectBoxProps[] { return mainChapters.map((chapter: ChapterListProps): SelectBoxProps => ({ value: chapter.chapterId, label: `${chapter.chapterOrder}. ${chapter.title}`, })); } return (
{chapters && chapters.length > 0 ? ( chapters.map(function (chapter: ActChapter): React.JSX.Element { return ( { return onUnlinkChapter(chapterInfoId, chapterId); }} /> ); }) ) : (

{t('noLinkedChapter')}

)} { return onLinkChapter(actId, selectedChapterId); }} input={ ): void { setSelectedChapterId(e.target.value); }} data={mainChaptersData()} placeholder={t('selectChapterPlaceholder')} /> } isAddButtonDisabled={!selectedChapterId} />
); }