#!/usr/bin/env python3
"""Create the Lynch Vow Renewal Ceremony plan document."""

from docx import Document
from docx.shared import Pt, Inches, RGBColor, Cm
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT
from docx.oxml.ns import qn, nsdecls
from docx.oxml import parse_xml
import os

doc = Document()

# ── Page setup ──
for section in doc.sections:
    section.top_margin = Inches(1)
    section.bottom_margin = Inches(0.75)
    section.left_margin = Inches(1.2)
    section.right_margin = Inches(1.2)

# ── Style defaults ──
style = doc.styles['Normal']
font = style.font
font.name = 'Calibri'
font.size = Pt(11)
font.color.rgb = RGBColor(0x33, 0x33, 0x33)
style.paragraph_format.space_after = Pt(4)
style.paragraph_format.space_before = Pt(2)
style.paragraph_format.line_spacing = 1.15

# ── Colors ──
NAVY = RGBColor(0x1B, 0x3A, 0x5C)
GOLD = RGBColor(0xC4, 0x9A, 0x3C)
DARK = RGBColor(0x2C, 0x2C, 0x2C)
MEDIUM = RGBColor(0x55, 0x55, 0x55)
LIGHT_GRAY = RGBColor(0x99, 0x99, 0x99)

def add_decorative_line(color=GOLD, width=4.5):
    """Add a thin decorative horizontal line."""
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.CENTER
    pPr = p._p.get_or_add_pPr()
    pBdr = parse_xml(
        f'<w:pBdr {nsdecls("w")}>'
        f'  <w:bottom w:val="single" w:sz="{int(width*2)}" w:space="1" w:color="{str(color).replace('#','')}"/>'
        f'</w:pBdr>'
    )
    pPr.append(pBdr)
    p.paragraph_format.space_after = Pt(8)
    return p

def add_title_text(text, size=28, color=NAVY, bold=True, spacing_after=2):
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.CENTER
    run = p.add_run(text)
    run.font.name = 'Calibri'
    run.font.size = Pt(size)
    run.font.color.rgb = color
    run.bold = bold
    p.paragraph_format.space_after = Pt(spacing_after)
    p.paragraph_format.space_before = Pt(0)
    return p

def add_section_heading(text):
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.LEFT
    run = p.add_run(text)
    run.font.name = 'Calibri'
    run.font.size = Pt(16)
    run.font.color.rgb = NAVY
    run.bold = True
    p.paragraph_format.space_before = Pt(20)
    p.paragraph_format.space_after = Pt(6)
    # Add underline bar
    add_decorative_line(GOLD, 2)
    return p

def add_body(text, bold=False, italic=False, indent=0, size=11, color=DARK, spacing_after=4):
    p = doc.add_paragraph()
    run = p.add_run(text)
    run.font.name = 'Calibri'
    run.font.size = Pt(size)
    run.font.color.rgb = color
    run.bold = bold
    run.italic = italic
    if indent:
        p.paragraph_format.left_indent = Inches(indent)
    p.paragraph_format.space_after = Pt(spacing_after)
    return p

def add_timeline_item(time_text, desc):
    p = doc.add_paragraph()
    p.paragraph_format.left_indent = Inches(0.3)
    p.paragraph_format.space_after = Pt(6)
    run_time = p.add_run(time_text)
    run_time.font.name = 'Calibri'
    run_time.font.size = Pt(11)
    run_time.font.color.rgb = GOLD
    run_time.bold = True
    run_sep = p.add_run("  —  ")
    run_sep.font.name = 'Calibri'
    run_sep.font.size = Pt(11)
    run_sep.font.color.rgb = LIGHT_GRAY
    run_desc = p.add_run(desc)
    run_desc.font.name = 'Calibri'
    run_desc.font.size = Pt(11)
    run_desc.font.color.rgb = DARK
    return p

def add_bullet(text, indent=0.5, bold_prefix=None):
    p = doc.add_paragraph()
    p.paragraph_format.left_indent = Inches(indent)
    p.paragraph_format.space_after = Pt(3)
    if bold_prefix:
        run_b = p.add_run(bold_prefix)
        run_b.font.name = 'Calibri'
        run_b.font.size = Pt(11)
        run_b.font.color.rgb = DARK
        run_b.bold = True
        run_t = p.add_run(text)
        run_t.font.name = 'Calibri'
        run_t.font.size = Pt(11)
        run_t.font.color.rgb = DARK
    else:
        run = p.add_run("•  " + text)
        run.font.name = 'Calibri'
        run.font.size = Pt(11)
        run.font.color.rgb = DARK
    return p

