#!/usr/bin/env node
import {
  ENTER,
  ESCAPE,
  INPUT_DELAY_MS,
  RENDER_DELAY_MS,
  delay
} from "../../chunk-PUT7X3GA.js";
import {
  render
} from "../../chunk-66UDJBF6.js";
import {
  createMockCategory,
  createMockMatrix,
  createMockSkill,
  getTestSkill
} from "../../chunk-7FMEMXJ4.js";
import {
  afterEach,
  describe,
  globalExpect,
  it,
  vi
} from "../../chunk-XY3XDVMI.js";
import {
  StepBuild
} from "../../chunk-TC3NHO34.js";
import "../../chunk-K77I4XGL.js";
import "../../chunk-H7WJK7NJ.js";
import "../../chunk-GG4BSB6S.js";
import {
  orderDomains
} from "../../chunk-BKJHAJQW.js";
import "../../chunk-MGNYPVOJ.js";
import "../../chunk-BNQ5O6LE.js";
import {
  getSkillDisplayLabel,
  validateBuildStep
} from "../../chunk-WF6RM73R.js";
import "../../chunk-TZXYBG3R.js";
import "../../chunk-OCEFD7V6.js";
import "../../chunk-T4EXUIBY.js";
import "../../chunk-LWXRUR6B.js";
import "../../chunk-6OWHQ7HM.js";
import "../../chunk-EC3UJRKZ.js";
import {
  init_esm_shims
} from "../../chunk-DHET7RCE.js";

// src/cli/components/wizard/step-build.test.tsx
init_esm_shims();
import { indexBy } from "remeda";

// src/cli/lib/__tests__/mock-data/mock-categories.ts
init_esm_shims();
var WEB_FRAMEWORK_CATEGORY = createMockCategory("web-framework", "Framework", {
  domain: "web",
  required: true,
  order: 0
});
var WEB_STYLING_CATEGORY = createMockCategory("web-styling", "Styling", {
  domain: "web",
  required: true,
  order: 1
});
var WEB_STATE_CATEGORY = createMockCategory("web-client-state", "Client State", {
  domain: "web",
  required: false,
  order: 2
});
var API_FRAMEWORK_CATEGORY = createMockCategory("api-api", "API Framework", {
  domain: "api",
  required: true,
  order: 0
});
var API_DATABASE_CATEGORY = createMockCategory("api-database", "Database", {
  domain: "api",
  required: false,
  order: 1
});
var FRAMEWORK_CATEGORY = createMockCategory("web-framework", "Framework", {
  description: "Web frameworks",
  exclusive: true,
  required: false,
  order: 1
});

