@extends('backend.layout')

@section('backend_content')
    <div class="container-fluid">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <h4 class="fw-bold mb-1">Menu Items - {{ $foodCart->name }}</h4>
                <small class="text-muted">Add and manage food items individually for search and ordering.</small>
            </div>
            <div class="d-flex gap-2">
                <a href="{{ route('admin.food-carts.items.create', $foodCart) }}" class="btn btn-primary">
                    <i class="bx bx-plus"></i> Add Item
                </a>
                <a href="{{ route('admin.food-carts.index') }}" class="btn btn-light">
                    <i class="bx bx-arrow-back"></i> Back
                </a>
            </div>
        </div>

        <div class="card border-0 shadow-sm">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>Item</th>
                            <th>Price</th>
                            <th>Status</th>
                            <th>Tags</th>
                            <th>Created By</th>
                            <th class="text-end">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse ($items as $item)
                            <tr>
                                <td>
                                    <div class="d-flex align-items-center gap-2">
                                        @if ($item->image)
                                            <img src="{{ asset('storage/' . $item->image) }}" alt="{{ $item->title }}"
                                                class="rounded" style="width:42px;height:42px;object-fit:cover;">
                                        @else
                                            <div class="bg-light border rounded d-flex align-items-center justify-content-center"
                                                style="width:42px;height:42px;"><i class="bx bx-bowl-hot"></i></div>
                                        @endif
                                        <div>
                                            <div class="fw-semibold">{{ $item->title }}</div>
                                            <small
                                                class="text-muted">{{ \Illuminate\Support\Str::limit($item->description, 55) }}</small>
                                        </div>
                                    </div>
                                </td>
                                <td>${{ number_format((float) $item->price, 2) }}</td>
                                <td>
                                    @if ($item->is_available)
                                        <span class="badge bg-success">Available</span>
                                    @else
                                        <span class="badge bg-secondary">Unavailable</span>
                                    @endif
                                </td>
                                <td>
                                    @php $tags = collect($item->search_tags ?? [])->take(3); @endphp
                                    @forelse ($tags as $tag)
                                        <span class="badge bg-light text-dark">{{ $tag }}</span>
                                    @empty
                                        <span class="text-muted">-</span>
                                    @endforelse
                                </td>
                                <td>{{ $item->creator?->name ?? 'N/A' }}</td>
                                <td class="text-end">
                                    <div class="btn-group">
                                        <a href="{{ route('admin.food-carts.items.edit', [$foodCart, $item]) }}"
                                            class="btn btn-sm btn-outline-warning">
                                            <i class="bx bx-edit"></i>
                                        </a>
                                        <form action="{{ route('admin.food-carts.items.destroy', [$foodCart, $item]) }}"
                                            method="POST" onsubmit="return confirm('Delete this food item?');">
                                            @csrf
                                            @method('DELETE')
                                            <button class="btn btn-sm btn-outline-danger" type="submit">
                                                <i class="bx bx-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="text-center text-muted py-5">No food items found. Add your first
                                    item.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
