import { describe, it, expect } from "vitest";
import { handleCompose } from "../../src/tools/compose.js";
import { ComponentRegistry } from "../../src/registry.js";

describe("pettyui.compose", () => {
  const registry = new ComponentRegistry();

  it("generates JSX for specified components — Dialog + Button both present", () => {
    const result = handleCompose(registry, { components: ["Dialog", "Button"] });
    expect(result.jsx).toContain("Dialog");
    expect(result.jsx).toContain("Button");
    expect(result.imports).toContain("pettyui/dialog");
    expect(result.imports).toContain("pettyui/button");
  });

  it("generates imports for all — Form + TextField + Button → 3 imports", () => {
    const result = handleCompose(registry, { components: ["Form", "TextField", "Button"] });
    expect(result.imports).toHaveLength(3);
  });

  it("uses required parts — Dialog → jsx contains Dialog.Content and Dialog.Title", () => {
    const result = handleCompose(registry, { components: ["Dialog"] });
    expect(result.jsx).toContain("Dialog.Content");
    expect(result.jsx).toContain("Dialog.Title");
  });

  it("skips unknown with warning — FakeComponent gets warning, Dialog still in jsx", () => {
    const result = handleCompose(registry, { components: ["Dialog", "FakeComponent"] });
    expect(result.warnings).toContain('Component "FakeComponent" not found');
    expect(result.jsx).toContain("Dialog");
    expect(result.imports).toHaveLength(1);
  });
});
