import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
import { getFileList } from "~/fns/code";
import { useFuzzyFinder } from "~/hooks/use-fuzzy-finder";
import { EmptyState } from "~/ui/EmptyState";
import { Panel } from "~/ui/Panel";
import { inputClass } from "~/ui/Field";
import { cn } from "~/utils/cn";
import { TextLink } from "~/ui/TextLink";
export const Route = createFileRoute("/$owner/$repo/find/$")({
loader: ({ params }) => getFileList({ data: { owner: params.owner, repo: params.repo, ref: params._splat ?? "" } }),
component: FindFilePage,
});
function runs(path: string, positions: number[]): Array<{ start: number; text: string; marked: boolean }> {
const marks = new Set(positions);
const out: Array<{ start: number; text: string; marked: boolean }> = [];
for (let index = 0; index < path.length; index++) {
const marked = marks.has(index);
const last = out[out.length - 1];
if (last && last.marked === marked) last.text += path[index];
else out.push({ start: index, text: path[index], marked });
}
return out;
}
function Highlighted({ path, positions }: { path: string; positions: number[] }) {
return (
<>
{runs(path, positions).map((run) => (
<span key={run.start} className={run.marked ? "font-semibold text-accent-400" : undefined}>
{run.text}
</span>
))}
</>
);
}
function FindFilePage() {
const data = Route.useLoaderData();