<?php $__env->startSection('title'); ?>
    <?php echo e(__('messages.dashboard')); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('styles'); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>

    <div class="d-flex justify-content-between">
        <h3 class="dashboard">
            <?php echo e(__('messages.dashboard')); ?>

            <button class="btn btn-light text-center" style="color: #ccc;" onclick="attendDemo()" title="For Attendance Report Testing">Attendance Data Entry (Demo Data)</button>
        </h3>
        <button class="btn btn-light text-center" style="background-color: #009A75; color: #FFF;" onclick="sendNotification()">Send Notification</button>
        <input type="hidden" id="id_device_token" value="<?php echo e(auth()->user()->device_token); ?>">
    </div>
    <div class="row mt-4">
        

        

        <div class="col-md-3">
            <div class="card">
                <div class="card-body">
                    <h6 class="top-title"><?php echo e(__('messages.total_employees')); ?></h6>
                    <h1 class="total_number"><?php echo e($total_employees); ?></h1>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card">
                <div class="card-body">
                    <h6 class="top-title"><?php echo e(__('messages.total_holidays')); ?></h6>
                    <h1 class="total_number"><?php echo e($total_holidays); ?></h1>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card">
                <div class="card-body">
                    <h6 class="top-title"><?php echo e(__('messages.total_leaves')); ?></h6>
                    <h1 class="total_number"><?php echo e($total_leaves); ?></h1>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card">
                <div class="card-body">
                    <h6 class="top-title"><?php echo e(__('messages.today_present')); ?></h6>
                    <h1 class="total_number"><?php echo e(COUNT($todays_attendance_status)); ?></h1>
                </div>
            </div>
        </div>
    </div>





    <div class="row mt-4">
        <div class="col-md-4">
            <div class="card">
                <div class="card-body">
                    <h6 class="top-title"><?php echo e(__('messages.active_employees')); ?></h6>
                    <h1 class="total_number"><?php echo e($active_employees); ?></h1>
                </div>
            </div>
        </div>

        <div class="col-md-8">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-hover table-striped">
                            <caption>
                                Today's Attendance Status
                            </caption>
                            <thead>
                                <tr>
                                    <th colspan="8" class="text-center">Today's Attendance Status</th>
                                </tr>
                                <tr>
                                    <th>#</th><th><?php echo e(__('messages.employee_name')); ?></th><th><?php echo e(__('messages.employee_no')); ?></th>
                                    <th><?php echo e(__('messages.designation')); ?></th><th><?php echo e(__('messages.duty_shift')); ?></th>
                                    <th><?php echo e(__('messages.in_time')); ?></th><th><?php echo e(__('messages.out_time')); ?></th><th><?php echo e(__('messages.late')); ?></th>
                                </tr>
                            </thead>

                            <tbody>
                                <?php $__currentLoopData = $todays_attendance_status; $__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->employee_name); ?></td>
                                    <td><?php echo e($item->employee_no); ?></td>
                                    <td><?php echo e($item->designation_name); ?></td>
                                    <td><?php echo e($item->duty_shift ?: 'N/A'); ?></td>
                                    <td><?php echo e($item->in_time ?: ''); ?></td>
                                    <td><?php echo e($item->out_time ?: ''); ?></td>
                                    <td><?php echo e($item->is_delay ? 'Yes' : ''); ?></td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- donut chart start -->
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    
    
    
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
        $(document).ready(function ($) {
            $('.select2-multiple').select2();
            $('#get-data-btn').prop("disabled", true);
            $('#organization').change(function () {
                var organization_id = $(this).val();
                if (organization_id) {
                    $.ajax({
                        type: "GET",
                        url: "<?php echo e(url('system/statistics/get-herd-list')); ?>?organization_id=" + organization_id,
                        success: function (res) {
                            if (res) {
                                $('#get-data-btn').prop("disabled", false);
                                $("#herd").empty().append('<option>Select Herd</option>');
                                $.each(res, function (key) {
                                    $("#herd").append('<option value="' + res[key].id +
                                        '">' + res[key].name + '</option>');
                                });
                            } else {
                                $("#herd").empty();
                            }
                        }
                    });
                } else {
                    $("#herd").empty();
                    $("#lot").empty();
                }
            });
            $('#herd').on('change', function () {
                var lot_id = $(this).val();
                if (lot_id) {
                    $.ajax({
                        type: "GET",
                        url: "<?php echo e(url('system/statistics/get-lot-list')); ?>?lot_id=" + lot_id,
                        success: function (res) {
                            if (res) {
                                $("#lot").empty().append('<option>Select Lot</option>');
                                $.each(res, function (key, value) {
                                    $("#lot").append('<option value="' + res[key].id +
                                        '">' + res[key].name + '</option>');
                                });

                            } else {
                                $("#lot").empty();
                            }
                        }
                    });
                } else {
                    $("#lot").empty();
                }

            });
        });
    </script>

    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

    <script type="text/javascript">
        var labels = 11;
        var users = 100;

        const data = {
            labels: labels,
            datasets: [{
                label: 'Top 10 Milking Employee',
                backgroundColor: 'rgb(255, 99, 132)',
                borderColor: 'rgb(255, 99, 132)',
                data: users,
            }]
        };

        const config = {
            type: 'line',
            data: data,
            options: {}
        };

        const topTenMilkingEmployee = new Chart(
            document.getElementById('topTenMilkingEmployee'),
            config
        );

    </script>
    <script>

    </script>
    <!-- Send Notification Start-->
    <script src="https://www.gstatic.com/firebasejs/7.23.0/firebase.js"></script>
    <script>
        var firebaseConfig = {
            apiKey: "<?php echo e(env('APIKEY')); ?>",
            authDomain: "<?php echo e(env('AUTH_DOMAIN')); ?>",
            projectId: "<?php echo e(env('PROJECTID')); ?>",
            storageBucket: "<?php echo e(env('STORAGE_BUCKET')); ?>",
            messagingSenderId: "<?php echo e(env('MESSAGING_SENDERID')); ?>",
            appId: "<?php echo e(env('APPID')); ?>",
            measurementId: "<?php echo e(env('MEASUREMENTID')); ?>"
        };

        firebase.initializeApp(firebaseConfig);
        const messaging = firebase.messaging();

        function initFirebaseMessagingRegistration() {
                messaging
                .requestPermission()
                .then(function () {
                    return messaging.getToken()
                })
                .then(function(token) {
                    if($('#id_device_token').val() !== token){
                        $.ajaxSetup({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            }
                        });

                        $.ajax({
                            url: '<?php echo e(route("save-token")); ?>',
                            type: 'POST',
                            data: {
                                token: token
                            },
                            dataType: 'JSON',
                            success: function (response) {
                                toastr.success("Successfully saved token!");
                            },
                            error: function (err) {
                                toastr.warning("Error! " + err);
                            },
                        });
                    }
                }).catch(function (err) {
                    toastr.warning("Error! " + err);
                });
        }

        messaging.onMessage(function(payload) {
            const noteTitle = payload.notification.title;
            const noteOptions = {
                body: payload.notification.body,
                icon: payload.notification.icon,
            };
            new Notification(noteTitle, noteOptions);
        });

    </script>
    <script>
        $(document).ready(function() {
            // initFirebaseMessagingRegistration();
        });
        function sendNotification(){
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            $.ajax({
                url: '<?php echo e(route("send-notification")); ?>',
                type: 'POST',
                success: function (response) {
                    toastr.success("Successfully send notification!");
                },
                error: function (err) {
                    toastr.warning("Error! " + err);
                },
            });
        }

        function attendDemo(){
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            $.ajax({
                url: '<?php echo e(route("auto_attend")); ?>',
                type: 'POST',
                success: function (response) {
                    toastr.success("Successfully the demo data entry done !");
                    setTimeout( function() {
                        location.reload();
                    }, 1000);
                },
                error: function (err) {
                    toastr.warning("Error! " + err);
                },
            });
        }
    </script>
    <!-- Send Notification End-->
<?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/dashboard.blade.php ENDPATH**/ ?>