"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const designSystem = require("@choiceform/design-system");
const iconsReact = require("@choiceform/icons-react");
const React = require("react");
const index = require("../../../../i18n/index.cjs");
const tv = require("./tv.cjs");
const usePlanUpdates = require("./hooks/use-plan-updates.cjs");
const todoItem = require("./components/todo-item.cjs");
const PromptPlanTodoList = React.memo(
  React.forwardRef(function PromptPlanTodoList2(props, ref) {
    const { className } = props;
    const { currentPlan, currentStepIndex, isExecuting } = usePlanUpdates.usePlanUpdates();
    const [expanded, setExpanded] = React.useState(true);
    const tv$1 = tv.planTodoListTv({ expanded });
    const currentStepDescription = React.useMemo(() => {
      if (!currentPlan || currentPlan.length === 0) return "";
      if (currentStepIndex == null || currentStepIndex < 0 || currentStepIndex >= currentPlan.length)
        return "";
      return currentPlan[currentStepIndex]?.description || "";
    }, [currentPlan, currentStepIndex]);
    const todoTitle = index.t("prompt-input", "todo-title");
    if (!currentPlan || currentPlan.length === 0) {
      return null;
    }
    return /* @__PURE__ */ jsxRuntime.jsxs(
      "div",
      {
        ref,
        className: tv$1.root({ className }),
        children: [
          /* @__PURE__ */ jsxRuntime.jsxs(
            "div",
            {
              className: tv$1.header(),
              onClick: () => {
                if (!expanded) {
                  setExpanded(true);
                }
              },
              children: [
                /* @__PURE__ */ jsxRuntime.jsx(
                  designSystem.IconButton,
                  {
                    variant: "ghost",
                    onClick: () => setExpanded(!expanded),
                    children: expanded ? /* @__PURE__ */ jsxRuntime.jsx(iconsReact.ChevronDownSmall, {}) : /* @__PURE__ */ jsxRuntime.jsx(iconsReact.ChevronRightSmall, {})
                  }
                ),
                /* @__PURE__ */ jsxRuntime.jsxs("h3", { className: tv$1.title(), children: [
                  todoTitle,
                  " (",
                  currentPlan.length,
                  ")"
                ] }),
                isExecuting && currentStepDescription && !expanded && /* @__PURE__ */ jsxRuntime.jsx(
                  designSystem.MdRender,
                  {
                    className: tv$1.current(),
                    components: {
                      p: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-body-medium animate-pulse truncate [&>*]:!font-normal", children })
                    },
                    content: currentStepDescription
                  }
                )
              ]
            }
          ),
          expanded && currentPlan.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.ScrollArea, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.ScrollArea.Viewport, { className: tv$1.viewport(), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.ScrollArea.Content, { className: tv$1.content(), children: currentPlan.map((step, index2) => /* @__PURE__ */ jsxRuntime.jsx(
            todoItem.TodoItem,
            {
              step,
              isActive: isExecuting && index2 === currentStepIndex
            },
            step.id ?? index2
          )) }) }) })
        ]
      }
    );
  })
);
exports.PromptPlanTodoList = PromptPlanTodoList;
//# sourceMappingURL=prompt-plan-todo-list.cjs.map
