<?php $__env->startSection('title',' Holidays'); ?>
<?php $__env->startSection('content'); ?>
<h2 class="ms-2 mb-3 card-title"><?php echo e(__('messages.holiday') ." ". __('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('holiday.create')): ?>
                <div class="add-new-button-hidden">
                    <button class="btn add_new_btn" data-bs-toggle="modal" data-bs-target="#holiday_add_modal"
                            ><i class="plus-ico"></i> <?php echo e(__('messages.add') ." ". __('messages.holiday')); ?>

                    </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.holiday')); ?> <?php echo e(__('messages.date_start')); ?></th>
                    <th><?php echo e(__('messages.holiday')); ?> <?php echo e(__('messages.date_end')); ?></th>
                    <th><?php echo e(__('messages.holiday')); ?></th>
                    <th><?php echo e(__('messages.description')); ?>-(<?php echo e(__('messages.holiday')); ?>)</th>
                    <th><?php echo e(__('messages.status')); ?></th>
                    <th style="width:25% !important"><?php echo e(__('messages.action')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__currentLoopData = $holidays; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e(++$key); ?></td>
                        <td><?php echo e(date('d-M-Y', strtotime($item->adate))); ?></td>
                        <td><?php echo e(date('d-M-Y', strtotime($item->adate2))); ?></td>
                        <td style="width:100px !important">
                            <div>
                                <?php echo e($item->holidayss); ?>

                            </div>
                        </td>
                        <td><?php echo e($item->atext); ?></td>
                        <td><?php echo e(($item->approval_status > 1) ? 'Approved' : 'Draft'); ?></td>
                        <td class="center">
                            <?php if($item->approval_status < 2): ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('holiday.edit')): ?>
                                    <a id="edit_btn" edit-id="<?php echo e($item->hd_id); ?>" class="btn btn-sm btn-success" data-bs-toggle="modal"
                                    data-bs-target="#holiday_add_modal"><i class="edit-ico"></i> Edit</a>
                                <?php endif; ?>

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

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

                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('holiday.delete')): ?>
                                    <a href="#" class="btn btn-sm btn-danger" onclick="deletePost(<?php echo e($item->hd_id); ?>)">
                                        <img src="<?php echo e(asset('assets/icons/svg/delete.svg')); ?>" alt="" /> Remove
                                        <form id="delete-form-<?php echo e($item->hd_id); ?>"
                                            action="<?php echo e(route('holidays.destroy', $item->hd_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="holiday_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.holiday') ." ". __('messages.information')); ?></h4>
                <div class="modal-body p-0 mt-3">
                    <form action="<?php echo e(route('holidays.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="hd_id" id="hd_id">
                                <div class="form-group">
                                    <label class="form-label" for="session_id">Session<span class="text-danger">*</span></label>
                                    <select class="form-control <?php $__errorArgs = ['session_id'];
$__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="session_id" id="session_id" required>
                                        <option value="">Select Session</option>
                                        <?php $__currentLoopData = $session_data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($item->session_id); ?>"><?php echo e($item->session_name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="adate"><?php echo e(__('messages.holiday')); ?> <?php echo e(__('messages.date_start')); ?><span class="text-danger">*</span></label>
                                    <input type="date" class="form-control" name="adate" placeholder="<?php echo e(__('messages.enter')); ?>" id="adate"/>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="atext"><?php echo e(__('messages.holiday')); ?> <?php echo e(__('messages.description')); ?><span class="text-danger">*</span></label>
                                    <textarea type="text" class="form-control <?php $__errorArgs = ['atext'];
$__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="atext" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.holiday') ." ". __('messages.description')); ?>" required id="atext"/></textarea>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="adate2"><?php echo e(__('messages.holiday')); ?> <?php echo e(__('messages.date_end')); ?><span class="text-danger">*</span></label>
                                    <input type="date" class="form-control" name="adate2" placeholder="<?php echo e(__('messages.enter')); ?>" id="adate2"/>
                                </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('holiday.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/holidays')); ?>/" + id + "/edit",
                    success: function (res) {
                        $('#session_id').val(res.session_id);
                        $('#adate').val(res.adate);
                        $('#adate2').val(res.adate2);
                        $('#atext').val(res.atext);
                        $('#hd_id').val(res.hd_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();
            })
        });

        // $("#adate").datepicker({
        //     autoHide: true,
        //     endDate: "today",
        //     // format: 'dd-mm-yyyy',
        //     format: 'yyy-mm-dd',
        // });
        // $("#adate2").datepicker({
        //     autoHide: true,
        //     endDate: "today",
        //     // format: 'dd-mm-yyyy',
        //     format: 'yyy-mm-dd',
        // });
    </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/holiday.blade.php ENDPATH**/ ?>