import React, { useState, useEffect } from 'react'; import { Palette, RotateCcw, Check, Layout, Type, Sparkles, Grid3X3, Layers, Play, Clock, Image, LayoutGrid } from 'lucide-react'; import { Button, Card, Input } from '../common'; import { ThemeConfig, GALLERY_THEME_PRESETS, GalleryLayoutType } from '../../types/theme.types'; // import { settingsService } from '../../services/settings.service'; // import { toast } from 'react-toastify'; import { useTranslation } from 'react-i18next'; interface ThemeCustomizerEnhancedProps { value: ThemeConfig; onChange: (theme: ThemeConfig) => void; presetName?: string; onPresetChange?: (presetName: string) => void; isPreviewMode?: boolean; showGalleryLayouts?: boolean; hideActions?: boolean; } const layoutIcons: Record = { grid: , masonry: , carousel: , timeline: , hero: , mosaic: }; // Layout descriptions will use translation keys export const ThemeCustomizerEnhanced: React.FC = ({ value, onChange, presetName = 'default', onPresetChange, isPreviewMode = false, showGalleryLayouts = true, hideActions = false }) => { const { t } = useTranslation(); const [localTheme, setLocalTheme] = useState(value); const [selectedPreset, setSelectedPreset] = useState(presetName); const [customCss, setCustomCss] = useState(value.customCss || ''); // const logoInputRef = useRef(null); useEffect(() => { setLocalTheme(value); setCustomCss(value.customCss || ''); }, [value]); useEffect(() => { setSelectedPreset(presetName); }, [presetName]); const handleChange = (key: keyof ThemeConfig, newValue: any) => { const updated = { ...localTheme, [key]: newValue }; setLocalTheme(updated); // When any change is made, mark it as custom if (selectedPreset !== 'custom' && onPresetChange) { setSelectedPreset('custom'); onPresetChange('custom'); } if (isPreviewMode) { onChange(updated); } }; const handlePresetSelect = (presetKey: string) => { const preset = GALLERY_THEME_PRESETS[presetKey]; if (preset) { setSelectedPreset(presetKey); setLocalTheme(preset.config); if (onPresetChange) { onPresetChange(presetKey); } if (isPreviewMode) { onChange(preset.config); } } }; const handleApply = () => { onChange({ ...localTheme, customCss }); }; const handleReset = () => { const defaultPreset = GALLERY_THEME_PRESETS['default']; if (defaultPreset) { setSelectedPreset('default'); setLocalTheme(defaultPreset.config); setCustomCss(''); onChange(defaultPreset.config); if (onPresetChange) { onPresetChange('default'); } } }; // const handleLogoUpload = async (e: React.ChangeEvent) => { // const file = e.target.files?.[0]; // if (file) { // try { // const logoUrl = await settingsService.uploadLogo(file); // handleChange('logoUrl', logoUrl); // toast.success('Logo uploaded successfully'); // } catch (error) { // console.error('Failed to upload logo:', error); // toast.error('Failed to upload logo'); // } // } // }; const updateGallerySettings = (key: string, value: any) => { const updatedSettings = { ...localTheme.gallerySettings, [key]: value }; handleChange('gallerySettings', updatedSettings); }; return (
{/* Preset Themes */}

{t('branding.themePresets')}

{Object.entries(GALLERY_THEME_PRESETS).map(([key, theme]) => ( ))}
{/* Gallery Layout */} {showGalleryLayouts && (

{t('branding.galleryLayout')}

{(Object.keys(layoutIcons) as GalleryLayoutType[]).map((layout) => ( ))}
{/* Layout-specific settings */} {localTheme.galleryLayout && (

{t('branding.layoutSettings')}

{/* Common settings */}
{/* Grid specific */} {localTheme.galleryLayout === 'grid' && (
updateGallerySettings('gridColumns', { ...localTheme.gallerySettings?.gridColumns, mobile: parseInt(e.target.value) })} />
updateGallerySettings('gridColumns', { ...localTheme.gallerySettings?.gridColumns, tablet: parseInt(e.target.value) })} />
updateGallerySettings('gridColumns', { ...localTheme.gallerySettings?.gridColumns, desktop: parseInt(e.target.value) })} />
)} {/* Carousel specific */} {localTheme.galleryLayout === 'carousel' && ( <>
{localTheme.gallerySettings?.carouselAutoplay && (
updateGallerySettings('carouselInterval', parseInt(e.target.value) * 1000)} />
)} )} {/* Timeline specific */} {localTheme.galleryLayout === 'timeline' && (
)}
)}
)} {/* Color Customization */}

{t('branding.colors')}

handleChange('primaryColor', e.target.value)} className="h-10 w-20 rounded border border-neutral-300 cursor-pointer" /> handleChange('primaryColor', e.target.value)} placeholder="#5C8762" className="flex-1" />
handleChange('accentColor', e.target.value)} className="h-10 w-20 rounded border border-neutral-300 cursor-pointer" /> handleChange('accentColor', e.target.value)} placeholder="#22c55e" className="flex-1" />
handleChange('backgroundColor', e.target.value)} className="h-10 w-20 rounded border border-neutral-300 cursor-pointer" /> handleChange('backgroundColor', e.target.value)} placeholder="#fafafa" className="flex-1" />
handleChange('textColor', e.target.value)} className="h-10 w-20 rounded border border-neutral-300 cursor-pointer" /> handleChange('textColor', e.target.value)} placeholder="#171717" className="flex-1" />
{/* Typography & Style */}

{t('branding.typographyAndStyle')}

{/* Custom CSS */}

{t('branding.customCSS')}