<?php
	$class = '';
	if (FreshRSS_Context::$user_conf->hide_read_feeds &&
			FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_NOT_READ) &&
			!FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_READ)) {
		$class = ' state_unread';
	}
?>

<div class="aside aside_feed<?php echo $class; ?>" id="aside_feed">
	<a class="toggle_aside" href="#close"><?php echo _i('close'); ?></a>

	<?php if (FreshRSS_Auth::hasAccess()) { ?>
	<div class="stick configure-feeds no-mobile">
		<a class="btn btn-important" href="<?php echo _url('subscription', 'index'); ?>"><?php echo _t('index.menu.subscription'); ?></a>
		<a class="btn btn-important" href="<?php echo _url('importExport', 'index'); ?>"><?php echo _i('import'); ?></a>
	</div>
	<?php } elseif (FreshRSS_Auth::accessNeedsLogin()) { ?>
	<a href="<?php echo _url('index', 'about'); ?>"><?php echo _t('index.menu.about'); ?></a>
	<?php } ?>

	<form id="mark-read-aside" method="post" style="display: none"></form>

	<ul class="tree">
		<li class="tree-folder category all<?php echo FreshRSS_Context::isCurrentGet('a') ? ' active' : ''; ?>">
			<div class="tree-folder-title">
				<?php echo _i('all'); ?> <a class="title" data-unread="<?php echo format_number(FreshRSS_Context::$total_unread); ?>" href="<?php echo _url('index', 'index'); ?>"><?php echo _t('index.menu.main_stream'); ?></a>
			</div>
		</li>

		<li class="tree-folder category favorites<?php echo FreshRSS_Context::isCurrentGet('s') ? ' active' : ''; ?>">
			<div class="tree-folder-title">
				<?php echo _i('bookmark'); ?> <a class="title" data-unread="<?php echo format_number(FreshRSS_Context::$total_starred['unread']); ?>" href="<?php echo _url('index', 'index', 'get', 's'); ?>"><?php echo _t('index.menu.favorites', format_number(FreshRSS_Context::$total_starred['all'])); ?></a>
			</div>
		</li>

		<?php
			foreach ($this->categories as $cat) {
				$feeds = $cat->feeds();
				if (!empty($feeds)) {
					$c_active = FreshRSS_Context::isCurrentGet('c_' . $cat->id());
					$c_show = $c_active && (!FreshRSS_Context::$user_conf->display_categories ||
					                        FreshRSS_Context::$current_get['feed']);
		?>
		<li class="tree-folder category<?php echo $c_active ? ' active' : ''; ?>" data-unread="<?php echo $cat->nbNotRead(); ?>">
			<div class="tree-folder-title">
				<a class="dropdown-toggle" href="#"><?php echo _i($c_show ? 'up' : 'down'); ?></a>
				<a class="title" data-unread="<?php echo format_number($cat->nbNotRead()); ?>" href="<?php echo _url('index', 'index', 'get', 'c_' . $cat->id()); ?>"><?php echo $cat->name(); ?></a>
			</div>

			<ul class="tree-folder-items<?php echo $c_show ? ' active' : ''; ?>">
				<?php
					foreach ($feeds as $feed) {
						$f_active = FreshRSS_Context::isCurrentGet('f_' . $feed->id());
				?>
				<li id="f_<?php echo $feed->id(); ?>" class="item feed<?php echo $f_active ? ' active' : ''; ?><?php echo $feed->inError() ? ' error' : ''; ?><?php echo $feed->nbEntries() <= 0 ? ' empty' : ''; ?>" data-unread="<?php echo $feed->nbNotRead(); ?>" data-priority="<?php echo $feed->priority(); ?>">
					<div class="dropdown no-mobile">
						<div class="dropdown-target"></div>
						<a class="dropdown-toggle" data-fweb="<?php echo $feed->website(); ?>"><?php echo _i('configure'); ?></a>
						<?php /* feed_config_template */ ?>
					</div>
					<img class="favicon" src="<?php echo $feed->favicon(); ?>" alt="✇" /> <a class="item-title" data-unread="<?php echo format_number($feed->nbNotRead()); ?>" href="<?php echo _url('index', 'index', 'get', 'f_' . $feed->id()); ?>"><?php echo $feed->name(); ?></a>
				</li>
				<?php } ?>
			</ul>
		</li>
		<?php
				}
			}
		?>
	</ul>
</div>

<script id="feed_config_template" type="text/html">
	<ul class="dropdown-menu">
		<li class="dropdown-close"><a href="#close">❌</a></li>
		<li class="item"><a href="<?php echo _url('index', 'index', 'get', 'f_------'); ?>"><?php echo _t('gen.action.filter'); ?></a></li>
		<?php if (FreshRSS_Auth::hasAccess()) { ?>
		<li class="item"><a href="<?php echo _url('stats', 'repartition', 'id', '------'); ?>"><?php echo _t('index.menu.stats'); ?></a></li>
		<?php } ?>
		<li class="item"><a target="_blank" href="http://example.net/"><?php echo _t('gen.action.see_website'); ?></a></li>
		<?php if (FreshRSS_Auth::hasAccess()) { ?>
		<li class="separator"></li>
		<li class="item"><a href="<?php echo _url('subscription', 'index', 'id', '------'); ?>"><?php echo _t('gen.action.manage'); ?></a></li>
		<li class="item"><a href="<?php echo _url('feed', 'actualize', 'id', '------'); ?>"><?php echo _t('gen.action.actualize'); ?></a></li>
		<li class="item">
			<?php $confirm = FreshRSS_Context::$user_conf->reading_confirm ? 'confirm' : ''; ?>
			<button class="read_all as-link <?php echo $confirm; ?>"
			        form="mark-read-aside"
			        formaction="<?php echo _url('entry', 'read', 'get', 'f_------'); ?>"
			        type="submit"><?php echo _t('gen.action.mark_read'); ?></button>
		</li>
		<?php } ?>
	</ul>
</script>
