@extends('layouts.admin.theme')

@section('title', env('APP_NAME') . ' :: Editar Cadastro')

@section('content')
    <div class="container-fluid px-4">
        <div class="card shadow-lg my-4">
            @php
                $headLine = $tipo === 'candidato' ? __('Editar Candidato') : __('Editar Empresa');
            @endphp
            @include('components.buttons._headLineButtonsBackAdd', [
                'headLine' => $headLine,
                'routeBack' => 'admin.curriculos.listaCadastros',
                'routeBackParams' => $searchParams ?? [],
                'nameBack' => __('Voltar'),
                'permission' => 'GERENCIADOR_DE_CURRICULOS',
            ])

            <div class="card-body p-4">
                @include('errors.messageFlash')

                <form action="{{ route('admin.curriculos.updateCadastro', ['tipo' => $tipo, 'id' => $cadastro->id]) }}"
                    method="POST" class="needs-validation" novalidate>
                    @csrf
                    @method('PUT')
                    @if(isset($searchParams) && !empty($searchParams))
                        <input type="hidden" name="return_url" value="{{ route('admin.curriculos.listaCadastros', $searchParams) }}">
                    @endif

                    <div class="row">
                        @if ($tipo === 'candidato')
                            <div class="col-md-6">
                                <label for="name" class="form-label">Nome Completo</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="fa-solid fa-user"></i></span>
                                    <input type="text" name="name" id="name" class="form-control form-control-lg"
                                        value="{{ old('name', $cadastro->name) }}" required>
                                </div>
                                @error('name')
                                    <div class="invalid-feedback d-block">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-6">
                                <label for="cpf" class="form-label">CPF</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="fa-solid fa-address-card"></i></span>
                                    <input type="text" name="cpf" id="cpf"
                                        class="form-control form-control-lg cpf-mask"
                                        value="{{ old('cpf', $cadastro->cpf) }}" required>
                                </div>
                                @error('cpf')
                                    <div class="invalid-feedback d-block">{{ $message }}</div>
                                @enderror
                            </div>
                        @elseif ($tipo === 'empresa')
                            <div class="col-md-6">
                                <label for="corporate_name" class="form-label">Razão Social</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="fa-solid fa-building-user"></i></span>
                                    <input type="text" name="corporate_name" id="corporate_name"
                                        class="form-control form-control-lg"
                                        value="{{ old('corporate_name', $cadastro->corporate_name) }}" required>
                                </div>
                                @error('corporate_name')
                                    <div class="invalid-feedback d-block">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-6">
                                <label for="cnpj" class="form-label">CNPJ</label>
                                <div class="input-group">
                                    <span class="input-group-text"><i class="fa-solid fa-building"></i></span>
                                    <input type="text" name="cnpj" id="cnpj"
                                        class="form-control form-control-lg"
                                        value="{{ old('cnpj', $cadastro->cnpj) }}"
                                        placeholder="Apenas números"
                                        inputmode="numeric"
                                        pattern="[0-9]*"
                                        required>
                                </div>
                                @error('cnpj')
                                    <div class="invalid-feedback d-block">{{ $message }}</div>
                                @enderror
                            </div>
                        @endif

                        <div class="col-md-12">
                            <label for="email" class="form-label">E-mail</label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="fa-solid fa-envelope"></i></span>
                                <input type="email" name="email" id="email" class="form-control form-control-lg"
                                    value="{{ old('email', $cadastro->email) }}" required>
                            </div>
                            @error('email')
                                <div class="invalid-feedback d-block">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>

                    <div class="d-flex justify-content-end mt-4 gap-2">
                        <a href="{{ Route('admin.curriculos.listaCadastros') }}"
                            class="btn btn-outline-secondary btn-lg px-4">
                            <i class="bi bi-x-circle me-1"></i> Cancelar
                        </a>
                        <button type="submit" class="btn btn-primary btn-lg px-4">
                            <i class="bi bi-check-circle me-1"></i> Salvar Alterações
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
