<?php
include 'includes/auth.php';
include 'db.php';
include 'includes/header.php';
// ================= LOGGED-IN USER =================
$username = $_SESSION['username'] ?? 'Guest';
$dashboard_title = $dashboard_title ?? 'Dashboard'; // Set per page
$dashboard_icon  = $dashboard_icon ?? 'fa-tachometer-alt'; // Set per page
$module_cards    = $module_cards ?? []; // Array of modules
?>
<style>.card-module .icon-box {
    font-size: 24px;               /* icon size */
    width: 60px;                    /* width of icon container */
    height: 60px;                   /* height of icon container */
    display: flex;                  /* flex for centering */
    align-items: center;            /* vertical center */
    justify-content: center;        /* horizontal center */
    border-radius: 50%;             /* make circle */
    margin: 0 auto 10px auto;       /* center in card horizontally, spacing below */
    color: #fff;                    /* icon color */
    background-color: #6c757d;      /* default bg if no color assigned */
    transition: transform 0.2s;
}

.card-module .icon-box i {
    display: block;                 /* ensure icon is treated as block */
}

.card-module:hover .icon-box {
    transform: scale(1.1);          /* hover effect */
}
</style>
<div class="container-fluid mt-4">

    <!-- ================= WELCOME MESSAGE ================= -->
    <div class="welcome-msg">
        <i class="fa fa-user-circle"></i> Welcome, <strong><?= htmlspecialchars($username) ?></strong>!
    </div>

    <h3 class="mb-3">
        <i class="fa <?= $dashboard_icon ?> text-success"></i> <?= $dashboard_title ?>
    </h3>
    <hr>

    <!-- ================= MODULE CARDS ================= -->
    <div class="row g-2" align="center">
        <?php
        function moduleCard($link, $icon, $title, $color='bg-success'){
            echo '
            <div class="col-md-2">
                <a href="'.$link.'" class="text-decoration-none">
                    <div class="card card-module shadow-sm">
                        <div class="card-body text-center p-2">
                            <div class="icon-box '.$color.' mx-auto mb-1">
                                <i class="fa '.$icon.'"></i>
                            </div>
                            <h6>'.$title.'</h6>
                        </div>
                    </div>
                </a>
            </div>';
        }

        foreach($module_cards as $card){
            moduleCard($card['link'], $card['icon'], $card['title'], $card['color']);
        }
        ?>
    </div>

</div>

<?php include 'includes/footer.php'; ?>
