#!/usr/bin/env node
import {
  useMeasuredHeight
} from "./chunk-K77I4XGL.js";
import {
  getDomainDisplayName
} from "./chunk-YRVTXSXP.js";
import {
  CategoryGrid
} from "./chunk-ABE55TEU.js";
import {
  ViewTitle
} from "./chunk-KWWLPPHF.js";
import {
  buildCategoriesForDomain,
  validateBuildStep
} from "./chunk-KZNPPUQG.js";
import {
  CLI_COLORS
} from "./chunk-FVN5PFFY.js";
import {
  init_esm_shims
} from "./chunk-DHET7RCE.js";

// src/cli/components/wizard/step-build.tsx
init_esm_shims();
import { Box, Text, useInput } from "ink";
import { useState } from "react";

// src/cli/lib/wizard/index.ts
init_esm_shims();

// src/cli/components/hooks/use-framework-filtering.ts
init_esm_shims();
import { useMemo } from "react";
function useFrameworkFiltering({
  domain,
  allSelections,
  matrix,
  expertMode,
  selections,
  installedSkillIds
}) {
  return useMemo(
    () => buildCategoriesForDomain(
      domain,
      allSelections,
      matrix,
      expertMode,
      selections,
      installedSkillIds
    ),
    [domain, allSelections, matrix, expertMode, selections, installedSkillIds]
  );
}

// src/cli/components/wizard/step-build.tsx
import { jsx, jsxs } from "react/jsx-runtime";
var Footer = ({ validationError }) => {
  return /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginTop: 1, children: validationError && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [
    /* @__PURE__ */ jsx(Text, { color: CLI_COLORS.WARNING, children: validationError }),
    /* @__PURE__ */ jsx(Text, { dimColor: true, children: "Press ESC to go back, or select a skill and press ENTER to continue." })
  ] }) });
};
var StepBuild = ({
  matrix,
  domain: activeDomain,
  selectedDomains,
  selections,
  allSelections,
  showLabels,
  expertMode,
  installedSkillIds,
  onToggle,
  onToggleLabels,
  onContinue,
  onBack
}) => {
  const [validationError, setValidationError] = useState(void 0);
  const { ref: gridRef, measuredHeight: gridHeight } = useMeasuredHeight();
  const categories = useFrameworkFiltering({
    domain: activeDomain,
    allSelections,
    matrix,
    expertMode,
    selections,
    installedSkillIds
  });
  useInput((_input, key) => {
    if (key.return) {
      const validation = validateBuildStep(categories, selections);
      if (validation.valid) {
        setValidationError(void 0);
        onContinue();
      } else {
        setValidationError(validation.message);
      }
    } else if (key.escape) {
      setValidationError(void 0);
      onBack();
    }
  });
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", width: "100%", flexGrow: 1, flexBasis: 0, children: [
    /* @__PURE__ */ jsx(
      Box,
      {
        columnGap: 2,
        flexDirection: "row",
        justifyContent: "space-between",
        marginBottom: 1,
        paddingRight: 1,
        marginTop: -1,
        borderTop: false,
        borderRight: false,
        borderLeft: false,
        borderColor: CLI_COLORS.NEUTRAL,
        borderStyle: "single",
        children: /* @__PURE__ */ jsx(Box, { columnGap: 2, flexDirection: "row", children: selectedDomains.map((domain) => {
          const isActive = domain === activeDomain;
          return /* @__PURE__ */ jsx(Text, { color: isActive ? CLI_COLORS.WARNING : void 0, bold: isActive, children: getDomainDisplayName(domain) }, domain);
        }) })
      }
    ),
    /* @__PURE__ */ jsx(ViewTitle, { children: `Customize your ${getDomainDisplayName(activeDomain)} stack` }),
    /* @__PURE__ */ jsx(Box, { ref: gridRef, flexGrow: 1, flexBasis: 0, children: /* @__PURE__ */ jsx(
      CategoryGrid,
      {
        categories,
        availableHeight: gridHeight,
        expertMode,
        showLabels,
        onToggle,
        onToggleLabels
      },
      activeDomain
    ) }),
    /* @__PURE__ */ jsx(Footer, { validationError })
  ] });
};

export {
  StepBuild
};
//# sourceMappingURL=chunk-KCYNTAAF.js.map