import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";

import { ConditionConfidenceCard } from "../condition-confidence-card";

describe("ConditionConfidenceCard", () => {
  it.each([
    ["NWT", "New with tags", "Unworn item with original retail tags attached."],
    ["NWOT", "New without tags", "New item without retail tags; no expected wear from use."],
    ["EUC", "Excellent used condition", "Lightly used and carefully kept, with no obvious flaws expected."],
    ["GUC", "Good used condition", "Used item with normal signs of wear, still ready for regular use."],
    ["Fair", "Fair condition", "Visible wear is expected; review photos and measurements closely before buying."],
    ["Poor", "Poor condition", "Heavy wear or flaws are expected; best for buyers comfortable with visible issues."],
  ])("maps %s to buyer-friendly condition copy", (condition, label, description) => {
    render(<ConditionConfidenceCard condition={condition} />);

    expect(screen.getByRole("region", { name: "Condition confidence" })).toBeInTheDocument();
    expect(screen.getByText(label)).toBeInTheDocument();
    expect(screen.getByText(description)).toBeInTheDocument();
  });

  it("renders a neutral fallback for unknown condition codes", () => {
    render(<ConditionConfidenceCard condition="Vintage" />);

    expect(screen.getByText("Condition details")).toBeInTheDocument();
    expect(
      screen.getByText(
        "Review the seller photos, description, and measurements for the best read on this item.",
      ),
    ).toBeInTheDocument();
    expect(screen.getByText("Seller condition: Vintage")).toBeInTheDocument();
  });

  it("omits future note headings when sparse data has no flaws or inspection notes", () => {
    render(
      <ConditionConfidenceCard
        condition={null}
        flaws={["", "  "]}
        inspectionNotes=" "
      />,
    );

    expect(screen.getByText("Condition details")).toBeInTheDocument();
    expect(screen.queryByText("Flaws noted")).toBeNull();
    expect(screen.queryByText("Inspection notes")).toBeNull();
  });

  it("renders future flaws and inspection notes only when provided", () => {
    render(
      <ConditionConfidenceCard
        condition="GUC"
        flaws={["Small mark on sleeve"]}
        inspectionNotes="Checked for stains and loose seams."
      />,
    );

    expect(screen.getByText("Flaws noted")).toBeInTheDocument();
    expect(screen.getByText("Small mark on sleeve")).toBeInTheDocument();
    expect(screen.getByText("Inspection notes")).toBeInTheDocument();
    expect(screen.getByText("Checked for stains and loose seams.")).toBeInTheDocument();
  });
});
