@php $pool = $pool ?? null; @endphp
<div class="row g-3">
    <div class="col-md-6">
        <label class="form-label">{{ __('admin/ip_pools.field_name') }} <span class="text-danger">*</span></label>
        <input type="text" name="name" class="form-control @error('name') is-invalid @enderror"
               value="{{ old('name', $pool->name ?? '') }}">
        @error('name') <div class="invalid-feedback">{{ $message }}</div> @enderror
    </div>

    <div class="col-md-6">
        <label class="form-label">{{ __('admin/ip_pools.field_server') }} <span class="text-danger">*</span></label>
        <select name="server_id" class="form-select @error('server_id') is-invalid @enderror"
                @if($mode === 'edit') disabled @endif>
            <option value="">{{ __('admin/common.select') }}</option>
            @foreach($servers as $s)
                <option value="{{ $s->id }}" @selected(old('server_id', $pool->server_id ?? '') == $s->id)>{{ $s->name }}</option>
            @endforeach
        </select>
        @error('server_id') <div class="invalid-feedback">{{ $message }}</div> @enderror
    </div>

    @if($mode === 'create')
    <div class="col-md-6">
        <label class="form-label">{{ __('admin/ip_pools.field_cidr') }} <span class="text-danger">*</span></label>
        <input type="text" name="cidr" id="cidr" placeholder="10.0.0.0/24"
               class="form-control @error('cidr') is-invalid @enderror" value="{{ old('cidr') }}">
        @error('cidr') <div class="invalid-feedback">{{ $message }}</div> @enderror
        <div class="form-text small">{{ __('admin/ip_pools.field_cidr_help') }}</div>
        <div id="cidr-preview" class="form-text small text-info"></div>
    </div>
    @endif

    <div class="col-md-6">
        <label class="form-label">{{ __('admin/ip_pools.field_gateway') }}</label>
        <input type="text" name="gateway" class="form-control" value="{{ old('gateway', $pool->gateway ?? '') }}">
    </div>

    <div class="col-md-4">
        <label class="form-label">{{ __('admin/ip_pools.field_allocator') }} <span class="text-danger">*</span></label>
        <select name="allocator" class="form-select">
            <option value="sequential" @selected(old('allocator', $pool->allocator ?? 'sequential') === 'sequential')>{{ __('admin/ip_pools.allocator_sequential') }}</option>
            <option value="random" @selected(old('allocator', $pool->allocator ?? 'sequential') === 'random')>{{ __('admin/ip_pools.allocator_random') }}</option>
        </select>
    </div>

    <div class="col-md-4">
        <label class="form-label">{{ __('admin/ip_pools.field_quarantine_days') }} <span class="text-danger">*</span></label>
        <input type="number" name="quarantine_days" min="0" max="365"
               class="form-control" value="{{ old('quarantine_days', $pool->quarantine_days ?? 7) }}">
    </div>

    <div class="col-md-4 d-flex align-items-end">
        <div class="form-check form-switch">
            <input type="hidden" name="is_default" value="0">
            <input type="checkbox" name="is_default" value="1" id="is_default" class="form-check-input"
                   @checked(old('is_default', $pool->is_default ?? false))>
            <label for="is_default" class="form-check-label">{{ __('admin/ip_pools.field_is_default') }}</label>
        </div>
    </div>

    <div class="col-md-4 d-flex align-items-end">
        <div class="form-check form-switch">
            <input type="hidden" name="is_active" value="0">
            <input type="checkbox" name="is_active" value="1" id="is_active" class="form-check-input"
                   @checked(old('is_active', $pool->is_active ?? true))>
            <label for="is_active" class="form-check-label">{{ __('admin/ip_pools.field_is_active') }}</label>
        </div>
    </div>

    @if($mode === 'create')
    <div class="col-md-8 d-flex align-items-end">
        <div class="form-check form-switch">
            <input type="hidden" name="auto_import" value="0">
            <input type="checkbox" name="auto_import" value="1" id="auto_import" class="form-check-input" @checked(old('auto_import', true))>
            <label for="auto_import" class="form-check-label">{{ __('admin/ip_pools.field_auto_import') }}</label>
        </div>
    </div>
    @endif

    <div class="col-12">
        <label class="form-label">{{ __('admin/ip_pools.field_notes') }}</label>
        <textarea name="notes" rows="2" class="form-control">{{ old('notes', $pool->notes ?? '') }}</textarea>
    </div>
</div>
