<?php
    /**
     * Rune upgrade report filter view.
     *
     * To be included from the rune upgrade report view.
     *
     * @category View
     * @property_read mixed[] $filters Selected filters.
     * @property_read int $page Player ID.
     */
?>
<?php
    if (count($custom_filters) > 0){
?>
        <script>

            /**
             * Changes the filter description.
             *
             * @param id Filter id.
             */
            function customFilterDescription(id){
                switch (id){
<?php
                    foreach($custom_filters AS $filter){
?>
                        case '<?=$filter->id?>':
                            document.getElementById("custom_filter_description").style.display = 'block';
                            document.getElementById("custom_filter_description").innerHTML = '<?=$filter->description?>';
                            break;
<?php
                    }
?>
                }
            }
        </script>
        <form action='/<?=$UID?>/report/runeupgrade/' method='get' id='custom_filter_runes' class='custom_filter'>
            <span class='custom_filter_title'>Custom filters:</span>
            <select name='custom_filter' onChange='customFilterDescription(this.value);' onload='alert("LOAD");customFilterDescription("<?=$_GET["custom_filter"]?>");'>
                <option> </option>
<?php
                 foreach($custom_filters AS $filter){
                    if ($_GET["custom_filter"] == $filter->id){
                        $selected = "selected='selected'";
                    }
                    else{
                        $selected = "";
                    }
?>
                    <option value='<?=$filter->id?>' <?=$selected?>><?=$filter->name?></option>
<?php
                 }
?>
            </select>
            <input type='submit' value='Apply'/>
            <p id='custom_filter_description'> </p>
            <script>
                customFilterDescription("<?=$_GET["custom_filter"]?>");
            </script>
        </form>
<?php
    }
?>
<form action='/<?=$UID?>/report/runeupgrade/' method='get' id='filter_runeupgrade' class='filter'>
    <table>
        <tr>
            <td class='filter filter_title' rowspan='2'>
                <span>
                    Monster
                </span>
            </td>
            <td class='filter' colspan='3'>
                <span>Name:</span>
                <input type='text' name='monster_name' id='filter_name' value='<?=$filters["MONSTER_NAME"]?>'/>
            </td>
            <td class='filter'>
                <span>Stars:</span>
                <input type='number' name='monster_min_stars' id='filter_stars_min' min='1' max='6' value='<?=$filters["MONSTER_MIN_STARS"]?>'/>
                -
                <input type='number' name='monster_max_stars' id='filter_stars_max' min='1' max='6' value='<?=$filters["MONSTER_MAX_STARS"]?>'/>
            </td>
        </tr>
            <td class='filter' colspan='4'>
<?php
                $checked = "";
                if ($filters["MONSTER_IN_STORAGE"]){
                    $checked = "checked";
                }
?>
                <input type='checkbox' name='monster_in_storage' id='filter_monster_in_storage' <?=$checked?>/>
                <label for='filter_monster_in_storage'>Show monsters in storage</label>
            </td>
        </tr>
        <tr>
            <td class='filter filter_title filter_separator' rowspan='5'>
                <span>
                    Runes
                </span>
            </td>
            <td class='filter filter_stars filter_separator' colspan='2'>
                <span>Stars:</span>
                <input type='number' name='rune_min_stars' id='filter_stars_min' min='1' max='6' value='<?=$filters["RUNE_MIN_STARS"]?>'/>
                -
                <input type='number' name='rune_max_stars' id='filter_stars_max' min='1' max='6' value='<?=$filters["RUNE_MAX_STARS"]?>'/>
            </td>
            <td class='filter filter_separator' colspan='2'>
                <span>Level:</span>
                <input type='number' name='rune_min_level' id='filter_level_min' min='0' max='15' value='<?=$filters["RUNE_MIN_LEVEL"]?>'/>
                -
                <input type='number' name='rune_max_level' id='filter_level_max' min='0' max='15' value='<?=$filters["RUNE_MAX_LEVEL"]?>'/>
            </td>
        </tr>
        <tr>
            <td class='filter' rowspan='4'>
                <span>Slot:</span>
                <select multiple name='rune_slot[]' id='filter_slot'>
