import { jsx, jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { makeRelativePath } from "../../utils/messageFormatting.js";
import { formatLineNum, getLineNumWidth } from "./diff-shared.js";
function FileRenderer({ data, maxLines = 20 }) {
  const { operation, lineCount, path, content } = data;
  const relativePath = makeRelativePath(path);
  if (operation === "read") {
    const lineText = lineCount !== void 0 ? `${lineCount} lines` : "file";
    return /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
      "  \u23BF ",
      "Read ",
      lineText,
      " from ",
      relativePath
    ] });
  }
  if (operation === "write" || operation === "create") {
    const verb = operation === "create" ? "Created" : "Wrote";
    if (operation === "create" && content) {
      const lines = content.split("\n");
      const displayLines = lines.slice(0, maxLines);
      const truncatedCount = lines.length - displayLines.length;
      const lineNumWidth = getLineNumWidth(lines.length);
      return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
        /* @__PURE__ */ jsxs(Box, { children: [
          /* @__PURE__ */ jsx(Text, { color: "gray", children: "  \u23BF " }),
          /* @__PURE__ */ jsx(Text, { children: relativePath }),
          /* @__PURE__ */ jsx(Text, { color: "green", children: " (created)" })
        ] }),
        /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [
          displayLines.map((line, index) => /* @__PURE__ */ jsxs(Box, { children: [
            /* @__PURE__ */ jsx(Text, { color: "gray", children: formatLineNum(index + 1, lineNumWidth) }),
            /* @__PURE__ */ jsxs(Text, { wrap: "wrap", children: [
              "   ",
              line
            ] })
          ] }, index)),
          truncatedCount > 0 && /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
            "... +",
            truncatedCount,
            " lines"
          ] })
        ] })
      ] });
    }
    const lineText = lineCount !== void 0 ? `${lineCount} lines` : "content";
    return /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
      "  \u23BF ",
      verb,
      " ",
      lineText,
      " to ",
      relativePath
    ] });
  }
  if (operation === "delete") {
    return /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
      "  \u23BF ",
      "Deleted ",
      relativePath
    ] });
  }
  return /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
    "  \u23BF ",
    operation
  ] });
}
export {
  FileRenderer
};
