<x-app-layout>
    <x-slot name="header"><i class="bi bi-pencil-square me-2"></i>{{ __('Edit Item') }}: {{ $item->name }}</x-slot>

    <div class="card shadow-sm" style="max-width:700px;">
        <div class="card-body">
            <form action="{{ route('items.update', $item) }}" method="POST">
                @csrf @method('PUT')
                <div class="row g-3">
                    <div class="col-md-6">
                        <label class="form-label">{{ __('Name') }} <span class="text-danger">*</span></label>
                        <input type="text" name="name" class="form-control @error('name') is-invalid @enderror" value="{{ old('name', $item->name) }}" required>
                        @error('name')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">{{ __('Category') }} <span class="text-danger">*</span></label>
                        <div class="input-group">
                            <select name="category" class="form-select @error('category') is-invalid @enderror" required>
                                <option value="">{{ __('-- Select Category --') }}</option>
                                @foreach($categories as $cat)
                                    <option value="{{ $cat->name }}" {{ old('category', $item->category) == $cat->name ? 'selected' : '' }}>
                                        {{ $cat->name }}
                                    </option>
                                @endforeach
                            </select>
                            <a href="{{ route('items.categories') }}" class="btn btn-outline-secondary" title="{{ __('Manage Categories') }}">
                                <i class="bi bi-gear"></i>
                            </a>
                        </div>
                        @error('category')<div class="invalid-feedback d-block">{{ $message }}</div>@enderror
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">{{ __('Unit') }} <span class="text-danger">*</span></label>
                        <select name="unit" class="form-select @error('unit') is-invalid @enderror" required>
                            @foreach(App\Models\Item::$units as $u)
                                <option value="{{ $u }}" {{ old('unit', $item->unit) == $u ? 'selected' : '' }}>{{ ucfirst($u) }}</option>
                            @endforeach
                        </select>
                        @error('unit')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">{{ __('Quantity') }} <span class="text-danger">*</span></label>
                        <input type="number" name="quantity" class="form-control @error('quantity') is-invalid @enderror" value="{{ old('quantity', $item->quantity) }}" min="0" step="0.01" required>
                        @error('quantity')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">{{ __('Unit Price') }} <span class="text-danger">*</span></label>
                        <input type="number" name="unit_price" class="form-control @error('unit_price') is-invalid @enderror" value="{{ old('unit_price', $item->unit_price) }}" min="0" step="0.01" required>
                        @error('unit_price')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                    <div class="col-12">
                        <label class="form-label">{{ __('Description') }}</label>
                        <textarea name="description" class="form-control" rows="2">{{ old('description', $item->description) }}</textarea>
                    </div>
                </div>
                <div class="mt-3 d-flex gap-2">
                    <button type="submit" class="btn btn-primary"><i class="bi bi-save me-1"></i>{{ __('Update Item') }}</button>
                    <a href="{{ route('items.index') }}" class="btn btn-outline-secondary">{{ __('Cancel') }}</a>
                </div>
            </form>
        </div>
    </div>
</x-app-layout>
