<?php
    /**
     * Monsters view.
     *
     * Contains the view layout and ome code to present the data.
     *
     * @category View
     * @property_read Monsters_Page $page The page model.
     * @property_read int $UID Player ID.
     */

    namespace swdb;
?>
<!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?>monsters.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>
<?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_monsters.php";
?>
            </article>

        </section> <!-- #filters -->
        <section class='list'>
            <h2>
                Monsters
            </h2>
            <article>
<?php
                foreach ($page->monsters as $mon){
?>
                    <div class='monster'>
                        <a href='/<?=$UID?>/monsters/<?=$mon->id?>'>
                            <div class='monster_panel'>
                                <?=HTML::unit_panel($mon)?>
                            </div>
                        </a>
                        <div class='monster_tooltip'>
                            <h4>
                                <?=$mon->title?>
                            </h4>
<?php
                            $building_attack = floor(($mon->attack * $page->building_stats["atk"] / 100) + ($mon->attack * $page->building_stats["elm"][$mon->unit->element] / 100));
                            $building_defense = floor($page->building_stats["def"] * $mon->defense / 100);
                            $building_hp = floor($page->building_stats["hp"] * $mon->hp / 100);
                            $building_speed = $page->building_stats["spd"];
                            $building_crit_rate = 0;
                            $building_crit_damage = $page->building_stats["crd"];
                            $building_accuracy = 0;
                            $building_resistance = 0;
?>
                            <table class='stats'>
                                <tr>
                                    <th>
                                        Stats
                                    </th>
                                    <th>
                                        Base
                                    </th>
                                    <th>
                                        Runes
                                    </th>
                                    <th>
                                        Buildings
                                    </th>
                                    <th>
                                        Total
                                    </th>
                                </tr>
                                <tr>
                                    <th>
                                        ATK
                                    </th>
                                    <td class='base'>
                                        <?=$mon->attack?>
                                    </td>
                                    <td class='extra'>
                                        +<?=$mon->rune_attack?>
                                    </td>
                                    <td class='extra'>
                                        +<?=$building_attack?>
                                    </td>
                                    <td class='total'>
                                        <?=$mon->attack + $mon->rune_attack + $building_attack?>
                                    </td>
                                </tr>
                                <tr>
                                    <th>
                                        DEF
                                    </th>
                                    <td class='base'>
                                        <?=$mon->defense?>
                                    </td>
                                    <td class='extra'>
                                        +<?=$mon->rune_defense?>
                                    </td>
                                    <td class='extra'>
                                        +<?=$building_defense?>
                                    </td>
                                    <td class='total'>
                                        <?=$mon->defense + $mon->rune_defense + $building_defense?>
                                    </td>
                                </tr>
                                <tr>
                                    <th>
                                        HP
                                    </th>
                                    <td class='base'>
                                        <?=$mon->hp?>
                                    </td>
                                    <td class='extra'>
                                        +<?=$mon->rune_hp?>
                                    </td>
                                    <td class='extra'>
                                        +<?=$building_hp?>
                                    </td>
                                    <td class='total'>
                                        <?=$mon->hp + $mon->rune_hp + $building_hp?>
                                    </td>
                                </tr>
                                <tr>
                                    <th>
                                        SPD
                                    </th>
                                    <td class='base'>
                                        <?=$mon->speed?>
                                    </td>
                                    <td class='extra'>
                                        +<?=$mon->rune_speed?>
                                    </td>
                                    <td class='extra'>
                                        +<?=$building_speed?>
                                    </td>
                                    <td class='total'>
                                        <?=$mon->speed + $mon->rune_speed + $building_speed?>
                                    </td>
                                </tr>
                                <tr>
                                    <th>
                                        CRR
                                    </th>
                                    <td class='base'>
                                        <?=$mon->crit_rate?>%
                                    </td>
                                    <td class='extra'>
                                        +<?=$mon->rune_crit_rate?>%
                                    </td>
                                    <td class='extra'>
                                        +<?=$building_crit_rate?>%
                                    </td>
                                    <td class='total'>
                                        <?=$mon->crit_rate + $mon->rune_crit_rate + $building_crit_rate?>%
                                    </td>
                                </tr>
                                <tr>
                                    <th>
                                        CRD
                                    </th>
                                    <td class='base'>
                                        <?=$mon->crit_damage?>%
                                    </td>
                                    <td class='extra'>
                                        +<?=$mon->rune_crit_damage?>%
                                    </td>
                                    <td class='extra'>
                                        +<?=$building_crit_damage?>%
                                    </td>
                                    <td class='total'>
                                        <?=$mon->crit_damage + $mon->rune_crit_damage + $building_crit_damage?>%
                                    </td>
                                </tr>
                                <tr>
                                    <th>
                                        ACC
                                    </th>
                                    <td class='base'>
                                        <?=$mon->accuracy?>%
                                    </td>
                                    <td class='extra'>
                                        +<?=$mon->rune_accuracy?>%
                                    </td>
                                    <td class='extra'>
                                        +<?=$building_accuracy?>%
                                    </td>
                                    <td class='total'>
                                        <?=$mon->accuracy + $mon->rune_accuracy + $building_accuracy?>%
                                    </td>
                                </tr>
                                <tr>
                                    <th>
                                        RES
                                    </th>
                                    <td class='base'>
                                        <?=$mon->resistance?>%
                                    </td>
                                    <td class='extra'>
                                        +<?=$mon->rune_resistance?>%
                                    </td>
                                    <td class='extra'>
                                        +<?=$building_resistance?>%
                                    </td>
                                    <td class='total'>
                                        <?=$mon->resistance + $mon->rune_resistance + $building_resistance?>%
                                    </td>
                                </tr>
                            </table>
                            <div class='skills'>
<?php
                                $skill_num = 0;
                                foreach ($mon->unit->skill as $skill){
                                    $cur_lvl = $mon->skill_levels[$skill_num];
                                    $max_lvl = $skill->max_level;
                                    if ($max_lvl == $cur_lvl){
                                        $maxed = "maxed";
                                    }
                                    else{
                                        $maxed = "";
                                    }
?>
                                    <div class='skill'>
                                        <img 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>
                        </div>
                    </div>
<?php
            }
?>
                </article>
            </section> <!-- #catalog -->

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

