<?php
/**
 * @package    WT JoomShopping last seen products
 * @author     Sergey Tolkachyov, info@web-tolk.ru https://web-tolk.ru
 * @copyright  Copyright (C) 2021 Sergey Tolkachyov. All rights reserved.
 * @license    GNU General Public License version 3 or later
 */

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;

/*
 * Available products data you can echo
 *	$product->product_id
 *	$product->category_id
 *	$product->name
 *	$product->short_description
 *	$product->product_ean
 *	$product->manufacturer_code
 *	$product->image					full image url (thumb)
 *	$product->product_name_image					full image name without url
 *	$product->product_thumb_image					thumb image name without url
 *	$product->product_price
 *	$product->product_old_price
 *	$product->product_old_price
 *	$product->product_weight
 *	$product->average_rating
 *	$product->reviews_count
 *	$product->hits
 *	$product->template_block_product
 *	$product->product_link
 *	$product->buy_link
 *	$product->unlimited
 *
 *
 *	Try
 * */
//echo '<pre>';
//print_r($products);
//echo '</pre>';
/**
 * to see all products data
 */




if (!empty($products)) : ?>
	<div class="jshop last_seen_products d-flex flex-nowrap flex-lg-wrap overflow-auto">
		<?php
		$i = 0;
		foreach ($products as $product) : ?>
			<?php if ($params->get('products_count') > $i) : ?>
				<article class="block_item p-0">
					<div class="card h-100">
						<div class="row g-0">
							<?php if ($params->get('show_image', 1)) : ?>
								<div class="item_image col-12 col-md-4 p-1 d-flex justify-content-center">
									<?php if (property_exists($product,'_label_image')) : ?>
										<div class="product_label">

											<img src="<?php echo $product->_label_image ?>"
												 alt="<?php echo $product->_label_name ?>"/>
										</div>
									<?php endif; ?>
									<a href="<?php echo $product->product_link; ?>" class="stretched-link">

										<?php
										$img_options = [
											'title'   => $product->name,
											'loading' => 'lazy',
											'class'=>'img-fluid'
										];
										if($jshopConfig->image_product_width > 0){
											$img_options['width'] = $jshopConfig->image_product_width;
										}
										if($jshopConfig->image_product_height > 0){
											$img_options['height'] = $jshopConfig->image_product_height;
										}
										echo HTMLHelper::image($product->image,$product->name,$img_options);
										?>
									</a>
								</div>
							<?php endif; ?>
							<div class="col-12 col-md-8">
								<div class="card-body d-flex flex-column justify-content-center">
									<?php if ($params->get('show_name', 1)) : ?>
										<div class="item_name mt-auto text-center">
											<a href="<?php echo $product->product_link ?>"><h6><?php echo $product->name ?></h6></a>
										</div>
									<?php endif; ?>
									<?php if ($params->get('show_price', 1)) : ?>
										<?php if ($params->get('show_old_price', 1) && !empty($product->product_old_price)) : ?>
											<s class="text-center"><?php echo \JSHelper::formatprice($product->product_old_price); ?></s>
										<?php endif; ?>
										<?php if (!empty($product->product_price)) : ?>
											<div class="item_price h3 text-center">
												<?php echo \JSHelper::formatprice($product->product_price); ?>
											</div>
										<?php endif; ?>
									<?php endif; ?>
								</div>
								<?php if ($params->get('show_buy_button', 0) && !empty($product->buy_link)) : ?>
									<div class="card-footer d-flex bg-white border-0 justify-content-center">
										<a href="<?php echo $product->buy_link; ?>"
										   class="btn btn-primary"><?php echo Text::_('JSHOP_BUY'); ?></a>
									</div>
								<?php endif; ?>
							</div>
						</div>
					</div>
				</article>
				<?php $i++; ?>
			<?php endif; ?>
		<?php endforeach; ?>
	</div>
<?php else : ?>
	<?php echo Text::_('MOD_WTJSHOPPINGLASTSEENPRODUCTS_NO_PRODUCTS'); ?>
<?php endif; ?>