<?php
                    for ($i = 0; $i < 6; $i ++){
                        if (in_array($i, $filters["RUNE_SLOT"])){
                            $selected = "selected='selected'";
                        }
                        else{
                            $selected = "";
                        }
?>
                        <option value='<?=$i?>' <?=$selected?>><?=$i?></option>
<?php
                    }
?>
                </select>
            </td>
            <td class='filter' colspan='3'>
                <span>Quality:</span>
<?php

                $selected = Array("", "", "", "", "");
                $selected[$filters["RUNE_MIN_QUALITY"] - 1] = "selected";
?>
                <select name='rune_min_quality' id='filter_quality_min'>
                    <option value='<?=QUALITY_ID::NORMAL?>' <?=$selected[0]?>>Normal</option>
                    <option value='<?=QUALITY_ID::MAGIC?>' <?=$selected[1]?>>Magic</option>
                    <option value='<?=QUALITY_ID::RARE?>' <?=$selected[2]?>>Rare</option>
                    <option value='<?=QUALITY_ID::HERO?>' <?=$selected[3]?>>Hero</option>
                    <option value='<?=QUALITY_ID::LEGEND?>' <?=$selected[4]?>>Legend</option>
                </select>
                -
<?php
                $selected = Array("", "", "", "", "");
                $selected[$filters["RUNE_MAX_QUALITY"] - 1] = "selected";
?>
                <select name='rune_max_quality' id='filter_quality_max'>
                    <option value='<?=QUALITY_ID::NORMAL?>' <?=$selected[0]?>>Normal</option>
                    <option value='<?=QUALITY_ID::MAGIC?>' <?=$selected[1]?>>Magic</option>
                    <option value='<?=QUALITY_ID::RARE?>' <?=$selected[2]?>>Rare</option>
                    <option value='<?=QUALITY_ID::HERO?>' <?=$selected[3]?>>Hero</option>
                    <option value='<?=QUALITY_ID::LEGEND?>' <?=$selected[4]?>>Legend</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class='filter' colspan='3'>
                <span>Original quality:</span>
<?php
                $selected = Array("", "", "", "", "");
                $selected[$filters["RUNE_MIN_ORIGINAL_QUALITY"] - 1] = "selected";
?>
                <select name='rune_min_original_quality' id='filter_original_quality_min'>
                    <option value='<?=QUALITY_ID::NORMAL?>' <?=$selected[0]?>>Normal</option>
                    <option value='<?=QUALITY_ID::MAGIC?>' <?=$selected[1]?>>Magic</option>
                    <option value='<?=QUALITY_ID::RARE?>' <?=$selected[2]?>>Rare</option>
                    <option value='<?=QUALITY_ID::HERO?>' <?=$selected[3]?>>Hero</option>
                    <option value='<?=QUALITY_ID::LEGEND?>' <?=$selected[4]?>>Legend</option>
                </select>
                -
<?php
                $selected = Array("", "", "", "", "");
                $selected[$filters["RUNE_MAX_ORIGINAL_QUALITY"] - 1] = "selected";
