#!/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 {
  afterEach,
  describe,
  globalExpect,
  it,
  vi
} from "../../chunk-XY3XDVMI.js";
import {
  SearchModal
} from "../../chunk-F3O5YHSI.js";
import "../../chunk-KUV24B5M.js";
import "../../chunk-FVN5PFFY.js";
import {
  init_esm_shims
} from "../../chunk-DHET7RCE.js";

// src/cli/components/wizard/search-modal.test.tsx
init_esm_shims();
import { jsx } from "react/jsx-runtime";
var candidates = [
  {
    id: "web-framework-react-pro",
    sourceUrl: "github:awesome-dev/skills",
    sourceName: "awesome-dev",
    alias: "react",
    description: "Opinionated React with strict TS"
  },
  {
    id: "web-framework-react-strict",
    sourceUrl: "github:team-xyz/skills",
    sourceName: "team-xyz",
    alias: "react",
    description: "Strict mode React"
  },
  {
    id: "web-framework-react-minimal",
    sourceUrl: "github:solo-dev/skills",
    sourceName: "solo-dev",
    alias: "react",
    description: "Minimal hooks-only React"
  }
];
var defaultProps = {
  results: candidates,
  alias: "react",
  onBind: vi.fn(),
  onClose: vi.fn()
};
var renderModal = (props = {}) => {
  return render(/* @__PURE__ */ jsx(SearchModal, { ...defaultProps, ...props }));
};
describe("SearchModal component", () => {
  let cleanup;
  afterEach(() => {
    cleanup?.();
    cleanup = void 0;
  });
  describe("rendering", () => {
    it("should render the alias in the title", () => {
      const { lastFrame, unmount } = renderModal();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("react");
      globalExpect(output).toContain("Search results");
    });
    it("should render all result source names", () => {
      const { lastFrame, unmount } = renderModal();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("awesome-dev");
      globalExpect(output).toContain("team-xyz");
      globalExpect(output).toContain("solo-dev");
    });
    it("should render result descriptions", () => {
      const { lastFrame, unmount } = renderModal();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Opinionated React with strict TS");
      globalExpect(output).toContain("Strict mode React");
    });
    it("should show focused marker on first result by default", () => {
      const { lastFrame, unmount } = renderModal();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("\u25B8");
    });
    it("should show 'No results found' when results array is empty", () => {
      const { lastFrame, unmount } = renderModal({ results: [] });
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("No results found");
    });
    it("should render help text with navigation hints", () => {
      const { lastFrame, unmount } = renderModal();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("navigate");
      globalExpect(output).toContain("ENTER");
      globalExpect(output).toContain("ESC");
    });
  });
  describe("keyboard navigation", () => {
    it("should move focus down with arrow down", async () => {
      const { stdin, lastFrame, unmount } = renderModal();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("team-xyz");
    });
    it("should move focus up with arrow up", async () => {
      const { stdin, lastFrame, unmount } = renderModal();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      stdin.write(ARROW_UP);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("awesome-dev");
    });
    it("should wrap from last result to first on arrow down", async () => {
      const { stdin, lastFrame, unmount } = renderModal();
      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);
      const output = lastFrame();
      globalExpect(output).toContain("awesome-dev");
    });
    it("should wrap from first result to last on arrow up", async () => {
      const { stdin, lastFrame, unmount } = renderModal();
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ARROW_UP);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("solo-dev");
    });
  });
  describe("actions", () => {
    it("should call onBind with focused candidate on Enter", async () => {
      const onBind = vi.fn();
      const { stdin, unmount } = renderModal({ onBind });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onBind).toHaveBeenCalledWith(candidates[0]);
    });
    it("should call onBind with second candidate after navigating down", async () => {
      const onBind = vi.fn();
      const { stdin, unmount } = renderModal({ onBind });
      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(onBind).toHaveBeenCalledWith(candidates[1]);
    });
    it("should call onClose on Escape", async () => {
      const onClose = vi.fn();
      const { stdin, unmount } = renderModal({ onClose });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onClose).toHaveBeenCalled();
    });
    it("should not call onBind on Enter when results are empty", async () => {
      const onBind = vi.fn();
      const { stdin, unmount } = renderModal({ results: [], onBind });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ENTER);
      await delay(INPUT_DELAY_MS);
      globalExpect(onBind).not.toHaveBeenCalled();
    });
    it("should not call onBind on Escape", async () => {
      const onBind = vi.fn();
      const { stdin, unmount } = renderModal({ onBind });
      cleanup = unmount;
      await delay(RENDER_DELAY_MS);
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onBind).not.toHaveBeenCalled();
    });
  });
});
//# sourceMappingURL=search-modal.test.js.map