<!DOCTYPE html>
<html>
<head>
     <?= $this->include('admin/inc/title') ?>
    <link rel="stylesheet"
          href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
</head>
<body>
 <?= $this->include('admin/inc/header') ?>
<div class="container mt-4">

    <h3 class="mb-4">Employee Attendance Report</h3>

    <!-- 🔹 FILTER FORM -->
    <form method="get" class="row mb-3">
        <div class="col-md-3">
            <input type="date" name="from_date" class="form-control"
                   value="<?= $_GET['from_date'] ?? '' ?>" required>
        </div>
        <div class="col-md-3">
            <input type="date" name="to_date" class="form-control"
                   value="<?= $_GET['to_date'] ?? '' ?>" required>
        </div>
        <div class="col-md-3">
            <button class="btn btn-primary">Filter</button>
            <a href="<?= base_url('admin/attendance/exportCsv?from_date=' . ($_GET['from_date'] ?? '') . '&to_date=' . ($_GET['to_date'] ?? '')) ?>"
               class="btn btn-success ml-2">
                Download CSV
            </a>
        </div>
    </form>

    <!-- 🔹 TABLE -->
    <table class="table table-bordered table-striped">
        <thead class="thead-dark">
        <tr>
            <th>Name</th>
            <th>Username</th>
            <th>Date</th>
            <th>Punch In</th>
            <th>Punch Out</th>
            <th>Work Mode</th>
        </tr>
        </thead>
        <tbody>
        <?php if (!empty($records)) { ?>
            <?php foreach ($records as $row) { ?>
                <tr>
                    <td><?= esc($row['name']) ?></td>
                    <td><?= esc($row['username']) ?></td>
                    <td><?= esc($row['attendance_date']) ?></td>
                    <td><?= esc($row['punch_in_time']) ?></td>
                    <td><?= esc($row['punch_out_time'] ?? '-') ?></td>
                    <td><?= esc($row['work_mode']) ?></td>
                </tr>
            <?php } ?>
        <?php } else { ?>
            <tr>
                <td colspan="6" class="text-center text-danger">No records found</td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
<div class="row mt-5">
		<div class="col-md-4"></div>
		<div class="col-md-4"><a href="<?= base_url('home')?>"><button class="btn btn-danger btn-md">Return to Home</button></a></div>
		<div class="col-md-4"></div>
        </div>
</div>
 <?= $this->include('admin/inc/footer') ?>
</body>
</html>