?>
                <select name='rune_max_original_quality' id='filter_original_quality_max'>
                    <option value='<?=QUALITY_ID::NORMAL?>' <?=$selected[0]?>>Normal</option>
                    <option value='<?=QUALITY_ID::MAGIC?>' <?=$selected[1]?>>Magic</option>
                    <option value='<?=QUALITY_ID::RARE?>' <?=$selected[2]?>>Rare</option>
                    <option value='<?=QUALITY_ID::HERO?>' <?=$selected[3]?>>Hero</option>
                    <option value='<?=QUALITY_ID::LEGEND?>' <?=$selected[4]?>>Legend</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class='filter' colspan='3'>
                <span>Efficiency:</span>
                <input type='number' name='rune_min_efficiency' id='filter_efficiency_min' min='0' max='100' value='<?=$filters["RUNE_MIN_EFFICIENCY"]?>'/>%
                -
                <input type='number' name='rune_max_efficiency' id='filter_efficiency_max' min='0' max='100' value='<?=$filters["RUNE_MAX_EFFICIENCY"]?>'/>%
            </td>
        </tr>
        <tr>
            <td class='filter' colspan='3'>
                <span>Maximum efficiency:</span>
                <input type='number' name='rune_min_max_efficiency' id='filter_max_efficiency_min' min='0' max='100' value='<?=$filters["RUNE_MIN_MAX_EFFICIENCY"]?>'/>%
                -
                <input type='number' name='rune_max_max_efficiency' id='filter_max_efficiency_max' min='0' max='100' value='<?=$filters["RUNE_MAX_MAX_EFFICIENCY"]?>'/>%
            </td>
        </tr>
        <tr>
            <td class='filter filter_title filter_separator' rowspan='3'>
                <span>
                    Alternatives
                </span>
            </td>
            <td class='filter filter_stars filter_separator'>
                <span>Min. stars:</span>
                <input type='number' name='alternative_min_stars' id='filter_stars_min' min='1' max='6' value='<?=$filters["ALTERNATIVE_MIN_STARS"]?>'/>
            </td>
            <td class='filter filter_separator' colspan='2'>
                <span>Min. O. quality:</span>
<?php
                $selected = Array("", "", "", "", "");
                $selected[$filters["ALTERNATIVE_MIN_ORIGINAL_QUALITY"]] = "selected";
?>
                <select name='alternative_min_original_quality' id='filter_original_quality_min'>
                    <option value='<?=QUALITY_ID::NORMAL?>' <?=$selected[0]?>>Normal</option>
                    <option value='<?=QUALITY_ID::MAGIC?>' <?=$selected[1]?>>Magic</option>
                    <option value='<?=QUALITY_ID::RARE?>' <?=$selected[2]?>>Rare</option>
                    <option value='<?=QUALITY_ID::HERO?>' <?=$selected[3]?>>Hero</option>
                    <option value='<?=QUALITY_ID::LEGEND?>' <?=$selected[4]?>>Legend</option>
                </select>
            </td>
            <td class='filter filter_separator'>
                <span>Min. Level:</span>
                <input type='number' name='alternative_min_level' id='filter_level_min' min='0' max='15' value='<?=$filters["ALTERNATIVE_MIN_LEVEL"]?>'/>
            </td>
        </tr>
        <tr>
            <td class='filter' colspan='4'>
                <span>Condition:</span>
<?php
                $selected = Array("", "", "", "", "", "");
                $selected[$filters["ALTERNATIVE_CONDITION"]] = "selected";

?>
                <select name='alternative_condition'>
                    <option value='0' <?=$selected[0]?>>Higher grade, any quality
                    <option value='1' <?=$selected[1]?>>Higher grade or higher quality
                    <option value='2' <?=$selected[2]?>>Equal or higher grade and equal or higher quality</option>
                    <option value='3' <?=$selected[3]?>>Equal or higher grade and higher quality</option>
                    <option value='4' <?=$selected[4]?>>Equal grade and equal or higher quality</option>
                    <option value='5' <?=$selected[5]?>>Higher grade and higher quality</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class='filter' colspan='4'>
                <span>Source:</span>
<?php
                $selected = Array("", "", "", "");
                $selected[$filters["ALTERNATIVE_SOURCE"]] = "selected";
?>
                <select name='alternative_source'>
                    <option value='0' <?=$selected[0]?>>Inventory only</option>
                    <option value='1' <?=$selected[1]?>>Inventory or assigned to a lower grade monster</option>
                    <option value='2' <?=$selected[2]?>>Any</option>
                </select>
            </td>
        </tr>
    </table>
    <div id='filter_apply'>
        <input type='submit' value='Apply'/>
    </div>
</form>

