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

<div class="container" style="max-width: 600px;">
    <div class="card" style="border-top: 5px solid var(--primary);">
        <h2 style="margin-top:0;">TAMBAH BAHAN BAKU</h2>
        <p style="color: #6b7280; font-size: 0.9rem;">Masukkan data bahan untuk hitung HPP otomatis.</p>
        
        <form action="../../api/add_ingredient.php" method="POST">
            <div class="input-group">
                <label>Nama Bahan</label>
                <input type="text" name="name" placeholder="Contoh: Daging Kebab, Tortilla, Saus" required>
            </div>

            <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
                <div class="input-group">
                    <label>Satuan</label>
                    <select name="unit" required style="width: 100%; padding: 12px; border-radius: 12px; border: 1px solid #ddd;">
                        <option value="gram">Gram (Daging/Saus)</option>
                        <option value="pcs">Pcs (Tortilla/Kemasan)</option>
                    </select>
                </div>
                <div class="input-group">
                    <label>Harga per Satuan (Rp)</label>
                    <input type="number" name="price_per_unit" placeholder="Contoh: 120" required>
                </div>
            </div>

            <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
                <div class="input-group">
                    <label>Stok Awal</label>
                    <input type="number" name="stock_qty" value="0" required>
                </div>
                <div class="input-group">
                    <label>Batas Stok Kritis</label>
                    <input type="number" name="min_stock_level" value="10" required>
                </div>
            </div>

            <button type="submit" class="btn-primary" style="margin-top: 10px;">SIMPAN BAHAN</button>
        </form>
    </div>
</div>