import { jsxs } from "react/jsx-runtime";
import path from "path";
import { Box, Text } from "ink";
function toRelativePath(absolutePath) {
  const cwd = process.cwd();
  const relative = path.relative(cwd, absolutePath);
  if (relative === "") return ".";
  if (!relative.startsWith("..") && !path.isAbsolute(relative)) {
    return relative;
  }
  return absolutePath;
}
function SearchRenderer({ data, maxMatches = 5 }) {
  const { pattern, matches, totalMatches, truncated: dataTruncated } = data;
  const displayMatches = matches.slice(0, maxMatches);
  const truncated = dataTruncated || matches.length > maxMatches;
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
    /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
      "  \u23BF ",
      totalMatches,
      " match",
      totalMatches !== 1 ? "es" : "",
      ' for "',
      pattern,
      '"',
      truncated && " (truncated)"
    ] }),
    displayMatches.map((match, i) => /* @__PURE__ */ jsxs(Text, { color: "gray", wrap: "truncate", children: [
      "  \u23BF ",
      toRelativePath(match.file),
      match.line > 0 && `:${match.line}`
    ] }, i)),
    matches.length > maxMatches && /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
      "  \u23BF ",
      "... ",
      matches.length - maxMatches,
      " more"
    ] })
  ] });
}
export {
  SearchRenderer
};
