<?php
require_once 'includes/header.php';
$pdo = db();

$dealers = $pdo->query("SELECT * FROM users WHERE role = 'Dealer' ORDER BY created_at DESC")->fetchAll();
?>

<div class="page-header">
    <h1>Dealer Management</h1>
    <a href="users.php?role=Dealer" class="btn-sm btn-primary">Manage All Users</a>
</div>

<div class="card-grid" style="grid-template-columns: 1fr;">
    <table class="data-table">
        <thead>
            <tr>
                <th>Username</th>
                <th>Email</th>
                <th>Status</th>
                <th>Performance (Sales)</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($dealers as $dealer): ?>
            <tr>
                <td><?php echo htmlspecialchars($dealer['username']); ?></td>
                <td><?php echo htmlspecialchars($dealer['email']); ?></td>
                <td><span style="padding:0.2rem 0.5rem; background:rgba(76, 175, 80, 0.2); color:#4caf50; border-radius:4px;">Active</span></td>
                <td>$0.00 (0 Sales)</td> <!-- Placeholder for now -->
                <td>
                    <a href="users.php?edit=<?php echo $dealer['id']; ?>" class="btn-sm" style="background:var(--accent-color); color:black;">Edit</a>
                </td>
            </tr>
            <?php endforeach; ?>
            <?php if (empty($dealers)): ?>
            <tr>
                <td colspan="5" style="text-align:center; color:var(--text-secondary); padding:2rem;">No dealers found. Create one in the Users section.</td>
            </tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>

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