"""Structural readability check of a returned deck: slide size, shapes per slide, smallest font, empty placeholders,
boxes whose text likely overflows (rough chars-per-area estimate), and whether charts/pictures are present."""
import sys
from pptx import Presentation
from pptx.util import Emu
prs = Presentation(sys.argv[1])
W, H = prs.slide_width, prs.slide_height
print(f"slide size: {Emu(W).inches:.2f} x {Emu(H).inches:.2f} in")
for i, s in enumerate(prs.slides, 1):
    shapes = list(s.shapes); charts = sum(1 for sh in shapes if getattr(sh,'has_chart',False) and sh.has_chart)
    pics = sum(1 for sh in shapes if sh.shape_type == 13)
    empty = [sh.name for sh in shapes if sh.is_placeholder and sh.has_text_frame and not sh.text_frame.text.strip()]
    fonts=set(); risky=[]
    for sh in shapes:
        if not sh.has_text_frame or not sh.text_frame.text.strip(): continue
        for p in sh.text_frame.paragraphs:
            for r in p.runs:
                if r.font.size: fonts.add(round(r.font.size.pt))
        if sh.width and sh.height:
            area = Emu(sh.width).inches * Emu(sh.height).inches
            chars = len(sh.text_frame.text)
            size = max([r.font.size.pt for p in sh.text_frame.paragraphs for r in p.runs if r.font.size] or [18])
            cap = area * (1400 / (size/12)**2)   # ~1400 chars per sq in at 12 pt, scaled
            if chars > cap * 1.15: risky.append((sh.name, chars, int(cap), size))
        off = sh.left < 0 or sh.top < 0 or (sh.left+sh.width) > W*1.01 or (sh.top+sh.height) > H*1.01
        if off: risky.append((sh.name, 'off-slide'))
    print(f"slide {i}: {len(shapes)} shapes, {charts} charts, {pics} pictures, fonts {sorted(fonts)}, empty placeholders {empty}, risky {risky}")
