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

    <div class="actions">
        <a data-ajax class="btn btn-default btn-sm" href="<?= admin_url_to('/accounts') ?>"><?= __('List') ?></a>
        <a class="btn btn-default btn-sm" href="<?= admin_url_to('/accounts/logs/' . $account['username']) ?>" data-load-with-modal data-modal="modal-logs"><?= __('Logs') ?></a>
        <a class="btn btn-default btn-sm" href="<?= admin_url_to('/accounts/warehouse/' . $account['username']) ?>" data-load-with-modal data-modal="modal-warehouse"><?= __('Warehouse') ?></a>
        <?php if ($account['blocked']): ?>
            <a data-ajax-action data-confirm="<?= __('Are you sure you want to unban this account?') ?>" class="btn btn-default btn-sm" href="<?= admin_url_to('/accounts/unban/' . $account['username']) ?>"><?= __('Remove ban') ?></a>
        <?php else: ?>
            <a data-load-with-modal data-modal="modal-ban" class="btn btn-danger btn-sm" href="<?= admin_url_to('/accounts/ban/' . $account['username']) ?>"><?= __('Ban') ?></a>
        <?php endif ?>
    </div>
</section>


<div id="modal-warehouse" data-width="<?= config('warehouse.extended') ? 517 : 258 ?>" class="modal"></div>
<div id="modal-ban" data-width="400" class="modal"></div>
<div id="modal-logs" data-width="800" class="modal"></div>

<section class="content">
    <div class="box box-default">
        <form data-ajax class="form-focus" method="post" action="<?= admin_url_to('/accounts/edit/' . $account['username']) ?>">
            <?= 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><?= __('Account') ?></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="name"><?= __('Name') ?> <span class="required">*</span></label>
                                <input class="form-control" type="text" value="<?= $account['name'] ?>" name="name" id="name" />
                            </div>

                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label"><?= __('Username') ?></label>
                                        <p class="form-control-static"><?= $account['username'] ?></p>
                                    </div>
                                </div>

                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label" for="password"><?= __('Password') ?></label>
                                        <input class="form-control" type="password" value="" id="password" name="password" />
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-5">
                                    <div class="form-group">
                                        <label class="control-label" for="email"><?= __('E-mail') ?></label>
                                        <input class="form-control" type="text" value="<?= $account['email'] ?>" id="email" name="email" />
                                    </div>
                                </div>

                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="control-label" for="confirm-email"><?= __('Confirmed e-mail') ?></label>
                                        <div>
                                            <input class="form-control toggle" type="checkbox" id="confirm-email"<?= $account['confirmedEmail'] ? ' checked="checked"' : '' ?> value="1" name="confirmed_email" />
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="pid"><?= __('Personal ID') ?></label>
                                        <input class="form-control" type="text" id="pid" value="<?= $account['personalId'] ?>" name="pid" />
                                    </div>
                                </div>
                            </div>

                            <?php if (count(config('register.secret_questions', []))): ?>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label" for="secret-question"><?= __('Secret question') ?></label>
                                            <input class="form-control" type="text" value="<?= $account['secretQuestion'] ?>" name="secret_question" id="secret-question" />
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label" for="secret-answer"><?= __('Secret answer') ?></label>
                                            <input class="form-control" type="text" id="secret-answer" value="<?= $account['secretAnswer'] ?>" name="secret_answer" />
                                        </div>
                                    </div>
                                </div>
                            <?php endif ?>

                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="credit"><?= __('Credits') ?></label>
                                        <input class="form-control money" type="text" value="<?= util('Number')->format($account['credit'], 2, ',') ?>" id="credit" name="credit" />
                                    </div>
                                </div>

                                <?php if (config('register.countries_flag_column', null)): ?>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label class="control-label" for="country"><?= __('Country') ?></label>
                                            <select class="form-control" id="country" name="country">
                                                <option value=""></option>
                                                <?php foreach (countries() as $id => $country): ?>
                                                    <option<?= $account['country'] === $id ? ' selected' : '' ?> value="<?= $id ?>"><?= $country ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                <?php endif ?>
                            </div>

                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label"><?= __('Created at') ?></label>
                                        <p class="form-control-static"><?= util('Date')->dateTime($account['createdAt']) ?></p>
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label"><?= __('Status') ?></label>
                                        <p class="form-control-static">
                                            <?php if ($account['blocked']): ?>
                                                <span class="label label-danger" style="font-size:12px;vertical-align:3px;"><?= strtoupper(__('Blocked')) ?></span>
                                            <?php else: ?>
                                                <?= __('Normal') ?>
                                            <?php endif ?>
                                        </p>
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label"><?= __('Online') ?></label>
                                        <p class="form-control-static">
                                            <?= util('Character')->status($account['connected']) ?>
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <?php if (config('vip.table')): ?>
                    <div class="section">
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                <h5><?= __('Vip') ?></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="vip-type"><?= __('Vip') ?></label>
                                            <select class="form-control" id="vip-type" name="vip_type">
                                                <option value=""></option>
                                                <?php foreach (config('vip.types', []) as $code => $name): ?>
                                                    <option value="<?= $code ?>"<?= $code == $account['vipType'] ? ' selected="selected"' : '' ?>><?= $name ?></option>
                                                <?php endforeach ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label" for="vip-expire"><?= __('Maturity') ?></label>
                                            <input class="form-control" type="text" data-show-calendar id="vip-expire" value="<?= util('Date')->date($account['vipExpire']) ?>" name="vip_expire" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endif ?>

                <?php if (count(config('coins', []))): ?>
                    <div class="section">
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                <h5><?= __('Coins') ?></h5>
                            </div>

                            <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                <div class="row">
                                    <?php foreach (config('coins', []) as $coin): ?>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label class="control-label" for="coin-<?= $coin['id'] ?>"><?= $coin['name'] ?></label>
                                                <input class="form-control" type="text" id="coin-<?= $coin['id'] ?>" value="<?= $account['coins'][$coin['id']] ?>" name="coin_<?= $coin['id'] ?>" />
                                            </div>
                                        </div>
                                    <?php endforeach ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endif ?>

                <?php if (!empty($account['bans'])): ?>
                    <div class="section">
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                <h5><?= __('Blocking history') ?></h5>
                            </div>

                            <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                <table class="table table-condensed table-hover table-striped">
                                    <thead>
                                    <tr>
                                        <th width="240"><?= __('Period') ?></th>
                                        <th><?= __('Cause') ?></th>
                                        <th><?= __('Notes') ?></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach ($account['bans'] as $ban): ?>
                                        <tr>
                                            <td><?= util('Date')->dateTime($ban['block_date']) ?> - <?= util('Date')->dateTime($ban['unblock_date']) ?></td>
                                            <td><?= nl2br($ban['cause']) ?></td>
                                            <td><?= nl2br($ban['notes']) ?></td>
                                        </tr>
                                    <?php endforeach ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                <?php endif ?>

                <?php notify('admin.accounts.edit.render', $account) ?>
            </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>