<?php
require_once('global.php');
require_once(ABSOLUTE_PATH.'/class/ChampionHelper.php');
require_once(ABSOLUTE_PATH.'/class/LiveMatchesManager.php');
require_once(ABSOLUTE_PATH.'/class/NewsManager.php');
require_once(ABSOLUTE_PATH.'/class/Paginator.php');
require_once(ABSOLUTE_PATH.'/class/SalesManager.php');

$ch = ChampionHelper::getInstance();

$template_body_class.= 'background-index';
$template_navbar_class.= 'nav-index';

// Ads: Special Case: Curse wants different script for index page
/*
$ad_headhtml = '<script>
window.factorem = {};
window.factorem.slotSizes =  [
    [[728, 90]],
    [[300,250]],
    [[300,250]],
    [[728,90]],
    [[728, 90]],
    [[300,250]],
    [[160,600]],
    [[160,600]],
];
var script = document.createElement(\'script\');
var tstamp = new Date();
script.id = \'factorem\';
script.src =  \'//cdm.cursecdn.com/js/lolskill/cdmfactorem_min.js?sec=home&misc=\' + tstamp.getTime();
script.async = false;
script.type=\'text/javascript\';
document.head.appendChild(script);
</script>';
*/

// Landing
$template_content.= '		<section id="landing">
			<div class="container text-center d-flex align-items-center h-100">
				<div class="content text-center w-100">
					<h2>League of Legends</h2>
					<h1 class="color-secondary">Game &amp; Summoner Analysis</h1>
					'.$template_searchcontainer.'
				</div>
			</div>
		</section>';
$template_content.= $am->getLeaderboard();
// Don't show search in header
$template_searchcontainer = '';

// Blog
$nm = NewsManager::getInstance();
$newsLatest = $nm->getLatestIds(2, 0); // limit, offset
if($newsLatest!=null){
	$template_content.= '		<section id="blog">';
	$template_content.= '			<div class="container">
				<h2 class="headline">Blog</h2>
				<div class="row">
					<div class="col-12 col-lg-7 col-xl-8">
						<div class="row">';
	foreach($newsLatest as $news){
		$template_content.= $nm->getPrintableNewsPreviewIndex($news);
	}
	$template_content.= '						</div>
						<div class="text-center">
							<a href="blog" class="btn btn-outline-primary button-viewall">View All</a>
						</div>
					</div>
					<div class="col-lg-5 col-xl-4 hidden-md-down text-center">';
	$template_content.= $am->getMediumRectangle();
	$template_content.= $am->getMediumRectangle();
	$template_content.= $template_socialmedia;
	$template_content.= '					</div>
				</div>
			</div>
		</section>';
}

// Featured live matches
$lmm = LiveMatchesManager::getInstance();
$matchesFeatured = $lmm->getFeaturedLiveMatches();
if($matchesFeatured!=null){
	$template_content.= '		<section id="featuredmatches">
			<div class="container">
				<h2 class="headline">Featured Matches</h2>';
	foreach($matchesFeatured as $match){
		$template_content.= $lmm->getPrintableMatch($match);
	}
	$template_content.= '				<div class="row">
					<div class="col-12 text-center">
						<a href="live-matches" class="btn btn-outline-primary button-viewall">View All</a>
					</div>
				</div>
			</div>
		</section>';
}

// Free to play
$freetoplay = $ch->getFreeToPlayChampions();
if($freetoplay != null && !empty($freetoplay)){
	$count = count($freetoplay);
	$width = floor(10 * (90 / $count)) / 10;
	$template_content.= $am->getLeaderboard();
	$template_content.= '		<section id="freetoplay">';
	$template_content.= '			<div class="container text-center">
				<h2 class="headline has-subheadline">Free Champions of the Week</h2>
				<h5 class="headline subheadline color-secondary">'.date('d.m.Y').'</h5>';
	foreach($freetoplay as $champion){
		$template_content.= '				<a class="champion" data-champion-id="'.$champion.'" href="champion/'.$ch->getChampionCode($champion).'">
					<div class="champion-slice d-inline-block" style="background-image:url('.$ch->getSkinImage($champion, 0, 'loading').'); width:'.$width.'%;"></div>
				</a>';
	}
	$template_content.= '			</div>
		</section>';
}

// Sales
$sam = SalesManager::getInstance();
$sales = $sam->getActiveSales();
if($sales!=null){
	$template_content.= '		<section id="sales">';
	$template_content.= '			<div class="container">
				<h2 class="headline has-subheadline">Champion & Skin Sales</h2>
				<h5 class="headline subheadline color-secondary">50% RP off</h5>
				<div class="row d-flex align-items-center">
					<div class="col-12 col-md-4 text-center text-md-left">';
	$i=1;
	foreach($sales as $sale){
		if($sale['skinId']!=0){
			continue;
		}
		if($i > 4){
			break;
		}
		$template_content.= '						<a class="champion" data-champion-id="'.$sale['championId'].'" href="champion/'.$ch->getChampionCode($sale['championId']).'">
							<div class="champion-slice d-inline-block" style="background-image:url('.$ch->getSkinImage($sale['championId'], $sale['skinId'], 'loading').'); width:23.5%;"></div>
						</a>';
		$i++;
	}
	$template_content.= '					</div>
					<div class="col-12 col-md-4 d-flex justify-content-center">';
	$template_content.= $am->getMediumRectangle();
	$template_content.= '					</div>
					<div class="col-12 col-md-4 text-center text-md-right">';
	$i=1;
	foreach($sales as $sale){
		if($sale['skinId']==0){
			continue;
		}
		if($i > 4){
			break;
		}
		$template_content.= '						<a class="champion" data-champion-id="'.$sale['championId'].'" href="champion/'.$ch->getChampionCode($sale['championId']).'">
							<div class="champion-slice d-inline-block" style="background-image:url('.$ch->getSkinImage($sale['championId'], $sale['skinId'], 'loading').'); width:23%;">
								&nbsp;
							</div>
						</a>';
		$i++;
	}
	$template_content.= '					</div>
				</div>
			</div>
		</section>';
}
$template_content.= $am->getLeaderboard();

include_once(ABSOLUTE_PATH.'/template.php');
?>