<?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-match-view">
	<div class="spsoccer-match-view">

		<div class="spsoccer-row">
			<div class="match-details-top">
				<div class="spsoccer-container">
					<?php if (!empty($this->item->list_match_stats)) {?>
						<div class="match-time">
							<span><?php echo $this->tournament->title . ' - ' . JHtml::date($this->item->date, 'd M Y'); ?></span>
							<span><?php echo JHTML::date($this->item->time, 'h:i a'); ?></span>
						</div>
						<div class="match-result">
							<!-- goal-timeline -->
							<div class="goal-timeline hidden-sm hidden-xs">
							<span class="timeline-titme">00"</span>
							<ul class="goal-timeline1">
								<?php
									$total_playtime = str_replace(':00', '', $this->item->play_time);
									$half_time 			= round($total_playtime/2);
								?>
								<?php foreach ($this->match_goals_before45s as $goal_before45) {
									$time_percentage = round(($goal_before45['time']/$half_time)*100);
								?>
								<li style="left:<?php echo $time_percentage; ?>%" class="team1 goal"><span class="time"><?php echo $goal_before45['player']. ' ' . $goal_before45['time']; ?>"</span></li>
								<?php } ?>
							</ul>
							<span class="timeline-titme"><?php echo $half_time; ?>"</span>
							<ul class="goal-timeline2">
								<?php foreach ($this->match_goals_after45s as $goal_after45) {
									$time_percentage = round((($goal_after45['time']-$half_time)/$half_time)*100);
								?>
								<li style="left:<?php echo $time_percentage; ?>%" class="team1 goal"><span class="time"><?php echo $goal_after45['player']. ' ' . $goal_after45['time']; ?>"</span></li>
								<?php } ?>

							</ul>
							<span class="timeline-titme"><?php echo $total_playtime; ?>"</span>
						</div>
						<!-- END:: goal-timeline -->
						<div class="spsoccer-row">
							<div class="match-goal-content-wrap">
								<div class="bg-white"></div>
								<div class="match-team-left spsoccer-col-md-3 text-left hidden-sm hidden-xs">
									<?php if (!empty($this->t1_g_players)) {?>
										<div class="goal-scorer">
											<div class="goal-football"></div>
											<?php foreach ($this->t1_g_players as $t1_g_player) { ?>
												<p><?php echo $t1_g_player->title.' '. $t1_g_player->squad_no.'`'; ?></p>
											<?php } ?>
										</div>
									<?php } ?>
								</div>

								<div class="spsoccer-col-sm-12 spsoccer-col-md-6">
									<div class="match-goal-count">
										<div class="match-title">
											<img class="match-result-logo-thumb" src="<?php echo $this->team1_info->logo; ?>">
											<h4><?php echo $this->team1_info->title; ?></h4>
										</div>
										<div class="match-result-content-wrap">
											<h3><?php echo $this->item->teamone_score . ' : ' . $this->item->teamtwo_score; ?></h3>
										</div>
										<div class="match-title">
											<img class="match-result-logo-thumb" src="<?php echo $this->team2_info->logo; ?>">
											<h4><?php echo $this->team2_info->title; ?></h4>
										</div>
									</div>
								</div>
								<div class="match-team-right spsoccer-col-md-3 text-right hidden-sm hidden-xs">
									<?php if (!empty($this->t1_g_players)) {?>
									<div class="goal-scorer">
										<div class="goal-football"></div>
											<?php foreach ($this->t2_g_players as $t2_g_player) { ?>
												<p><?php echo $t2_g_player->title.' '. $t1_g_player->squad_no.'`'; ?></p>
											<?php } ?>
										</div>
									</div>
									<?php } ?>
								</div>
							</div> <!-- /.match-goal-content-wrap -->
						</div>
					</div>
					<?php } ?>
				</div> <!-- /.spsoccer-container -->
			</div> <!-- /.match-details-top -->
		</div> <!-- /.spsoccer-row -->
		<div class="spsoccer-fixture-content-wrap match-details">
			<div class="container match-tab">
				<!-- Nav tabs -->
				<ul class="nav nav-tabs" role="tablist">
					<li role="presentation" class="active">
							<a href="#state" aria-controls="state" role="tab" data-toggle="tab">
								<?php echo JText::_('COM_SOSOCCER_MATCH_STATE'); ?>
							</a>
						</li>
					<li role="presentation">
							<a href="#timeline" aria-controls="timeline" role="tab" data-toggle="tab">
								<?php echo JText::_('COM_SOSOCCER_MATCH_TIMELINE'); ?>
							</a>
						</li>
					<li role="presentation">
							<a href="#team" aria-controls="team" role="tab" data-toggle="tab">
								<?php echo JText::_('COM_SOSOCCER_MATCH_TEAM'); ?>
							</a>
						</li>
					<li role="presentation">
							<a href="#substitue" aria-controls="substitue" role="tab" data-toggle="tab">
								<?php echo JText::_('COM_SOSOCCER_MATCH_SUBSTITUTE'); ?>
							</a>
						</li>
				</ul>

				<!-- Tab panes -->
				<div class="tab-content">
					<div role="tabpanel" class="tab-pane active" id="state">
						<!-- Has match stats -->
						<?php if (!empty($this->item->list_match_stats)) {?>
						<div class="spsoccer-match-states">
							<!-- Team info -->
							<div class="spsoccer-match-result">

								<div class="spsoccer-row">
									<div class="spsoccer-col-xs-12 spsoccer-col-sm-5 match-details-team text-left">
										<div class="media">
											<div class="pull-left">
												<img class="spsoccer-img-thumbnail spsoccer-img-responsive soccer-team-thumb" src="<?php echo $this->team1_info->logo; ?>" alt="<?php echo $this->team1_info->title; ?>">
											</div>
											<div class="media-body">
												<span class="spsoccer-team-name"><?php echo $this->team1_info->title; ?></span>
												<h3 class="spsoocer-team-formation"><?php echo $this->item->teamone_formation?></h3>
											</div>
										</div>
									</div> <!-- /.spsoccer-col-lg -->

									<div class="spsoccer-col-xs-12 spsoccer-col-sm-2 text-center">
										<h4 class="spsoocer-vs"><?php echo JText::_('COM_SOSOCCER_TEAM_VS'); ?></h4>
									</div> <!-- /.spsoccer-col-lg -->

									<div class="spsoccer-col-xs-12 spsoccer-col-sm-5 match-details-team text-right">
										<div class="media">
											<div class="pull-right">
												<img class="spsoccer-img-thumbnail spsoccer-img-responsive soccer-team-thumb" src="<?php echo $this->team2_info->logo; ?>" alt="<?php echo $this->team2_info->title; ?>">
											</div>
											<div class="media-body">
												<span class="spsoccer-team-name"><?php echo $this->team2_info->title; ?></span>
												<h3 class="spsoocer-team-formation"><?php echo $this->item->teamtwo_formation?></h3>
											</div>
										</div>
									</div> <!-- /.spsoccer-col-lg -->

								</div>
								</div> <!-- /.spsoccer-row -->
								<div class="spsoccer-match-status-list">
									<div class="spsoccer-row item-list-wrap">
										<div class="spsoccer-col-xs-4 spsoccer-col-sm-5 text-left">
											<?php if($this->item->teamone_score) { ?>
												<h3><?php echo $this->item->teamone_score; ?></h3>
											<?php } ?>
										</div>
										<div class="spsoccer-col-xs-4 spsoccer-col-sm-2 text-center">
											<h4 class="status"><?php echo JText::_('COM_SOSOCCER_MATCH_GOAL'); ?></h4>
										</div>
										<div class="spsoccer-col-xs-4 spsoccer-col-sm-5 text-right">
											<?php if($this->item->teamtwo_score) { ?>
												<h3><?php echo $this->item->teamtwo_score; ?></h3>
											<?php } ?>
										</div>
									</div>
									<?php foreach ($this->match_stats as $this->match_state) {
										if ($this->match_state['teamone'] || $this->match_state['teamone']) { ?>
										<div class="spsoccer-row item-list-wrap">
											<div class="spsoccer-col-xs-4 spsoccer-col-sm-5 text-left">
												<h3> <?php echo $this->match_state['teamone']; ?> </h3>
											</div> <!-- /.spsoccer-col-lg -->

											<div class="spsoccer-col-xs-4 spsoccer-col-sm-2 text-center">
												<h4 class="status"> <?php echo $this->match_state['type']; ?> </h4>
											</div> <!-- /.spsoccer-col-lg -->

											<div class="spsoccer-col-xs-4 spsoccer-col-sm-5 text-right">
												<h3> <?php echo $this->match_state['teamtwo']; ?> </h3>
											</div> <!-- /.spsoccer-col-lg -->

									</div> <!-- /.spsoccer-row -->
									<?php } } ?>
								</div>
						</div>
						<?php } // Has match stats ?>

						<div class="spsoccer-item-content">
							<h3><?php echo JText::_('COM_SOSOCCER_MATCH_SUMMARY'); ?></h3>
							<p class="soccer-item-description">
								<?php echo $this->item->description; ?>
							</p>
						</div> <!-- /.spsoccer-item-content -->
					</div>

					<div role="tabpanel" class="tab-pane" id="timeline">
						<!-- has match timelines -->
						<?php if (!empty($this->item->list_match_timeline)) {?>
							<div class="spsoccer-match-timeline">
								<?php foreach ($this->match_timelines as $this->match_timeline) {

									$timeline_image = JFile::exists(JPATH_ROOT . '/components/com_spsoccer/assets/images/timeline_images/' . $this->match_timeline['name'] . '.png');

									// has image
									if ($timeline_image) {
										$timeline_image = JURI::root(true) . '/components/com_spsoccer/assets/images/timeline_images/' . $this->match_timeline['name'] . '.png';
									}else{
										$timeline_image= '';
									}

									?>
									<div class="spsoccer-row item-list-wrap <?php echo ($this->match_timeline['type'] == 'goal')? 'goal' : ''?>">
										<div class="spsoccer-col-xs-3 spsoccer-col-sm-3 time">
											<h3>
												<?php echo $this->match_timeline['time']; ?>
												<sub>MIN</sub>
											</h3>
										</div> <!-- /.spsoccer-col-lg -->

										<div class="spsoccer-col-xs-7 spsoccer-col-sm-7 status">
											<h3 class="text-uppercase">
												<?php echo $this->match_timeline['type']; ?>
												<span class="text-capitalize">
													<?php echo $this->match_timeline['squad_no'] . '. ' .$this->match_timeline['player'] . ' (' . $this->match_timeline['team'] . ')'; ?>
												</span>
											</h3>
										</div> <!-- /.spsoccer-col-lg -->

										<div class="spsoccer-col-xs-2 spsoccer-col-sm-2 match-status-icon">
											<?php if ($timeline_image) { ?>
												<img class="soccer-timeline-thumb" src="<?php echo $timeline_image; ?>" alt="<?php echo $this->match_timeline['type']; ?>">
											<?php } ?>
										</div> <!-- /.spsoccer-col-lg -->

									</div>	<!-- /.spsoccer-row -->
								<?php } ?>
							</div> <!-- /.spsoccer-match-timeline -->
						<?php } // has match timelines ?>
					</div>

					<div role="tabpanel" class="tab-pane" id="team">
							<div class="spsoccer-match-team">
								<div class="spsoccer-row spsoccer-match-teams-info">
									<div class="spsoccer-col-xs-12 spsoccer-col-sm-6">
										<div class="spsoccer-team-info media text-left">
											<div class="pull-left">
												<img class="spsoccer-img-thumbnail soccer-team-thumb inline-block" src="<?php echo $this->team1_info->logo; ?>" alt="<?php echo $this->team1_info->title; ?>">
											</div>
											<div class="media-body">
												<h3 class="spsoccer-team-name inline-block"><?php echo $this->team1_info->title; ?></h3>
												<h3 class="spsoocer-team-formation"><?php echo $this->item->teamone_formation?></h3>
											</div>
										</div>
									</div> <!-- /.spsoccer-col-lg -->
									<div class="spsoccer-col-xs-12 spsoccer-col-sm-6 text-right">
										<div class="spsoccer-team-info">
											<div class="pull-right">
												<img class="spsoccer-img-thumbnail soccer-team-thumb inline-block" src="<?php echo $this->team2_info->logo; ?>" alt="<?php echo $this->team2_info->title; ?>">
											</div>
											<div class="media-body">
												<h3 class="spsoccer-team-name inline-block"><?php echo $this->team2_info->title; ?></h3>
												<h3 class="spsoocer-team-formation"><?php echo $this->item->teamtwo_formation?></h3>
											</div>
										</div> <!-- /.spsoccer-team-info -->
									</div> <!-- /.spsoccer-col-lg -->
								</div>	<!-- /.spsoccer-row -->

								<div class="spsoccer-row spsoccer-match-teams-players">
									<div class="spsoccer-col-sm-6 spsoccer-player-right-wrapper">
										<?php foreach ($this->teamone_players as $this->teamone_player) {
											$this->teamone_player->banner = ($this->teamone_player->banner_image) ? $this->teamone_player->banner_image : $this->teamone_player->image;

											$this->teamone_player->image = SpsoccerHelper::hasImg($this->teamone_player->image);

											$this->teamone_player->url = JRoute::_('index.php?option=com_spsoccer&view=player&id=' . $this->teamone_player->spsoccer_player_id . ':' . $this->teamone_player->slug . SpsoccerHelper::getItemid('players'));
											?>
											<div class="spsoccer-player-info item-list-wrap text-left">

												<img class="spsoccer-img-thumbnail soccer-team-thumb inline-block" src="<?php echo $this->teamone_player->image; ?>" alt="<?php echo $this->teamone_player->title; ?>">
												<p class="inline-block"><?php echo $this->teamone_player->squad_no . '. ' . $this->teamone_player->title; ?></p>

												<div class="cleafix"></div>

												<div class="player-overlay">
													<div class="team-overlay-inner">
														<div class="player-image-wrap">
															<img src="<?php echo $this->teamone_player->banner; ?>">
														</div>
														<div class="player-name-inner">
															<h4><?php echo $this->teamone_player->title; ?></h4>
															<span><?php echo $this->teamone_player->position; ?></span>
															<div class="more">
																<a href="<?php echo $this->teamone_player->url; ?>"><i class="fa fa-long-arrow-right"></i></a>
															</div>
														</div>
														<ul>
															<?php if($this->teamone_player->team) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_CLUB'); ?>: </span>
																	<span>
																		<?php echo $this->teamone_player->team; ?>
																	</span>
																</li>
															<?php } if($this->teamone_player->position) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_POSITION'); ?>: </span>
																	<span>
																		<?php echo $this->teamone_player->position; ?>
																	</span>
																</li>
															<?php } if($this->teamone_player->birth_place) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_COUNTRY'); ?>: </span>
																	<span>
																		<?php echo $this->teamone_player->birth_place; ?>
																	</span>
																</li>
															<?php } if($this->teamone_player->dob != '0000-00-00' && $this->teamone_player->dob) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_BIRTHDAY'); ?>: </span>
																	<span>
																		<?php echo $this->teamone_player->dob; ?>
																	</span>
																</li>
															<?php } if($this->teamone_player->height) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_HEIGHT'); ?>: </span>
																	<span>
																		<?php echo $this->teamone_player->height; ?>
																	</span>
																</li>
															<?php } if($this->teamone_player->weight) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_WEIGHT'); ?>: </span>
																	<span>
																		<?php echo $this->teamone_player->weight; ?>
																	</span>
																</li>
															<?php } ?>
														</ul>
													</div>
												</div>

											</div>
										<?php } // END:: foreach $this->teamone_players  ?>

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

									<div class="spsoccer-col-sm-6 spsoccer-player-left-wrapper text-right">

										<?php foreach ($this->teamtwo_players as $this->teamtwo_player) {
											$this->teamtwo_player->banner = ($this->teamtwo_player->banner_image) ? $this->teamtwo_player->banner_image : $this->teamtwo_player->image;

											$this->teamtwo_player->image = SpsoccerHelper::hasImg($this->teamtwo_player->image);

											$this->teamtwo_player->url = JRoute::_('index.php?option=com_spsoccer&view=player&id=' . $this->teamtwo_player->spsoccer_player_id . ':' . $this->teamtwo_player->slug . SpsoccerHelper::getItemid('players'));
										?>
											<div class="spsoccer-player-info item-list-wrap">
												<p class="inline-block"><?php echo $this->teamtwo_player->squad_no . '. ' . $this->teamtwo_player->title; ?></p>
												<img class="spsoccer-img-thumbnail soccer-team-thumb inline-block" src="<?php echo $this->teamtwo_player->image; ?>" alt="<?php echo $this->teamtwo_player->title; ?>">

												<div class="cleafix"></div>

												<div class="player-overlay player-overlay-right">
													<div class="team-overlay-inner">
														<div class="player-image-wrap">
															<img src="<?php echo $this->teamtwo_player->banner; ?>">
														</div>
														<div class="player-name-inner">
															<h4><?php echo $this->teamtwo_player->title; ?></h4>
															<span><?php echo $this->teamtwo_player->position; ?></span>
															<div class="more">
																<a href="<?php echo $this->teamtwo_player->url; ?>"><i class="fa fa-long-arrow-right"></i></a>
															</div>
														</div>
														<ul>
															<?php if($this->teamtwo_player->team) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_CLUB'); ?>: </span>
																	<span>
																		<?php echo $this->teamtwo_player->team; ?>
																	</span>
																</li>
															<?php } if($this->teamtwo_player->position) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_POSITION'); ?>: </span>
																	<span>
																		<?php echo $this->teamtwo_player->position; ?>
																	</span>
																</li>
															<?php } if($this->teamtwo_player->birth_place) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_COUNTRY'); ?>: </span>
																	<span>
																		<?php echo $this->teamtwo_player->birth_place; ?>
																	</span>
																</li>
															<?php } if($this->teamtwo_player->dob != '0000-00-00' && $this->teamtwo_player->dob) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_BIRTHDAY'); ?>: </span>
																	<span>
																		<?php echo $this->teamtwo_player->dob; ?>
																	</span>
																</li>
															<?php } if($this->teamtwo_player->height) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_HEIGHT'); ?>: </span>
																	<span>
																		<?php echo $this->teamtwo_player->height; ?>
																	</span>
																</li>
															<?php } if($this->teamtwo_player->weight) { ?>
																<li>
																	<span class="payer-info"><?php echo JText::_('COM_SOSOCCER_PLAYER_WEIGHT'); ?>: </span>
																	<span>
																		<?php echo $this->teamtwo_player->weight; ?>
																	</span>
																</li>
															<?php } ?>
														</ul>
													</div> <!-- /.team-overlay-inner -->
												</div> <!-- /.player-overlay -->
											</div> <!-- /.spsoccer-player-info -->
										<?php } // END:: foreach $this->teamone_players  ?>
									</div> <!-- /.spsoccer-col-lg -->
								</div>	<!-- /.spsoccer-row -->
							</div> <!-- /.spsoccer-match-timeline -->
					</div>

					<div role="tabpanel" class="tab-pane" id="substitue">
						<!-- has match substitutes -->
						<?php if (!empty($this->item->list_substitutes)) {?>
							<div class="spsoccer-match-substitutes">
								<?php foreach ($this->match_subs as $this->match_sub) {
								$this->match_sub['team_logo'] = SpsoccerHelper::hasImg($this->match_sub['team_logo']);
								?>
								<div class="spsoccer-row item-list-wrap">
								<div class="spsoccer-col-xs-2 spsoccer-col-sm-2">
									<h3>
										<?php echo $this->match_sub['time']; ?>
										<sub><?php echo JText::_('COM_SOSOCCER_MATCH_SUB_MINUTE'); ?></sub>
									</h3>
								</div> <!-- /.spsoccer-col-lg -->

								<div class="spsoccer-col-xs-7 spsoccer-col-sm-7">
									<p class="spsoccer-match-player-up">
										<?php echo $this->match_sub['p_up_no']; ?>.
										<?php echo $this->match_sub['p_up_name']; ?>
										<strong><?php echo JText::_('COM_SOSOCCER_MATCH_SUB_UP'); ?></strong>
									</p>

									<p class="spsoccer-match-player-up">
										<?php echo $this->match_sub['p_down_no']; ?>.
										<?php echo $this->match_sub['p_down_name']; ?>
										<strong><?php echo JText::_('COM_SOSOCCER_MATCH_SUB_DOWN'); ?></strong>
									</p>
									</div> <!-- /.spsoccer-col-lg -->
									<div class="spsoccer-col-xs-3 spsoccer-col-sm-3 text-right">
										<img class="spsoccer-img-thumbnail soccer-team-thumb inline-block" src="<?php echo $this->match_sub['team_logo']; ?>" alt="<?php echo $this->match_sub['team_name']; ?>">
									</div> <!-- /.spsoccer-col-lg -->

								</div>	<!-- /.spsoccer-row -->
								<?php } ?>
							</div>	<!-- /.spsoccer-match-team-->
						<?php } // has match substitutes ?>
					</div>
				</div>
			</div>
		</div><!-- /.spsoccer-match-tab-content -->
	</div> <!-- /.spsoccer-tournament -->
</div> <!-- /#spsoccer .spsoccer -->
