<script type="text/javascript">
    $(function () {
        $(document).on("click", ".add-department", function (e) {
            var $this = $(this);
            var $container = $this.closest("form").find(".container-add-department");

            $container.append('<input class="form-control" type="text" style="margin-top:5px;" name="department[]" />');
            e.preventDefault();
        });
    });
</script>

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

<section class="content">

    <div class="box box-default">
        <form data-ajax class="form-focus" action="<?= admin_url_to('/helpdesk/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-6">
                                    <div class="form-group">
                                        <label class="control-label" for="max-char-message"><?= __('Max characters') ?></label>
                                        <input class="form-control" type="text" value="<?= config('helpdesk.max_char_message') ?>" name="max_char_message" id="max-char-message" />
                                    </div>
                                </div>

                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label" for="timeout"><?= __('Timeout') ?></label>
                                        <input class="form-control" type="text" value="<?= config('helpdesk.timeout') ?>" name="timeout" id="timeout" />
                                    </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><?= __('Departments') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <div class="container-add-department">
                                    <?php foreach (config('helpdesk.departments', []) as $department): ?>
                                        <input class="form-control" type="text" style="margin-bottom:5px;" value="<?= $department ?>" name="department[]" />
                                    <?php endforeach ?>
                                    <input class="form-control" type="text" name="department[]" />
                                </div>

                                <div style="text-align:right;margin-top:10px">
                                    <a class="btn btn-success btn-xs add-department" href="javascript:void(0)"><?= __('Add') ?></a>
                                </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><?= __('Rules') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <textarea class="form-control" id="rules" style="height:200px" name="rules"><?= config('helpdesk.rules') ?></textarea>
                            </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>