#!/usr/bin/env node
import {
  ENTER,
  ESCAPE,
  INPUT_DELAY_MS,
  RENDER_DELAY_MS,
  delay
} from "../../chunk-YZTWZVGX.js";
import {
  render
} from "../../chunk-66UDJBF6.js";
import {
  TEST_SKILLS,
  createMockCategory,
  createMockMatrix,
  createMockSkill
} from "../../chunk-3JRWNWBF.js";
import {
  afterEach,
  describe,
  globalExpect,
  it,
  vi
} from "../../chunk-XY3XDVMI.js";
import {
  StepBuild
} from "../../chunk-KCYNTAAF.js";
import "../../chunk-K77I4XGL.js";
import "../../chunk-YRVTXSXP.js";
import "../../chunk-ABE55TEU.js";
import "../../chunk-GG4BSB6S.js";
import "../../chunk-KWWLPPHF.js";
import "../../chunk-FYNMNY4P.js";
import {
  getSkillDisplayLabel,
  validateBuildStep
} from "../../chunk-KZNPPUQG.js";
import "../../chunk-ZECXM7LP.js";
import "../../chunk-T4EXUIBY.js";
import "../../chunk-473YHDYQ.js";
import "../../chunk-FVN5PFFY.js";
import {
  init_esm_shims
} from "../../chunk-DHET7RCE.js";

// src/cli/components/wizard/step-build.test.tsx
init_esm_shims();
import { indexBy } from "remeda";
import { jsx } from "react/jsx-runtime";
var SKILL_DEFAULTS = { categoryExclusive: true };
var buildTestMatrix = (categories, skills) => createMockMatrix(
  indexBy(skills, (s) => s.id),
  {
    categories: indexBy(categories, (c) => c.id)
  }
);
var frameworkCategory = createMockCategory("web-framework", "Framework", {
  domain: "web",
  required: true,
  order: 0
});
var stylingCategory = createMockCategory("web-styling", "Styling", {
  domain: "web",
  required: true,
  order: 1
});
var stateCategory = createMockCategory("web-client-state", "Client State", {
  domain: "web",
  required: false,
  order: 2
});
var apiFrameworkCategory = createMockCategory("api-api", "API Framework", {
  domain: "api",
  required: true,
  order: 0
});
var databaseCategory = createMockCategory("api-database", "Database", {
  domain: "api",
  required: false,
  order: 1
});
var reactSkill = { ...TEST_SKILLS.react, ...SKILL_DEFAULTS, displayName: "react" };
var vueSkill = { ...TEST_SKILLS.vue, ...SKILL_DEFAULTS, displayName: "vue" };
var tailwindSkill = createMockSkill("web-styling-tailwind", "web-styling", {
  ...SKILL_DEFAULTS,
  displayName: "tailwind"
});
var scssSkill = {
  ...TEST_SKILLS.scssModules,
  ...SKILL_DEFAULTS,
  displayName: "scss-modules"
};
var zustandSkill = { ...TEST_SKILLS.zustand, ...SKILL_DEFAULTS, displayName: "zustand" };
var honoSkill = { ...TEST_SKILLS.hono, ...SKILL_DEFAULTS, displayName: "hono" };
var expressSkill = createMockSkill("api-framework-express", "api-api", {
  ...SKILL_DEFAULTS,
  displayName: "express"
});
var postgresSkill = createMockSkill("api-database-postgres", "api-database", {
  ...SKILL_DEFAULTS
});
var defaultMatrix = buildTestMatrix(
  [frameworkCategory, stylingCategory, stateCategory, apiFrameworkCategory, databaseCategory],
  [
    reactSkill,
    vueSkill,
    tailwindSkill,
    scssSkill,
    zustandSkill,
    honoSkill,
    expressSkill,
    postgresSkill
  ]
);
var defaultProps = {
  matrix: defaultMatrix,
  domain: "web",
  selectedDomains: ["web"],
  selections: {},
  allSelections: [],
  showLabels: false,
  expertMode: 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");
    });
  });
  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 expertMode to CategoryGrid", () => {
      const { lastFrame, unmount } = renderStepBuild({
        expertMode: true
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toBeDefined();
    });
    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();
    });
    it("should not handle expert mode toggle locally (handled globally)", () => {
      const { lastFrame, unmount } = renderStepBuild();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toBeDefined();
    });
  });
  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-drizzle"],
        // API skills (aliases)
        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", {
        ...SKILL_DEFAULTS,
        displayName: "commander"
      });
      const matrixWithCli = buildTestMatrix(
        [
          frameworkCategory,
          stylingCategory,
          stateCategory,
          apiFrameworkCategory,
          databaseCategory,
          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", id: "web-framework-react" })).toBe("react");
  });
  it("should return id when no displayName", () => {
    globalExpect(getSkillDisplayLabel({ id: "web-framework-react" })).toBe("web-framework-react");
  });
  it("should prefer displayName over id", () => {
    globalExpect(
      getSkillDisplayLabel({ displayName: "scss-modules", id: "web-styling-scss-modules" })
    ).toBe("scss-modules");
  });
});
//# sourceMappingURL=step-build.test.js.map