<?php 
$css = array("pokemon", "stat-bar");
require 'includes/pdo.php';
include 'includes/pokemon-functions.php';
include 'includes/pokemon-search-recieve.php';
include 'includes/pokemon-name-title.php';
include 'includes/minecraft-redirect.php';
require 'includes/head.php';
?>

<body>
<?php include 'includes/hero.php';?>

<?php include 'includes/menu.php';?>

<div class="container-main" id="data">
    <div class="content">

        <div class="help-box">
            <div class="entry"><a href="#info">Info</a></div>
            <div class="divider"></div>
            <div class="entry"><a href="#training">Training</a></div>
            <div class="divider"></div>
            <div class="entry"><a href="#breeding">Breeding</a></div>
            <div class="divider"></div>
            <div class="entry"><a href="#stats">Base Stats</a></div>
            <div class="divider"></div>
            <div class="entry"><a href="#evolution">Evolutions</a></div>
            <div class="divider"></div>
            <div class="entry"><a href="#abilities">Abilities</a></div>
            <div class="divider"></div>
            <div class="entry"><a href="#moves">Moves</a></div>
            <div class="divider"></div>
            <div class="entry"><a href="#locations">Locations</a></div>
        </div>

        
        <div class="test-container">
            <div class="pokemon-container">

                <?php 

                //          ----- TYPE DATA -----

                $types = getPokemonTypes($pdo, $id);

                switch ($ver) {
                    case  3:
                        include 'includes/modify-type.php';
                        $image_size = 256;
                        $type_size = 28;
                        break;
                    case  4:
                        include 'includes/modify-type.php';
                        $image_size = 320;
                        $type_size = 28;
                        break;
                    case  6:
                        $image_size = 256;
                        $type_size = 20;
                        break;
                    default:
                        include 'includes/modify-type.php';
                        $image_size = 160;
                        $type_size = 28;
                }

                if ($id < 10) {
                    $display_value = "00";
                } elseif ($id < 100) {
                    $display_value = "0";
                } else {
                    $display_value = "";
                }



                //         ----- GENERAL DATA -----

                $species = getPokemonSpeciesInfo($pdo, $id);



                //          ----- STATS DATA -----

                $stats = getPokemonStats($pdo, $id);

                for ($x=0;$x<=5;$x++) {

                    $stat_bars[$x] = round($stats[$x] / 1.7, 1);
                    $stat_total = $stat_total + $stats[$x];

                    if ($stat_bars[$x] > 100) {
                        $stat_bars[$x] = 100;
                    }
                    if ($stats[$x] >= 140) {
                        $stat_color[$x] = 6;
                    } elseif ($stats[$x] >= 110) {
                        $stat_color[$x] = 5;
                    } elseif ($stats[$x] >= 80) {
                        $stat_color[$x] = 4;
                    } elseif ($stats[$x] >= 60) {
                        $stat_color[$x] = 3;
                    } elseif ($stats[$x] >= 45) {
                        $stat_color[$x] = 2;
                    } else {
                        $stat_color[$x] = 1;
                    }
                    if ($x == 0) {
                        // floor((2 * B + I + E) * L / 100 + L + 10) | E=63/I=31
                        $min_stat[$x] = floor(2 * $stats[$x] + 110);
                        $max_stat[$x] = floor(2 * $stats[$x] + 204);
                    } else {
                        // floor(floor((2 * B + I + E) * L / 100 + 5) * N) | E=63/I=31
                        $min_stat[$x] = floor(floor(2 * $stats[$x] + 5) * 0.9);
                        $max_stat[$x] = floor(floor(2 * $stats[$x] + 99) * 1.1);
                    }
                }
                $stat_name[0] = "HP"; $stat_name[1] = "Attack"; $stat_name[2] = "Defence"; $stat_name[3] = "Sp.Atk"; $stat_name[4] = "Sp.Def"; $stat_name[5] = "Speed"; 

                // 

                $species[7]

                ?>

                <div class="pokemon-image">
                    <?php echo '<img src="images/sprites-gen'.$ver.'/'.$id.'.png" height='.$image_size.'>';?>

                </div>
                <div>
                    <div class="pokedex-data" id="info">
                        <div class="pokemon-title"><?php if ($ver>4) {echo $title;} else {echo strtoupper($title);}?></div>
                        <table>
                            <tbody>
                                <tr>
                                    <th>National No.</th>
                                    <td><?php echo $display_value.''.$id;?></td>
                                </tr>
                                <tr>
                                    <th>Type</th>
                                    <td>
                                        <div class="type-container">
                                            <?php echo '<img src="images/types-gen'.$ver.'/'.$types[0].'.png" height='.$type_size.'>';?>

                                            <?php if (isset($types[1])) { echo '<img src="images/types-gen'.$ver.'/'.$types[1].'.png" height='.$type_size.'>';} ?>

                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th>Species</th>
                                    <td><?php echo $species[0];?></td>
                                </tr>
                                <tr>
                                    <th>Abilities</th>
                                    <td>
                                        <?php 
                                        $abilities = getPokemonAbilities($pdo, $id, $ver);
                                        echo '1. <a href="#ability">'.$abilities[0][0].'</a>';
                                        
                                        if (isset($abilities[1][0])) {
                                            echo '<br>2. <a href="#ability">'.$abilities[1][0].'</a>';
                                        }
                                        if ($ver > 4 && isset($abilities[2][0])) {
                                            echo '<br><div class="hidden-ability"><a href="#ability">'.$abilities[2][0].'</a> (hidden ability)</div>';
                                        }
                                        ?>

                                    </td>
                                </tr>
                                <tr>
                                    <th>Local No.</th>
                                    <td>
                                        <?php
                                        $regions = findObtainableRegions($pdo, $id, $ver);
                                        foreach ($regions as $region) {
                                            if ($region[0] < 10) {
                                                $display_value = "00";
                                            } elseif ($region[0] < 100) {
                                                $display_value = "0";
                                            } else {
                                                $display_value = "";
                                            }
                                            echo $display_value.''.$region[0];
                                            switch ($region[1]) {
                                                case "1,2,3,10,11":
                                                    echo ' <div class="dex-location">(FireRed/LeafGreen)</div><br>';
                                                    break;
                                                case "7,8,9":
                                                    echo ' <div class="dex-location">(Ruby/Sapphire/Emerald)</div><br>';
                                                    break;
                                                case "12,13":
                                                    echo ' <div class="dex-location">(Diamond/Pearl)</div><br>';
                                                    break;
                                                case "14":
                                                    echo ' <div class="dex-location">(Platinum)</div><br>';
                                                    break;
                                                case "15,16":
                                                    echo ' <div class="dex-location">(HeartGold/SoulSilver)</div><br>';
                                                    break;
                                                case "17,18":
                                                    echo ' <div class="dex-location">(Black/White)</div><br>';
                                                    break;
                                                case "21,22":
                                                    echo ' <div class="dex-location">(Black 2/White 2)</div><br>';
                                                    break;
                                                case "23,24":
                                                    echo ' <div class="dex-location">(X/Y - '.$region[3].')</div><br>';
                                                    break;
                                                case "25,26":
                                                    echo ' <div class="dex-location">(Omega Ruby/Alpha Sapphire)</div><br>';
                                                    break;
                                            }
                                        }
                                        ?>

                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                
                <div class="extra-stats">
                    <div class="pokedex-data" id="training">
                        <div class="pokemon-title">Training</div>
                        <table>
                            <tbody>
                                <tr>
                                    <th>Growth Rate</th>
                                    <td><?php echo ucwords($species[1]);?></td>
                                </tr>
                                <tr>
                                    <th>Catch Rate</th>
                                    <td><?php echo $species[2];?></td>
                                </tr>
                                <tr>
                                    <th>Base Friendship</th>
                                    <td><?php echo $species[3];?></td>
                                </tr>
                                <tr>
                                    <th>Base Exp.</th>
                                    <td><?php echo $species[4];?></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="pokedex-data" id="breeding">
                        <div class="pokemon-title">Breeding</div>
                        <table>
                            <tbody>
                                <tr>
                                    <th>Egg Groups</th>
                                    <td><?php echo $species[5]; if ($species[5] != $species[6]) {echo ', '.$species[6];}?></td>
                                </tr>
                                <tr>
                                    <th>Gender</th>
                                    <td><?php echo $gender_rate[7];?></td>

                                </tr>
                                <tr>
                                    <th>Egg Cycles</th>
                                    <td><?php echo $species[8].' <div class="dex-location">('.(($species[8] - 1) * 256).' steps)</div>';?></td>

                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        
            <div class="pokemon-container" id="stats">
                <div class="pokemon-stats">
                    <div class="pokemon-title">Base stats</div>
                    <table>
                        <tbody>
                            <?php
                            for ($x=0;$x<=5;$x++) {
                                echo '
                                <tr>
                                    <th>'.$stat_name[$x].'</th>
                                    <td class="value">'.$stats[$x].'</td>
                                    <td class="stat">
                                        <div class="stat-bar stat-bar-'.$stat_color[$x].'" style="width: '.$stat_bars[$x].'%;"></div>
                                    </td>
                                    <td>'.$min_stat[$x].'</td>
                                    <td>'.$max_stat[$x].'</td>
                                </tr>';
                            }
                            ?>

                        </tbody>
                        <tfoot>
                            <tr>
                                <th>Total</th>
                                <?php echo '<td><b>'.$stat_total.'</b></td>';?>

                                <td></td>
                                <td>Min</td>
                                <td>Max</td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
        
        <?php
        /*
        echo $title.'<br>';
        echo '<br>';

        $stat = getPokemonStats($pdo, $id);
        for ($x = 0; $x <= 5; $x++) { echo $stat[$x].'<br>'; }
        echo '<br>';
        
        $ability = getPokemonAbilities($pdo, $id);
        $ability1 = decodePokemonAbility($pdo, $ability[0]);
        
        if (!isset($ability[1])) {
            echo 'none<br>';
        } else {
            $ability2 = decodePokemonAbility($pdo, $ability[1]);
        }

        if (!isset($ability[2])) {
            echo 'none<br><br>';
        } else {
            $ability3 = decodePokemonAbility($pdo, $ability[2]);
        }
        
        echo $ability1[0].', '.$ability1[1].' Added in gen '.$ability1[2].'<br>';

        if (isset($ability2)) { 
            echo $ability2[0].', '.$ability2[1].' Added in gen '.$ability2[2].'<br>';
        }
        
        if (isset($ability3)) { 
            echo $ability3[0].', '.$ability3[1].' Added in gen '.$ability3[2].'<br>';
        }
        */


        include 'includes/evolution-chain.php';



        ?>

        <br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.<br>.

    </div>
</div>
<?php include 'includes/footer.php';?>

</body>
</html>