import React, { useState, useEffect } from 'react'; import { StorageService } from '../services/storageService'; import { UserProfile } from '../types'; import { useLanguage } from '../contexts/LanguageContext'; import { ArrowLeft, Check, Lock, Palette, Search, RefreshCw, Sparkles, ChevronRight } from 'lucide-react'; import { useNavigate, Link } from 'react-router-dom'; import { Button } from '../components/ui/Button'; import { THEME_REGISTRY, THEME_CATEGORIES } from '../config/themes'; const ThemeSelection: React.FC = () => { const { t } = useLanguage(); const navigate = useNavigate(); const [profile, setProfile] = useState(null); const [activeTheme, setActiveTheme] = useState('default'); const [activeCategory, setActiveCategory] = useState('All'); const [searchQuery, setSearchQuery] = useState(''); useEffect(() => { const loadData = async () => { const p = await StorageService.getProfile(); setProfile(p); if (p?.activeTheme) setActiveTheme(p.activeTheme); }; loadData(); }, []); const handleSelectTheme = async (themeId: string) => { if (!profile) return; const theme = THEME_REGISTRY[themeId]; if (theme?.isPremium && !profile.unlockedItems?.includes(themeId)) return; setActiveTheme(themeId); await StorageService.updateProfile({ activeTheme: themeId }); setProfile(prev => prev ? { ...prev, activeTheme: themeId } : null); window.dispatchEvent(new Event('rudraksha-profile-update')); }; const handleRandomize = () => { const unlockedThemes = Object.values(THEME_REGISTRY).filter(theme => !theme.isPremium || profile?.unlockedItems?.includes(theme.id) ); const randomTheme = unlockedThemes[Math.floor(Math.random() * unlockedThemes.length)]; handleSelectTheme(randomTheme.id); }; const categoriesToRender = activeCategory === 'All' ? THEME_CATEGORIES.filter(c => c !== 'All') : [activeCategory]; // Defined filteredThemes to solve the "Cannot find name 'filteredThemes'" error. const filteredThemes = Object.values(THEME_REGISTRY).filter(theme => (activeCategory === 'All' || theme.category === activeCategory) && theme.name.toLowerCase().includes(searchQuery.toLowerCase()) ); return (

{t("Theme Studio", "Theme Studio")}

Customize your ritual environment.

setSearchQuery(e.target.value)} placeholder="Find aesthetic..." className="w-full pl-10 pr-4 py-2.5 bg-white dark:bg-gray-800 border-2 border-gray-100 dark:border-gray-700 rounded-xl outline-none focus:border-red-500 transition-all" />
{/* Category Navigation */}
{THEME_CATEGORIES.map(cat => ( ))}
{/* Section Divisions */} {categoriesToRender.map(cat => { const catThemes = Object.values(THEME_REGISTRY).filter(theme => theme.category === cat && theme.name.toLowerCase().includes(searchQuery.toLowerCase()) ); if (catThemes.length === 0) return null; return (

{cat} Collection

{catThemes.map((theme) => { const isLocked = theme.isPremium && !profile?.unlockedItems?.includes(theme.id); const isActive = activeTheme === theme.id; const palette = Object.values(theme.colors); return (
!isLocked && handleSelectTheme(theme.id)} className={` relative overflow-hidden rounded-[2.5rem] border-4 transition-all cursor-pointer group h-72 flex flex-col ${isActive ? 'border-red-500 shadow-2xl scale-[1.02] ring-4 ring-red-500/10' : 'border-white dark:border-gray-800 hover:border-gray-200 dark:hover:border-gray-600 shadow-lg'} ${isLocked ? 'grayscale-[0.5] opacity-80' : ''} `} >
{theme.isAnimated && (
)}
{isActive ? (
ACTIVE
) : isLocked ? (
BAZAAR
) : (
{theme.category}
)} {theme.isAnimated && ( NEON FLOW )}

{theme.name}

{palette.map((c, i) => (
))}
{isLocked ? 'Premium' : 'Standard'} {theme.uiMode} mode
{isLocked ? ( ) : ( )}
); })}
); })} {filteredThemes.length === 0 && (

No matching aesthetic found

)}
); }; export default ThemeSelection;