@props([
    'action',
    'method' => 'POST',
    'region' => null,
    'countryOptions' => [],
    'submitLabel',
])

@php
    $names = is_array($region?->name) ? $region->name : [];
@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-6">
                    <x-ui.form.search-select
                        name="country_id"
                        lookup="countries"
                        :label="__('geography.fields.country')"
                        :options="$countryOptions"
                        :selected="old('country_id', $region?->country_id)"
                        :placeholder="__('geography.placeholders.country')"
                        required
                    />
                </div>
                <div class="col-md-3">
                    <x-ui.form.input
                        name="sort_order"
                        type="number"
                        min="0"
                        :label="__('geography.fields.sort_order')"
                        :value="old('sort_order', $region?->sort_order ?? 0)"
                    />
                </div>
                @if ($region !== null)
                    <div class="col-md-3">
                        <x-ui.form.select
                            name="is_active"
                            :label="__('geography.fields.status')"
                            :options="[
                                1 => __('geography.status.active'),
                                0 => __('geography.status.inactive'),
                            ]"
                            :selected="old('is_active', $region->is_active ? 1 : 0)"
                            required
                        />
                    </div>
                @endif
                <div class="col-md-6">
                    <x-ui.form.input
                        name="name_en"
                        :label="__('geography.fields.name_en')"
                        :value="old('name_en', $names['en'] ?? '')"
                        required
                    />
                </div>
                <div class="col-md-6">
                    <x-ui.form.input
                        name="name_ar"
                        :label="__('geography.fields.name_ar')"
                        :value="old('name_ar', $names['ar'] ?? '')"
                    />
                </div>
            </div>
        </div>
        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('settings.geography.regions.index')">
                {{ __('common.cancel') }}
            </x-ui.buttons.secondary>
            <x-ui.buttons.primary type="submit">{{ $submitLabel }}</x-ui.buttons.primary>
        </div>
    </div>
</form>
