<?php
/**
 * @package     SP Soccer
 * @author      JoomShaper http://www.joomshaper.com
 * @copyright   Copyright (C) 2010 - 2016 JoomShaper. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die('Restricted access');

// Get Columns
$columns = $this->params->get('columns', 2);

if(count($this->items)) {
	$menu 	= JFactory::getApplication()->getMenu();
	$itemId = '';
	if(is_object($menu->getActive())) {
		$active = $menu->getActive();
		$itemId = '&Itemid=' . $active->id;
	}
}

$slide_item = 6;

?>

<div id="spsoccer" class="spsoccer view-spsoccer-tournaments">
	<!-- START Tournament Caoursel -->
	<div id="trounament-carousel" class="sppb-carousel sppb-slide spsoccer-tournament-carousel" data-ride="sppb-carousel">		
		<!-- Wrapper for slides -->
		<div class="sppb-carousel-inner">
			<?php $this->slide_no = 1;
			$slides = 1;
			$loaded_item = array();
			foreach(array_chunk($this->items, 3) as $chunk_key => $this->slide_items) { ?>
			<div class="sppb-item <?php echo ($chunk_key == 0) ? 'active': ''; ?>">
				<div class="sppb-row">
					<?php foreach ($this->slide_items as $key => $this->item) { 
						  $loaded_item [] =  $this->item->spsoccer_tournament_id;
						?>
						<div class="sppb-col-sm-4">
							<div class="spsoccer-tournament-content-warp">
								<div class="spsoccer-tournament-img-wrap">
									<img src="<?php echo $this->item->image; ?>" alt="<?php echo $this->item->title; ?>">
								</div>
								<div class="spsoccer-text-content">
									<h3><a href="<?php echo $this->item->url; ?>"><?php echo $this->item->title; ?></a></h3>
									<p>
										<span class="spsoccer-tournament-yerar">Year: <?php echo $this->item->year; ?><br></span>
										<span class="spsoccer-tournament-region">Region: <?php echo $this->item->region; ?><br></span>
										<span class="spsoccer-tournament-number">Number: <?php echo $this->item->teams; ?></span>
									</p>
								</div>
							</div>
						</div>
						<?php if($this->slide_no==$slide_item) {
							break;
						}?>
					<?php $this->slide_no++; } ?>
				</div><!-- End row -->
			</div> <!-- End sppb-item -->
			<?php if($this->slide_no==$slide_item) {
				break;
			}?>
			<?php $slides++; } ?>
		</div>
		<!-- Indicators -->
		<ol class="sppb-carousel-indicators"></ol>
	</div>
	<!-- END Touranament Carousel -->

	<div class="spsoccer-row">
		<div class="spsoccer-col-lg-12">
			<h3 class="spsoccer-more-tournaments-title"><?php echo JText::_('COM_SOSOCCER_TEAM_MORE_TOURNAMENTS');?></h3>
		</div>
	</div>

	<?php
	foreach ($this->items as $key => $this->item){
		if (in_array($this->item->spsoccer_tournament_id, $loaded_item)) {
			unset($this->items[$key]);
		}
	}
	?>
	<!-- Column -->
	<?php foreach(array_chunk($this->items, $columns) as $this->items) { ?>
		<div class="spsoccer-row">
			<?php foreach ($this->items as $item_key => $this->item) { ?>
			<?php if (!in_array($this->item->spsoccer_tournament_id, $loaded_item)) { ?>
				<!-- START:: SP Soccer Tournaments -->
				<div class="spsoccer-col-lg-<?php echo round(12/$columns); ?> spsoccer-col-md-6 spsoccer-col-sm-12">
					<div class="spsoccer-row">
						<div class="spsoccer-tournament-name">
							<div class="tournament-image spsoccer-col-sm-6">
								<a href="<?php echo $this->item->url; ?>">
									<img class="spsoccer-img spsoccer-img-responsive" src="<?php echo $this->item->image; ?>" alt="<?php echo $this->item->title; ?>">
								</a>
							</div>
								<div class="tournament-details spsoccer-col-sm-6">
									<a href="<?php echo $this->item->url; ?>">
										<h3><?php echo $this->item->title; ?></h3>
									</a>
									<h4>
										<span class="title">year: </span>
										<span><?php echo $this->item->year; ?></span>
									</h4>
									<h4>
										<span class="title">Region: </span>
										<span><?php echo $this->item->region; ?></span>
									</h4>
									<h4>
										<span class="title">Number of teams: </span>
										<span><?php echo $this->item->teams; ?></span>
									</h4>
							</div>
						</div>
					</div>
				</div> <!-- /Column -->
				<!-- END:: SP Soccer Tournaments -->
			<?php } //check loaded item?>
			<?php } ?>
		</div>
	<?php } ?>
		

	<!-- START:: Pagination -->
	<?php if ($this->params->get('show_pagination', 1)) { ?>
		<?php if ($this->pagination->get('pages.total') >1) { ?>
			<div class="soccer-pagination">
				<?php echo $this->pagination->getPagesLinks(); ?>
			</div>
		<?php } ?>
	<?php } ?>
	<!-- END:: Pagination -->
</div>
