@php($isEdit = isset($itemCategory))
<form action="{{ $isEdit ? route('item-categories.update', $itemCategory) : route('item-categories.store') }}" method="POST">
	@csrf
	@if($isEdit)
		@method('PUT')
	@endif

	<div class="mb-3">
		<label for="name" class="form-label">Name</label>
		<input type="text" id="name" name="name" class="form-control @error('name') is-invalid @enderror" value="{{ old('name', $isEdit ? $itemCategory->name : '') }}" required>
		@error('name')
			<div class="invalid-feedback">{{ $message }}</div>
		@enderror
	</div>

	<div class="mb-3">
		<label for="parent_category_id" class="form-label">Parent Category (optional)</label>
		<select id="parent_category_id" name="parent_category_id" class="form-select @error('parent_category_id') is-invalid @enderror">
			<option value="{{ $inventoryAccount->id }}">— Inventory (Main) —</option>
			@foreach($categories as $id => $name)
				<option value="{{ $id }}" {{ (string) old('parent_category_id', $isEdit ? $itemCategory->parent_id : '') === (string) $id ? 'selected' : '' }}>{{ $name }}</option>
			@endforeach
		</select>
		<div class="form-text">Categories will be created under the Inventory account in Chart of Accounts.</div>
		@error('parent_category_id')
			<div class="invalid-feedback">{{ $message }}</div>
		@enderror
	</div>

	<!-- @if($isEdit)
	<div class="mb-3">
		<label for="is_active" class="form-label">Status</label>
		<select id="is_active" name="is_active" class="form-select @error('is_active') is-invalid @enderror">
			<option value="1" {{ old('is_active', $itemCategory->is_active ? '1' : '0') === '1' ? 'selected' : '' }}>Active</option>
			<option value="0" {{ old('is_active', $itemCategory->is_active ? '1' : '0') === '0' ? 'selected' : '' }}>Inactive</option>
		</select>
		@error('is_active')
			<div class="invalid-feedback">{{ $message }}</div>
		@enderror
	</div>
	@endif -->

	<div class="d-flex gap-2">
		<button type="submit" class="btn btn-primary">{{ $isEdit ? 'Update' : 'Create' }}</button>
		<a href="{{ route('item-categories.index') }}" class="btn btn-secondary">Cancel</a>
	</div>
</form>
