#!/usr/bin/env python3
"""Render five original A4 write-on diagrams for fictional General Mathematics cards."""
import subprocess
from html import escape
from pathlib import Path

P=Path(__file__).resolve().parent
INK='#19323b'; BLUE='#204f70'; GREEN='#11665b'; ORANGE='#8a4d1f'; PAPER='#fcfaf4'

def t(x,y,s,size=18,bold=400,colour=INK):
    return f'<text x="{x}" y="{y}" font-family="DejaVu Sans" font-size="{size}" font-weight="{bold}" fill="{colour}">{escape(str(s))}</text>'
def b(x,y,w,h,stroke=BLUE,fill='white'):
    return f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="10" fill="{fill}" stroke="{stroke}" stroke-width="2"/>'
def l(x,y,X,Y,colour=BLUE,width=2):
    return f'<line x1="{x}" y1="{y}" x2="{X}" y2="{Y}" stroke="{colour}" stroke-width="{width}"/>'
def emit(stem,title,subtitle,desc,parts):
    body='\n'.join(['<svg xmlns="http://www.w3.org/2000/svg" width="210mm" height="297mm" viewBox="0 0 794 1123" role="img" aria-labelledby="title desc">',f'<title id="title">{escape(title)}</title><desc id="desc">{escape(desc)}</desc>',b(0,0,794,1123,PAPER,PAPER),b(35,30,724,11,GREEN,GREEN),t(43,91,title,29,700,BLUE),t(43,126,subtitle,15),*parts,l(43,1057,751,1057,'#bdc9c7',1),t(43,1086,'SubjectNest · Year 11 General Mathematics · all values invented · A4',12,400,BLUE),'</svg>'])
    svg=P/(stem+'.svg');svg.write_text(body,encoding='utf8')
    subprocess.run(['rsvg-convert','-f','pdf','-o',str(P/(stem+'.pdf')),str(svg)],check=True)

v=[b(44,164,706,358,BLUE),t(63,208,'CARD H · RATE FOR EACH HOUR BAND',20,700,BLUE),t(63,258,'REGULAR: 8 hours × $28/hour = __________',19),t(63,316,'ADDITIONAL RATE: $28/hour × 1.5 = __________',18),t(63,374,'ADDITIONAL: 2 hours × new rate = __________',18),t(63,441,'GROSS MODEL TOTAL = __________',22,700),b(44,543,706,402,GREEN),t(63,587,'CARD I · ADD AN ALLOWANCE ONCE',20,700,GREEN),t(63,638,'REGULAR: 6 hours × $31/hour = __________',18),t(63,689,'ADDITIONAL: 2 hours × (1.25 × $31/hour) = ______',17),t(63,739,'ONE-SHIFT ALLOWANCE: $24',17),t(63,801,'GROSS MODEL TOTAL = __________',22,700),t(63,868,'Label each amount as per hour or once per shift.',16),t(54,1006,'These model multipliers are not real legal pay rates.',16,700,ORANGE)]
emit('wage-layers','WAGE LAYERS','Cards H–I · attach each multiplier and count to the right rate.','Two large boxed fictional wage models: regular hours, additional hours, once-only allowance and blank totals.',v)

v=[b(44,166,706,340,BLUE),t(62,208,'MARK-UP: COST IS THE BASE',21,700,BLUE),t(62,262,'Card J: cost $80 · mark-up 25% on cost',18),t(62,322,'$80 × 0.25 = gap $__________',20),t(62,382,'cost + gap = price $__________',20),t(62,449,'Reverse check: price − cost = gap',17),b(44,527,706,411,GREEN),t(62,572,'ONE GAP, TWO DENOMINATORS',21,700,GREEN),t(62,622,'Card K: cost $72 · price $90 · gap $18',18),t(62,685,'Mark-up = $18 ÷ $72 × 100 = ______%',18),t(62,740,'Margin = $18 ÷ $90 × 100 = ______%',18),t(62,811,'Mark each denominator before calculating.',17),t(62,868,'Other expenses and tax are unknown.',16),t(54,998,'A price gap is not proven net profit.',17,700,ORANGE)]
emit('markup-margin','TWO PERCENTAGE BASES','Cards J–K · cost for mark-up; selling price for margin.','A top mark-up-on-cost box and a lower mark-up-versus-margin box with distinct denominators and blanks.',v)

