import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import { PoStatusBadge } from "@/components/po/po-status-badge";
import { PO_STATUS_LABELS } from "@/lib/utils";
import type { POStatus } from "@prisma/client";

const ALL_STATUSES: POStatus[] = [
  "DRAFT", "SUBMITTED", "MGR_REVIEW", "VENDOR_ID_PENDING",
  "EDITS_REQUESTED", "REJECTED", "MGR_APPROVED",
  "SENT_FOR_PAYMENT", "PAID_DELIVERED", "CLOSED",
];

describe("PoStatusBadge", () => {
  it.each(ALL_STATUSES)("renders the correct label for %s", (status) => {
    render(<PoStatusBadge status={status} />);
    expect(screen.getByText(PO_STATUS_LABELS[status])).toBeInTheDocument();
  });

  it("renders 'Draft' for DRAFT status", () => {
    render(<PoStatusBadge status="DRAFT" />);
    expect(screen.getByText("Draft")).toBeInTheDocument();
  });

  it("renders 'Approved' for MGR_APPROVED status", () => {
    render(<PoStatusBadge status="MGR_APPROVED" />);
    expect(screen.getByText("Approved")).toBeInTheDocument();
  });

  it("renders 'Rejected' for REJECTED status", () => {
    render(<PoStatusBadge status="REJECTED" />);
    expect(screen.getByText("Rejected")).toBeInTheDocument();
  });

  it("renders 'Under Review' for MGR_REVIEW status", () => {
    render(<PoStatusBadge status="MGR_REVIEW" />);
    expect(screen.getByText("Under Review")).toBeInTheDocument();
  });

  it("renders 'Edits Requested' for EDITS_REQUESTED status", () => {
    render(<PoStatusBadge status="EDITS_REQUESTED" />);
    expect(screen.getByText("Edits Requested")).toBeInTheDocument();
  });

  it("renders 'Vendor ID Pending' for VENDOR_ID_PENDING status", () => {
    render(<PoStatusBadge status="VENDOR_ID_PENDING" />);
    expect(screen.getByText("Vendor ID Pending")).toBeInTheDocument();
  });

  it("renders exactly one badge element", () => {
    const { container } = render(<PoStatusBadge status="DRAFT" />);
    // Badge renders as a single span/div-like element
    expect(container.firstChild).not.toBeNull();
    expect(container.children).toHaveLength(1);
  });
});
