<?php
    /**
     * Guild view.
     *
     * Contains the view layout and some code to present the data.
     *
     * @category View
     * @property_read Guild_Page $page The page model.
     */

    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?>guild.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'/>
    </head>
    <body>
<?php
        include __DIR__ . "/inc/header.php";
        if (!isset($page->guild)){
?>
            <section id='no_guild'>
                <h2>
                    Guild
                </h2>
                You are not currently in a guild.
            </section>
<?php
        }
        else{
?>
            <section id='guild_info' class='content'>
                <h2>
                    <?=$page->guild->name?>
                </h2>
                <div id='guild_details'>
                    <span id='guild_level'>
                        Lv. <?=$page->guild->level?>
                    </span>
                    <span id='guild_experience'>
                        (Exp: <?=$page->guild->experience?>)
                    </span>
                    <p id='guild_comment'>
                        <?=$page->guild->comment?>
                    </p>
                    <p id='guild_notice'>
                        <?=$page->guild->notice?>
                    </p>
                    <div id='guild_skills'>
<?php
                        foreach ($page->skill_groups as $group){
?>
                            <div class='skill_group'>
                                <span class='skill_group_title'>
                                    <?=$group->name?>
                                </span>
                                <img class='skill_group_image' alt='<?=$group->name?>' src='<?=$group->get_image()?>'/>
                                <div class='skill_group_content'>
                                    <span class='description'>
                                        <?=$group->description?>
                                    </span>
                                    <ul>
<?php
                                        foreach ($group->skills as $skill){
                                            if ($skill->level > $page->guild->level){
                                                $unavailable = "unavailable";
                                            }
                                            else{
                                                $unavailable = "";
                                            }
?>
                                            <li class='<?=$unavailable?>'>
                                                Lv. <?=$skill->level?>: <?=$skill->effect?>
                                            </li>
<?php
                                        }
?>
                                    </ul>
                                </div>
                            </div>
<?php
                        }
?>
                    </div>
                </div>
                <table id='guild_members'>
                    <tr>
                        <th>
                            &nbsp;
                        </th>
                        <th>
                            Name
                        </th>
                        <th>
                            Lv.
                        </th>
                        <th colspan='2'>
                            Arena
                        </th>
                        <th>
                            War
                        </th>
                        <th>
                            Def
                        </th>
                        <th>
                            Login
                        </th>
                    </tr>
<?php
                    $odd = "";
                    foreach ($page->guild->members as $member){
?>
                        <tr>
                            <td class='grade <?=$odd?>'>
<?php
                                if ($member->grade == GUILD_MEMBER_GRADE::LEADER){
?>
                                    <img alt='yes' src='<?=URL::IMG["ICON"] . "leader.png"?>'/>
<?php
                                }
                                elseif ($member->grade == GUILD_MEMBER_GRADE::VICELEADER){
?>
                                    <img alt='yes' src='<?=URL::IMG["ICON"] . "viceleader.png"?>'/>
<?php
                                }
?>
                            </td>
                            <td class='name <?=$odd?>'>
                                <?=$member->name?>
                            </td>
                            <td class='level <?=$odd?>'>
                                <?=$member->level?>
                            </td>
                            <td class='score <?=$odd?>'>
                                <?=$member->arena_score?>
                            </td>
                            <td class='score_icon <?=$odd?>'>
<?php
                                if ($member->arena_score >= ARENA_RANKING_POINTS::BEGINER && (ARENA_RANKING_RANK::BEGINER == null || $member->rating <= ARENA_RANKING_RANK::BEGINER)){
                                    $src = URL::IMG["ICON"] . "rank_beg.png";
                                    $tit = "Beginer";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::CHALLENGER_1 && (ARENA_RANKING_RANK::CHALLENGER_1 == null || $member->rating <= ARENA_RANKING_RANK::CHALLENGER_1)){
                                    $src = URL::IMG["ICON"] . "rank_cha1.png";
                                    $tit = "Challenger 1";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::CHALLENGER_2 && (ARENA_RANKING_RANK::CHALLENGER_2 == null || $member->rating <= ARENA_RANKING_RANK::CHALLENGER_2)){
                                    $src = URL::IMG["ICON"] . "rank_cha2.png";
                                    $tit = "Challenger 2";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::CHALLENGER_3 && (ARENA_RANKING_RANK::CHALLENGER_3 == null || $member->rating <= ARENA_RANKING_RANK::CHALLENGER_3)){
                                    $src = URL::IMG["ICON"] . "rank_cha3.png";
                                    $tit = "Challenger 3";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::FIGHTER_1 && (ARENA_RANKING_RANK::FIGHTER_1 == null || $member->rating <= ARENA_RANKING_RANK::FIGHTER_1)){
                                    $src = URL::IMG["ICON"] . "rank_fig1.png";
                                    $tit = "Fighter 1";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::FIGHTER_2 && (ARENA_RANKING_RANK::FIGHTER_2 == null || $member->rating <= ARENA_RANKING_RANK::FIGHTER_2)){
                                    $src = URL::IMG["ICON"] . "rank_fig2.png";
                                    $tit = "Fighter 2";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::FIGHTER_3 && (ARENA_RANKING_RANK::FIGHTER_3 == null || $member->rating <= ARENA_RANKING_RANK::FIGHTER_3)){
                                    $src = URL::IMG["ICON"] . "rank_fig3.png";
                                    $tit = "Fighter 3";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::CONQUEROR_1 && (ARENA_RANKING_RANK::CONQUEROR_1 == null || $member->rating <= ARENA_RANKING_RANK::CONQUEROR_1)){
                                    $src = URL::IMG["ICON"] . "rank_con1.png";
                                    $tit = "Conqueror 1";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::CONQUEROR_2 && (ARENA_RANKING_RANK::CONQUEROR_2 == null || $member->rating <= ARENA_RANKING_RANK::CONQUEROR_2)){
                                    $src = URL::IMG["ICON"] . "rank_con2.png";
                                    $tit = "Conqueror 2";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::CONQUEROR_3 && (ARENA_RANKING_RANK::CONQUEROR_3 == null || $member->rating <= ARENA_RANKING_RANK::CONQUEROR_3)){
                                    $src = URL::IMG["ICON"] . "rank_con3.png";
                                    $tit = "Conqueror 3";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::GUARDIAN_1 && (ARENA_RANKING_RANK::GUARDIAN_1 == null || $member->rating <= ARENA_RANKING_RANK::GUARDIAN_1)){
                                    $src = URL::IMG["ICON"] . "rank_gua1.png";
                                    $tit = "Guardian 1";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::GUARDIAN_2 && (ARENA_RANKING_RANK::GUARDIAN_2 == null || $member->rating <= ARENA_RANKING_RANK::GUARDIAN_2)){
                                    $src = URL::IMG["ICON"] . "rank_gua2.png";
                                    $tit = "Guardian 2";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::GUARDIAN_3 && (ARENA_RANKING_RANK::GUARDIAN_3 == null || $member->rating <= ARENA_RANKING_RANK::GUARDIAN_3)){
                                    $src = URL::IMG["ICON"] . "rank_gua3.png";
                                    $tit = "Guardian 3";
                                }
                                if ($member->arena_score >= ARENA_RANKING_POINTS::LEGEND && (ARENA_RANKING_RANK::LEGEND == null || $member->rating <= ARENA_RANKING_RANK::LEGEND)){
                                    $src = URL::IMG["ICON"] . "rank_leg.png";
                                    $tit = "Legend";
                                }
?>
                                <img alt='<?=$tit?>' src='<?=$src?>'/>
                            </td>
                            <td class='war <?=$odd?>'>
<?php
                                if ($member->in_war){
?>
                                    <img alt='yes' src='<?=URL::IMG["ICON"] . "ok.png"?>'/>
<?php
                                }
?>
                            </td>
                            <td class='defense <?=$odd?>'>
<?php
                                if ($member->has_defense){
?>
                                    <img alt='yes' src='<?=URL::IMG["ICON"] . "ok.png"?>'/>
<?php
                                }
?>
                            </td>
<?php
                            $now = time();
                            $date = (new DateTime("@$member->last_login"))->format('Y-m-d H:i:s');
                            $days = $now - strtotime($date);
                            $days = floor($days / (60 * 60 * 24));
                            if ($days == 0){
                                $hours = floor($days / (60 * 60));
                                if ($hours == 0){
                                    $last_login = "Online";
                                }
                                else if ($hours == 1){
                                    $last_login = "1 hour";
                                }
                                else{
                                    $last_login = floor($days / (60 * 60)) . " hours";
                                }
                                $warning = "";
                            }
                            else{
                                $last_login = "$days days";
                                if ($days < 2){
                                    $last_login = "$days day";
                                    $warning = "";
                                }
                                elseif ($days < 5){
                                    $warning = "warning";
                                }
                                else{
                                    $warning = "danger";
                                }
                            }
?>
                            <td class='last_login <?=$odd?> <?=$warning?>'>
                                <?=$last_login?>
                            </td>
                        </tr>
<?php
                        if ($odd == ""){
                            $odd = "odd";
                        }
                        else{
                            $odd = "";
                        }
                    }
?>
                </table>
            </section>
<?php
        }
        include __DIR__ . "/inc/footer.php";
?>
    </body>
</html>

