import { describe, expect, it } from "vitest";
import { WORKSHOPS, findWorkshop, type WorkshopSlug } from "./workshops";

describe("WORKSHOPS data", () => {
  it("defines exactly 8 workshops in the Phase 10 canonical order", () => {
    const slugs = WORKSHOPS.map((w) => w.slug);
    expect(slugs).toEqual([
      "diagrams",
      "icons",
      "themes",
      "wallpapers",
      "documents",
      "brand-kits",
      "social",
      "convert",
    ] satisfies WorkshopSlug[]);
  });

  it("has unique slugs", () => {
    const slugs = WORKSHOPS.map((w) => w.slug);
    expect(new Set(slugs).size).toBe(slugs.length);
  });

  it("has a title, subtitle, icon, and componentKey for every workshop", () => {
    for (const w of WORKSHOPS) {
      expect(w.title).toMatch(/^[A-Z ]+$/);
      expect(w.subtitle.length).toBeGreaterThan(0);
      // Lucide icons are React forwardRef components (object), not plain functions.
      expect(["function", "object"]).toContain(typeof w.icon);
      expect(w.icon).not.toBeNull();
      expect(w.componentKey.length).toBeGreaterThan(0);
    }
  });

  it("uses uppercase titles only", () => {
    for (const w of WORKSHOPS) {
      expect(w.title).toBe(w.title.toUpperCase());
    }
  });

  it("has unique componentKeys", () => {
    const keys = WORKSHOPS.map((w) => w.componentKey);
    expect(new Set(keys).size).toBe(keys.length);
  });
});

describe("findWorkshop", () => {
  it("returns the workshop definition for a known slug", () => {
    const w = findWorkshop("diagrams");
    expect(w).not.toBeNull();
    expect(w?.title).toBe("DIAGRAMS");
  });

  it("returns null for an unknown slug", () => {
    expect(findWorkshop("nope")).toBeNull();
    expect(findWorkshop("")).toBeNull();
  });
});