# ═══════════════════════════════════════════════
# DOCUMENT CONTENT
# ═══════════════════════════════════════════════

# Spacer
doc.add_paragraph().paragraph_format.space_after = Pt(20)

# Title
add_title_text("Lynch Vow Renewal Ceremony", size=30, color=NAVY)
add_title_text("April 3, 2026", size=18, color=GOLD, bold=False, spacing_after=8)
add_decorative_line(GOLD, 3)
add_title_text("Isle of Palms Beach, South Carolina", size=14, color=MEDIUM, bold=False, spacing_after=2)
add_title_text("Sunset  ~7:15 PM", size=12, color=LIGHT_GRAY, bold=False, spacing_after=12)

# Spacer
doc.add_paragraph().paragraph_format.space_after = Pt(6)

# ── SECTION 1: CEREMONY TIMELINE ──
add_section_heading("Ceremony Timeline")

timeline = [
    ("6:45 PM", "Family gathers on beach"),
    ("6:50 PM", 'Music begins: "Ain\u2019t No Mountain High Enough" instrumental loop (0:00\u20131:21, 10-minute loop)'),
    ("6:55 PM", "Joe and Keli walk to minister as music plays"),
    ("7:00 PM", "Minister welcomes the family"),
    ("7:05 PM", "Minister\u2019s words (see speech below)"),
    ("7:10 PM", "Joe reads his vows"),
    ("7:15 PM", "Keli reads her vows"),
    ("7:18 PM", "The kiss"),
    ("7:18 PM", "Music plays: upbeat section (2:25 to end) \u2014 Joe and Keli dance"),
    ("7:20 PM", "Walk back to house \u2014 Spotify playlist plays"),
]

for time, desc in timeline:
    add_timeline_item(time, desc)

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(10)
run = p.add_run("Wedding over... let\u2019s eat!")
run.font.name = 'Calibri'
run.font.size = Pt(13)
run.font.color.rgb = GOLD
run.bold = True
run.italic = True

# ── SECTION 2: MUSIC TRACKS ──
add_section_heading("Music Tracks (Ready to Play)")

add_body("Track 1 \u2014 Walk to Minister (10-Minute Loop)", bold=True, size=12, color=NAVY, spacing_after=2)
add_bullet("Ain\u2019t No Mountain High Enough \u2014 Marvin Gaye & Tammi Terrell", bold_prefix="Song:  ")
add_bullet("Opening instrumental (0:00\u20131:21), seamlessly looped for 10 minutes", bold_prefix="Section:  ")
add_bullet("walk-to-minister-10min.mp3", bold_prefix="File:  ")

doc.add_paragraph().paragraph_format.space_after = Pt(4)

add_body("Track 2 \u2014 After the Kiss Dance", bold=True, size=12, color=NAVY, spacing_after=2)
add_bullet("Ain\u2019t No Mountain High Enough \u2014 Marvin Gaye & Tammi Terrell", bold_prefix="Song:  ")
add_bullet("Upbeat portion (2:25 to end)", bold_prefix="Section:  ")
add_bullet("after-the-kiss-dance.mp3", bold_prefix="File:  ")

# ── SECTION 3: MINISTER'S SPEECH ──
add_section_heading("Minister\u2019s Speech")

speech_paragraphs = [
    "Welcome, everyone. Welcome to this beach, this sunset, and this moment that belongs to all of you.",

    "We\u2019re here tonight because twenty-three years ago, something extraordinary happened \u2014 and it started in the most ordinary way. A blind date. Triumph Brewery in Princeton, New Jersey. Joe showed up... and he brought his brother Pete along, just in case things went sideways.",

    "He never needed the safety net.",

    "From that very first evening, Joe and Keli knew. There was something there \u2014 something real, something that couldn\u2019t be explained over a pint of craft beer but didn\u2019t need to be. It just was. And twenty-three years later, here they stand \u2014 not at the beginning of their story, but deep in the middle of it, surrounded by the three most beautiful chapters they\u2019ve written together: Danielle, Juliana, and Isabella.",

    "Girls, I want to talk to you for a moment.",

    "You\u2019ve been hearing a song today \u2014 \u201cAin\u2019t No Mountain High Enough.\u201d You probably know it as Mom and Dad\u2019s wedding song. But tonight, that changes. Tonight, that song stops belonging to just two people and starts belonging to all five of you.",

    "Listen to those lyrics \u2014 really listen. \u201cNo mountain high enough, no valley low enough, no river wide enough to keep me from getting to you.\u201d That\u2019s not just a love song between a husband and wife. That is a promise from your parents to you. It means: there is nothing in this world \u2014 no distance, no obstacle, no hardship \u2014 that will ever keep them from showing up for you. Their advocacy. Their protection. Their love. For eternity.",

    "That\u2019s what these vows are about tonight. Not just the renewal of a marriage, but the renewal of a promise to this whole family. Mom and Dad are standing here on this beach, with sand between their toes and the ocean behind them, telling you \u2014 and telling each other \u2014 that they\u2019re all in. They always have been. They always will be.",

    "This song belongs to all of you now.",

    "So, Joe and Keli \u2014 with your daughters beside you, the sun setting over the water, and twenty-three years of proof that you got it right... let\u2019s hear those vows."
]

