<script type="text/javascript">
    $(function () {
        $("#packages-table").find("tbody").sortable({
            opacity: 0.6,
            cursor: "move",
            placeholder: "placeholder",
            helper: fixHelper,
            axis: "y",
            update: function() {
                var order = $(this).sortable("serialize");
                $.post(prefix + "profile/block-packages/reorder", order, function(data) {
                });
            }
        });
    });
</script>

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

<div class="modal" id="modal-add-package"></div>
<div class="modal" id="modal-edit-package"></div>

<section class="content">

    <div class="box box-default">
        <form data-ajax class="form-focus" action="<?= admin_url_to('/profile/config') ?>" 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="control-label" for="show-equipments"><?= __('Show equipments') ?></label>
                                        <div>
                                            <input class="form-control toggle" type="checkbox"<?= config('profile.show_equipments') ? ' checked' : '' ?> id="show-equipments" value="1" name="show_equipments" />
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="column-hours"><?= __('Column hours') ?></label>
                                        <input class="form-control" type="text" id="column-hours" value="<?= config('profile.column_hours') ?>" name="column_hours" />
                                    </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><?= __('Block packages') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <?php if (empty($packages)): ?>
                                <div class="callout callout-warning">
                                    <h4>Ops!</h4>
                                    <p><?= __('No packages found') ?></p>
                                </div>
                            <?php else: ?>
                                <div class="table-responsive">
                                    <table id="packages-table" class="table table-condensed table-hover table-striped">
                                        <thead>
                                            <tr>
                                                <th><?= __('Package') ?></th>
                                                <th width="150"><?= __('Block hours') ?></th>
                                                <th width="10"></th>
                                            </tr>
                                        </thead>

                                        <tbody>
                                            <?php foreach ($packages as $package): ?>
                                                <tr id="sequence_<?= $package['id'] ?>" class="<?= $package['active'] ? 'border-success' : 'border-error' ?>">
                                                    <td>
                                                        <i class="fa fa-bars"></i> <?= $package['package'] ?>
                                                    </td>
                                                    <td><?= $package['hours'] ?></td>
                                                    <td class="record-actions">
                                                        <a data-load-with-modal data-modal="modal-edit-package" class="btn btn-default btn-xs" href="<?= admin_url_to('/profile/block-packages/edit/' . $package['id']) ?>"><?= __('Edit') ?></a>
                                                        <a data-ajax-delete class="btn btn-danger btn-xs"href="<?= admin_url_to('/profile/block-packages/delete/' . $package['id']) ?>"><?= __('Delete') ?></a>
                                                    </td>
                                                </tr>
                                            <?php endforeach ?>
                                        </tbody>
                                    </table>
                                </div>
                            <?php endif ?>

                            <div style="text-align:right;margin-top:10px">
                                <a data-load-with-modal data-modal="modal-add-package" class="btn btn-xs btn-success" href="<?= admin_url_to('/profile/block-packages/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>