<?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 class="mod-tour-list row row-cols-1 row-cols-lg-2 row-cols-xxl-3">
	<?php if ($grouped) : ?>
		<div class="alert alert-warning"><?php echo Text::_('TPL_NO_SUPPORT'); ?></div>
	<?php else : ?>
		<?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
				$introImage = json_decode($item->images)->image_intro;
			?>
			<div class="col">
				<div class="item-inner tour-item" data-aos="fade-up" data-aos-delay="<?php echo ($i+3)*100 ;?>">
						<div class="intro-image">
							<?php if($introImage) :?>
								<img src="<?php echo $introImage ;?>" alt="<?php echo $item->title; ?>" />
							<?php else : ?>
								<div class="blank-image"></div>
							<?php endif ;?>

							<?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 ;?>
						</div>

					<div class="info-article">
						<?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">
							<h4>
								<?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; ?>
							</h4>
						</div>

						<?php if($price) :?>
							<div class="tour-price">
								<?php echo $price ;?>
							</div>
						<?php endif ;?>

						<?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($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 ($item->displayCategoryTitle) : ?>
								<div class="category-article ms-sm-auto">
									<?php echo $item->displayCategoryTitle; ?>
								</div>
							<?php endif; ?>
						</div>
						<?php endif; ?>
					</div>
				</div>
			</div>
		<?php $i++; endforeach; ?>
	<?php endif; ?>
</div>


