'use client';
import Image from "next/image";
import { Search, LibraryBigIcon, Code, Layers } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { Card } from "@/components/ui/card";
import { CardContent } from "@/components/ui/card";
import { ContextItem, RepoContextItem, SearchContextItem } from "@/features/chat/components/chatBox/contextSelector";
import { DemoExamples, DemoSearchExample, DemoSearchContextExample, DemoSearchContext } from "@/types";
import { cn, getCodeHostIcon } from "@/lib/utils";
import { RepositoryQuery, SearchContextQuery } from "@/lib/types";
interface AskSourcebotDemoCardsProps {
demoExamples: DemoExamples;
selectedItems: ContextItem[];
setSelectedItems: (items: ContextItem[]) => void;
searchContexts: SearchContextQuery[];
repos: RepositoryQuery[];
}
export const AskSourcebotDemoCards = ({
demoExamples,
selectedItems,
setSelectedItems,
searchContexts,
repos,
}: AskSourcebotDemoCardsProps) => {
const handleExampleClick = (example: DemoSearchExample) => {
if (example.url) {
window.open(example.url, '_blank');
}
}
const getContextIcon = (context: DemoSearchContext, size: number = 20) => {
const sizeClass = size === 12 ? "h-3 w-3" : "h-5 w-5";
if (context.type === "set") {
return ;
}
const handleContextClick = (demoSearchContexts: DemoSearchContext[], contextExample: DemoSearchContextExample) => {
const context = demoSearchContexts.find((context) => context.id === contextExample.searchContext)
if (!context) {
console.error(`Search context ${contextExample.searchContext} not found on handleContextClick`);
return;
}
if (context.type === "set") {
const searchContext = searchContexts.find((item) => item.name === context.value);
if (!searchContext) {
console.error(`Search context ${context.value} not found on handleContextClick`);
return;
}
const isSelected = selectedItems.some(
(selected) => selected.type === 'context' && selected.value === context.value
);
const newSelectedItems = isSelected
? selectedItems.filter(
(selected) => !(selected.type === 'context' && selected.value === context.value)
)
: [...selectedItems, { type: 'context', value: context.value, name: context.displayName, repoCount: searchContext.repoNames.length } as SearchContextItem];
setSelectedItems(newSelectedItems);
} else {
const repo = repos.find((repo) => repo.repoName === context.value);
if (!repo) {
console.error(`Repo ${context.value} not found on handleContextClick`);
return;
}
const isSelected = selectedItems.some(
(selected) => selected.type === 'repo' && selected.value === context.value
);
const newSelectedItems = isSelected
? selectedItems.filter(
(selected) => !(selected.type === 'repo' && selected.value === context.value)
)
: [...selectedItems, { type: 'repo', value: context.value, name: context.displayName, codeHostType: repo.codeHostType } as RepoContextItem];
setSelectedItems(newSelectedItems);
}
}
return (
Select the context you want to ask questions about
{contextExample.description}
Check out these featured ask results from the community
{example.description}