<?php
require_once __DIR__ . '/../config.php';
requireLogin();

$pageTitle = 'Suppliers';
include __DIR__ . '/../includes/admin-header.php';

require_once __DIR__ . '/../lib/logic.php';
$suppliers = getSupplierPerformance();
?>

        <div class="row g-4 mb-4">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header"><h5 class="mb-0">Supplier Performance</h5></div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Supplier ID</th>
                                        <th>Supplier Name</th>
                                        <th>Lead Time (Days)</th>
                                        <th>Rating</th>
                                        <th>Total Orders</th>
                                        <th>Total Value</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if (empty($suppliers)): ?>
                                    <tr><td colspan="6" class="text-center">No suppliers found</td></tr>
                                    <?php else: ?>
                                    <?php foreach ($suppliers as $s): ?>
                                    <tr>
                                        <td><?php echo sanitize($s['SupplierID']); ?></td>
                                        <td><?php echo sanitize($s['SupplierName']); ?></td>
                                        <td><?php echo $s['LeadTime_Days']; ?></td>
                                        <td><?php echo number_format($s['Rating'], 1); ?>/5</td>
                                        <td><?php echo $s['TotalOrders']; ?></td>
                                        <td>$<?php echo number_format($s['TotalValue'], 2); ?></td>
                                    </tr>
                                    <?php endforeach; ?>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

<?php include __DIR__ . '/../includes/admin-footer.php'; ?>