'use client'; import { useEffect } from 'react'; import { useThemeStore } from '@/stores/theme-store'; import { SettingsSection } from './settings-section'; import { cn } from '@/lib/utils'; import { Check, Palette, Lock } from 'lucide-react'; import { toast } from '@/stores/toast-store'; import { usePolicyStore } from '@/stores/policy-store'; export function ThemesSettings() { const { installedThemes, activeThemeId, activateTheme } = useThemeStore(); const { isThemeDisabled, getThemePolicy, getForcedThemeId, isThemeForceEnabled } = usePolicyStore(); const themePolicy = getThemePolicy(); const forcedThemeId = getForcedThemeId(installedThemes.map((theme) => theme.id)); // Filter out themes disabled by admin policy const visibleThemes = installedThemes.filter( theme => !isThemeDisabled(theme.id, !!theme.builtIn) ); useEffect(() => { if (forcedThemeId && activeThemeId !== forcedThemeId) { activateTheme(forcedThemeId); } }, [activeThemeId, activateTheme, forcedThemeId]); // If the active theme was disabled by admin, fall back to default useEffect(() => { if (activeThemeId) { const activeTheme = installedThemes.find(t => t.id === activeThemeId); if (activeTheme && isThemeDisabled(activeThemeId, !!activeTheme.builtIn)) { activateTheme(forcedThemeId ?? null); } } }, [activeThemeId, activateTheme, forcedThemeId, installedThemes, isThemeDisabled]); const handleActivate = (id: string | null) => { if (forcedThemeId && id !== forcedThemeId) { const forcedTheme = installedThemes.find((theme) => theme.id === forcedThemeId); toast.info(`Theme "${forcedTheme?.name ?? 'Admin theme'}" is forced by admin and cannot be changed`); return; } activateTheme(id); toast.success(id ? 'Theme activated' : 'Default theme restored'); }; return ( {forcedThemeId && (
Theme selection is locked by an administrator.
)} {/* Theme Grid */}
{/* Default theme card */} handleActivate(null)} /> {/* Installed themes */} {visibleThemes.map(theme => { const isForceEnabled = theme.id === forcedThemeId || theme.forceEnabled || isThemeForceEnabled(theme.id); return ( handleActivate(theme.id)} /> ); })}
); } // ─── Theme Card ────────────────────────────────────────────── interface ThemeCardProps { name: string; author: string; preview?: string; isActive: boolean; isBuiltIn: boolean; isDefault?: boolean; isForceEnabled?: boolean; disabled?: boolean; variants?: ('light' | 'dark')[]; onActivate: () => void; } function ThemeCard({ name, author, preview, isActive, isDefault, isForceEnabled, disabled, variants, onActivate }: ThemeCardProps) { return (
); }