#!/usr/bin/env python3
"""Create ceremony-plan-v3.docx with elegant formatting."""

from docx import Document
from docx.shared import Pt, Inches, RGBColor, Cm, Emu
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

NAVY = RGBColor(0x00, 0x2B, 0x5C)
GOLD = RGBColor(0xC5, 0x9E, 0x3C)
DARK_GRAY = RGBColor(0x33, 0x33, 0x33)
MED_GRAY = RGBColor(0x88, 0x88, 0x88)
LIGHT_GRAY = RGBColor(0xAA, 0xAA, 0xAA)
WHITE = RGBColor(0xFF, 0xFF, 0xFF)

doc = Document()

# Set default font
style = doc.styles['Normal']
font = style.font
font.name = 'Calibri'
font.size = Pt(11)
font.color.rgb = DARK_GRAY

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

def add_gold_line(doc):
    """Add a decorative gold horizontal line."""
    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('━' * 50)
    run.font.color.rgb = GOLD
    run.font.size = Pt(8)
    run.font.name = 'Calibri'

def add_thin_gold_line(doc):
    """Add a thinner decorative gold line."""
    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(10)
    run.font.name = 'Calibri'

def add_section_heading(doc, text):
    """Add a navy blue section heading with gold accents."""
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.CENTER
    p.paragraph_format.space_before = Pt(16)
    p.paragraph_format.space_after = Pt(4)
    
    # Gold diamond before
    r1 = p.add_run('◆  ')
    r1.font.color.rgb = GOLD
    r1.font.size = Pt(10)
    r1.font.name = 'Calibri'
    
    # Heading text
    r2 = p.add_run(text.upper())
    r2.font.color.rgb = NAVY
    r2.font.size = Pt(14)
    r2.font.bold = True
    r2.font.name = 'Calibri'
    
    # Gold diamond after
    r3 = p.add_run('  ◆')
    r3.font.color.rgb = GOLD
    r3.font.size = Pt(10)
    r3.font.name = 'Calibri'
    
    add_gold_line(doc)

def add_timeline_item(doc, time_str, description):
    """Add a timeline item with gold diamond bullet and gold timestamp."""
    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)
    
    # Gold diamond bullet
    r1 = p.add_run('◆  ')
    r1.font.color.rgb = GOLD
    r1.font.size = Pt(9)
    r1.font.name = 'Calibri'
    
    if time_str:
        # Gold timestamp
        r2 = p.add_run(time_str)
        r2.font.color.rgb = GOLD
        r2.font.size = Pt(11)
        r2.font.bold = True
        r2.font.name = 'Calibri'
        
        r3 = p.add_run(' — ')
        r3.font.color.rgb = DARK_GRAY
        r3.font.size = Pt(11)
        r3.font.name = 'Calibri'
    
    r4 = p.add_run(description)
    r4.font.color.rgb = DARK_GRAY
    r4.font.size = Pt(11)
    r4.font.name = 'Calibri'

def add_body_text(doc, text, bold=False, italic=False, color=DARK_GRAY, size=Pt(11), indent=0, align=None, space_before=Pt(2), space_after=Pt(2)):
    """Add a paragraph of body text."""
    p = doc.add_paragraph()
    if align:
        p.alignment = align
    p.paragraph_format.space_before = space_before
    p.paragraph_format.space_after = space_after
    if indent:
        p.paragraph_format.left_indent = Inches(indent)
    r = p.add_run(text)
    r.font.color.rgb = color
    r.font.size = size
    r.font.bold = bold
    r.font.italic = italic
    r.font.name = 'Calibri'
    return p

def add_speech_paragraph(doc, text):
    """Add a speech paragraph - italic, indented."""
    p = doc.add_paragraph()
    p.paragraph_format.left_indent = Inches(0.5)
    p.paragraph_format.right_indent = Inches(0.3)
    p.paragraph_format.space_before = Pt(4)
    p.paragraph_format.space_after = Pt(4)
    r = p.add_run(text)
    r.font.italic = True
    r.font.color.rgb = DARK_GRAY
    r.font.size = Pt(10.5)
    r.font.name = 'Calibri'

def add_bullet_item(doc, text, color=DARK_GRAY, indent=0.3):
    """Add a gold-bulleted item."""
    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)
    
    r1 = p.add_run('◆  ')
    r1.font.color.rgb = GOLD
    r1.font.size = Pt(8)
    r1.font.name = 'Calibri'
    
    r2 = p.add_run(text)
    r2.font.color.rgb = color
    r2.font.size = Pt(11)
    r2.font.name = 'Calibri'

# ============================================================
# TITLE SECTION
# ============================================================

# Add some top spacing
p = doc.add_paragraph()
p.paragraph_format.space_after = Pt(4)

