@extends('layouts.app')

@section('content')
    <div class="row justify-content-center">
        <div class="col-lg-6">
            <div class="card shadow-sm">
                <div class="card-header fw-bold">Edit City</div>
                <div class="card-body">
                    <form method="POST" action="{{ route('cities.update', $city) }}" class="row g-2">
                        @csrf
                        @method('PUT')
                        <div class="col-12">
                            <label class="form-label">Country</label>
                            <select name="country_id" class="form-select" required>
                                @foreach($countries as $c)
                                    <option value="{{ $c->id }}" {{ (string) old('country_id', $city->country_id) === (string) $c->id ? 'selected' : '' }}>
                                        {{ $c->name }} ({{ optional($c->parentContinent)->name ?: $c->continent }})
                                    </option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-12">
                            <label class="form-label">City name</label>
                            <input name="name" class="form-control" required maxlength="255" value="{{ old('name', $city->name) }}">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Status</label>
                            <select name="status" class="form-select">
                                <option value="1" {{ old('status', $city->status) ? 'selected' : '' }}>Active</option>
                                <option value="0" {{ !old('status', $city->status) ? 'selected' : '' }}>Inactive</option>
                            </select>
                        </div>
                        <div class="col-12 d-flex gap-2">
                            <button class="btn btn-primary">Update</button>
                            <a href="{{ route('cities.index') }}" class="btn btn-outline-secondary">Back</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
