<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_related_items
 *
 * @copyright   (C) 2006 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\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\Registry\Registry;

?>
<div class="relateditems <?php echo $moduleclass_sfx; ?> mod-list type-2">
    <div class="row">
        <?php foreach ($list as $item) : ?>
            <?php
                $extrafields = new Registry($item->attribs);

                $price = $extrafields->get('price');
                $person = $extrafields->get('person');
                $day = $extrafields->get('day');
                $location = $extrafields->get('location');    
            ?>
            <div class="col-12 col-md-6 col-lg-4 item">  
                <?php  
                $images = "";
                if (isset($item->images)) {
                    $images = json_decode($item->images);
                }

                $imgexists = (isset($images->image_intro) and !empty($images->image_intro)) || (isset($images->image_fulltext) and !empty($images->image_fulltext));
                
                if ($imgexists) {           
                    $images->image_intro = $images->image_intro?$images->image_intro:$images->image_fulltext;
                }
                ?>

                <div class="tour-item">
                    <div class="intro-image">
                        <figure class="pull-left item-image">
                            <img src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo $item->title; ?>" />
                        </figure>
                    </div>

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

                            <div class="page-header">
                                <h2 itemprop="headline">
                                    <a class="mod-articles-category-title heading-link" href="<?php echo $item->route; ?>"><?php echo $item->title; ?></a>
                                </h2>
                            </div>

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

                        <div class="extra-info-tour">

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

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