@extends('admin.layouts.layout')

@section('content')
<div class="row match-height">
    <div class="col-md-12 col-12">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title text-primary">Editando Agente Político</h4>
                <p class="text-muted">Editando Agente Político no Sistema</p>
                <a class="btn btn-outline-primary btn-block" href="{{ route('agentespoliticos.index') }}">Ver todos</a>
            </div>
            <div class="card-body">
                <form action="{{ route('agentespoliticos.update', $agentespoliticos->id) }}" method="POST" enctype="multipart/form-data">
                    @method('PUT')
                    @csrf

                    <div class="form-group">
                        <label for="nome">Nome <span>*</span></label>
                        <input type="text" name="nome" value="{{ old('nome', $agentespoliticos->nome) }}" class="form-control @error('nome') is-invalid @enderror">
                        @error('nome') <div class="text-danger">{{ $message }}</div> @enderror
                    </div>

                    <div class="form-group">
                        <label for="id_cargo">Cargo</label>
                        <select name="id_cargo" class="form-control @error('id_cargo') is-invalid @enderror">
                            @foreach ($cargos as $cargo)
                                <option value="{{ $cargo->id }}" @if (old('id_cargo', $agentespoliticos->id_cargo) == $cargo->id) selected @endif>
                                    {{ $cargo->descricao }}
                                </option>
                            @endforeach
                        </select>
                        @error('id_cargo') <div class="text-danger">{{ $message }}</div> @enderror
                    </div>

                    <div class="form-group">
                        <label for="foto">Foto Atual</label>
                        @if($agentespoliticos->foto)
                            <div class="mb-2">
                                <img src="{{ asset('storage/' . $agentespoliticos->foto) }}" alt="Foto do Agente" class="img-thumbnail" width="150">
                            </div>
                        @endif
                        <input type="file" name="foto" class="form-control @error('foto') is-invalid @enderror">
                        @error('foto') <div class="text-danger">{{ $message }}</div> @enderror
                    </div>

                    <div class="form-group">
                        <label for="telefone">Telefone</label>
                        <input type="text" name="telefone" value="{{ old('telefone', $agentespoliticos->telefone) }}" class="form-control @error('telefone') is-invalid @enderror">
                        @error('telefone') <div class="text-danger">{{ $message }}</div> @enderror
                    </div>

                    <div class="form-group">
                        <label for="email">E-mail</label>
                        <input type="email" name="email" value="{{ old('email', $agentespoliticos->email) }}" class="form-control @error('email') is-invalid @enderror">
                        @error('email') <div class="text-danger">{{ $message }}</div> @enderror
                    </div>

                    <div class="form-group">
                        <label>Status</label><br>
                        <label><input type="radio" name="status" value="S" @if(old('status', $agentespoliticos->status) == 'S') checked @endif> Sim</label>
                        <label><input type="radio" name="status" value="N" @if(old('status', $agentespoliticos->status) == 'N') checked @endif> Não</label>
                        @error('status') <div class="text-danger">{{ $message }}</div> @enderror
                    </div>

                    <button type="submit" class="btn btn-success btn-block">Salvar Alterações</button>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
