<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_category
 *
 * @copyright   (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;

$modShow = $params->get('show-link');
$modCat = $params->get('title-category');
$modMenu = $params->get('link-category');

?>
<div class="<?php echo $moduleclass_sfx; ?> mod-list-layout-1">
	<div class="container">
		<div class="row v-gutters">
			<?php if ($grouped) : ?>
				<?php foreach ($list as $groupName => $items) : ?>
					<?php $i=0; foreach ($items as $item) :$i++ ?>
						<div class="col <?php echo ($i==1) ? 'col-12 item-highlight' : 'col-12 col-md-4 item-child' ;?>" data-aos="fade-up" data-aos-delay="<?php echo $i ;?>00">
						<div class="item-article">
							<?php
								// Intro Image
								$introImage = json_decode($item->images)->image_intro;
							?>
							<!-- Intro Image -->
							<div class="article-media">
							<?php if($introImage) : ?>
								<div class="intro-image">
									<img src="<?php echo $introImage ;?>" alt="<?php echo $item->title; ?>" />
								</div>
							<?php endif ;?>
							</div>
							
							<div class="article-content">
								<div class="content-inner">
									<dl class="article-info">
										<?php if ($item->displayCategoryTitle) : ?>
											<dd class="category-name">
												<?php echo $item->displayCategoryTitle; ?>
											</dd>
										<?php endif; ?>

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

										<?php if ($item->displayHits) : ?>
											<dd class="mod-articles-category-hits">
												<?php echo Text::_('JGLOBAL_HITS').' '.$item->displayHits; ?>
											</dd>
										<?php endif; ?>

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

									<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>

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

									<?php if ($params->get('show_readmore')) : ?>
										<p class="mod-articles-category-readmore">
											<a class="mod-articles-category-title heading-link <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
												<i class="fas fa-play-circle"></i>

												<?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; ?>
								</div>
							</div>
						</div>
					</div>
					<?php endforeach; ?>
				<?php endforeach; ?>
			<?php else : ?>
				<?php $i=0; foreach ($list as $item) : $i++ ?>
					<div class="col <?php echo ($i==1) ? 'col-12 item-highlight' : 'col-12 col-md-4 item-child' ;?>" data-aos="fade-up" data-aos-delay="<?php echo $i ;?>00">
						<div class="item-article">
							<?php
								// Intro Image
								$introImage = json_decode($item->images)->image_intro;
							?>
							<!-- Intro Image -->
							<div class="article-media">
							<?php if($introImage) : ?>
								<div class="intro-image">
									<img src="<?php echo $introImage ;?>" alt="<?php echo $item->title; ?>" />
								</div>
							<?php endif ;?>
							</div>
							
							<div class="article-content">
								<div class="content-inner">
									<dl class="article-info">
										<?php if ($item->displayCategoryTitle) : ?>
											<dd class="category-name">
												<?php echo $item->displayCategoryTitle; ?>
											</dd>
										<?php endif; ?>

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

										<?php if ($item->displayHits) : ?>
											<dd class="mod-articles-category-hits">
												<?php echo Text::_('JGLOBAL_HITS').' '.$item->displayHits; ?>
											</dd>
										<?php endif; ?>

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

									<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>

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

									<?php if ($params->get('show_readmore')) : ?>
										<p class="mod-articles-category-readmore">
											<a class="mod-articles-category-title heading-link <?php echo $item->active; ?>" href="<?php echo $item->link; ?>">
												<i class="fas fa-play-circle"></i>

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

		<?php if($modShow && $modCat) :?>
		<div class="bottom-actions text-center" data-aos="fade-up" data-aos-delay="200">
			<a class="btn btn-primary" href="<?php  echo Route::_("index.php?Itemid={$modMenu}"); ?>" title="<?php echo $modCat ;?>">
					<?php echo $modCat ;?>
			</a>
		</div>
			<?php endif ;?>
	</div>
</div>
