import React from 'react'; import { Module } from "@/interfaces"; import useExamEditorStore from "@/stores/examEditor"; import Dropdown from "./SettingsDropdown"; import { LevelSectionSettings } from "@/stores/examEditor/types"; interface Props { module: Module; sectionId: number; localSettings: LevelSectionSettings; updateLocalAndScheduleGlobal: (updates: Partial, schedule?: boolean) => void; } const SectionPicker: React.FC = ({ module, sectionId, localSettings, updateLocalAndScheduleGlobal }) => { const { dispatch } = useExamEditorStore(); const [selectedValue, setSelectedValue] = React.useState(null); const sectionState = useExamEditorStore(state => state.modules["level"].sections.find((s) => s.sectionId === sectionId) ); if (sectionState === undefined) return null; const { readingSection, listeningSection } = sectionState; const currentValue = selectedValue ?? (module === "reading" ? readingSection : listeningSection); const options = module === "reading" ? [1, 2, 3] : [1, 2, 3, 4]; const openPicker = module === "reading" ? "isReadingPickerOpen" : "isListeningPickerOpen"; const handleSectionChange = (value: number) => { setSelectedValue(value); dispatch({ type: "UPDATE_SECTION_SINGLE_FIELD", payload: { sectionId, module: "level", field: module === "reading" ? "readingSection" : "listeningSection", value: value } }); }; const getTitle = () => { const section = module === "reading" ? "Passage" : "Section"; if (!currentValue) return `Choose a ${section}`; return `${section} ${currentValue}`; }; return ( updateLocalAndScheduleGlobal({ [openPicker]: isOpen }, false) } contentWrapperClassName={`pt-6 px-4 bg-gray-200 rounded-b-lg shadow-md transition-all duration-300 ease-in-out border border-ielts-${module}`} >
{options.map((num) => ( ))}
); }; export default SectionPicker;