import React, { useState, useEffect } from 'react'; import { X, Save, RotateCcw } from 'lucide-react'; import { Button } from '../common'; import { ThemeCustomizerEnhanced } from './ThemeCustomizerEnhanced'; import { ThemeConfig, GALLERY_THEME_PRESETS } from '../../types/theme.types'; import { useTranslation } from 'react-i18next'; interface ThemeEditorModalProps { isOpen: boolean; onClose: () => void; onSave: (theme: ThemeConfig, presetName: string) => void; currentTheme: ThemeConfig | string; eventName: string; } export const ThemeEditorModal: React.FC = ({ isOpen, onClose, onSave, currentTheme, eventName }) => { const { t } = useTranslation(); const [theme, setTheme] = useState(GALLERY_THEME_PRESETS.default.config); const [presetName, setPresetName] = useState('default'); useEffect(() => { if (currentTheme) { if (typeof currentTheme === 'string') { try { if (currentTheme.startsWith('{')) { const parsedTheme = JSON.parse(currentTheme); setTheme(parsedTheme); // Try to find matching preset const matchingPreset = Object.entries(GALLERY_THEME_PRESETS).find( ([_, preset]) => JSON.stringify(preset.config) === JSON.stringify(parsedTheme) ); setPresetName(matchingPreset ? matchingPreset[0] : 'custom'); } else { // Legacy theme name const preset = GALLERY_THEME_PRESETS[currentTheme]; if (preset) { setTheme(preset.config); setPresetName(currentTheme); } } } catch (e) { console.error('Failed to parse theme:', e); setTheme(GALLERY_THEME_PRESETS.default.config); setPresetName('default'); } } else { setTheme(currentTheme); setPresetName('custom'); } } }, [currentTheme]); const handleThemeChange = (newTheme: ThemeConfig) => { setTheme(newTheme); }; const handlePresetChange = (newPresetName: string) => { setPresetName(newPresetName); if (newPresetName !== 'custom') { const preset = GALLERY_THEME_PRESETS[newPresetName]; if (preset) { setTheme(preset.config); } } }; const handleSave = () => { onSave(theme, presetName); onClose(); }; const handleReset = () => { const defaultPreset = GALLERY_THEME_PRESETS.default; setTheme(defaultPreset.config); setPresetName('default'); }; if (!isOpen) return null; return (
{/* Header */}

{t('events.galleryTheme')}

{t('events.customizingThemeFor', { event: eventName })}

{/* Content */}
{/* Footer */}
); }; ThemeEditorModal.displayName = 'ThemeEditorModal';