import { jsx, jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { usePhraseCycler } from "../hooks/usePhraseCycler.js";
import { useElapsedTime } from "../hooks/useElapsedTime.js";
import { useTokenCounter } from "../hooks/useTokenCounter.js";
import { useAnimationTick } from "../hooks/useAnimationTick.js";
import { BRAILLE_SPINNER_FRAMES } from "../constants/spinnerFrames.js";
function StatusSpinner({ enabled, color }) {
  const tick = useAnimationTick({ enabled, intervalMs: 80 });
  const frame = BRAILLE_SPINNER_FRAMES[tick % BRAILLE_SPINNER_FRAMES.length];
  return /* @__PURE__ */ jsx(Text, { color, children: frame });
}
function StatusBar({
  agent,
  isProcessing,
  isThinking,
  isCompacting,
  approvalQueueCount,
  copyModeEnabled = false,
  isAwaitingApproval = false,
  todoExpanded = true,
  hasTodos = false,
  planModeActive = false,
  autoApproveEdits = false,
  backgroundTasksRunning = 0
}) {
  const animationsActive = isProcessing && !isAwaitingApproval && !copyModeEnabled;
  const { phrase } = usePhraseCycler({ isActive: animationsActive && !isCompacting });
  const { formatted: elapsedTime, elapsedMs } = useElapsedTime({
    isActive: animationsActive,
    intervalMs: 1e3
  });
  const { formatted: tokenCount } = useTokenCounter({ agent, isActive: animationsActive });
  const showTime = elapsedMs >= 3e4;
  if (copyModeEnabled) {
    return /* @__PURE__ */ jsx(Box, { paddingX: 1, marginBottom: 0, children: /* @__PURE__ */ jsx(Text, { color: "yellowBright", bold: true, children: "\u{1F4CB} Copy Mode - Select text with mouse. Press any key to exit." }) });
  }
  if (!isProcessing) {
    return null;
  }
  if (isAwaitingApproval) {
    return null;
  }
  const todoHint = hasTodos ? todoExpanded ? "ctrl+t to hide todos" : "ctrl+t to show todos" : null;
  const backgroundHint = backgroundTasksRunning > 0 ? "ctrl+b to view bg tasks" : null;
  if (isCompacting) {
    const metaParts2 = [];
    if (showTime) metaParts2.push(`(${elapsedTime})`);
    if (backgroundTasksRunning > 0) {
      metaParts2.push(
        `${backgroundTasksRunning} bg task${backgroundTasksRunning > 1 ? "s" : ""}`
      );
    }
    if (backgroundHint) metaParts2.push(backgroundHint);
    metaParts2.push("Esc to cancel");
    if (todoHint) metaParts2.push(todoHint);
    const metaContent2 = metaParts2.join(" \u2022 ");
    return /* @__PURE__ */ jsxs(Box, { paddingX: 1, marginTop: 1, flexDirection: "column", children: [
      /* @__PURE__ */ jsxs(Box, { flexDirection: "row", alignItems: "center", children: [
        /* @__PURE__ */ jsx(StatusSpinner, { enabled: true, color: "yellow" }),
        /* @__PURE__ */ jsx(Text, { color: "yellow", children: " \u{1F4E6} Compacting context..." })
      ] }),
      /* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { color: "gray", children: metaContent2 }) })
    ] });
  }
  if (isThinking) {
    const metaParts2 = [];
    if (showTime) metaParts2.push(`(${elapsedTime})`);
    if (tokenCount) metaParts2.push(tokenCount);
    if (backgroundTasksRunning > 0) {
      metaParts2.push(
        `${backgroundTasksRunning} bg task${backgroundTasksRunning > 1 ? "s" : ""}`
      );
    }
    if (backgroundHint) metaParts2.push(backgroundHint);
    metaParts2.push("Esc to cancel");
    if (todoHint) metaParts2.push(todoHint);
    const metaContent2 = metaParts2.join(" \u2022 ");
    return /* @__PURE__ */ jsxs(Box, { paddingX: 1, marginTop: 1, flexDirection: "column", children: [
      /* @__PURE__ */ jsxs(Box, { flexDirection: "row", alignItems: "center", children: [
        /* @__PURE__ */ jsx(StatusSpinner, { enabled: true, color: "green" }),
        /* @__PURE__ */ jsxs(Text, { color: "green", children: [
          " ",
          phrase
        ] })
      ] }),
      /* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { color: "gray", children: metaContent2 }) })
    ] });
  }
  const metaParts = [];
  if (showTime) metaParts.push(`(${elapsedTime})`);
  if (tokenCount) metaParts.push(tokenCount);
  if (backgroundTasksRunning > 0) {
    metaParts.push(`${backgroundTasksRunning} bg task${backgroundTasksRunning > 1 ? "s" : ""}`);
  }
  if (backgroundHint) metaParts.push(backgroundHint);
  metaParts.push("Esc to cancel");
  if (todoHint) metaParts.push(todoHint);
  const metaContent = metaParts.join(" \u2022 ");
  return /* @__PURE__ */ jsxs(Box, { paddingX: 1, marginTop: 1, flexDirection: "column", children: [
    /* @__PURE__ */ jsxs(Box, { flexDirection: "row", alignItems: "center", children: [
      /* @__PURE__ */ jsx(StatusSpinner, { enabled: true, color: "green" }),
      /* @__PURE__ */ jsxs(Text, { color: "green", children: [
        " ",
        phrase
      ] }),
      approvalQueueCount > 0 && /* @__PURE__ */ jsxs(Text, { color: "yellowBright", children: [
        " \u2022 ",
        approvalQueueCount,
        " queued"
      ] })
    ] }),
    /* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { color: "gray", children: metaContent }) })
  ] });
}
export {
  StatusBar
};
