<?php
    /**
     * Skillup report view.
     *
     * Contains the view layout and ome code to present the data.
     *
     * @category View
     * @property_read Report_Skillup_Page $page The page model.
     */
?>
<!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='<?=URL::CSS?>ui.css'/>
        <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>report_skillup.css'/>
        <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>filters.css'/>
        <!-- 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'/>
        <script>

            /**
             * Shows or hiddes the filters panel.
             */
            function toggleFilters(){
                var content = document.getElementById('filters_content');
                var slid = document.getElementById('filters_slid');
                if (content.style.maxHeight != '30em'){
                    content.style.maxHeight = '30em';
                    slid.style.transform = 'rotate(90deg)';
                }
                else{
                    content.style.maxHeight = '0px';
                    slid.style.transform = 'rotate(0deg)';
                }
            };
        </script>
    </head>
    <body id='body_report_skillup'>
<?php
        include __DIR__ . "/inc/header.php";
?>
        <section class='filters'>
            <h2 id='filters_title' onClick='toggleFilters();'>
                <img id='filters_slid' id='filters_slid' alt=' ' src='<?=URL::IMG["ICON"]?>slid.png'/>
                Monster filters
            </h2>
            <article id='filters_content'>
<?php
                $filters = $page->filters;
                $custom_filters = $page->custom_filters;
                include __DIR__ . "/inc/filter_report_skillup.php";
?>
            </article>

        </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='<?=URL::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 = 1;
                            $absolute_level = 0;
                            $absolute_max_level = 0;
                            $ponderated_level = 0.0;
                            $ponderated_max_level = 0.0;
                            foreach ($unit->unit->skill as $skill){
                                if ($skill->max_level > 1){
                                    $absolute_max_level += $skill->max_level;
                                }
                                $cur_lvl = $unit->skill_levels[$skill_num - 1];
                                if ($skill->max_level > 1){
                                    $absolute_level += $cur_lvl;
                                    $ponderated_level += $cur_lvl * (($skill_num + 1) / 2.0);
                                    $ponderated_max_level += $skill->max_level * (($skill_num + 1) / 2.0);
                                }
                                $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>

