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

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

# Colors
NAVY = RGBColor(0x00, 0x2B, 0x5C)
GOLD = RGBColor(0xC5, 0x9E, 0x3C)
DARK_GOLD = RGBColor(0xA0, 0x7E, 0x2E)
LIGHT_GRAY = RGBColor(0x4A, 0x4A, 0x4A)
WHITE = RGBColor(0xFF, 0xFF, 0xFF)

doc = Document()

# -- Page margins --
for section in doc.sections:
    section.top_margin = Inches(0.8)
    section.bottom_margin = Inches(0.8)
    section.left_margin = Inches(1.0)
    section.right_margin = Inches(1.0)

# -- Style defaults --
style = doc.styles['Normal']
font = style.font
font.name = 'Calibri'
font.size = Pt(11)
font.color.rgb = LIGHT_GRAY

# ============================================================
# HELPER FUNCTIONS
# ============================================================

def add_gold_divider(doc):
    """Add a centered gold divider line using a series of decorative characters."""
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.CENTER
    p.paragraph_format.space_before = Pt(6)
    p.paragraph_format.space_after = Pt(6)
    run = p.add_run("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
    run.font.color.rgb = GOLD
    run.font.size = Pt(10)
    run.font.name = 'Calibri'

def add_thin_divider(doc):
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.CENTER
    p.paragraph_format.space_before = Pt(4)
    p.paragraph_format.space_after = Pt(4)
    run = p.add_run("· · · · · · · · · · · · · · ·")
    run.font.color.rgb = GOLD
    run.font.size = Pt(9)
    run.font.name = 'Calibri'

def add_section_heading(doc, text):
    """Add a navy blue section heading with gold accent."""
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.LEFT
    p.paragraph_format.space_before = Pt(24)
    p.paragraph_format.space_after = Pt(4)
    
    # Gold diamond accent
    accent = p.add_run("◆  ")
    accent.font.color.rgb = GOLD
    accent.font.size = Pt(12)
    accent.font.name = 'Calibri'
    
    run = p.add_run(text.upper())
    run.font.color.rgb = NAVY
    run.font.size = Pt(14)
    run.font.name = 'Calibri'
    run.bold = True
    
    # Gold line under heading
    p2 = doc.add_paragraph()
    p2.alignment = WD_ALIGN_PARAGRAPH.LEFT
    p2.paragraph_format.space_before = Pt(0)
    p2.paragraph_format.space_after = Pt(12)
    run2 = p2.add_run("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
    run2.font.color.rgb = GOLD
    run2.font.size = Pt(8)
    run2.font.name = 'Calibri'

def add_timeline_item(doc, time_str, description):
    """Add a timeline entry with gold time and navy description."""
    p = doc.add_paragraph()
    p.paragraph_format.space_before = Pt(3)
    p.paragraph_format.space_after = Pt(3)
    p.paragraph_format.left_indent = Inches(0.3)
    
    time_run = p.add_run(time_str)
    time_run.font.color.rgb = GOLD
    time_run.font.size = Pt(11)
    time_run.font.name = 'Calibri'
    time_run.bold = True
    
    sep = p.add_run("  —  ")
    sep.font.color.rgb = LIGHT_GRAY
    sep.font.size = Pt(11)
    sep.font.name = 'Calibri'
    
    desc = p.add_run(description)
    desc.font.color.rgb = LIGHT_GRAY
    desc.font.size = Pt(11)
    desc.font.name = 'Calibri'

def add_bullet(doc, text, indent=0.5, bold_prefix=None):
    """Add a styled bullet point."""
    p = doc.add_paragraph()
    p.paragraph_format.space_before = Pt(2)
    p.paragraph_format.space_after = Pt(2)
    p.paragraph_format.left_indent = Inches(indent)
    
    bullet = p.add_run("▸  ")
    bullet.font.color.rgb = GOLD
    bullet.font.size = Pt(10)
    bullet.font.name = 'Calibri'
    
    if bold_prefix:
        bp = p.add_run(bold_prefix)
        bp.font.color.rgb = NAVY
        bp.font.size = Pt(11)
        bp.font.name = 'Calibri'
        bp.bold = True
        
        rest = p.add_run(text)
        rest.font.color.rgb = LIGHT_GRAY
        rest.font.size = Pt(11)
        rest.font.name = 'Calibri'
    else:
        run = p.add_run(text)
        run.font.color.rgb = LIGHT_GRAY
        run.font.size = Pt(11)
        run.font.name = 'Calibri'

def add_playlist_item(doc, number, song, artist, note=None):
    """Add a numbered playlist entry."""
    p = doc.add_paragraph()
    p.paragraph_format.space_before = Pt(2)
    p.paragraph_format.space_after = Pt(2)
    p.paragraph_format.left_indent = Inches(0.5)
    
    num_run = p.add_run(f"{number}.  ")
    num_run.font.color.rgb = GOLD
    num_run.font.size = Pt(11)
    num_run.font.name = 'Calibri'
    num_run.bold = True
    
    song_run = p.add_run(f'"{song}"')
    song_run.font.color.rgb = NAVY
    song_run.font.size = Pt(11)
    song_run.font.name = 'Calibri'
    song_run.bold = True
    
    artist_run = p.add_run(f"  —  {artist}")
    artist_run.font.color.rgb = LIGHT_GRAY
    artist_run.font.size = Pt(11)
    artist_run.font.name = 'Calibri'
    
    if note:
        note_run = p.add_run(f"  ({note})")
        note_run.font.color.rgb = DARK_GOLD
        note_run.font.size = Pt(10)
        note_run.font.name = 'Calibri'
        note_run.italic = True

def add_speech_paragraph(doc, text, italic=False):
    """Add a paragraph of speech text."""
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.LEFT
    p.paragraph_format.space_before = Pt(4)
    p.paragraph_format.space_after = Pt(4)
    p.paragraph_format.left_indent = Inches(0.5)
    p.paragraph_format.right_indent = Inches(0.5)
    
    run = p.add_run(text)
    run.font.color.rgb = LIGHT_GRAY
    run.font.size = Pt(11)
    run.font.name = 'Calibri'
    run.italic = italic

# ============================================================
# DOCUMENT CONTENT
# ============================================================

# --- TITLE ---
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(40)
p.paragraph_format.space_after = Pt(4)

# Small gold accent above title
p0 = doc.add_paragraph()
p0.alignment = WD_ALIGN_PARAGRAPH.CENTER
p0.paragraph_format.space_before = Pt(20)
p0.paragraph_format.space_after = Pt(8)
run0 = p0.add_run("✦")
run0.font.color.rgb = GOLD
run0.font.size = Pt(16)
run0.font.name = 'Calibri'

# Title
p1 = doc.add_paragraph()
p1.alignment = WD_ALIGN_PARAGRAPH.CENTER
p1.paragraph_format.space_before = Pt(0)
p1.paragraph_format.space_after = Pt(4)
title_run = p1.add_run("Lynch Vow Renewal Ceremony")
title_run.font.color.rgb = NAVY
title_run.font.size = Pt(28)
title_run.font.name = 'Calibri'
title_run.bold = True

# Date
p2 = doc.add_paragraph()
p2.alignment = WD_ALIGN_PARAGRAPH.CENTER
p2.paragraph_format.space_before = Pt(0)
p2.paragraph_format.space_after = Pt(4)
date_run = p2.add_run("April 3, 2026")
date_run.font.color.rgb = GOLD
date_run.font.size = Pt(18)
date_run.font.name = 'Calibri'

add_gold_divider(doc)

# Subtitle
p3 = doc.add_paragraph()
p3.alignment = WD_ALIGN_PARAGRAPH.CENTER
p3.paragraph_format.space_before = Pt(4)
p3.paragraph_format.space_after = Pt(8)
sub_run = p3.add_run("Isle of Palms, South Carolina  —  Sunset")
sub_run.font.color.rgb = LIGHT_GRAY
sub_run.font.size = Pt(14)
sub_run.font.name = 'Calibri'
sub_run.italic = True

# Another small accent
p4 = doc.add_paragraph()
p4.alignment = WD_ALIGN_PARAGRAPH.CENTER
p4.paragraph_format.space_before = Pt(4)
p4.paragraph_format.space_after = Pt(20)
run4 = p4.add_run("✦")
run4.font.color.rgb = GOLD
run4.font.size = Pt(16)
run4.font.name = 'Calibri'

# ============================================================
# SECTION 1: CEREMONY TIMELINE
# ============================================================
add_section_heading(doc, "Ceremony Timeline")

timeline = [
    ("7:00 PM", "Family gathers on beach, music begins (Diana Ross instrumental loop playing softly)"),
    ("7:05 PM", "Joe and Keli walk toward Neisha as music plays"),
    ("7:10 PM", "Neisha welcomes the family"),
    ("7:12 PM", "Neisha delivers the opening speech"),
    ("7:20 PM", "Neisha reads Joe's vows, then Keli's vows"),
    ("7:28 PM", "Joe and Keli exchange rings"),
    ("7:30 PM", "The kiss"),
    ("7:30 PM", 'Music plays: Diana Ross fades elegantly, Joe\'s voice intro, then Marvin Gaye & Tammi Terrell kicks in — Joe and Keli dance'),
    ("7:40 PM", "Ceremony wraps"),
    ("7:41 PM", "Pictures with the sunset and family, music playing"),
]

for time_str, desc in timeline:
    add_timeline_item(doc, time_str, desc)

add_thin_divider(doc)

# Walk back items (no specific time)
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(6)
p.paragraph_format.space_after = Pt(3)
p.paragraph_format.left_indent = Inches(0.3)
icon = p.add_run("🎵  ")
icon.font.size = Pt(11)
walk_run = p.add_run('Walk back to house — Spotify playlist (first song: "Daughters" by John Mayer)')
walk_run.font.color.rgb = LIGHT_GRAY
walk_run.font.size = Pt(11)
walk_run.font.name = 'Calibri'
walk_run.italic = True

p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(6)
p.paragraph_format.space_after = Pt(6)
p.paragraph_format.left_indent = Inches(0.3)
p.alignment = WD_ALIGN_PARAGRAPH.LEFT
eat_run = p.add_run('"Wedding over... let\'s eat!"')
eat_run.font.color.rgb = NAVY
eat_run.font.size = Pt(12)
eat_run.font.name = 'Calibri'
eat_run.bold = True
eat_run.italic = True

# ============================================================
# SECTION 2: MUSIC TRACKS
# ============================================================
add_section_heading(doc, "Music Tracks (Ready to Play)")

# Track 1
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(8)
p.paragraph_format.space_after = Pt(4)
p.paragraph_format.left_indent = Inches(0.3)
t1 = p.add_run("Track 1 — Walk to Neisha  ")
t1.font.color.rgb = NAVY
t1.font.size = Pt(12)
t1.font.name = 'Calibri'
t1.bold = True
t1note = p.add_run("(10-minute loop)")
t1note.font.color.rgb = DARK_GOLD
t1note.font.size = Pt(11)
t1note.font.name = 'Calibri'
t1note.italic = True

add_bullet(doc, '"Ain\'t No Mountain High Enough" — Diana Ross', bold_prefix="Song:  ")
add_bullet(doc, "Opening (0:00 to 1:21), seamlessly looped with smooth crossfades", bold_prefix="Section:  ")
add_bullet(doc, "diana-walk-to-minister-10min-smooth.mp3", bold_prefix="File:  ")
add_bullet(doc, "Start playing at 7:00 PM as family gathers", bold_prefix="Cue:  ")

add_thin_divider(doc)

# Track 2
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(8)
p.paragraph_format.space_after = Pt(4)
p.paragraph_format.left_indent = Inches(0.3)
t2 = p.add_run("Track 2 — After the Kiss  ")
t2.font.color.rgb = NAVY
t2.font.size = Pt(12)
t2.font.name = 'Calibri'
t2.bold = True
t2note = p.add_run("(One seamless track)")
t2note.font.color.rgb = DARK_GOLD
t2note.font.size = Pt(11)
t2note.font.name = 'Calibri'
t2note.italic = True

add_bullet(doc, "Diana Ross plays beautifully for 2:29, then elegantly fades away")
add_bullet(doc, "")

# Joe's voice quote - special formatting
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(6)
p.paragraph_format.space_after = Pt(6)
p.paragraph_format.left_indent = Inches(0.7)
p.paragraph_format.right_indent = Inches(0.5)

label = p.add_run("Joe's voice:  ")
label.font.color.rgb = NAVY
label.font.size = Pt(11)
label.font.name = 'Calibri'
label.bold = True

quote = p.add_run('"Not only can you count on me, family, to go through rivers and over mountains for you, but you can count on Marvin always to make an appearance. Hit it Marvin and Tammy."')
quote.font.color.rgb = LIGHT_GRAY
quote.font.size = Pt(11)
quote.font.name = 'Calibri'
quote.italic = True

add_bullet(doc, "Marvin Gaye & Tammi Terrell kicks in — full song")
add_bullet(doc, "ceremony-full-track.mp3", bold_prefix="File:  ")
add_bullet(doc, "Play immediately after the kiss", bold_prefix="Cue:  ")

# ============================================================
# SECTION 3: NEISHA'S OPENING SPEECH
# ============================================================
add_section_heading(doc, "Neisha's Opening Speech")

p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(4)
p.paragraph_format.space_after = Pt(8)
p.paragraph_format.left_indent = Inches(0.3)
note = p.add_run("Approximately 2–3 minutes spoken. Warm, personal, from the heart.")
note.font.color.rgb = DARK_GOLD
note.font.size = Pt(10)
note.font.name = 'Calibri'
note.italic = True

speech_paragraphs = [
    '"Good evening, everyone. Welcome.',
    'We are gathered here — with the water behind us and the sky painting itself golden — not for a beginning, but for a deepening.',
    'Twenty-three years ago, Joe Lynch walked into Triumph Brewery in Princeton, New Jersey for a blind date. And just in case things went sideways, he brought his brother Pete as a safety net.',
    'He never needed it.',
    'From that very first evening, Joe and Keli were inseparable. A trip to Montreal. Then a lifetime. Two became five — Danielle, Juliana, and Isabella, you are the living proof that what started at that brewery table was something extraordinary.',
    'Tonight is not just about the two of them. It is about all of you. Because the song you are about to hear — Ain\'t No Mountain High Enough — is not just Mom and Dad\'s wedding song anymore.',
    'Listen to those lyrics. Really listen.',
    'No mountain high enough. No valley low enough. No river wide enough to keep me from getting to you.',
    'That is not just a promise between husband and wife. That is a promise from these two people to every single one of you standing here. Mom and Dad guarantee their advocacy, their love, their protection — for eternity. With these vows and these lyrics, this song now belongs to ALL of you. It is the Lynch family anthem.',
    'And with that..."',
]

for para_text in speech_paragraphs:
    add_speech_paragraph(doc, para_text, italic=True)

add_thin_divider(doc)

# Stage direction after speech
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(8)
p.paragraph_format.space_after = Pt(4)
p.paragraph_format.left_indent = Inches(0.5)
run = p.add_run("Then Neisha reads Joe's vows, then Keli's vows. Joe and Keli exchange rings.")
run.font.color.rgb = NAVY
run.font.size = Pt(11)
run.font.name = 'Calibri'
run.italic = True

# Note to Neisha
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(12)
p.paragraph_format.space_after = Pt(4)
p.paragraph_format.left_indent = Inches(0.5)

note_label = p.add_run("Note to Neisha:  ")
note_label.font.color.rgb = GOLD
note_label.font.size = Pt(11)
note_label.font.name = 'Calibri'
note_label.bold = True

note_text = p.add_run("Joe and Keli will provide their written vows to you before the ceremony.")
note_text.font.color.rgb = LIGHT_GRAY
note_text.font.size = Pt(11)
note_text.font.name = 'Calibri'
note_text.italic = True

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

p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(4)
p.paragraph_format.space_after = Pt(12)
p.paragraph_format.left_indent = Inches(0.3)
p.alignment = WD_ALIGN_PARAGRAPH.LEFT
sub = p.add_run('"Walking back home from the beach"')
sub.font.color.rgb = DARK_GOLD
sub.font.size = Pt(11)
sub.font.name = 'Calibri'
sub.italic = True

playlist = [
    (1, "Daughters", "John Mayer", "FIRST SONG"),
    (2, "Better Together", "Jack Johnson", None),
    (3, "Something in the Orange", "Zach Bryan", None),
    (4, "Chicken Fried", "Zac Brown Band", None),
    (5, "Banana Pancakes", "Jack Johnson", None),
    (6, "I Remember Everything", "Zach Bryan (feat. Kacey Musgraves)", None),
    (7, "Toes", "Zac Brown Band", None),
    (8, "Upside Down", "Jack Johnson", None),
    (9, "Heading South", "Zach Bryan", None),
    (10, "Knee Deep", "Zac Brown Band (feat. Jimmy Buffett)", None),
    (11, "Sitting, Waiting, Wishing", "Jack Johnson", None),
    (12, "Sun to Me", "Zach Bryan", None),
    (13, "Colder Weather", "Zac Brown Band", None),
    (14, "Flake", "Jack Johnson", None),
    (15, "Pink Skies", "Zach Bryan", None),
    (16, "Free", "Zac Brown Band", None),
]

for num, song, artist, note in playlist:
    add_playlist_item(doc, num, song, artist, note)

add_thin_divider(doc)

p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(6)
p.paragraph_format.space_after = Pt(4)
p.paragraph_format.left_indent = Inches(0.3)
note_run = p.add_run("Note: ")
note_run.font.color.rgb = GOLD
note_run.font.size = Pt(10)
note_run.font.name = 'Calibri'
note_run.bold = True
note_text = p.add_run("Play in this order — starts with Daughters for the girls, then mixes the artists for the walk home.")
note_text.font.color.rgb = LIGHT_GRAY
note_text.font.size = Pt(10)
note_text.font.name = 'Calibri'
note_text.italic = True

# ============================================================
# SECTION 5: LOGISTICS
# ============================================================
add_section_heading(doc, "Logistics")

logistics = [
    "Download all music files to Joe's phone before heading to the beach",
    "Test Bluetooth speaker volume on the beach beforehand",
    "Sunset on April 3 in Isle of Palms: approximately 7:40 PM",
    "Ceremony should START by 7:00 PM for best golden hour light",
    "7:41 PM — sunset photos with family (best light)",
    "Backup: if weather is bad, ceremony can move to the rental house deck at 806 Carolina Blvd",
    "Joe and Keli: write your vows and give them to Neisha before the ceremony",
    "Bring: rings, speaker, phone with music, tissues",
]

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

# ============================================================
# FOOTER
# ============================================================
add_gold_divider(doc)

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(16)
p.paragraph_format.space_after = Pt(4)
accent = p.add_run("🦞")
accent.font.size = Pt(14)

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(4)
p.paragraph_format.space_after = Pt(4)
footer = p.add_run("Planned with love by Rob Lobster for Joe and Keli Lynch")
footer.font.color.rgb = NAVY
footer.font.size = Pt(11)
footer.font.name = 'Calibri'
footer.italic = True

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(20)
date_footer = p.add_run("March 30, 2026")
date_footer.font.color.rgb = GOLD
date_footer.font.size = Pt(10)
date_footer.font.name = 'Calibri'

# Save
output_path = "/Users/joemac/.openclaw/workspace/projects/ceremony/ceremony-plan-v2.docx"
doc.save(output_path)
print(f"✅ Document saved to {output_path}")
