<?php
/**
 * main-content.php — the per-page content region of the panel (page title +
 * breadcrumb + permission error + the included page).
 *
 * Rendered in TWO contexts, both from index.php with $page / $allowed_pages /
 * AUTH_USER already defined:
 *   1. Full page load — included inside <main id="main-content">.
 *   2. Partial (SPA-lite) navigation — included on its own and echoed as the
 *      whole response body, so the client navigator (js/whp-nav.js) can swap it
 *      into #main-content without a full reload. See $is_partial in index.php.
 *
 * Keep this file output-only (no <main> wrapper) so the same markup drops into
 * both contexts. The client replaces #main-content's innerHTML with this.
 */
?>
            <div id="wrapper" class="container-fluid whp-content-wrapper">
                <div class="content-wrapper container">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="page-title">
                                <div class="d-flex justify-content-between align-items-start mb-4">
                                    <div>
                                        <h1 class="mb-1">
                                            <?php echo htmlspecialchars($allowed_pages[$page]); ?>
                                        </h1>
                                        <?php if ($page === 'dashboard'): ?>
                                        <p class="text-muted mb-0">Welcome, <?php echo htmlspecialchars(AUTH_USER); ?></p>
                                        <?php endif; ?>
                                    </div>
                                    <nav aria-label="breadcrumb">
                                        <div class="rounded p-2 border" style="background: var(--whp-card-bg); border-color: var(--whp-card-border) !important;">
                                            <ol class="breadcrumb mb-0">
                                                <li class="breadcrumb-item">
                                                    <a href="index.php?page=dashboard" class="text-decoration-none text-primary" aria-label="Dashboard">
                                                        <i class="fa fa-home" aria-hidden="true"></i>
                                                    </a>
                                                </li>
                                                <?php if ($page !== 'dashboard'): ?>
                                                <li class="breadcrumb-item active" aria-current="page">
                                                    <?php echo htmlspecialchars($allowed_pages[$page]); ?>
                                                </li>
                                                <?php endif; ?>
                                            </ol>
                                        </div>
                                    </nav>
                                </div>
                            </div>
                        </div>
                    </div><!-- end .page title-->

                    <?php
                    // Display permission error message if one exists
                    display_permission_error();
                    ?>
                    <?php
                    // Dynamically include the requested page content
                    $page_file = __DIR__ . '/../pages/' . $page . '.php';
                    if (file_exists($page_file)) {
                        include $page_file;
                    } else {
                        echo '<div class="alert alert-danger">Page not found.</div>';
                    }
                    ?>
                </div>
            </div>
