	<!-- Side Nav -->
<?php
    $nav = [
        ['name' => '首页', 'id' => 'index', 'svg' => 'home', 'href' => '/'],
        ['name' => '快捷功能', 'id' => 'categories', 'svg' => 'category', 'sidenav' => [
            ['name' => '书籍列表', 'href' => '/lists'],
            ['name' => '书籍检索', 'href' => '/search']
        ]],
        ['name' => '用户中心', 'id' => 'users', 'svg' => 'profile', 'sidenav' => [
            ['name' => '个人资料', 'href' => '/user/info'],
            ['name' => '借书记录', 'href' => '/user/record']
        ]],
        ['name' => '管理中心', 'id' => 'admins', 'svg' => 'wishlist', 'sidenav' => [
            ['name' => '用户管理', 'href' => '/admin/users'],
            ['name' => '书籍管理', 'href' => '/admin/books'],
            ['name' => '库存管理', 'href' => '/admin/stock'],
            ['name' => '分类管理', 'href' => '/admin/categories'],
        ]]
    ];
?>
	<nav class="absolute lg:relative lg:flex lg:text-sm bg-indigo-darker lg:bg-transparent pin-l pin-r py-4 px-6 lg:pt-10 lg:pl-12 lg:pr-6 -mt-1 lg:mt-0 overflow-y-auto lg:w-1/5 lg:border-r z-40 hidden">
		<ul class="list-reset mb-8 w-full">
<?php
    foreach ($nav as $item) {
        if (isset($item['sidenav'])) {
            if ($item['id'] == 'admins' && !(isset($_SESSION['user']) && $_SESSION['user']['type'] == 1)) continue; ?>
			<li class="ml-2 mb-4">
				<div class="flex" id="sidenav-<?=$item['id']?>-trigger">
					<img src="/assets/img/<?=$item['svg']?>-default.svg" alt="<?=$item['svg']?>-icon" class="w-4 h-4 mr-2">
					<div class="hover:cursor-pointer text-white lg:text-indigo-darkest no-underline font-medium w-full relative">
						<?=$item['name']."\n"?>
						<div class="pointer-events-none absolute pin-y pin-r flex items-center px-1 text-grey-darker" id="sidenav-<?=$item['id']?>-icon">
							<svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
								<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
							</svg>
						</div>
					</div>
				</div>
				<ul class="text-grey lg:text-grey-dark list-reset leading-loose mt-2" id="sidenav-<?=$item['id']?>">
<?php           foreach ($item['sidenav'] as $sidenav) { ?>
					<?=gen_li_tag($sidenav['name'], $sidenav['href'])?>
<?php           } ?>
				</ul>
			</li>
<?php   } else { ?>
			<li class="ml-2 mb-4 flex">
				<img src="/assets/img/<?=$item['svg']?>-default.svg" alt="<?=$item['svg']?>-icon" class="w-4 h-4 mr-2">
				<div class="font-medium mobile-home-trigger">
				    <a class="hover:cursor-pointer text-white lg:text-indigo-darkest no-underline" href="<?=$item['href']?>"><?=$item['name']?></a>
				</div>
			</li>
<?php   }
    }
    
    function gen_li_tag($name, $href) {
        return $href == explode('?', $_SERVER['REQUEST_URI'])[0] ?
            '<li class="flex justify-between items-center transition-normal ml-1 border-l border-grey-dark pl-4 mobile-home-trigger">'.
                '<a class="no-underline text-indigo-lighter lg:text-indigo-darker font-medium hover:cursor-pointer" href="'.$href.'">'.
                    '<span>'.$name.'</span>'.
                '</a>'.
            '</li>'."\n":
            '<li class="transition-normal ml-1 border-l border-grey-dark pl-4">'.
                '<a class="no-underline text-white lg:text-grey-dark hover:text-indigo-dark hover:cursor-pointer" href="'.$href.'">'.$name.'</a>'.
            '</li>'."\n";
    }
?>
	</nav>
