@extends('layouts.app')

@section('title', 'Menu')

@section('content')
<div class="row">
    <div class="col-12">
        <h2 class="mb-4"><i class="fas fa-utensils me-2"></i>Daftar Menu</h2>
    </div>
</div>

@foreach($categories as $category)
    @if($category->menus->count() > 0)
    <div class="row mb-4">
        <div class="col-12">
            <h4 class="border-bottom pb-2 mb-3">
                <i class="fas fa-tags me-2"></i>{{ $category->name }}
                @if($category->description)
                    <small class="text-muted fs-6">{{ $category->description }}</small>
                @endif
            </h4>
        </div>
        
        @foreach($category->menus as $menu)
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card menu-card h-100">
                @if($menu->image)
                <img src="{{ asset('images/menus/' . $menu->image) }}" class="menu-image card-img-top" alt="{{ $menu->name }}">
                @else
                <div class="menu-image bg-secondary d-flex align-items-center justify-content-center">
                    <i class="fas fa-utensils fa-3x text-white"></i>
                </div>
                @endif
                <div class="card-body">
                    <h5 class="card-title">{{ $menu->name }}</h5>
                    <p class="card-text text-muted">{{ $menu->description ?? 'Tidak ada deskripsi' }}</p>
                    <div class="d-flex justify-content-between align-items-center">
                        <span class="price-tag">Rp {{ number_format($menu->price, 0, ',', '.') }}</span>
                        @if($menu->is_available)
                        <button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#addToCartModal{{ $menu->id }}">
                            <i class="fas fa-cart-plus me-1"></i>Tambah
                        </button>
                        @else
                        <span class="badge bg-secondary">Tidak Tersedia</span>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        <!-- Add to Cart Modal -->
        <div class="modal fade" id="addToCartModal{{ $menu->id }}" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Tambah ke Keranjang</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                    </div>
                    <form action="{{ route('menu.add-to-cart') }}" method="POST">
                        @csrf
                        <div class="modal-body">
                            <h6>{{ $menu->name }}</h6>
                            <p class="text-muted">Rp {{ number_format($menu->price, 0, ',', '.') }}</p>
                            <input type="hidden" name="menu_id" value="{{ $menu->id }}">
                            <div class="mb-3">
                                <label for="quantity{{ $menu->id }}" class="form-label">Jumlah</label>
                                <input type="number" class="form-control" id="quantity{{ $menu->id }}" name="quantity" value="1" min="1" required>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                            <button type="submit" class="btn btn-primary">Tambah ke Keranjang</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        @endforeach
    </div>
    @endif
@endforeach

@if($categories->isEmpty() || $categories->every(fn($c) => $c->menus->count() == 0))
<div class="text-center py-5">
    <i class="fas fa-utensils fa-4x text-muted mb-3"></i>
    <h4 class="text-muted">Menu belum tersedia</h4>
    <p>Silakanhubungi admin untuk menambahkan menu.</p>
</div>
@endif
@endsection
