#!/usr/bin/env python3
"""Morning Package Builder — Sunday March 29, 2026"""

from docx import Document
from docx.shared import Pt, RGBColor, Inches, Cm
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml.ns import qn
from docx.oxml import OxmlElement
import datetime

OUTPUT_DOCX = "/Users/joemac/.openclaw/workspace/projects/daily/morning-package-2026-03-29.docx"

doc = Document()

# ── Page margins ──────────────────────────────────────────────────────────────
section = doc.sections[0]
section.top_margin    = Inches(0.6)
section.bottom_margin = Inches(0.6)
section.left_margin   = Inches(0.75)
section.right_margin  = Inches(0.75)

# ── Helper functions ──────────────────────────────────────────────────────────
def add_heading(text, level=1, color=RGBColor(0x1A, 0x1A, 0x2E)):
    p = doc.add_paragraph()
    p.alignment = WD_ALIGN_PARAGRAPH.LEFT
    run = p.add_run(text)
    run.bold = True
    run.font.color.rgb = color
    if level == 1:
        run.font.size = Pt(18)
        p.paragraph_format.space_before = Pt(12)
        p.paragraph_format.space_after  = Pt(4)
    elif level == 2:
        run.font.size = Pt(13)
        p.paragraph_format.space_before = Pt(8)
        p.paragraph_format.space_after  = Pt(2)
    else:
        run.font.size = Pt(11)
        p.paragraph_format.space_before = Pt(4)
        p.paragraph_format.space_after  = Pt(1)
    return p

def add_body(text, bold=False, indent=False):
    p = doc.add_paragraph()
    if indent:
        p.paragraph_format.left_indent = Inches(0.25)
    p.paragraph_format.space_before = Pt(1)
    p.paragraph_format.space_after  = Pt(1)
    run = p.add_run(text)
    run.font.size = Pt(10.5)
    run.bold = bold
    return p

def add_divider():
    p = doc.add_paragraph("─" * 80)
    p.runs[0].font.size = Pt(8)
    p.runs[0].font.color.rgb = RGBColor(0xCC, 0xCC, 0xCC)
    p.paragraph_format.space_before = Pt(2)
    p.paragraph_format.space_after  = Pt(2)

def add_checkbox(text, indent=True):
    p = doc.add_paragraph()
    if indent:
        p.paragraph_format.left_indent = Inches(0.2)
    p.paragraph_format.space_before = Pt(1)
    p.paragraph_format.space_after  = Pt(1)
    run = p.add_run(f"☐  {text}")
    run.font.size = Pt(10.5)
    return p

def add_alert(text, emoji="🚨"):
    p = doc.add_paragraph()
    p.paragraph_format.left_indent = Inches(0.2)
    p.paragraph_format.space_before = Pt(1)
    p.paragraph_format.space_after  = Pt(1)
    run = p.add_run(f"{emoji}  {text}")
    run.font.size = Pt(10.5)
    run.bold = True
    run.font.color.rgb = RGBColor(0xC0, 0x20, 0x20)
    return p

# ══════════════════════════════════════════════════════════════════════════════
#  TITLE BLOCK
# ══════════════════════════════════════════════════════════════════════════════
title = doc.add_paragraph()
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
r = title.add_run("🦞  ROB LOBSTER DAILY BRIEF")
r.font.size = Pt(22)
r.font.bold = True
r.font.color.rgb = RGBColor(0x1A, 0x1A, 0x2E)

sub = doc.add_paragraph()
sub.alignment = WD_ALIGN_PARAGRAPH.CENTER
r2 = sub.add_run("Sunday, March 29, 2026   ·   6:00 AM ET")
r2.font.size = Pt(12)
r2.font.color.rgb = RGBColor(0x55, 0x55, 0x55)

add_divider()

# ══════════════════════════════════════════════════════════════════════════════
#  SECTION 1 — WEATHER
# ══════════════════════════════════════════════════════════════════════════════
add_heading("☀️  WEATHER — LBI / Tuckerton", level=2)