# Decorative top line
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = p.add_run('◆ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ◆')
r.font.color.rgb = GOLD
r.font.size = Pt(10)
r.font.name = 'Calibri'

# Main title
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(12)
p.paragraph_format.space_after = Pt(4)
r = p.add_run('Lynch Vow Renewal Ceremony')
r.font.color.rgb = NAVY
r.font.size = Pt(28)
r.font.bold = True
r.font.name = 'Calibri'

# Subtitle - date
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(4)
p.paragraph_format.space_after = Pt(2)
r = p.add_run('April 3, 2026')
r.font.color.rgb = GOLD
r.font.size = Pt(16)
r.font.name = 'Calibri'

# Subtitle - location
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(2)
p.paragraph_format.space_after = Pt(8)
r = p.add_run('Isle of Palms, South Carolina — Sunset')
r.font.color.rgb = NAVY
r.font.size = Pt(13)
r.font.italic = True
r.font.name = 'Calibri'

# Decorative bottom line
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_after = Pt(8)
r = p.add_run('◆ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ◆')
r.font.color.rgb = GOLD
r.font.size = Pt(10)
r.font.name = 'Calibri'

# ============================================================
# CEREMONY TIMELINE
# ============================================================

add_section_heading(doc, 'Ceremony Timeline')

timeline_items = [
    ('7:00 PM', 'Family gathers on beach, music begins 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 (see below)'),
    ('7:25 PM', 'Neisha reads Joe\u2019s vows, then Keli\u2019s vows'),
    ('7:32 PM', 'Joe and Keli exchange rings'),
    ('7:35 PM', 'The kiss'),
    ('7:35 PM', 'Music plays: Diana Ross fades elegantly, Joe\u2019s voice intro, then Marvin Gaye and Tammi Terrell kicks in \u2014 Joe and Keli dance'),
    ('7:40 PM', 'Ceremony wraps'),
    ('7:41 PM', 'Pictures with the sunset and family, music playing'),
    (None, 'Walk back to house \u2014 Spotify playlist plays (first song: \u201cDaughters\u201d by John Mayer)'),
    (None, 'Wedding over... let\u2019s eat!'),
]

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

# ============================================================
# 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.2)
r = p.add_run('Track 1 \u2014 Walk to Neisha (10-Minute Loop)')
r.font.color.rgb = NAVY
r.font.size = Pt(12)
r.font.bold = True
r.font.name = 'Calibri'

details = [
    ('Song: ', 'Ain\u2019t No Mountain High Enough \u2014 Diana Ross'),
    ('Section: ', 'Opening (0:00 to 1:21), seamlessly looped with smooth crossfades for 10 minutes'),
    ('File: ', 'diana-walk-to-minister-10min-smooth.mp3'),
    ('', 'Start playing at 7:00 PM as family gathers'),
]

for label, text in details:
    p = doc.add_paragraph()
    p.paragraph_format.space_before = Pt(1)
    p.paragraph_format.space_after = Pt(1)
    p.paragraph_format.left_indent = Inches(0.4)
    if label:
        r1 = p.add_run(label)
        r1.font.color.rgb = GOLD
        r1.font.size = Pt(10.5)
        r1.font.bold = True
        r1.font.name = 'Calibri'
    r2 = p.add_run(text)
    r2.font.color.rgb = DARK_GRAY
    r2.font.size = Pt(10.5)
    r2.font.name = 'Calibri'
    if label == '' and 'Start playing' in text:
        r2.font.italic = True

add_thin_gold_line(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.2)
r = p.add_run('Track 2 \u2014 After the Kiss (One Seamless Track)')
r.font.color.rgb = NAVY
r.font.size = Pt(12)
r.font.bold = True
r.font.name = 'Calibri'

track2_items = [
    'Diana Ross plays beautifully for 2:29, then elegantly fades away (9-second fade)',
    'Brief pause',
    'Joe\u2019s voice: \u201cNot 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.\u201d',
    'Marvin Gaye and Tammi Terrell kicks in \u2014 full song to the end',
]

for item in track2_items:
    add_bullet_item(doc, item, indent=0.4)

# File and play info
for label, text in [('File: ', 'ceremony-full-track.mp3'), ('', 'Play immediately after the kiss')]:
    p = doc.add_paragraph()
    p.paragraph_format.space_before = Pt(1)
    p.paragraph_format.space_after = Pt(1)
    p.paragraph_format.left_indent = Inches(0.4)
    if label:
        r1 = p.add_run(label)
        r1.font.color.rgb = GOLD
        r1.font.size = Pt(10.5)
        r1.font.bold = True
        r1.font.name = 'Calibri'
    r2 = p.add_run(text)
    r2.font.color.rgb = DARK_GRAY
    r2.font.size = Pt(10.5)
    r2.font.name = 'Calibri'
    if label == '':
        r2.font.italic = True

