

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

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

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

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">List of Companies</div>
            <div class="panel-body">
                <?php if(count($companies)>0): ?>
                <table class="table table-striped table-responsive">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Country</th>
                            <th>Website</th>
                            <th>Image</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $companies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $company): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($company->name); ?></td>
                            <td><?php echo e($company->country->name); ?></td>
                            <td><a target="_blank" href="<?php echo e($company->url); ?>"><?php echo e($company->url); ?></a></td>
                            <td><img src="<?php echo e(asset('images/'.$company->image)); ?>" class="img-responsive img-thumbnail" alt="<?php echo e($company->name); ?>"></td>
                            <td class="text-center"> <p> <a id="editBtn" data-id="<?php echo e($company->id); ?>" data-countryid="<?php echo e($company->country->id); ?>" data-companyname="<?php echo e($company->name); ?>" data-companyurl="<?php echo e($company->url); ?>" data-companyimage="<?php echo e(asset('images/'.$company->image)); ?>" href="#" class="btn btn-warning" data-toggle="modal" data-target="#editModal">Edit</a> </p> <p> <a id="deleteCompany" data-id="<?php echo e($company->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($companies->links()); ?>

                <?php else: ?>
                No companies 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 company</h4>
            </div>
            <div class="modal-body">
                <?php echo $__env->make('errors.form', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                <form id="editForm" enctype="multipart/form-data" method="POST" action="<?php echo e(url('/admin/company')); ?>">
                    <?php echo e(csrf_field()); ?>

                    <input type="hidden" name="_method" value="PATCH">
                    <input type="hidden" id="company_id" name="company_id" value="0">
                    <div class="form-group">
                        <label>Company Name</label>
                        <input type="text" id="current_company_name" name="name" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Company Website</label>
                        <input id="current_company_website" type="url" name="website" class="form-control" value="http://" placeholder="URL must begin with http:// or https://">
                    </div>
                    <div class="form-group">
                        <label>Country</label>
                        <select id="country" name="country" class="form-control">
                            <?php $__currentLoopData = $countries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $country): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($country->id); ?>"><?php echo e($country->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>Current Company Logo</label>
                        <img id="current_company_logo" class="img-responsive" alt="No Image Found">
                    </div>
                    <div class="form-group">
                        <label>New Company Logo</label>
                        <input type="file" name="image" class="btn btn-info">
                        <span class="help-block">(Do not upload new image if you do not require to change the old image.)</span>
                    </div>
                    <input type="submit" name="submit" value="Edit Company" class="btn 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 company</h4>
            </div>
            <div class="modal-body">
                <p>Are you sure you want to delete this company?</p>
                <form id="deleteCompanyForm" method="POST" action="<?php echo e(url('/admin/company')); ?>">
                    <?php echo e(csrf_field()); ?>

                    <input id="company_id" type="hidden" name="company_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','#deleteCompany',function(){
    var file = $(this).data('id');
    $("#deleteCompanyForm #company_id").val(file);
});

  $(document).on('click','#editBtn',function(){
    var companyId = $(this).data('id');
    var companyName = $(this).data('companyname');
    var companyUrl = $(this).data('companyurl');
    var companyImage = $(this).data('companyimage');
    var companyCountryId = $(this).data('countryid');
    $("#editForm #company_id").val(companyId);
    $("#editForm #current_company_name").val(companyName);
    $("#editForm #current_company_website").val(companyUrl);
    $("#editForm #current_company_logo").attr('src',companyImage);
    $("#editForm #country").val(companyCountryId);
});
</script>

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


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