add_body("TODAY — Sunday March 29")
add_body("Right now: 30°F  ·  Clear sky  ·  Feels like 27°F  ·  Wind SSE 3 mph", indent=True)
add_body("Sunrise: 6:46 AM  ·  Sunset: 7:19 PM", indent=True)
add_body("Morning: Cold clear start (34°F)  ·  Warms quickly to 54°F by noon  ·  High 58°F", indent=True)
add_body("Afternoon: Sunny & breezy (SSW 12–16 mph)  ·  Feels like low 50s", indent=True)
add_body("Evening: Clouds rolling in, still dry  ·  45°F by 9 PM", indent=True)
add_body("→ Beautiful sunny Sunday — cold start, pleasant afternoon. Jacket weather until noon.", bold=True, indent=True)

add_body("")
add_body("TOMORROW — Monday March 30")
add_body("Overcast all day  ·  High 56°F  ·  Dry but cloudy  ·  SW winds 15–17 mph", indent=True)

add_body("")
add_body("TUESDAY March 31 (Preview)")
add_body("Sunny & warm  ·  High 69°F  ·  Feels like low 60s  ·  Spring has arrived!", indent=True)

add_divider()

# ══════════════════════════════════════════════════════════════════════════════
#  SECTION 2 — MARKET SNAPSHOT
# ══════════════════════════════════════════════════════════════════════════════
add_heading("📈  MARKET SNAPSHOT", level=2)
add_body("Last Close — Friday, March 27, 2026")

# Market table
table = doc.add_table(rows=4, cols=4)
table.style = 'Table Grid'
hdr = table.rows[0].cells
hdr[0].text = "Index"
hdr[1].text = "Your Exit Baseline"
hdr[2].text = "Last Close (3/27)"
hdr[3].text = "Move vs. Exit"

data = [
    ("S&P 500",  "6,591.90",  "6,368.85",  "▼ 223.05  (-3.38%)"),
    ("Dow Jones","46,429.49", "45,167.00",  "▼ 1,262.49  (-2.72%)"),
]
for i, (idx, base, close, move) in enumerate(data, start=1):
    row = table.rows[i].cells
    row[0].text = idx
    row[1].text = base
    row[2].text = close
    row[3].text = move

# Style header
for cell in table.rows[0].cells:
    for para in cell.paragraphs:
        for run in para.runs:
            run.bold = True
            run.font.size = Pt(9)
            run.font.color.rgb = RGBColor(0xFF, 0xFF, 0xFF)
        shading = OxmlElement('w:shd')
        shading.set(qn('w:fill'), '1A1A2E')
        cell._tc.get_or_add_tcPr().append(shading)

# Style data rows
for i in range(1, 3):
    for j, cell in enumerate(table.rows[i].cells):
        for para in cell.paragraphs:
            for run in para.runs:
                run.font.size = Pt(10)
                if j == 3:  # move column — red
                    run.font.color.rgb = RGBColor(0xC0, 0x20, 0x20)
                    run.bold = True

doc.add_paragraph("")
add_body("✅  Your treasuries move (March 25) continues to look prescient.", bold=True)
add_body("Markets now DOWN 5 consecutive weeks. Tariff uncertainty + Iran/oil driving selloff.", indent=True)
add_body("Dow officially in correction territory. S&P testing key support levels.", indent=True)
add_body("April 30 restructuring day: 32 days out — plenty of time for more downside.", indent=True)
add_body("⚠️  Markets closed Monday April 7 (Good Friday weekend extended); plan around it.", indent=True)

add_divider()

# ══════════════════════════════════════════════════════════════════════════════
#  SECTION 3 — TODAY'S SCHEDULE & REMINDERS
# ══════════════════════════════════════════════════════════════════════════════
add_heading("📅  TODAY'S SCHEDULE & REMINDERS", level=2)

add_body("SUNDAY, MARCH 29  (5 days until Charleston Easter Trip)")
add_body("")

add_alert("BOOK OFFICIANT TODAY — April 3 ceremony is THIS THURSDAY", "🚨")
add_body("Top pick: Vows by Dawn — explicitly does vow renewals, last-minute OK, 15+ years.", indent=True)
add_body("Backup: Custom Vows by Casey (laid-back Charleston local).", indent=True)
add_body("Full list: projects/charleston-officiant-options.md", indent=True)

add_body("")
add_alert("Keli & Joe's ANNIVERSARY — April 3 (Thursday) — 5 days out!", "💍")
add_body("This is non-negotiable, most important day. Plan something special while in Charleston.", indent=True)
add_body("Isle of Palms: 806 Carolina Blvd  ·  Check-in Apr 3  ·  Door code: 008471", indent=True)

