#!/usr/bin/env python3
"""
Create PowerPoint presentation: Test Modes Reference
One slide per test mode with technical details
"""

from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
from pptx.enum.shapes import MSO_SHAPE
import os

# Create presentation with widescreen dimensions
prs = Presentation()
prs.slide_width = Inches(13.333)
prs.slide_height = Inches(7.5)

# Color scheme - Professional blue/gray
DARK_BLUE = RGBColor(0, 51, 102)
ACCENT_BLUE = RGBColor(0, 112, 192)
LIGHT_BLUE = RGBColor(220, 235, 250)
DARK_GRAY = RGBColor(64, 64, 64)
LIGHT_GRAY = RGBColor(240, 240, 240)
WHITE = RGBColor(255, 255, 255)
ACCENT_ORANGE = RGBColor(230, 126, 34)


def add_title_slide(title, subtitle=""):
    """Add a title slide"""
    slide_layout = prs.slide_layouts[6]  # Blank
    slide = prs.slides.add_slide(slide_layout)

    # Background shape
    shape = slide.shapes.add_shape(
        MSO_SHAPE.RECTANGLE, 0, 0, prs.slide_width, prs.slide_height
    )
    shape.fill.solid()
    shape.fill.fore_color.rgb = DARK_BLUE
    shape.line.fill.background()

    # Title
    title_box = slide.shapes.add_textbox(
        Inches(0.5), Inches(2.5), Inches(12.333), Inches(1.5)
    )
    tf = title_box.text_frame
    p = tf.paragraphs[0]
    p.text = title
    p.font.size = Pt(54)
    p.font.bold = True
    p.font.color.rgb = WHITE
    p.alignment = PP_ALIGN.CENTER

    if subtitle:
        sub_box = slide.shapes.add_textbox(
            Inches(0.5), Inches(4.2), Inches(12.333), Inches(1)
        )
        tf = sub_box.text_frame
        p = tf.paragraphs[0]
        p.text = subtitle
        p.font.size = Pt(28)
        p.font.color.rgb = LIGHT_BLUE
        p.alignment = PP_ALIGN.CENTER

    return slide


def add_section_slide(section_title, tests_list):
    """Add a section divider slide with mini TOC"""
    slide_layout = prs.slide_layouts[6]  # Blank
    slide = prs.slides.add_slide(slide_layout)

    # Left accent bar
    bar = slide.shapes.add_shape(
        MSO_SHAPE.RECTANGLE, 0, 0, Inches(0.3), prs.slide_height
    )
    bar.fill.solid()
    bar.fill.fore_color.rgb = ACCENT_BLUE
    bar.line.fill.background()

    # Section title
    title_box = slide.shapes.add_textbox(
        Inches(0.8), Inches(0.5), Inches(12), Inches(1.2)
    )
    tf = title_box.text_frame
    p = tf.paragraphs[0]
    p.text = section_title
    p.font.size = Pt(44)
    p.font.bold = True
    p.font.color.rgb = DARK_BLUE

    # Subtitle
    sub_box = slide.shapes.add_textbox(
        Inches(0.8), Inches(1.5), Inches(12), Inches(0.5)
    )
    tf = sub_box.text_frame
    p = tf.paragraphs[0]
    p.text = "Tests in This Section:"
    p.font.size = Pt(20)
    p.font.color.rgb = DARK_GRAY

    # Tests list
    list_box = slide.shapes.add_textbox(
        Inches(1.2), Inches(2.2), Inches(11), Inches(4.5)
    )
    tf = list_box.text_frame
    tf.word_wrap = True

    for i, test in enumerate(tests_list, 1):
        if i == 1:
            p = tf.paragraphs[0]
        else:
            p = tf.add_paragraph()
        p.text = f"{i}. {test}"
        p.font.size = Pt(22)
        p.font.color.rgb = DARK_GRAY
        p.space_after = Pt(8)

    return slide


