<?php
require_once('global.php');
require_once(ABSOLUTE_PATH.'/class/ChampionHelper.php');

$template_body_class.= 'background-global';

$meta_title = 'Champions &ndash; LoLSkill';
$meta_description = 'Statistics, abilities, information, skins, store details and more for every League of Legends champion.';
$template_og['url'] = DYNAMIC_PATH.'/champions';
$template_og['title'] = 'Champions &ndash; LoLSkill';
$template_og['description'] = 'Statistics, abilities, information, skins, store details and more for every League of Legends champion.';

$ch = ChampionHelper::getInstance();

// Top champions
$template_content = '		<section id="championsBest">
			'.$am->getLeaderboard().'
			<div class="container">
				<h2 class="headline">Champions</h2>';
$championHighest = $ch->getChampionStats(0, ChampionHelper::HIGHEST);
if($championHighest!==null && $championHighest!==false){
	$highestPickrate = key($championHighest['pickrate']);
	$highestWinrate = key($championHighest['winrate']);
	$highestBanrate = key($championHighest['banrate']);
	$printableHighestPickrate = number_format(100 * $championHighest['pickrate'][$highestPickrate], 1, '.', ',') + 0;
	$printableHighestWinrate = number_format(100 * $championHighest['winrate'][$highestWinrate], 1, '.', ',') + 0;
	$printableHighestBanrate = number_format(100 * $championHighest['banrate'][$highestBanrate], 1, '.', ',') + 0;

	$template_content.= '			<div class="best-champion-banners d-flex flex-wrap text-center">
				<div class="best-champion-banner" style="background-image:url('.$ch->getSkinImage($highestPickrate, 0, 'splash').');">
					<a href="champion/'.$ch->getChampionCode($highestPickrate).'">
						<div class="d-flex overlay align-items-center justify-content-center w-100 h-100">
							<div class="d-flex flex-column align-items-center justify-content-center">
								<p class="champion-name text-uppercase">'.$ch->getDisplayName($highestPickrate).'</p>
								<p class="category text-uppercase">Most Popular</p>
								<p class="value text-uppercase color-secondary">'.$printableHighestPickrate.'% Pick Rate</p>
							</div>
						</div>
					</a>
				</div>
				<div class="best-champion-banner" style="background-image:url('.$ch->getSkinImage($highestWinrate, 0, 'splash').');">
					<a href="champion/'.$ch->getChampionCode($highestWinrate).'">
						<div class="d-flex overlay align-items-center justify-content-center w-100 h-100">
							<div class="d-flex flex-column align-items-center justify-content-center">
								<p class="champion-name text-uppercase">'.$ch->getDisplayName($highestWinrate).'</p>
								<p class="category text-uppercase">Highest Win Rate</p>
								<p class="value text-uppercase color-secondary">'.$printableHighestWinrate.'% Win Rate</p>
							</div>
						</div>
					</a>
				</div>
				<div class="best-champion-banner" style="background-image:url('.$ch->getSkinImage($highestBanrate, 0, 'splash').');">
					<a href="champion/'.$ch->getChampionCode($highestBanrate).'">
						<div class="d-flex overlay align-items-center justify-content-center w-100 h-100">
							<div class="d-flex flex-column align-items-center justify-content-center">
								<p class="champion-name text-uppercase">'.$ch->getDisplayName($highestBanrate).'</p>
								<p class="category text-uppercase">Most Banned</p>
								<p class="value text-uppercase color-secondary">'.$printableHighestBanrate.'% Ban Rate</p>
							</div>
						</div>
					</a>
				</div>
			</div>
		</section>';
}

// Champion List
$template_content.= '		<section id="championList">
			<div class="container">
				<div class="d-flex flex-wrap">';
foreach($ch->getChampions() as $champion){
	$championAvg = $ch->getChampionStats($champion, ChampionHelper::AVERAGE);
	$championStats = $ch->getChampionStats($champion, ChampionHelper::STATS);
	$championRoles = $ch->getChampionStats($champion, ChampionHelper::ROLES);
	$metaRoles = [];
	if($championAvg!==false && $championStats!==false){
		$pickrate = (number_format(100 * $championAvg['pickrate'], 1, '.', ',') + 0).'%';
		$banrate = (number_format(100 * $championAvg['banrate'], 1, '.', ',') + 0).'%';
		$winrate = (number_format(100 * $championAvg['winrate'], 1, '.', ',') + 0).'%';
		if($championRoles!==null && $championRoles!==false){
			foreach($championRoles as $role => $count){
				if($count / $championStats['games'] >= 0.15){
					$metaRoles[] = ucfirst($role);
				}
			}
		}
	}else $pickrate = $banrate = $winrate = '';
	$roles = '&nbsp;';
	if(!empty($metaRoles)){
		$roles = 'META ';
		foreach($metaRoles as $metaRole){
			$roles.= '<img class="role tip" src="'.STATIC_PATH.'/img/roles/32/'.strtolower($metaRole).'.png" title="'.ucfirst($metaRole).'" alt="'.ucfirst($metaRole).'">';
		}
	}

	$template_content.= '					<a class="champion-container-wrapper d-block w-100" href="champion/'.$ch->getChampionCode($champion).'">
						<div class="champion-container d-flex align-items-center" style="background-image:url('.$ch->getSkinImage($champion, 0, 'tablerow').');">
							<div class="champion-icon text-center" style="background-image:url('.$ch->getChampionImage($champion, 64).');">
								&nbsp;
							</div>
							<div class="name mr-auto text-left">
								<p class="value champion-name">'.$ch->getDisplayName($champion).'</p>
								<p class="text roles">'.$roles.'</p>
							</div>
							<div class="rp ml-auto text-center tip hidden-md-down" title="Riot Points">
								<p class="value">'.$ch->getRP($champion).'</p>
								<p class="text"><img src="'.STATIC_PATH.'/img/rp.png" alt=""> RP</p>
							</div>
							<div class="ip text-center tip hidden-md-down" title="Influence Points">
								<p class="value">'.$ch->getIP($champion).'</p>
								<p class="text"><img src="'.STATIC_PATH.'/img/ip.png" alt=""> IP</p>
							</div>
							<div class="rate text-center">
								<p class="value">'.$pickrate.'</p>
								<p class="text">Pick Rate</p>
							</div>
							<div class="rate text-center">
								<p class="value">'.$winrate.'</p>
								<p class="text">Win Rate</p>
							</div>
							<div class="rate text-center">
								<p class="value">'.$banrate.'</p>
								<p class="text">Ban Rate</p>
							</div>
							<div class="more color-secondary">
								<img src="'.STATIC_PATH.'/img/icon_showmore.png" alt="&gt;">
							</div>
						</div>
					</a>';
}
$template_content.= '				</div>
			</div>
		</section>';
$template_content.= $am->getLeaderboard();

include_once(ABSOLUTE_PATH.'/template.php');
?>