<?php
require_once __DIR__ . '/../includes/config.php';
requireLogin();

$user   = currentUser();
$action = $_GET['action'] ?? 'chat';

$isMultipart = str_contains($_SERVER['CONTENT_TYPE'] ?? '', 'multipart/form-data');

if ($isMultipart) {
    $body      = $_POST;
    $csrfToken = $body['csrf_token'] ?? '';
} else {
    if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
        jsonResponse(['success' => false, 'message' => 'Method not allowed'], 405);
    }
    $body      = json_decode(file_get_contents('php://input'), true) ?? [];
    $csrfToken = $body['csrf_token'] ?? '';
}

if (!verifyCsrf($csrfToken)) {
    jsonResponse(['success' => false, 'message' => 'Invalid CSRF token'], 403);
}

// ── Ensure session ────────────────────────────────────────────────
if ($action !== 'new_session' && empty($_SESSION['chat_session_id'])) {
    $_SESSION['chat_session_id'] = bin2hex(random_bytes(16));
}
$sessionId = $_SESSION['chat_session_id'] ?? '';

switch ($action) {

    // ── New session ─────────────────────────────────────────────
    case 'new_session':
        $_SESSION['chat_session_id'] = bin2hex(random_bytes(16));
        jsonResponse(['success' => true, 'session_id' => $_SESSION['chat_session_id']]);

    // ── Rename session title ───────────────────────────────
    case 'rename_session':
        $sessionId = $body['session_id'] ?? '';
        $newTitle = trim($body['title'] ?? '');
        if (empty($sessionId) || empty($newTitle)) {
            jsonResponse(['success' => false, 'message' => 'Invalid data'], 422);
        }
        $stmt = db()->prepare('UPDATE ai_chats SET message = ? WHERE session_id = ? AND role = "user" ORDER BY created_at ASC LIMIT 1');
        $stmt->execute([$newTitle, $sessionId]);
        jsonResponse(['success' => true]);

    // ── Delete session ────────────────────────────────────────
    case 'delete_session':
        $sessionId = $body['session_id'] ?? '';
        if (empty($sessionId)) {
            jsonResponse(['success' => false, 'message' => 'Invalid session'], 422);
        }
        $stmt = db()->prepare('DELETE FROM ai_chats WHERE session_id = ? AND user_id = ?');
        $stmt->execute([$sessionId, $user['id']]);
        jsonResponse(['success' => true]);

    // ── Upload document ─────────────────────────────────────────
    case 'upload_doc':
        $file = $_FILES['document'] ?? null;
        if (!$file || $file['error'] !== UPLOAD_ERR_OK) {
            $errMap = [1=>'File too large',2=>'File too large',3=>'Partial upload',4=>'No file',6=>'No temp dir',7=>'Write failed'];
            $msg = $errMap[$file['error'] ?? 4] ?? 'Upload error';
            jsonResponse(['success' => false, 'message' => $msg], 422);
        }
        $maxSize     = (int) env('MAX_FILE_SIZE', 5242880);
        $allowedExts = ['pdf','txt','docx','doc','html','csv','md'];
        if ($file['size'] > $maxSize) {
            jsonResponse(['success' => false, 'message' => 'File too large (max 5MB)'], 422);
        }
        $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
        if (!in_array($ext, $allowedExts)) {
            jsonResponse(['success' => false, 'message' => 'Unsupported type. Use PDF, TXT, DOCX, CSV, HTML, or MD.'], 422);
        }
        $uploadDir = __DIR__ . '/../uploads/';
        if (!is_dir($uploadDir)) mkdir($uploadDir, 0750, true);
        $storedName = bin2hex(random_bytes(16)) . '.' . $ext;
        $dest       = $uploadDir . $storedName;
        if (!move_uploaded_file($file['tmp_name'], $dest)) {
            jsonResponse(['success' => false, 'message' => 'Failed to save file'], 500);
        }
        $extractedText = extractTextFromFile($dest, $ext);
        if (empty(trim($extractedText))) {
            unlink($dest);
            jsonResponse(['success' => false, 'message' => 'Could not read text from this file. Try a plain .txt or .docx.'], 422);
        }
        $extractedText = mb_substr($extractedText, 0, 6000);
        $stmt = db()->prepare('INSERT INTO uploaded_docs (user_id, session_id, original_name, stored_name, mime_type, file_size, extracted_text) VALUES (?,?,?,?,?,?,?)');
        $stmt->execute([$user['id'], $sessionId, $file['name'], $storedName, $file['type'], $file['size'], $extractedText]);
        $docId = db()->lastInsertId();
        jsonResponse(['success' => true, 'doc_id' => $docId, 'filename' => $file['name'], 'preview' => mb_substr($extractedText, 0, 200) . '...']);

    // ── Generate flashcards ─────────────────────────────────────
    case 'generate_flashcards':
        $topic      = trim($body['topic'] ?? '');
        $count      = min(10, max(1, (int)($body['count'] ?? 5)));
        $difficulty = in_array($body['difficulty'] ?? '', ['easy','medium','hard']) ? $body['difficulty'] : 'medium';
        $docId      = (int)($body['doc_id'] ?? 0);
        $subject    = trim($body['subject'] ?? $topic);

        $diffGuide = [
            'easy'   => 'basic recall and definitions, suitable for beginners',
            'medium' => 'conceptual understanding and cause-effect relationships',
            'hard'   => 'deep analysis, application, and critical thinking',
        ];

        $docContext = '';
        $sourceFile = null;
        if ($docId) {
            $dStmt = db()->prepare('SELECT extracted_text, original_name FROM uploaded_docs WHERE id=? AND user_id=?');
            $dStmt->execute([$docId, $user['id']]);
            $doc = $dStmt->fetch();
            if ($doc) { $docContext = $doc['extracted_text']; $sourceFile = $doc['original_name']; }
        }

        if ($docContext) {
            $prompt = "You are an expert educator. Based on the document below, create exactly {$count} flashcards at {$difficulty} difficulty ({$diffGuide[$difficulty]}).

DOCUMENT:\n{$docContext}

Rules: {$count} flashcards total. Questions must be clear and specific. Answers must be complete (1-3 sentences). Cover diverse aspects of the document.

Reply ONLY with a JSON array — no markdown fences, no explanation:
[{\"question\":\"...\",\"answer\":\"...\"}]";
        } else {
            $prompt = "You are an expert educator. Create exactly {$count} flashcards about: \"{$topic}\" at {$difficulty} difficulty ({$diffGuide[$difficulty]}).

Rules: {$count} flashcards total. Mix definitions, examples, comparisons, applications. Answers 1-3 sentences.

Reply ONLY with a JSON array — no markdown fences, no explanation:
[{\"question\":\"...\",\"answer\":\"...\"}]";
        }

        $result = callGroq('', [['role'=>'user','content'=>$prompt]], 2500, false, 0.2);
        if (!$result['success']) jsonResponse(['success' => false, 'message' => $result['error']], 500);

        $raw   = trim($result['text']);
        $raw   = preg_replace('/^```(?:json)?\s*/i', '', $raw);
        $raw   = preg_replace('/\s*```$/', '', $raw);
        // Extract JSON array even if wrapped in text
        if (preg_match('/\[.+\]/s', $raw, $m)) $raw = $m[0];
        $cards = json_decode($raw, true);

        if (!is_array($cards) || empty($cards)) {
            jsonResponse(['success' => false, 'message' => 'AI returned invalid data. Please try again with a different topic.'], 500);
        }
        $cards = array_values(array_filter(array_slice($cards, 0, $count), fn($c) => !empty($c['question']) && !empty($c['answer'])));
        if (empty($cards)) {
            jsonResponse(['success' => false, 'message' => 'No valid flashcards could be generated.'], 500);
        }

        $deckTitle = $sourceFile ? "From: {$sourceFile}" : "Topic: {$topic}";
        $srcType   = $sourceFile ? 'document' : 'ai';
        $stmtDeck  = db()->prepare('INSERT INTO flashcard_decks (user_id, title, subject, difficulty, card_count, source, source_filename) VALUES (?,?,?,?,?,?,?)');
        $stmtDeck->execute([$user['id'], $deckTitle, $subject ?: $topic, $difficulty, count($cards), $srcType, $sourceFile]);
        $deckId = db()->lastInsertId();

        $stmtCard = db()->prepare('INSERT INTO flashcards (deck_id, user_id, question, answer, `order`) VALUES (?,?,?,?,?)');
        foreach ($cards as $i => $card) {
            $stmtCard->execute([$deckId, $user['id'], trim($card['question']), trim($card['answer']), $i]);
        }
        jsonResponse(['success' => true, 'deck_id' => $deckId, 'count' => count($cards), 'title' => $deckTitle]);

    // ── Get doc ──────────────────────────────────────────────
    case 'get_doc':
        $docId = (int)($_GET['doc_id'] ?? $body['doc_id'] ?? 0);
        if (!$docId) jsonResponse(['success' => false, 'message' => 'Invalid ID'], 422);
        $stmt = db()->prepare('SELECT original_name, extracted_text FROM uploaded_docs WHERE id=? AND user_id=?');
        $stmt->execute([$docId, $user['id']]);
        $doc = $stmt->fetch();
        if (!$doc) jsonResponse(['success' => false, 'message' => 'Not found'], 404);
        jsonResponse(['success' => true, 'filename' => $doc['original_name'], 'text' => $doc['extracted_text']]);

    // ── Delete doc ──────────────────────────────────────────────
    case 'delete_doc':
        $docId = (int)($body['doc_id'] ?? 0);
        if (!$docId) jsonResponse(['success' => false, 'message' => 'Invalid ID'], 422);
        $stmt = db()->prepare('SELECT stored_name FROM uploaded_docs WHERE id=? AND user_id=?');
        $stmt->execute([$docId, $user['id']]);
        $doc = $stmt->fetch();
        if ($doc) {
            $path = __DIR__ . '/../uploads/' . $doc['stored_name'];
            if (file_exists($path)) unlink($path);
            db()->prepare('DELETE FROM uploaded_docs WHERE id=?')->execute([$docId]);
        }
        jsonResponse(['success' => true]);

    // ── Rename session ──────────────────────────────────────────
    case 'rename_session':
        $sid   = trim($body['session_id'] ?? '');
        $title = mb_substr(trim($body['title'] ?? ''), 0, 120);
        if (!$sid || !$title) jsonResponse(['success' => false, 'message' => 'Missing data'], 422);
        db()->prepare('UPDATE ai_chat_sessions SET title=? WHERE session_id=? AND user_id=?')->execute([$title, $sid, $user['id']]);
        jsonResponse(['success' => true]);

    // ── Delete session ──────────────────────────────────────────
    case 'delete_session':
        $sid = trim($body['session_id'] ?? '');
        if (!$sid) jsonResponse(['success' => false, 'message' => 'Missing session_id'], 422);
        db()->prepare('DELETE FROM ai_chats WHERE session_id=? AND user_id=?')->execute([$sid, $user['id']]);
        db()->prepare('DELETE FROM ai_chat_sessions WHERE session_id=? AND user_id=?')->execute([$sid, $user['id']]);
        db()->prepare('DELETE FROM uploaded_docs WHERE session_id=? AND user_id=?')->execute([$sid, $user['id']]);
        jsonResponse(['success' => true]);

    // ── Generate presentation ─────────────────────────────────────
    case 'generate_presentation':
        $message = trim($body['message'] ?? '');
        if (empty($message)) jsonResponse(['success' => false, 'message' => 'Message cannot be empty'], 422);

        $sys = "You are a presentation designer. Create professional slide content. Respond ONLY with valid JSON object (no markdown, no text outside JSON).";
        
        $result = callGroq($sys, [['role'=>'user','content'=>$message]], 2000, false, 0.5);
        if (!$result['success']) jsonResponse(['success' => false, 'message' => $result['error']], 500);

        $raw = trim($result['text']);
        $raw = preg_replace('/^```(?:json)?\s*/i', '', $raw);
        $raw = preg_replace('/\s*```$/', '', $raw);
        
        $data = json_decode($raw, true);
        if (!$data || !isset($data['slides'])) {
            jsonResponse(['success' => false, 'message' => 'Invalid presentation format'], 500);
        }

        jsonResponse(['success' => true, 'title' => $data['title'] ?? 'Presentation', 'slides' => $data['slides']]);

    // ── Export PPTX ────────────────────────────────────────────────
    case 'export_pptx':
        $slides = $body['slides'] ?? [];
        $template = $body['template'] ?? 'minimal';
        
        if (empty($slides)) jsonResponse(['success' => false, 'message' => 'No slides to export'], 422);
        
        try {
            $pptx = generatePPTX($slides, $template);
            jsonResponse(['success' => true, 'pptx' => base64_encode($pptx)]);
        } catch (Exception $e) {
            jsonResponse(['success' => false, 'message' => 'Failed to generate PPTX: ' . $e->getMessage()], 500);
        }

    // ── Main chat ────────────────────────────────────────────────
    default:
        $message = trim($body['message'] ?? '');
        $docId   = (int)($body['doc_id'] ?? 0);
        if (empty($message)) jsonResponse(['success' => false, 'message' => 'Message cannot be empty'], 422);

        $docContext = '';
        $docName    = '';
        if ($docId) {
            $dStmt = db()->prepare('SELECT extracted_text, original_name FROM uploaded_docs WHERE id=? AND user_id=?');
            $dStmt->execute([$docId, $user['id']]);
            $doc = $dStmt->fetch();
            if ($doc) { $docContext = "\n\n[DOCUMENT: {$doc['original_name']}]\n" . mb_substr($doc['extracted_text'], 0, 5000); $docName = $doc['original_name']; }
        }

        $stmt = db()->prepare('SELECT role, message FROM ai_chats WHERE user_id=? AND session_id=? ORDER BY created_at ASC LIMIT 30');
        $stmt->execute([$user['id'], $sessionId]);
        $history = $stmt->fetchAll();

        $messages = [];
        foreach ($history as $h) {
            $messages[] = ['role' => $h['role'], 'content' => $h['message']];
        }
        $messages[] = ['role' => 'user', 'content' => $message . $docContext];

        $sys  = "You are Astro, an enthusiastic AI study companion inside SPACE (Student Productivity App & Companion Experience).";
        $sys .= "\nStudent: {$user['full_name']}";
        if ($user['course']) $sys .= ", studying {$user['course']}";
        if ($user['school']) $sys .= " at {$user['school']}";
        $sys .= "\n\nBe friendly, encouraging, and clear. Use bullet points and **bold** for key terms when helpful. If a document is attached, analyze it thoroughly and reference it specifically. Keep responses focused and educational.";

        $result = callGroq($sys, $messages, 1500, false, 0.7);
        if (!$result['success']) jsonResponse(['success' => false, 'message' => $result['error']], 500);

        $reply = $result['text'];

        $ins = db()->prepare('INSERT INTO ai_chats (user_id, session_id, role, message) VALUES (?,?,?,?)');
        $ins->execute([$user['id'], $sessionId, 'user', $message]);
        $ins->execute([$user['id'], $sessionId, 'assistant', $reply]);

        // Auto-title on first message
        $cnt = (int)db()->prepare('SELECT COUNT(*) FROM ai_chats WHERE user_id=? AND session_id=?')
                        ->execute([$user['id'], $sessionId]) ? 0 : 0;
        $cntStmt = db()->prepare('SELECT COUNT(*) FROM ai_chats WHERE user_id=? AND session_id=?');
        $cntStmt->execute([$user['id'], $sessionId]);
        $totalMsgs = (int)$cntStmt->fetchColumn();

        if ($totalMsgs <= 2) {
            $titleMsg  = $docName ? "Document analysis: {$docName}" : $message;
            $titlePrm  = "In 4-6 words, create a concise conversation title for: \"{$titleMsg}\". Reply with ONLY the title. No punctuation at end. No quotes.";
            $titleRes  = callGroq('', [['role'=>'user','content'=>$titlePrm]], 20, false, 0.1);
            $autoTitle = $titleRes['success'] ? mb_substr(trim($titleRes['text']), 0, 80) : mb_substr($message, 0, 60);
            db()->prepare('INSERT INTO ai_chat_sessions (user_id, session_id, title) VALUES (?,?,?) ON DUPLICATE KEY UPDATE updated_at=NOW()')
                ->execute([$user['id'], $sessionId, $autoTitle]);
        } else {
            db()->prepare('UPDATE ai_chat_sessions SET updated_at=NOW() WHERE session_id=? AND user_id=?')->execute([$sessionId, $user['id']]);
        }

        jsonResponse(['success' => true, 'reply' => $reply]);
}

// ────────────────────────────────────────────────────────────────────
// HELPER: Call Groq OpenAI-compatible endpoint
// ────────────────────────────────────────────────────────────────────
function callGroq(string $system, array $messages, int $maxTokens = 1000, bool $noSystem = false, float $temp = 0.7): array {
    $apiKey = env('GROQ_API_KEY', '');
    $model  = env('GROQ_MODEL', 'llama-3.3-70b-versatile');

    if (empty($apiKey)) {
        return ['success' => true, 'text' => "⚙️ Groq API key not configured.\n\nAdd GROQ_API_KEY to your .env file.\nGet a free key at https://console.groq.com"];
    }

    $payload = ['model' => $model, 'max_tokens' => $maxTokens, 'temperature' => $temp];

    if ($noSystem || empty($system)) {
        $payload['messages'] = $messages;
    } else {
        $payload['messages'] = array_merge([['role' => 'system', 'content' => $system]], $messages);
    }

    $ch = curl_init('https://api.groq.com/openai/v1/chat/completions');
    curl_setopt_array($ch, [
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => json_encode($payload),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 60,
        CURLOPT_HTTPHEADER     => [
            'Content-Type: application/json',
            'Authorization: Bearer ' . $apiKey,
        ],
    ]);

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $curlErr  = curl_error($ch);
    curl_close($ch);

    if ($curlErr) return ['success' => false, 'error' => 'Connection failed: ' . $curlErr];

    $data = json_decode($response, true);
    if ($httpCode !== 200) {
        $errMsg = $data['error']['message'] ?? "Groq API error (HTTP {$httpCode})";
        return ['success' => false, 'error' => $errMsg];
    }

    $text = $data['choices'][0]['message']['content'] ?? '';
    if (empty($text)) return ['success' => false, 'error' => 'Empty response from Groq'];

    return ['success' => true, 'text' => $text];
}

// ────────────────────────────────────────────────────────────────────
// HELPER: Extract text from uploaded file
// ────────────────────────────────────────────────────────────────────
function extractTextFromFile(string $path, string $ext): string {
    switch ($ext) {
        case 'txt': case 'md': case 'csv':
            return mb_convert_encoding(file_get_contents($path), 'UTF-8', 'auto');
        case 'html':
            return strip_tags(mb_convert_encoding(file_get_contents($path), 'UTF-8', 'auto'));
        case 'pdf':
            $c = file_get_contents($path);
            $t = '';
            // Extract BT...ET blocks
            preg_match_all('/BT\s*(.*?)\s*ET/s', $c, $m);
            foreach ($m[1] as $blk) {
                preg_match_all('/\(((?:[^()\\\\]|\\\\.)*)\)\s*Tj/s', $blk, $s);
                foreach ($s[1] as $x) $t .= stripcslashes($x) . ' ';
            }
            // Try decompressed streams
            if (strlen(trim($t)) < 100) {
                preg_match_all('/stream\r?\n(.*?)\r?\nendstream/s', $c, $streams);
                foreach ($streams[1] as $stream) {
                    $decoded = @gzuncompress($stream);
                    if (!$decoded) $decoded = @gzinflate(substr($stream, 2));
                    if ($decoded) {
                        preg_match_all('/\(([^)]{1,300})\)/', $decoded, $pm);
                        foreach ($pm[1] as $p) $t .= $p . ' ';
                    }
                }
            }
            return trim(preg_replace('/\s+/', ' ', $t));
        case 'docx': case 'doc':
            if (!class_exists('ZipArchive')) return '';
            $zip = new ZipArchive();
            if ($zip->open($path) !== true) return '';
            $xml = $zip->getFromName('word/document.xml');
            $zip->close();
            if (!$xml) return '';
            $xml = preg_replace('/<w:br[^>]*>/', "\n", $xml);
            $xml = preg_replace('/<\/w:p>/', "\n", $xml);
            return trim(preg_replace('/\s+/', ' ', strip_tags($xml)));
        default:
            return '';
    }
}

// ────────────────────────────────────────────────────────────────────
// HELPER: Generate PPTX file (minimal implementation using ZipArchive)
// ────────────────────────────────────────────────────────────────────
function generatePPTX(array $slides, string $template = 'minimal'): string {
    $colors = getTemplateColors($template);
    $slideCount = count($slides);
    
    $tempFile = tempnam(sys_get_temp_dir(), 'pptx_');
    $zip = new ZipArchive();
    
    if ($zip->open($tempFile, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) {
        throw new Exception('Failed to create ZIP file');
    }
    
    // [Content_Types].xml
    $contentTypes = generateContentTypes($slideCount);
    $zip->addFromString('[Content_Types].xml', $contentTypes);
    
    // _rels/.rels
    $zip->addFromString('_rels/.rels', generateRootRels());
    
    // ppt/_rels/presentation.xml.rels
    $zip->addFromString('ppt/_rels/presentation.xml.rels', generatePresentationRels($slideCount));
    
    // ppt/presentation.xml
    $zip->addFromString('ppt/presentation.xml', generatePresentation($slideCount));
    
    // ppt/slides/slide1.xml, slide2.xml, etc.
    foreach ($slides as $i => $slide) {
        $slideNum = $i + 1;
        $zip->addFromString("ppt/slides/slide{$slideNum}.xml", generateSlide($slide, $slideNum, $colors));
    }
    
    // ppt/theme/theme1.xml
    $zip->addFromString('ppt/theme/theme1.xml', generateTheme($colors));
    
    // ppt/styles.xml
    $zip->addFromString('ppt/styles.xml', generateStyles());
    
    $zip->close();
    
    $content = file_get_contents($tempFile);
    unlink($tempFile);
    
    return $content;
}

function generateContentTypes(int $slideCount): string {
    $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>
<Override PartName="/ppt/presentationSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentationSettings+xml"/>
<Override PartName="/ppt/tableStyles.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml"/>
<Override PartName="/ppt/viewProps.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml"/>
<Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
<Override PartName="/ppt/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.style+xml"/>';
    
    for ($i = 1; $i <= $slideCount; $i++) {
        $xml .= "
<Override PartName=\"/ppt/slides/slide{$i}.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.presentationml.slide+xml\"/>";
    }
    
    $xml .= "\n</Types>";
    return $xml;
}

function generateRootRels(): string {
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/>
</Relationships>';
}

function generatePresentationRels(int $slideCount): string {
    $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/>
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps" Target="viewProps.xml"/>
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/presentationSettings" Target="presentationSettings.xml"/>
<Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles" Target="tableStyles.xml"/>';
    
    for ($i = 1; $i <= $slideCount; $i++) {
        $xml .= "\n<Relationship Id=\"rId" . ($i + 5) . "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide\" Target=\"slides/slide{$i}.xml\"/>";
    }
    
    $xml .= "\n</Relationships>";
    return $xml;
}

function generatePresentation(int $slideCount): string {
    $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:rp="http://schemas.openxmlformats.org/root-properties" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/vocabTypes" mc:Ignorable="mc"p14="http://schemas.microsoft.com/office/powerpoint/2010/main" p14:id="{00000000-0000-0000-0000-000000000000}" p:prl="http://schemas.openxmlformats.org/presentationml/2006/present">
<p:sldSz cx="9144000" cy="6858000"/>
<p:sldIdLst>';
    
    for ($i = 1; $i <= $slideCount; $i++) {
        $xml .= '<p:sldId id="' . (256 + $i - 1) . '" r:id="rId' . ($i + 5) . '"/>';
    }
    
    $xml .= '</p:sldIdLst>
<p:txStyles>
<p:bodyStyle>
<p:lvl1pPr>
<p:defRPr sz="1800" kern="1200"/>
<a:rPr lang="en-US"/>
<a:pPr marL="0" marR="0" marT="0" marB="0" indent="0"/>
</p:lvl1pPr>
<p:lvl2pPr>
<p:defRPr sz="1600" kern="1200"/>
<a:rPr lang="en-US"/>
<a:pPr marL="457200" marR="0" marT="0" marB="0" indent="0"/>
</p:lvl2pPr>
</p:bodyStyle>
<p:titleStyle>
<p:lvl1pPr>
<p:defRPr sz="3200" kern="1200"/>
<a:rPr lang="en-US" b="1"/>
<a:pPr marL="0" marR="0" marT="0" marB="0" indent="0"/>
</p:lvl1pPr>
</p:titleStyle>
</p:txStyles>
</p:presentation>';
    return $xml;
}

function generateSlide(array $slide, int $num, array $colors): string {
    $heading = htmlspecialchars($slide['heading'] ?? 'Slide ' . $num);
    $content = $slide['content'] ?? [];
    $isTitle = ($num === 1) || ($slide['layout'] ?? '') === 'title';
    
    $accent = $colors['accent'] ?? '4F46E5';
    $primary = $colors['primary'] ?? '1A1A2E';
    $bg = $colors['bg'] ?? 'FFFFFF';
    
    $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc2010="http://schemas.openxmlformats.org/markup-compatibility/2010" xmlns:rp="http://schemas.openxmlformats.org/root-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/vocabTypes" mc:Ignorable="mc2010 rp">
<p:cSld>
<p:bg>
<p:bgRef>
<a:rgbClr val="' . $bg . '"/>
</a:rgbRef>
</p:bg>
<p:spTree>
<p:nvGrpSpPr>
<p:cNvPr id="1" name=""/>
<p:cNvGrpSpPr/>
<p:nvPr/>
</p:nvGrpSpPr>
<p:grpSpPr/>
<p:sp>
<p:nvSpPr>
<p:cNvPr id="2" name="Title"/>
<p:cNvSpPr>
<p:spPr/>
</p:cNvSpPr>
<p:nvPr/>
</p:nvSpPr>
<p:spPr>
<a:xfrm>
<a:off x="914400" y="1219200"/>
<a:size cx="7315200" y="1038240"/>
</a:xfrm>
</p:spPr>
<p:txBody>
<a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
<a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:r>
<a:rPr sz="3200" b="1" lang="en-US" altLang="en-US">
<a:solidFill>
<a:srgbClr val="' . ($isTitle ? $primary : $accent) . '"/>
</a:solidFill>
</a:rPr>
<a:t>' . $heading . '</a:t>
</a:r>
<a:endParaRPr lang="en-US"/>
</a:p>
</p:txBody>
</p:sp>';
    
    if (!$isTitle && !empty($content)) {
        $xml .= '
<p:sp>
<p:nvSpPr>
<p:cNvPr id="3" name="Content Placeholder"/>
<p:cNvSpPr>
<p:spPr/>
</p:cNvSpPr>
<p:nvPr>
<p:ph type="body" idx="1"/>
</p:nvPr>
</p:nvSpPr>
<p:spPr>
<a:xfrm>
<a:off x="914400" y="2618280"/>
<a:size cx="7315200" y="4015440"/>
</a:xfrm>
</p:spPr>
<p:txBody>
<a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
<a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">';
        
        foreach ($content as $item) {
            $item = htmlspecialchars($item);
            $xml .= '
<a:r>
<a:rPr sz="1800" lang="en-US" altLang="en-US">
<a:solidFill>
<a:srgbClr val="' . $primary . '"/>
</a:solidFill>
</a:rPr>
<a:t>' . $item . '</a:t>
</a:r>
<a:br xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>';
        }
        
        $xml .= '
<a:endParaRPr lang="en-US"/>
</a:p>
</p:txBody>
</p:sp>';
    }
    
    // Watermark
    $xml .= '
<p:sp>
<p:nvSpPr>
<p:cNvPr id="9999" name="Watermark"/>
<p:cNvSpPr><p:spPr/></p:cNvSpPr>
<p:nvPr/>
</p:nvSpPr>
<p:spPr>
<a:xfrm>
<a:off x="0" y="6500000"/>
<a:size cx="9144000" y="300000"/>
</a:xfrm>
</p:spPr>
<p:txBody>
<a:bodyPr/>
<a:p>
<a:r>
<a:rPr sz="1000" lang="en-US">
<a:solidFill>
<a:srgbClr val="CCCCCC"/>
</a:solidFill>
</a:rPr>
<a:t>Created by SPACE</a:t>
</a:r>
<a:endParaRPr/>
</a:p>
</p:txBody>
</p:sp>';
    
    $xml .= '
</p:spTree>
</p:cSld>
<p:clrMapOvr>
<a:override clrMapping="bg1"/>
</p:clrMapOvr>
</p:sld>';
    
    return $xml;
}

function generateTheme(array $colors): string {
    $accent = $colors['accent'] ?? '4F46E5';
    $primary = $colors['primary'] ?? '1A1A2E';
    
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">
<a:themeElements>
<a:clrScheme name="Office" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:dk1><a:srgbClr val="000000"/></a:dk1>
<a:lt1><a:srgbClr val="FFFFFF"/></a:lt1>
<a:dk2><a:srgbClr val="1F1F1F"/></a:dk2>
<a:lt2><a:srgbClr val="F2F2F2"/></a:lt2>
<a:accent1><a:srgbClr val="' . $accent . '"/></a:accent1>
<a:accent2><a:srgbClr val="' . $primary . '"/></a:accent2>
<a:hlink><a:srgbClr val="0066CC"/></a:hlink>
<a:folHlink><a:srgbClr val="999999"/></a:folHlink>
</a:clrScheme>
<a:fontScheme name="Office" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:majorFont>
<a:latin typeface="Arial"/>
<a:ea typeface=""/>
<a:cs typeface=""/>
</a:majorFont>
<a:minorFont>
<a:latin typeface="Arial"/>
<a:ea typeface=""/>
<a:cs typeface=""/>
</a:minorFont>
</a:fontScheme>
<a:fmtScheme name="Office" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:fillStyleLst>
<a:solidFill>
<a:schemeClr val="bg1"/>
</a:solidFill>
<a:solidFill>
<a:schemeClr val="bg2"/>
</a:solidFill>
<a:solidFill>
<a:schemeClr val="tx1"/>
</a:solidFill>
</a:fillStyleLst>
<a:lnStyleLst>
<a:ln w="9525" cmpd="sng" algn="ctr">
<a:solidFill>
<a:schemeClr val="tx1"/>
</a:solidFill>
<a:prstDash val="solid"/>
<a:cap val="rnd"/>
<a:miter val="800000"/>
<a:join val="round"/>
</a:ln>
<a:ln w="9525" cmpd="sng" algn="ctr">
<a:solidFill>
<a:schemeClr val="tx1"/>
</a:solidFill>
<a:prstDash val="solid"/>
<a:cap val="rnd"/>
<a:miter val="800000"/>
<a:join val="round"/>
</a:ln>
<a:ln w="9525" cmpd="sng" algn="ctr">
<a:solidFill>
<a:schemeClr val="tx1"/>
</a:solidFill>
<a:prstDash val="solid"/>
<a:cap val="rnd"/>
<a:miter val="800000"/>
<a:join val="round"/>
</a:ln>
</a:lnStyleLst>
<a:effectStyleLst>
<a:effectStyle>
<a:effectLst/>
</a:effectStyle>
<a:effectStyle>
<a:effectLst/>
</a:effectStyle>
<a:effectStyle>
<a:effectLst/>
</a:effectStyle>
</a:effectStyleLst>
<a:bgFillStyleLst>
<a:solidFill>
<a:schemeClr val="bg1"/>
</a:solidFill>
<a:solidFill>
<a:schemeClr val="bg2"/>
</a:solidFill>
<a:solidFill>
<a:schemeClr val="bg1"/>
</a:solidFill>
</a:bgFillStyleLst>
</a:fmtScheme>
</a:themeElements>
<a:objectDefaults/>
<a:extraClrSchemeLst/>
</a:theme>';
}

function generateStyles(): string {
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:styles xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/vocabTypes">
<p:defStyle>
<p:bodyStyle>
<p:lvl1pPr>
<p:defRPr sz="1800" kern="1200"/>
<a:pPr marL="0" marR="0" marT="0" marB="0" indent="0"/>
</p:lvl1pPr>
<p:lvl2pPr>
<p:defRPr sz="1600" kern="1200"/>
<a:pPr marL="457200" marR="0" marT="0" marB="0" indent="0"/>
</p:lvl2pPr>
</p:bodyStyle>
<p:titleStyle>
<p:lvl1pPr>
<p:defRPr sz="3200" kern="1200" b="1"/>
<a:pPr marL="0" marR="0" marT="0" marB="0" indent="0"/>
</p:lvl1pPr>
</p:titleStyle>
</p:defStyle>
</p:styles>';
}

function getTemplateColors(string $template): array {
    return match($template) {
        'modern' => ['primary' => '0F172A', 'accent' => '06B6D4', 'bg' => '0F172A'],
        'nature' => ['primary' => '1E3A2F', 'accent' => '22C55E', 'bg' => 'F0FDF4'],
        'sunset' => ['primary' => '3D1A4A', 'accent' => 'F97316', 'bg' => 'FFF7ED'],
        'ocean' => ['primary' => '0C1929', 'accent' => '0EA5E9', 'bg' => '0C1929'],
        'royal' => ['primary' => '2D1B4E', 'accent' => 'A855F7', 'bg' => '2D1B4E'],
        'corporate' => ['primary' => '1E3A8A', 'accent' => '3B82F6', 'bg' => '1E3A8A'],
        'elegant' => ['primary' => '292524', 'accent' => 'D97706', 'bg' => '292524'],
        default => ['primary' => '1A1A2E', 'accent' => '4F46E5', 'bg' => 'FFFFFF'],
    };
}

function getContentTypes(int $slideCount = 1): string {
    $types = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
  <Default Extension="xml" ContentType="application/xml"/>
  <Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>
  <Override PartName="/ppt/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.style+xml"/>
  <Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>';
    
    for ($i = 1; $i <= $slideCount; $i++) {
        $types .= '
  <Override PartName="/ppt/slides/slide' . $i . '.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>';
    }
    
    $types .= '
</Types>';
    return $types;
}

function getRels(): string {
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/>
</Relationships>';
}

function getPresentationRels(int $slideCount = 1): string {
    $rels = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/>
  <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>';
    
    for ($i = 1; $i <= $slideCount; $i++) {
        $rels .= '
  <Relationship Id="rId' . ($i + 2) . '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide' . $i . '.xml"/>';
    }
    
    $rels .= '
</Relationships>';
    return $rels;
}

function getPresentationXml(array $slides): string {
    $slideRefs = '';
    $sldIds = '';
    foreach ($slides as $i => $slide) {
        $slideId = $i + 1;
        $slideRefs .= '<p:slide r:id="rId' . $slideId . '"/>';
        $sldIds .= '<p:sldId id="' . (256 + $i) . '" r:id="rId' . $slideId . '"/>';
    }
    
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  <p:sldIdLst>' . $sldIds . '</p:sldIdLst>
  <p:sldSz cx="9144000" cy="6858000"/>
  <p:sldCntr>
    <p:sld>' . $slideRefs . '</p:sld>
  </p:sldCntr>
</p:presentation>';
}

function getSlideXml(array $slide, int $id, array $colors = []): string {
    $heading = htmlspecialchars($slide['heading'] ?? 'Slide ' . $id);
    $contentItems = $slide['content'] ?? [];
    $contentXml = '';
    $accent = $colors['accent'] ?? '4F46E5';
    $primary = $colors['primary'] ?? '1A1A2E';
    $bgColor = $colors['bg'] ?? 'FFFFFF';
    
    $isTitle = ($id === 1) || ($slide['layout'] ?? '') === 'title';
    
    if ($isTitle) {
        $subtitle = htmlspecialchars($contentItems[0] ?? '');
        return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  <p:cSld bg="1">
    <p:bgFill>
      <p:solidFill>
        <a:srgbClr val="' . $bgColor . '"/>
      </p:solidFill>
    </p:bgFill>
    <p:spTree>
      <p:nvGrpSpPr>
        <p:cNvPr id="1" name=""/>
        <p:cNvGrpSpPr/>
        <p:nvPr/>
      </p:nvGrpSpPr>
      <p:grpSpPr/>
      <p:sp>
        <p:nvSpPr>
          <p:cNvPr id="2" name="Title"/>
          <p:cNvSpPr/>
          <p:nvPr/>
        </p:nvSpPr>
        <p:spPr/>
        <p:txBody>
          <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
          <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
            <a:r>
              <a:rPr sz="4400" b="1" font="Arial">
                <a:solidFill>
                  <a:srgbClr val="' . $primary . '"/>
                </a:solidFill>
              </a:r>
              <a:t>' . $heading . '</a:t>
            </a:r>
            <a:pPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
          </a:p>
        </p:txBody>
      </p:sp>
      <p:sp>
        <p:nvSpPr>
          <p:cNvPr id="3" name="Subtitle"/>
          <p:cNvSpPr/>
          <p:nvPr/>
        </p:nvSpPr>
        <p:spPr/>
        <p:txBody>
          <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
          <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
            <a:r>
              <a:rPr sz="2400" font="Arial">
                <a:solidFill>
                  <a:srgbClr val="666666"/>
                </a:solidFill>
              </a:r>
              <a:t>' . $subtitle . '</a:t>
            </a:r>
          </a:p>
        </p:txBody>
      </p:sp>
      <p:sp>
        <p:nvSpPr>
          <p:cNvPr id="4" name="Watermark"/>
          <p:cNvSpPr/>
          <p:nvPr/>
        </p:nvSpPr>
        <p:spPr/>
        <p:txBody>
          <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
          <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
            <a:r>
              <a:rPr sz="1000" font="Arial">
                <a:solidFill>
                  <a:srgbClr val="CCCCCC"/>
                </a:solidFill>
              </a:r>
              <a:t>Created by SPACE</a:t>
            </a:r>
          </a:p>
        </p:txBody>
      </p:sp>
    </p:spTree>
  </p:cSld>
</p:sld>';
    }
    
    foreach ($contentItems as $item) {
        $item = htmlspecialchars($item);
        $contentXml .= '<a:p><a:r><a:rPr font="Arial"><a:solidFill><a:srgbClr val="' . $primary . '"/></a:solidFill></a:rPr><a:t>' . $item . '</a:t></a:r></a:p>';
    }
    
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  <p:cSld bg="1">
    <p:bgFill>
      <p:solidFill>
        <a:srgbClr val="' . $bgColor . '"/>
      </p:solidFill>
    </p:bgFill>
    <p:spTree>
      <p:nvGrpSpPr>
        <p:cNvPr id="1" name=""/>
        <p:cNvGrpSpPr/>
        <p:nvPr/>
      </p:nvGrpSpPr>
      <p:grpSpPr/>
      <p:sp>
        <p:nvSpPr>
          <p:cNvPr id="2" name="Title"/>
          <p:cNvSpPr/>
          <p:nvPr/>
        </p:nvSpPr>
        <p:spPr/>
        <p:txBody>
          <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
          <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
            <a:r>
              <a:rPr sz="3600" b="1" font="Arial">
                <a:solidFill>
                  <a:srgbClr val="' . $accent . '"/>
                </a:solidFill>
              </a:r>
              <a:t>' . $heading . '</a:t>
            </a:r>
          </a:p>
        </p:txBody>
      </p:sp>
      <p:sp>
        <p:nvSpPr>
          <p:cNvPr id="3" name="Content"/>
          <p:cNvSpPr/>
          <p:nvPr/>
        </p:nvSpPr>
        <p:spPr/>
        <p:txBody>
          <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
          <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">' . $contentXml . '</a:p>
        </p:txBody>
      </p:sp>
      <p:sp>
        <p:nvSpPr>
          <p:cNvPr id="4" name="Watermark"/>
          <p:cNvSpPr/>
          <p:nvPr/>
        </p:nvSpPr>
        <p:spPr/>
        <p:txBody>
          <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
          <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
            <a:r>
              <a:rPr sz="1000" font="Arial">
                <a:solidFill>
                  <a:srgbClr val="CCCCCC"/>
                </a:solidFill>
              </a:r>
              <a:t>Created by SPACE</a:t>
            </a:r>
          </a:p>
        </p:txBody>
      </p:sp>
    </p:spTree>
  </p:cSld>
</p:sld>';
}

function getTheme(array $colors = []): string {
    $accent = $colors['accent'] ?? '4F46E5';
    $primary = $colors['primary'] ?? '1A1A2E';
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">
  <a:themeElements>
    <a:clrScheme name="Office">
      <a:dk1><a:srgbClr val="000000"/></a:dk1>
      <a:lt1><a:srgbClr val="FFFFFF"/></a:lt1>
      <a:dk2><a:srgbClr val="1F1F1F"/></a:dk2>
      <a:lt2><a:srgbClr val="F2F2F2"/></a:lt2>
      <a:accent1><a:srgbClr val="' . $accent . '"/></a:accent1>
    </a:clrScheme>
    <a:fontScheme name="Office">
      <a:majorFont>
        <a:latin typeface="Calibri"/>
      </a:majorFont>
      <a:minorFont>
        <a:latin typeface="Calibri"/>
      </a:minorFont>
    </a:fontScheme>
  </a:themeElements>
</a:theme>';
}

function getStyles(): string {
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:styles xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
  <p:defStyle>
    <p:defPPr>
      <a:pPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
    </p:defPPr>
  </p:defStyle>
</p:styles>';
}
