<?php $__env->startSection('title', 'Jobs - Edit #' . $job->id); ?>

<?php $__env->startSection('content_header', 'Jobs <small>edit job</small>'); ?>

<?php $__env->startSection('content'); ?>
    <div class="row">
        <section class="col-lg-12">
            <div class="nav-tabs-custom">
                <?php echo $__env->make('admin.jobs._partials.tabs', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                <div class="tab-content">
                    <div class="tab-pane active">
                        <form class="form-horizontal" method="POST" action="<?php echo e(route('admin.jobs.update', $job->id)); ?>">
                            <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
                            <?php if(count($errors) > 0): ?>
                                <div class="alert alert-danger alert-dismissable">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                    <h4><i class="icon fa fa-ban"></i> <strong>Whoops!</strong> There were some problems with your input.</h4>
                                    <ul>
                                        <?php foreach($errors->all() as $error): ?>
                                            <li><?php echo e($error); ?></li>
                                        <?php endforeach; ?>
                                    </ul>
                                </div>
                            <?php endif; ?>
                            <div class="form-group <?php if($errors->has('user')): ?> has-error <?php endif; ?>">
                                <label for="selectUser" class="col-sm-2 control-label">User</label>
                                <div class="col-sm-10">
                                    <select name="user" id="selectUser" class="form-control">
                                        <option value="__none__">-- select --</option>
                                        <?php foreach($users as $user): ?>
                                            <option value="<?php echo e($user->id); ?>" <?php if(old('user', $job->user_id) == $user->id): ?> selected <?php endif; ?>><?php echo e($user->name); ?>, (<?php echo e($user->email); ?>)</option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group <?php if($errors->has('company')): ?> has-error <?php endif; ?>">
                                <label for="selectCompany" class="col-sm-2 control-label">Company</label>
                                <div class="col-sm-10">
                                    <select name="company" id="selectCompany" class="form-control">
                                        <option value="__none__">-- none --</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group <?php if($errors->has('title')): ?> has-error <?php endif; ?>">
                                <label for="inputTitle" class="col-sm-2 control-label">Title</label>
                                <div class="col-sm-10">
                                    <input name="title" type="text" class="form-control" id="inputTitle" value="<?php echo e(old('title', $job->title)); ?>">
                                </div>
                            </div>
                            <div class="form-group <?php if($errors->has('description')): ?> has-error <?php endif; ?>">
                                <label for="inputDescription" class="col-sm-2 control-label">Description</label>
                                <div class="col-sm-10">
                                    <textarea name="description" class="form-control" id="inputDescription" rows="7"><?php echo e(old('description', $job->description)); ?></textarea>
                                </div>
                            </div>
                            <div class="form-group <?php if($errors->has('instructions')): ?> has-error <?php endif; ?>">
                                <label for="inputInstructions" class="col-sm-2 control-label">Instructions</label>
                                <div class="col-sm-10">
                                    <textarea name="instructions" class="form-control" id="inputInstructions" rows="4"><?php echo e(old('instructions', $job->instructions)); ?></textarea>
                                </div>
                            </div>
                            <div class="form-group <?php if($errors->has('categories')): ?> has-error <?php endif; ?>">
                                <label class="col-sm-2 control-label">Categories</label>
                                <div class="col-sm-10">
                                    <?php foreach($categories as $category): ?>
                                        <div class="checkbox">
                                            <label>
                                                <input name="categories[]" type="checkbox" id="checkboxCategory<?php echo e($category->id); ?>" value="<?php echo e($category->id); ?>" <?php if(in_array($category->id, old('categories', $job->categories()->lists('jobs_categories.category_id', 'jobs_categories.category_id')))): ?> checked <?php endif; ?>> <?php echo e($category->title); ?>

                                            </label>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                            <div class="form-group <?php if($errors->has('type')): ?> has-error <?php endif; ?>">
                                <label class="col-sm-2 control-label">Job type</label>
                                <div class="col-sm-10">
                                    <?php foreach($types as $type): ?>
                                        <div class="radio">
                                            <label>
                                                <input type="radio" name="type" id="optionType<?php echo e($type->id); ?>" value="<?php echo e($type->id); ?>" <?php if(old('type', $job->type->id) == $type->id): ?> checked <?php endif; ?>>
                                                <?php echo e($type->title); ?>

                                            </label>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                            <div class="form-group <?php if($errors->has('remote')): ?> has-error <?php endif; ?>">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-10">
                                    <div class="checkbox">
                                        <label>
                                            <input name="remote" type="hidden" value="0">
                                            <input name="remote" type="checkbox" id="checkboxRemote" value="1" <?php if(old('remote', $job->remote) == '1'): ?> checked <?php endif; ?>>
                                            Remote - job position is worldwide.
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div id="locationInputs" <?php if((bool) old('remote', $job->remote) == true): ?> class="hidden" <?php endif; ?>>
                                <div class="form-group <?php if($errors->has('country')): ?> has-error <?php endif; ?>">
                                    <label for="inputCountry" class="col-sm-2 control-label">Country</label>
                                    <div class="col-sm-10">
                                        <input name="country" type="text" class="form-control" id="inputCountry" value="<?php echo e(old('country', $job->country)); ?>">
                                    </div>
                                </div>
                                <div class="form-group <?php if($errors->has('city')): ?> has-error <?php endif; ?>">
                                    <label for="inputCity" class="col-sm-2 control-label">City</label>
                                    <div class="col-sm-10">
                                        <input name="city" type="text" class="form-control" id="inputCity" value="<?php echo e(old('city', $job->city)); ?>">
                                    </div>
                                </div>
                            </div>
                            <hr>
                            <div class="form-group <?php if($errors->has('active')): ?> has-error <?php endif; ?>">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-10">
                                    <div class="checkbox">
                                        <label>
                                            <input name="active" type="hidden" value="0">
                                            <input name="active" type="checkbox" id="checkboxActive" value="1" <?php if(old('active', $job->active) == '1'): ?> checked <?php endif; ?>>
                                            Active
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div id="activeToInputBlock" <?php if((bool) old('active', $job->active) == false): ?> class="hidden" <?php endif; ?>>
                                <div class="form-group <?php if($errors->has('active_to')): ?> has-error <?php endif; ?>">
                                    <label for="inputCity" class="col-sm-2 control-label">Active to</label>
                                    <div class="col-sm-10">
                                        <input name="active_to" type="text" class="form-control datetimepicker" id="inputActiveTo" value="<?php echo e(old('active_to', $job->active_to)); ?>">
                                    </div>
                                </div>
                            </div>
                            <hr>
                            <div class="form-group <?php if($errors->has('featured')): ?> has-error <?php endif; ?>">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-10">
                                    <div class="checkbox">
                                        <label>
                                            <input name="featured" type="hidden" value="0">
                                            <input name="featured" type="checkbox" value="1" <?php if(old('featured', $job->featured) == '1'): ?> checked <?php endif; ?>>
                                            Featured
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <hr>
                            <div class="clearfix">
                                <div class="pull-right">
                                    <button type="submit" class="btn btn-success">Save</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </section>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom_scripts'); ?>
    <script type="text/javascript">

        function loadCompanies(user_id, active)
        {
            $.ajax({
                url: base_url + "/api/user-companies/" + user_id,
                method: "GET",
                dataType: "json"
            }).done(function (data) {
                var company_selector = $("#selectCompany");

                var options = [];

                if (active == '__none__') {
                    options.push('<option value="__none__" selected>-- none --</option>')
                } else {
                    options.push('<option value="__none__">-- none --</option>')
                }

                $.each(data, function (k, v) {
                    if (active == v.id) {
                        options.push('<option value="' + v.id + '" selected>' + v.name + '</option>');
                    } else {
                        options.push('<option value="' + v.id + '">' + v.name + '</option>');
                    }
                });

                company_selector.html(options.join(""));
            });
        }

        $(document).ready(function () {
            if ('<?php echo e(old('user', $job->user_id)); ?>' != '__none__') {
                loadCompanies($("#selectUser").val(), '<?php echo e(old('company', $job->company_id ? $job->company_id : '__none__')); ?>');
            }

            $("#selectUser").on("change", function () {
                loadCompanies($(this).val(), '__none__');
            });

            $("#checkboxRemote").on("change", function () {
                if ($(this).is(":checked")) {
                    $("#locationInputs").addClass("hidden");
                } else {

                    $("#locationInputs").removeClass("hidden");
                }
            });

            $("#checkboxActive").on("change", function () {
                if ($(this).is(":checked")) {
                    $("#activeToInputBlock").removeClass("hidden");
                } else {

                    $("#activeToInputBlock").addClass("hidden");
                }
            });
        });

    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>