def add_test_slide(
    test_name,
    org,
    year,
    test_type,
    purpose,
    setup_data,
    dummy_data,
    criteria_data,
    image_path=None,
    note=None,
):
    """Add a test mode slide with all details"""
    slide_layout = prs.slide_layouts[6]  # Blank
    slide = prs.slides.add_slide(slide_layout)

    # Header bar
    header = slide.shapes.add_shape(
        MSO_SHAPE.RECTANGLE, 0, 0, prs.slide_width, Inches(1.0)
    )
    header.fill.solid()
    header.fill.fore_color.rgb = DARK_BLUE
    header.line.fill.background()

    # Test name
    title_box = slide.shapes.add_textbox(
        Inches(0.3), Inches(0.15), Inches(10), Inches(0.7)
    )
    tf = title_box.text_frame
    p = tf.paragraphs[0]
    p.text = test_name
    p.font.size = Pt(32)
    p.font.bold = True
    p.font.color.rgb = WHITE

    # Org/Year/Type badge
    badge_box = slide.shapes.add_textbox(
        Inches(10.5), Inches(0.25), Inches(2.5), Inches(0.5)
    )
    tf = badge_box.text_frame
    p = tf.paragraphs[0]
    p.text = f"{org} | {year}"
    p.font.size = Pt(14)
    p.font.color.rgb = LIGHT_BLUE
    p.alignment = PP_ALIGN.RIGHT

    # Test type below badge
    type_box = slide.shapes.add_textbox(
        Inches(10.5), Inches(0.55), Inches(2.5), Inches(0.4)
    )
    tf = type_box.text_frame
    p = tf.paragraphs[0]
    p.text = test_type
    p.font.size = Pt(12)
    p.font.color.rgb = LIGHT_BLUE
    p.alignment = PP_ALIGN.RIGHT

    # Purpose section
    purpose_label = slide.shapes.add_textbox(
        Inches(0.3), Inches(1.15), Inches(2), Inches(0.3)
    )
    tf = purpose_label.text_frame
    p = tf.paragraphs[0]
    p.text = "PURPOSE"
    p.font.size = Pt(12)
    p.font.bold = True
    p.font.color.rgb = ACCENT_BLUE

    purpose_box = slide.shapes.add_textbox(
        Inches(0.3), Inches(1.4), Inches(6.5), Inches(0.9)
    )
    tf = purpose_box.text_frame
    tf.word_wrap = True
    p = tf.paragraphs[0]
    p.text = purpose
    p.font.size = Pt(14)
    p.font.color.rgb = DARK_GRAY

    # Left column - Test Setup
    setup_label = slide.shapes.add_textbox(
        Inches(0.3), Inches(2.4), Inches(3), Inches(0.3)
    )
    tf = setup_label.text_frame
    p = tf.paragraphs[0]
    p.text = "TEST SETUP"
    p.font.size = Pt(12)
    p.font.bold = True
    p.font.color.rgb = ACCENT_BLUE

    setup_box = slide.shapes.add_textbox(
        Inches(0.3), Inches(2.7), Inches(3.5), Inches(2.0)
    )
    tf = setup_box.text_frame
    tf.word_wrap = True

    for i, (param, value) in enumerate(setup_data):
        if i == 0:
            p = tf.paragraphs[0]
        else:
            p = tf.add_paragraph()
        p.text = f"{param}: {value}"
        p.font.size = Pt(12)
        p.font.color.rgb = DARK_GRAY
        p.space_after = Pt(4)

    # Middle column - Dummy & Instrumentation
    dummy_label = slide.shapes.add_textbox(
        Inches(4.0), Inches(2.4), Inches(3.5), Inches(0.3)
    )
    tf = dummy_label.text_frame
    p = tf.paragraphs[0]
    p.text = "DUMMY & INSTRUMENTATION"
    p.font.size = Pt(12)
    p.font.bold = True
    p.font.color.rgb = ACCENT_BLUE

    dummy_box = slide.shapes.add_textbox(
        Inches(4.0), Inches(2.7), Inches(3.5), Inches(2.0)
    )
    tf = dummy_box.text_frame
    tf.word_wrap = True

    for i, (item, spec) in enumerate(dummy_data):
        if i == 0:
            p = tf.paragraphs[0]
        else:
            p = tf.add_paragraph()
        p.text = f"{item}: {spec}"
        p.font.size = Pt(12)
        p.font.color.rgb = DARK_GRAY
        p.space_after = Pt(4)

    # Bottom section - Injury Criteria table
    criteria_label = slide.shapes.add_textbox(
        Inches(0.3), Inches(4.8), Inches(3), Inches(0.3)
    )
    tf = criteria_label.text_frame
    p = tf.paragraphs[0]
    p.text = "INJURY CRITERIA & LIMITS"
    p.font.size = Pt(12)
    p.font.bold = True
    p.font.color.rgb = ACCENT_BLUE

    # Criteria as text (simplified table format)
    criteria_box = slide.shapes.add_textbox(
        Inches(0.3), Inches(5.1), Inches(7.5), Inches(2.2)
    )
    tf = criteria_box.text_frame
    tf.word_wrap = True

    for i, (metric, limit, region) in enumerate(criteria_data[:6]):  # Limit to 6 rows
        if i == 0:
            p = tf.paragraphs[0]
        else:
            p = tf.add_paragraph()
        p.text = f"{metric}: {limit} ({region})"
        p.font.size = Pt(11)
        p.font.color.rgb = DARK_GRAY
        p.space_after = Pt(2)

    # Right side - Image placeholder or actual image
    if image_path and os.path.exists(image_path):
        try:
            slide.shapes.add_picture(
                image_path, Inches(8.0), Inches(1.2), width=Inches(5.0)
            )
        except:
            # Fallback if image fails
            img_box = slide.shapes.add_shape(
                MSO_SHAPE.RECTANGLE, Inches(8.0), Inches(1.2), Inches(5.0), Inches(3.5)
            )
            img_box.fill.solid()
            img_box.fill.fore_color.rgb = LIGHT_GRAY
    else:
        # Image placeholder
        img_box = slide.shapes.add_shape(
            MSO_SHAPE.RECTANGLE, Inches(8.0), Inches(1.2), Inches(5.0), Inches(3.5)
        )
        img_box.fill.solid()
        img_box.fill.fore_color.rgb = LIGHT_GRAY
        img_box.line.color.rgb = DARK_GRAY

        img_text = slide.shapes.add_textbox(
            Inches(8.0), Inches(2.7), Inches(5.0), Inches(0.5)
        )
        tf = img_text.text_frame
        p = tf.paragraphs[0]
        p.text = "[Test Image]"
        p.font.size = Pt(14)
        p.font.color.rgb = DARK_GRAY
        p.alignment = PP_ALIGN.CENTER

    # Note if present
    if note:
        note_box = slide.shapes.add_textbox(
            Inches(8.0), Inches(5.0), Inches(5.0), Inches(1.5)
        )
        tf = note_box.text_frame
        tf.word_wrap = True
        p = tf.paragraphs[0]
        p.text = f"Note: {note}"
        p.font.size = Pt(11)
        p.font.italic = True
        p.font.color.rgb = DARK_GRAY

    return slide


