#!/usr/bin/env node
import {
  ARROW_DOWN,
  ARROW_UP,
  ESCAPE,
  INPUT_DELAY_MS,
  delay
} from "../../chunk-YZTWZVGX.js";
import {
  render
} from "../../chunk-66UDJBF6.js";
import {
  afterEach,
  beforeEach,
  describe,
  globalExpect,
  it,
  vi
} from "../../chunk-XY3XDVMI.js";
import {
  StepSettings
} from "../../chunk-ELRGSZHZ.js";
import "../../chunk-7SOPVGDV.js";
import "../../chunk-KUV24B5M.js";
import "../../chunk-KWWLPPHF.js";
import "../../chunk-U3IGFMCY.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-settings.test.tsx
init_esm_shims();
import { jsx } from "react/jsx-runtime";
vi.mock("../../lib/configuration/source-manager.js", () => ({
  getSourceSummary: vi.fn(),
  addSource: vi.fn(),
  removeSource: vi.fn()
}));
vi.mock("../../lib/configuration/config.js", () => ({
  DEFAULT_SOURCE: "github:agents-inc/skills"
}));
var LOADING_SETTLE_MS = 200;
var defaultProps = {
  projectDir: "/test/project",
  onClose: vi.fn()
};
var renderStepSettings = (props = {}) => {
  return render(/* @__PURE__ */ jsx(StepSettings, { ...defaultProps, ...props }));
};
describe("StepSettings component", () => {
  let cleanup;
  beforeEach(async () => {
    vi.resetAllMocks();
    const { getSourceSummary } = await import("../../source-manager-HXFXBZJU.js");
    vi.mocked(getSourceSummary).mockResolvedValue({
      sources: [
        { name: "public", url: "github:agents-inc/skills", enabled: true },
        { name: "acme-corp", url: "github:acme-corp/claude-skills", enabled: true }
      ],
      localSkillCount: 3,
      pluginSkillCount: 1
    });
  });
  afterEach(() => {
    cleanup?.();
    cleanup = void 0;
  });
  describe("rendering", () => {
    it("should render the title", async () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Skill Sources");
    });
    it("should render configured sources", async () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Public");
      globalExpect(output).toContain("acme-corp");
    });
    it("should show default label for public source", async () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("(default)");
    });
    it("should show source URLs", async () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("github:agents-inc/skills");
      globalExpect(output).toContain("github:acme-corp/claude-skills");
    });
    it("should show local skill count", async () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("3");
      globalExpect(output).toContain(".claude/skills/");
    });
    it("should show plugin count", async () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("1");
      globalExpect(output).toContain("installed plugins");
    });
    it("should show add source input area", async () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Add source");
    });
    it("should show loading state initially", () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      const output = lastFrame();
      globalExpect(output).toContain("Loading sources...");
    });
  });
  describe("keyboard navigation", () => {
    it("should navigate down with arrow down", async () => {
      const { lastFrame, stdin, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      stdin.write(ARROW_DOWN);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("acme-corp");
    });
    it("should navigate up with arrow up", async () => {
      const { lastFrame, stdin, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_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("Public");
    });
    it("should not navigate above first item", async () => {
      const { lastFrame, stdin, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      stdin.write(ARROW_UP);
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Public");
    });
  });
  describe("escape to close", () => {
    it("should call onClose when Escape is pressed", async () => {
      const onClose = vi.fn();
      const { stdin, unmount } = renderStepSettings({ onClose });
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onClose).toHaveBeenCalledTimes(1);
    });
  });
  describe("add source input mode", () => {
    it("should enter add source mode on 'a' key", async () => {
      const { lastFrame, stdin, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      stdin.write("a");
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("\u2588");
    });
    it("should exit add source mode on Escape", async () => {
      const onClose = vi.fn();
      const { lastFrame, stdin, unmount } = renderStepSettings({ onClose });
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      stdin.write("a");
      await delay(INPUT_DELAY_MS);
      stdin.write(ESCAPE);
      await delay(INPUT_DELAY_MS);
      globalExpect(onClose).not.toHaveBeenCalled();
      const output = lastFrame();
      globalExpect(output).toContain("Skill Sources");
    });
    it("should show hint text for add mode", async () => {
      const { lastFrame, stdin, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      stdin.write("a");
      await delay(INPUT_DELAY_MS);
      const output = lastFrame();
      globalExpect(output).toContain("ENTER submit");
      globalExpect(output).toContain("ESC cancel");
    });
    it("should show hint text for normal mode", async () => {
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("DEL remove");
      globalExpect(output).toContain("close");
    });
  });
  describe("edge cases", () => {
    it("should handle empty sources list gracefully", async () => {
      const { getSourceSummary } = await import("../../source-manager-HXFXBZJU.js");
      vi.mocked(getSourceSummary).mockResolvedValue({
        sources: [{ name: "public", url: "github:agents-inc/skills", enabled: true }],
        localSkillCount: 0,
        pluginSkillCount: 0
      });
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Public");
      globalExpect(output).toContain("0");
    });
    it("should handle getSourceSummary failure gracefully", async () => {
      const { getSourceSummary } = await import("../../source-manager-HXFXBZJU.js");
      vi.mocked(getSourceSummary).mockRejectedValue(new Error("Config read failed"));
      const { lastFrame, unmount } = renderStepSettings();
      cleanup = unmount;
      await delay(LOADING_SETTLE_MS);
      const output = lastFrame();
      globalExpect(output).toContain("Public");
    });
  });
});
//# sourceMappingURL=step-settings.test.js.map