<?php
require_once '../../includes/auth_middleware.php';
require_once '../../config/database.php';
require_once '../../includes/header.php';
checkRole(['admin']);

$products = $pdo->query("SELECT * FROM products ORDER BY product_name ASC")->fetchAll();
?>

<div class="container" style="max-width: 600px;">
    <div class="card">
        <h2>TAMBAH MENU PRODUK</h2>
        <form action="../../api/add_product.php" method="POST">
            <div class="input-group">
                <label>Nama Produk (Contoh: Kebab Tamvan Spesial)</label>
                <input type="text" name="product_name" required>
            </div>
            <div class="input-group">
                <label>Harga Jual (Rp)</label>
                <input type="number" name="selling_price" required placeholder="Contoh: 15000">
            </div>
            <button type="submit" class="btn-primary">TAMBAH PRODUK</button>
        </form>
    </div>

    <div class="card" style="margin-top: 2rem;">
        <h3>DAFTAR MENU JUALAN</h3>
        <table style="width: 100%; border-collapse: collapse;">
            <tbody>
                <?php foreach ($products as $p): ?>
                <tr style="border-bottom: 1px solid #eee;">
                    <td style="padding: 15px; font-weight: bold;"><?= $p['product_name'] ?></td>
                    <td style="text-align: right; color: var(--accent);">Rp <?= number_format($p['selling_price'], 0, ',', '.') ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>