'use client';
import { getRepoCodeHostInfo } from "@/lib/utils";
import { useCallback, useMemo } from "react";
import Image from "next/image";
import { DoubleArrowDownIcon, DoubleArrowUpIcon, FileIcon } from "@radix-ui/react-icons";
import clsx from "clsx";
import { Separator } from "@/components/ui/separator";
import { SearchResultFile } from "@/lib/types";
import { FileMatch } from "./fileMatch";
export const MAX_MATCHES_TO_PREVIEW = 3;
interface FileMatchContainerProps {
file: SearchResultFile;
onOpenFile: () => void;
onMatchIndexChanged: (matchIndex: number) => void;
showAllMatches: boolean;
onShowAllMatchesButtonClicked: () => void;
isBranchFilteringEnabled: boolean;
}
export const FileMatchContainer = ({
file,
onOpenFile,
onMatchIndexChanged,
showAllMatches,
onShowAllMatchesButtonClicked,
isBranchFilteringEnabled,
}: FileMatchContainerProps) => {
const matchCount = useMemo(() => {
return file.ChunkMatches.length;
}, [file]);
const matches = useMemo(() => {
const sortedMatches = file.ChunkMatches.sort((a, b) => {
return a.ContentStart.LineNumber - b.ContentStart.LineNumber;
});
if (!showAllMatches) {
return sortedMatches.slice(0, MAX_MATCHES_TO_PREVIEW);
}
return sortedMatches;
}, [file, showAllMatches]);
const fileNameRange = useMemo(() => {
for (const match of matches) {
if (match.FileName && match.Ranges.length > 0) {
const range = match.Ranges[0];
return {
from: range.Start.Column - 1,
to: range.End.Column - 1,
}
}
}
return null;
}, [matches]);
const { repoIcon, repoName, repoLink } = useMemo(() => {
const info = getRepoCodeHostInfo(file.Repository);
if (info) {
return {
repoName: info.repoName,
repoLink: info.repoLink,
repoIcon:
{showAllMatches ?