import { Box, Button, Tab, Tabs, Typography } from '@mui/material'; import CloseRoundedIcon from '@mui/icons-material/CloseRounded'; import { useLocation, useNavigate } from 'react-router-dom'; import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded'; import { useEffect, useRef, useState } from 'react'; import { Tooltip } from '@mui/material'; import { fetchCoins } from '../api'; import CustomTooltip from './CustomTooltip'; import CoinsDisplay from './CoinsDisplay'; declare global { interface Window { electron: { ipcRenderer: { invoke(channel: string, ...args: unknown[]): Promise; on(channel: string, func: (...args: unknown[]) => void): void; removeAllListeners(channel: string): void; }; }; } } // Определяем пропсы interface TopBarProps { onRegister?: () => void; // Опционально, если нужен обработчик регистрации username?: string; } export default function TopBar({ onRegister, username }: TopBarProps) { // Получаем текущий путь const location = useLocation(); const isLoginPage = location.pathname === '/login'; const isLaunchPage = location.pathname.startsWith('/launch'); const isVersionsExplorerPage = location.pathname.startsWith('/'); const isRegistrationPage = location.pathname === '/registration'; const navigate = useNavigate(); const [coins, setCoins] = useState(0); const [value, setValue] = useState(1); const [activePage, setActivePage] = useState('versions'); const tabsWrapperRef = useRef(null); const handleChange = (event: React.SyntheticEvent, newValue: number) => { setValue(newValue); if (newValue === 0) { navigate('/news'); } else if (newValue === 1) { navigate('/'); } else if (newValue === 2) { navigate('/profile'); } else if (newValue === 3) { navigate('/shop'); } else if (newValue === 4) { navigate('/marketplace'); } }; useEffect(() => { if (location.pathname === '/news') { setValue(0); setActivePage('news'); } else if (location.pathname === '/') { setValue(1); setActivePage('versions'); } else if (location.pathname.startsWith('/profile')) { setValue(2); setActivePage('profile'); } else if (location.pathname.startsWith('/shop')) { setValue(3); setActivePage('shop'); } else if (location.pathname.startsWith('/marketplace')) { setValue(4); setActivePage('marketplace'); } }, [location.pathname]); const handleLaunchPage = () => { navigate('/'); }; const handleTabsWheel = (event: React.WheelEvent) => { // чтобы страница не скроллилась вертикально event.preventDefault(); if (!tabsWrapperRef.current) return; // Находим внутренний скроллер MUI Tabs const scroller = tabsWrapperRef.current.querySelector( '.MuiTabs-scroller', ) as HTMLDivElement | null; if (!scroller) return; // Прокручиваем горизонтально, используя вертикальный скролл мыши scroller.scrollLeft += event.deltaY * 0.3; }; // const getPageTitle = () => { // if (isLoginPage) { // return 'Вход'; // } // if (isLaunchPage) { // return 'Запуск'; // } // if (isVersionsExplorerPage) { // if (activePage === 'versions') { // return 'Версии'; // } // if (activePage === 'profile') { // return 'Профиль'; // } // if (activePage === 'shop') { // return 'Магазин'; // } // if (activePage === 'marketplace') { // return 'Рынок'; // } // } // return 'Неизвестная страница'; // }; // Функция для получения количества монет const fetchCoinsData = async () => { if (!username) return; try { const coinsData = await fetchCoins(username); setCoins(coinsData.coins); } catch (error) { console.error('Ошибка при получении количества монет:', error); } }; useEffect(() => { if (username) { fetchCoinsData(); // Создаем интервалы для периодического обновления данных const coinsInterval = setInterval(fetchCoinsData, 60000); return () => { clearInterval(coinsInterval); }; } }, [username]); const logout = () => { localStorage.removeItem('launcher_config'); navigate('/login'); }; return ( {/* Левая часть */} {(isLaunchPage || isRegistrationPage) && ( )} {!isLaunchPage && !isRegistrationPage && !isLoginPage && ( { setActivePage('news'); }} sx={{ color: 'white', fontFamily: 'Benzin-Bold', fontSize: '0.7em', '&.Mui-selected': { color: 'rgba(255, 77, 77, 1)', }, '&:hover': { color: 'rgb(177, 52, 52)', }, transition: 'all 0.3s ease', }} /> { setActivePage('versions'); }} sx={{ color: 'white', fontFamily: 'Benzin-Bold', fontSize: '0.7em', '&.Mui-selected': { color: 'rgba(255, 77, 77, 1)', }, '&:hover': { color: 'rgb(177, 52, 52)', }, transition: 'all 0.3s ease', }} /> { setActivePage('profile'); }} sx={{ color: 'white', fontFamily: 'Benzin-Bold', fontSize: '0.7em', '&.Mui-selected': { color: 'rgba(255, 77, 77, 1)', }, '&:hover': { color: 'rgb(177, 52, 52)', }, transition: 'all 0.3s ease', }} /> { setActivePage('shop'); }} sx={{ color: 'white', fontFamily: 'Benzin-Bold', fontSize: '0.7em', '&.Mui-selected': { color: 'rgba(255, 77, 77, 1)', }, '&:hover': { color: 'rgb(177, 52, 52)', }, transition: 'all 0.3s ease', }} /> { setActivePage('marketplace'); }} sx={{ color: 'white', fontFamily: 'Benzin-Bold', fontSize: '0.7em', '&.Mui-selected': { color: 'rgba(255, 77, 77, 1)', }, '&:hover': { color: 'rgb(177, 52, 52)', }, transition: 'all 0.3s ease', }} /> )} {/* Центр */} {/* {getPageTitle()} */} {/* Правая часть со всеми кнопками */} {!isLoginPage && !isRegistrationPage && username && ( )} {/* Кнопка регистрации, если на странице логина */} {!isLoginPage && !isRegistrationPage && username && ( )} {isLoginPage && ( )} {/* Кнопки управления окном */} ); }