import json, subprocess
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
QA=ROOT/'qa_screenshots'; QA.mkdir(exist_ok=True)
views=[('mobile',390,844),('ipad',820,1180),('desktop',1440,960)]
cards=[
('Pass/Motion Lab','runtime · atlet · passvy'),
('Visual review + correction','review · correction patch'),
('Motion trace verifier','trace · QA'),
('Special prop binding','prop · bar · box'),
('Video / Screen Pose Capture','video · screen capture · keyframes'),
('MediaPipe extractor','landmarks · patch export'),
('Green motion expansion','green list · runtime gates')]

def render(name,w,h):
    card_html=''.join(f'<article class="card"><div class="k">Test</div><h2>{a}</h2><p>{b}</p><button>Öppna</button></article>' for a,b in cards)
    html=f'''<!doctype html><html><head><meta charset="utf-8"><style>@page{{size:{w}px {h}px;margin:0}}*{{box-sizing:border-box}}body{{margin:0;font-family:system-ui,-apple-system,Segoe UI,sans-serif;background:radial-gradient(circle at 10% 0,#153d5c,#07111f 58%,#02060d);color:#e9fbff;padding:22px}}.top{{display:flex;align-items:center;gap:12px;margin-bottom:18px}}.hamb{{width:48px;height:48px;border:1px solid rgba(120,233,255,.3);border-radius:18px;display:grid;place-items:center;flex:0 0 auto}}.brand{{font-weight:950;letter-spacing:.08em;white-space:nowrap}}.nav{{margin-left:auto;display:flex;gap:10px;color:#bdefff;flex-wrap:wrap;justify-content:flex-end}}.nav span{{border:1px solid rgba(120,233,255,.22);border-radius:999px;padding:8px 11px}}.nav .active{{background:#76e8ff;color:#031323}}.hero{{border:1px solid rgba(120,233,255,.24);background:rgba(255,255,255,.055);border-radius:22px;padding:20px;margin-bottom:14px}}.meta{{color:#76e8ff;font-weight:900;letter-spacing:.08em;text-transform:uppercase;font-size:12px}}h1{{font-size:clamp(36px,6vw,70px);line-height:.92;margin:8px 0}}p{{color:#b9d2de;line-height:1.4}}.grid{{display:grid;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));gap:14px}}.card{{border:1px solid rgba(120,233,255,.2);background:rgba(255,255,255,.05);border-radius:18px;padding:16px;min-height:160px}}.card:nth-child(5){{outline:3px solid rgba(118,232,255,.35)}}.k{{color:#76e8ff;font-weight:900;font-size:12px;text-transform:uppercase}}h2{{margin:8px 0 4px}}button{{background:#76e8ff;border:0;border-radius:999px;padding:10px 14px;font-weight:950;color:#031323}}.check{{margin-top:16px;border:1px solid rgba(120,233,255,.22);background:rgba(0,0,0,.25);border-radius:18px;padding:16px}}@media(max-width:600px){{body{{padding:14px}}.top{{gap:10px}}.nav{{display:none}}.brand{{font-size:18px}}.grid{{grid-template-columns:1fr}}button{{width:100%;text-align:center}}}}</style></head><body><div class="top"><div class="hamb">☰</div><div class="brand">NEXT Athlete OS</div><div class="nav"><span>Dashboard</span><span>Övningar</span><span class="active">Testcenter</span></div></div><section class="hero"><div class="meta">RC52 · {name} · Testcenter + Video Pose Capture</div><h1>Testa det som ska testas</h1><p>Samlad testsida för passläge, rörelse-, bild- och video/screen-capture-granskning. Nytt: volatile video/screen capture som sparar skeleton JSON men ingen video.</p></section><main class="grid">{card_html}</main><section class="check"><b>Snabb-runda:</b> Motion Lab → referensfilm via Video / Screen Pose Capture → exportera rc52_video_pose_capture.json → Visual review om något ser fel ut.</section></body></html>'''
    html_path=QA/f'rc52_{name}_static_qa.html'; pdf_path=QA/f'rc52_{name}_static_qa.pdf'; base=QA/f'rc52_{name}_static_qa'
    html_path.write_text(html,encoding='utf-8')
    import weasyprint
    weasyprint.HTML(string=html,base_url=str(ROOT)).write_pdf(str(pdf_path))
    subprocess.run(['pdftoppm','-png','-singlefile',str(pdf_path),str(base)],check=True)
for v in views: render(*v)
report={'version':'rc52','scope':'Video / Screen Pose Capture Lab in Testcenter','runtimeChanged':False,'tool':'tools/video_screen_pose_capture_lab.html','route':'#testcenter','screenshots':['rc52_mobile_static_qa.png','rc52_ipad_static_qa.png','rc52_desktop_static_qa.png']}
(QA/'rc52_static_qa_report.json').write_text(json.dumps(report,indent=2,ensure_ascii=False),encoding='utf-8')
print(json.dumps(report,indent=2))
