// @vitest-environment happy-dom
import { afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, render, screen, fireEvent } from "@testing-library/react";
import { Lane } from "./Lane";
import type { InboxClaimRow } from "@/lib/inbox-api";

afterEach(() => cleanup());

const sampleRows: InboxClaimRow[] = [
  {
    id: "CLP-1",
    kind: "claim",
    patient_control_number: "PCN-1",
    charge_amount: 100,
    payer_id: "PAYER-A",
    provider_npi: "1234567890",
    state: "rejected",
    rejection_reason: "R69",
    rejected_at: "2026-06-20T09:00:00Z",
    service_date_from: null,
    score: null,
    score_tier: null,
    score_breakdown: null,
  },
];

describe("Lane", () => {
  it("renders the lane name and row count", () => {
    const { container } = render(
      <Lane name="REJECTED" accent="oxblood" rows={sampleRows} onRowClick={() => {}} />,
    );
    expect(container.textContent).toContain("REJECTED");
    expect(container.textContent).toContain("1");
  });

  it("renders an empty state when no rows", () => {
    const { container } = render(
      <Lane name="DONE" accent="muted" rows={[]} onRowClick={() => {}} />,
    );
    expect(container.textContent).toMatch(/nothing here/i);
  });

  it("supports multi-select via row checkbox toggle", () => {
    const onSelectionChange = vi.fn();
    render(
      <Lane
        name="REJECTED"
        accent="oxblood"
        rows={sampleRows}
        onRowClick={() => {}}
        onSelectionChange={onSelectionChange}
      />,
    );
    const cb = screen.getByRole("checkbox");
    fireEvent.click(cb);
    expect(onSelectionChange).toHaveBeenCalled();
  });
});
