#!/usr/bin/env node
import {
  useMeasuredHeight
} from "./chunk-K77I4XGL.js";
import {
  ViewTitle
} from "./chunk-KWWLPPHF.js";
import {
  useWizardStore
} from "./chunk-FYNMNY4P.js";
import {
  CLI_COLORS,
  SCROLL_VIEWPORT,
  UI_SYMBOLS
} from "./chunk-FVN5PFFY.js";
import {
  init_esm_shims
} from "./chunk-DHET7RCE.js";

// src/cli/components/wizard/step-agents.tsx
init_esm_shims();
import { Box, Text, useInput } from "ink";
import { useRef, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var AGENT_GROUPS = [
  {
    label: "Web",
    items: [
      {
        id: "web-developer",
        label: "Web Developer",
        description: "Frontend features, components, TypeScript"
      },
      { id: "web-reviewer", label: "Web Reviewer", description: "UI component code review" },
      { id: "web-researcher", label: "Web Researcher", description: "Frontend pattern discovery" },
      {
        id: "web-tester",
        label: "Web Tester",
        description: "Frontend tests, E2E, component tests"
      },
      { id: "web-pm", label: "Web PM", description: "Implementation specs and planning" },
      {
        id: "web-architecture",
        label: "Web Architecture",
        description: "App scaffolding, foundational patterns"
      },
      {
        id: "web-pattern-critique",
        label: "Web Pattern Critique",
        description: "Critique patterns against industry standards"
      }
    ]
  },
  {
    label: "API",
    items: [
      {
        id: "api-developer",
        label: "API Developer",
        description: "Backend routes, database, middleware"
      },
      { id: "api-reviewer", label: "API Reviewer", description: "Backend and config code review" },
      { id: "api-researcher", label: "API Researcher", description: "Backend pattern discovery" }
    ]
  },
  {
    label: "CLI",
    items: [
      {
        id: "cli-developer",
        label: "CLI Developer",
        description: "CLI commands, interactive prompts"
      },
      { id: "cli-tester", label: "CLI Tester", description: "CLI application tests" },
      { id: "cli-reviewer", label: "CLI Reviewer", description: "CLI code review" },
      { id: "cli-migrator", label: "CLI Migrator", description: "Commander.js to oclif migration" }
    ]
  },
  {
    label: "Meta",
    items: [
      {
        id: "pattern-scout",
        label: "Pattern Scout",
        description: "Extract codebase patterns and standards"
      },
      { id: "agent-summoner", label: "Agent Summoner", description: "Create and improve agents" },
      {
        id: "skill-summoner",
        label: "Skill Summoner",
        description: "Create technology-specific skills"
      },
      { id: "documentor", label: "Documentor", description: "AI-focused documentation" }
    ]
  }
];
var FOCUSABLE_IDS = [
  ...AGENT_GROUPS.flatMap((group) => group.items.map((a) => a.id)),
  "continue"
];
var FLAT_ROWS = AGENT_GROUPS.flatMap((group, groupIndex) => [
  ...groupIndex > 0 ? [{ type: "spacer" }] : [],
  { type: "header", label: group.label },
  ...group.items.map((agent) => ({ type: "agent", agent }))
]);
var StepAgents = () => {
  const store = useWizardStore();
  const [focusedId, setFocusedId] = useState(FOCUSABLE_IDS[0]);
  const { ref: listRef, measuredHeight: listHeight } = useMeasuredHeight();
  const scrollTopRef = useRef(0);
  const scrollEnabled = listHeight > 0 && listHeight >= SCROLL_VIEWPORT.MIN_VIEWPORT_ROWS;
  if (scrollEnabled && focusedId !== "continue") {
    const rowIndex = FLAT_ROWS.findIndex(
      (row) => row.type === "agent" && row.agent.id === focusedId
    );
    if (rowIndex >= 0) {
      if (rowIndex < scrollTopRef.current) {
        scrollTopRef.current = rowIndex;
      } else if (rowIndex + 1 > scrollTopRef.current + listHeight) {
        scrollTopRef.current = rowIndex + 1 - listHeight;
      }
    }
  }
  useInput((input, key) => {
    if (key.escape) {
      store.goBack();
      return;
    }
    const currentIdx = FOCUSABLE_IDS.indexOf(focusedId);
    if (key.upArrow || input === "k") {
      const nextIdx = currentIdx <= 0 ? FOCUSABLE_IDS.length - 1 : currentIdx - 1;
      setFocusedId(FOCUSABLE_IDS[nextIdx]);
      return;
    }
    if (key.downArrow || input === "j") {
      const nextIdx = currentIdx >= FOCUSABLE_IDS.length - 1 ? 0 : currentIdx + 1;
      setFocusedId(FOCUSABLE_IDS[nextIdx]);
      return;
    }
    if (key.return) {
      store.setStep("confirm");
      return;
    }
    if (input === " " && focusedId !== "continue") {
      store.toggleAgent(focusedId);
    }
  });
  const selectedCount = store.selectedAgents.length;
  const continueLabel = selectedCount > 0 ? `Continue with ${selectedCount} agent(s)` : "Continue without agents";
  const isContinueFocused = focusedId === "continue";
  const rowElements = FLAT_ROWS.map((row, index) => {
    switch (row.type) {
      case "header":
        return /* @__PURE__ */ jsx(Box, { flexShrink: 0, children: /* @__PURE__ */ jsxs(Text, { dimColor: true, bold: true, children: [
          "  ",
          row.label
        ] }) }, `header-${row.label}`);
      case "spacer":
        return /* @__PURE__ */ jsx(Box, { flexShrink: 0, children: /* @__PURE__ */ jsx(Text, { children: " " }) }, `spacer-${index}`);
      case "agent": {
        const isFocused = row.agent.id === focusedId;
        const isSelected = store.selectedAgents.includes(row.agent.id);
        const checkbox = isSelected ? "[\u2713]" : "[ ]";
        const pointer = isFocused ? UI_SYMBOLS.CURRENT : " ";
        return /* @__PURE__ */ jsx(Box, { flexShrink: 0, children: /* @__PURE__ */ jsxs(Text, { children: [
          /* @__PURE__ */ jsx(Text, { color: isFocused ? CLI_COLORS.PRIMARY : void 0, children: pointer }),
          /* @__PURE__ */ jsxs(
            Text,
            {
              color: isSelected || isFocused ? CLI_COLORS.PRIMARY : void 0,
              bold: isFocused,
              children: [
                " ",
                checkbox,
                " ",
                row.agent.label
              ]
            }
          ),
          /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
            " - ",
            row.agent.description
          ] })
        ] }) }, row.agent.id);
      }
    }
  });
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", width: "100%", flexGrow: 1, flexBasis: 0, children: [
    /* @__PURE__ */ jsx(ViewTitle, { children: "Select agents to compile:" }),
    !scrollEnabled ? /* @__PURE__ */ jsx(Box, { ref: listRef, flexDirection: "column", flexGrow: 1, flexBasis: 0, overflow: "hidden", children: rowElements }) : /* @__PURE__ */ jsx(Box, { ref: listRef, flexDirection: "column", flexGrow: 1, flexBasis: 0, children: /* @__PURE__ */ jsx(Box, { flexDirection: "column", overflow: "hidden", flexGrow: 1, children: /* @__PURE__ */ jsx(
      Box,
      {
        flexDirection: "column",
        marginTop: scrollTopRef.current > 0 ? -scrollTopRef.current : 0,
        flexShrink: 0,
        children: rowElements
      }
    ) }) }),
    /* @__PURE__ */ jsxs(Text, { color: isContinueFocused ? CLI_COLORS.PRIMARY : void 0, bold: isContinueFocused, children: [
      isContinueFocused ? UI_SYMBOLS.CURRENT : " ",
      " ",
      "\u2192",
      " ",
      continueLabel
    ] })
  ] });
};

export {
  StepAgents
};
//# sourceMappingURL=chunk-WWSKP5SR.js.map