import { useTranslation } from "react-i18next"; import { FeatherBuilding2, FeatherCheckSquare, FeatherChevronDown, FeatherClock, FeatherFile, FeatherFolder, FeatherLoader, FeatherSearch, FeatherShield, FeatherTrendingUp, FeatherUser, FeatherUsers, } from "@subframe/core"; import { SPOTLIGHT_SEARCH_ENTITY_ORDER, type SpotlightSearchDialogVM, type SpotlightSearchEntityType, type SpotlightSearchItemVM, type SpotlightSearchRecentVM, } from "@hivegrid/view-models"; import { UI_ACTION_IDS, UI_ID_PATTERNS, UI_SURFACE_IDS, getCommandPaletteActionId, getCommandPaletteRecentId, getCommandPaletteResultId, } from "~/application/ui/uiRegistry"; import { CommandDialog, CommandGroup, CommandInput, CommandItem, CommandList } from "~/components/ui/command"; import { ArrowLeftRightIcon, ChevronRightIcon, CodeIcon, CreditCard, FileTextIcon, HomeIcon, LogOut, PlusIcon, ShieldCheckIcon, StoreIcon, UserIcon, } from "~/components/ui/icons/vendor"; import { useLocaleFormatters } from "~/locale/format"; import { BadgeShortcut } from "~/ui/components/BadgeShortcut"; import { Button } from "~/ui/components/Button"; import { IconWithBackground } from "~/ui/components/IconWithBackground"; export type SpotlightSearchDialogActions = { readonly onOpenChange: (open: boolean) => void; readonly onQueryChange: (query: string) => void; readonly onToggleEntityType: (entityType: SpotlightSearchEntityType) => void; readonly onSelectRecent: (recent: SpotlightSearchRecentVM) => void; readonly onPrepareResultSelection: () => void; readonly onSelectResult: (item: SpotlightSearchItemVM) => void; readonly onLoadMore: () => void; readonly onRetry: () => void; readonly onSelectAction: (actionId: string) => void; readonly onCommandKeyDownCapture: React.KeyboardEventHandler; readonly onCloseAutoFocus: (event: Event) => void; }; /** Presentational AD-28 interim UI. Data and side effects enter only through vm/actions. */ export function SpotlightSearchDialogView({ vm, actions }: { vm: SpotlightSearchDialogVM; actions: SpotlightSearchDialogActions }) { const { t } = useTranslation(); const formatters = useLocaleFormatters(); return ( {vm.canUseGlobalSearch ? (
{SPOTLIGHT_SEARCH_ENTITY_ORDER.map((entityType) => { const active = vm.selectedEntityTypes.includes(entityType); return ( ); })}
) : null} {vm.canUseGlobalSearch && !vm.isSearchQuery ? ( } dataUiId={UI_SURFACE_IDS.commandPaletteQueryHint}> {t("search.command.minimumCharacters")} ) : null} {vm.canUseGlobalSearch && vm.isSearchQuery && vm.searchState === "loading" ? ( } dataUiId={UI_SURFACE_IDS.commandPaletteSearchStatus} live> {t("search.command.loading")} ) : null} {vm.canUseGlobalSearch && vm.isSearchQuery && vm.searchState === "error" ? ( } dataUiId={UI_SURFACE_IDS.commandPaletteSearchStatus} live> {t("search.command.error")} ) : null} {vm.canUseGlobalSearch && vm.isSearchQuery && vm.searchState === "empty" ? ( } dataUiId={UI_SURFACE_IDS.commandPaletteSearchStatus} live> {t("search.results.empty")} ) : null} {vm.canUseGlobalSearch && !vm.isSearchQuery && vm.searchState !== "loading" && vm.recentSearches.length > 0 ? ( {vm.recentSearches.map((recent) => ( actions.onSelectRecent(recent)} > } className="size-8 shrink-0" />
{recent.queryText}
{t("search.results.title", { count: recent.resultCount })}
))}
) : null} {vm.canUseGlobalSearch && !vm.isSearchQuery && vm.searchState !== "loading" && vm.hasResolvedResponse && vm.recentSearches.length === 0 ? ( } dataUiId={UI_SURFACE_IDS.commandPaletteRecentStatus}> {t("search.recent.empty")} ) : null} {vm.canUseGlobalSearch && vm.isSearchQuery && vm.searchState !== "error" ? vm.searchGroups.map((group) => ( {group.items.map((item) => ( actions.onSelectResult(item)} >
{highlightMatch(item.title, vm.query.trim())}
{item.subtitle ? (
{highlightMatch(item.subtitle, vm.query.trim())}
) : null}
{item.updatedAt ? ( {formatters.relativeDate(item.updatedAt)} ) : null}
))}
)) : null} {vm.canLoadMore ? (
) : null} {vm.canUseGlobalSearch && vm.isSearchQuery && vm.searchState !== "loading" && vm.hiddenEntityTypes.length > 0 ? ( } dataUiId={UI_SURFACE_IDS.commandPalettePermissionHint} subtle> {t("search.results.hidden", { entities: vm.hiddenEntityTypes.map((type) => t(`search.entities.${type}`)).join(", "), })} ) : null} {vm.visibleActions.length > 0 ? ( {vm.visibleActions.map((action) => ( actions.onSelectAction(action.id)}>
{action.name}
{action.subtitle ? (
{action.subtitle}
) : null}
))}
) : null} {!vm.canUseGlobalSearch && vm.visibleActions.length === 0 ? ( } dataUiId={UI_SURFACE_IDS.commandPaletteSearchStatus}> {t("app.commands.empty.title")} ) : null}
↑↓ {t("search.command.navigate")} ↵ {t("search.command.open")} ⌘↵ {t("search.command.openNewTab")}
); } function commandActionUiIdAttrs(actionId: string) { return { "data-ui-id": getCommandPaletteActionId(actionId), "data-ui-id-pattern": UI_ID_PATTERNS.commandPaletteAction, "data-ui-id-param-actionid": actionId, }; } function getActionIcon(actionId: string) { switch (actionId) { case "dashboard": case "registry-dashboard": return ; case "profile": case "members": return ; case "subscription": return ; case "account": return ; case "apiKeys": return ; case "auditTrails": case "events": return ; case "switch account": return ; case "create account": return ; case "switch to admin": return ; case "logout": return ; default: return ; } } function SearchStatus({ children, icon, dataUiId, live = false, subtle = false, }: { children: React.ReactNode; icon: React.ReactNode; dataUiId: string; live?: boolean; subtle?: boolean; }) { return (
{icon} {children}
); } function entityIcon(entityType: SpotlightSearchEntityType) { switch (entityType) { case "contact": return ; case "company": return ; case "lead": return ; case "project": return ; case "file": return ; case "task": return ; case "employee": return ; case "user": return ; } } function highlightMatch(value: string, query: string) { if (!query) return value; const index = value.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()); if (index < 0) return value; const before = value.slice(0, index); const match = value.slice(index, index + query.length); const after = value.slice(index + query.length); return ( <> {before} {match} {after} ); }