<?php


/**
 * @package     SP Simple Portfolio
 * @subpackage  mod_spsimpleportfolio
 *
 * @copyright   Copyright (C) 2010 - 2018 JoomShaper. All rights reserved.
 * @license     GNU General Public License version 2 or later.
 */

defined('_JEXEC') or die;

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

HTMLHelper::_('jquery.framework');
HTMLHelper::_('bootstrap.framework');

jimport( 'joomla.filesystem.file' );
$layout_type = $params->get('layout_type', 'default');

?>

<div id="mod-sp-simpleportfolio<?php echo $module->id. '-' . str_replace(' ', '-', strtolower($module->title)); ?>" class="sp-simpleportfolio sp-simpleportfolio-view-items layout-<?php echo str_replace('_', '-', $layout_type); ?> <?php echo $moduleclass_sfx; ?>">

	<?php
		//Videos
		foreach ($items as $item) {
			if($item->video) {
				$video = parse_url($item->video);

				switch($video['host']) {
					case 'youtu.be':
					$video_id 	= trim($video['path'],'/');
					$video_src 	= '//www.youtube.com/embed/' . $video_id;
					break;

					case 'www.youtube.com':
					case 'youtube.com':
					parse_str($video['query'], $query);
					$video_id 	= $query['v'];
					$video_src 	= '//www.youtube.com/embed/' . $video_id;
					break;

					case 'vimeo.com':
					case 'www.vimeo.com':
					$video_id 	= trim($video['path'],'/');
					$video_src 	= "//player.vimeo.com/video/" . $video_id;
				}
				echo '<iframe class="sp-simpleportfolio-lightbox" src="'. $video_src .'" width="500" height="281" id="sp-simpleportfolio-video'.$item->spsimpleportfolio_item_id.'" style="border:none;" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
			}
		}
	?>
	
	<div id="spsimpleportfolio-slide<?php echo $module->id. '-' . str_replace(' ', '-', strtolower($module->title)); ?>" class="carousel slide" data-bs-ride="carousel">
		<div class="carousel-inner spsimpleportfolio-items" role="listbox">
			<?php foreach (array_chunk($items, $params->get('columns', 3)) as $chunk_key => $items) { ?>
			<?php $active = ($chunk_key == 0) ? 'active': '';?>
				<div class="carousel-item sp-row <?php echo $active; ?>">
					<?php foreach ($items as $item) { ?>
						<div class="sp-simpleportfolio-item col-md-<?php echo 12/$params->get('columns', 3); ?>">
							<div class="sp-simpleportfolio-item-wrap">
								<a href="<?php echo $item->url; ?>" class="full-link"></a>
								<div class="sp-simpleportfolio-overlay-wrapper">
									<?php if($item->video) { ?>
										<span class="sp-simpleportfolio-icon-video"></span>
									<?php } ?>
									<img class="sp-simpleportfolio-img" src="<?php echo $item->thumb; ?>" alt="<?php echo $item->title; ?>">
								</div>
	
								<div class="sp-simpleportfolio-info">
									<div class="sp-simpleportfolio-title-wrap">
										<h5 class="sp-simpleportfolio-title">
											<a href="<?php echo $item->url; ?>">
												<?php echo $item->title; ?>
											</a>
										</h5>
									</div>
								</div>
							</div>
						</div>
					<?php } ?>
				</div> <!-- /.carousel-item -->
			<?php } ?>
		</div> <!-- /.carousel-inner -->

		<button type=button  class="carousel-control-prev" data-bs-target="#spsimpleportfolio-slide<?php echo $module->id. '-' . str_replace(' ', '-', strtolower($module->title)); ?>"  data-bs-slide="prev">
			<span class="fa fa-arrow-left" aria-hidden="true"></span>
			<span class="sr-only"><?php echo Text::_('SP_PORTFOLIO_PREVIOUS');?></span>
		</button>
		<button type=button class="carousel-control-next" data-bs-target="#spsimpleportfolio-slide<?php echo $module->id. '-' . str_replace(' ', '-', strtolower($module->title)); ?>"  data-bs-slide="next">
			<span class="fa fa-arrow-right" aria-hidden="true"></span>
			<span class="sr-only"><?php echo Text::_('SP_PORTFOLIO_NEXT');?></span>
		</button>
	</div> <!-- /.spsimpleportfolioSlide -->

</div> <!--/#mod-sp-simpleportfolio -->