# ============================================================================
# BUILD THE PRESENTATION
# ============================================================================

# Title slide
add_title_slide(
    "Safety Test Modes Reference",
    "One Slide Per Test Mode | Comprehensive Technical Guide",
)

# ============================================================================
# SECTION 1: NHTSA / FMVSS REGULATORY TESTS
# ============================================================================

add_section_slide(
    "SECTION 1: NHTSA / FMVSS REGULATORY TESTS",
    [
        "FMVSS 208 - Full Frontal Impact",
        "FMVSS 214 - Side Impact (MDB)",
        "FMVSS 214 - Side Pole Impact",
        "FMVSS 216 - Roof Crush Resistance",
        "FMVSS 301 - Fuel System Integrity",
        "FMVSS 208 - Out-of-Position (OOP)",
        "FMVSS 213 - Child Restraint Systems",
        "FMVSS 201 - Interior Impact (FMH)",
    ],
)

# FMVSS 208 - Full Frontal
add_test_slide(
    "FMVSS 208 - Full Frontal Impact",
    "NHTSA",
    "1968/1984",
    "Full Vehicle Crash Test",
    "Evaluates occupant protection in head-on collisions. The most fundamental crash test - simulates striking a fixed barrier at highway speed. Forms the basis of NCAP 5-star ratings.",
    [
        ("Speed", "35 mph (56 km/h)"),
        ("Barrier", "Rigid concrete wall"),
        ("Overlap", "100% full width"),
        ("Vehicle", "Production vehicle"),
        ("Orientation", "Perpendicular"),
    ],
    [
        ("Driver ATD", "Hybrid III 50th male"),
        ("Passenger ATD", "Hybrid III 5th female"),
        ("Total Channels", "~94"),
        ("Key Sensors", "Head accel, chest, femur"),
    ],
    [
        ("HIC15", "≤ 700", "Head"),
        ("Chest Accel (3ms)", "≤ 60g", "Thorax"),
        ("Chest Deflection", "≤ 63mm / 52mm", "Thorax"),
        ("Femur Load", "≤ 10 kN", "Lower Ext"),
        ("Nij", "≤ 1.0", "Neck"),
        ("Neck Tension", "≤ 4,170 N", "Neck"),
    ],
    "assets/crash_test_dummies_subaru.jpg",
)

# FMVSS 214 - Side MDB
add_test_slide(
    "FMVSS 214 - Side Impact (MDB)",
    "NHTSA",
    "1990",
    "Full Vehicle Crash Test",
    "Evaluates occupant protection when struck broadside. Side impacts are particularly dangerous - only inches separate the door from the occupant.",
    [
        ("MDB Speed", "33.5 mph (54 km/h)"),
        ("MDB Mass", "3,015 lb (1,368 kg)"),
        ("Angle", "27° crabbed"),
        ("Impact Point", "Driver side, H-point"),
        ("Barrier Face", "Deformable honeycomb"),
    ],
    [
        ("Driver ATD", "ES-2re"),
        ("Rear ATD", "SID-IIs (5th female)"),
        ("Total Channels", "~80"),
        ("Key Sensors", "Ribs, pelvis, abdomen"),
    ],
    [
        ("HIC36", "≤ 1000", "Head"),
        ("Rib Deflection", "≤ 44 mm", "Thorax"),
        ("Lower Spine Accel", "≤ 82g", "Pelvis"),
        ("Abdominal Force", "≤ 2.5 kN", "Abdomen"),
        ("Pubic Force", "≤ 6 kN", "Pelvis"),
        ("V*C", "≤ 1.0 m/s", "Thorax"),
    ],
    "assets/iihs_side_barrier.jpg",
)

# FMVSS 214 - Side Pole
add_test_slide(
    "FMVSS 214 - Side Pole Impact",
    "NHTSA",
    "2007",
    "Full Vehicle Crash Test",
    "Simulates sliding sideways into a narrow object (tree, pole). Concentrates force on small area, causing severe intrusion. Side curtain airbags critical.",
    [
        ("Speed", "20 mph (32 km/h)"),
        ("Pole Diameter", "254 mm (10 in)"),
        ("Impact Angle", "75° oblique"),
        ("Impact Location", "Driver head position"),
        ("Vehicle", "Propelled into pole"),
    ],
    [
        ("Driver ATD", "ES-2re or WorldSID"),
        ("Total Channels", "~40"),
        ("Key Sensors", "Head, ribs, pelvis"),
    ],
    [
        ("HIC36", "≤ 1000", "Head"),
        ("Rib Deflection", "≤ 44 mm", "Thorax"),
        ("Lower Spine Accel", "≤ 82g", "Pelvis"),
        ("Abdominal Force", "≤ 2.5 kN", "Abdomen"),
    ],
    "assets/iihs_side_2021.jpg",
    "Side curtain airbags became essential for passing this test.",
)

# FMVSS 216 - Roof Crush
add_test_slide(
    "FMVSS 216 - Roof Crush Resistance",
    "NHTSA",
    "1973/2009",
    "Static Test",
    "Ensures roof supports vehicle weight during rollover. 2009 upgrade doubled requirement to 3x after Ford/Firestone crisis showed original 1.5x inadequate.",
    [
        ("Test Type", "Static (no crash)"),
        ("Force Application", "Angled steel plate"),
        ("Plate Angle", "25° from horizontal"),
        ("Force Required", "≥ 3× vehicle weight"),
        ("Duration", "5 seconds"),
    ],
    [
        ("ATD", "None (static test)"),
        ("Measurements", "Force, displacement"),
        ("Channels", "~4-6"),
        ("Key Sensors", "Load cells"),
    ],
    [
        ("Strength-to-Weight", "≥ 3.0", "Structure"),
        ("Max Displacement", "≤ 127 mm", "Before 3×"),
        ("Both Sides", "Must pass", "Independent"),
    ],
    "assets/roof_strength_test.jpg",
    "Original 1.5× standard (1973) doubled to 3× in 2009.",
)

