<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_category
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\Registry\Registry;

defined('_JEXEC') or die;
?>
<div id="categories-module-<?php echo $module->id; ?>" class="mod-tour-slide">
	<div class="container">
		<?php if ($grouped) : ?>
			<div class="alert alert-warning"><?php echo Text::_('TPL_NO_SUPPORT'); ?></div>
		<?php else : ?>
			<div class="owl-carousel">
				<?php $i=0; foreach ($list as $item) : ?>
					<?php
						// Custom field
						$extrafields = new Registry($item->attribs);
						$price = $extrafields->get('price');
						$location = $extrafields->get('location');
						$person = $extrafields->get('person');
						$day = $extrafields->get('day');
						$tourInfo = $extrafields->get('tour-hot');

						// Intro Image
						$fullImage = json_decode($item->images)->image_fulltext;
						$introImage = json_decode($item->images)->image_intro;
						$bgIntro = '';

						if($fullImage) {
							$bgIntro = 'style="background-image: url('.$fullImage.');"';
						} elseif($introImage) {
							$bgIntro = 'style="background-image: url('.$introImage.');"';
						}
					?>
					<div class="col">
						<div class="item-inner tour-item" <?php echo $bgIntro ;?>>
							<div class="info-article">
								<?php if($tourInfo == 'featured') :?>
								<div class="label-featured tour-label">
									<i class="fas fa-star-of-david"></i> <?php echo Text::_('TPL_FEATURED_LABEL'); ?>
								</div>
								<?php elseif ($tourInfo == 'best') :?>
									<div class="label-best tour-label">
										<i class="fas fa-fire"></i> <?php echo Text::_('TPL_HOT_LABEL'); ?>
									</div>
								<?php endif ;?>

								<?php if($location) :?>
									<div class="item info-location">
										<i class="fas fa-map-marker-alt"></i>
										<?php echo $location ;?>
									</div>
								<?php endif ;?>

								<div class="mod-articles-title">
									<h2>
										<?php if ($params->get('link_titles') == 1) : ?>
											<a class="heading-link <?php echo $item->active; ?>" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a>
										<?php else : ?>
											<?php echo $item->title; ?>
										<?php endif; ?>
									</h2>
								</div>

								<?php if ($item->displayHits || $params->get('show_author') || $item->displayDate || ($params->get('show_tags', 0) && $item->tags->itemTags) ) : ?>
								<div class="tour-other-info my-2">
									<?php if ($item->displayHits) : ?>
										<span class="mod-articles-category-hits">
											(<?php echo $item->displayHits; ?>)
										</span>
									<?php endif; ?>

									<?php if ($params->get('show_author')) : ?>
										<span class="mod-articles-category-writtenby">
											<?php echo $item->displayAuthorName; ?>
										</span>
									<?php endif; ?>


									<?php if ($item->displayDate) : ?>
										<span class="mod-articles-category-date">
											<?php echo $item->displayDate; ?>
										</span>
									<?php endif; ?>

									<?php if ($params->get('show_tags', 0) && $item->tags->itemTags) : ?>
										<div class="mod-articles-category-tags">
											<?php echo LayoutHelper::render('joomla.content.tags', $item->tags->itemTags); ?>
										</div>
									<?php endif; ?>
								</div>
								<?php endif; ?>

								<?php if ($params->get('show_introtext')) : ?>
									<p class="mod-articles-category-introtext">
										<?php echo $item->displayIntrotext; ?>
									</p>
								<?php endif; ?>

								<?php if ($params->get('show_readmore')) : ?>
								<p class="mod-articles-category-readmore">
									<a class="mod-articles-category-title <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
										<?php if ($item->params->get('access-view') == false) : ?>
											<?php echo Text::_('MOD_ARTICLES_CATEGORY_REGISTER_TO_READ_MORE'); ?>
										<?php elseif ($readmore = $item->alternative_readmore) : ?>
											<?php echo $readmore; ?>
											<?php echo HTMLHelper::_('string.truncate', $item->title, $params->get('readmore_limit')); ?>
										<?php elseif ($params->get('show_readmore_title', 0) == 0) : ?>
											<?php echo Text::sprintf('MOD_ARTICLES_CATEGORY_READ_MORE_TITLE'); ?>
										<?php else : ?>
											<?php echo Text::_('MOD_ARTICLES_CATEGORY_READ_MORE'); ?>
											<?php echo HTMLHelper::_('string.truncate', $item->title, $params->get('readmore_limit')); ?>
										<?php endif; ?>
									</a>
								</p>
							<?php endif; ?>

							<?php if($person || $day || $item->displayCategoryTitle) :?>
							<div class="extra-info-tour">
								<?php if ($item->displayCategoryTitle) : ?>
									<div class="category-article">
										<?php echo $item->displayCategoryTitle; ?>
									</div>
								<?php endif; ?>

								<?php if($person) :?>
									<div class="item">
										<i class="fas fa-users"></i>
										<?php echo $person ;?>
									</div>
								<?php endif ;?>

								<?php if($day) :?>
									<div class="item">
										<i class="fas fa-clock"></i>
										<?php echo $day ;?>
									</div>
								<?php endif ;?>

								<?php if($price) :?>
									<div class="item">
										<i class="fas fa-tag"></i>
										<?php echo $price ;?>
									</div>
								<?php endif ;?>
							</div>
							<?php endif; ?>
							</div>
						</div>
					</div>
				<?php $i++; endforeach; ?>
			</div>
		<?php endif; ?>
	</div>
</div>


<script>
(function($){
  jQuery(document).ready(function($) {
    $("#categories-module-<?php echo $module->id; ?> .owl-carousel").owlCarousel({
      addClassActive: true,
      items: 1,
      margin: 32,
      loop: true,
      nav : false,
      dots: true,
      slideTransition: 'linear',
      autoplayHoverPause: true
    });
  });
})(jQuery);
</script>