// src/cli/components/wizard/step-build.test.tsx
import { jsx } from "react/jsx-runtime";
var buildTestMatrix = (categories, skills) => createMockMatrix(
  indexBy(skills, (s) => s.id),
  {
    categories: indexBy(categories, (c) => c.id)
  }
);
var reactSkill = getTestSkill("react", { displayName: "react" });
var vueSkill = getTestSkill("vue", { displayName: "vue" });
var tailwindSkill = createMockSkill("web-styling-tailwind", "web-styling", {
  displayName: "tailwind"
});
var scssSkill = getTestSkill("scss-modules", { displayName: "scss-modules" });
var zustandSkill = getTestSkill("zustand", { displayName: "zustand" });
var honoSkill = getTestSkill("hono", { displayName: "hono" });
var expressSkill = createMockSkill("api-framework-express", "api-api", {
  displayName: "express"
});
var postgresSkill = createMockSkill("api-database-postgres", "api-database");
var defaultMatrix = buildTestMatrix(
  [
    WEB_FRAMEWORK_CATEGORY,
    WEB_STYLING_CATEGORY,
    WEB_STATE_CATEGORY,
    API_FRAMEWORK_CATEGORY,
    API_DATABASE_CATEGORY
  ],
  [
    reactSkill,
    vueSkill,
    tailwindSkill,
    scssSkill,
    zustandSkill,
    honoSkill,
    expressSkill,
    postgresSkill
  ]
);
var defaultProps = {
  matrix: defaultMatrix,
  domain: "web",
  selectedDomains: ["web"],
  selections: {},
  allSelections: [],
  showLabels: false,
  onToggle: vi.fn(),
  onToggleLabels: vi.fn(),
  onContinue: vi.fn(),
  onBack: vi.fn()
};
var renderStepBuild = (props = {}) => {
  return render(/* @__PURE__ */ jsx(StepBuild, { ...defaultProps, ...props }));
};
describe("StepBuild component", () => {
  let cleanup;
  afterEach(() => {
    cleanup?.();
    cleanup = void 0;
  });
  describe("rendering", () => {
    it("should render CategoryGrid with correct categories for domain", () => {
      const { lastFrame, unmount } = renderStepBuild({
        selections: { "web-framework": ["web-framework-react"] }
        // Framework selected to show other categories
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Framework");
      globalExpect(output).toContain("Styling");
      globalExpect(output).toContain("Client State");
      globalExpect(output).not.toContain("API Framework");
      globalExpect(output).not.toContain("Database");
    });
    it("should render API categories when domain is api", () => {
      const { lastFrame, unmount } = renderStepBuild({
        domain: "api"
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("API Framework");
      globalExpect(output).toContain("Database");
      globalExpect(output).not.toContain("Styling");
      globalExpect(output).not.toContain("Client State");
    });
    it("should render skills as options", () => {
      const { lastFrame, unmount } = renderStepBuild({
        selections: { "web-framework": ["web-framework-react"] }
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("react");
      globalExpect(output).toContain("vue");
      globalExpect(output).toContain("tailwind");
      globalExpect(output).toContain("scss-modules");
    });
    it("should show required indicator (*) for required categories", () => {
      const { lastFrame, unmount } = renderStepBuild();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("*");
    });
    it("should render categories for the domain", () => {
      const { lastFrame, unmount } = renderStepBuild({
        selections: { "web-framework": ["web-framework-react"] }
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Framework");
      globalExpect(output).toContain("Styling");
    });
  });
  describe("domain header", () => {
    it("should show ViewTitle with current domain when multiple domains selected", () => {
      const { lastFrame, unmount } = renderStepBuild({
        selectedDomains: ["web", "api"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your Web stack");
    });
    it("should show ViewTitle with domain when only one selected", () => {
      const { lastFrame, unmount } = renderStepBuild({
        selectedDomains: ["web"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your Web stack");
    });
    it("should show ViewTitle for current domain on final domain", () => {
      const { lastFrame, unmount } = renderStepBuild({
        selectedDomains: ["web", "api"],
        domain: "api"
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your API stack");
    });
    it("should show correct domain display names", () => {
      const { lastFrame, unmount } = renderStepBuild({
        selectedDomains: ["web", "api", "cli"],
        domain: "api"
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your API stack");
    });
    it("should display domains in canonical order regardless of selection order", () => {
      globalExpect(orderDomains(["cli", "mobile", "api", "web"])).toEqual([
        "web",
        "api",
        "mobile",
        "cli"
      ]);
    });
    it("should preserve canonical order with partial domain selection", () => {
      globalExpect(orderDomains(["cli", "web"])).toEqual(["web", "cli"]);
    });
    it("should place custom domains before built-in domains", () => {
      globalExpect(orderDomains(["web", "gaming", "api", "devops"])).toEqual([
        "devops",
        "gaming",
        "web",
        "api"
      ]);
    });
  });
  describe("category filtering", () => {
    it("should filter categories correctly by domain", () => {
      const { lastFrame: webFrame, unmount: webUnmount } = renderStepBuild({
        domain: "web",
        selections: { "web-framework": ["web-framework-react"] }
      });
      const webOutput = webFrame();
      webUnmount();
      const { lastFrame: apiFrame, unmount: apiUnmount } = renderStepBuild({
        domain: "api"
      });
      cleanup = apiUnmount;
      const apiOutput = apiFrame();
      globalExpect(webOutput).toContain("Framework");
      globalExpect(webOutput).toContain("Styling");
      globalExpect(webOutput).toContain("Client State");
      globalExpect(webOutput).not.toContain("API Framework");
      globalExpect(apiOutput).toContain("API Framework");
      globalExpect(apiOutput).toContain("Database");
      globalExpect(apiOutput).not.toContain("Styling");
    });
    it("should sort categories by order", () => {
      const { lastFrame, unmount } = renderStepBuild({
        selections: { "web-framework": ["web-framework-react"] }
      });
      cleanup = unmount;
      const output = lastFrame();
      const frameworkIndex = output?.indexOf("Framework") ?? -1;
      const stylingIndex = output?.indexOf("Styling") ?? -1;
      const stateIndex = output?.indexOf("Client State") ?? -1;
      globalExpect(frameworkIndex).toBeLessThan(stylingIndex);
      globalExpect(stylingIndex).toBeLessThan(stateIndex);
    });
  });
  describe("option states", () => {
    it("should show selected options correctly", () => {
      const { lastFrame, unmount } = renderStepBuild({
        allSelections: ["web-framework-react"],
        selections: { "web-framework": ["web-framework-react"] }
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("react");
    });
    it("should pass showLabels to CategoryGrid", () => {
      const { lastFrame, unmount } = renderStepBuild({
        showLabels: true
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toBeDefined();
    });
  });
  describe("keyboard navigation", () => {
    it("should call onContinue when Enter is pressed with valid selections", async () => {
      const onContinue = vi.fn();
      const { stdin, unmount } = renderStepBuild({
        onContinue,
        selections: {
          "web-framework": ["web-framework-react"],
          "web-styling": ["web-styling-tailwind"]
        }
      });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onContinue).toHaveBeenCalled();
    });
    it("should call onBack when Escape is pressed", async () => {
      const onBack = vi.fn();
      const { stdin, unmount } = renderStepBuild({ onBack });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onBack).toHaveBeenCalled();
    });
    it("should pass toggle callback to CategoryGrid", async () => {
      const onToggle = vi.fn();
      const { stdin, unmount } = renderStepBuild({
        onToggle
      });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(" ");
      await delay(INPUT_DELAY_MS);
      globalExpect(onToggle).toHaveBeenCalled();
    });
  });
  describe("toggle callbacks", () => {
    it("should pass onToggleLabels to CategoryGrid", async () => {
      const onToggleLabels = vi.fn();
      const { stdin, unmount } = renderStepBuild({ onToggleLabels });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write("d");
      await delay(INPUT_DELAY_MS);
      globalExpect(onToggleLabels).toHaveBeenCalled();
    });
  });
  describe("edge cases", () => {
    it("should handle domain with no categories", () => {
      const { lastFrame, unmount } = renderStepBuild({
        domain: "mobile"
        // No mobile categories in test matrix
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("No categories to display");
    });
    it("should handle unknown domain gracefully", () => {
      const { lastFrame, unmount } = renderStepBuild({
        domain: "shared"
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toBeDefined();
    });
    it("should handle empty allSelections", () => {
      const { lastFrame, unmount } = renderStepBuild({
        allSelections: []
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Framework");
    });
    it("should handle allSelections with skills from other domains", () => {
      const { lastFrame, unmount } = renderStepBuild({
        domain: "web",
        allSelections: ["api-framework-hono", "api-database-postgres"],
        // API skills in test matrix
        selections: { "web-framework": ["web-framework-react"] }
        // Need framework to see other categories
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Framework");
      globalExpect(output).toContain("Styling");
    });
  });
  describe("multi-domain scenarios", () => {
    it("should show ViewTitle for current domain in multi-domain flow", () => {
      const { lastFrame, unmount } = renderStepBuild({
        domain: "web",
        selectedDomains: ["web", "api"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your Web stack");
    });
    it("should show ViewTitle for last domain in multi-domain flow", () => {
      const { lastFrame, unmount } = renderStepBuild({
        domain: "api",
        selectedDomains: ["web", "api"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your API stack");
    });
    it("should show ViewTitle for current domain in three-domain flow", () => {
      const cliFrameworkCategory = createMockCategory("cli-framework", "CLI Framework", {
        domain: "cli",
        required: true,
        order: 0
      });
      const commanderSkill = createMockSkill("cli-cli-framework-commander", "cli-framework", {
        displayName: "commander"
      });
      const matrixWithCli = buildTestMatrix(
        [
          WEB_FRAMEWORK_CATEGORY,
          WEB_STYLING_CATEGORY,
          WEB_STATE_CATEGORY,
          API_FRAMEWORK_CATEGORY,
          API_DATABASE_CATEGORY,
          cliFrameworkCategory
        ],
        [
          reactSkill,
          vueSkill,
          tailwindSkill,
          scssSkill,
          zustandSkill,
          honoSkill,
          expressSkill,
          postgresSkill,
          commanderSkill
        ]
      );
      const { lastFrame, unmount } = renderStepBuild({
        matrix: matrixWithCli,
        domain: "api",
        selectedDomains: ["web", "api", "cli"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your API stack");
    });
  });
  describe("header and selection count", () => {
    it("should show ViewTitle with domain name", () => {
      const { lastFrame, unmount } = renderStepBuild();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your Web stack");
    });
    it("should render ViewTitle with domain display name", () => {
      const { lastFrame, unmount } = renderStepBuild({
        domain: "api"
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize your API stack");
    });
  });
  describe("keyboard help text", () => {
    it("should respond to d key for toggling compatibility labels", async () => {
      const onToggleLabels = vi.fn();
      const { stdin, unmount } = renderStepBuild({ onToggleLabels });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write("d");
      await delay(INPUT_DELAY_MS);
      globalExpect(onToggleLabels).toHaveBeenCalled();
    });
  });
  describe("validateBuildStep", () => {
    it("should return valid when required categories have selections", () => {
      const categories = [
        {
          id: "web-framework",
          displayName: "Framework",
          required: true,
          exclusive: true,
          options: [{ id: "web-framework-react", label: "React", state: "normal", selected: true }]
        }
      ];
      const selections = { "web-framework": ["web-framework-react"] };
      const result = validateBuildStep(categories, selections);
      globalExpect(result.valid).toBe(true);
      globalExpect(result.message).toBeUndefined();
    });
    it("should return invalid when required category has no selection", () => {
      const categories = [
        {
          id: "web-framework",
          displayName: "Framework",
          required: true,
          exclusive: true,
          options: [
            { id: "web-framework-react", label: "React", state: "normal", selected: false }
          ]
        }
      ];
      const selections = {};
      const result = validateBuildStep(categories, selections);
      globalExpect(result.valid).toBe(false);
      globalExpect(result.message).toContain("Framework");
    });
    it("should return valid when optional categories have no selections", () => {
      const categories = [
        {
          id: "web-client-state",
          displayName: "State Management",
          required: false,
          exclusive: true,
          options: [
            {
              id: "web-state-zustand",
              label: "Zustand",
              state: "normal",
              selected: false
            }
          ]
        }
      ];
      const selections = {};
      const result = validateBuildStep(categories, selections);
      globalExpect(result.valid).toBe(true);
    });
    it("should return invalid for first missing required category", () => {
      const categories = [
        {
          id: "web-framework",
          displayName: "Framework",
          required: true,
          exclusive: true,
          options: []
        },
        {
          id: "web-styling",
          displayName: "Styling",
          required: true,
          exclusive: true,
          options: []
        }
      ];
      const selections = {};
      const result = validateBuildStep(categories, selections);
      globalExpect(result.valid).toBe(false);
      globalExpect(result.message).toContain("Framework");
    });
  });
  describe("validation on continue", () => {
    it("should show validation error when trying to continue without required selection", async () => {
      const onContinue = vi.fn();
      const { stdin, lastFrame, unmount } = renderStepBuild({
        onContinue,
        selections: {}
      });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Select at least one skill");
      globalExpect(onContinue).not.toHaveBeenCalled();
    });
    it("should call onContinue when validation passes", async () => {
      const onContinue = vi.fn();
      const { stdin, unmount } = renderStepBuild({
        onContinue,
        selections: {
          "web-framework": ["web-framework-react"],
          "web-styling": ["web-styling-tailwind"]
        }
      });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onContinue).toHaveBeenCalled();
    });
  });
});
describe("getSkillDisplayLabel", () => {
  it("should return displayName when available", () => {
    globalExpect(getSkillDisplayLabel({ displayName: "react" })).toBe("react");
  });
  it("should return displayName", () => {
    globalExpect(getSkillDisplayLabel({ displayName: "scss-modules" })).toBe("scss-modules");
  });
});
//# sourceMappingURL=step-build.test.js.map