<?php $__env->startSection('title',' Schedules'); ?>
<?php $__env->startSection('content'); ?>
<h2 class="ms-2 mb-3 card-title"><?php echo e(__('messages.schedules') ." ". __('messages.list')); ?></h2>

    <div class="card  mt-3 m-lg-2">
        <div class="card-body table_card  mt-2">
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('schedule.create')): ?>
                <div class="add-new-button-hidden">
                    <button class="btn add_new_btn" data-bs-toggle="modal" data-bs-target="#schedule_add_modal"
                            ><i class="plus-ico"></i> <?php echo e(__('messages.add') ." ". __('messages.schedules')); ?>

                    </button>
                </div>
            <?php endif; ?>
            <table id="myTable" class="table table-bordered dt-responsive nowrap w-100">
                <thead>
                <tr>
                    <th><?php echo e(__('messages.sl')); ?></th>
                    <th><?php echo e(__('messages.duty_shift')); ?></th>
                    <th><?php echo e(__('messages.in_time')); ?></th>
                    <th><?php echo e(__('messages.description')); ?></th>
                    <th><?php echo e(__('messages.added_on')); ?></th>
                    <th><?php echo e(__('messages.status')); ?></th>
                    <th style="width:25% !important"><?php echo e(__('messages.action')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__currentLoopData = $schedules; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e(++$key); ?></td>
                        <td><?php echo e($item->duty_shift); ?></td>
                        <td><?php echo e($item->duty_start_time); ?></td>
                        <td><?php echo e($item->schedule_remark); ?></td>
                        <td><?php echo e($item->added_on); ?></td>
                        <td><?php echo e(($item->schedule_status > 1) ? 'Approved' : 'Draft'); ?></td>
                        <td class="center">
                            <?php if($item->schedule_status <= 1): ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('schedule.edit')): ?>
                                    <a id="edit_btn" edit-id="<?php echo e($item->sas_id); ?>" class="btn btn-sm btn-success" data-bs-toggle="modal"
                                    data-bs-target="#schedule_add_modal"><i class="edit-ico"></i> Edit</a>
                                <?php endif; ?>

                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('schedule.approve')): ?>
                                    <a id="approve_btn" onclick="approvePost(<?php echo e($item->sas_id); ?>)" class="btn btn-sm btn-warning">
                                        <i class="ok-ico"></i> Approve

                                        <form id="approve-form-<?php echo e($item->sas_id); ?>"
                                            action="<?php echo e(route('schedules.approve', $item->sas_id)); ?>" method="POST" style="display: none;">
                                            <?php echo csrf_field(); ?>
                                        </form>
                                    </a>
                                <?php endif; ?>

                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('schedule.delete')): ?>
                                    <a href="#" class="btn btn-sm btn-danger" onclick="deletePost(<?php echo e($item->sas_id); ?>)">
                                        <img src="<?php echo e(asset('assets/icons/svg/delete.svg')); ?>" alt="" /> Remove
                                        <form id="delete-form-<?php echo e($item->sas_id); ?>"
                                            action="<?php echo e(route('schedules.destroy', $item->sas_id)); ?>" method="POST"
                                            style="display: none;">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                        </form>
                                    </a>
                                <?php endif; ?>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>
    </div>

    
    <div class="modal fade" id="schedule_add_modal" tabindex="-1" aria-labelledby="exampleModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <h4 class="card-title"><?php echo e(__('messages.schedules') ." ". __('messages.information')); ?></h4>
                <div class="modal-body p-0 mt-3">
                    <form action="<?php echo e(route('schedules.store')); ?>" method="POST" role="form" id="form1"
                          enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <div class="row">
                            <div class="col-md-6">
                                <input type="hidden" name="sas_id" id="sas_id">
                                <div class="form-group">
                                    <label class="form-label" for="duty_shift">
                                        <?php echo e(__('messages.duty_shift')); ?>

                                        <span class="text-danger">*</span></label>
                                    

                                        <select id="duty_shift" name="duty_shift" class="form-control" style="width:100%;height:auto">
                                            <option value="">-Select-</option>
                                            <option value="Morning">Morning</option>
                                            <option value="Day">Day</option>
                                            <option value="Both">Both-Morning & Day</option>
                                            <option value="Night">Night</option>
                                            <option value="FullTime">FullTime</option>
                                        </select>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="duty_start_time"><?php echo e(__('messages.in_time')); ?><span class="text-danger">*</span></label>
                                    <input type="time" step="0.01" class="form-control <?php $__errorArgs = ['duty_start_time'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           name="duty_start_time" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.in_time')); ?>" required id="duty_start_time"/>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="schedule_remark"><?php echo e(__('messages.comments')); ?></label>
                                    <textarea type="text" class="form-control" name="schedule_remark" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.comments')); ?>"
                                        id="schedule_remark"/></textarea>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="added_on"><?php echo e(__('messages.added_on')); ?> <span
                                            class="text-danger"></span></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['added_on'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           name="added_on" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.added_on')); ?>" id="added_on" value="<?php echo date('Y-m-d H:i:s')?>" readonly required/>
                                </div>
                            </div>
                        </div>
                        <div class="mt-5 d-flex justify-content-end ">
                            <button type="button" class="btn btn-sm btn-danger  me-2" data-bs-dismiss="modal"
                                    style=""><?php echo e(__('messages.close')); ?>

                            </button>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('schedule.create')): ?>
                                <button type="submit" class="btn btn-sm btn-primary" >
                                    <?php echo e(__('messages.save')); ?>

                                </button>
                            <?php endif; ?>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    
