<div class="panel-actions">
    <a class="btn-primary" href="<?= e(url('admin/urun/ekle')) ?>">+ Yeni Ürün</a>
    <form method="get" action="<?= e(url('admin/urunler')) ?>" class="filter-form">
        <select name="cat" onchange="this.form.submit()">
            <option value="0">Tüm Kategoriler</option>
            <?php foreach ($categories as $c): ?>
                <option value="<?= (int)$c['id'] ?>" <?= $catFilter==$c['id']?'selected':'' ?>><?= e($c['name']) ?></option>
            <?php endforeach; ?>
        </select>
    </form>
</div>

<div class="panel">
    <div class="table-scroll">
    <table class="data-table">
        <thead><tr><th>Görsel</th><th>Ad</th><th>Kategori</th><th>Fiyat</th><th>Kalori</th><th>Öne Çıkan</th><th>Durum</th><th>İşlem</th></tr></thead>
        <tbody>
        <?php foreach ($products as $p): ?>
            <tr>
                <td>
                    <?php if (!empty($p['video'])): ?>
                        <span class="thumb thumb-emoji">🎬</span>
                    <?php elseif (!empty($p['image'])): ?>
                        <img class="thumb" src="<?= e(media_url($p['image'])) ?>" alt="">
                    <?php else: ?><span class="thumb thumb-emoji">🍽</span><?php endif; ?>
                </td>
                <td><strong><?= e($p['name']) ?></strong></td>
                <td><?= e($p['category_name'] ?? '—') ?></td>
                <td><?= e(money($p['price'], setting('currency','₺'))) ?></td>
                <td><?= $p['calories'] ? (int)$p['calories'].' kcal' : '—' ?></td>
                <td><?= $p['is_featured'] ? '⭐' : '' ?></td>
                <td><?= $p['is_active'] ? '<span class="pill on">Aktif</span>' : '<span class="pill off">Pasif</span>' ?></td>
                <td class="actions">
                    <a class="mini-btn" href="<?= e(url('admin/urun/duzenle/'.$p['id'])) ?>">Düzenle</a>
                    <a class="mini-btn danger" href="<?= e(del_link('admin/urun/sil/'.$p['id'])) ?>" data-confirm="Bu ürünü silmek istediğinize emin misiniz?">Sil</a>
                </td>
            </tr>
        <?php endforeach; ?>
        <?php if (empty($products)): ?><tr><td colspan="8" class="muted">Ürün yok.</td></tr><?php endif; ?>
        </tbody>
    </table>
    </div>
</div>
