<?php include($_SERVER['DOCUMENT_ROOT'] . "/COMPONENTS/root/path.php"); ?>
<h6 class="card-subtitle"></h6>
<div class="table-responsive">
    <table id="example1" class="example1" style='Width:100%'>
        <thead class="bg-info">
            <tr>
                <th scope="col" style="width:50px;">Date</th>
                <th scope="col">Staff Id</th>
                <th scope="col">Name</th>
                <th scope="col">Role</th>
                <th scope="col">Temperature</th>
                <th scope="col">Time In</th>
                <th scope="col">Time Out</th>
                <th scope="col">Status</th>
            </tr>
        </thead>
    </table>
</div>




<script>
    $(".modals").load(domain + "/COMPONENTS/sub-pages/modals.php");
    var staff = sessionStorage.getItem("staff");
    var dateFrom = sessionStorage.getItem("dateFrom");
    var dateTo = sessionStorage.getItem("dateTo");
    var rowCount = 1;
    var table = $('.example1').DataTable({
        responsive: true,
        "ajax": {
            "url": domain_api + "/staff/attendance.php?staff=" + encodeURIComponent(staff) + "&dateFrom=" + encodeURIComponent(dateFrom) + "&dateTo=" + encodeURIComponent(dateTo) + "",
            "dataSrc": "staff_attendance"
        },
        "columns": [{
                "data": "Date",
            },
            {
                "data": "idd"
            },
            {
                "data": null,
                render: function(data, type, row) {
                    return data.fullname;
                }
            },
            {
                "data": "role"
            },
            {
                "data": "Temperature"
            },
            {
                "data": null,
                render: function(data, type, row) {
                    if (data.StatusIndicating == "Present") {
                        return "<span style='color:green; font-weight:500;'>" + data.TimeIn + "</span>";
                    } else {
                        return "<span style='color:red; font-weight:500;'>" + data.TimeIn + "</span>";
                    }
                }
            },
            {
                "data": "TimeOut"
            },
            {
                "data": null,
                render: function(data, type, row) {
                    if (data.StatusIndicating == "Present") {
                        return "<span style='color:green; font-weight:500;'>" + data.StatusIndicating + "</span>";
                    } else {
                        return "<span style='color:red; font-weight:500;'>" + data.StatusIndicating + "</span>";
                    }
                }
            }

        ],
        "ordering": true,
        order: [
            ["0", 'asc']
        ]
    });

    new $.fn.dataTable.FixedHeader(table);
</script>