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

<div class="modal" id="modal-add-condition" data-width="500"></div>
<div class="modal" id="modal-edit-condition" data-width="500"></div>

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

            <div class="box-body">
                <div class="section">
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                            <h5><?= __('Settings') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="form-control-label" for="type"><?= __('Type') ?></label>
                                        <select class="form-control" id="type" name="type">
                                            <option value=""></option>
                                            <?php foreach (['A' => 'Cumulative', 'P' => 'Scored'] as $type => $name): ?>
                                                <option<?= config('reset.type') === $type ? ' selected' : '' ?> value="<?= $type ?>"><?= __($name) ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="form-control-label" for="max"><?= __('Max') ?></label>
                                        <input type="text" class="form-control" value="<?= config('reset.max') ?>" name="max" id="max" />
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="section">
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                            <h5><?= __('Conditions') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <?php if (empty($conditions)): ?>
                                <div class="callout callout-warning">
                                    <p><?= __('No conditions found') ?></p>
                                </div>
                            <?php else: ?>
                                <table class="table table-condensed table-hover table-striped">
                                    <thead>
                                        <tr>
                                            <th><?= __('Interval') ?></th>
                                            <th width="10"></th>
                                        </tr>
                                    </thead>

                                    <tbody>
                                        <?php foreach ($conditions as $index => $condition): ?>
                                            <tr>
                                                <td><?= $condition['starts'] ?> - <?= $condition['ends'] ?></td>
                                                <td class="record-actions">
                                                    <a data-load-with-modal data-modal="modal-edit-condition"  class="btn btn-xs btn-warning" href="<?= admin_url_to('/configs/reset/conditions/edit/' . $index) ?>"><?= __('Edit') ?></a>
                                                    <a data-ajax-delete class="btn btn-xs btn-danger" href="<?= admin_url_to('/configs/reset/conditions/delete/' . $index) ?>"><?= __('Delete') ?></a>
                                                </td>
                                            </tr>
                                        <?php endforeach ?>
                                    </tbody>
                                </table>
                            <?php endif ?>

                            <div style="text-align:right;margin-top:10px">
                                <a data-load-with-modal data-modal="modal-add-condition" class="btn btn-xs btn-success" href="<?= admin_url_to('/configs/reset/conditions/add') ?>"><?= __('Add') ?></a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-3" style="padding-left:15px">
                        <input type="submit" class="btn btn-primary" value="<?= __('Save') ?>" />
                    </div>
                </div>
            </div>
        </form>
    </div>
</section>