<?php
/** @var yii\web\View $this */
/** @var string $content */

use yii\helpers\Html;
use yii\helpers\Url;

$user     = Yii::$app->user->identity;
$fullName = $user ? Html::encode($user->getFullName()) : 'User';
$isAdmin  = $user && $user->isAdmin();
$baseUrl  = Yii::$app->request->baseUrl;
?>
<?php $this->beginPage(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="<?= Html::encode(Yii::$app->charset) ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?= Html::encode($this->title ?? 'LMS') ?> | LMS</title>
    <?php $this->head(); ?>

    <link href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <link rel="stylesheet" href="<?= $baseUrl ?>/css/lms.css">
</head>
<body>
<?php $this->beginBody(); ?>

<!-- ====== HEADER ====== -->
<header class="lms-header">
    <div class="logo-text">
        <i class="fas fa-graduation-cap"></i> LMS
    </div>

    <div class="lms-header-user">
        <img src="https://ui-avatars.com/api/?name=<?= urlencode($fullName) ?>&background=0f3460&color=fff&size=64"
             alt="avatar">
        <div class="lms-dropdown">
            <div class="lms-dropdown-toggle" id="lmsUserToggle">
                <?= $fullName ?> &nbsp;<i class="fas fa-caret-down"></i>
            </div>
            <div class="lms-dropdown-menu" id="lmsUserMenu">
                <a href="<?= Url::to(['site/change-password']) ?>">
                    <i class="fas fa-key"></i> Change Password
                </a>
                <a href="#" onclick="document.getElementById('logout-form').submit(); return false;">
                    <i class="fas fa-sign-out-alt"></i> Logout
                </a>
            </div>
        </div>
    </div>
</header>

<!-- Hidden logout form (POST required by Yii CSRF) -->
<form id="logout-form" action="<?= Url::to(['site/logout']) ?>" method="post" style="display:none;">
    <input type="hidden" name="<?= Yii::$app->request->csrfParam ?>"
           value="<?= Yii::$app->request->csrfToken ?>">
</form>

<!-- ====== SIDEBAR ====== -->
<nav class="lms-sidebar">
    <ul>
        <li>
            <a href="<?= Url::to(['dashboard/index']) ?>">
                <i class="fas fa-tachometer-alt"></i> Dashboard
            </a>
        </li>
        <li>
            <a href="<?= Url::to(['courses/index']) ?>">
                <i class="fas fa-book-open"></i> Courses
            </a>
        </li>
        <li>
            <a href="<?= Url::to(['tags/index']) ?>">
                <i class="fas fa-tags"></i> Tags
            </a>
        </li>
        <li>
            <a href="<?= Url::to(['categories/index']) ?>">
                <i class="fas fa-sitemap"></i> Categories
            </a>
        </li>
        <li>
            <a href="<?= Url::to(['types/index']) ?>">
                <i class="fas fa-layer-group"></i> Types
            </a>
        </li>
        <li>
            <a href="<?= Url::to(['colour-scheme/index']) ?>">
                <i class="fas fa-palette"></i> Colour Schemes
            </a>
        </li>
        <li>
            <a href="<?= Url::to(['tenant/index']) ?>">
                <i class="fas fa-building"></i> Tenants
            </a>
        </li>
        <li>
            <a href="<?= Url::to(['enrolled-status/index']) ?>">
                <i class="fas fa-list-ol"></i> Enrolled Statuses
            </a>
        </li>
        <li>
            <a href="<?= Url::to(['assessment/index']) ?>">
                <i class="fas fa-clipboard-list"></i> Assessments
            </a>
        </li>
        <?php if ($isAdmin): ?>
        <li>
            <a href="<?= Url::to(['users/index']) ?>">
                <i class="fas fa-users"></i> Users
            </a>
        </li>
        <?php endif; ?>
    </ul>
</nav>

<!-- ====== PAGE CONTENT ====== -->
<div class="lms-content">

    <?php if (Yii::$app->session->hasFlash('success')): ?>
        <div class="lms-alert lms-alert-success" data-auto-dismiss>
            <i class="fas fa-check-circle"></i>
            <?= Html::encode(Yii::$app->session->getFlash('success')) ?>
        </div>
    <?php endif; ?>

    <?php if (Yii::$app->session->hasFlash('error')): ?>
        <div class="lms-alert lms-alert-danger" data-auto-dismiss>
            <i class="fas fa-exclamation-circle"></i>
            <?= Html::encode(Yii::$app->session->getFlash('error')) ?>
        </div>
    <?php endif; ?>

    <?= $content ?>
</div>

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="<?= $baseUrl ?>/js/lms.js"></script>
<?php $this->endBody(); ?>
</body>
</html>
<?php $this->endPage(); ?>
