"""Side B (BASELINE, no skill) — test written directly against the app.
Selectors taken from reading the source. Straight-line assertions."""
from playwright.sync_api import sync_playwright

URL = "http://localhost:8931/index.html"
failures = []

def check(name, actual, expected):
    ok = actual == expected
    print(f"{'PASS' if ok else 'FAIL'}: {name} — expected {expected}, got {actual}")
    if not ok:
        failures.append(f"{name}: expected {expected}, got {actual}")

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()
    page.goto(URL)
    page.wait_for_load_state("networkidle")

    # Defaults: bill 100, tax 10%, tip 15%, people 2
    check("tax amount", page.text_content("#taxAmount"), "10.00")
    check("tip amount", page.text_content("#tipAmount"), "15.00")
    check("total", page.text_content("#total"), "125.00")
    check("per person", page.text_content("#perPerson"), "62.50")

    # Split between 4 people
    page.fill("#people", "4")
    page.wait_for_timeout(300)
    check("per person after split change", page.text_content("#perPerson"), "31.25")

    browser.close()

print(f"\n=== SIDE B RESULT: {len(failures)} failing check(s) ===")
for f in failures:
    print("BUG EVIDENCE:", f)
