<!DOCTYPE html>
<html lang='en'>
    <head>
        <meta content='text/html; charset=utf-8' http-equiv='content-type'/>
        <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'/>
        <title><?=$page->title?></title>
        <link rel='shortcut icon' href='<?=$page->favicon?>'/>
        <!-- CSS files -->
        <link rel='stylesheet' type='text/css' href='<?=$path["css"]?>ui.css'/>
        <link rel='stylesheet' type='text/css' href='<?=$path["css"]?>report_skillup.css'/>
        <link rel='stylesheet' type='text/css' href='<?=$path["css"]?>filters.css'/>
        <!-- Script files -->
        <script src="<?=$path["js"]?>ui.js"></script>
        <!-- Meta tags -->
        <link rel='canonical' href='<?=$page->canonical?>'/>
        <link rel='author' href='<?=$page->author?>'/>
        <link rel='publisher' href='<?=$page->author?>'/>
        <meta name='description' content='<?=$page->description?>'/>
        <meta property='og:title' content='<?=$page->title?>'/>
        <meta property='og:url' content='<?=$page->canonical?>'/>
        <meta property='og:description' content='<?=$page->description?>'/>
        <meta property='og:image' content='<?=$page->icon?>'/>
        <meta property='og:site_name' content='<?=$page->name?>'/>
        <meta property='og:type' content='website'/>
        <meta property='og:locale' content='en'/>
        <meta name='twitter:card' content='summary'/>
        <meta name='twitter:title' content='<?=$page->title?>'/>
        <meta name='twitter:description' content='<?=$page->description?>'/>
        <meta name='twitter:image' content='<?=$page->icon?>'/>
        <meta name='twitter:url' content='<?=$page->canonical?>'/>
        <meta name='robots' content='index follow'/>
    </head>
    <body id='body_report_skillup'>
<?php
        include __DIR__ . "/inc/header.php";
?>
        <section class='filters'>
            <h2>
                <span>
                    Monster filters
                </span>
            </h2>
<?php
            $filters = $page->filters;
            include __DIR__ . "/inc/filter_report_skillup.php";
?>
        </section> <!-- #filters -->
<?php
        $index = 1;
        foreach ($page->units as $unit){
            if ($unit->unit->awakens_from == "" && $unit->unit->awakens_to == ""){
                // No to, no from, silver monster.
                $star_class ="star_silver";
                $unit_title = $unit->unit->element . " " . $unit->unit->name;
            }
            elseif ($unit->unit->awakens_from != "" && $unit->unit->awakens_to == ""){
                // Already awakened
                if ($unit->unit->base_stars - $unit->unit->natural_stars == 1){
                    // Normal awaken.
                    $star_class = "star_purple";
                }
                else{
                    // Second awaken.
                    $star_class = "star_red";
                }
                $unit_title = $unit->unit->name;
            }
            elseif ($unit->unit->awakens_to != ""){
                // Awakeable.
                $star_class = "star_gold";
                $unit_title = $unit->unit->element . " " . $unit->unit->name;
            }
            switch ($index % 10){
                case 1:
                    $index_title = $index . "<span class='superindex'>st</span> - " . $unit_title;
                    break;
                case 2:
                    $index_title = $index . "<span class='superindex'>nd</span> - " . $unit_title;
                    break;
                case 3:
                    $index_title = $index . "<span class='superindex'>rd</span> - " . $unit_title;
                    break;
                default:
                    $index_title = $index . "<span class='superindex'>th</span> - " . $unit_title;
                    break;
            }
            switch ($index % 100){
                case 11:
                case 12:
                case 13:
                    $index_title = $index . "<span class='superindex'>th</span> - " . $unit_title;
                    break;
            }
?>
            <section class='content'>
                <h2>
                    <span>
                        <?=$index_title?>
                    </span>
                </h2>
                <article>
                    <div class='monster'>
                        <div class='profile'>
                            <div class='monster_panel'>
                                <span class='stars'>
<?php
                                    for ($i = 0; $i < $unit->stars; $i ++){
?>
                                        <img class='star <?=$star_class?>' src='<?=$path["img"]["icon"] . "star.png"?>'/>
<?php
                                    }
?>
                                </span>
                                <img title='<?=$unit_title?>' class='monster border_<?=$unit->unit->element_name?>' src='<?=$unit->unit->get_image()?>'/>
                                <span class='level'>
                                    <?=$unit->level?>
                                </span>
                            </div>
                        </div> <!-- .profile -->
                        <div class='skills'>
<?php
                            $skill_num = 0;
                            $absolute_level = 0;
                            $absolute_max_level = 0;
                            $ponderated_level = 0;
                            $ponderated_max_level = 0;
                            foreach ($unit->unit->skill as $skill){
                                if ($skill->max_level > 1){
                                    $absolute_max_level += $skill->max_level - 1;
                                }
                                $cur_lvl = $unit->skill_levels[$skill_num];
                                if ($skill->max_level > 1){
                                    $absolute_level += $cur_lvl - 1;
                                    $ponderated_level += ($cur_lvl - 1) * (1 + ($skill_num / 2));
                                    $ponderated_max_level += ($skill->max_level - 1) * (1 + ($skill_num / 2));
                                }
                                $max_lvl = $skill->max_level;
                                if ($max_lvl == $cur_lvl){
                                    $maxed = "maxed";
                                }
                                else{
                                    $maxed = "";
                                }
?>
                                <div class='skill'>
                                    <img title='<?=$skill->description?>' src='<?=$skill->get_image()?>'/>
                                    <span class='skill_level <?=$maxed?>'>
                                        <?=$cur_lvl?>/<?=$max_lvl?>
                                    </span>
                                    <span class='skill_name'>
                                        <?=$skill->name?>
                                    </span>
                                </div>
<?php
                                $skill_num ++;
                            }
?>
                        </div> <!-- #skills -->
                        <table id='skill_averages'>
                            <tr>
                                <td class='title'>
                                    Absolute skill-ups:
                                </td>
                                <td class='value'>
                                    <?=number_format($absolute_level * 100 / $absolute_max_level, 2)?>%
                                </td>
                            </tr>
                            <tr>
                                <td class='title'>
                                    Ponderated skill-ups:
                                </td>
                                <td class='value'>
                                    <?=number_format($ponderated_level * 100 / $ponderated_max_level, 2)?>%
                                </td>
                            </tr>
                            <tr>
                                <td class='title'>
                                    Remaining skill-ups:
                                </td>
                                <td class='value'>
                                    <?=$absolute_max_level - $absolute_level?>
                                </td>
                            </tr>
                        </table>
                    </div>
                </article>
            </section> 
<?php
            $index ++;
        }
?>


<?php
        include __DIR__ . "/inc/footer.php";
?>
    </body>
</html>
