<?php include 'includes/header.php'; ?>
<?php include 'includes/sidebar.php'; ?>
<?php require 'includes/db_connect.php'; ?>

<div class="container mt-4">
    <h4 class="text-orange">Pending Mails</h4>

    <table class="table table-bordered table-striped mt-3">
        <thead class="bg-orange text-white">
            <tr>
                <th>Tracking No</th>
                <th>Subject</th>
                <th>Type</th>
                <th>Last Moved To</th>
                <th>Date</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $query = $conn->query("SELECT * FROM mails WHERE status = 'Pending' ORDER BY id DESC");
            if ($query->num_rows > 0) {
                while ($mail = $query->fetch_assoc()) {
                    echo "<tr>
                        <td>{$mail['tracking_no']}</td>
                        <td>{$mail['subject']}</td>
                        <td>{$mail['type']}</td>
                        <td>{$mail['last_moved_to']}</td>
                        <td>{$mail['reg_date']}</td>
                        <td>
                            <a href='minute_mail.php?mail_id={$mail['id']}' class='btn btn-sm btn-primary'>Minute</a>
                            <a href='mail_history.php?mail_id={$mail['id']}' class='btn btn-sm btn-info'>History</a>
                        </td>
                    </tr>";
                }
            } else {
                echo "<tr><td colspan='6' class='text-center'>No Pending Mails Found.</td></tr>";
            }
            ?>
        </tbody>
    </table>
</div>

<?php include 'includes/footer.php'; ?>
