"use client";
import {
IconAt,
IconFile,
IconFolder,
IconListCheck,
IconClipboardList,
} from "@tabler/icons-react";
import type { MentionItem } from "@/hooks/use-inline-mention";
import { getFileName, isDirectory } from "@/lib/utils/file-path";
import { PopupMenu, PopupMenuItem, useMenuItemRefs } from "./popup-menu";
type MentionMenuProps = {
isOpen: boolean;
isLoading: boolean;
position?: { x: number; y: number } | null;
clientRect?: (() => DOMRect | null) | null;
items: MentionItem[];
query: string;
selectedIndex: number;
onSelect: (item: MentionItem) => void;
onClose: () => void;
setSelectedIndex: (index: number) => void;
};
// Get the appropriate icon for an item
function getItemIcon(item: MentionItem) {
if (item.kind === "prompt") {
return ;
}
if (item.kind === "plan") {
return ;
}
if (item.kind === "task") {
return ;
}
const isDir = isDirectory(item.label);
return isDir ? : ;
}
// Get the label and description for an item
function getItemDisplay(item: MentionItem): { label: string; description?: string } {
if (item.kind === "prompt" || item.kind === "plan" || item.kind === "task") {
return { label: item.label, description: item.description };
}
const name = getFileName(item.label);
const parent = item.label.slice(0, item.label.length - name.length);
return { label: name, description: parent || undefined };
}
export function MentionMenu({
isOpen,
isLoading,
position,
clientRect,
items,
query,
selectedIndex,
onSelect,
onClose,
setSelectedIndex,
}: MentionMenuProps) {
const { setItemRef } = useMenuItemRefs(selectedIndex);
const emptyState = (
{(() => {
if (isLoading) return "Loading...";
if (query) return "No results found";
return "Type to search...";
})()}
);
return (
0}
emptyState={emptyState}
>
{items.map((item, index) => {
const { label, description } = getItemDisplay(item);
return (
onSelect(item)}
onMouseEnter={() => setSelectedIndex(index)}
itemRef={setItemRef(index)}
/>
);
})}
);
}