@props([
    'action',
    'method' => 'POST',
    'submitLabel',
    'categories' => [],
])

@php
    $categoryOptions = ['' => __('inventory.items.all_categories')] + collect($categories)
        ->mapWithKeys(fn ($c) => [$c->id => $c->code.' — '.$c->name])
        ->all();
@endphp

<form method="POST" action="{{ $action }}" novalidate>
    @csrf
    @if (strtoupper($method) !== 'POST')
        @method($method)
    @endif

    <div class="card">
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-8">
                    <x-ui.form.input
                        name="name"
                        :label="__('inventory.items.fields.name')"
                        :value="old('name')"
                        :placeholder="__('inventory.items.placeholders.name')"
                        required
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.search-select
                        name="inventory_category_id"
                        lookup="categories"
                        :label="__('inventory.items.fields.category')"
                        :options="$categoryOptions"
                        :selected="old('inventory_category_id')"
                        :placeholder="__('inventory.items.all_categories')"
                        optional
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.input
                        name="barcode"
                        :label="__('inventory.items.fields.barcode')"
                        :value="old('barcode')"
                        :placeholder="__('inventory.items.placeholders.barcode')"
                    />
                </div>
                <div class="col-12">
                    <x-ui.form.input
                        name="description"
                        :label="__('inventory.items.fields.description')"
                        :value="old('description')"
                        :placeholder="__('inventory.items.placeholders.description')"
                        optional
                    />
                </div>
            </div>
            <div class="d-flex justify-content-end gap-2 mt-4">
                <x-ui.buttons.secondary :href="route('inventory.items.index')">
                    {{ __('common.cancel') }}
                </x-ui.buttons.secondary>
                <x-ui.buttons.primary type="submit">{{ $submitLabel }}</x-ui.buttons.primary>
            </div>
        </div>
    </div>
</form>