# FMVSS 301 - Fuel System
add_test_slide(
    "FMVSS 301 - Fuel System Integrity",
    "NHTSA",
    "1968/1977",
    "Full Vehicle Crash Test",
    "Prevents fuel leakage after crashes to reduce fire risk. Strengthened in 1977 after infamous Ford Pinto case showed $11 fix vs. deaths calculation.",
    [
        ("Rear Speed", "50 mph MDB"),
        ("Side Speed", "20 mph MDB"),
        ("Rollover", "360° rotation"),
        ("MDB Mass", "4,000 lb"),
        ("Duration", "5 min post-crash"),
    ],
    [
        ("ATD", "None (leakage test)"),
        ("Measurements", "Fuel leakage volume"),
        ("Duration", "5 minutes static"),
    ],
    [
        ("Impact Leakage", "≤ 28g", "During crash"),
        ("Static Leakage", "≤ 142g/min", "Post-crash"),
        ("Rollover Leakage", "≤ 142g/min", "Each position"),
    ],
    "assets/cadaver_crash_test.jpg",
    "Ford Pinto: 'Cheaper to let them burn' memo became infamous.",
)

# FMVSS 208 - OOP
add_test_slide(
    "FMVSS 208 - Out-of-Position (OOP)",
    "NHTSA",
    "2000",
    "Static Deployment Test",
    "Ensures airbags don't injure occupants too close at deployment. Added after 175+ deaths from early aggressive airbags (mostly children and small adults).",
    [
        ("Position 1", "Chin on module"),
        ("Position 2", "Chest on module"),
        ("Position 3", "Abdomen on module"),
        ("Position 4", "Child seat present"),
        ("Test", "Airbag deployment"),
    ],
    [
        ("ATDs Used", "5th female, children"),
        ("Children", "6yr, 3yr, 12mo CRABI"),
        ("Total Channels", "~30 per test"),
        ("Key Sensors", "Head/neck, chest"),
    ],
    [
        ("HIC15", "≤ 700", "Head"),
        ("Nij", "≤ 1.0", "Neck"),
        ("Neck Tension", "≤ 2,620 N", "Neck (5th)"),
        ("Chest Deflection", "≤ 52 mm", "Thorax (5th)"),
    ],
    "assets/crabi_infant_dummy.jpg",
    "Led to multi-stage airbags and suppression systems.",
)

# FMVSS 213 - Child Restraint
add_test_slide(
    "FMVSS 213 - Child Restraint Systems",
    "NHTSA",
    "1971",
    "Sled Test",
    "Ensures child car seats protect children in crashes. Tests the child restraint system itself, not the vehicle. Multiple dummy sizes used.",
    [
        ("Test Type", "Sled test"),
        ("Delta-V", "30 mph (48 km/h)"),
        ("Peak G", "23-26g"),
        ("Pulse Duration", "~80 ms"),
        ("Seat Bench", "Standardized"),
    ],
    [
        ("Dummies", "CRABI, HIII 3/6/10 yr"),
        ("Total Channels", "~15-20 per dummy"),
        ("Key Sensors", "Head accel, excursion"),
    ],
    [
        ("HIC36", "≤ 1000", "All dummies"),
        ("Head Excursion", "≤ 720 mm", "Forward"),
        ("Knee Excursion", "≤ 915 mm", "Forward"),
        ("Chest Accel (3ms)", "≤ 60g", "All"),
    ],
    "assets/child_dummy_booster.jpg",
)

# FMVSS 201 - Interior Impact
add_test_slide(
    "FMVSS 201 - Interior Impact (FMH)",
    "NHTSA",
    "1968/1998",
    "Component Test",
    "Ensures interior surfaces (pillars, header) don't cause severe head injury when struck. Led to padded pillars and roof-mounted airbags.",
    [
        ("Test Type", "Component test"),
        ("Impactor", "Free Motion Headform"),
        ("FMH Mass", "4.5 kg (10 lb)"),
        ("Impact Speed", "15 mph (24 km/h)"),
        ("Targets", "A/B/C pillars, header"),
    ],
    [
        ("FMH Sensors", "Triaxial accelerometer"),
        ("Total Channels", "3"),
        ("Sample Rate", "≥ 8,000 Hz"),
        ("Filter", "CFC 1000"),
    ],
    [("HIC(d)", "≤ 1000", "All points")],
    "assets/iihs_dummy_sensors.jpg",
    "Multiple impact points tested across each pillar.",
)


# ============================================================================
# SECTION 2: IIHS CONSUMER TESTS
# ============================================================================

add_section_slide(
    "SECTION 2: IIHS CONSUMER INFORMATION TESTS",
    [
        "IIHS Moderate Overlap Frontal",
        "IIHS Small Overlap Frontal",
        "IIHS Side Impact (2021 Updated)",
        "IIHS Roof Strength",
        "IIHS Head Restraint / Whiplash (Discontinued)",
        "IIHS Front Crash Prevention - V2V",
        "IIHS Headlights",
        "IIHS Front Crash Prevention - Pedestrian",
    ],
)