for i, para in enumerate(speech_paragraphs):
    italic = (para == "He never needed the safety net." or 
              para == "This song belongs to all of you now." or
              para == "Girls, I want to talk to you for a moment.")
    spacing = 8 if i < len(speech_paragraphs) - 1 else 4
    p = add_body(para, italic=italic, indent=0.2, spacing_after=spacing)
    p.paragraph_format.line_spacing = 1.3

# ── SECTION 4: WALK-BACK PLAYLIST ──
add_section_heading("Walk-Back Playlist (Spotify)")

add_body("Walking back home from the beach \u2014 barefoot, happy, married all over again.", italic=True, color=MEDIUM, spacing_after=10)

# Jack Johnson
add_body("Jack Johnson", bold=True, size=12, color=NAVY, spacing_after=2)
jj_songs = ["Better Together", "Banana Pancakes", "Upside Down", "Sitting, Waiting, Wishing", "Flake"]
for i, s in enumerate(jj_songs, 1):
    add_bullet(f"{i}.  {s}", indent=0.5)

doc.add_paragraph().paragraph_format.space_after = Pt(4)

# Zach Bryan
add_body("Zach Bryan", bold=True, size=12, color=NAVY, spacing_after=2)
zb_songs = ["Something in the Orange", "I Remember Everything (feat. Kacey Musgraves)", "Heading South", "Sun to Me", "Pink Skies"]
for i, s in enumerate(zb_songs, 1):
    add_bullet(f"{i}.  {s}", indent=0.5)

doc.add_paragraph().paragraph_format.space_after = Pt(4)

# Zac Brown Band
add_body("Zac Brown Band", bold=True, size=12, color=NAVY, spacing_after=2)
zbb_songs = ["Chicken Fried", "Toes", "Knee Deep (feat. Jimmy Buffett)", "Colder Weather", "Free"]
for i, s in enumerate(zbb_songs, 1):
    add_bullet(f"{i}.  {s}", indent=0.5)

doc.add_paragraph().paragraph_format.space_after = Pt(6)
add_body("Suggested play order: mix the artists, alternate for variety. Or just shuffle all 15.", italic=True, color=MEDIUM, indent=0.2)

# ── SECTION 5: LOGISTICS NOTES ──
add_section_heading("Logistics Notes")

logistics = [
    "Download all 3 music files to Joe\u2019s phone before heading to the beach",
    "Test Bluetooth speaker volume on the beach beforehand",
    "Sunset on April 3 in Isle of Palms: approx 7:23 PM \u2014 ceremony should start by 7:00 PM",
    "Backup: if weather is bad, ceremony can move to the rental house deck at 806 Carolina Blvd",
]

for item in logistics:
    add_bullet(item, indent=0.3)

# ── FOOTER ──
doc.add_paragraph().paragraph_format.space_after = Pt(30)
add_decorative_line(GOLD, 2)

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(6)
run = p.add_run("Planned with love by Rob Lobster \U0001f99e for Joe and Keli Lynch")
run.font.name = 'Calibri'
run.font.size = Pt(10)
run.font.color.rgb = LIGHT_GRAY
run.italic = True

p2 = doc.add_paragraph()
p2.alignment = WD_ALIGN_PARAGRAPH.CENTER
run2 = p2.add_run("March 30, 2026")
run2.font.name = 'Calibri'
run2.font.size = Pt(10)
run2.font.color.rgb = LIGHT_GRAY
run2.italic = True

# ── SAVE ──
output_path = "/Users/joemac/.openclaw/workspace/projects/ceremony/ceremony-plan.docx"
doc.save(output_path)
print(f"Document saved to {output_path}")
print(f"File size: {os.path.getsize(output_path):,} bytes")
