export const THEME_STORAGE_KEY = 'ifixkart.themeCustomizer'; export type ThemeLayout = 'default' | 'mini' | 'horizontal-single' | 'without-header' | 'detached' | 'hoverview'; export type ThemeWidth = 'fluid' | 'boxed'; export interface ThemeSettings { mode: 'light' | 'dark'; colorId: string; color: string; sidebarId: string; sidebarCustom: string; topbarId: string; topbarCustom: string; layout: ThemeLayout; width: ThemeWidth; rtl: boolean; sidebarBg: string; } export const DEFAULT_THEME: ThemeSettings = { mode: 'light', colorId: 'primary', color: '#5BA4C7', sidebarId: 'default', sidebarCustom: '#1b2559', topbarId: 'default', topbarCustom: '#ffffff', layout: 'default', width: 'fluid', rtl: false, sidebarBg: '', }; export const LAYOUT_OPTIONS = [ { id: 'default', label: 'Default', image: '/theme/default.svg' }, { id: 'mini', label: 'Mini', image: '/theme/mini.svg' }, { id: 'horizontal-single', label: 'Horizontal Single', image: '/theme/horizontal.svg' }, { id: 'without-header', label: 'Without Header', image: '/theme/without-header.svg' }, { id: 'rtl', label: 'RTL', image: '/theme/rtl.svg' }, { id: 'detached', label: 'Detached', image: '/theme/horizontal-single.svg' }, ] as const; export const SIDEBAR_SIZES = [ { id: 'default', label: 'Default', image: '/theme/default.svg' }, { id: 'mini', label: 'Compact', image: '/theme/compact.svg' }, { id: 'hoverview', label: 'Hover View', image: '/theme/hoverview.svg' }, ] as const; export const SIDEBAR_BACKGROUNDS = [ { id: 'bg1', image: '/theme/bg-01.jpg' }, { id: 'bg2', image: '/theme/bg-02.jpg' }, { id: 'bg3', image: '/theme/bg-03.jpg' }, { id: 'bg4', image: '/theme/bg-04.jpg' }, { id: 'bg5', image: '/theme/bg-05.jpg' }, { id: 'bg6', image: '/theme/bg-06.jpg' }, ] as const; export const THEME_COLORS = [ { id: 'primary', label: 'Primary', value: '#5BA4C7' }, { id: 'brightblue', label: 'Bright blue', value: '#4680ff' }, { id: 'lunargreen', label: 'Lunar green', value: '#365e32' }, { id: 'lavendar', label: 'Lavender', value: '#69235B' }, { id: 'magenta', label: 'Magenta', value: '#e83e8c' }, { id: 'chromeyellow', label: 'Chrome yellow', value: '#ff9b04' }, { id: 'lavared', label: 'Lava red', value: '#dc2626' }, ]; export const SIDEBAR_COLORS = [ { id: 'default', label: 'Default', bg: '', fg: '' }, { id: 'light', label: 'Light', bg: '#ffffff', fg: '#1b2559' }, { id: 'darkgreen', label: 'Dark green', bg: '#123524', fg: '#e7f6ee' }, { id: 'nightblue', label: 'Night blue', bg: '#0b1437', fg: '#e0e5f2' }, { id: 'darkgray', label: 'Dark gray', bg: '#1f2937', fg: '#f3f4f6' }, { id: 'royalblue', label: 'Royal blue', bg: '#1e3a8a', fg: '#e0e7ff' }, { id: 'indigo', label: 'Indigo', bg: '#312e81', fg: '#e0e7ff' }, ]; export const TOPBAR_COLORS = [ { id: 'default', label: 'Default', bg: '', fg: '' }, { id: 'white', label: 'White', bg: '#ffffff', fg: '#1b2559' }, { id: 'darkaqua', label: 'Dark aqua', bg: '#0e7490', fg: '#ffffff' }, { id: 'whiterock', label: 'White rock', bg: '#f4f1ea', fg: '#1b2559' }, { id: 'rockblue', label: 'Rock blue', bg: '#8ea4c8', fg: '#0f172a' }, { id: 'bluehaze', label: 'Blue haze', bg: '#d5deef', fg: '#1b2559' }, { id: 'orange', label: 'Orange', bg: '#f97316', fg: '#ffffff' }, { id: 'purple', label: 'Purple', bg: '#7c3aed', fg: '#ffffff' }, { id: 'blue', label: 'Blue', bg: '#2563eb', fg: '#ffffff' }, { id: 'maroon', label: 'Maroon', bg: '#9f1239', fg: '#ffffff' }, ]; export function loadTheme(): ThemeSettings | null { if (typeof window === 'undefined') return null; try { const raw = localStorage.getItem(THEME_STORAGE_KEY); if (!raw) return null; return { ...DEFAULT_THEME, ...JSON.parse(raw) }; } catch { return null; } } export function saveTheme(settings: ThemeSettings) { localStorage.setItem(THEME_STORAGE_KEY, JSON.stringify(settings)); } export function clearAppliedTheme() { const root = document.documentElement; root.style.removeProperty('--primary'); root.style.removeProperty('--ring'); root.style.removeProperty('--sidebar-active'); root.style.removeProperty('--theme-sidebar-bg'); root.style.removeProperty('--theme-sidebar-fg'); root.style.removeProperty('--theme-topbar-bg'); root.style.removeProperty('--theme-topbar-fg'); root.removeAttribute('data-sidebar'); root.removeAttribute('data-topbar'); root.removeAttribute('data-width'); root.removeAttribute('data-layout'); root.removeAttribute('data-sidebarbg'); root.setAttribute('dir', 'ltr'); } export function applyTheme(settings: ThemeSettings) { const root = document.documentElement; root.style.setProperty('--primary', settings.color); root.style.setProperty('--ring', settings.color); root.style.setProperty('--sidebar-active', settings.color); if (settings.sidebarId === 'default') { root.removeAttribute('data-sidebar'); root.style.removeProperty('--theme-sidebar-bg'); root.style.removeProperty('--theme-sidebar-fg'); } else if (settings.sidebarId === 'custom') { root.setAttribute('data-sidebar', 'custom'); root.style.setProperty('--theme-sidebar-bg', settings.sidebarCustom); root.style.setProperty('--theme-sidebar-fg', '#ffffff'); } else { const sidebar = SIDEBAR_COLORS.find((item) => item.id === settings.sidebarId); if (sidebar?.bg) { root.setAttribute('data-sidebar', sidebar.id); root.style.setProperty('--theme-sidebar-bg', sidebar.bg); root.style.setProperty('--theme-sidebar-fg', sidebar.fg); } } if (settings.topbarId === 'default') { root.removeAttribute('data-topbar'); root.style.removeProperty('--theme-topbar-bg'); root.style.removeProperty('--theme-topbar-fg'); } else if (settings.topbarId === 'custom') { root.setAttribute('data-topbar', 'custom'); root.style.setProperty('--theme-topbar-bg', settings.topbarCustom); root.style.setProperty('--theme-topbar-fg', '#1b2559'); } else { const topbar = TOPBAR_COLORS.find((item) => item.id === settings.topbarId); if (topbar?.bg) { root.setAttribute('data-topbar', topbar.id); root.style.setProperty('--theme-topbar-bg', topbar.bg); root.style.setProperty('--theme-topbar-fg', topbar.fg); } } root.setAttribute('data-layout', settings.layout); root.setAttribute('data-width', settings.width); root.setAttribute('dir', settings.rtl ? 'rtl' : 'ltr'); if (settings.sidebarBg) root.setAttribute('data-sidebarbg', settings.sidebarBg); else root.removeAttribute('data-sidebarbg'); }