You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.5 KiB
95 lines
3.5 KiB
import React, { useMemo } from 'react'
|
|
import { useLocation } from 'react-router-dom'
|
|
import { SidebarTrigger } from '@/components/ui/sidebar'
|
|
import { buttonVariants } from '@/components/ui/button'
|
|
import ThemeToggle from '@/components/layout/ThemeToggle'
|
|
import ServerHealthTrigger from '@/components/layout/ServerHealthTrigger'
|
|
import LanguageSwitcher from '@/components/layout/LanguageSwitcher'
|
|
import { getNavigationConfig } from '@/config/navigation'
|
|
import { useSupportPortalUrl } from '@/features/support/supportPortal'
|
|
import { useTranslation } from '@/i18n'
|
|
import { Ic } from '@/icons'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
export default function Topbar() {
|
|
const { pathname } = useLocation()
|
|
const { t } = useTranslation()
|
|
const supportPortalUrl = useSupportPortalUrl()
|
|
|
|
const navConfig = useMemo(() => getNavigationConfig(t), [t])
|
|
|
|
// پیدا کردن پویای عنوان صفحه بر اساس مسیر فعلی و زبان فعال
|
|
const currentTitle = useMemo(() => {
|
|
if (pathname === '/') return t('navigation.dashboardTitle')
|
|
|
|
for (const group of navConfig) {
|
|
for (const it of group.items) {
|
|
if (it.to === pathname) {
|
|
return it.title
|
|
}
|
|
if (it.children) {
|
|
for (const sub of it.children) {
|
|
if (sub.to === pathname) {
|
|
return sub.title
|
|
}
|
|
if (sub.children) {
|
|
const grand = sub.children.find((g) => g.to === pathname)
|
|
if (grand) {
|
|
return grand.title
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return t('navigation.brand')
|
|
}, [pathname, navConfig, t])
|
|
|
|
return (
|
|
<header className="flex h-16 shrink-0 items-center justify-between gap-3 border-b border-border-soft bg-background px-4 md:px-8">
|
|
<div className="flex items-center gap-3 min-w-0">
|
|
<SidebarTrigger className="-ms-1 shrink-0" />
|
|
|
|
{/* عنوان و مسیر با ترجمه بلادرنگ */}
|
|
<div className="min-w-0">
|
|
<p className="truncate text-[11px] text-grey-3">
|
|
{t('navigation.brandShort')} / {currentTitle}
|
|
</p>
|
|
<h1 className="truncate text-base font-extrabold text-foreground md:text-lg">
|
|
{currentTitle}
|
|
</h1>
|
|
</div>
|
|
</div>
|
|
|
|
{/* ابزارهای هدر: انتخابگر زبان، گزارش مشکلات، وضعیت اتصال سرور، سوئیچ تم */}
|
|
<div className="flex items-center gap-2 sm:gap-2.5 shrink-0">
|
|
{/* انتخابگر زبان سه گانه (فارسی، عربی، انگلیسی) */}
|
|
<LanguageSwitcher />
|
|
|
|
{/* دکمه گزارش مشکلات (پرتال پشتیبانی CRM) */}
|
|
<a
|
|
href={supportPortalUrl}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
title={t('topbar.reportIssues')}
|
|
aria-label={t('topbar.reportIssues')}
|
|
className={cn(
|
|
buttonVariants({ variant: 'outline', size: 'sm' }),
|
|
'h-9 px-2.5 sm:px-3 rounded-xl border-border/70 bg-card/40 hover:bg-card text-xs font-semibold gap-2 shadow-xs transition-all',
|
|
)}
|
|
>
|
|
<Ic name="headset" className="size-4 text-primary shrink-0" />
|
|
<span className="hidden sm:inline-block text-[12px] text-foreground">
|
|
{t('topbar.reportIssues')}
|
|
</span>
|
|
</a>
|
|
|
|
{/* نشانگر وضعیت اتصال سرور */}
|
|
<ServerHealthTrigger />
|
|
|
|
{/* سوئیچ دارک و لایت */}
|
|
<ThemeToggle />
|
|
</div>
|
|
</header>
|
|
)
|
|
}
|