import { describe, expect, it } from "vitest";
import {
  ALLOCATION_STATUS_BADGE,
  VACATION_STATUS_BADGE,
  VACATION_TYPE_LABELS,
  VACATION_TYPE_BADGE,
  PROJECT_STATUS_BADGE,
  ORDER_TYPE_BADGE,
  VACATION_TIMELINE_COLORS,
  VACATION_TIMELINE_BORDER,
  VACATION_TYPE_LABELS_SHORT,
  VACATION_CALENDAR_COLORS,
} from "./status-styles.js";

// ---------------------------------------------------------------------------
// ALLOCATION_STATUS_BADGE
// ---------------------------------------------------------------------------

describe("ALLOCATION_STATUS_BADGE", () => {
  const expectedKeys = ["ACTIVE", "PROPOSED", "CONFIRMED", "COMPLETED", "CANCELLED"];

  it("contains all expected allocation status keys", () => {
    expectedKeys.forEach((key) => {
      expect(ALLOCATION_STATUS_BADGE).toHaveProperty(key);
    });
  });

  it("has no extra unexpected keys", () => {
    expect(Object.keys(ALLOCATION_STATUS_BADGE).sort()).toEqual(expectedKeys.sort());
  });

  it.each(expectedKeys)("value for %s is a non-empty string", (key) => {
    expect(typeof ALLOCATION_STATUS_BADGE[key]).toBe("string");
    expect(ALLOCATION_STATUS_BADGE[key]!.length).toBeGreaterThan(0);
  });

  it("ACTIVE uses green classes", () => {
    expect(ALLOCATION_STATUS_BADGE.ACTIVE).toContain("green");
  });

  it("CANCELLED uses red classes", () => {
    expect(ALLOCATION_STATUS_BADGE.CANCELLED).toContain("red");
  });

  it("PROPOSED uses yellow classes", () => {
    expect(ALLOCATION_STATUS_BADGE.PROPOSED).toContain("yellow");
  });

  it("CONFIRMED uses blue classes", () => {
    expect(ALLOCATION_STATUS_BADGE.CONFIRMED).toContain("blue");
  });

  it("COMPLETED uses gray classes", () => {
    expect(ALLOCATION_STATUS_BADGE.COMPLETED).toContain("gray");
  });
});

// ---------------------------------------------------------------------------
// VACATION_STATUS_BADGE
// ---------------------------------------------------------------------------

describe("VACATION_STATUS_BADGE", () => {
  const expectedKeys = ["PENDING", "APPROVED", "REJECTED", "CANCELLED"];

  it("contains all expected vacation status keys", () => {
    expectedKeys.forEach((key) => {
      expect(VACATION_STATUS_BADGE).toHaveProperty(key);
    });
  });

  it("has no extra unexpected keys", () => {
    expect(Object.keys(VACATION_STATUS_BADGE).sort()).toEqual(expectedKeys.sort());
  });

  it.each(expectedKeys)("value for %s is a non-empty string", (key) => {
    expect(typeof VACATION_STATUS_BADGE[key]).toBe("string");
    expect(VACATION_STATUS_BADGE[key]!.length).toBeGreaterThan(0);
  });

  it("APPROVED uses green/emerald classes", () => {
    expect(VACATION_STATUS_BADGE.APPROVED).toMatch(/emerald|green/);
  });

  it("REJECTED uses red classes", () => {
    expect(VACATION_STATUS_BADGE.REJECTED).toContain("red");
  });

  it("PENDING uses amber/yellow classes", () => {
    expect(VACATION_STATUS_BADGE.PENDING).toMatch(/amber|yellow/);
  });

  it("CANCELLED uses gray classes", () => {
    expect(VACATION_STATUS_BADGE.CANCELLED).toContain("gray");
  });
});

// ---------------------------------------------------------------------------
// VACATION_TYPE_LABELS
// ---------------------------------------------------------------------------

describe("VACATION_TYPE_LABELS", () => {
  it("provides human-readable label for ANNUAL", () => {
    expect(VACATION_TYPE_LABELS.ANNUAL).toBe("Annual Leave");
  });

  it("provides human-readable label for SICK", () => {
    expect(VACATION_TYPE_LABELS.SICK).toBe("Sick Leave");
  });

  it("provides human-readable label for PUBLIC_HOLIDAY", () => {
    expect(VACATION_TYPE_LABELS.PUBLIC_HOLIDAY).toBe("Public Holiday");
  });

  it("provides human-readable label for OTHER", () => {
    expect(VACATION_TYPE_LABELS.OTHER).toBe("Other");
  });

  it("covers exactly the four expected types", () => {
    expect(Object.keys(VACATION_TYPE_LABELS).sort()).toEqual([
      "ANNUAL",
      "OTHER",
      "PUBLIC_HOLIDAY",
      "SICK",
    ]);
  });
});

