import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Claude hub pools weight Ultra and Pro by plan capacity", WEB, async ({t3,app,screen,browser}) => {
 await fetch("http://127.0.0.1:18917/fixture/ultra");
 await t3.project("Quota demo");
 await t3.open("/settings/providers");
 await screen.getByRole("button", "Add hub", {exact:true}).tap();
 await screen.getByRole("textbox", "Hub URL").fill("http://127.0.0.1:18917");
 await screen.getByRole("textbox", "Management key").fill("synthetic-fixture-key");
 await screen.getByRole("textbox", "Label (optional)").fill("Claude pool hub");
 await screen.getByRole("button", "Add hub", {exact:true}).tap();
 await t3.open("/usage?metric=limits");
 await screen.getByRole("button", "UE: 6% left", {exact:false}).waitFor({state:"visible"});
 await app.screenshot("claude-pooled-limits");
 await screen.getByRole("button", "UE: 6% left", {exact:false}).tap();
 await screen.getByText("Plan", {exact:true}).waitFor({state:"visible"});
 await browser.evaluate(async () => { await Promise.all(document.getAnimations().map(a => a.finished.catch(() => {}))); return null; });
 await app.screenshot("claude-weekly-contribution");
 await browser.keyboard.press("Escape");
 await expect(screen.getByText("15%", {exact:true})).toBeVisible();
 await expect(screen.getByText("45%", {exact:true})).toBeVisible();
 for (const [mode, session, weekly, plan] of [
   ["max", "50%", "22%", "Claude Max Subscription"],
   ["unknown", "70%", "53%", "Claude Subscription"],
   ["failed-profile", "70%", "53%", "Claude Subscription"],
 ] as const) {
   await fetch(`http://127.0.0.1:18917/fixture/${mode}`);
   await screen.getByRole("button", "Refresh limits", {exact:true}).tap();
   await expect(screen.getByRole("button", "Refresh limits", {exact:true})).toBeEnabled();
   await expect(screen.getByText(session, {exact:true})).toBeVisible();
   await expect(screen.getByText(weekly, {exact:true})).toBeVisible();
   await app.screenshot(`claude-${mode}-pool`);
   await screen.getByRole("button", "UE: 6% left", {exact:false}).tap();
   await expect(screen.getByText(plan, {exact:true})).toBeVisible();
   await browser.evaluate(async () => { await Promise.all(document.getAnimations().map(a => a.finished.catch(() => {}))); return null; });
   await app.screenshot(`claude-${mode}-plan`);
   await browser.keyboard.press("Escape");
 }
});