# IIHS Moderate Overlap
add_test_slide(
    "IIHS Moderate Overlap Frontal",
    "IIHS",
    "1995",
    "Full Vehicle Crash Test",
    "Simulates head-on crash with partial engagement - the most common serious frontal crash. More demanding than FMVSS 208 because it bypasses part of crush structure.",
    [
        ("Speed", "40 mph (64 km/h)"),
        ("Overlap", "40% of width"),
        ("Barrier", "Deformable honeycomb"),
        ("Barrier Height", "650 mm"),
        ("Barrier Width", "1,000 mm"),
    ],
    [
        ("Driver ATD", "Hybrid III 50th male"),
        ("Total Channels", "~47"),
        ("Key Sensors", "Head, neck, chest, legs"),
    ],
    [
        ("Head/Neck", "Good/Acceptable/Marginal/Poor", "Risk level"),
        ("Chest", "Good/Acceptable/Marginal/Poor", "Risk level"),
        ("Hip/Thigh", "Good/Acceptable/Marginal/Poor", "Risk level"),
        ("Lower Leg", "Good/Acceptable/Marginal/Poor", "Risk level"),
    ],
    "assets/iihs_frontal_crash_test.jpg",
)

# IIHS Small Overlap
add_test_slide(
    "IIHS Small Overlap Frontal",
    "IIHS",
    "2012/2017",
    "Full Vehicle Crash Test",
    "Addresses corner impacts (tree, pole). Many vehicles that aced moderate overlap failed initially - BMW, Mercedes, Audi all rated Marginal/Poor in 2012.",
    [
        ("Speed", "40 mph (64 km/h)"),
        ("Overlap", "25% of width"),
        ("Barrier", "RIGID (not deformable)"),
        ("Tests", "Driver AND Passenger sides"),
        ("Barrier Edge", "Rounded"),
    ],
    [
        ("ATD", "Hybrid III 50th male"),
        ("Total Channels", "~47"),
        ("Key Sensors", "Head, neck, chest, legs"),
    ],
    [
        ("Structure", "Intrusion measured", "Compartment"),
        ("Kinematics", "Stayed in zone?", "Restraint"),
        ("Injury Risk", "G/A/M/P", "All regions"),
    ],
    "assets/small_overlap_test.jpg",
    "2012 launch: Only 3 of 13 midsize cars earned 'Good'.",
)

# IIHS Side 2021
add_test_slide(
    "IIHS Side Impact (2021 Updated)",
    "IIHS",
    "2003/2021",
    "Full Vehicle Crash Test",
    "Simulates T-bone by larger SUV. 2021 update: heavier barrier (4,200 lb vs 3,300 lb) and faster (37 mph vs 31 mph) to reflect real-world vehicle size increases.",
    [
        ("Barrier Speed", "37 mph (2021)"),
        ("Barrier Mass", "4,200 lb (2021)"),
        ("Ground Clearance", "Higher (SUV-like)"),
        ("Face Height", "Taller"),
        ("Impact", "Driver side"),
    ],
    [
        ("Front ATD", "SID-IIs (5th female)"),
        ("Rear ATD", "SID-IIs (5th female)"),
        ("Total Channels", "~60"),
        ("Key Sensors", "Head, ribs, pelvis"),
    ],
    [
        ("Head/Neck", "G/A/M/P", "HIC, accel"),
        ("Torso", "G/A/M/P", "Rib deflection"),
        ("Pelvis", "G/A/M/P", "Accel, pubic"),
    ],
    "assets/iihs_side_2021.jpg",
    "Original (2003): 31 mph, 3,300 lb barrier.",
)

# IIHS Roof
add_test_slide(
    "IIHS Roof Strength",
    "IIHS",
    "2009",
    "Static Test",
    "Evaluates roof strength for rollover. IIHS 'Good' requires 4× vehicle weight - exceeds federal 3× requirement. Most vehicles now earn Good.",
    [
        ("Test Type", "Static loading"),
        ("Plate Angle", "25°"),
        ("Loading Rate", "≤ 5 mm/sec"),
        ("Crush Limit", "127 mm"),
        ("Both Sides", "Tested separately"),
    ],
    [("ATD", "None"), ("Measurements", "Force, displacement")],
    [
        ("Good", "≥ 4.0×", "Strength-to-weight"),
        ("Acceptable", "3.25 - 3.99×", "Strength-to-weight"),
        ("Marginal", "2.50 - 3.24×", "Strength-to-weight"),
        ("Poor", "< 2.50×", "Strength-to-weight"),
    ],
    "assets/roof_strength_test.jpg",
    "Discontinued after 2016 - nearly all vehicles earn Good.",
)

# IIHS Whiplash
add_test_slide(
    "IIHS Head Restraint / Whiplash",
    "IIHS",
    "2004-2020",
    "Sled Test (DISCONTINUED)",
    "Evaluated whiplash protection in rear-end crashes. Used BioRID II dummy with 24-vertebrae spine. Discontinued because nearly all seats now earn Good.",
    [
        ("Test Type", "Sled test"),
        ("Delta-V", "10 mph (16 km/h)"),
        ("Peak Accel", "~10g"),
        ("Pulse", "Rear-end simulated"),
        ("Status", "DISCONTINUED 2020"),
    ],
    [
        ("ATD", "BioRID II"),
        ("Special", "24-vertebrae spine"),
        ("Total Channels", "~35"),
        ("Key Sensors", "Neck, spine motion"),
    ],
    [
        ("Contact Time", "How quickly head reached restraint", "Timing"),
        ("Torso Accel", "Peak acceleration", "Severity"),
        ("Neck Shear", "Maximum force", "Injury risk"),
        ("Neck Tension", "Maximum force", "Injury risk"),
    ],
    "assets/hybrid_iii_family.jpg",
    "IIHS developing more demanding rear-impact test.",
)

