import {useState} from 'react'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faChevronDown, faChevronUp} from '@fortawesome/free-solid-svg-icons'; import {ActChapter, ChapterListProps} from '@/lib/models/Chapter'; import {SelectBoxProps} from '@/shared/interface'; import ActChapterItem from './ActChapter'; import InputField from '@/components/form/InputField'; import SelectBox from '@/components/form/SelectBox'; import {useTranslations} from 'next-intl'; 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 (
{isExpanded && (
{chapters && chapters.length > 0 ? ( chapters.map((chapter: ActChapter) => ( onUpdateChapterSummary(chapterId, summary) } onUnlink={(chapterInfoId, chapterId) => onUnlinkChapter(chapterInfoId, chapterId) } /> )) ) : (

{t('noLinkedChapter')}

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