import React, { ReactNode, useCallback, useEffect, useMemo, useState, useRef } from "react"; import { FaEye, FaFileUpload } from "react-icons/fa"; import clsx from "clsx"; import Select from "@/components/Low/Select"; import Input from "@/components/Low/Input"; import AutoExpandingTextArea from "@/components/Low/AutoExpandingTextarea"; import Option from '@/interfaces/option' import Dropdown from "./Shared/SettingsDropdown"; import useSettingsState from "../Hooks/useSettingsState"; import { Module } from "@/interfaces"; import { SectionSettings } from "@/stores/examEditor/types"; import useExamEditorStore from "@/stores/examEditor"; interface SettingsEditorProps { sectionId: number, sectionLabel: string; module: Module, introPresets: Option[]; children?: ReactNode; canPreview: boolean; canSubmit: boolean; submitModule: () => void; preview: () => void; } const SettingsEditor: React.FC = ({ sectionId, sectionLabel, module, introPresets, children, preview, submitModule, canPreview, canSubmit }) => { const examLabel = useExamEditorStore((state) => state.modules[module].examLabel) || ''; const { localSettings, updateLocalAndScheduleGlobal } = useSettingsState( module, sectionId ); const options = useMemo(() => [ { value: 'None', label: 'None' }, ...introPresets, { value: 'Custom', label: 'Custom' } ], [introPresets]); const onCategoryChange = useCallback((text: string) => { updateLocalAndScheduleGlobal({ category: text }); }, [updateLocalAndScheduleGlobal]); const onIntroOptionChange = useCallback((option: { value: string | null, label: string }) => { let updates: Partial = { introOption: option }; switch (option.label) { case 'None': updates.currentIntro = undefined; break; case 'Custom': updates.currentIntro = localSettings.customIntro; break; default: const selectedPreset = introPresets.find(preset => preset.label === option.label); if (selectedPreset) { updates.currentIntro = selectedPreset.value! .replace('{part}', sectionLabel) .replace('{label}', examLabel); } } updateLocalAndScheduleGlobal(updates); }, [updateLocalAndScheduleGlobal, localSettings.customIntro, introPresets, sectionLabel, examLabel]); const onCustomIntroChange = useCallback((text: string) => { updateLocalAndScheduleGlobal({ introOption: { value: 'Custom', label: 'Custom' }, customIntro: text, currentIntro: text }); }, [updateLocalAndScheduleGlobal]); return (
{sectionLabel} Settings
updateLocalAndScheduleGlobal({ isCategoryDropdownOpen: isOpen }, false)} > updateLocalAndScheduleGlobal({ isIntroDropdownOpen: isOpen }, false)} >