import { Link, useLocation } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { motion } from 'framer-motion'; import { useQuery } from '@tanstack/react-query'; import { useAuthStore } from '@/store/auth'; import { brandingApi, getCachedBranding, setCachedBranding, preloadLogo, isLogoPreloaded, } from '@/api/branding'; import { cn } from '@/lib/utils'; import { usePlatform } from '@/platform'; // Icons import { HomeIcon, SubscriptionIcon, WalletIcon, UsersIcon, ChatIcon, UserIcon, LogoutIcon, GamepadIcon, ClipboardIcon, InfoIcon, CogIcon, WheelIcon, } from './icons'; const FALLBACK_NAME = import.meta.env.VITE_APP_NAME || 'Cabinet'; const FALLBACK_LOGO = import.meta.env.VITE_APP_LOGO || 'V'; interface DesktopSidebarProps { isAdmin?: boolean; wheelEnabled?: boolean; referralEnabled?: boolean; hasContests?: boolean; hasPolls?: boolean; } export function DesktopSidebar({ isAdmin, wheelEnabled, referralEnabled, hasContests, hasPolls, }: DesktopSidebarProps) { const { t } = useTranslation(); const location = useLocation(); const { user, logout } = useAuthStore(); const { haptic } = usePlatform(); // Branding const { data: branding } = useQuery({ queryKey: ['branding'], queryFn: async () => { const data = await brandingApi.getBranding(); setCachedBranding(data); preloadLogo(data); return data; }, initialData: getCachedBranding() ?? undefined, staleTime: 60000, refetchOnWindowFocus: true, retry: 1, }); const appName = branding ? branding.name : FALLBACK_NAME; const logoLetter = branding?.logo_letter || FALLBACK_LOGO; const hasCustomLogo = branding?.has_custom_logo || false; const logoUrl = branding ? brandingApi.getLogoUrl(branding) : null; const isActive = (path: string) => location.pathname === path; const isAdminActive = () => location.pathname.startsWith('/admin'); const navItems = [ { path: '/', label: t('nav.dashboard'), icon: HomeIcon }, { path: '/subscription', label: t('nav.subscription'), icon: SubscriptionIcon }, { path: '/balance', label: t('nav.balance'), icon: WalletIcon }, ...(referralEnabled ? [{ path: '/referral', label: t('nav.referral'), icon: UsersIcon }] : []), { path: '/support', label: t('nav.support'), icon: ChatIcon }, ...(hasContests ? [{ path: '/contests', label: t('nav.contests'), icon: GamepadIcon }] : []), ...(hasPolls ? [{ path: '/polls', label: t('nav.polls'), icon: ClipboardIcon }] : []), ...(wheelEnabled ? [{ path: '/wheel', label: t('nav.wheel'), icon: WheelIcon }] : []), { path: '/info', label: t('nav.info'), icon: InfoIcon }, ]; const handleNavClick = () => { haptic.impact('light'); }; return ( ); }