import { X } from "lucide-react";
import type { ReactNode } from "react";
import type { SearchTab } from "./types";
export type { SearchTab } from "./types";
type Props = {
activeTabId: string | null;
tabs: SearchTab[];
onSelect: (tab: SearchTab) => void;
onClose: (tabId: string) => void;
renderLeading?: (tab: SearchTab, active: boolean) => ReactNode;
};
export function SearchTabStrip({
activeTabId,
tabs,
onSelect,
onClose,
renderLeading,
}: Props) {
if (tabs.length === 0) return null;
return (
{tabs.map((tab) => {
const active = tab.id === activeTabId;
return (
onSelect(tab)}
onKeyDown={(event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
onSelect(tab);
}
}}
className={`group flex shrink-0 cursor-pointer items-center gap-1.5 rounded-md px-2.5 py-1.5 text-sm transition ${
active
? "bg-base-300 text-base-content shadow-sm"
: "text-base-content/80 hover:bg-base-200"
}`}
>
{renderLeading ? renderLeading(tab, active) : null}
{tab.label}
);
})}
);
}