from PIL import Image, ImageDraw, ImageFont
import pathlib,sys,textwrap
root=pathlib.Path(sys.argv[1]); side=sys.argv[2]; sha=sys.argv[3]
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',30)
for state in ['unviewed','viewed']:
    shot=Image.open(root/(state+'.png')).convert('RGB')
    tree=(root/(state+'.txt')).read_text()
    row=next(l.split('"')[1] for l in tree.splitlines() if 'View diff for docs/internals/14_i18n.md,' in l)
    canvas=Image.new('RGB',(shot.width,shot.height+310),'#101828'); canvas.paste(shot,(0,0))
    d=ImageDraw.Draw(canvas)
    lines=[f'{side} {sha} | Pixel 9 / Android 36 / English / light',f'Accessibility tree capture ({state}):']+textwrap.wrap(row,62)
    d.multiline_text((30,shot.height+25),'\n'.join(lines),font=font,fill='white',spacing=12)
    canvas.save(root/(state+'-annotated.png'))