add_body("")
add_body("CHARLESTON TRIP LOGISTICS (April 3–6):")
add_body("  • Juliana: BHM→CHS Apr 3 (AA KIGNPA)  ·  return CHS→BHM Apr 6", indent=True)
add_body("  • Danielle: AUS→CHS Apr 3 (SW B5FIM6)  ·  return CHS→AUS Apr 6 6:40PM", indent=True)
add_body("  • Isle of Palms rental: $4,202.93 total  ·  1 block from beach", indent=True)
add_body("  • Ray O'Connor meeting (colorant industry reconnect) — come prepared", indent=True)

add_body("")
add_body("THIS WEEK PRIORITIES:")
add_body("  Mon 3/30 — Work day; Concrete drain at TLC targeted before Easter", indent=True)
add_body("  Tue 3/31 — Firehouse plans to structural engineer (if not already done)", indent=True)
add_body("  Wed 4/1  — Final prep before family Easter trip", indent=True)
add_body("  Thu 4/3  — DEPART for Charleston / Anniversary", indent=True)

add_divider()

# ══════════════════════════════════════════════════════════════════════════════
#  SECTION 4 — URGENT ITEMS
# ══════════════════════════════════════════════════════════════════════════════
add_heading("⚡  URGENT ITEMS", level=2)

urgents = [
    ("🚨", "OFFICIANT BOOKING — April 3 ceremony. Call TODAY. (See Section 3)"),
    ("💍", "ANNIVERSARY — April 3. 5 days out. Surprise/gesture planned?"),
    ("🏠", "ISLE OF PALMS CONTRACT — Joe asked Rob to OK to sign. $4,202.93. Ready to sign."),
    ("👰", "NUPTIALS BY NEISHA — Review vow renewal packages (WeddingWire). ~$975 avg. Reply via WeddingWire."),
    ("🔧", "CONCRETE DRAIN at TLC — Target completion before Easter. Where does this stand?"),
    ("📐", "FIREHOUSE FLOOR PLAN V6 — Review & mark up. Send to structural engineer THIS WEEK."),
    ("💻", "MAC SETUP NIGHT — OpenClaw update, Gmail send, Claude Max switch, browser automation still pending."),
    ("📊", "SURFBOX SOCIAL MEDIA — April 30 go-live target. 32 days out. Marketing plan ready."),
]

for emoji, text in urgents:
    add_alert(text, emoji)

add_divider()

# ══════════════════════════════════════════════════════════════════════════════
#  SECTION 5 — EMAIL SUMMARY
# ══════════════════════════════════════════════════════════════════════════════
add_heading("📬  EMAIL SUMMARY (Rob's Inbox Check)", level=2)
add_body("Checked: Rob Gmail  ·  jlynch@tlcnj.com / josephfl12@gmail.com senders")
add_body("")

emails = [
    ("Nuptials by Neisha", "Vow renewal packages — WeddingWire. $175 start, ~$975 avg. Confirmed Apr 3 avail. Joe reply needed via WeddingWire."),
    ("Isle of Palms Rental", "806 Carolina Blvd reservation — $4,202.93 total. Check-in Apr 3. Door code: 008471. Ready to sign per Joe's request."),
    ("Juliana Flight", "BHM→CHS Apr 3 / CHS→BHM Apr 6 — AA KIGNPA. Confirmed."),
    ("Danielle Flight", "AUS→CHS Apr 3 (SW B5FIM6) / CHS→AUS Apr 6 6:40PM SW. Confirmed both legs."),
    ("Check-In Instructions", "806 Carolina Blvd details sent to Joe. Door code included."),
    ("Blank MMS forwards", "Several vzwpix.com empty forwards — failed photo messages from Joe's phone (ignore)."),
]

for subject, summary in emails:
    p = doc.add_paragraph()
    p.paragraph_format.left_indent = Inches(0.2)
    p.paragraph_format.space_before = Pt(1)
    p.paragraph_format.space_after = Pt(1)
    r = p.add_run(f"• {subject}:  ")
    r.bold = True
    r.font.size = Pt(10.5)
    r2 = p.add_run(summary)
    r2.font.size = Pt(10.5)

add_body("")
add_body("Note: Gmail API send not yet configured. Email to jlynch@tlcnj.com pending setup.", indent=True)

add_divider()

