import { ArrowLeftOnRectangleIcon, ArrowsRightLeftIcon, BanknotesIcon, BuildingOffice2Icon, ClipboardDocumentCheckIcon, Cog6ToothIcon, CalendarDaysIcon, ChartBarIcon, ChatBubbleLeftEllipsisIcon, CreditCardIcon, DevicePhoneMobileIcon, DocumentTextIcon, HeartIcon, KeyIcon, LockClosedIcon, StarIcon, TagIcon, UserCircleIcon, UserGroupIcon, UsersIcon, UserPlusIcon, WrenchScrewdriverIcon, FolderOpenIcon, IdentificationIcon, } from "@heroicons/react/24/outline"; import { NavLink, useNavigate } from "react-router-dom"; import { useAuthStore } from "../../stores/authStore"; import { useUiStore } from "../../stores/uiStore"; import { useSubscription } from "../../hooks/useSubscription"; type SectionItem = { to: string; icon: React.ElementType; label: string; feature?: string }; type Section = { label: string; items: SectionItem[] }; function buildSections(primaryRole: string | null, dbUuid: string | null): Section[] { if (primaryRole === 'admin') { return [ { label: 'عمومی', items: [ { to: '/admin/dashboard', icon: ChartBarIcon, label: 'داشبورد' }, { to: '/admin/users', icon: UserGroupIcon, label: 'کاربران' }, { to: '/admin/doctors', icon: HeartIcon, label: 'پزشکان' }, { to: '/admin/clinics', icon: BuildingOffice2Icon, label: 'کلینیک‌ها' }, ], }, { label: 'مدیریت', items: [ { to: '/admin/appointments', icon: CalendarDaysIcon, label: 'نوبت‌ها' }, { to: '/admin/payments', icon: CreditCardIcon, label: 'پرداخت‌ها' }, { to: '/admin/settlements', icon: BanknotesIcon, label: 'تسویه‌حساب' }, { to: '/admin/pre-registrations', icon: ClipboardDocumentCheckIcon, label: 'درخواست‌های ثبت‌نام' }, ], }, { label: 'محتوا', items: [ { to: '/admin/comments', icon: ChatBubbleLeftEllipsisIcon, label: 'نظرات' }, { to: '/admin/ratings', icon: StarIcon, label: 'امتیازها' }, { to: '/admin/blogs', icon: DocumentTextIcon, label: 'بلاگ' }, { to: '/admin/sms', icon: DevicePhoneMobileIcon, label: 'پیامک' }, ], }, { label: 'سیستم', items: [ { to: '/admin/categories', icon: TagIcon, label: 'دسته‌بندی‌ها' }, { to: '/admin/representations', icon: UsersIcon, label: 'نمایندگان' }, { to: '/admin/secretaries', icon: KeyIcon, label: 'منشی‌ها' }, { to: '/admin/admin-subscription', icon: CreditCardIcon, label: 'اشتراک‌ها' }, { to: '/admin/settings', icon: Cog6ToothIcon, label: 'تنظیمات' }, ], }, ]; } if (primaryRole === 'clinic') { const clinicTo = dbUuid ? `/admin/clinics/${dbUuid}` : '/admin/my-clinic'; return [ { label: 'عمومی', items: [ { to: '/admin/dashboard', icon: ChartBarIcon, label: 'داشبورد' }, { to: clinicTo, icon: BuildingOffice2Icon, label: 'کلینیک من' }, ], }, { label: 'مدیریت', items: [ { to: '/admin/appointments', icon: CalendarDaysIcon, label: 'نوبت‌ها' }, { to: '/admin/my-patients', icon: FolderOpenIcon, label: 'پرونده بیماران', feature: 'patient_records' }, { to: '/admin/staff', icon: UserPlusIcon, label: 'پرسنل' }, { to: '/admin/my-secretaries', icon: IdentificationIcon, label: 'منشیان' }, { to: '/admin/clinic-services', icon: WrenchScrewdriverIcon, label: 'سرویس‌ها', feature: 'services' }, { to: '/admin/sms-wallet', icon: DevicePhoneMobileIcon, label: 'کیف پول پیامک', feature: 'sms_panel' }, ], }, { label: 'اشتراک', items: [ { to: '/admin/subscription', icon: CreditCardIcon, label: 'پنل اشتراکی' }, ], }, ]; } if (primaryRole === 'doctor') { return [ { label: 'عمومی', items: [ { to: '/admin/dashboard', icon: ChartBarIcon, label: 'داشبورد' }, ], }, { label: 'پروفایل', items: [ { to: '/admin/profile', icon: UserCircleIcon, label: 'پروفایل من' }, ], }, { label: 'مدیریت', items: [ { to: '/admin/appointments', icon: CalendarDaysIcon, label: 'نوبت‌های من' }, { to: '/admin/my-patients', icon: FolderOpenIcon, label: 'پرونده بیماران', feature: 'patient_records' }, { to: '/admin/staff', icon: UserPlusIcon, label: 'پرسنل' }, { to: '/admin/my-secretaries', icon: IdentificationIcon, label: 'منشیان' }, { to: '/admin/clinic-services', icon: WrenchScrewdriverIcon, label: 'سرویس‌ها', feature: 'services' }, { to: '/admin/sms-wallet', icon: DevicePhoneMobileIcon, label: 'کیف پول پیامک', feature: 'sms_panel' }, ], }, { label: 'اشتراک', items: [ { to: '/admin/subscription', icon: CreditCardIcon, label: 'پنل اشتراکی' }, ], }, ]; } if (primaryRole === 'secretary') { return [ { label: 'عمومی', items: [ { to: '/admin/dashboard', icon: ChartBarIcon, label: 'داشبورد' }, ], }, { label: 'مدیریت', items: [ { to: '/admin/appointments', icon: CalendarDaysIcon, label: 'نوبت‌ها' }, { to: '/admin/my-patients', icon: FolderOpenIcon, label: 'پرونده بیماران', feature: 'patient_records' }, ], }, ]; } return [ { label: 'عمومی', items: [{ to: '/admin/dashboard', icon: ChartBarIcon, label: 'داشبورد' }], }, ]; } const ROLE_LABELS: Record = { admin: 'مدیر کل', clinic: 'مالک کلینیک', doctor: 'پزشک', secretary: 'منشی', user: 'کاربر', }; const HUES = [256, 205, 162, 295, 272]; function avatarBg(name: string): string { const hue = HUES[(name.charCodeAt(0) ?? 0) % HUES.length]; return `linear-gradient(145deg, oklch(0.62 0.15 ${hue}), oklch(0.48 0.16 ${hue}))`; } interface Props { mobileOpen?: boolean; onMobileClose?: () => void; } export default function Sidebar({ mobileOpen: _m, onMobileClose: _c }: Props) { const sidebarOpen = useUiStore((s) => s.sidebarOpen); const { logout, primaryRole, userName, availableContexts, dbUuid } = useAuthStore(); const { hasFeature } = useSubscription(); const navigate = useNavigate(); const sections = buildSections(primaryRole, dbUuid); const initials = (userName ?? 'U').charAt(0).toUpperCase(); return ( ); }