<?php $__env->stopSection(); ?>
<?php $__env->startPush('scripts'); ?>
    <script type="text/javascript">


        function approvePost(id) {
            swal({
                title: 'Are you sure?',
                text: "You won't be able to revert this!",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Yes, approve it!',
                cancelButtonText: 'No, cancel!',
                confirmButtonClass: 'btn btn-warning ms-2',
                cancelButtonClass: 'btn btn-success',
                buttonsStyling: false,
                reverseButtons: true
            }).then((result) => {
                if (result.value) {
                    event.preventDefault();
                    document.getElementById('approve-form-' + id).submit();
                }
            })
        }
        $(document).ready(function ($) {
            $(document).on('click', '#edit_btn', function () {
                let id = $(this).attr('edit-id');
                $.ajax({
                    type: "GET",
                    url: "<?php echo e(url('system/schedules')); ?>/" + id + "/edit",
                    success: function (res) {
                        $('#duty_start_time').val(res.duty_start_time);
                        $('#duty_shift').val(res.duty_shift);
                        $('#schedule_remark').val(res.schedule_remark);
                        $('#schedule_start').val(res.schedule_start);
                        $('#sas_id').val(res.sas_id);
                    },
                    error: function (response) {
                        console.log(response);
                    }
                });
            });


            $('.add_new_btn').click(function () {
                // axios.get("<?php echo e(url('system/roles/create')); ?>").then(function (response) {
                //     $('.roleCreateModal').html(response.data);
                //     $('.modal-spinner').hide();
                //     $(".modal").on("hidden.bs.modal", function () {
                //         $(".roleCreateModal").html(` <div class="modal-spinner d-flex flex-column align-items-center">
                //             <div class="spinner-border text-secondary" role="status">
                //                 <span class="sr-only"></span>
                //             </div>
                //             <h5 class="mt-1">Loading...</h5>
                //         </div>`);
                //     });
                //     createPageJS();
                // }).catch(function (error) {
                //     console.log(error)
                // })
                document.getElementById("form1").reset();
            })
        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/ussitbd/public_html/hr.ussitbd.com/resources/views/backend/hr/attend/schedule.blade.php ENDPATH**/ ?>