import { render, screen } from "@testing-library/react";
import { beforeEach, describe, expect, it } from "vitest";
import { KEYS } from "../../data/mock/keys";
import type { RadarSweep } from "../../domain/types";
import { I18nProvider } from "../../i18n/I18nContext";
import { SweepFunnelSummary } from "./SweepFunnelSummary";

beforeEach(() => {
  localStorage.setItem(KEYS.uiPrefs, JSON.stringify({ locale: "zh-TW", currency: "TWD", theme: "system" }));
});

const sweep: RadarSweep = {
  id: "s1", watch_id: "w1", path: "api", hit_count: 10, deduped_count: 2, prefilter_pass_count: 6,
  prefilter_rejected_count: 2, cached_judgment_count: 1, judged_count: 5, created_count: 3, budget_deferred_count: 1,
  truncated_count: 0, sweep_status: "partial_budget", credit_search: 1, credit_demand_map: 0, credit_judge: 2,
  credit_reply: 0, credits_used: 3, started_at: 1,
};

describe("SweepFunnelSummary", () => {
  it("shows funnel counters, status and credit breakdown", () => {
    render(
      <I18nProvider>
        <SweepFunnelSummary sweep={sweep} />
      </I18nProvider>,
    );
    expect(screen.getByText("預算暫停")).toBeTruthy();
    expect(screen.getByText("新增商機").nextElementSibling?.textContent).toBe("3");
    expect(screen.getByText("合計 3")).toBeTruthy();
    expect(screen.getByText(/預算未使用的候選/)).toBeTruthy();
  });
});
