<?php
// addons/support_system/main.php

function render_support_section($section, $pdo) {
    // 1. Define the absolute path to views
    $view_path = __DIR__ . '/views/';
    
    // 2. Security: Sanitize the section name again just in case
    // This prevents any attempts to use '../' to navigate folders
    $allowed_sections = ['rules', 'center', 'submit', 'my_requests'];
    
    // If the section isn't allowed, default to 'center'
    if (!in_array($section, $allowed_sections)) {
        $section = 'center';
    }

    // 3. Determine which file to include
    $file_to_include = $view_path . $section . '_view.php';

    // 4. Check if the file actually exists before including
    if (file_exists($file_to_include)) {
        /**
         * By including it here, the view files (.php) 
         * will have access to the $pdo variable automatically.
         */
        include $file_to_include;
    } else {
        // Fallback if you accidentally delete a view file
        echo "<div style='text-align:center; padding: 40px;'>
                <i class='fa-solid fa-file-circle-exclamation' style='font-size: 40px; color: #ffcc00;'></i>
                <h3 style='color: white; margin-top: 20px;'>View Terminal Offline</h3>
                <p style='color: var(--text-gray);'>The requested support module [".htmlspecialchars($section)."] is missing from the vault.</p>
                <a href='support.php' style='color: var(--primary); text-decoration: none; font-weight: 800;'>Return to Support Home</a>
              </div>";
    }
}