<?php

namespace Amwdeveloper\core;

use Amwdeveloper\model\layer;

class details extends layer
{
    public static function descriptionitem(object $description, int $section, int $index, int $level, int $excelents, int $durabillity, int $ancient, int $harmony, int $item360, int $socket1, int $socket2, int $socket3, int $socket4, int $socket5)
    {
        $life = 0;
        $nameitem = 0;
        $preview = '';
        $levelitem = 0;
        if ($level >= 128) {
            $skill = 1;
            $level -= 128;
        } else $skill = 0;

        while ($level >= 8) {
            $levelitem++;
            $level = $level - 8;
        }

        if ($level >= 4) {
            $luck = 1;
            $level -= 4;
        } else  $luck = 0;

        while ($level > 0) {
            $life += 4;
            $level--;
        }

        for ($options = 0; $options <= 6; $options++) {
            if (($excelents & (1 << $options)) != 0) {
                $opt[$options] = true;

                if ($nameitem == 0 && $options != 6)
                    $nameitem = 1;
            } else {
                $opt[$options] = false;
            }
        }

        $nameDivisionOne = explode("[", $description->name);

        if (isset($nameDivisionOne[1])) {
            $exp = explode("]", $nameDivisionOne[1]);
            $nameDivision = $exp[0];
        } else $nameDivision = "C";

        if ($opt[6] == true) $life += 16;
        ($nameitem == 1 and $section != 12) ?
            $preview = "<p class='" . strtolower($nameDivision) . " e'>Excellent {$description->name} +{$levelitem}</p>"
            :
            $preview = "<p class='" . strtolower($nameDivision) . "'>{$description->name} +{$levelitem}</p>";

        $classe = "";
        $attackscpeed = "";
        $defense = "";
        $defenserate = "";
        $damagemin = "";
        $reqlevel = "";
        $walkspeed = "";
        $reqstrength = "";
        $reqdexterity = "";
        $reqenergy = "";
        $reqvitality = "";
        $magicdurability = "";
        $magicrate = "";
        $swimming = "";
        $ancientoption = "";

        if ($description->dw != 0) {
            if ($description->dw == 1) $classe .= "<p>Can be equipped by: Dark Wizard</p>";
            else $classe .= "<p>Can be equipped by: Soul Master</p>";
        }
        if ($description->dk != 0) {
            if ($description->dk == 1) $classe .= "<p>Can be equipped by: Dark Knight</p>";
            else $classe .= "<p>Can be equipped by: Blade Knight</p>";
        }
        if ($description->fe != 0) {
            if ($description->fe == 1) $classe .= "<p>Can be equipped by: Fairy Elf</p>";
            else $classe .= "<p>Can be equipped by: Muse Elf</p>";
        }
        if ($description->mg != 0) {
            if ($description->mg == 1) $classe .= "<p>Can be equipped by: Magic Gladiator</p>";
        }
        if ($description->dl != 0) {
            if ($description->dl == 1) $classe .= "<p>Can be equipped by: Dark Lord</p>";
            else $classe .= "<p>Can be equipped by: Duel Master</p>";
        }
        if ($description->su != 0) {
            if ($description->su == 1) $classe .= "<p>Can be equipped by: Summoner</p>";
            else $classe .= "<p>Can be equipped by: Bloody Summoner</p>";
        }
        if ($description->rf != 0) {
            if ($description->rf == 1) $classe .= "<p>Can be equipped by: Rage Fighter</p>";
            else $classe .= "<p>Can be equipped by: Fist Fighter</p>";
        }

        if ($description->attackspeed != 0) {
            $attackscpeed = "<p>Attack Speed: {$description->attackspeed}</p>";
        }
        if ($description->defense >= 1) {
            $color = "";
            $livelcount = 0;
            if ($section != 6) {
                if ($levelitem <= 9)  $livelcount = (($levelitem * 3));
                elseif ($levelitem == 10)  $livelcount = (($levelitem * 3) + 1);
                elseif ($levelitem == 11)  $livelcount = (($levelitem * 3) + 3);
                elseif ($levelitem == 12)  $livelcount = (($levelitem * 3) + 6);
                elseif ($levelitem == 13)  $livelcount = (($levelitem * 3) + 10);
                elseif ($levelitem == 14)  $livelcount = (($levelitem * 3) + 15);
                elseif ($levelitem == 15)  $livelcount = (($levelitem * 3) + 21);
            } else {
                $livelcount = $levelitem;
            }

            if ($section == 12) {
                $livelcount -= 2;
            }


            if ($opt[0] or $opt[1] or $opt[2] or $opt[3] or $opt[4] or $opt[5]) {
                if ($section != 6 and $section != 12) {
                    $color = "blue";
                    $livelcount += 18;
                }
            }
            $defense = "<p class='{$color}'>Defense: " . ($description->defense + ($livelcount)) . "</p>";
        }

        if ($section == 6) {

            if ($opt[0] or $opt[1] or $opt[2] or $opt[3] or $opt[4] or $opt[5]) {
                if ($levelitem == 11) $defenserate = "<p class='blue'>Defense rate: " . floor(($description->defense + $levelitem) * 4.1) + 16 . "</p>";
                if ($levelitem == 12) $defenserate = "<p class='blue'>Defense rate: " . floor(($description->defense + $levelitem) * 4.1) + 18 . "</p>";
                if ($levelitem == 13) $defenserate = "<p class='blue'>Defense rate: " . floor(($description->defense + $levelitem) * 4.1) + 21 . "</p>";
                if ($levelitem == 14) $defenserate = "<p class='blue'>Defense rate: " . floor(($description->defense + $levelitem) * 4.1) + 25 . "</p>";
                if ($levelitem == 15) $defenserate = "<p class='blue'>Defense rate: " . floor(($description->defense + $levelitem) * 4.1) + 30 . "</p>";
                else $defenserate = "<p class='blue'>Defense rate: " . floor(($description->defense + $levelitem) * 4.1) + 20 . "</p>";
            } else {
                $defenserate = "<p class='blue'>Defense rate: " . floor(($description->defense + $levelitem) * 5.5) . "</p>";
            }
        }
        if ($description->damagemin != 0) {
            $damagemin = "<p class='blue'>Attack Power: " . floor(($description->damagemin * 2) / 1.46) . " ~ " . floor(($description->damagemax * 2) / 1.5) . "</p>";
        }
        if ($description->reqlevel != 0) {
            $reqlevel = "<p>Level available: {$description->reqlevel}</p>";
        }
        if ($section == 11) {
            $walkspeed = "<p>&nbsp;</p><p class='blue'>Increase movement speed</p>";
        }
        if ($description->reqstrength != 0) {
            $reqstrength = "<p>Strength available: {$description->reqstrength}</p>";
        }
        if ($description->reqdexterity != 0) {
            $reqdexterity = "<p>Dexterity available: {$description->reqdexterity}</p>";
        }
        if ($description->reqenergy != 0) {
            $reqenergy = "<p>Energy available: {$description->reqenergy}</p>";
        }
        if ($description->reqvitality != 0) {
            $reqvitality = "<p>Vitality available: {$description->reqvitality}</p>";
        }
        if ($description->magicdurability != 0) {
            $magicdurability = "<p>&nbsp;</p><p class='blue'>Magic attack durability: {$description->magicdurability}</p>";
        }
        if ($description->magicrate != 0) {
            $magicrate = "<p class='blue'>Increases Wizardry dry by " . floor($description->magicrate / 2) . "%</p>";
        }

        if ($ancient and $section <= 6) {
            $ancientoption = "<p class='blue'>Increases strength +5 </p>";
        }

        if ($section == 10) $swimming = "<p class='blue'>Increases swimming speed</p>";

        if ($section == 13 and ($index >= 0 and $index <= 5)) {
            $preview .= "<p>&nbsp;</p><p>Life: [{$description->durability}]</p><p>&nbsp;</p>";
        } else {
            $preview .= "<p>&nbsp;</p>
            {$damagemin}
            {$defense}
            {$defenserate}
            {$attackscpeed}
            <p>Durabillity: [{$durabillity}/{$durabillity}]</p>
            {$reqstrength}
            {$reqdexterity}
            {$reqenergy}
            {$reqvitality}
            {$magicrate}
            {$swimming}
            {$walkspeed}
            <p>&nbsp;</p>
            {$classe}
            {$ancientoption}
            <p>&nbsp;</p>
            ";
        }

        if ($skill == 1 and ($section != 13 and $index <= 4)) $preview .= "<p>+ Skill</p>";

        if ($item360 == 136 and ($section >= 7 or $section <= 11)) {
            $preview .= "<p class='purple'>" . additional['item380']['defense']['add_01'] . "</p>";
            $preview .= "<p class='purple'>" . additional['item380']['defense']['add_02'] . "</p> <p>&nbsp;</p>";
        }


        if (!empty($harmony) && (isset(additional['harmony']['weapons'][$harmony]) or isset(additional['harmony']['defense']))) {
            if ($section < 6) {
                $preview .= "<p>&nbsp;</p>";
                $preview .= "<p class='yellow'>" . additional['harmony']['weapons'][$harmony] . "</p>";
                $preview .= "<p>&nbsp;</p>";
            } else {
                $preview .= "<p>&nbsp;</p>";
                $preview .= "<p class='yellow'>" . additional['harmony']['defense'][$harmony] . "</p>";
                $preview .= "<p>&nbsp;</p>";
            }
        }


        if ($luck == 1) {
            $preview .= "
                    <p class='blue'>Luck (Success rate increase +10%)</p>
                    <p class='blue'>Luck (Critical damage rate +5%)</p>
                    ";
        }

        if ($section < 6) {
            if ($life > 0) $preview .= "<p class='blue'>Additional Damage +" . $life . "</p>";
            if ($opt[5] == true) $preview .= "<p class='blue'>Excellent damage rate +10%</p>";
            if ($opt[4] == true) $preview .= "<p class='blue'>Increase damage +level/20</p>";
            if ($opt[3] == true) $preview .= "<p class='blue'>Increase damage +2%</p>";
            if ($opt[2] == true) $preview .= "<p class='blue'>Increase Attacking(wizardry) speed +7</p>";
            if ($opt[1] == true) $preview .= "<p class='blue'>Increases recovery mana after hunting monsters +life/8</p>";
            if ($opt[0] == true) $preview .= "<p class='blue'>Increases recovery mana after hunting monsters +mana/8</p>";
        } elseif ($section < 12) {
            if ($life > 0) $preview .= "<p class='blue'>Additional defense +" . $life . "</p>";
            if ($opt[5] == true) $preview .= "<p class='blue'>Increase maximum life +4%</p>";
            if ($opt[4] == true) $preview .= "<p class='blue'>Increase maximum mana +4%</p>";
            if ($opt[3] == true) $preview .= "<p class='blue'>Damage decrease +4%</p>";
            if ($opt[2] == true) $preview .= "<p class='blue'>Reflect damage +5%</p>";
            if ($opt[1] == true) $preview .= "<p class='blue'>Defense success rate + 10%</p>";
            if ($opt[0] == true) $preview .= "<p class='blue'>Increases zen drop rate +70% </p>";
        }

        if ($section == 13 and ($index >= 8 and $index <= 13)) {
            if ($opt[0] == true) $preview .= "<p class='blue'>Automatic life recovery +7</p>";
            if ($opt[5] == true) $preview .= "<p class='blue'>Increase maximum life +4%</p>";
            if ($opt[4] == true) $preview .= "<p class='blue'>Increase maximum mana +4%</p>";
            if ($opt[3] == true) $preview .= "<p class='blue'>Damage decrease +4%</p>";
            if ($opt[2] == true) $preview .= "<p class='blue'>Reflect damage +5%</p>";
            if ($opt[1] == true) $preview .= "<p class='blue'>Defense success rate 10%</p>";
            if ($opt[0] == true) $preview .= "<p class='blue'>Increases zen drop rate +70</p>";
        } elseif ($section == 13 and ($index >= 20 and $index <= 28)) {
            if ($opt[0] == true) $preview .= "<p class='blue'>Max AG increased by 7%</p>";
            if ($opt[5] == true) $preview .= "<p class='blue'>Excellent damage rate +10%</p>";
            if ($opt[4] == true) $preview .= "<p class='blue'>Increase damage +level/20</p>";
            if ($opt[3] == true) $preview .= "<p class='blue'>Increase damage +2%</p>";
            if ($opt[2] == true) $preview .= "<p class='blue'>Increase attacking (wizardry) speed +7</p>";
            if ($opt[1] == true) $preview .= "<p class='blue'>Increases recovery mana after hunting monsters +life/8</p>";
            if ($opt[0] == true) $preview .= "<p class='blue'>Increases recovery mana after hunting monsters +mana/8</p>";
        } elseif ($section == 13 && $index == 30) {

            if ($opt[0] == true) $preview .= "<p class='blue'>HP " . (50 + ($levelitem * 5)) . " increased</p>";
            if ($opt[1] == true) $preview .= "<p class='blue'>Mana " . (50 + ($levelitem * 5)) . " increased</p>";
            if ($opt[2] == true) $preview .= "<p class='blue'>Ignore opponent's defensive power 3%</p>";
            if ($opt[4] == true) $preview .= "<p class='blue'>Increase command +85</p>";
            if ($life > 0) {
                $preview .= "<p class='blue'>Additional damage +" . $life . "</p>";
            }
        } elseif ($section == 12 && $index < 7) {

            if ($opt[0] == true) $preview .= "<p class='blue'>HP " . (50 + ($levelitem * 5)) . " increased</p>";
            if ($opt[1] == true) $preview .= "<p class='blue'>Mana " . (50 + ($levelitem * 5)) . " increased</p>";
            if ($opt[2] == true) $preview .= "<p class='blue'>Ignore opponent's defensive power 3%</p>";
            if ($opt[3] == true) $preview .= "<p class='blue'>Max AG +50 increased</p>";
            if ($opt[4] == true) $preview .= "<p class='blue'>Increase attacking (wizardry) speed +5</p>";
            if ($life > 0) {
                if ($opt[5] == true) {
                    $life = $life / 4;
                    $preview .= "<p class='blue'>Automatic life recovery " . $life . "%</p>";
                } else $preview .= "<p class='blue'>Additional damage +" . $life . "</p>";
            }
        }

        if ($section == 13 and $index == 0) {
            $preview .= "
                <p>Absorb 20% of damage</p>
                <p>Increases maximum HP by +50</p>
                <p>Minimum level required:83 </p>
            ";
        }
        if ($section == 13 and $index == 1) {
            $preview .= "
                <p>Absorb 20% of damage</p>
                <p>Increases attach power and wizardry by 30%</p>
                <p>Minimum level required:88 </p>
            ";
        }
        if ($section == 13 and $index == 2) {
            $preview .= "
                <p>Minimum level required:88 </p>
            ";
        }
        if ($section == 13 and $index == 3) {
            $preview .= "
            <p>Increases damage by 15%</p>
            <p>Absorb 10% of damage</p>
            <p>&nbsp;</p></p>
            <p class='blue'>Raid skill (Mana:9) </p>
            <p class='bred'>Knight specific skill </p>
            ";
        }
        if ($section == 13 and $index == 4) {
            $preview .= "
            <p class='bred'>Can be equipped by Dark Lord</p>
            <p class='blue'>Earth Shake Skill (Mana:0)</p>
            <p class='blue'>Increased defensive skill +185 </p>
            <p class='blue'>Absorb 15% additional damage</p>
            <p class='blue'>Increase 2 possible attack distance </p>
            ";
        }

        if ($section >= 7 and $ancient >= 5) {
            if ($ancient == 5) {
                $preview .= "  
                    <p>&nbsp;</p> 
                    <p class='yellow'>Set item option info</p>
                    <p>&nbsp;</p> 

                        <p class='gray'>" . additional['ancient']['defense'][1]['add_01'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][1]['add_02'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][1]['add_03'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][1]['add_04'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][1]['add_05'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][1]['add_06'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][1]['add_07'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][1]['add_08'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][1]['add_09'] . "</p>
                ";
            }
            if ($ancient == 10) {
                $preview .= "  
                    <p>&nbsp;</p> 
                    <p class='yellow'>Set item option info</p>
                    <p>&nbsp;</p> 
                    <p class='gray'>" . additional['ancient']['defense'][2]['add_01'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][2]['add_02'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][2]['add_03'] . "</p>
                        <p class='gray'>" . additional['ancient']['defense'][2]['add_04'] . "</p>
                ";
            }
        }

        if ($section <= 6 and $ancient >= 5) {
            if ($ancient == 5) {
                $preview .= "
                        <p>&nbsp;</p> 
                        <p class='yellow'>Set item option info</p>
                        <p>&nbsp;</p> 
                        <p class='gray'>" . additional['ancient']['weapons'][1]['add_01'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][1]['add_02'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][1]['add_03'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][1]['add_04'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][1]['add_05'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][1]['add_06'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][1]['add_07'] . "</p>   
                    ";
            }

            if ($ancient == 10) {
                $preview .= "
                        <p>&nbsp;</p> 
                        <p class='gray'>" . additional['ancient']['weapons'][2]['add_01'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][2]['add_02'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][2]['add_03'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][2]['add_04'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][2]['add_05'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][2]['add_06'] . "</p>
                        <p class='gray'>" . additional['ancient']['weapons'][2]['add_07'] . "</p>  
                    ";
            }
        }

        if ($socket1 and $socket1 != 255)
            $preview .= "
            <p>&nbsp; </p>
            <p class='purple'>" . additional['socket'][$socket1]['name'] . "</p>";
        if ($socket2 and $socket2 != 255)
            $preview .= "<p class='purple'>" . additional['socket'][$socket2]['name'] . "</p>";
        if ($socket3 and $socket3 != 255)
            $preview .= "<p class='purple'>" . additional['socket'][$socket3]['name'] . "</p>";
        if ($socket4 and $socket4 != 255)
            $preview .= "<p class='purple'>" . additional['socket'][$socket4]['name'] . "</p>";
        if ($socket5 and $socket5 != 255)
            $preview .= "<p class='purple'>" . additional['socket'][$socket5]['name'] . "</p>";

        return $preview;
    }
}
