<?php
/**
 * @package Sj Jobs Categories For Js Jobs
 * @version 1.0.0
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2015 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 *
 */

defined('_JEXEC') or die;

JHtml::stylesheet('modules/' . $module->module . '/assets/css/style.css');
if ($params->get('show_fontawesome', 1)) {
	JHtml::stylesheet('modules/' . $module->module . '/assets/css/font-awesome.min.css');
}
?>

<div class="sj_jsjob_categories">
	<?php if ($params->get('heading_title') != '') {?>
		<h3 class="sj-jsjob-categories__heading"><?php echo $params->get('heading_title', JText::_('Job Categories')); ?></h3>
	<?php }?>
	<div class="sj-jsjob-categories__content">
		<?php if (!empty($categories)) {?>
			<ul>
				<?php foreach ($categories as $cat) {?>
					<?php
						$categoryaliasid = JSModel::getJSModel('common')->removeSpecialCharacter($cat->categoryaliasid);
						$lnk_cat = JRoute::_('index.php?option=com_jsjobs&c=job&view=job&layout=jobs&cat='.$categoryaliasid.'&Itemid='.JFactory::getApplication()->input->getVar('Itemid', 0));
					?>
					<li>
						<a href="<?php echo $lnk_cat; ?>"><i class="fa fa-angle-right"></i> <?php echo $cat->cat_title; ?></a> <span class="count-jobs">(<?php echo JobsCategoreisHelper::getCountJobs($cat->id); ?>)</span>
						<?php if ($params->get('show_sub_category', 0) && JobsCategoreisHelper::getSubCategories($cat->id, $params)) {?>
							<?php $subcategories = JobsCategoreisHelper::getSubCategories($cat->id, $params); ?>
							<?php if ($subcategories) {?>
								<span class="fa fa-angle-up"></span>
								<ul>
									<?php foreach ($subcategories as $sub_cat) {?>
										<?php
											$subcategoryaliasid = JSModel::getJSModel('common')->removeSpecialCharacter($sub_cat->subcategoryaliasid);
											$lnk_subcat = JRoute::_('index.php?option=com_jsjobs&c=job&view=job&layout=jobs&cat='.$subcategoryaliasid.'&Itemid='.JFactory::getApplication()->input->getVar('Itemid', 0));
										?>
										<li><a href="<?php echo $lnk_subcat; ?>"><?php echo $sub_cat->title; ?></a> <span class="count-jobs">(<?php echo JobsCategoreisHelper::getCountJobs($sub_cat->id); ?>)</span></li>
									<?php }?>
								</ul>
							<?php }?>
						<?php }?>
					</li>
				<?php }?>
			</ul>
		<?php }else{?>
			<?php echo JText::_('Has no content to show!'); ?>
		<?php }?>
	</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
	var $element = $('.sj_jsjob_categories');
	$('span.fa-angle-up', $element).on('click', function() {
		if ($(this).hasClass('fa-angle-down')) {
			$(this).removeClass('fa-angle-down');
			$(this).next('ul').hide();
		}
		else {
			$(this).removeClass('fa-angle-down').addClass('fa-angle-down');
			$(this).next('ul').show();
		}
	})
})
</script>