import React, { useCallback, useEffect, useMemo, useState, } from 'react'; import PanelHeader from '../ui/PanelHeader'; import { DEFAULT_SETTINGS_SECTIONS } from './sections'; const SettingsModal = ({ open = false, onClose, sections, defaultSectionId, ...sectionProps }) => { const sectionList = useMemo(() => { if (Array.isArray(sections) && sections.length) { return sections; } return DEFAULT_SETTINGS_SECTIONS; }, [sections]); const firstSectionId = sectionList[0]?.id ?? null; const resolvedDefaultSection = defaultSectionId || firstSectionId; const [activeSection, setActiveSection] = useState(resolvedDefaultSection); useEffect(() => { if (!open) { setActiveSection(resolvedDefaultSection); return; } const hasActiveSection = sectionList.some((section) => section.id === activeSection); if (!hasActiveSection) { setActiveSection(resolvedDefaultSection); } }, [open, sectionList, resolvedDefaultSection, activeSection]); const handleBackdropClick = useCallback(() => { onClose?.(); }, [onClose]); const handleInnerClick = useCallback((event) => { event.stopPropagation(); }, []); if (!open) { return null; } const activeSectionConfig = sectionList.find((section) => section.id === activeSection); let sectionContent = null; if (activeSectionConfig) { if (activeSectionConfig.component) { const SectionComponent = activeSectionConfig.component; sectionContent = ; } else if (typeof activeSectionConfig.render === 'function') { sectionContent = activeSectionConfig.render(sectionProps); } } return (
Close )} />
{sectionContent || (

Select a settings section.

)}
); }; export default SettingsModal;