#!/usr/bin/env python3
"""Generate Firehouse Measurement Worksheet for Joe to fill in on-site."""

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

doc = Document()

style = doc.styles['Normal']
font = style.font
font.name = 'Calibri'
font.size = Pt(12)

# Title
title = doc.add_heading('FIREHOUSE MEASUREMENT WORKSHEET', level=0)
for run in title.runs:
    run.font.color.rgb = RGBColor(0xC0, 0x39, 0x2B)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER

p = doc.add_paragraph('18 New St, Crosswicks, NJ 08515')
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
p.runs[0].font.size = Pt(11)
p.runs[0].font.color.rgb = RGBColor(0x55, 0x55, 0x55)

p = doc.add_paragraph('Date: ____________    Measured by: ____________')
p.alignment = WD_ALIGN_PARAGRAPH.CENTER

doc.add_paragraph()

# Helper
def add_section(title_text, measurements):
    h = doc.add_heading(title_text, level=2)
    for run in h.runs:
        run.font.color.rgb = RGBColor(0xC0, 0x39, 0x2B)
    
    table = doc.add_table(rows=1 + len(measurements), cols=3)
    table.style = 'Light Grid Accent 1'
    table.alignment = WD_TABLE_ALIGNMENT.CENTER
    
    # Set column widths
    for cell in table.columns[0].cells:
        cell.width = Inches(0.4)
    for cell in table.columns[1].cells:
        cell.width = Inches(3.5)
    for cell in table.columns[2].cells:
        cell.width = Inches(2.5)
    
    # Header
    headers = ['#', 'What to Measure', 'Measurement (ft-in)']
    for i, h_text in enumerate(headers):
        cell = table.rows[0].cells[i]
        cell.text = h_text
        for p in cell.paragraphs:
            for run in p.runs:
                run.bold = True
                run.font.size = Pt(10)
    
    # Rows
    for idx, (num, desc) in enumerate(measurements):
        row = table.rows[idx + 1]
        row.cells[0].text = str(num)
        row.cells[1].text = desc
        row.cells[2].text = ''  # blank for Joe to fill in
        for p in row.cells[0].paragraphs:
            p.alignment = WD_ALIGN_PARAGRAPH.CENTER
            for run in p.runs:
                run.font.size = Pt(11)
        for p in row.cells[1].paragraphs:
            for run in p.runs:
                run.font.size = Pt(11)
    
    doc.add_paragraph()

# ==========================================
# SECTION 1: OVERALL BUILDING (CRITICAL)
# ==========================================
add_section('⭐ OVERALL BUILDING (Most Important — Do These First)', [
    (1, 'Total building WIDTH (front face, left corner to right corner)'),
    (2, 'Total building DEPTH (side wall, front to back)'),
    (3, 'Central dividing wall — distance from LEFT exterior wall to center wall'),
    (4, 'Wall thickness (measure one interior wall — probably 6" or 8")'),
])

# ==========================================
# SECTION 2: FIRST FLOOR
# ==========================================
add_section('FIRST FLOOR — Garage & Entry Side', [
    (5, 'Garage interior WIDTH (inside wall to inside wall)'),
    (6, 'Garage interior DEPTH (front to back, inside)'),
    (7, 'Garage door opening WIDTH'),
    (8, 'Existing Entry room WIDTH'),
    (9, 'Existing Entry room DEPTH'),
    (10, 'Vestibule WIDTH (bump-out on left side)'),
    (11, 'Vestibule DEPTH'),
])

add_section('FIRST FLOOR — Kitchen / Living Side', [
    (12, 'Kitchen WIDTH (inside walls)'),
    (13, 'Kitchen DEPTH (inside walls)'),
    (14, 'Great Room / Living Room WIDTH'),
    (15, 'Great Room / Living Room DEPTH'),
    (16, 'Dining area WIDTH (if separated from kitchen)'),
    (17, 'Dining area DEPTH'),
])

add_section('FIRST FLOOR — Other Rooms', [
    (18, 'Bedroom 5 WIDTH'),
    (19, 'Bedroom 5 DEPTH'),
    (20, 'Office (old stairwell area) WIDTH'),
    (21, 'Office (old stairwell area) DEPTH'),
    (22, 'Pantry WIDTH'),
    (23, 'Pantry DEPTH'),
    (24, 'Mudroom WIDTH'),
    (25, 'Mudroom DEPTH'),
    (26, 'Stairwell opening WIDTH'),
    (27, 'Stairwell opening DEPTH'),
])

add_section('FIRST FLOOR — Chimney & Special Features', [
    (28, 'Chimney WIDTH'),
    (29, 'Chimney DEPTH'),
    (30, 'Chimney — distance from LEFT wall'),
    (31, 'Chimney — distance from BACK wall'),
])

# ==========================================
# SECTION 3: SECOND FLOOR (VERIFY)
# ==========================================
add_section('SECOND FLOOR — Verify Key Dimensions', [
    (32, 'Master Bedroom WIDTH (we have 24\' — confirm)'),
    (33, 'Master Bedroom DEPTH (we have 24\' — confirm)'),
    (34, 'Hallway WIDTH'),
    (35, 'Jack & Jill Bath WIDTH'),
    (36, 'Jack & Jill Bath DEPTH'),
])

# ==========================================
# SECTION 4: WINDOWS & DOORS
# ==========================================
add_section('WINDOWS & DOORS (If Time Allows)', [
    (37, 'Window WIDTH (standard size — measure one)'),
    (38, 'Window HEIGHT'),
    (39, 'Window sill height from floor'),
    (40, 'Exterior door WIDTH'),
    (41, 'Interior door WIDTH (standard)'),
    (42, 'Ceiling height — First Floor'),
    (43, 'Ceiling height — Second Floor'),
])

# Notes section
doc.add_heading('NOTES / SKETCHES', level=2)
doc.add_paragraph('Use this space for any notes, corrections, or quick sketches:')
doc.add_paragraph()
doc.add_paragraph('_' * 80)
doc.add_paragraph()
doc.add_paragraph('_' * 80)
doc.add_paragraph()
doc.add_paragraph('_' * 80)
doc.add_paragraph()
doc.add_paragraph('_' * 80)
doc.add_paragraph()
doc.add_paragraph('_' * 80)
doc.add_paragraph()
doc.add_paragraph('_' * 80)
doc.add_paragraph()

# Tip
p = doc.add_paragraph()
p.add_run('TIP: ').bold = True
p.add_run('Take a PHOTO of each measurement with your phone as backup. '
           'Measurements 1-4 are the most critical — everything else I can estimate from those.')

# Footer
doc.add_paragraph()
p = doc.add_paragraph('— Rob Lobster 🦞')
p.alignment = WD_ALIGN_PARAGRAPH.RIGHT
p.runs[0].font.italic = True
p.runs[0].font.color.rgb = RGBColor(0x7F, 0x8C, 0x8D)

output = '/Users/joemac/.openclaw/workspace/projects/firehouse/firehouse-measurement-worksheet.docx'
doc.save(output)
print(f'Saved: {output}')
