#!/usr/bin/env python3
"""
Eenvoudige 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_simple_pptx():
    """Maakt een eenvoudige PPTX presentatie met 16 slides"""
    
    # Maak nieuwe presentatie
    prs = Presentation()
    
    # Set slide sizes (standaard 16:9)
    slides_width = Inches(16)
    slides_height = Inches(9)
    prs.slide_width = slides_width
    prs.slide_height = slides_height
    
    # Definieer slide layout (gebruik de eerste 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)
    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
    
    # Create table
    rows, cols = (4, 4)
    left = Inches(0.5)
    top = Inches(1.5)
    width = Inches(9.0)
    height = Inches(0.4 * rows)
    
    table = slide.shapes.add_table(rows, cols, left, top, width, height).table
    
    # Fill headers
    headers = ["Stof", "ADR", "Hoeveelheid", "Bijzonder"]
    for i, header in enumerate(headers):
        cell = table.cell(0, i)
        cell.text = header
        cell.fill.solid()
        cell.fill.fore_color.rgb = RGBColor(0, 51, 102)
        for paragraph in cell.text_frame.paragraphs:
            for run in paragraph.runs:
                run.font.color.rgb = RGBColor(255, 255, 255)
                run.font.bold = True
    
    # Fill data
    data = [
        ["NaOH 50%", "8 VG II", "100 L", "Bijtend"],
        ["H₂SO₄ (25/50/75%)", "8 VG II", "200 L", "Bijtend"],
        ["CaO", "8 VG III", "10 kg", "Bijtend"],
        ["V₂O₅", "6.1 VG II", "TBV", "CMR 1B + Acute Tox. 2"]
    ]
    
    for i, row in enumerate(data):
        for j, cell_data in enumerate(row):
            cell = table.cell(i + 1, j)
            cell.text = str(cell_data)
    
    # 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
    
    # Create table
    rows, cols = (3, 2)
    left = Inches(0.5)
    top = Inches(1.5)
    width = Inches(9.0)
    height = Inches(0.4 * rows)
    
    table = slide.shapes.add_table(rows, cols, left, top, width, height).table
    
    # Fill headers
    headers = ["Route", "Resultaat"]
    for i, header in enumerate(headers):
        cell = table.cell(0, i)
        cell.text = header
        cell.fill.solid()
        cell.fill.fore_color.rgb = RGBColor(0, 51, 102)
        for paragraph in cell.text_frame.paragraphs:
            for run in paragraph.runs:
                run.font.color.rgb = RGBColor(255, 255, 255)
                run.font.bold = True
    
    # Fill data
    data = [
        ["ADR 8 (bijtend, onbrandbaar)", "Basisveiligheidsniveau"],
        ["ADR 6.1 (V₂O₅)", "C-niveau"],
        ["CLP Acute Tox. 2 (V₂O₅)", "C-niveau (strengste)"]
    ]
    
    for i, row in enumerate(data):
        for j, cell_data in enumerate(row):
            cell = table.cell(i + 1, j)
            cell.text = str(cell_data)
    
    # Continue met de overige slides (vereenvoudigde versie)
    slide_content = [
        "Wat Betekent C-niveau?",
        "Wanneer Schalen naar A-niveau?",
        "Compliance Toetsing — Score",
        "Compliance — Hoofdbevindingen",
        "Actiepunten — Top 5",
        "Openstaande Vragen",
        "Implementatie Planning",
        "Investeringen — Indicatie",
        "Vervolgstappen",
        "Afsluiting"
    ]
    
    for i, title in enumerate(slide_content):
        slide = prs.slides.add_slide(content_layout)
        title_shape = slide.shapes.title
        title_shape.text = title
        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]
        if i == 0:  # Wat Betekent C-niveau?
            points = [
                "Wbdbo 60 minuten (brandwerende wanden/constructie)",
                "Branddetectiesysteem (NEN 2535)",
                "Productopvang (opvangbakken/vloer)",
                "Stoffenscheiding (zuur ↔ base, giftig ↔ bijtend)",
                "Basisveiligheidsniveau (volledig van toepassing)"
            ]
        elif i == 1:  # Wanneer Schalen naar A-niveau?
            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"
            ]
        elif i == 2:  # Compliance Score
            points = [
                "✅ Voldoet: 18%",
                "⚠️ Gedeeltelijk: 31%",
                "❓ Niet te toetsen: 51%"
            ]
        elif i == 3:  # Hoofdbevindingen
            points = [
                "Sterk: SDS beschikbaar, PBM-beleid aanwezig, TRA-systeem operationeel",
                "Zwak: Branddetectie niet aangetoond, Wbdbo 60 min niet aangetoond",
                "Zwak: Stoffenscheiding niet gedocumenteerd, Stoffenregistratie incompleet"
            ]
        elif i == 4:  # Actiepunten Top 5
            points = [
                "A01: Branddetectie (NEN 2535) installeren 🔴 Hoog",
                "A02: Wbdbo 60 min constructie toetsen 🔴 Hoog",
                "A03: Stoffenregistratie completeren 🔴 Hoog",
                "A04: Scheiding zuur/base implementeren 🔴 Hoog",
                "A05: Scheiding giftig/bijtende implementeren 🔴 Hoog"
            ]
        elif i == 5:  # Openstaande Vragen
            points = [
                "1. Hoeveel V₂O₅ wordt maximaal opgeslagen? (bepaalt C vs A)",
                "2. Is de stoffenlijst compleet? (missende stoffen = andere niveaus)",
                "3. Zijn er brandstoffen op locatie? (ADR 3 = geheel ander niveau)"
            ]
        elif i == 6:  # Implementatie Planning
            points = [
                "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"
            ]
        elif i == 7:  # Investeringen
            points = [
                "Branddetectie (NEN 2535): [TBV]",
                "Wbdbo 60 min aanpassing: [TBV]",
                "Productopvang: [TBV]",
                "Scheidingsmaatregelen: [TBV]",
                "Training medewerkers: [TBV]"
            ]
        elif i == 8:  # Vervolgstappen
            points = [
                "Beantwoord kritieke vragen (V₂O₅ hoeveelheid, complete stoffenlijst, brandstoffen)",
                "Goedkeuring beleidsdocument opslagveiligheid",
                "Start fase 1: data verzameling + constructieve inspectie"
            ]
        else:  # Afsluiting
            points = [
                "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"
            ]
        
        for point in points:
            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_simple_pptx()