<?php
require_once __DIR__ . '/../../includes/auth.php';
requireLogin();
requirePermission('inventory.manage');

require_once __DIR__ . '/../../config/database.php';

$stmt = $pdo->query("SELECT * FROM inventory_products ORDER BY created_at DESC");
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);

$breadcrumb = "Inventory Products";
require_once __DIR__ . '/../../includes/layout.php';
?>

<div class="container">

    <div class="page-header">
        <h2>Inventory Products</h2>
        <p class="page-subtitle">
            Manage product catalog (models, brands, categories).
        </p>
    </div>

    <div class="topbar">
        <a class="btn" href="add_product.php">+ Add Product</a>
        <a class="btn secondary" href="index.php">← Back to Inventory</a>
    </div>

    <div class="table-wrap">
        <table>
            <thead>
                <tr>
                    <th>Category</th>
                    <th>Brand</th>
                    <th>Model</th>
                    <th>SKU</th>
                    <th>Created</th>
                </tr>
            </thead>
            <tbody>

            <?php if (!$products): ?>
                <tr>
                    <td colspan="5">No products found.</td>
                </tr>
            <?php else: ?>

            <?php foreach ($products as $p): ?>
                <tr>
                    <td><?= htmlspecialchars($p['category']) ?></td>
                    <td><?= htmlspecialchars($p['brand']) ?></td>
                    <td><?= htmlspecialchars($p['model']) ?></td>
                    <td><?= htmlspecialchars($p['sku']) ?></td>
                    <td><?= htmlspecialchars($p['created_at']) ?></td>
                </tr>
            <?php endforeach; ?>

            <?php endif; ?>

            </tbody>
        </table>
    </div>

</div>

<?php require_once __DIR__ . '/../../includes/layout_footer.php'; ?>