@php $inputName = fn ($field) => $type ? "old_{$field}" : $field; @endphp
<div class="grid gap-4 sm:grid-cols-2">
    <div>
        <label class="block text-sm font-medium text-slate-700">Name</label>
        <input type="text" name="name" value="{{ old('name', $type->name ?? '') }}" required class="mt-1 w-full rounded-lg border-slate-300 text-sm">
    </div>
    <div>
        <label class="block text-sm font-medium text-slate-700">Code</label>
        <input type="text" name="code" value="{{ old('code', $type->code ?? '') }}" class="mt-1 w-full rounded-lg border-slate-300 text-sm">
    </div>
    <div>
        <label class="block text-sm font-medium text-slate-700">Category</label>
        <select name="category" required class="mt-1 w-full rounded-lg border-slate-300 text-sm">
            @foreach ($categories as $value => $label)
                <option value="{{ $value }}" @selected(old('category', $type->category ?? '') === $value)>{{ $label }}</option>
            @endforeach
        </select>
    </div>
    <div>
        <label class="block text-sm font-medium text-slate-700">Unit</label>
        <input type="text" name="unit" value="{{ old('unit', $type->unit ?? '') }}" class="mt-1 w-full rounded-lg border-slate-300 text-sm">
    </div>
    <div>
        <label class="block text-sm font-medium text-slate-700">Reference low</label>
        <input type="number" step="any" name="reference_low" value="{{ old('reference_low', $type->reference_low ?? '') }}" class="mt-1 w-full rounded-lg border-slate-300 text-sm">
    </div>
    <div>
        <label class="block text-sm font-medium text-slate-700">Reference high</label>
        <input type="number" step="any" name="reference_high" value="{{ old('reference_high', $type->reference_high ?? '') }}" class="mt-1 w-full rounded-lg border-slate-300 text-sm">
    </div>
    <div class="sm:col-span-2">
        <label class="block text-sm font-medium text-slate-700">Reference text</label>
        <input type="text" name="reference_text" value="{{ old('reference_text', $type->reference_text ?? '') }}" class="mt-1 w-full rounded-lg border-slate-300 text-sm" placeholder="e.g. Negative, Normal">
    </div>
    <div>
        <label class="block text-sm font-medium text-slate-700">Price (minor units)</label>
        <input type="number" name="price_minor" value="{{ old('price_minor', $type->price_minor ?? 0) }}" class="mt-1 w-full rounded-lg border-slate-300 text-sm">
    </div>
    <div class="flex items-end">
        <label class="inline-flex items-center gap-2 text-sm">
            <input type="checkbox" name="is_active" value="1" @checked(old('is_active', $type->is_active ?? true)) class="rounded border-slate-300"> Active
        </label>
    </div>
    <div class="sm:col-span-2">
        <label class="block text-sm font-medium text-slate-700">Description</label>
        <textarea name="description" rows="2" class="mt-1 w-full rounded-lg border-slate-300 text-sm">{{ old('description', $type->description ?? '') }}</textarea>
    </div>
</div>
