<?php
require_once "../php/db_connect.php";

$sql = "SELECT * FROM users WHERE role = 'admin' AND status = 'pending' ORDER BY id DESC";
$result = $conn->query($sql);
?>

<h1>Applicant Requests</h1>
<p class="subtitle">Review pending shop owner applications.</p>

<div class="table-wrapper">
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Shop Name</th>
                <th>Shop Type</th>
                <th>Permit No.</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if ($result && $result->num_rows > 0): ?>
                <?php while ($row = $result->fetch_assoc()): ?>
                    <tr>
                        <td><?php echo htmlspecialchars($row["id"]); ?></td>
                        <td><?php echo htmlspecialchars(($row["first_name"] ?? '') . ' ' . ($row["last_name"] ?? '')); ?></td>
                        <td><?php echo htmlspecialchars($row["shop_name"] ?? ''); ?></td>
                        <td><?php echo htmlspecialchars($row["shop_type"] ?? ''); ?></td>
                        <td><?php echo htmlspecialchars($row["business_permit_number"] ?? ''); ?></td>
                        <td class="actions text-center">
    <a href="view-applicant.php?id=<?php echo $row["id"]; ?>"
       class="btn-action btn-view">
        <i class="fa-solid fa-eye"></i> View
    </a>

    <a href="../php/update-applicant-status.php?id=<?php echo $row["id"]; ?>&action=approve"
       class="btn-action btn-approve"
       onclick="return confirm('Approve this applicant?');">
        <i class="fa-solid fa-check"></i> Approve
    </a>

    <a href="../php/update-applicant-status.php?id=<?php echo $row["id"]; ?>&action=reject"
       class="btn-action btn-reject"
       onclick="return confirm('Reject this applicant?');">
        <i class="fa-solid fa-xmark"></i> Reject
    </a>
</td>
                    </tr>
                <?php endwhile; ?>
            <?php else: ?>
                <tr>
                    <td colspan="8">No pending applicant requests found.</td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>

<style>
    .btn-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    color: #fff !important;
    margin-right: 6px;
}

.btn-view {
    background: #0ea5e9;
}

.btn-approve {
    background: #22c55e;
}

.btn-reject {
    background: #ef4444;
}
</style>