{{--
    Shared create/edit fields for an asset category.

    $category — the AssetCategory being edited, or a fresh instance with defaults
    $parents  — root categories eligible as a parent (never the record itself)
--}}
@php
    /** @var \App\Models\AssetCategory $category */
    $hasChildren = $category->exists && $category->children()->exists();
@endphp

<x-form.fieldset legend="Details">
    <div class="row g-3">
        <div class="col-md-8">
            <x-form.input
                name="name"
                label="Category Name"
                :value="$category->name"
                placeholder="Laptop"
                autocomplete="off"
                help="For example Laptop, Monitor or Mobile Phone."
                required />
        </div>

        <div class="col-md-4">
            <x-form.input
                name="code"
                label="Code"
                :value="$category->code"
                autocomplete="off"
                maxlength="10"
                placeholder="LAP"
                help="Capitals and numbers only. Becomes part of every asset tag, e.g. AUM-LAP-0042."
                required />
        </div>
    </div>

    @if ($hasChildren)
        <div class="alert alert-secondary mb-0">
            <i class="bi bi-diagram-2" aria-hidden="true"></i>
            <div class="flex-grow-1">
                This is a top-level category with subcategories of its own, so it
                cannot be moved under another category.
            </div>
        </div>
    @else
        <x-form.select
            name="parent_id"
            label="Parent Category"
            placeholder="None — this is a top-level category"
            :selected="$category->parent_id"
            :options="$parents->pluck('name', 'id')->all()"
            help="Categories may be nested one level deep. Leave blank for a top-level category." />
    @endif
</x-form.fieldset>

<x-form.fieldset
    legend="Defaults for new assets"
    hint="Pre-filled when an asset of this type is added. Either can be overridden on the asset itself.">

    <div class="row g-3">
        <div class="col-md-6">
            <x-form.input
                name="default_warranty_months"
                label="Default Warranty (months)"
                type="number"
                min="1"
                max="600"
                :value="$category->default_warranty_months"
                placeholder="36"
                help="Pre-fills the warranty end date when an asset of this type is added." />
        </div>

        <div class="col-md-6">
            <x-form.input
                name="depreciation_years"
                label="Depreciation (years)"
                type="number"
                min="1"
                max="255"
                :value="$category->depreciation_years"
                placeholder="3"
                help="Recorded for reporting. Does not affect any calculation yet." />
        </div>
    </div>
</x-form.fieldset>

<x-form.fieldset legend="Availability">
    <x-form.checkbox
        name="is_active"
        label="Category is active"
        :checked="$category->is_active"
        help="Inactive categories keep their assets and history, but are not offered when adding a new asset." />
</x-form.fieldset>
