<?php
$tags = json_decode((string) ($item['dietary_tags'] ?? '[]'), true);
$tags = is_array($tags) ? $tags : [];
?>
<article class="menu-card">
    <div class="menu-card-art <?= !empty($item['image_url']) ? 'has-image' : '' ?>"
        <?php if (!empty($item['image_url'])): ?>style="background-image:url('<?= e($item['image_url']) ?>')"<?php endif; ?>>
        <?php if (empty($item['image_url'])): ?>
            <span><?= e(strtoupper(substr((string) $item['name'], 0, 2))) ?></span>
        <?php endif; ?>
        <?php if (!empty($item['featured'])): ?><span class="card-badge">House Pick</span><?php endif; ?>
    </div>
    <div class="menu-card-body">
        <div class="menu-card-heading">
            <h3><?= e($item['name']) ?></h3>
            <strong><?= money($item['price_cents']) ?></strong>
        </div>
        <p><?= e($item['description']) ?></p>
        <?php if ($tags): ?>
            <div class="tag-list">
                <?php foreach ($tags as $tag): ?><span><?= e($tag) ?></span><?php endforeach; ?>
            </div>
        <?php endif; ?>
        <form class="quick-add" action="<?= e(url('/cart/add')) ?>" method="post">
            <?= csrf_field() ?>
            <input type="hidden" name="menu_item_id" value="<?= (int) $item['id'] ?>">
            <input type="hidden" name="return_to" value="<?= e(\FatBottom\Core\Http::path()) ?>">
            <label>
                <span class="sr-only">Quantity</span>
                <select name="quantity" aria-label="Quantity for <?= e($item['name']) ?>">
                    <?php for ($quantity = 1; $quantity <= 8; $quantity++): ?>
                        <option value="<?= $quantity ?>"><?= $quantity ?></option>
                    <?php endfor; ?>
                </select>
            </label>
            <button class="button button-small" type="submit">Add to Order</button>
        </form>
    </div>
</article>
