<?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');
?>
<div id="spsoccer" class="spsoccer view-spsoccer-tournament">
	<div class="spsoccer-tournament">
		<div class="spsoccer-row">
			<div class="tournament-details-top" <?php echo $this->match_banner; ?> >
				<div class="color-overlay">
					<div class="spsoccer-container">
						<?php if (!empty($this->last_played_match)) {?>

							<div class="match-time">
								<span><?php echo JText::_('COM_SPSOOCER_LAST_MATCH_PLAYED'); ?> - <?php echo JHtml::date($this->last_played_match->date, 'd M Y'); ?></span>
							</div>
							<div class="match-result">
								<div class="spsoccer-col-sm-5 text-left">
									<img class="match-result-logo-thumb" src="<?php echo $this->last_played_match->teamone_logo; ?>">
									<h3><?php echo $this->last_played_match->teamone_name; ?></h3>
								</div>
								<div class="spsoccer-col-sm-2 text-center">
									<h3><?php echo $this->last_played_match->teamone_score . ' : ' . $this->last_played_match->teamtwo_score; ?></h3>
								</div>
								<div class="spsoccer-col-sm-5 text-right">
									<h3><?php echo $this->last_played_match->teamtwo_name; ?></h3>
									<img class="match-result-logo-thumb" src="<?php echo $this->last_played_match->teamtwo_logo; ?>">
								</div>
							</div>
							<?php } else{ ?>
								<div class="match-result text-center">
									<h2><?php echo JText::_('COM_SPSOOCER_NO_MATCH_PLAYED'); ?></h2>
								</div>
							<?php } ?>
					</div>
			</div>
			</div>
		</div>

		<div class="spsoccer-container">

			<div class="spsoccer-row-fluid">
				<div class="torunament-info">
					<div class="tournament-header">
						<h2 class="soccer-title"><?php echo $this->item->title; ?></h2>
					</div>
				</div> <!-- /.spsoccer-col-lg -->
			</div> <!-- /.spsoccer-row -->


			<div class="tournament-details-tab" role="tabpanel">

			<!-- Nav tabs -->
				<ul class="nav nav-tabs" role="tablist">

					<li role="presentation" class="active">
						<a href="#tournament-group" aria-controls="tournament-group" role="tab" data-toggle="tab">
							<h2 class="text-center"><?php echo JText::_('COM_SPSOOCER_GROUPS'); ?></h2>
						</a>
					</li>

					<li role="presentation">
						<a href="#tournament-fixture" aria-controls="tournament-fixture" role="tab" data-toggle="tab">
							<h2 class="text-center"><?php echo JText::_('COM_SPSOOCER_FIXTURE'); ?></h2>
						</a>
					</li>
					<li role="presentation">
						<a href="#tournament-result" aria-controls="tournament-result" role="tab" data-toggle="tab">
							<h2 class="text-center"><?php echo JText::_('COM_SPSOOCER_RESULTS'); ?></h2>
						</a>
					</li>
					<li role="presentation">
						<a href="#tournament-standing" aria-controls="tournament-standing" role="tab" data-toggle="tab">
							<h2 class="text-center"><?php echo JText::_('COM_SPSOOCER_STANDINGS'); ?></h2>
						</a>
					</li>
				</ul>

			<!-- Tab panes -->
				<div class="tab-content">

					<div role="tabpanel" class="tab-pane active" id="tournament-group">
						<!-- has Groups -->
						<?php if(!empty($this->groups) && $this->show_group) {
							$i = 1;
						 	foreach ($this->groups as $this->group) { ?>
							<div class="spsoccer-group-wrapper <?php echo $this->group->ungroup; ?>">
								<h3 class="text-center title"><span><?php echo $this->group->title; ?></span></h3>
								<div class="item-list-wrap">
									<?php foreach ($this->group->groups_teams_info as $this->group_team_infos) {
										$this->group_team_infos['team_logo'] = SpsoccerHelper::hasImg($this->group_team_infos['team_logo']);
										?>

										<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 child-<?php echo $i; ?>">

											<a href="<?php echo $this->group_team_infos['team_url']; ?>">
											<?php if ($i != 3) { ?>
												<div class="club-name">
													<img class="spsoccer-img-thumbnail spsoccer-img-responsive" src="<?php echo $this->group_team_infos['team_logo']; ?>" alt="<?php echo $this->group_team_infos['team_name']; ?>">
													<span class="spsoccer-team-name"><?php echo $this->group_team_infos['team_name']; ?></span>
												</div>
											<?php } elseif ($i == 3) {?>
												<div class="club-name">
													<img class="spsoccer-img-thumbnail spsoccer-img-responsive" src="<?php echo $this->group_team_infos['team_logo']; ?>" alt="<?php echo $this->group_team_infos['team_name']; ?>">
													<span class="spsoccer-team-name"><?php echo $this->group_team_infos['team_name']; ?></span>
												</div>

											<?php } ?>
											</a>

										</div> <!-- /.spsoccer-col-lg -->

									<?php

										if ($i == 3){ $i = 0; }
											$i++;
										} // END:: forech $group_teams_infos ?>
								</div> <!-- ./spsoccer-row -->
							</div> <!-- ./spsoccer-group-wrapper -->
							<?php } // END:: forech $this->groups ?>
						<?php } // END:: !empty groups ?>
				  	</div> <!-- ./tournament-group -->

				  	<div role="tabpanel" class="tab-pane" id="tournament-fixture">
				  		<!-- has Sessions -->
							<?php if(!empty($this->sessions)) {?>

								<?php
									foreach ($this->sessions as $session) {
									// has session matches
									if (!empty($session->session_matches)) {
								?>
								<div class="spsoccer-fixture-wrapper">
									<h3 class="text-center title"><span><?php echo $session->title; ?></span></h3>

									<?php foreach ($session->session_matches as $session_match) {
										$session_match->team_two_info->logo = SpsoccerHelper::hasImg($session_match->team_two_info->logo);

										?>

										<!-- START:: fixture -->
										<div class="item-list-wrap">

											<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 text-left">
												<img class="spsoccer-img-thumbnail spsoccer-img-responsive" src="<?php echo $session_match->team_one_info->logo; ?>" alt="<?php echo $session_match->team_one_info->title; ?>">
												<span class="spsoccer-team-name"><?php echo $session_match->team_one_info->title; ?></span>
											</div> <!-- /.spsoccer-col-lg -->

											<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 text-center">
												<div class="spsoccer-match-date-time">
													<span><?php echo $session_match->match_date; ?></span>,
													<span><?php echo $session_match->match_time; ?></span>
												</div>
												<p class="spsoccer-match-location">
													<?php echo $session_match->match_location->title; ?>
												</p>
											</div><!-- /.spsoccer-col-lg -->

											<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 text-right">
												<span class="spsoccer-team-name"><?php echo $session_match->team_two_info->title; ?></span>
												<img class="spsoccer-img-thumbnail spsoccer-img-responsive" src="<?php echo $session_match->team_two_info->logo; ?>" alt="<?php echo $session_match->team_two_info->title; ?>">
											</div><!-- /.spsoccer-col-lg -->

										</div>
										<!-- /.spsoccer-row -->

										<?php //print_r($session_match); ?>

									<?php } // END:: forech $session_matches ?>
								</div> <!-- ./spsoccer-group-wrapper -->
								<?php } // END:: has session match  ?>
								<?php } // END:: forech $this->sessions  ?>
							<?php } // END:: !empty sessions ?>

				  	</div> <!-- /.tournament-fixture -->


				  	<div role="tabpanel" class="tab-pane" id="tournament-result">
						<!-- has match is played -->
						<?php if(!empty($this->sessions)) {?>

							<?php foreach ($this->sessions as $session) {
								// Has match session
								if (!empty($session->played_matches)) {

									$session->title = (strpos($this->group->slug, 'uncategory') !== FALSE) ? JText::_('COM_SPSOOCER_RESULTS') : $session->title;
							?>
							<div class="spsoccer-result-wrapper">
								<h3 class="text-center title"><span><?php echo $session->title; ?></span></h3>
								<?php foreach ($session->played_matches as $session_played_match) {
									$session_played_match->team_one_info->logo = SpsoccerHelper::hasImg($session_played_match->team_one_info->logo);
									$session_played_match->team_two_info->logo = SpsoccerHelper::hasImg($session_played_match->team_two_info->logo);
								?>

								<!-- START:: fixture -->
								<div class="item-list-wrap">

									<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 text-left">
										<a href="<?php echo $session_played_match->url; ?>">
											<img class="spsoccer-img-thumbnail spsoccer-img-responsive" src="<?php echo $session_played_match->team_one_info->logo; ?>" alt="<?php echo $session_played_match->team_one_info->title; ?>">
											<span class="spsoccer-team-name"><?php echo $session_played_match->team_one_info->title; ?></span>
										</a>
									</div> <!-- /.spsoccer-col-lg -->

									<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 text-center">

										<h2><?php echo $session_played_match->teamone_score . ' : ' . $session_played_match->teamtwo_score; ?></h2>

										<div class="spsoccer-match-date-time">
											<span><?php echo $session_played_match->match_date; ?></span>,
											<span><?php echo $session_played_match->match_time; ?></span>
										</div>
										<p class="spsoccer-match-location">
											<?php echo $session_played_match->match_location->title; ?>
										</p> <!-- /.spsoccer-match-location-->

									</div><!-- /.spsoccer-col-lg -->

									<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 text-right">
										<a href="<?php echo $session_played_match->url; ?>">
											<span class="spsoccer-team-name"><?php echo $session_played_match->team_two_info->title; ?></span>
											<img class="spsoccer-img-thumbnail spsoccer-img-responsive" src="<?php echo $session_played_match->team_two_info->logo; ?>" alt="<?php echo $session_played_match->team_two_info->title; ?>">
										</a>
									</div><!-- /.spsoccer-col-lg -->

								</div>
								<!-- END:: fixture -->
								<!-- /.spsoccer-row -->

								<?php //print_r($session_played_match); ?>

								<?php } // END:: forech $session_matches ?>
							</div> <!-- ./spsoccer-group-wrapper -->
								<?php } // END:: has session match  ?>
								<?php } // END:: forech $this->sessions  ?>
								<?php } // END:: !empty sessions ?>
				  	</div>	<!-- /.tournament-result -->



				  	<div role="tabpanel" class="tab-pane" id="tournament-standing">

				  		<!-- has Standings -->
						<div class="spsoccer-standings-wrapper">

							<div class="pointboard-header">
								<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 header-left spsoccer-col-xs-5">
									<ul>
										<li><?php echo JText::_('COM_SPSOOCER_POSITION'); ?></li>
										<li><?php echo JText::_('COM_SPSOOCER_TEAM'); ?></li>
									</ul>
								</div>
								<div class="spsoccer-col-lg-8 spsoccer-col-md-8 spsoccer-col-sm-12 header-right spsoccer-col-xs-7">
									<ul>
										<li><?php echo JText::_('COM_SPSOOCER_STANDINGS_P'); ?></li>
										<li><?php echo JText::_('COM_SPSOOCER_STANDINGS_W'); ?></li>
										<li><?php echo JText::_('COM_SPSOOCER_STANDINGS_D'); ?></li>
										<li><?php echo JText::_('COM_SPSOOCER_STANDINGS_L'); ?></li>
										<li><?php echo JText::_('COM_SPSOOCER_STANDINGS_GF'); ?></li>
										<li><?php echo JText::_('COM_SPSOOCER_STANDINGS_GA'); ?></li>
										<li><?php echo JText::_('COM_SPSOOCER_STANDINGS_AVG'); ?></li>
										<li><?php echo JText::_('COM_SPSOOCER_STANDINGS_PTS'); ?></li>
									</ul>
								</div>
							</div>

							<?php
							// start countig team
							foreach ($this->groups as $sgroup) {
								if(!empty($sgroup->point_tables )){

								if ($this->sgroup->uncategory == false) { ?>
								<div class="item-list-wrap text-center">
									<h3><?php echo $sgroup->title; ?></h3>
								</div>
							<?php
								} // END:: $this->sgroup->uncategory
								// has point table
								if (!empty($sgroup->point_tables)) {
								$item_no = 1;
								foreach ($sgroup->point_tables as $point_table){

								$point_table['team_logo'] = SpsoccerHelper::hasImg($point_table['team_logo']);
							?>

							<div class="item-list-wrap">

								<div class="spsoccer-col-lg-4 spsoccer-col-md-4 spsoccer-col-sm-12 spsoccer-col-xs-5 team-position">
									<div class="teamthumb">
										<div class="inline-block">
											<p><?php echo $item_no; ?></p>
										</div>
										<img class="spsoccer-img-thumbnail spsoccer-img-responsive" src="<?php echo $point_table['team_logo']; ?>" alt="<?php echo $point_table['team_name']; ?>">
										<span class="spsoccer-team-name"><?php echo $point_table['team_name']; ?></span>
									</div>
								</div> <!-- /.spsoccer-col-lg -->

								<div class="spsoccer-col-lg-8 spsoccer-col-md-8 spsoccer-col-sm-12 spsoccer-col-xs-7 team-stats">
									<div class="team-point-table">
										<ul>
											<li> <span><?php echo $point_table['plays']; ?></span> </li>
											<li> <span><?php echo $point_table['wons']; ?></span> </li>
											<li> <span><?php echo $point_table['draws']; ?></span> </li>
											<li> <span><?php echo $point_table['losts']; ?></span> </li>
											<li> <span><?php echo $point_table['gforwards']; ?></span> </li>
											<li> <span><?php echo $point_table['gagainsts']; ?></span> </li>
											<li> <span><?php echo $point_table['avgs']; ?></span> </li>
											<li> <span><?php echo $point_table['ptss']; ?></span> </li>
										</ul>
									</div>
								</div> <!-- /.spsoccer-col-lg -->

							</div> <!-- ./spsoccer-row -->

							<?php $item_no ++; } } // END:: forech $group_teams_infos // END:: has point table  ?>
						<?php } }// END:: foreach $this->point_tables ?>

						</div> <!-- ./spsoccer-standings-wrapper -->
						<?php  // END:: !empty groups ?>
				  	</div> <!-- /.tournament-standing -->

				</div> <!-- /.tab-content -->

			</div> <!-- tabpanel -->

		</div> <!-- /. spsoccer-container -->

	</div> <!-- /.spsoccer-tournament -->
</div> <!-- /#spsoccer .spsoccer -->
