<?php $__env->startSection('main-body'); ?>
<div class="container-fluid">
    <div class="page-header">
        <div class="row">
            <div class="col-sm-12">
                <h3>Profession Management</h3>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="/">Dashboard</a></li>
                    <li class="breadcrumb-item active"><a href="/professions">Professions</a></li>
                </ol>
                <?php if($loggedUser->can('create-professions')): ?>
                <span class="pull-right"><?php echo Html::decode(link_to_Route('professions.create', '<i class="fa fa-plus"></i> Create Profession', [], ['class' => 'btn btn-primary'])); ?></span>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-styling" id="profession-list">
                            <thead>
                                <tr>
                                    <th>Profession</th>
                                    <th>Parent</th>
                                    <th>Salutation</th>
                                    <th>Hexa Color</th>
                                    <th class="text-center">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $professions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $profession): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo $profession->name; ?></td>
                                    <td><?php echo $profession->parent_name; ?></td>
                                    <td><?php echo $profession->salutation; ?></td>
                                    <td><?php echo $profession->color_hex; ?></td>
                                    <td class="text-center">
                                        <div class="d-none d-md-block">
                                            <?php echo Form::open(array('route'=>array('professions.destroy',$profession->id),'class'=>'d-flex justify-content-around align-items-center','method'=>'DELETE','id'=>'profession-remove-form-'.$profession->id)); ?>

                                            <?php if($loggedUser->can('update-professions')): ?>
                                            <?php echo Html::decode(link_to_Route('professions.edit','<i class="fa fa-pencil"></i><span class="d-none d-md-inline"> Edit</span>', $profession->id, array('class' => 'm-auto text-dark', 'type' => 'button'))); ?>

                                            <?php endif; ?>
                                            <?php if($loggedUser->can('view-professions')): ?>
                                            <a href="#" class="m-auto text-dark" type="button" id="<?php echo e($profession->id); ?>" onclick="viewDetails(this)"><i class="fa fa-eye"></i><span class="d-md-inline"> View</span></a>
                                            <?php endif; ?>
                                            <?php if($loggedUser->can('delete-professions')): ?>
                                            <a href="#" class="m-auto text-dark" type="button" id="<?php echo e($profession->id); ?>" onclick="professionDelete(this)"><i class="fa fa-trash"></i><span class="d-md-inline"> Delete</span></a>
                                            <?php endif; ?>
                                            <?php echo Form::close(); ?>

                                        </div>
                                        <div class="btn-group d-md-none">
                                            <button class="btn bg-transparent text-dark dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false"></button>
                                            <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                            <?php echo Form::open(array('route'=>array('professions.destroy',$profession->id),'class'=>'d-flex justify-content-space-between align-items-center','method'=>'DELETE','id'=>'profession-remove-form-'.$profession->id)); ?>

                                            <?php if($loggedUser->can('update-professions')): ?>
                                            <?php echo Html::decode(link_to_Route('professions.edit','<i class="fa fa-pencil"></i>', $profession->id, array('class' => 'm-auto text-dark', 'type' => 'button'))); ?>

                                            <?php endif; ?>
                                            <?php if($loggedUser->can('view-professions')): ?>
                                            <a href="#" class="m-auto text-dark" type="button" id="<?php echo e($profession->id); ?>" onclick="viewDetails(this)"><i class="fa fa-eye"></i></a>
                                            <?php endif; ?>
                                            <?php if($loggedUser->can('delete-professions')): ?>
                                            <a href="#" class="m-auto text-dark" type="button" id="<?php echo e($profession->id); ?>" onclick="professionDelete(this)"><i class="fa fa-trash"></i></a>
                                            <?php endif; ?>
                                            <?php echo Form::close(); ?>

                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php if($loggedUser->can('view-professions')): ?>
<div class="modal fade" id="detailsModal" tabindex="-1" role="dialog" aria-labelledby="confirmation" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-md" role="document">
        <div class="modal-content">
            <div class="modal-body" style="padding-left: 50px; padding-top:50px;">
                <div class="row">
                    <h4>Profession Details</h4>
                </div>
                <div class="row p-t-30">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label>Profession Name: <span id="profession-name-d"></span></label>
                        </div>
                    </div>
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label>Salutation: <span id="salutation-d"></span></label>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label>Hexa Color: <span id="hexa-color-d"></span></label>
                        </div>
                    </div>
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label>Parent Profesion: <span id="parent-d"></span></label>
                        </div>
                    </div>
                </div>
                <div class="form-group m-t-30">
                    <span class="pull-right">
                        <?php if($loggedUser->can('update-professions')): ?>
                        <button type="button" class="btn btn-primary" id="detailsEditBtn" onclick="professionEdit(this)">Edit</button>
                        <?php endif; ?>
                        <?php if($loggedUser->can('delete-professions')): ?>
                        <button type="button" class="btn btn-danger" id="detailsDeleteBtn" onclick="professionDelete(this)">Delete</button>
                        <?php endif; ?>
                        <button type="button" class="btn btn-light" data-bs-dismiss="modal">Close</button>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>
<?php endif; ?>
<?php echo $__env->make('modals.confirmation', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>

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

function viewDetails(elem) {

    $.ajax({
        url: '/professions/'+elem.id+'/get-profession-details',
        method: 'GET',
        success: function(result){
            console.log(result);
            $('#profession-name-d').html(result.name);
            $('#salutation-d').html(result.salutation);
            $('#hexa-color-d').html(result.color_hex);
            $('#parent-d').html(result.parent_name);

            $('#detailsEditBtn').val(result.id);
            $('#detailsDeleteBtn').val(result.id);

            $('#detailsModal').modal('show');
        }
    });
}

function professionEdit(elem) {
    window.location.replace('/professions/'+elem.value+'/edit');
}

function professionDelete(elem) {

    let professionId = elem.value > 0 ? elem.value : elem.id;

    $('#confirmation-title').html("Delete");
    $('#confirmation-body').html("Are you sure you want to delete this profession? This process cannot be undone." );

    $('#submit-btn').html('Delete');
    $('#submit-btn').removeClass('btn-primary');
    $('#submit-btn').addClass('btn-danger');
    $('#submit-btn').val(professionId);

    $('#detailsModal').modal('hide');

    $('#confirmationModal').modal('show');
}

function submitForm(elem) {
    let = professionId = elem.value;
    console.log('PROF == ', professionId);
    $.ajax({
        url: '/professionals/'+professionId+'/get-by-profession',
        method: 'GET',
        success: function(result){
            console.log(result);
            if (result.length > 0) {
                $('#info-title').html("Unsuccessful");
                $('#info-body').html("Unable delete profession. This profession are used by one or more users");

                $('#confirmationModal').modal('hide');
                $('#infoModal').modal('show');
            } else {
                $('#profession-remove-form-'+professionId).submit();
            }
        }
    });
}

<?php echo $__env->make('notifications.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

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

<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/desxpert-admin/resources/views/professions/index.blade.php ENDPATH**/ ?>