"""Write a review redesign (17 Nov 2026): plan rules and a11y hooks stay right."""
import copy, datetime as dt, json
from pathlib import Path
import generator

HERE = Path(__file__).resolve().parents[1]
PAID = json.loads((HERE / "data/ato/example-flight-academy.json").read_text())


def html_for(tmp_path, plan, **extra):
    d = tmp_path / plan; d.mkdir(parents=True, exist_ok=True)
    (d / "a.json").write_text(json.dumps(copy.deepcopy(PAID)))
    generator.build(d, d / "out", "midnight", dt.date(2026, 11, 17), viewer={"kind": "member", "plan": plan, "name": "t.example", **extra})
    return (d / "out" / PAID["slug"] / "index.html").read_text()


def test_anonymous_only_for_pro_and_founding(tmp_path):
    for plan in ("pro", "founding"):
        h = html_for(tmp_path, plan)
        assert 'class="ob-anon-c"' in h and 'class="ob-agree-c"' in h and "wr-lock" not in h
    for plan, word in (("trial", "Trial"), ("free", "Free")):
        h = html_for(tmp_path, plan)
        assert "ob-anon-c" not in h and "ob-agree-c" not in h
        assert 'aria-disabled="true"' in h and f"{word} members post with their name." in h


def test_trial_cannot_be_shown_as_anonymous_even_if_asked(tmp_path):
    h = html_for(tmp_path, "trial", anonymous_on=True)
    assert 'data-name="t.example">t.example</span>' in h


def test_counter_is_tied_to_the_field_and_targets(tmp_path):
    h = html_for(tmp_path, "pro")
    assert 'id="wr-count"' in h and 'aria-describedby="wr-count"' in h
    css = (HERE / "shared/page.css").read_text()
    assert ".ob-revs .ap-vb{min-width:44px;min-height:44px}" in css
    assert "#write-review .ob-rgrid{--rg-cell:44px" in css