# ============================================================
# NEISHA'S OPENING SPEECH
# ============================================================

add_section_heading(doc, 'Neisha\u2019s Opening Speech')

speech_paragraphs = [
    '\u201cWelcome, 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 \u2018Ain\u2019t No Mountain High Enough.\u2019 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. \u2018No mountain high enough, no valley low enough, no river wide enough to keep me from getting to you.\u2019 That is 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 water 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...\u201d',
]

for para in speech_paragraphs:
    add_speech_paragraph(doc, para)

# Post-speech notes
add_thin_gold_line(doc)

p = doc.add_paragraph()
p.paragraph_format.left_indent = Inches(0.5)
p.paragraph_format.space_before = Pt(6)
p.paragraph_format.space_after = Pt(2)
r = p.add_run('Neisha then reads Joe\u2019s vows, followed by Keli\u2019s vows. Joe and Keli exchange rings.')
r.font.italic = True
r.font.color.rgb = DARK_GRAY
r.font.size = Pt(10.5)
r.font.name = 'Calibri'

p = doc.add_paragraph()
p.paragraph_format.left_indent = Inches(0.5)
p.paragraph_format.space_before = Pt(6)
p.paragraph_format.space_after = Pt(4)
r = p.add_run('(Note to Neisha: Joe and Keli will provide their written vows to you before the ceremony.)')
r.font.italic = True
r.font.color.rgb = MED_GRAY
r.font.size = Pt(10)
r.font.name = 'Calibri'

# ============================================================
# WALK-BACK PLAYLIST
# ============================================================

add_section_heading(doc, 'Walk-Back Playlist (Spotify)')

add_body_text(doc, 'Walking back home from the beach \u2014 barefoot, happy, married all over again.',
              italic=True, color=NAVY, size=Pt(11), indent=0.2, space_before=Pt(4), space_after=Pt(8))

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

for num, title, artist, note in playlist:
    p = doc.add_paragraph()
    p.paragraph_format.space_before = Pt(1)
    p.paragraph_format.space_after = Pt(1)
    p.paragraph_format.left_indent = Inches(0.3)
    
    # Number in gold
    r1 = p.add_run(f'{num}  ')
    r1.font.color.rgb = GOLD
    r1.font.size = Pt(11)
    r1.font.bold = True
    r1.font.name = 'Calibri'
    
    # Song title in navy bold
    r2 = p.add_run(title)
    r2.font.color.rgb = NAVY
    r2.font.size = Pt(11)
    r2.font.bold = True
    r2.font.name = 'Calibri'
    
    # Artist
    r3 = p.add_run(f' \u2014 {artist}')
    r3.font.color.rgb = DARK_GRAY
    r3.font.size = Pt(11)
    r3.font.name = 'Calibri'
    
    # Note if any
    if note:
        r4 = p.add_run(f'  {note}')
        r4.font.color.rgb = MED_GRAY
        r4.font.size = Pt(10)
        r4.font.italic = True
        r4.font.name = 'Calibri'

# Playlist note
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)
r = p.add_run('Play in this order \u2014 starts with Daughters for the girls, then mixes the artists for the walk home. Or shuffle all 16.')
r.font.color.rgb = MED_GRAY
r.font.size = Pt(10)
r.font.italic = True
r.font.name = 'Calibri'

# ============================================================
# LOGISTICS NOTES
# ============================================================

add_section_heading(doc, 'Logistics Notes')

logistics = [
    'Download all 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:40 PM',
    'Ceremony should START by 7:00 PM for best golden hour light',
    '7:41 PM \u2014 sunset photos with family (best light moment)',
    '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_item(doc, item)

# ============================================================
# FOOTER
# ============================================================

# Add spacing before footer
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(20)
p.paragraph_format.space_after = Pt(4)
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = p.add_run('◆ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ◆')
r.font.color.rgb = GOLD
r.font.size = Pt(10)
r.font.name = 'Calibri'

p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.paragraph_format.space_before = Pt(8)
p.paragraph_format.space_after = Pt(4)
r = p.add_run('Planned with love by Rob Lobster for Joe and Keli Lynch \u2014 March 30, 2026')
r.font.color.rgb = LIGHT_GRAY
r.font.size = Pt(10)
r.font.italic = True
r.font.name = 'Calibri'

# Save
output_path = '/Users/joemac/.openclaw/workspace/projects/ceremony/ceremony-plan-v3.docx'
os.makedirs(os.path.dirname(output_path), exist_ok=True)
doc.save(output_path)
print(f'✅ Saved to {output_path}')
