@extends('layouts.admin')

@section('content')
    <div class="card shadow mb-4">
        <div class="card-header py-3 d-flex">
            <h6 class="m-0 font-weight-bold text-success">
                Edit state: ({{ $city->name }})
            </h6>
            <div class="ml-auto">
                <a href="{{ route('admin.cities.index') }}" class="btn btn-success">
                    <span class="icon text-white-50">
                    </span>
                    <span class="text">Back to states</span>
                </a>
            </div>
        </div>
        <div class="card-body">
            <form action="{{ route('admin.cities.update', $city) }}" method="POST" enctype="multipart/form-data">
                @csrf
                @method('PATCH')
                <div class="row">
                    <div class="col-4">
                        <div class="form-group">
                            <label for="name">Name</label>
                            <input class="form-control" id="name" type="text" name="name" value="{{ old('name', $city->name) }}">
                            @error('name')<span class="text-danger">{{ $message }}</span>@enderror
                        </div>
                    </div>
                    <div class="col-4">
                        <div class="form-group">
                            <label for="state_id">State</label>
                            <select name="state_id" id="state_id" class="form-control">
                                <option value="">---</option>
                                @forelse($states as $state)
                                    <option value="{{ $state->id }}"
                                        {{ old('state_id', $city->state_id) == $state->id ? 'selected' : null }}>
                                        {{ $state->name }}
                                    </option>
                                @empty
                                @endforelse
                            </select>
                            @error('state_id')<span class="text-danger">{{ $message }}</span>@enderror
                        </div>
                    </div>
                    <div class="col-4">
                        <div class="form-group">
                            <label for="active">Status</label>
                            <select name="status" id="status" class="form-control">
                                <option value="1" {{ old('active', $city->active) == "Active" ? 'selected' : null }}>Active</option>
                                <option value="0" {{ old('active', $city->active) == "Inactive" ? 'selected' : null }}>Inactive</option>
                            </select>
                            @error('status')<span class="text-danger">{{ $message }}</span>@enderror
                        </div>
                    </div>
                </div>

                <div class="form-group pt-4">
                    <button class="btn btn-success" type="submit" name="submit">Update</button>
                </div>
            </form>
        </div>
    </div>
@endsection
