#!/usr/bin/env python3
"""
Basis PPTX Converter voor Phoenix Metals Management Presentatie
Genereert PPTX met 16 slides op basis van de gestructureerde MD inhoud
"""

import os
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.text import MSO_AUTO_SIZE, PP_ALIGN
from pptx.dml.color import RGBColor
from datetime import datetime

def create_basic_pptx():
    """Maakt een basis PPTX presentatie met 16 slides"""
    
    # Maak nieuwe presentatie
    prs = Presentation()
    
    # Set slide sizes (standaard 16:9)
    prs.slide_width = Inches(16)
    prs.slide_height = Inches(9)
    
    # Definieer slide layout
    title_layout = prs.slide_layouts[0]  # Title slide
    content_layout = prs.slide_layouts[1]  # Title and Content
    
    # Slide 1: Titelblad
    slide = prs.slides.add_slide(title_layout)
    
    # Set background color
    background = slide.background
    fill = background.fill
    fill.solid()
    fill.fore_color.rgb = RGBColor(0, 51, 102)  # #003366
    
    title_shape = slide.shapes.title
    title_shape.text = "PGS 15:2025 — Opslag Gevaarlijke Stoffen Phoenix Metals"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
    title_shape.text_frame.paragraphs[0].font.size = Pt(44)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    subtitle_shape = slide.placeholders[1]
    subtitle_shape.text = "Niveaubepaling, Compliance Toetsing & Actieplan"
    subtitle_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
    subtitle_shape.text_frame.paragraphs[0].font.size = Pt(24)
    
    # Slide 2: Agenda
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Agenda"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    agenda_items = [
        "Wat is PGS 15:2025?",
        "Phoenix Metals stoffenlijst", 
        "Niveaubepaling — Resultaat",
        "Compliance toetsing — Bevindingen",
        "Actiepunten & Prioriteiten",
        "Investeringen & Planning",
        "Vervolgstappen"
    ]
    
    for item in agenda_items:
        p = content.text_frame.add_paragraph()
        p.text = f"• {item}"
        p.font.size = Pt(24)
        p.space_after = Pt(12)
    
    # Slide 3: Wat is PGS 15:2025?
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Wat is PGS 15:2025?"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    points = [
        "PGS 15 is de Nederlandse standaard voor veilige opslag van gevaarlijke stoffen",
        "Richtlijn voor opslag verpakte gevaarlijke stoffen",
        "Bepaalt veiligheidsniveau (Basis, C, B, A) op basis van stofeigenschappen en hoeveelheden",
        "Sinds januari 2025: vernieuwde versie (PGS 15:2025)",
        "Status: stand van techniek — gehanteerd door Inspectie SZW en omgevingsdiensten"
    ]
    
    for point in points:
        p = content.text_frame.add_paragraph()
        p.text = point
        p.font.size = Pt(20)
        p.space_after = Pt(10)
    
    # Slide 4: Phoenix Metals — Gevaarlijke Stoffen
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Phoenix Metals — Gevaarlijke Stoffen"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    
    # Create a simple table using text
    content.text_frame.add_paragraph().text = "Stof | ADR | Hoeveelheid | Bijzonder"
    content.text_frame.add_paragraph().text = "---|---|---|---"
    content.text_frame.add_paragraph().text = "NaOH 50% | 8 VG II | 100 L | Bijtend"
    content.text_frame.add_paragraph().text = "H₂SO₄ (25/50/75%) | 8 VG II | 200 L | Bijtend"
    content.text_frame.add_paragraph().text = "CaO | 8 VG III | 10 kg | Bijtend"
    content.text_frame.add_paragraph().text = "V₂O₅ | 6.1 VG II | TBV | CMR 1B + Acute Tox. 2"
    
    # Format the table text
    for paragraph in content.text_frame.paragraphs:
        paragraph.font.size = Pt(16)
        paragraph.space_after = Pt(5)
    
    # Slide 5: Waarom V₂O₅ Bepalend Is
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Waarom V₂O₅ Bepalend Is"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    points = [
        "V₂O₅ combineert kankerverwekkend en dodelijk bij inademing in één stof",
        "Carc. 1B (H350i) → kankerverwekkend bij inademing",
        "Acute Tox. 2 (H330) → dodelijk bij inademing",
        "Repr. 2 (H361fd) → schadelijk voor voortplanting",
        "ADR 6.1 VG II → giftig"
    ]
    
    for point in points:
        p = content.text_frame.add_paragraph()
        p.text = point
        p.font.size = Pt(20)
        p.space_after = Pt(10)
    
    # Slide 6: Niveaubepaling — Resultaat
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Niveaubepaling — Resultaat"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    content.text_frame.add_paragraph().text = "Route | Resultaat"
    content.text_frame.add_paragraph().text = "---|---"
    content.text_frame.add_paragraph().text = "ADR 8 (bijtend, onbrandbaar) | Basisveiligheidsniveau"
    content.text_frame.add_paragraph().text = "ADR 6.1 (V₂O₅) | C-niveau"
    content.text_frame.add_paragraph().text = "CLP Acute Tox. 2 (V₂O₅) | C-niveau (strengste)"
    
    for paragraph in content.text_frame.paragraphs:
        paragraph.font.size = Pt(18)
        paragraph.space_after = Pt(5)
    
    # Slide 7: Wat Betekent C-niveau?
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Wat Betekent C-niveau?"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    points = [
        "Wbdbo 60 minuten (brandwerende wanden/constructie)",
        "Branddetectiesysteem (NEN 2535)",
        "Productopvang (opvangbakken/vloer)",
        "Stoffenscheiding (zuur ↔ base, giftig ↔ bijtend)",
        "Basisveiligheidsniveau (volledig van toepassing)"
    ]
    
    for point in points:
        p = content.text_frame.add_paragraph()
        p.text = point
        p.font.size = Pt(20)
        p.space_after = Pt(10)
    
    # Slide 8: Wanneer Schalen naar A-niveau?
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Wanneer Schalen naar A-niveau?"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    points = [
        "Bij >10 ton V₂O₅ opslag wordt automatische blussing verplicht",
        "0 kg → Basis",
        "1 kg – 10 ton → C",
        ">10 ton → A (+VBB-installatie)",
        "Aanbeveling: Houd V₂O₅ opslag onder 10 ton"
    ]
    
    for point in points:
        p = content.text_frame.add_paragraph()
        p.text = point
        p.font.size = Pt(20)
        p.space_after = Pt(10)
    
    # Slide 9: Compliance Toetsing — Score
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Compliance Toetsing — Score"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    points = [
        "✅ Voldoet: 18%",
        "⚠️ Gedeeltelijk: 31%",
        "❓ Niet te toetsen: 51%"
    ]
    
    for point in points:
        p = content.text_frame.add_paragraph()
        p.text = point
        p.font.size = Pt(24)
        p.space_after = Pt(15)
    
    # Slide 10: Compliance — Hoofdbevindingen
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Compliance — Hoofdbevindingen"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    points = [
        "Sterk:",
        "• SDS beschikbaar, PBM-beleid aanwezig",
        "• TRA-systeem operationeel",
        "• Seveso: geen drempels overschreden",
        "",
        "Zwak:",
        "• Branddetectie niet aangetoond",
        "• Wbdbo 60 min niet aangetoond",
        "• Stoffenscheiding niet gedocumenteerd",
        "• Stoffenregistratie incompleet (V₂O₅ ontbreekt)"
    ]
    
    for point in points:
        p = content.text_frame.add_paragraph()
        p.text = point
        p.font.size = Pt(18)
        p.space_after = Pt(8)
    
    # Slide 11: Actiepunten — Top 5
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Actiepunten — Top 5"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    action_items = [
        "A01 | Branddetectie (NEN 2535) installeren | 🔴 Hoog | Nieuw",
        "A02 | Wbdbo 60 min constructie toetsen | 🔴 Hoog | Nieuw",
        "A03 | Stoffenregistratie completeren | 🔴 Hoog | Nieuw",
        "A04 | Scheiding zuur/base implementeren | 🔴 Hoog | Nieuw",
        "A05 | Scheiding giftig/bijtend implementeren | 🔴 Hoog | Nieuw"
    ]
    
    for item in action_items:
        p = content.text_frame.add_paragraph()
        p.text = item
        p.font.size = Pt(18)
        p.space_after = Pt(8)
    
    # Slide 12: Openstaande Vragen
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Openstaande Vragen"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    questions = [
        "1. Hoeveel V₂O₅ wordt maximaal opgeslagen?",
        "   (bepaalt C vs A-niveau)",
        "",
        "2. Is de stoffenlijst compleet?",
        "   (missende stoffen = andere niveaus)",
        "",
        "3. Zijn er brandstoffen op locatie?",
        "   (ADR 3 = geheel ander niveau)"
    ]
    
    for question in questions:
        p = content.text_frame.add_paragraph()
        p.text = question
        p.font.size = Pt(20)
        p.space_after = Pt(8)
    
    # Slide 13: Implementatie Planning
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Implementatie Planning"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    phases = [
        "Fase 1 | Weken 1-2 | Beleid vaststellen + data verzamelen",
        "Fase 2 | Weken 3-6 | Constructieve maatregelen (Wbdbo, detectie)",
        "Fase 3 | Weken 4-8 | Procedures + training",
        "Fase 4 | Weken 9-10 | Interne audit + bijsturing"
    ]
    
    for phase in phases:
        p = content.text_frame.add_paragraph()
        p.text = phase
        p.font.size = Pt(20)
        p.space_after = Pt(10)
    
    # Slide 14: Investeringen — Indicatie
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Investeringen — Indicatie"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    investments = [
        "Post | Indicatie kosten | Opmerking",
        "---|---|---",
        "Branddetectie (NEN 2535) | [TBV] | Afhankelijk van ruimteomvang",
        "Wbdbo 60 min aanpassing | [TBV] | Afhankelijk van huidige constructie",
        "Productopvang | [TBV] | Opvangbakken / vloerafdichting",
        "Scheidingsmaatregelen | [TBV] | Wanden of afstandscheiding",
        "Training medewerkers | [TBV] | PGS 15 + V₂O₅ specifiek",
        "**Totaal** | **[TBV]** |"
    ]
    
    for item in investments:
        p = content.text_frame.add_paragraph()
        p.text = item
        p.font.size = Pt(16)
        p.space_after = Pt(5)
    
    # Slide 15: Vervolgstappen
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Vervolgstappen"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    next_steps = [
        "1. Beantwoord kritieke vragen",
        "   • V₂O₅ hoeveelheid",
        "   • Complete stoffenlijst",
        "   • Brandstoffen op locatie",
        "",
        "2. Goedkeuring beleidsdocument opslagveiligheid",
        "",
        "3. Start fase 1: data verzameling + constructieve inspectie"
    ]
    
    for step in next_steps:
        p = content.text_frame.add_paragraph()
        p.text = step
        p.font.size = Pt(20)
        p.space_after = Pt(8)
    
    # Slide 16: Afsluiting
    slide = prs.slides.add_slide(content_layout)
    title_shape = slide.shapes.title
    title_shape.text = "Samenvatting"
    title_shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 51, 102)
    title_shape.text_frame.paragraphs[0].font.size = Pt(36)
    title_shape.text_frame.paragraphs[0].font.bold = True
    
    content = slide.shapes.placeholders[1]
    summary = [
        "• Phoenix Metals valt onder PGS 15:2025 C-niveau vanwege V₂O₅",
        "• Houd V₂O₅ opslag <10 ton om A-niveau te voorkomen",
        "• 5 kritieke actiepunten identificeren",
        "• 3 openstaande vragen beantwoorden",
        "• Planning: 10 weken naar compliance",
        "",
        "**Contact**: [HSE Manager, email, telefoon]"
    ]
    
    for point in summary:
        p = content.text_frame.add_paragraph()
        p.text = point
        p.font.size = Pt(20)
        p.space_after = Pt(10)
    
    # Sla presentatie op
    output_path = "/root/projects/jg/2026-pgs15-2025-phoenix-metals/pptx_working/management_presentatie_v1.0.pptx"
    prs.save(output_path)
    print(f"✅ PPTX created successfully: {output_path}")
    
    return output_path

if __name__ == "__main__":
    create_basic_pptx()