# IIHS FCP V2V
add_test_slide(
    "IIHS Front Crash Prevention - V2V",
    "IIHS",
    "2013",
    "Track Test",
    "Evaluates AEB and FCW systems. Tests response to passenger cars, motorcycles, and semi-trailers. Points for warnings and speed reductions.",
    [
        ("Targets", "Car, motorcycle, trailer"),
        ("Speeds", "31, 37, 43 mph"),
        ("Car Config", "Centered and offset"),
        ("Motorcycle", "Centered and offset"),
        ("Semi", "FCW only (steer out)"),
    ],
    [
        ("Instrumentation", "GPS, speed, decel"),
        ("FCW Timing", "≥ 2.1 sec required"),
        ("AEB Weight", "2/3 of score"),
        ("FCW Weight", "1/3 of score"),
    ],
    [
        ("Full Avoidance", "Maximum points", "AEB"),
        ("Speed Reduction", "Partial points", "AEB"),
        ("Warning ≥2.1s", "Required", "FCW"),
    ],
    "assets/iihs_fcp_car_target.png",
)

# IIHS Headlights
add_test_slide(
    "IIHS Headlights",
    "IIHS",
    "2016",
    "Track Evaluation",
    "Evaluates headlight illumination and glare. Revealed huge variation - some 'luxury' vehicles had poor headlights. Tests straights and curves.",
    [
        ("Track", "Straight and curved"),
        ("Curves", "500ft, 800ft radius"),
        ("Measurements", "Light intensity"),
        ("Conditions", "Nighttime, dry"),
        ("High Beam", "Auto-assist evaluated"),
    ],
    [
        ("Instrumentation", "Light meters"),
        ("Measurements", "Illumination distance"),
        ("Factors", "Low beam, high beam, glare"),
    ],
    [
        ("Low Beam Straight", "Primary factor", "Distance"),
        ("Low Beam Curves", "Critical", "Safety"),
        ("High Beam", "Additional credit", "Bonus"),
        ("Excessive Glare", "Deductions", "Penalty"),
    ],
    "assets/iihs_crash_hall.jpg",
    "Wide variation even within same model (trim levels).",
)

# IIHS Pedestrian AEB
add_test_slide(
    "IIHS Front Crash Prevention - Pedestrian",
    "IIHS",
    "2019",
    "Track Test",
    "Evaluates AEB for pedestrian detection. Pedestrian fatalities increased as SUV sales grew. Tests adult and child crossing scenarios.",
    [
        ("Adult Perp", "50th male crossing"),
        ("Adult Parallel", "Walking along edge"),
        ("Child", "Darting into road"),
        ("Speeds", "25, 37 mph"),
        ("Conditions", "Daytime"),
    ],
    [
        ("Targets", "Adult/child body forms"),
        ("Movement", "Propelled on track"),
        ("Instrumentation", "Speed, braking"),
    ],
    [
        ("Superior", "Avoid/reduce all scenarios", "Rating"),
        ("Advanced", "Significant reduction", "Rating"),
        ("Basic", "Warning only", "Rating"),
    ],
    "assets/euroncap_headform.png",
    "Euro NCAP added night testing in 2024.",
)


# ============================================================================
# SECTION 3: NCAP TESTS
# ============================================================================

add_section_slide(
    "SECTION 3: NCAP CONSUMER RATING TESTS",
    [
        "NHTSA NCAP 5-Star Frontal",
        "NHTSA NCAP 5-Star Side",
        "Euro NCAP MPDB (Mobile Progressive Deformable Barrier)",
    ],
)

# NHTSA NCAP Frontal
add_test_slide(
    "NHTSA NCAP 5-Star Frontal",
    "NHTSA",
    "1979",
    "Full Vehicle Crash Test",
    "Provides consumers comparative frontal crash ratings. Same test as FMVSS 208 but published as 1-5 stars based on injury probability.",
    [
        ("Speed", "35 mph (56 km/h)"),
        ("Barrier", "Rigid wall"),
        ("Overlap", "100% full frontal"),
        ("Same as", "FMVSS 208"),
    ],
    [
        ("Driver ATD", "Hybrid III 50th male"),
        ("Passenger ATD", "Hybrid III 5th female"),
        ("Total Channels", "~94"),
    ],
    [
        ("5 Stars", "≤ 10% injury probability", "Best"),
        ("4 Stars", "11-20%", "Good"),
        ("3 Stars", "21-35%", "Average"),
        ("2 Stars", "36-45%", "Below avg"),
        ("1 Star", "≥ 46%", "Worst"),
    ],
    "assets/crash_test_dummies_subaru.jpg",
)

# NHTSA NCAP Side
add_test_slide(
    "NHTSA NCAP 5-Star Side",
    "NHTSA",
    "1997/2011",
    "Full Vehicle Crash Test",
    "Provides consumers comparative side crash ratings. Combines MDB and pole tests (added 2011) for overall side rating.",
    [
        ("MDB Speed", "38.5 mph (62 km/h)"),
        ("MDB Mass", "3,015 lb"),
        ("Pole Speed", "20 mph"),
        ("Pole Diameter", "254 mm"),
        ("Combined", "Single rating"),
    ],
    [
        ("Driver MDB", "ES-2re"),
        ("Driver Pole", "WorldSID"),
        ("Rear", "SID-IIs 5th female"),
    ],
    [
        ("MDB + Pole", "Combined rating", "Overall"),
        ("Driver", "Front seat", "Primary"),
        ("Rear", "Second row", "Included"),
    ],
    "assets/iihs_side_barrier.jpg",
)

