import { jsx, jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { StyledBox } from "./StyledBox.js";
function truncateContent(content, maxLength = 100) {
  if (content.length <= maxLength) return content;
  return content.slice(0, maxLength) + "...";
}
function getRoleStyle(role) {
  switch (role) {
    case "user":
      return { color: "blue", icon: ">" };
    case "assistant":
      return { color: "green", icon: "|" };
    case "system":
      return { color: "orange", icon: "#" };
    case "tool":
      return { color: "green", icon: "*" };
    default:
      return { color: "white", icon: "-" };
  }
}
function SessionHistoryBox({ data }) {
  if (data.messages.length === 0) {
    return /* @__PURE__ */ jsx(StyledBox, { title: `Session History: ${data.sessionId.slice(0, 8)}`, children: /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { color: "gray", children: "No messages in this session yet." }) }) });
  }
  return /* @__PURE__ */ jsxs(StyledBox, { title: `Session History: ${data.sessionId.slice(0, 8)}`, children: [
    data.messages.map((msg, index) => {
      const style = getRoleStyle(msg.role);
      return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginTop: index === 0 ? 1 : 0, children: [
        /* @__PURE__ */ jsxs(Box, { children: [
          /* @__PURE__ */ jsxs(Text, { color: style.color, bold: true, children: [
            style.icon,
            " "
          ] }),
          /* @__PURE__ */ jsxs(Text, { color: style.color, children: [
            "[",
            msg.role,
            "]"
          ] }),
          /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
            " ",
            msg.timestamp
          ] })
        ] }),
        /* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { children: truncateContent(msg.content) }) })
      ] }, index);
    }),
    /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
      "Total: ",
      data.total,
      " messages"
    ] }) })
  ] });
}
export {
  SessionHistoryBox
};
