<section class="content-header">
    <h1><?= __('Setting new records') ?></h1>
</section>

<div class="modal" id="modal-add-custom-field" data-width="350"></div>

<section class="content">

    <div class="box box-default">
        <form data-ajax class="form-focus" action="<?= admin_url_to('/configs/register') ?>" 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="form-group">
                                <label class="control-label" for="config-news-limit"><?= __('Secret questions') ?></label>

                                <div class="field container-add-secret-question">
                                    <?php if (isset($register['secret_questions'])): ?>
                                        <?php foreach ($register['secret_questions'] as $question): ?>
                                            <input class="form-control" type="text" style="margin-bottom:5px;" value="<?= $question ?>" name="secret_questions[]" />
                                        <?php endforeach ?>
                                    <?php endif ?>
                                    <input class="form-control" type="text" name="secret_questions[]" />
                                </div>

                                <div style="text-align:right;margin-top:10px">
                                    <a class="btn btn-xs btn-success add-secret-question" href="javascript:void(0)"><?= __('Add') ?></a>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="confirm_email"><?= __('Email confirmation') ?></label>
                                        <div>
                                            <input class="form-control toggle" type="checkbox" id="confirm_email"<?= isset($register['confirm_email']) && $register['confirm_email'] ? 'checked="checked"' : '' ?> value="1" name="confirm_email" />
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="blocked"><?= __('Create blocked') ?></label>
                                        <div>
                                            <input class="form-control toggle" type="checkbox" id="blocked"<?= isset($register['create_blocked']) && $register['create_blocked'] ? 'checked="checked"' : '' ?> value="1" name="create_blocked" />
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="countries-flag-column"><?= __('Countries flag column') ?></label>
                                        <select class="form-control" name="countries_flag_column" id="countries-flag-column">
                                            <option value=""></option>
                                            <?php foreach (sql_table_columns('MEMB_INFO', config('conn.default.me', config('conn.default.dbname'))) as $column): ?>
                                                <option<?= config('register.countries_flag_column') === $column['COLUMN_NAME'] ? ' selected' : '' ?> value="<?= $column['COLUMN_NAME'] ?>"><?= $column['COLUMN_NAME'] ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="multiple_email"><?= __('Multiple e-mails') ?></label>
                                        <div>
                                            <input class="form-control toggle" type="checkbox" id="multiple_email"<?= isset($register['multiple_email']) && $register['multiple_email'] ? 'checked="checked"' : '' ?> value="1" name="multiple_email" />
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="username_only_lower"><?= __('Username only lowercase') ?></label>
                                        <div>
                                            <input class="form-control toggle" type="checkbox" id="username_only_lower"<?= isset($register['username_only_lower']) && $register['username_only_lower'] ? 'checked="checked"' : '' ?> value="1" name="username_only_lower" />
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="terms"><?= __('Terms') ?></label>
                                <textarea class="form-control" id="terms" name="terms" style="height:250px"><?= config('register.terms') ?></textarea>
                            </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><?= __('Custom fields') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <?php if (empty($register['custom_fields'])): ?>
                                <div class="callout callout-warning">
                                    <p><?= __('No custom field found') ?></p>
                                </div>
                            <?php else: ?>
                                <table class="table table-condensed table-hover table-striped">
                                    <thead>
                                        <tr>
                                            <th><?= __('Name') ?></th>
                                            <th><?= __('Label') ?></th>
                                            <th><?= __('Required') ?></th>
                                            <th><?= __('Type') ?></th>
                                            <th width="10"></th>
                                        </tr>
                                    </thead>

                                    <tbody>
                                        <?php foreach ($register['custom_fields'] as $field): ?>
                                            <tr>
                                                <td><?= $field['name'] ?></td>
                                                <td><?= $field['label'] ?></td>
                                                <td><?= $field['required'] == 1 ? __('Yes') : __('No') ?></td>
                                                <td><?= $field['type'] ?></td>
                                                <td class="record-actions">
                                                    <a data-ajax-delete class="btn btn-xs btn-danger" href="<?= admin_url_to('/configs/register/delete_custom_field/' . $field['name']) ?>"><?= __('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-custom-field" class="btn btn-xs btn-success" href="<?= admin_url_to('/configs/register/add_custom_field') ?>"><?= __('Add') ?></a>
                            </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><?= __('Vip bonus') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label" for="bonus-vip-type"><?= __('Vip') ?></label>
                                        <select class="form-control" id="bonus-vip-type" name="bonus_vip_type">
                                            <option value=""></option>
                                            <?php foreach (config('vip.types', []) as $key => $value): ?>
                                                <option value="<?= $key ?>"<?= $key == config('register.bonus.vip.type') ? ' selected="selected"' : '' ?>><?= $value ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label" for="bonus-vip-days"><?= __('Days') ?></label>
                                        <input class="form-control" type="text" id="bonus-vip-days" name="bonus_vip_days" value="<?= config('register.bonus.vip.days') ?>" />
                                    </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><?= __('Coin bonus') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label" for="bonus-coin"><?= __('Coin') ?></label>
                                        <select class="form-control" id="bonus-coin" name="bonus_vip_coin">
                                            <option value=""></option>
                                            <?php foreach (config('coins', []) as $key => $coin): ?>
                                                <option value="<?= $coin['id'] ?>"<?= $coin['id'] == config('register.bonus.coin.type') ? ' selected="selected"' : '' ?>><?= $coin['name'] ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label" for="bonus-coin-amount"><?= __('Amount') ?></label>
                                        <input class="form-control" type="text" id="bonus-coin-amount" name="bonus_vip_coin_amount" value="<?= config('register.bonus.coin.amount') ?>" />
                                    </div>
                                </div>
                            </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>