<?php 
    require PATH . '/config/array.config.php';
    $ProfileRank    = ranked((int)$AuthUser['xp'],$Rank); 
    $ArrayId        = array_search($ProfileRank['level'], array_column($Rank, 'level'))+1;
    $ArrayId        = ($ArrayId >= count($Rank) ? array_key_last($Rank) : $ArrayId);
    if(isset($ArrayId) AND $ArrayId < count($Rank)){
        $NextRank           = $Rank[$ArrayId];
        if($AuthUser['xp'] > $NextRank['xp']) {
            $HeaderProgressBar  = 100;
        } else {
            $HeaderProgressBar  = 100 * ((int)$AuthUser['xp'] - $ProfileRank['xp']) / ($NextRank['xp'] - $ProfileRank['xp']);  
        }
    }
?>
<div class="layout-sidenav sticky" id="aside" aria-hidden="true">
    <div class="nav-sidenav h-100 m-0 modal-dialog">
        <div class="navbar text-gray-600 pe-xl-3">
            <a href="<?php echo APP.'/admin';?>" class="navbar-brand text-gray-900">
                <img src="<?php echo ASSETS.'/img/logo.svg';?>" height="20">
            </a>
            <a href="<?php echo APP;?>" class="ms-auto btn btn-square btn-sm btn-ghost rounded-circle shadow-none" target="_blank" data-bs-tooltip="tooltip" data-bs-placement="bottom" title="<?php echo $this->translate('Go Frontend');?>">
                <svg width="16" height="16" stroke="currentColor" stroke-width="1.75" fill="none">
                    <use xlink:href="<?php echo ASSETS.'/sprite/sprite.svg#earth';?>"></use>
                </svg>
            </a>
            <button type="button" class="btn-close d-block d-lg-none shadow-none ms-4" data-bs-dismiss="modal" data-bs-target="#aside" aria-label="Close"></button>
        </div>
        <!-- Flex nav content -->
        <div class="flex scrollable hover">
            <div class="nav-border text-gray-700" data-nav>
                <ul class="nav fs-sm">
                    <?php
                        $Count['reports']   = $this->db->from(null,'SELECT count(reports.id) as total FROM `reports` WHERE status = 2')->total(); 
                        $Count['comments']  = $this->db->from(null,'SELECT count(comments.id) as total FROM `comments` WHERE status = 2')->total(); 
                        require_once PATH . '/config/menu.config.php';
                        echo nav($DashboardNav, isset($Config['nav']) ? $Config['nav'] : null, $Count);
                    ?>
                </ul>
            </div>
        </div>
        <!-- sidenav bottom -->
        <div class="no-shrink mt-auto d-flex align-items-center text-body">
            <div class="text-muted fs-xs">Version
                <?php echo VERSION;?>
            </div>
        </div>
    </div>
</div>
<div class="layout-content">
    <div class="navbar navbar-expand-lg layout-header navbar-light ps-xl-3">
        <div class="collapse navbar-collapse" id="navbarToggler">
            <?php if(isset($Config['search'])) { ?>
            <form class="form-light ms-xl-auto w-xl-200" method="post">
                <input type="hidden" name="_ACTION" value="filter">
                <div class="input-group input-group-inline">
                    <span class="input-group-text bg-transparent border-0 shadow-none ps-0 pe-3">
                        <svg width="18" height="18" stroke="currentColor" stroke-width="2" fill="none">
                            <use xlink:href="<?php echo ASSETS.'/sprite/sprite.svg#search';?>"></use>
                        </svg>
                    </span>
                    <input type="text" name="q" class="form-control shadow-none bg-transparent border-0 ps-1" id="search" placeholder="<?php echo $this->translate('Search');?> .." aria-label="Search">
                </div>
            </form>
            <?php } ?>
        </div>
        <button class="navbar-toggler border-0 shadow-none" type="button" data-bs-toggle="modal" data-bs-target="#aside" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <a href="" class="navbar-brand d-block d-lg-none">
            <img src="<?php echo ASSETS.'/img/logo.svg';?>" height="20">
        </a>
        <ul class="nav navbar-menu align-items-center">
            <li class="nav-item">
                <a href="<?php echo APP.'/admin/clear-cache';?>" class="nav-link" data-bs-tooltip="tooltip" data-bs-placement="bottom" title="<?php echo $this->translate('Clear cache');?>">
                    <svg width="20" height="20" fill="currentColor">
                        <use xlink:href="<?php echo ASSETS.'/sprite/sprite.svg#speed';?>"></use>
                    </svg>
                </a>
            </li>
            <!-- User dropdown menu -->
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle d-flex align-items-center py-0 px-3" role="button" id="Profile" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <?php echo gravatar($AuthUser['id'],$AuthUser['username'],$AuthUser['avatar'],'avatar avatar-sm text-white rounded-circle',$AuthUser['color']);?>
                    <div class="ps-3 d-none d-lg-block lh-xs">
                        <div class="fs-xs text-muted">
                            <?php echo $this->translate('Hello');?>,</div>
                        <div class="fs-xs fw-semibold">
                            <?php echo $AuthUser['name'];?>
                        </div>
                    </div>
                </a>
                <div class="dropdown-menu dropdown-menu-end dropdown-menu-md shadow border-0 mt-3 py-4 px-3 rounded-3" aria-labelledby="Profile">
                    <div class="px-3">
                        <div class="row align-items-center mb-3">
                            <div class="col-8">
                                <div class="fs-xs text-heading fw-semibold">
                                    <?php echo $ProfileRank['name'];?>
                                </div>
                                <div class="fs-xxs text-muted fw-bold">
                                    <?php echo $ProfileRank['xp'].' XP';?>
                                </div>
                                <div class="progress mt-2 bg-gray-200" style="height: 6px;">
                                    <div class="progress-bar progress-xp rounded-pill" role="progressbar" style="width: <?php echo $HeaderProgressBar ?>%" aria-valuenow="<?php echo $HeaderProgressBar ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                </div>
                            </div>
                            <div class="col-4">
                                <img src="<?php echo LOCAL.'/rank/'.$ProfileRank['level'].'.svg';?>" class="img-fluid">
                            </div>
                        </div>
                    </div>
                    <a class="dropdown-item fs-sm" href="<?php echo user($AuthUser['id'],$AuthUser['username']);?>">
                        <?php echo $this->translate('Profile');?>
                    </a>
                    <a class="dropdown-item fs-sm" href="<?php echo user($AuthUser['id'],$AuthUser['username']).'/like';?>">
                        <?php echo $this->translate('Liked games');?>
                    </a>
                    <a class="dropdown-item fs-sm" href="<?php echo user($AuthUser['id'],$AuthUser['username']).'/playing';?>">
                        <?php echo $this->translate('Keep playing');?>
                    </a>
                    <a class="dropdown-item fs-sm" href="<?php echo user($AuthUser['id'],$AuthUser['username']).'/comments';?>">
                        <?php echo $this->translate('Comments');?>
                    </a>
                    <div class="mt-3"></div>
                    <a class="dropdown-item fs-sm" href="<?php echo APP.'/dashboard/settings';?>">
                        <?php echo $this->translate('Settings');?>
                    </a>
                    <a class="dropdown-item fs-sm" href="<?php echo APP.'/logout';?>">
                        <?php echo $this->translate('Logout');?>
                    </a>
                </div>
            </li>
        </ul>
    </div>
    <div class="">