#!/usr/bin/env node
import {
  SelectionCard
} from "./chunk-ZWAL2ZY7.js";
import {
  ViewTitle
} from "./chunk-B4QYXVPZ.js";
import {
  useWizardStore
} from "./chunk-SPSGZWTZ.js";
import {
  DEFAULT_SCRATCH_DOMAINS
} from "./chunk-FTD5Z6QD.js";
import {
  init_esm_shims
} from "./chunk-DHET7RCE.js";

// src/cli/components/wizard/stack-selection.tsx
init_esm_shims();
import { Box, useInput } from "ink";
import { useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var INITIAL_FOCUSED_INDEX = 0;
var SCRATCH_LABEL = "Start from scratch";
var SCRATCH_DESCRIPTION = "Select domains and skills manually";
var EXTRA_ITEMS_COUNT = 1;
var StackSelection = ({ matrix, onCancel }) => {
  const { selectStack, setApproach, setStackAction, populateFromSkillIds, toggleDomain } = useWizardStore();
  const [focusedIndex, setFocusedIndex] = useState(INITIAL_FOCUSED_INDEX);
  const stacks = matrix.suggestedStacks;
  const stackCount = stacks.length;
  const scratchIndex = stackCount;
  const totalItems = stackCount + EXTRA_ITEMS_COUNT;
  useInput((input, key) => {
    if (key.escape) {
      if (onCancel) {
        onCancel();
      }
      return;
    }
    if (key.return) {
      if (focusedIndex === scratchIndex) {
        selectStack(null);
        setApproach("scratch");
        for (const domain of DEFAULT_SCRATCH_DOMAINS) {
          toggleDomain(domain);
        }
        return;
      }
      const focusedStack = stacks[focusedIndex];
      if (focusedStack) {
        selectStack(focusedStack.id);
        setStackAction("customize");
        populateFromSkillIds(focusedStack.allSkillIds, matrix.skills, matrix.categories);
        setApproach("stack");
      }
      return;
    }
    if (key.upArrow || input === "k") {
      setFocusedIndex((prev) => Math.max(0, prev - 1));
      return;
    }
    if (key.downArrow || input === "j") {
      setFocusedIndex((prev) => Math.min(totalItems - 1, prev + 1));
    }
  });
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
    /* @__PURE__ */ jsx(ViewTitle, { children: "Choose a stack" }),
    /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
      stacks.map((stack, index) => /* @__PURE__ */ jsx(
        SelectionCard,
        {
          label: stack.name,
          description: stack.description,
          isFocused: index === focusedIndex,
          marginBottom: 1
        },
        stack.id
      )),
      /* @__PURE__ */ jsx(
        SelectionCard,
        {
          label: SCRATCH_LABEL,
          description: SCRATCH_DESCRIPTION,
          isFocused: focusedIndex === scratchIndex
        }
      )
    ] })
  ] });
};

export {
  StackSelection
};
//# sourceMappingURL=chunk-QR2TM4OY.js.map