

<?php $__env->startSection('title','Jobs'); ?>

<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">Latest Jobs Posted</div>
            <div class="panel-body">
                <?php if(count($jobs)>0): ?>
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Title</th>
                            <th>Country</th>
                            <th>Company</th>
                            <th>Category</th>
                            <th>Salary</th>
                            <th>Description</th>
                            <th>Expires In</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $jobs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $job): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($job->title); ?></td>
                            <td><?php echo e($job->company->country->name); ?></td>
                            <td><?php echo e($job->company->name); ?></td>
                            <td><?php echo e($job->jobCategory->name); ?></td>
                            <td><?php echo e($job->salary); ?></td>
                            <td><?php echo $job->description; ?></td>
                            <td><?php echo e($job->expiryStatus()); ?></td>
                            <td class="text-center"><p> <a id="editBtn" data-id="<?php echo e($job->id); ?>" data-jobtitle="<?php echo e($job->title); ?>" data-jobcompanyid="<?php echo e($job->company->id); ?>" data-numberofvacancy="<?php echo e($job->vacancy); ?>" data-jobsalary="<?php echo e($job->salary); ?>" data-jobcategoryid="<?php echo e($job->job_category_id); ?>" data-jobdescription="<?php echo e(str_replace('<br />','',$job->description)); ?>" data-jobexpirydate="<?php echo e($job->expires_at->toFormattedDateString()); ?>" href="#" class="btn btn-warning" data-toggle="modal" data-target="#editModal">Edit</a> </p> <p> <a id="deleteJob" data-id="<?php echo e($job->id); ?>" href="#" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Delete</a> </p></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>                                        
                </table>
                <?php echo e($jobs->links()); ?>

                <?php else: ?>
                No jobs found.
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<div id="editModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Edit Job</h4>
            </div>
            <div class="modal-body">
                <?php echo $__env->make('errors.form', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                <form id="editForm" method="POST" action="<?php echo e(url('/admin/job')); ?>">
                    <?php echo e(csrf_field()); ?>

                    <input type="hidden" name="_method" value="PATCH">
                    <input type="hidden" name="job_id" id="current_job_id">
                    <div class="form-group">
                        <label>Job Title</label>
                        <input type="text" id="current_job_title" name="job_title" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>Company</label>
                        <select id="current_job_company" name="company" class="form-control">
                            <?php $__currentLoopData = $companies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $company): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($company->id); ?>"><?php echo e($company->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Number of vacancy</label>
                                <input id="current_vacancy" type="number" name="vacancy" class="form-control" min="1" value="10">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Salary</label>
                                <input id="current_salary" type="text" name="salary" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Job Category</label>
                                <select id="current_job_category" name="category" class="form-control">
                                    <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Final Date</label>
                                <input type="date" name="expires_at" class="form-control" min="<?php echo e(date('Y-m-d')); ?>" value="<?php echo e(date('Y-m-d')); ?>" required>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Job Description</label>
                        <textarea id="current_job_description" rows="10" class="form-control" name="description"></textarea>
                    </div>
                    <input type="submit" name="submit" value="Edit Job" class="btn btn-block btn-lg btn-success">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div id="deleteModal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Delete Job</h4>
            </div>
            <div class="modal-body">
                <p>Are you sure you want to delete this job?</p>
                <form id="deleteJobForm" method="POST" action="<?php echo e(url('/admin/job')); ?>">
                    <?php echo e(csrf_field()); ?>

                    <input id="job_id" type="hidden" name="job_id" value="">
                    <input type="hidden" name="_method" value="DELETE">
                    <input type="submit" name="submit" value="Yes" class="btn btn-success">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">No</button>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('footer'); ?>

<script type="text/javascript">
  $(document).on('click','#deleteJob',function(){
    var job = $(this).data('id');
    $("#deleteJobForm #job_id").val(job);
});

  $(document).on('click','#editBtn',function(){
    var jobId = $(this).data('id');
    var jobCompanyId = $(this).data('jobcompanyid');
    var jobTitle = $(this).data('jobtitle');
    var jobSalary = $(this).data('jobsalary');
    var numberOfVacancy = $(this).data('numberofvacancy');
    var jobDescription = $(this).data('jobdescription');
    var jobCategoryId = $(this).data('jobcategoryid');
    $("#editForm #current_job_id").val(jobId);
    $("#editForm #current_job_title").val(jobTitle);
    $("#editForm #current_salary").val(jobSalary);
    $("#editForm #current_vacancy").val(numberOfVacancy);
    $('#editForm #current_job_description').html(jobDescription);
    $('#editForm #current_job_category').val(jobCategoryId);
    $('#editForm #current_job_company').val(jobCompanyId);
});
</script>

<?php $__env->stopSection(); ?>

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