/**
 * Widget Registry Tests
 * Following TDD - write tests first!
 */

import { describe, it, expect } from "vitest";
import { widgetRegistry } from "../WidgetRegistry";
import { TasksWidget } from "../TasksWidget";
import { CalendarWidget } from "../CalendarWidget";
import { QuickCaptureWidget } from "../QuickCaptureWidget";

describe("WidgetRegistry", () => {
  it("should have a registry of widgets", () => {
    expect(widgetRegistry).toBeDefined();
    expect(typeof widgetRegistry).toBe("object");
  });

  it("should include TasksWidget in registry", () => {
    expect(widgetRegistry.TasksWidget).toBeDefined();
    expect(widgetRegistry.TasksWidget!.component).toBe(TasksWidget);
  });

  it("should include CalendarWidget in registry", () => {
    expect(widgetRegistry.CalendarWidget).toBeDefined();
    expect(widgetRegistry.CalendarWidget!.component).toBe(CalendarWidget);
  });

  it("should include QuickCaptureWidget in registry", () => {
    expect(widgetRegistry.QuickCaptureWidget).toBeDefined();
    expect(widgetRegistry.QuickCaptureWidget!.component).toBe(QuickCaptureWidget);
  });

  it("should have correct metadata for TasksWidget", () => {
    const tasksWidget = widgetRegistry.TasksWidget!;
    expect(tasksWidget.name).toBe("TasksWidget");
    expect(tasksWidget.displayName).toBe("Tasks");
    expect(tasksWidget.description).toBeDefined();
    expect(tasksWidget.defaultWidth).toBeGreaterThan(0);
    expect(tasksWidget.defaultHeight).toBeGreaterThan(0);
    expect(tasksWidget.minWidth).toBeGreaterThan(0);
    expect(tasksWidget.minHeight).toBeGreaterThan(0);
  });

  it("should have correct metadata for CalendarWidget", () => {
    const calendarWidget = widgetRegistry.CalendarWidget!;
    expect(calendarWidget.name).toBe("CalendarWidget");
    expect(calendarWidget.displayName).toBe("Calendar");
    expect(calendarWidget.description).toBeDefined();
    expect(calendarWidget.defaultWidth).toBeGreaterThan(0);
    expect(calendarWidget.defaultHeight).toBeGreaterThan(0);
  });

  it("should have correct metadata for QuickCaptureWidget", () => {
    const quickCaptureWidget = widgetRegistry.QuickCaptureWidget!;
    expect(quickCaptureWidget.name).toBe("QuickCaptureWidget");
    expect(quickCaptureWidget.displayName).toBe("Quick Capture");
    expect(quickCaptureWidget.description).toBeDefined();
    expect(quickCaptureWidget.defaultWidth).toBeGreaterThan(0);
    expect(quickCaptureWidget.defaultHeight).toBeGreaterThan(0);
  });

  it("should export getWidgetByName helper", async () => {
    const { getWidgetByName } = await import("../WidgetRegistry");
    expect(typeof getWidgetByName).toBe("function");
  });

  it("getWidgetByName should return correct widget", async () => {
    const { getWidgetByName } = await import("../WidgetRegistry");
    const widget = getWidgetByName("TasksWidget");
    expect(widget).toBeDefined();
    expect(widget?.component).toBe(TasksWidget);
  });

  it("getWidgetByName should return undefined for invalid name", async () => {
    const { getWidgetByName } = await import("../WidgetRegistry");
    const widget = getWidgetByName("InvalidWidget");
    expect(widget).toBeUndefined();
  });

  it("should export getAllWidgets helper", async () => {
    const { getAllWidgets } = await import("../WidgetRegistry");
    expect(typeof getAllWidgets).toBe("function");
  });

  it("getAllWidgets should return array of all widgets", async () => {
    const { getAllWidgets } = await import("../WidgetRegistry");
    const widgets = getAllWidgets();
    expect(Array.isArray(widgets)).toBe(true);
    expect(widgets.length).toBeGreaterThanOrEqual(3);
  });
});
