/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react'
import { useLocation, useNavigate } from '@tanstack/react-router'
import { ArrowRight, ChevronRight, Laptop, Moon, Sun } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { useSearch } from '@/context/search-provider'
import { useTheme } from '@/context/theme-provider'
import { useSidebarData } from '@/hooks/use-sidebar-data'
import {
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
} from '@/components/ui/command'
import { getNavGroupsForPath } from './layout/lib/workspace-registry'
import { ScrollArea } from './ui/scroll-area'
export function CommandMenu() {
const { t } = useTranslation()
const navigate = useNavigate()
const { setTheme } = useTheme()
const { open, setOpen } = useSearch()
const { pathname } = useLocation()
const sidebarData = useSidebarData()
// 根据当前路径从工作区注册表获取对应的侧边栏配置
const navGroups = getNavGroupsForPath(pathname, t) || sidebarData.navGroups
const runCommand = React.useCallback(
(command: () => unknown) => {
setOpen(false)
command()
},
[setOpen]
)
return (
{t('No results found.')}
{navGroups.map((group) => (
{group.items.map((navItem, i) => {
if (navItem.url)
return (
{
runCommand(() => navigate({ to: navItem.url }))
}}
>
{navItem.title}
)
return navItem.items?.map((subItem, i) => (
{
runCommand(() => navigate({ to: subItem.url }))
}}
>
{navItem.title} {subItem.title}
))
})}
))}
runCommand(() => setTheme('light'))}>
{t('Light')}
runCommand(() => setTheme('dark'))}>
{t('Dark')}
runCommand(() => setTheme('system'))}
>
{t('System')}
)
}