# Euro NCAP MPDB
add_test_slide(
    "Euro NCAP MPDB",
    "Euro NCAP",
    "2020",
    "Full Vehicle Crash Test",
    "Simulates head-on between similar vehicles. Uniquely measures 'aggressivity' - how much damage test vehicle inflicts on other car.",
    [
        ("Test Vehicle Speed", "50 km/h (31 mph)"),
        ("Trolley Speed", "50 km/h"),
        ("Overlap", "50%"),
        ("Trolley Mass", "1,400 kg"),
        ("Barrier", "Progressive deformable"),
    ],
    [
        ("Driver ATD", "THOR-50M"),
        ("Rear ATDs", "Q6, Q10 children"),
        ("THOR Features", "150+ channels"),
        ("Special", "Multi-point chest"),
    ],
    [
        ("Occupant Protection", "Injury scores", "Primary"),
        ("Compatibility", "Barrier deformation", "Unique"),
        ("Penalty", "Aggressive vehicles penalized", "Modifier"),
    ],
    "assets/thor_dummy.jpg",
    "THOR-50M: Most advanced frontal dummy in use.",
)


# ============================================================================
# SECTION 4: PEDESTRIAN PROTECTION
# ============================================================================

add_section_slide(
    "SECTION 4: PEDESTRIAN PROTECTION",
    [
        "Euro NCAP Pedestrian - Legform Impact",
        "Euro NCAP Pedestrian - Headform Impact",
        "Euro NCAP AEB Pedestrian/Cyclist",
    ],
)

# Legform
add_test_slide(
    "Euro NCAP Pedestrian - Legform Impact",
    "Euro NCAP",
    "1997",
    "Component Test",
    "Evaluates bumper design for pedestrian leg injuries. Bumper typically contacts leg first when vehicle strikes pedestrian.",
    [
        ("Impactor", "Flexible lower legform"),
        ("Impact Speed", "40 km/h (25 mph)"),
        ("Target", "Front bumper"),
        ("Test Points", "Multiple across width"),
        ("Upper Leg Mass", "8.6 kg"),
    ],
    [
        ("Knee Sensors", "Angle, shear"),
        ("Tibia Sensors", "Accel, bending"),
        ("Total Mass", "13.4 kg"),
    ],
    [
        ("Knee Bending", "≤15° good, ≥21° poor", "Angle"),
        ("Knee Shear", "≤3.5mm good, ≥6mm poor", "Displacement"),
        ("Tibia Accel", "≤150g good, ≥200g poor", "Acceleration"),
    ],
    "assets/euroncap_headform.png",
)

# Headform
add_test_slide(
    "Euro NCAP Pedestrian - Headform Impact",
    "Euro NCAP",
    "1997/2023",
    "Component Test",
    "Evaluates hood/windshield design for pedestrian head injuries. Hood surface and windshield base are where pedestrians' heads typically strike.",
    [
        ("Impact Speed", "40 km/h (25 mph)"),
        ("Adult Headform", "4.5 kg, 165mm"),
        ("Child Headform", "3.5 kg, 130mm"),
        ("Target", "Hood, windshield base"),
        ("Test Points", "Grid of locations"),
    ],
    [
        ("Sensors", "Triaxial accelerometer"),
        ("Channels", "3 per impact"),
        ("Filter", "CFC 1000"),
    ],
    [
        ("HIC15 Good", "≤ 650", "Green"),
        ("HIC15 Adequate", "650-1000", "Yellow"),
        ("HIC15 Poor", "≥ 1700", "Red"),
    ],
    "assets/euroncap_headform.png",
    "Led to raised hoods, pop-up systems, external airbags.",
)

# AEB Pedestrian/Cyclist
add_test_slide(
    "Euro NCAP AEB Pedestrian/Cyclist",
    "Euro NCAP",
    "2016/2018/2024",
    "Track Test",
    "Evaluates active systems that detect and brake for pedestrians/cyclists. 2024 update added night testing for pedestrians.",
    [
        ("Adult Crossing", "CPFA, CPNA scenarios"),
        ("Adult Along Road", "CPLA scenario"),
        ("Child Running", "CPNC scenario"),
        ("Cyclist", "CBFA, CBLA scenarios"),
        ("Speeds", "20, 40, 60 km/h"),
    ],
    [
        ("Targets", "Adult/child body forms"),
        ("Cyclist", "Bike + rider target"),
        ("2024 Update", "Night testing added"),
    ],
    [
        ("Full Avoidance", "Maximum points", "Best"),
        ("Speed Reduction", "Partial points", "Good"),
        ("Warning Only", "Minimal points", "Basic"),
        ("No Response", "Zero points", "Fail"),
    ],
    "assets/euroncap_cyclist_headform.png",
)


# ============================================================================
# SECTION 5: SPORTS / HELMET TESTING
# ============================================================================

add_section_slide(
    "SECTION 5: SPORTS / HELMET TESTING",
    [
        "NOCSAE Football Helmet - Drop Test",
        "NOCSAE Football Helmet - Linear Impactor",
        "NOCSAE Lacrosse Helmet",
        "Ice Hockey Helmet (ASTM/HECC/CSA)",
        "FMVSS 218 - Motorcycle Helmet",
    ],
)

