"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var BackgroundTasksPanel_exports = {};
__export(BackgroundTasksPanel_exports, {
  BackgroundTasksPanel: () => BackgroundTasksPanel
});
module.exports = __toCommonJS(BackgroundTasksPanel_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_ink = require("ink");
function padText(value, width) {
  if (value.length >= width) return value.slice(0, width - 1) + "\u2026";
  return value.padEnd(width, " ");
}
function formatStatus(status) {
  switch (status) {
    case "running":
      return "running";
    case "completed":
      return "done";
    case "failed":
      return "failed";
    case "cancelled":
      return "cancelled";
    default:
      return status;
  }
}
function BackgroundTasksPanel({
  tasks,
  isExpanded,
  isProcessing = false
}) {
  if (!isExpanded) return null;
  const sortedTasks = [...tasks].sort((a, b) => {
    if (a.status === b.status) return 0;
    if (a.status === "running") return -1;
    if (b.status === "running") return 1;
    return a.status.localeCompare(b.status);
  });
  const runningCount = tasks.filter((task) => task.status === "running").length;
  const totalCount = tasks.length;
  const headerText = `\u{1F9F5} Background Tasks (${runningCount}/${totalCount} running)`;
  if (totalCount === 0) {
    return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
      import_ink.Box,
      {
        flexDirection: "column",
        borderStyle: isProcessing ? void 0 : "round",
        borderColor: "gray",
        paddingX: 1,
        marginX: 1,
        marginBottom: 1,
        children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { bold: true, color: "cyan", children: headerText }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", dimColor: true, children: "No background tasks" })
        ]
      }
    );
  }
  const statusWidth = 10;
  const idWidth = 14;
  const descWidth = 48;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
    import_ink.Box,
    {
      flexDirection: "column",
      borderStyle: isProcessing ? void 0 : "round",
      borderColor: "gray",
      paddingX: 1,
      marginX: 1,
      marginBottom: 1,
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { bold: true, color: "cyan", children: headerText }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", dimColor: true, children: [
            " ",
            "\xB7 ctrl+b to hide bg tasks"
          ] })
        ] }),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", children: [
          padText("status", statusWidth),
          padText("task id", idWidth),
          padText("description", descWidth)
        ] }) }),
        sortedTasks.map((task) => {
          const status = formatStatus(task.status);
          const desc = task.description ?? "";
          return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: task.status === "running" ? "yellow" : "gray", children: [
            padText(status, statusWidth),
            padText(task.taskId, idWidth),
            padText(desc, descWidth)
          ] }) }, task.taskId);
        })
      ]
    }
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BackgroundTasksPanel
});
