<section class="content-header">
    <h1><?= __('Ranking Reward plugin settings') ?></h1>
</section>

<section class="content">
    <div class="box box-default">
        <form data-ajax class="form-horizontal form-focus" action="<?= admin_url_to('/rankings/reward/config') ?>" method="post">
            <?= csrf_field() ?>

            <div class="box-body" style="padding:0">
                <table class="table table-condensed table-hover table-striped">
                    <thead>
                        <tr>
                            <th><?= __('Name') ?></th>
                            <th width="100" class="text-center"><?= __('Reset') ?></th>
                            <th class="text-center" width="10"><?= __('Rewards 1st/2nd/3rd') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($rankings as $id => $ranking): ?>
                            <?php if (!$ranking['active']) continue; ?>
                            <?php $reward = config('rewards.rankings.' . $id) ?>
                            <tr>
                                <td style="vertical-align:middle"><?= $ranking['name'] ?></td>
                                <td class="text-center" style="vertical-align:middle">
                                    <input<?= $reward && $reward['normal']['reset'] ? ' checked' : '' ?> type="checkbox" name="reward[<?= $id ?>][normal][reset]" value="1" />
                                </td>
                                <td style="white-space:nowrap">
                                    <table>
                                        <tbody>
                                            <tr>
                                                <?php for ($i = 0; $i < 3; $i++): ?>
                                                    <td>
                                                        <select style="width:100px" name="reward[<?= $id ?>][normal][reward][<?= $i ?>][coin]" class="form-control">
                                                            <option value=""></option>
                                                            <?php foreach (config('coins', []) as $coin): ?>
                                                                <option<?= $reward && $reward['normal']['reward'][$i]['coin'] === $coin['id'] ? ' selected' : '' ?> value="<?= $coin['id'] ?>"><?= $coin['name'] ?></option>
                                                            <?php endforeach ?>
                                                        </select>
                                                    </td>
                                                    <td>
                                                        <input style="width:60px;margin-right:5px" type="text" value="<?= $reward ? $reward['normal']['reward'][$i]['amount'] : '' ?>" name="reward[<?= $id ?>][normal][reward][<?= $i ?>][amount]" class="form-control" />
                                                    </td>
                                                <?php endfor ?>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>

                            <?php if (isset($ranking['configs']['daily'])): ?>
                                <tr>
                                    <td style="vertical-align:middle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?= $ranking['name'] ?> <?= __('Daily') ?></td>
                                    <td class="text-center" style="vertical-align:middle">
                                        <input<?= $reward && isset($reward['daily']) && $reward['daily']['reset'] ? ' checked' : '' ?>  type="checkbox" name="reward[<?= $id ?>][daily][reset]" value="1" />
                                    </td>
                                    <td style="white-space:nowrap">
                                        <table>
                                            <tbody>
                                            <tr>
                                                <?php for ($i = 0; $i < 3; $i++): ?>
                                                    <td>
                                                        <select style="width:100px" name="reward[<?= $id ?>][daily][reward][<?= $i ?>][coin]" class="form-control">
                                                            <option value=""></option>
                                                            <?php foreach (config('coins', []) as $coin): ?>
                                                                <option<?= $reward && isset($reward['daily']) && $reward['daily']['reward'][$i]['coin'] === $coin['id'] ? ' selected' : '' ?> value="<?= $coin['id'] ?>"><?= $coin['name'] ?></option>
                                                            <?php endforeach ?>
                                                        </select>
                                                    </td>
                                                    <td>
                                                        <input style="width:60px;margin-right:5px" type="text" value="<?= $reward && isset($reward['daily']) ? $reward['daily']['reward'][$i]['amount'] : '' ?>" name="reward[<?= $id ?>][daily][reward][<?= $i ?>][amount]" class="form-control" />
                                                    </td>
                                                <?php endfor ?>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            <?php endif ?>
                            <?php if (isset($ranking['configs']['weekly'])): ?>
                                <tr>
                                    <td style="vertical-align:middle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?= $ranking['name'] ?> <?= __('Weekly') ?></td>
                                    <td class="text-center" style="vertical-align:middle">
                                        <input<?= $reward && isset($reward['weekly']) && $reward['weekly']['reset'] ? ' checked' : '' ?>  type="checkbox" name="reward[<?= $id ?>][weekly][reset]" value="1" />
                                    </td>
                                    <td style="white-space:nowrap">
                                        <table>

                                            <tbody>
                                            <tr>
                                                <?php for ($i = 0; $i < 3; $i++): ?>
                                                    <td>
                                                        <select style="width:100px" name="reward[<?= $id ?>][weekly][reward][<?= $i ?>][coin]" class="form-control">
                                                            <option value=""></option>
                                                            <?php foreach (config('coins', []) as $coin): ?>
                                                                <option<?= $reward && isset($reward['weekly']) && $reward['weekly']['reward'][$i]['coin'] === $coin['id'] ? ' selected' : '' ?> value="<?= $coin['id'] ?>"><?= $coin['name'] ?></option>
                                                            <?php endforeach ?>
                                                        </select>
                                                    </td>
                                                    <td>
                                                        <input style="width:60px;margin-right:5px" type="text" value="<?= $reward && isset($reward['weekly']) ? $reward['weekly']['reward'][$i]['amount'] : '' ?>" name="reward[<?= $id ?>][weekly][reward][<?= $i ?>][amount]" class="form-control" />
                                                    </td>
                                                <?php endfor ?>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            <?php endif ?>

                            <?php if (isset($ranking['configs']['monthly'])): ?>
                                <tr>
                                    <td style="vertical-align:middle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?= $ranking['name'] ?> <?= __('Monthly') ?></td>
                                    <td class="text-center" style="vertical-align:middle">
                                        <input<?= $reward && isset($reward['monthly']) && $reward['monthly']['reset'] ? ' checked' : '' ?>  type="checkbox" name="reward[<?= $id ?>][monthly][reset]" value="1" />
                                    </td>
                                    <td style="white-space:nowrap">
                                        <table>

                                            <tbody>
                                            <tr>
                                                <?php for ($i = 0; $i < 3; $i++): ?>
                                                    <td>
                                                        <select style="width:100px" name="reward[<?= $id ?>][monthly][reward][<?= $i ?>][coin]" class="form-control">
                                                            <option value=""></option>
                                                            <?php foreach (config('coins', []) as $coin): ?>
                                                                <option<?= $reward && isset($reward['monthly']) && $reward['monthly']['reward'][$i]['coin'] === $coin['id'] ? ' selected' : '' ?> value="<?= $coin['id'] ?>"><?= $coin['name'] ?></option>
                                                            <?php endforeach ?>
                                                        </select>
                                                    </td>
                                                    <td>
                                                        <input style="width:60px;margin-right:5px" type="text" value="<?= $reward && isset($reward['monthly']) ? $reward['monthly']['reward'][$i]['amount'] : '' ?>" name="reward[<?= $id ?>][monthly][reward][<?= $i ?>][amount]" class="form-control" />
                                                    </td>
                                                <?php endfor ?>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            <?php endif ?>

                        <?php endforeach ?>
                    </tbody>
                </table>
            </div>

            <div class="box-footer">
                <input type="submit" class="btn btn-primary" value="<?= __('Save') ?>" />
            </div>
        </form>
    </div>
</section>