@extends('admin.layout')

@section('title', 'Edit Menu Item')

@section('content')
<div class="max-w-4xl mx-auto">
    <div class="bg-white rounded-lg shadow p-6">
        <div class="flex justify-between items-center mb-6">
            <h2 class="text-2xl font-bold">Edit Menu Item</h2>
            <a href="{{ route('admin.categories.items', $item->category_id) }}" 
               class="px-4 py-2 bg-gray-200 text-gray-700 rounded hover:bg-gray-300">
                Back to Menu Items
            </a>
        </div>
        
        <form action="{{ route('admin.items.update', $item->id) }}" method="POST">
            @csrf
            @method('PUT')
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">Item Name *</label>
                    <input type="text" name="name" value="{{ old('name', $item->name) }}" required
                           class="w-full p-3 border rounded-lg">
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">Category *</label>
                    <select name="category_id" required
                            class="w-full p-3 border rounded-lg">
                        @foreach($categories as $cat)
                        <option value="{{ $cat->id }}" 
                                {{ $item->category_id == $cat->id ? 'selected' : '' }}>
                            {{ $cat->name }}
                        </option>
                        @endforeach
                    </select>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">Price *</label>
                    <input type="number" name="price" value="{{ old('price', $item->price) }}" 
                           required min="0" step="1000"
                           class="w-full p-3 border rounded-lg">
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">Display Order</label>
                    <input type="number" name="order" value="{{ old('order', $item->order) }}"
                           class="w-full p-3 border rounded-lg">
                </div>
                
                <div class="md:col-span-2">
                    <label class="block text-sm font-medium text-gray-700 mb-2">Description</label>
                    <textarea name="description" rows="2"
                              class="w-full p-3 border rounded-lg">{{ old('description', $item->description) }}</textarea>
                </div>
                <div class="flex items-center">
    <input type="checkbox" name="is_active" id="is_active" value="1"
           {{ $item->is_active ? 'checked' : '' }}
           class="h-5 w-5 text-gold rounded">
    <label for="is_active" class="ml-2 text-gray-700">Available for order</label>
</div>
            </div>
            
            <div class="mt-6 flex justify-end space-x-4">
                <a href="{{ route('admin.categories.items', $item->category_id) }}"
                   class="px-6 py-3 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50">
                    Cancel
                </a>
                <button type="submit"
                        class="px-6 py-3 bg-gold text-black font-semibold rounded-lg hover:bg-dark-gold transition">
                    Update Menu Item
                </button>
            </div>
        </form>
    </div>
</div>
@endsection