// ---------------------------------------------------------------------------
// VACATION_TYPE_BADGE
// ---------------------------------------------------------------------------

describe("VACATION_TYPE_BADGE", () => {
  const expectedKeys = ["ANNUAL", "SICK", "PUBLIC_HOLIDAY", "OTHER"];

  it("contains all expected vacation type keys", () => {
    expectedKeys.forEach((key) => {
      expect(VACATION_TYPE_BADGE).toHaveProperty(key);
    });
  });

  it("has no extra unexpected keys", () => {
    expect(Object.keys(VACATION_TYPE_BADGE).sort()).toEqual(expectedKeys.sort());
  });

  it.each(expectedKeys)("value for %s is a non-empty string", (key) => {
    expect(typeof VACATION_TYPE_BADGE[key]).toBe("string");
    expect(VACATION_TYPE_BADGE[key]!.length).toBeGreaterThan(0);
  });

  it("SICK uses red classes", () => {
    expect(VACATION_TYPE_BADGE.SICK).toContain("red");
  });

  it("OTHER uses purple classes", () => {
    expect(VACATION_TYPE_BADGE.OTHER).toContain("purple");
  });
});

// ---------------------------------------------------------------------------
// PROJECT_STATUS_BADGE
// ---------------------------------------------------------------------------

describe("PROJECT_STATUS_BADGE", () => {
  const expectedKeys = ["DRAFT", "ACTIVE", "ON_HOLD", "COMPLETED", "CANCELLED"];

  it("contains all expected project status keys", () => {
    expectedKeys.forEach((key) => {
      expect(PROJECT_STATUS_BADGE).toHaveProperty(key);
    });
  });

  it("has no extra unexpected keys", () => {
    expect(Object.keys(PROJECT_STATUS_BADGE).sort()).toEqual(expectedKeys.sort());
  });

  it.each(expectedKeys)("value for %s is a non-empty string", (key) => {
    expect(typeof PROJECT_STATUS_BADGE[key]).toBe("string");
    expect(PROJECT_STATUS_BADGE[key]!.length).toBeGreaterThan(0);
  });

  it("DRAFT uses gray classes", () => {
    expect(PROJECT_STATUS_BADGE.DRAFT).toContain("gray");
  });

  it("ACTIVE uses green classes", () => {
    expect(PROJECT_STATUS_BADGE.ACTIVE).toContain("green");
  });

  it("ON_HOLD uses yellow classes", () => {
    expect(PROJECT_STATUS_BADGE.ON_HOLD).toContain("yellow");
  });

  it("COMPLETED uses blue classes", () => {
    expect(PROJECT_STATUS_BADGE.COMPLETED).toContain("blue");
  });

  it("CANCELLED uses red classes", () => {
    expect(PROJECT_STATUS_BADGE.CANCELLED).toContain("red");
  });
});

// ---------------------------------------------------------------------------
// ORDER_TYPE_BADGE
// ---------------------------------------------------------------------------

describe("ORDER_TYPE_BADGE", () => {
  const expectedKeys = ["BD", "CHARGEABLE", "INTERNAL", "OVERHEAD"];

  it("contains all expected order type keys", () => {
    expectedKeys.forEach((key) => {
      expect(ORDER_TYPE_BADGE).toHaveProperty(key);
    });
  });

  it("has no extra unexpected keys", () => {
    expect(Object.keys(ORDER_TYPE_BADGE).sort()).toEqual(expectedKeys.sort());
  });

  it.each(expectedKeys)("value for %s is a non-empty string", (key) => {
    expect(typeof ORDER_TYPE_BADGE[key]).toBe("string");
    expect(ORDER_TYPE_BADGE[key]!.length).toBeGreaterThan(0);
  });

  it("BD uses purple classes", () => {
    expect(ORDER_TYPE_BADGE.BD).toContain("purple");
  });

  it("CHARGEABLE uses green classes", () => {
    expect(ORDER_TYPE_BADGE.CHARGEABLE).toContain("green");
  });

  it("INTERNAL uses blue classes", () => {
    expect(ORDER_TYPE_BADGE.INTERNAL).toContain("blue");
  });

  it("OVERHEAD uses gray classes", () => {
    expect(ORDER_TYPE_BADGE.OVERHEAD).toContain("gray");
  });
});

