'use client'
import { isNavigationTargetActive } from '@/lib/navigation'
import type { ReactNode } from 'react'
import Link from 'next/link'
import { usePathname, useSearchParams } from 'next/navigation'
import type { LucideIcon } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import Tooltip from '@/shared/ui/Tooltip'
import { useSidebarDrawer } from '@/components/layout/AppShell'
export function NavigationRow({
href,
label,
icon: Icon,
detail,
active,
children,
trailing,
}: {
href: string
label: string
icon?: LucideIcon
detail?: string
active?: boolean
children?: ReactNode
trailing?: ReactNode
}) {
const drawer = useSidebarDrawer()
const pathname = usePathname()
const search = useSearchParams()
const selected =
active ?? isNavigationTargetActive(href, pathname, new URLSearchParams(search.toString()))
return (
{
if (!event.metaKey && !event.ctrlKey && !event.shiftKey) drawer?.close()
}}
aria-current={selected ? 'page' : undefined}
className={`dt-navigation-row ${selected ? 'is-active' : ''}`}
>
{children ?? (Icon && )}
{label}
{trailing ??
(detail && (
{detail}
))}
)
}
/**
* A shelf's lead entry — the shelf's own home — set apart from the lists
* beneath it, with room for one action on its right.
*/
export function OverviewRow({
href,
label,
icon: Icon,
action,
}: {
href: string
label: string
icon: LucideIcon
action?: ReactNode
}) {
const drawer = useSidebarDrawer()
const pathname = usePathname()
const selected = pathname === href
return (
{
if (!event.metaKey && !event.ctrlKey && !event.shiftKey) drawer?.close()
}}
>
{label}
{action}
)
}
export function Section({
title,
action,
children,
}: {
title: string
action?: ReactNode
children: ReactNode
}) {
return (
{title}
{action}
{children}
)
}
export function Status({
loading,
error,
retry,
}: {
loading: boolean
error: boolean
retry: () => void
}) {
const { t } = useTranslation()
if (loading)
return (
{[0, 1, 2].map(value => (
))}
)
return error ? (
{t('navigation.loadError')}{' '}
) : null
}
export const matches = (label: string, query: string) =>
label.toLocaleLowerCase().includes(query.trim().toLocaleLowerCase())