"use client" import { useAuth } from '@/hooks/useAuth' import { useSidebar } from '@/hooks/useSidebar' import { Button } from '@/components/ui/button' import { Card } from '@/components/ui/card' import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar' import { useRouter, usePathname } from 'next/navigation' import { Settings, LogOut, Store, MessageCircle, Wrench, Warehouse, Users, Truck, Handshake, ChevronLeft, ChevronRight } from 'lucide-react' export function Sidebar() { const { user, logout } = useAuth() const router = useRouter() const pathname = usePathname() const { isCollapsed, toggleSidebar } = useSidebar() const getInitials = () => { const orgName = getOrganizationName() return orgName.charAt(0).toUpperCase() } const getOrganizationName = () => { if (user?.organization?.name) { return user.organization.name } if (user?.organization?.fullName) { return user.organization.fullName } return 'Организация' } const getCabinetType = () => { if (!user?.organization?.type) return 'Кабинет' switch (user.organization.type) { case 'FULFILLMENT': return 'Фулфилмент' case 'SELLER': return 'Селлер' case 'LOGIST': return 'Логистика' case 'WHOLESALE': return 'Оптовик' default: return 'Кабинет' } } const handleSettingsClick = () => { router.push('/settings') } const handleMarketClick = () => { router.push('/market') } const handleMessengerClick = () => { router.push('/messenger') } const handleServicesClick = () => { router.push('/services') } const handleWarehouseClick = () => { router.push('/warehouse') } const handleEmployeesClick = () => { router.push('/employees') } const handleSuppliesClick = () => { // Для фулфилмент кабинетов используем новый роут if (user?.organization?.type === 'FULFILLMENT') { router.push('/fulfillment-supplies') } else { router.push('/supplies') } } const handlePartnersClick = () => { router.push('/partners') } const isSettingsActive = pathname === '/settings' const isMarketActive = pathname.startsWith('/market') const isMessengerActive = pathname.startsWith('/messenger') const isServicesActive = pathname.startsWith('/services') const isWarehouseActive = pathname.startsWith('/warehouse') const isEmployeesActive = pathname.startsWith('/employees') const isSuppliesActive = pathname.startsWith('/supplies') || pathname.startsWith('/fulfillment-supplies') const isPartnersActive = pathname.startsWith('/partners') return (
{/* Кнопка сворачивания */}
{/* Информация о пользователе */} {!isCollapsed ? ( // Развернутое состояние
{user?.avatar ? ( ) : null} {getInitials()}

{getOrganizationName()}

{getCabinetType()}

) : ( // Свернутое состояние
{user?.avatar ? ( ) : null} {getInitials()}

{getOrganizationName().length > 12 ? getOrganizationName().substring(0, 12) + '...' : getOrganizationName() }

)}
{/* Навигация */}
{/* Услуги - только для фулфилмент центров */} {user?.organization?.type === 'FULFILLMENT' && ( )} {/* Сотрудники - только для фулфилмент центров */} {user?.organization?.type === 'FULFILLMENT' && ( )} {/* Поставки - для селлеров и фулфилмент */} {(user?.organization?.type === 'SELLER' || user?.organization?.type === 'FULFILLMENT') && ( )} {/* Склад - только для оптовиков */} {user?.organization?.type === 'WHOLESALE' && ( )}
{/* Кнопка выхода */}
) }