<?php $__env->startSection('maincontent'); ?>
    <style>
        .sweet-content p{
            text-align: justify!important;
        }
    </style>
    <div class="col-md-12">
        <div class="card">
            <div class="header">
                <button data-toggle="modal" data-target="#modal" onclick="loadModal('user-leave-apply')"
                        class="btn btn-info btn-fill pull-right">LEAVE APPLY <i class="fa fa-plus" aria-hidden="true"></i></button>
                <h4 class="title">Leave Statistics</h4>
            </div>
            <div class="content">
                <div class="row">
                    <div class="col-md-6 col-md-offset-3">
                        <?php echo Form::open(['url'=>'user-leave']); ?>

                        <?php echo Form::hidden('search','yes'); ?>

                        <div class="col-md-5">
                            <label>FROM</label>
                            <div class="form-group">
                                <input type="text" name="from_date" class="form-control datepicker"
                                       placeholder="From Date here"/>
                            </div>
                        </div>
                        <div class="col-md-5">
                            <label>TO</label>
                            <div class="form-group">
                                <input type="text" name="to_date" class="form-control datepicker"
                                       placeholder="To Date Here"/>
                            </div>
                        </div>
                        <div class="col-md-2">
                            <label>&nbsp;</label>
                            <div class="form-group">
                                <button class="btn btn-info btn-fill" type="submit">Search</button>
                            </div>
                        </div>
                        <?php echo Form::close(); ?>

                    </div>
                    <div class="col-md-12">
                        <div class="fresh-datatables">
                            <table id="datatable" class="table table-striped table-bordered table-hover" cellspacing="0"
                                   width="100%" style="width:100%">
                                <thead>
                                <tr>
                                    <th>Sl</th>
                                    <th>Leave Type</th>
                                    <th>Message</th>
                                    <th>Reply</th>
                                    <th>Desire Date</th>
                                    <th>Duration</th>
                                    <th>Apply date</th>
                                    <th>Reviewed At</th>
                                    <th>Status</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php $i = 0; ?>
                                <?php $__empty_1 = true; $__currentLoopData = $leaves; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $leave): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <?php if($leave->viewed==0 && $leave->status!=0): ?>
                                        <tr onclick="updateNotifyView('<?php echo e($leave->id); ?>',this)" style="background-color:#C8FFC8; cursor:pointer">
                                    <?php else: ?>
                                        <tr>
                                    <?php endif; ?>
                                        <td><?php echo e(++$i); ?></td>
                                        <td><?php echo e($leave->leaveType->title); ?></td>
                                        <td>

                                            <?php if(strlen($leave->message)>30): ?>
                                                <?php echo e(strip_tags(substr($leave->message,0,30))); ?>....<a
                                                        href="javascript:void(0)" onclick="getDetails(<?php echo e($leave); ?>)">more</a>
                                            <?php else: ?>
                                                <?php echo e(strip_tags($leave->message)); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td>

                                            <?php if(strlen($leave->reply)>20): ?>
                                                <?php echo e(substr($leave->reply,0,20)); ?>....<a href="javascript:void(0)" onclick="getDetails(<?php echo e($leave); ?>)">more</a>
                                            <?php else: ?>
                                                <?php echo e($leave->reply); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td><?php echo e($leave->from_date); ?> - <?php echo e($leave->to_date); ?></td>
                                        <td>
                                            <?php
                                            $duration= date_diff(date_create($leave->from_date),date_create($leave->to_date));
                                            echo $duration->days+1;
                                            ?>
                                        </td>
                                        <td><?php echo e($leave->created_at); ?></td>
                                        <td><?php echo e($leave->action_at); ?></td>
                                        <td>
                                            <?php if($leave->status=='1'): ?>
                                                <label class="label label-success">Approved</label>
                                            <?php elseif($leave->status=='0'): ?>
                                                <label class="label label-danger">Pending</label>
                                            <?php else: ?>
                                                <label class="label label-warning">Denied</label>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <a href="#" class="btn btn-simple btn-warning btn-icon" <?php if($leave->status==0): ?>
                                               data-toggle="modal" data-target="#modal"
                                               onclick="loadModalEdit('leave-apply-edit',<?php echo e($leave->id); ?>,'edit')" title="Edit" <?php else: ?> disabled title="You can't edit leave"  <?php endif; ?>><i class="fa fa-edit"></i></a>
                                            <a <?php if($leave->status==1): ?> disabled title="You can't delete approved leave" <?php else: ?> title="Delete" onclick="deleteConfirm('leave-apply-delete',<?php echo e($leave->id); ?>)"  <?php endif; ?> href="javascript:void(0)"
                                               class="btn btn-simple btn-danger btn-icon remove"><i
                                                        class="fa fa-times"></i></a>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="10">No request yet</td>
                                    </tr>
                                <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        function updateNotifyView(leaveId,obj) {
            $.ajax({
                url: "<?php echo e(URL::to('/')); ?>/leave-notification-view/"+leaveId ,
                type: 'GET', // define the type of HTTP verb we want to use (POST for our form)
                dataType: 'json',
                success: function (data) {
                    if(data.status=='success'){
                        $(obj).css({'background-color':'transparent'});
                    }
                }
            });
        }
        function getDetails(leave) {
            var reply= (leave.reply==null)?'No reply':leave.reply;
            swal({  title: 'Leave Application',
                confirmButtonText: 'Close',
                confirmButtonClass: "btn btn-danger",
                html:'<b>Message:</b><p style="text-align: justify; float:left;">'+leave.message+'</p>'+
                '<b>Reply:</b><p style="text-align: justify;">'+reply+'</p>'
            });
        }

    </script>
    <script src="<?php echo e(asset('public/vendor/unisharp/laravel-ckeditor/ckeditor.js')); ?>"></script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('backend._partials.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>