"""Embed screenshots into the DOCX — no heading styles needed."""

from docx import Document
from docx.shared import Inches, Pt, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
import os

DOCX_PATH = "/tmp/nur-falah-docx/Nur-Falah-App-Store-Submission.docx"
SCREENSHOTS_DIR = "/tmp/nur-falah-docx/appstore-assets/screenshots"

doc = Document(DOCX_PATH)

doc.add_page_break()

# Use formatted paragraph instead of heading (avoids missing style errors)
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.LEFT
run = p.add_run("Appendix: App Store Screenshots")
run.bold = True
run.font.size = Pt(18)
run.font.color.rgb = RGBColor(0xC9, 0xA8, 0x4C)
p_fmt = p.paragraph_format
p_fmt.space_before = Pt(24)
p_fmt.space_after = Pt(12)
p_fmt.keep_with_next = True

screenshots = [
    ("1-6.7-prayer-times.png", "Screenshot 1: Prayer Times — Accurate prayer schedules with 5 calculation methods"),
    ("2-6.7-qibla-finder.png", "Screenshot 2: Qibla Finder — Find the Qibla from anywhere in the world"),
    ("3-6.7-holy-quran.png", "Screenshot 3: Holy Quran — All 114 surahs with Arabic names"),
    ("4-6.7-99-names.png", "Screenshot 4: 99 Names of Allah — Study Asma-ul-Husna with search"),
    ("5-6.7-tasbih-counter.png", "Screenshot 5: Tasbih Counter — Digital dhikr counter"),
    ("6-6.7-hijri-calendar.png", "Screenshot 6: Hijri Calendar — Islamic date with Gregorian conversion"),
]

for filename, caption in screenshots:
    img_path = os.path.join(SCREENSHOTS_DIR, filename)
    if not os.path.exists(img_path):
        print(f"  ⚠️  Missing: {filename}")
        continue
    
    cap = doc.add_paragraph()
    cap.alignment = WD_ALIGN_PARAGRAPH.CENTER
    r = cap.add_run(caption)
    r.font.size = Pt(10)
    r.font.italic = True
    r.font.color.rgb = RGBColor(0x66, 0x66, 0x66)
    
    img_par = doc.add_paragraph()
    img_par.alignment = WD_ALIGN_PARAGRAPH.CENTER
    img_par.add_run().add_picture(img_path, width=Inches(3.5))
    doc.add_paragraph()

doc.save(DOCX_PATH)
print(f"✅ Updated: {DOCX_PATH}")
