#!/usr/bin/env node
import {
  ARROW_DOWN,
  ARROW_UP,
  ENTER,
  ESCAPE,
  INPUT_DELAY_MS,
  RENDER_DELAY_MS,
  SPACE,
  delay
} from "../../chunk-YZTWZVGX.js";
import {
  render
} from "../../chunk-66UDJBF6.js";
import {
  afterEach,
  describe,
  globalExpect,
  it,
  vi
} from "../../chunk-XY3XDVMI.js";
import {
  CheckboxGrid
} from "../../chunk-M4P5YJ45.js";
import "../../chunk-B4QYXVPZ.js";
import "../../chunk-FTD5Z6QD.js";
import {
  init_esm_shims
} from "../../chunk-DHET7RCE.js";

// src/cli/components/wizard/checkbox-grid.test.tsx
init_esm_shims();
import { jsx } from "react/jsx-runtime";
var TEST_ITEMS = [
  { id: "alpha", label: "Alpha", description: "First item" },
  { id: "beta", label: "Beta", description: "Second item" },
  { id: "gamma", label: "Gamma", description: "Third item" }
];
var defaultProps = {
  title: "Test title",
  subtitle: "Test subtitle",
  items: TEST_ITEMS,
  selectedIds: [],
  onToggle: vi.fn(),
  onContinue: vi.fn(),
  onBack: vi.fn(),
  continueLabel: (count) => `Continue with ${count} item(s)`,
  emptyMessage: "Select at least one"
};
var renderCheckboxGrid = (props = {}) => {
  return render(/* @__PURE__ */ jsx(CheckboxGrid, { ...defaultProps, ...props }));
};
describe("CheckboxGrid component", () => {
  let cleanup;
  afterEach(() => {
    cleanup?.();
    cleanup = void 0;
  });
  describe("rendering", () => {
    it("should render title and subtitle", () => {
      const { lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Test title");
      globalExpect(output).toContain("Test subtitle");
    });
    it("should render all items with correct labels", () => {
      const { lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Alpha");
      globalExpect(output).toContain("Beta");
      globalExpect(output).toContain("Gamma");
    });
    it("should render focused item description", () => {
      const { lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("First item");
      globalExpect(output).not.toContain("Second item");
      globalExpect(output).not.toContain("Third item");
    });
    it("should show unchecked checkboxes when nothing selected", () => {
      const { lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("[ ]");
      globalExpect(output).not.toContain("[\u2713]");
    });
    it("should show checked checkboxes for selected items", () => {
      const { lastFrame, unmount } = renderCheckboxGrid({
        selectedIds: ["alpha", "gamma"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("[\u2713]");
    });
    it("should show empty message when nothing selected", () => {
      const { lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Select at least one");
    });
    it("should show empty message as dimmed informational text", () => {
      const { lastFrame, unmount } = renderCheckboxGrid({
        emptyMessage: "No items selected"
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("No items selected");
    });
    it("should show selected summary when items are selected", () => {
      const { lastFrame, unmount } = renderCheckboxGrid({
        selectedIds: ["alpha", "beta"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Selected:");
      globalExpect(output).toContain("alpha");
      globalExpect(output).toContain("beta");
    });
    it("should show selected summary when items are selected instead of continue label", () => {
      const { lastFrame, unmount } = renderCheckboxGrid({
        selectedIds: ["alpha"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Selected:");
      globalExpect(output).toContain("alpha");
    });
    it("should show empty message when nothing selected instead of continue label", () => {
      const { lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Select at least one");
    });
  });
  describe("keyboard navigation", () => {
    it("should move focus down with arrow down", async () => {
      const { stdin, lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      let output = lastFrame();
      globalExpect(output).toBeDefined();
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      output = lastFrame();
      globalExpect(output).toBeDefined();
    });
    it("should move focus up with arrow up", async () => {
      const { stdin, lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_UP);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toBeDefined();
    });
    it("should move focus with j/k vim keys", async () => {
      const { stdin, lastFrame, unmount } = renderCheckboxGrid();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write("j");
      await delay(INPUT_DELAY_MS);
      let output = lastFrame();
      globalExpect(output).toBeDefined();
      stdin.write("k");
      await delay(INPUT_DELAY_MS);
      output = lastFrame();
      globalExpect(output).toBeDefined();
    });
    it("should toggle selection with SPACE", async () => {
      const onToggle = vi.fn();
      const { stdin, unmount } = renderCheckboxGrid({ onToggle });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(SPACE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onToggle).toHaveBeenCalledWith("alpha");
    });
    it("should toggle correct item after navigation", async () => {
      const onToggle = vi.fn();
      const { stdin, unmount } = renderCheckboxGrid({ onToggle });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(SPACE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onToggle).toHaveBeenCalledWith("beta");
    });
    it("should call onContinue with ENTER when items selected", async () => {
      const onContinue = vi.fn();
      const { stdin, unmount } = renderCheckboxGrid({
        onContinue,
        selectedIds: ["alpha"]
      });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onContinue).toHaveBeenCalled();
    });
    it("should call onContinue with ENTER even when nothing selected", async () => {
      const onContinue = vi.fn();
      const { stdin, unmount } = renderCheckboxGrid({
        onContinue,
        selectedIds: []
      });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onContinue).toHaveBeenCalled();
    });
    it("should call onBack with ESC", async () => {
      const onBack = vi.fn();
      const { stdin, unmount } = renderCheckboxGrid({ onBack });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onBack).toHaveBeenCalled();
    });
    it("should wrap focus from last to first item", async () => {
      const onToggle = vi.fn();
      const { stdin, unmount } = renderCheckboxGrid({ onToggle });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(SPACE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onToggle).toHaveBeenCalledWith("alpha");
    });
  });
  describe("custom props", () => {
    it("should show selected items in summary with custom selections", () => {
      const { lastFrame, unmount } = renderCheckboxGrid({
        selectedIds: ["alpha", "beta"]
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Selected:");
      globalExpect(output).toContain("alpha");
      globalExpect(output).toContain("beta");
    });
    it("should use custom emptyMessage", () => {
      const { lastFrame, unmount } = renderCheckboxGrid({
        emptyMessage: "Pick something!"
      });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Pick something!");
    });
  });
});
//# sourceMappingURL=checkbox-grid.test.js.map