"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 TodoPanel_exports = {};
__export(TodoPanel_exports, {
  TodoPanel: () => TodoPanel
});
module.exports = __toCommonJS(TodoPanel_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_ink = require("ink");
function getStatusIndicator(status) {
  switch (status) {
    case "completed":
      return { icon: "\u2713", color: "green" };
    case "in_progress":
      return { icon: "\u25CF", color: "yellow" };
    case "pending":
    default:
      return { icon: "\u25CB", color: "gray" };
  }
}
function TodoPanel({ todos, isExpanded, isProcessing = false }) {
  if (todos.length === 0) {
    return null;
  }
  const sortedTodos = [...todos].sort((a, b) => a.position - b.position);
  const currentTask = sortedTodos.find((t) => t.status === "in_progress");
  const nextPendingTask = sortedTodos.find((t) => t.status === "pending");
  const nextTask = currentTask || nextPendingTask;
  if (!isProcessing) {
    if (!isExpanded) {
      return null;
    }
    const completedCount = todos.filter((t) => t.status === "completed").length;
    const totalCount = todos.length;
    return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
      import_ink.Box,
      {
        flexDirection: "column",
        borderStyle: "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.jsxs)(import_ink.Text, { bold: true, color: "cyan", children: [
              "\u{1F4CB} Todo",
              " "
            ] }),
            /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", children: [
              "(",
              completedCount,
              "/",
              totalCount,
              ")"
            ] }),
            /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", dimColor: true, children: [
              " ",
              "\xB7 ctrl+t to hide todo list"
            ] })
          ] }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { flexDirection: "column", children: sortedTodos.map((todo) => {
            const { icon, color } = getStatusIndicator(todo.status);
            const isCompleted = todo.status === "completed";
            const isInProgress = todo.status === "in_progress";
            return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
              /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color, children: [
                icon,
                " "
              ] }),
              /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_ink.Text,
                {
                  color: isCompleted ? "gray" : isInProgress ? "white" : "gray",
                  strikethrough: isCompleted,
                  dimColor: !isInProgress && !isCompleted,
                  children: isInProgress ? todo.activeForm : todo.content
                }
              )
            ] }, todo.id);
          }) })
        ]
      }
    );
  }
  if (!isExpanded) {
    if (!currentTask) {
      return null;
    }
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { paddingX: 1, marginBottom: 1, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { marginLeft: 2, children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: "\u23BF " }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: currentTask.activeForm })
    ] }) });
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { flexDirection: "column", paddingX: 1, marginBottom: 1, children: sortedTodos.map((todo, index) => {
    const isFirst = index === 0;
    const isCompleted = todo.status === "completed";
    const isInProgress = todo.status === "in_progress";
    const checkbox = isCompleted ? "\u2611" : "\u2610";
    return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { marginLeft: 2, children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: isFirst ? "\u23BF  " : "   " }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: isCompleted ? "green" : isInProgress ? "yellow" : "white", children: [
        checkbox,
        " "
      ] }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: isCompleted ? "gray" : "white", dimColor: isCompleted, children: todo.content })
    ] }, todo.id);
  }) });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  TodoPanel
});
