<style>
    .fc-event
    {
        background-color:#fff;
        border:1px solid #fff;
    }

</style>
<section class="" style="padding-bottom: 1rem;">
    <div class="card bg-light-transparent mx-2">
        <div class="card-header bg-light">
            <h5 class="card-title">Maintenance Request Calendar</h5>           
            <a href="<?php echo base_url('hr/serviceform/onlineForm/maintenance_form') ?>" target="_blank" data-tooltip="tooltip" title="Listing" class="btn btn-outline-dark btn-sm" title="List"><i class="fa fa-plus"></i> Add New Maintenance</a>
            <a href="<?php echo base_url('hr/serviceform/onlineForm/maintenance_list') ?>" target="_blank" data-tooltip="tooltip" title="Listing" class="btn btn-outline-dark btn-sm" title="List"><i class="fa fa-list"></i> Maintenance Request List</a>
        </div>
        <div class="card-body">
            <div class="card no-shadow"> 
                <div class="card-body">
                    <h3>Colour Info</h3>
                    <div class="container">
                        <div class="row">
                            <?php foreach ($complain as $key => $row){ ?>
                                <div class="col mb-1">
                                    <div class="col text-center text-white">
                                        <div style="background-color:<?php echo $row['color_code']; ?>;min-width:20px;min-height:30px;border-radius:10px;font-weight:600;">
                                            <?php echo $row['Complaint'];?>
                                        </div>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>
                    </div><hr>
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12">
                                    <div class="fc-overflow">
                                        <div id="calendar"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<style type="text/css">
    .tooltipevent
    {
        width:auto;
        height:auto;
        background:rgba(0,0,0,0.75);
        position:absolute;
        color: #fff;
        z-index:10001;
        padding:10px 10px 10px 10px ;  
        line-height: 200%;
    }
</style>
<script type="text/javascript">
    $(document).ready(function(){
        var fc_event= '';
        var resource = <?php echo $resource;?>;

        var fullcalendar = $('#calendar').fullCalendar({ 
            themeSystem: 'bootstrap4',
            header: 
            {
                left: 'prev,next today',
                center: 'title',
                right: 'month,listMonth'
            },
            buttonText: {
                today: 'Today',
                month: 'Calendar',
                listMonth: 'List'
            },

            navLinks: true, // can click day/week names to navigate views
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: <?php echo $fc_event; ?>,
            eventMouseover: function (data, event, param, resource = <?php echo $resource;?>) {
                var js_res = JSON.parse(JSON.stringify(resource));
                var hover_item = js_res[data.id];
                // console.log(hover_item);
                var title = JSON.stringify(data.title);
                var start = moment(hover_item.createdTS).format('DD-MM-YYYY');
                // var end = moment(hover_item.date_fixed).format('DD-MM-YYYY');

                if((hover_item.date_fixed != null || hover_item.date_fixed != '' || hover_item.date_fixed != undefined) && hover_item.date_fixed != '0000-00-00'){
                    var end = moment(hover_item.date_fixed).format('DD-MM-YYYY');
                }else{
                    var end = 'No fixed date'
                }

                tooltip = '<div class="tooltipevent"> Requester : '+hover_item.userName+'['+hover_item.staff_id+']'+'<br/> Email : '+hover_item.email+'<br/> Complaint : '+hover_item.complain_category+'<br/> Start Date : '+start+'<br/> End Date : '+end+'<br/>Department : '+hover_item.dept_name+'/'+hover_item.branchName+'</div>';

                // console.log(tooltip);
                $("body").append(tooltip);
                $(this).mouseover(function (e) {
                    $(this).css('z-index', 10000);
                    $('.tooltipevent').fadeIn('500');
                    $('.tooltipevent').fadeTo('10', 1.9);
                }).mousemove(function (e) {
                    $('.tooltipevent').css('top', e.pageY + 10);
                    $('.tooltipevent').css('left', e.pageX + 20);
                });
            },

            eventMouseout: function(data, event) {
                $(this).css('z-index', 8);
                $('.tooltipevent').remove();
            },
        });

        fullcalendar.fullCalendar();
    });
</script>