v=[b(44,163,706,173,BLUE),t(62,208,'FICTIONAL FIGURES · NOT INFLATION DATA',19,700,BLUE),t(62,263,'Version 1: $125         Version 2: $137.50',20),b(44,361,706,267,GREEN),t(62,408,'FORWARD: $125 → $137.50',21,700,GREEN),t(62,464,'Difference $______ ÷ starting $125 × 100',18),t(62,520,'Percentage increase = ______%',19),t(62,576,'Reverse check: original × (1 + rate) = new',16),b(44,651,706,264,ORANGE),t(62,698,'RETURN: $137.50 → $125',21,700,ORANGE),t(62,754,'Difference $______ ÷ starting $137.50 × 100',18),t(62,810,'Percentage decrease ≈ ______%',19),t(62,867,'Same dollar difference; a different starting base.',16),t(54,1004,'Underline “from” before choosing a percentage denominator.',15,700,ORANGE)]
emit('change-ladder','CHANGE LADDER','Card L · the denominator is the value you start from.','Two large directional boxes compare the forward and return percentage change between invented $125 and $137.50.',v)

v=[b(44,160,706,158,BLUE),t(62,208,'STIPULATED EXERCISE RATE',19,700,BLUE),t(62,261,'AUD $1 = USD $0.64 · no fees or spread',21),b(44,344,706,267,GREEN),t(62,390,'AUD → USD : MULTIPLY BY 0.64',20,700,GREEN),t(62,454,'AUD $250 × 0.64 = USD $__________',21),t(62,524,'Reverse: USD result ÷ 0.64 = AUD $__________',17),b(44,633,706,278,ORANGE),t(62,680,'USD → AUD : DIVIDE BY 0.64',20,700,ORANGE),t(62,744,'USD $96 ÷ 0.64 = AUD $__________',21),t(62,814,'Reverse: AUD result × 0.64 = USD $__________',17),t(54,994,'Fictional rate only · not a quote · real fees/rates unknown.',16,700,ORANGE)]
emit('exchange-directions','EXCHANGE DIRECTIONS','Card M · label the source and target currency before the operation.','Two directional AUD and USD conversion panels based on a clearly fictional stipulated rate, with reverse-check blanks.',v)

v=[b(44,160,706,432,BLUE),t(62,204,'DIVIDEND DOLLARS VERSUS YIELD',20,700,BLUE),t(62,251,'Card N1: $24/share · $0.84 annual dividend/share',17),t(62,298,'Portfolio: 50 shares',17),t(62,351,'Annual dividend dollars: 50 × $0.84 = $______',18),t(62,405,'Yield: $0.84 ÷ $24 × 100 = ______%',18),t(62,465,'Match one-share dividend to one-share price.',16),t(62,525,'No future payout or return is guaranteed.',16),b(44,614,706,315,GREEN),t(62,660,'PRICE-TO-EARNINGS RATIOS',20,700,GREEN),t(62,715,'Cedar: $30 price ÷ $2 annual EPS = ______',17),t(62,772,'Slate: $36 price ÷ $3 annual EPS = ______',17),t(62,836,'P/E is a ratio, not a percentage.',17),t(54,1004,'A single measure cannot recommend a share purchase.',15,700,ORANGE)]
emit('share-measures','SHARE MEASURES','Card N · per-share amounts, portfolio totals and P/E are distinct.','Dividend dollar/yield formulas and two price-to-earnings calculations for fictional companies, with blank answers.',v)
