#!/usr/bin/env python3
"""Build five original A4 vector aids with selectable PDF text."""
import subprocess
from html import escape
from pathlib import Path

P=Path(__file__).resolve().parent
INK='#1b2e36';BLUE='#214d67';GREEN='#1b655b';AMBER='#925020';BG='#faf9f3'
def t(x,y,s,z=18,w=400,c=INK):return f'<text x="{x}" y="{y}" font-family="DejaVu Sans" font-size="{z}" font-weight="{w}" fill="{c}">{escape(str(s))}</text>'
def r(x,y,w,h,c=BLUE,fill='white'):return f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="11" fill="{fill}" stroke="{c}" stroke-width="2"/>'
def l(x,y,X,Y,c=BLUE,w=2):return f'<line x1="{x}" y1="{y}" x2="{X}" y2="{Y}" stroke="{c}" stroke-width="{w}"/>'
def emit(stem,title,subtitle,desc,body):
 svg='\n'.join(['<svg xmlns="http://www.w3.org/2000/svg" width="210mm" height="297mm" viewBox="0 0 794 1123" role="img" aria-labelledby="title description">',f'<title id="title">{escape(title)}</title><desc id="description">{escape(desc)}</desc>',r(0,0,794,1123,BG,BG),r(35,31,724,10,GREEN,GREEN),t(43,91,title,28,700,BLUE),t(43,123,subtitle,15),body,l(43,1064,751,1064,'#bac7c4',1),t(43,1090,'SubjectNest · Year 10 · invented paper case · A4',13,400,BLUE),'</svg>'])
 path=P/(stem+'.svg');path.write_text(svg,encoding='utf8');subprocess.run(['rsvg-convert','-f','pdf','-o',str(P/(stem+'.pdf')),str(path)],check=True)

b=[r(44,163,706,666),t(58,214,'Pattern family',17,700),t(315,214,'Pass',17,700),t(472,214,'Redraw',17,700),t(631,214,'Total',17,700)]
for i,name in enumerate(['Hatch','Ring','Solid','All paper mock-ups']):
 y=313+i*123;b += [l(56,y+34,736,y+34,'#aebfbe',1),t(62,y,name,19,700,GREEN if name=='Solid' else BLUE),t(331,y,'____',18),t(494,y,'____',18),t(641,y,'____',18)]
b += [r(44,855,706,163,AMBER),t(62,899,'Count in two directions',19,700,AMBER),t(62,942,'Pass + redraw = all. Row totals = all.',16),t(62,977,'A pass means only the internal paper-border check.',16)]
emit('full-register','COMPLETE REGISTER','Source B · 48 invented paper mock-ups · fill every cell and margin.','Blank two-way table with rows Hatch, Ring, Solid, All paper mock-ups; columns Pass, Redraw, Total.','\n'.join(b))

b=[r(44,165,706,340,BLUE),t(63,211,'FRAME 1  ·  ALL PAPER TILES',22,700,BLUE),t(63,255,'Hatch + Ring + Solid',18),t(63,307,'Passed ____     of all ____     = ____ %',20,700),t(63,369,'Included rows: Hatch, Ring, Solid',17),t(63,419,'What was observed? One fictional desk print check.',16),r(44,527,706,344,GREEN),t(63,573,'FRAME 2  ·  SELECTED FAMILIES',22,700,GREEN),t(63,617,'Hatch + Ring only; Solid omitted',18),t(63,669,'Passed ____     of selected ____     = ____ %',20,700),t(63,731,'Which source cells changed? None.',17),t(63,781,'Why can the second frame not stand for all tiles?',16),t(57,959,'A changed denominator is a changed question.',19,700,AMBER)]
emit('denominator-mat','DENOMINATOR WINDOWS','Move the category boundary; keep the fictional source cells fixed.','Two large frames: all Hatch Ring Solid, then selected Hatch Ring only, with blank pass and denominator slots.','\n'.join(b))

b=[]
for i,(title,lines) in enumerate([
 ('QUESTION + RULE',['What exactly counts as a border pass?','Write the 5 mm rule before seeing results.']),
 ('RECORD CONTROLS',['Print file, paper stock, setting, orientation.','Name and label each mock-up.']),
 ('INDEPENDENT CHECK',['Second reviewer uses same written rule.','Keep disagreements visible, do not erase them.']),
 ('OBSERVED OR PROPOSED?',['Old fictional register: supplied source only.','New result from your plan: NOT OBSERVED.'])]):
 y=165+i*204;c=[BLUE,GREEN,AMBER,BLUE][i];b += [r(44,y,706,184,c),t(62,y+40,title,20,700,c),t(62,y+84,lines[0],17),t(62,y+124,lines[1],17)]
emit('method-mat','METHOD / EVIDENCE MAT','A clear protocol is a plan until someone actually follows it.','Four stacked boxes for predeclared rule, recorded controls, independent check and observed-versus-proposed status.','\n'.join(b))

b=[r(44,163,706,386,AMBER),t(62,206,'DRAFT SPOTLIGHT  ·  first glance',20,700,AMBER),t(61,292,'64%',63,700,AMBER),t(62,337,'READY FOR PUBLIC DISPLAY',20,700),t(62,391,'Small caption: 23 of 36 selected Hatch/Ring tiles',15),t(62,427,'passed a fictional paper-border check.',15),t(62,475,'Missing from panel: Solid row and visitor evidence.',16),r(44,567,706,398,GREEN),t(62,610,'DRAFT FULL REGISTER  ·  first glance',20,700,GREEN),t(62,666,'25 of 48 paper mock-ups',27,700,GREEN),t(62,704,'passed the single-print border check (≈52.1%).',18),t(62,754,'Hatch/Ring subgroup: 23/36 (≈63.9%).',17),t(62,795,'Solid: 2/12. No visitor or accessibility test.',17),t(62,845,'Decision: consider another documented paper check.',17),t(62,925,'Which arrangement keeps the limit where readers first look?',16,700,BLUE)]
emit('layout-contrast','TWO WAYS TO FRAME ONE SOURCE','Original fictional layout drafts for a visual hierarchy critique.','Two stacked contrasting report panels: top foregrounds 64 percent and public-display claim, bottom foregrounds 25 of 48 and visible limits.','\n'.join(b))

b=[r(44,163,706,388,BLUE),t(62,205,'PANEL ONE  ·  FULL SOURCE',21,700,BLUE),t(62,251,'Paper-border result: ____ of ____',19),t(62,286,'What exactly passed? Which table?',16),l(63,322,730,322,'#aebfbe',1),l(63,376,730,376,'#aebfbe',1),l(63,430,730,430,'#aebfbe',1),l(63,484,730,484,'#aebfbe',1),r(44,568,706,389,GREEN),t(62,610,'PANEL TWO  ·  DECISION + CHECK',21,700,GREEN),t(62,653,'Subgroup if needed: ____ of ____',18),t(62,690,'Method limit + next paper action + who does it',16),l(63,730,730,730,'#aebfbe',1),l(63,783,730,783,'#aebfbe',1),l(63,836,730,836,'#aebfbe',1),l(63,889,730,889,'#aebfbe',1),t(51,1000,'No panel may imply public approval or tested access.',16,700,AMBER)]
emit('two-panel-brief','EDITOR BRIEF CANVAS','Create an original visual report; this page is a scaffold, not a finished artwork.','Two blank high-contrast panels for full-source result and a separate decision/next paper check.','\n'.join(b))