# ══════════════════════════════════════════════════════════════════════════════
#  SECTION 6 — ACTION CARD
# ══════════════════════════════════════════════════════════════════════════════
add_heading("✅  ACTION CARD — Sunday March 29, 2026", level=1, color=RGBColor(0x0D, 0x47, 0xA1))
add_body("Print · Carry · Scribble · Win", bold=False)
add_body("")

tracks = {
    "🚨 URGENT / TODAY": [
        "Book Charleston vow renewal officiant (Vows by Dawn — call NOW)",
        "Plan anniversary gesture for April 3 — Keli deserves something special",
        "Sign Isle of Palms rental contract ($4,202.93) — Rob says it's clean",
        "Reply to Nuptials by Neisha via WeddingWire (or Joe calls directly)",
    ],
    "💻 MAC / TECH": [
        "OpenClaw update (2026.3.24 available — run: openclaw update)",
        "Set up browser automation (managed Chrome for Rob)",
        "Switch to Claude Max $200/mo plan (API cost savings)",
        "Configure Gmail send (rob.lobster.claw@gmail.com → jlynch@tlcnj.com ONLY)",
        "Set up Gmail read-only on josephfl12@gmail.com",
        "Set up Floorplanner.com account (Rob will handle with browser)",
    ],
    "📞 CALLS": [
        "Officiant — Vows by Dawn (Charleston, SC) — April 3 ceremony",
        "Paul Devaney — status on concrete drain, prep for week",
        "Robert MacArthur — CPA: Roth IRA + W-2/salary restructure timing",
    ],
    "🏚️ FIREHOUSE": [
        "Review Floor Plan V6 (master suite / closets layout)",
        "Mark up V6 and send back to Rob for refinement",
        "Send finalized plan to structural engineer this week",
        "Research historic tax credit implications (National Register)",
    ],
    "🏗️ TLC / SURFBOX": [
        "Concrete drain at TLC — confirm completion before Easter",
        "Surfbox social media — confirm April 30 go-live prep (32 days)",
        "Epicor surcharge module — check with Amanda on status",
        "Edwin junior manager elevation — any actions this week?",
        "Neal & Denise — check Amon + Pagnotta prospecting status",
    ],
    "🏠 PROPERTIES": [
        "Corner Market deal (275 W 9th, Ship Bottom) — any updates?",
        "FireLots project — timeline check ($600–800K profit in 18–24 mo)",
        "Zoning Certificate of Compliance — Phil Reed status check",
        "Brother Matt property buyout — next step?",
    ],
    "👨‍👩‍👧‍👧 FAMILY": [
        "Easter Trip April 3–6 — Isle of Palms, Charleston. EVERYONE confirmed.",
        "Anniversary April 3 — plan the moment (it's non-negotiable)",
        "Ray O'Connor meeting in Charleston — prep colorant strategy questions",
        "Juliana — confidence-building summer plan (waitressing idea?)",
        "Isabella — Gettysburg→South Carolina transfer settled, check in",
        "Parents — anything needed this week?",
    ],
    "🛒 ERRANDS": [
        "Gio — $225 cash/check owed for parents' driveway work",
    ],
    "📆 COMING UP": [
        "APR 3-6 — Charleston Easter trip (Isle of Palms)",
        "APR 3   — Keli & Joe Anniversary 💍",
        "APR 3   — Vow renewal ceremony (BOOK OFFICIANT TODAY)",
        "APR 7   — Markets closed (Good Friday extended)",
        "APR 30  — BIG PORTFOLIO RESTRUCTURING DAY (29-stock build)",
        "APR 30  — Surfbox social media go-live",
    ],
}

for track_name, items in tracks.items():
    add_heading(track_name, level=2, color=RGBColor(0x0D, 0x47, 0xA1))
    for item in items:
        add_checkbox(item)
    doc.add_paragraph("")

# ══════════════════════════════════════════════════════════════════════════════
#  FOOTER
# ══════════════════════════════════════════════════════════════════════════════
add_divider()
footer_p = doc.add_paragraph()
footer_p.alignment = WD_ALIGN_PARAGRAPH.CENTER
fr = footer_p.add_run("🦞  Generated by Rob Lobster  ·  Sunday March 29, 2026  ·  6:00 AM ET")
fr.font.size = Pt(9)
fr.font.color.rgb = RGBColor(0x88, 0x88, 0x88)
fr.italic = True

doc.save(OUTPUT_DOCX)
print(f"Saved: {OUTPUT_DOCX}")