// ---------------------------------------------------------------------------
// VACATION_TIMELINE_COLORS
// ---------------------------------------------------------------------------

describe("VACATION_TIMELINE_COLORS", () => {
  const expectedKeys = ["ANNUAL", "SICK", "PUBLIC_HOLIDAY", "OTHER"];

  it("covers all vacation types", () => {
    expectedKeys.forEach((key) => {
      expect(VACATION_TIMELINE_COLORS).toHaveProperty(key);
    });
  });

  it.each(expectedKeys)("value for %s is a non-empty string", (key) => {
    expect(typeof VACATION_TIMELINE_COLORS[key]).toBe("string");
    expect(VACATION_TIMELINE_COLORS[key]!.length).toBeGreaterThan(0);
  });

  it("SICK uses red classes", () => {
    expect(VACATION_TIMELINE_COLORS.SICK).toContain("red");
  });
});

// ---------------------------------------------------------------------------
// VACATION_TIMELINE_BORDER
// ---------------------------------------------------------------------------

describe("VACATION_TIMELINE_BORDER", () => {
  const expectedKeys = ["ANNUAL", "SICK", "PUBLIC_HOLIDAY", "OTHER"];

  it("covers all vacation types", () => {
    expectedKeys.forEach((key) => {
      expect(VACATION_TIMELINE_BORDER).toHaveProperty(key);
    });
  });

  it.each(expectedKeys)("value for %s starts with 'border-'", (key) => {
    expect(VACATION_TIMELINE_BORDER[key]).toMatch(/^border-/);
  });

  it("SICK uses red border", () => {
    expect(VACATION_TIMELINE_BORDER.SICK).toContain("red");
  });
});

// ---------------------------------------------------------------------------
// VACATION_TYPE_LABELS_SHORT
// ---------------------------------------------------------------------------

describe("VACATION_TYPE_LABELS_SHORT", () => {
  it("provides short label for ANNUAL", () => {
    expect(VACATION_TYPE_LABELS_SHORT.ANNUAL).toBe("Annual");
  });

  it("provides short label for SICK", () => {
    expect(VACATION_TYPE_LABELS_SHORT.SICK).toBe("Sick");
  });

  it("provides short label for PUBLIC_HOLIDAY", () => {
    expect(VACATION_TYPE_LABELS_SHORT.PUBLIC_HOLIDAY).toBe("Holiday");
  });

  it("provides short label for OTHER", () => {
    expect(VACATION_TYPE_LABELS_SHORT.OTHER).toBe("Other");
  });

  it("short labels are shorter than or equal to full labels", () => {
    (Object.keys(VACATION_TYPE_LABELS_SHORT) as string[]).forEach((key) => {
      const short = VACATION_TYPE_LABELS_SHORT[key]!;
      const full = VACATION_TYPE_LABELS[key] ?? short;
      expect(short.length).toBeLessThanOrEqual(full.length);
    });
  });
});

// ---------------------------------------------------------------------------
// VACATION_CALENDAR_COLORS
// ---------------------------------------------------------------------------

describe("VACATION_CALENDAR_COLORS", () => {
  const expectedKeys = ["ANNUAL", "SICK", "PUBLIC_HOLIDAY", "OTHER"];

  it("covers all vacation types", () => {
    expectedKeys.forEach((key) => {
      expect(VACATION_CALENDAR_COLORS).toHaveProperty(key);
    });
  });

  it.each(expectedKeys)("value for %s starts with 'bg-'", (key) => {
    expect(VACATION_CALENDAR_COLORS[key]).toMatch(/^bg-/);
  });

  it("SICK uses red", () => {
    expect(VACATION_CALENDAR_COLORS.SICK).toContain("red");
  });

  it("PUBLIC_HOLIDAY uses emerald", () => {
    expect(VACATION_CALENDAR_COLORS.PUBLIC_HOLIDAY).toContain("emerald");
  });

  it("OTHER uses purple", () => {
    expect(VACATION_CALENDAR_COLORS.OTHER).toContain("purple");
  });
});
