#!/usr/bin/env node
import {
  ARROW_DOWN,
  ARROW_UP,
  ENTER,
  ESCAPE,
  INPUT_DELAY_MS,
  RENDER_DELAY_MS,
  delay
} from "../../chunk-YZTWZVGX.js";
import {
  render
} from "../../chunk-66UDJBF6.js";
import {
  TEST_MATRICES
} from "../../chunk-TBB3THSL.js";
import {
  afterEach,
  beforeEach,
  describe,
  globalExpect,
  it,
  vi
} from "../../chunk-XY3XDVMI.js";
import {
  StepSources
} from "../../chunk-HPJP3HFD.js";
import "../../chunk-K77I4XGL.js";
import "../../chunk-ZWAL2ZY7.js";
import "../../chunk-FXQYEXLS.js";
import "../../chunk-7SOPVGDV.js";
import "../../chunk-VSZ5GDET.js";
import "../../chunk-KUV24B5M.js";
import "../../chunk-GG4BSB6S.js";
import "../../chunk-B4QYXVPZ.js";
import {
  useWizardStore
} from "../../chunk-SPSGZWTZ.js";
import "../../chunk-INKJBMPJ.js";
import "../../chunk-GFDGYQ6M.js";
import "../../chunk-T4EXUIBY.js";
import "../../chunk-C4QI54PN.js";
import {
  DEFAULT_BRANDING,
  UI_SYMBOLS
} from "../../chunk-FTD5Z6QD.js";
import {
  init_esm_shims
} from "../../chunk-DHET7RCE.js";

// src/cli/components/wizard/step-sources.test.tsx
init_esm_shims();
import { jsx } from "react/jsx-runtime";
var mockMatrix = TEST_MATRICES.reactAndZustand;
var defaultProps = {
  matrix: mockMatrix,
  onContinue: vi.fn(),
  onBack: vi.fn()
};
var renderStepSources = (props = {}) => {
  return render(/* @__PURE__ */ jsx(StepSources, { ...defaultProps, ...props }));
};
describe("StepSources component", () => {
  let cleanup;
  beforeEach(() => {
    useWizardStore.getState().reset();
    useWizardStore.setState({
      domainSelections: {
        web: {
          "web-framework": ["web-framework-react"],
          "web-client-state": ["web-state-zustand"]
        }
      }
    });
  });
  afterEach(() => {
    cleanup?.();
    cleanup = void 0;
  });
  describe("choice view rendering", () => {
    it("should render technology count", () => {
      const { lastFrame, unmount } = renderStepSources();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("2");
      globalExpect(output).toContain("technologies");
    });
    it("should render 'Use all recommended' option", () => {
      const { lastFrame, unmount } = renderStepSources();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Use all recommended skills (verified)");
    });
    it("should render 'Customize skill sources' option", () => {
      const { lastFrame, unmount } = renderStepSources();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Customize skill sources");
    });
    it("should render verification description", () => {
      const { lastFrame, unmount } = renderStepSources();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("fastest option");
      globalExpect(output).toContain("verified");
      globalExpect(output).toContain(DEFAULT_BRANDING.NAME);
    });
    it("should render customize description", () => {
      const { lastFrame, unmount } = renderStepSources();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Choose alternative skills for each technology");
    });
    it("should show recommended as default selected", () => {
      const { lastFrame, unmount } = renderStepSources();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain(UI_SYMBOLS.CHEVRON);
      globalExpect(output).toContain("Use all recommended");
    });
  });
  describe("choice view keyboard navigation", () => {
    it("should toggle options with arrow up", async () => {
      const { lastFrame, stdin, unmount } = renderStepSources();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      let output = lastFrame();
      globalExpect(output).toContain("Use all recommended");
      stdin.write(ARROW_UP);
      await delay(INPUT_DELAY_MS);
      output = lastFrame();
      globalExpect(output).toContain("Customize skill sources");
    });
    it("should toggle options with arrow down", async () => {
      const { stdin, unmount } = renderStepSources();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
    });
    it("should call onContinue when Enter pressed on 'Use all recommended'", async () => {
      const onContinue = vi.fn();
      const { stdin, unmount } = renderStepSources({ onContinue });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onContinue).toHaveBeenCalledTimes(1);
    });
    it("should call onBack when Escape pressed", async () => {
      const onBack = vi.fn();
      const { stdin, unmount } = renderStepSources({ onBack });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onBack).toHaveBeenCalledTimes(1);
    });
    it("should switch to customize view when Enter pressed on 'Customize'", async () => {
      const { lastFrame, stdin, unmount } = renderStepSources();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Customize skill sources");
      globalExpect(output).toContain("react");
      globalExpect(output).toContain("zustand");
    });
  });
  describe("customize view", () => {
    it("should show source grid with selected technologies", async () => {
      const { lastFrame, stdin, unmount } = renderStepSources();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("react");
      globalExpect(output).toContain("zustand");
      globalExpect(output).toContain("Agents Inc");
    });
    it("should call onContinue when Enter pressed in customize view", async () => {
      const onContinue = vi.fn();
      const { stdin, unmount } = renderStepSources({ onContinue });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onContinue).toHaveBeenCalledTimes(1);
    });
    it("should go back to choice view when Escape pressed in customize view", async () => {
      const onBack = vi.fn();
      const { lastFrame, stdin, unmount } = renderStepSources({ onBack });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(lastFrame()).toContain("Customize skill sources");
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Use all recommended skills (verified)");
      globalExpect(output).toContain("Customize skill sources");
      globalExpect(onBack).not.toHaveBeenCalled();
    });
    it("should show ViewTitle in customize view", async () => {
      const { lastFrame, stdin, unmount } = renderStepSources();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Customize skill sources");
    });
  });
  describe("edge cases", () => {
    it("should handle zero technologies", () => {
      useWizardStore.setState({
        domainSelections: {}
      });
      const { lastFrame, unmount } = renderStepSources();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("0");
      globalExpect(output).toContain("technologies");
    });
    it("should handle single technology", () => {
      useWizardStore.setState({
        domainSelections: {
          web: {
            "web-framework": ["web-framework-react"]
          }
        }
      });
      const { lastFrame, unmount } = renderStepSources();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("1");
      globalExpect(output).toContain("technologies");
    });
    it("should handle multiple Enter presses on recommended", async () => {
      const onContinue = vi.fn();
      const { stdin, unmount } = renderStepSources({ onContinue });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onContinue).toHaveBeenCalledTimes(2);
    });
  });
  describe("store integration", () => {
    it("should set customizeSources when switching to customize view", async () => {
      const { stdin, unmount } = renderStepSources();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(useWizardStore.getState().customizeSources).toBe(true);
    });
    it("should reset customizeSources when escaping from customize view", async () => {
      const { stdin, unmount } = renderStepSources();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(useWizardStore.getState().customizeSources).toBe(true);
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      globalExpect(useWizardStore.getState().customizeSources).toBe(false);
    });
  });
});
//# sourceMappingURL=step-sources.test.js.map