# Football Drop
add_test_slide(
    "NOCSAE Football Helmet - Drop Test",
    "NOCSAE",
    "1973",
    "Drop Test",
    "Ensures helmets attenuate impact energy to prevent skull fracture and severe brain injury. Founding test that reduced football fatalities by 90%.",
    [
        ("Standard Drop", "60 inches (152 cm)"),
        ("Additional Heights", "36, 48, 72 inches"),
        ("Headform", "Humanoid (rigid)"),
        ("Anvils", "Flat, hemi, edge"),
        ("Temps", "Ambient, hot, cold"),
    ],
    [
        ("Sensors", "Triaxial accelerometer"),
        ("Sample Rate", "≥ 10,000 Hz"),
        ("Filter", "CFC 1000"),
    ],
    [
        ("SI Limit", "< 1200", "All conditions"),
        ("Drop Sequence", "Front, side, rear, top", "60 inch"),
        ("Conditioning", "Multiple impacts", "Per protocol"),
    ],
    "assets/hybrid_iii_family.jpg",
    "Pre-1973: 32 deaths/yr. Post-standard: ~3/yr (90% reduction).",
)

# Football Linear Impactor
add_test_slide(
    "NOCSAE Football - Linear Impactor",
    "NOCSAE",
    "2016",
    "Ram Impact Test",
    "Evaluates oblique impacts causing rotational acceleration - linked to concussions. Supplements drop tests to address rotational brain injury.",
    [
        ("Impactor", "Pneumatic ram"),
        ("Ram Mass", "~13 kg"),
        ("Impact Speed", "5.5-9.3 m/s"),
        ("Locations", "Multiple angles"),
        ("Headform", "Hybrid III head/neck"),
    ],
    [
        ("Linear Accel", "3-axis accelerometer"),
        ("Rotational Accel", "Angular rate sensors"),
        ("Rotational Velocity", "Calculated"),
    ],
    [
        ("Peak Linear", "Brain injury risk", "Linear"),
        ("Peak Rotational", "Concussion risk", "Rotational"),
        ("Velocity", "Brain strain", "Rotational"),
    ],
    "assets/atd_family.png",
    "NFL/NFLPA uses combined data for helmet rankings.",
)

# Lacrosse
add_test_slide(
    "NOCSAE Lacrosse Helmet",
    "NOCSAE",
    "ND041",
    "Drop + Projectile",
    "Protects against collision and ball impacts. Combines impact attenuation with projectile protection from high-speed lacrosse ball.",
    [
        ("Drop Heights", "60, 48, 36 inches"),
        ("Headform", "Humanoid"),
        ("Anvils", "Flat, hemispherical"),
        ("Ball Speed", "45 mph (20 m/s)"),
        ("Ball Targets", "Faceguard and shell"),
    ],
    [
        ("Sensors", "Triaxial accelerometer"),
        ("Sample Rate", "≥ 8,000 Hz"),
        ("Filter", "CFC 1000"),
    ],
    [
        ("Drop SI", "< 1200", "Impact attenuation"),
        ("Ball SI", "< 1200", "Projectile"),
        ("Penetration", "None allowed", "Faceguard"),
    ],
    "assets/atd_family.png",
)

# Hockey
add_test_slide(
    "Ice Hockey Helmet",
    "HECC/CSA/ASTM",
    "Multiple",
    "Drop + Puck",
    "Protects against falls, collisions, and puck impacts (100+ mph). Must allow facemask integration. Multiple international standards.",
    [
        ("Drop Heights", "1.5m, 2.0m"),
        ("Headform", "ISO/CSA specified"),
        ("Anvils", "Flat, hemi, edge"),
        ("Puck Mass", "170g (official)"),
        ("Puck Speed", "25-40 m/s"),
    ],
    [
        ("Standards", "CSA, ASTM, HECC, CE"),
        ("Sensors", "Triaxial accelerometer"),
        ("Primary", "Peak g measurement"),
    ],
    [
        ("Drop Flat", "Peak < 275g", "CSA"),
        ("Drop Hemi", "Peak < 275g", "CSA"),
        ("Puck Impact", "No fracture", "Shell"),
        ("Facemask", "No penetration", "Puck"),
    ],
    "assets/atd_family.png",
)

# Motorcycle
add_test_slide(
    "FMVSS 218 - Motorcycle Helmet",
    "NHTSA",
    "1968",
    "Drop + Penetration",
    "Minimum requirements for motorcycle helmets (DOT certification). Every street-legal helmet must pass. Snell and ECE exceed DOT.",
    [
        ("Drop Height", "1.83m (flat), 1.38m (hemi)"),
        ("Anvils", "Flat, hemispherical"),
        ("Headforms", "ISO (multiple sizes)"),
        ("Conditioning", "Ambient, hot, cold, wet"),
        ("Penetration", "3kg cone from 3m"),
    ],
    [
        ("Sensors", "Accelerometer"),
        ("Primary", "Peak acceleration"),
        ("Penetration", "Contact detection"),
    ],
    [
        ("Peak Accel", "≤ 400g", "DOT"),
        ("Penetration", "No headform contact", "Pass/Fail"),
        ("Snell M2020", "275g (voluntary)", "Stricter"),
        ("ECE 22.06", "Includes rotational", "Europe"),
    ],
    "assets/john_stapp_portrait.jpg",
    "DOT is minimum; Snell and ECE exceed requirements.",
)


# ============================================================================
# Save the presentation
# ============================================================================

output_file = "Test_Modes_Reference.pptx"
prs.save(output_file)
print(f"Presentation created: {output_file}")
print(f"Total slides: {len(prs.slides)}")
