'use client' import { useState } from 'react' import Link from 'next/link' import { usePathname, useRouter } from 'next/navigation' import { Search, X } from 'lucide-react' import { useTranslation } from 'react-i18next' import Tooltip from '@/shared/ui/Tooltip' import { useSettingsAccess } from '@/features/settings/navigation/SettingsAccessProvider' import { settingsAnchorHref } from '@/features/settings/navigation/settings-nav' import { SETTINGS_PAGE_GROUPS, settingsPageFamily, settingsPageIcon, settingsPageLabel, visibleSettingsPages, } from '@/features/settings/navigation/settings-pages' export default function SettingsNav({ onNavigate }: { onNavigate?: () => void }) { const { t, i18n } = useTranslation() // Fixed translators keep search bilingual (English + Chinese) regardless of // the active locale; rendering stays on t() with the active locale only. const tEn = i18n.getFixedT('en') const tZh = i18n.getFixedT('zh') const pathname = usePathname() const router = useRouter() const access = useSettingsAccess() const pages = visibleSettingsPages(access) const [query, setQuery] = useState('') const needle = query.trim().toLocaleLowerCase() const currentKey = pathname.split('/')[2] || 'general' const currentFamily = settingsPageFamily(currentKey) const matches = pages.filter(page => { const navLabel = settingsPageLabel(page.key, page.label) return [ page.label, t(page.label), tEn(page.label), tZh(page.label), page.blurb, t(page.blurb), tEn(page.blurb), tZh(page.blurb), navLabel, t(navLabel), tEn(navLabel), tZh(navLabel), page.key, page.key === 'connections' ? 'API Key token base url 密钥 凭据 地址 供应商' : '', ] .join(' ') .toLocaleLowerCase() .includes(needle) }) const groups = needle ? [{ label: 'Search results', pages: matches }] : SETTINGS_PAGE_GROUPS.map(group => ({ ...group, pages: group.keys.flatMap(key => { // If the family representative is restricted, use its first visible member. const page = settingsPageFamily(key) .map(member => pages.find(item => item.key === member)) .find(Boolean) return page ? [page] : [] }), })) return ( ) }