<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * ADMIN SIDEBAR
 * Expects: $active (current controller class), $user.
 * Super-admin-only items are gated with $this->auth->is_super().
 */
$active = isset($active) ? strtolower($active) : 'dashboard';
$is_super = $this->auth->is_super();

/* nav structure: section => [ [class, url, label, icon, super_only] ] */
$nav = array(
	'Main' => array(
		array('dashboard', 'admin/dashboard', 'Dashboard', 'chart', FALSE),
	),
	'Content' => array(
		array('hero', 'admin/hero', 'Hero Slides', 'image', FALSE),
		array('services_admin', 'admin/services', 'Services', 'sparkle', FALSE),
		array('portfolio_admin', 'admin/portfolio', 'Portfolio', 'grid', FALSE),
		array('talent_admin', 'admin/talent', 'Talent Roster', 'star', FALSE),
		array('events_admin', 'admin/events', 'Events', 'calendar', FALSE),
		array('blog_admin', 'admin/blog', 'Journal', 'edit', FALSE),
		array('partners_admin', 'admin/partners', 'Partners', 'handshake', FALSE),
		array('testimonials_admin', 'admin/testimonials', 'Testimonials', 'quote', FALSE),
		array('team_admin', 'admin/team', 'Team', 'users', FALSE),
		array('pages_admin', 'admin/pages', 'Pages', 'film', FALSE),
		array('media', 'admin/media', 'Media Library', 'camera', FALSE),
	),
	'Engagement' => array(
		array('applications', 'admin/applications', 'Applications', 'inbox', FALSE),
		array('inquiries', 'admin/inquiries', 'Inquiries', 'mail', FALSE),
		array('tickets', 'admin/tickets', 'Event Tickets', 'ticket', FALSE),
	),
	'System' => array(
		array('users', 'admin/users', 'Admin Users', 'users', TRUE),
		array('settings', 'admin/settings', 'Settings', 'settings', TRUE),
	),
);

/* pending counts for badges */
$counts = isset($nav_counts) ? $nav_counts : array();
?>
<aside class="sidebar">
	<div class="sidebar-brand">
		<span class="mark">b</span>
		<span>
			<span class="name">Bloom Iris</span><br>
			<span class="sub">Admin Panel</span>
		</span>
	</div>

	<nav class="sidebar-nav">
		<?php foreach ($nav as $section => $items): ?>
			<?php
			// Hide a whole section if every item is super-only and user isn't super.
			$visible = array_filter($items, function ($it) use ($is_super) {
				return ! $it[4] || $is_super;
			});
			if (empty($visible)) continue;
			?>
			<div class="nav-section"><?= $section ?></div>
			<?php foreach ($visible as $it):
				list($cls, $url, $label, $icon, $super) = $it;
				$badge = isset($counts[$cls]) && $counts[$cls] > 0 ? $counts[$cls] : NULL;
			?>
				<a href="<?= base_url($url) ?>" class="nav-item <?= $active === $cls ? 'active' : '' ?>">
					<?= bloom_icon($icon, 18) ?>
					<span><?= $label ?></span>
					<?php if ($badge): ?><span class="badge"><?= $badge ?></span><?php endif; ?>
				</a>
			<?php endforeach; ?>
		<?php endforeach; ?>
	</nav>

	<div class="sidebar-foot">
		<a href="<?= base_url() ?>" target="_blank" class="nav-item">
			<?= bloom_icon('arrow', 18) ?> <span>View Website</span>
		</a>
		<a href="<?= base_url('admin/login/logout') ?>" class="nav-item">
			<?= bloom_icon('logout', 18) ?> <span>Sign Out</span>
		</a>
	</div>
</aside>
