@extends('layouts.arte-sacra.theme')

@section('title', env('APP_NAME') . ' :: Editar Usuário')

@section('content')

    <div class="container my-5 py-5">
        <div class="row justify-content-center">
            <div class="col-lg-8 col-xl-6">
                <form id="editForm" action="{{ route('paginas.cultura.arteSacra.edit.update', $user->id) }}" method="post"
                    enctype="multipart/form-data" class="needs-validation" novalidate>
                    <div class="card shadow-lg border-0 rounded-4">
                        <div class="card-body p-5" style="background-color: #f8f9fa;">
                            <h2 class="mb-4 text-center text-dark fw-bold" style="font-family: 'Georgia', serif;">
                                Editar Usuário 
                            </h2>

                            @csrf
                            @method('PUT')

                            @include('errors.messageFlash')

                            <input type="hidden" name="redirect_to" value="{{ old('redirect_to', request('redirect_to', route('paginas.cultura.arteSacra.index'))) }}">

                            <div class="mb-4">
                                <label for="firstName" class="form-label fw-semibold">Nome <span class="text-danger">*</span></label>
                                <input type="text" class="form-control rounded-3 @error('firstName') is-invalid @enderror"
                                    name="firstName" id="firstName" value="{{ old('firstName', $user->firstName) }}" autocomplete="off">
                                @error('firstName')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="mb-4">
                                <label for="lastName" class="form-label fw-semibold">Sobrenome <span class="text-danger">*</span></label>
                                <input type="text" class="form-control rounded-3 @error('lastName') is-invalid @enderror"
                                    name="lastName" id="lastName" value="{{ old('lastName', $user->lastName) }}" autocomplete="off">
                                @error('lastName')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="mb-4">
                                <label for="cpf" class="form-label fw-semibold">CPF <span class="text-danger">*</span></label>
                                <input type="text" class="form-control rounded-3 bg-light @error('cpf') is-invalid @enderror"
                                    name="cpf" id="cpf" value="{{ old('cpf', $user->cpf) }}" readonly>
                                @error('cpf')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="mb-4">
                                <label for="phoneNumber" class="form-label fw-semibold">Telefone <span class="text-danger">*</span></label>
                                <input type="text" class="form-control rounded-3 @error('phoneNumber') is-invalid @enderror"
                                    name="phoneNumber" id="phoneNumber" value="{{ old('phoneNumber', $user->phoneNumber) }}" autocomplete="off">
                                @error('phoneNumber')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="mb-4">
                                <label for="email" class="form-label fw-semibold">Email <span class="text-danger">*</span></label>
                                <input type="email" class="form-control rounded-3 bg-light @error('email') is-invalid @enderror"
                                    name="email" id="email" value="{{ old('email', $user->email) }}" readonly>
                                @error('email')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="mb-4">
                                <label for="photo" class="form-label fw-semibold">Foto</label>
                                <input type="file" class="form-control rounded-3" name="photo" id="photo"
                                    accept="image/jpeg,image/jpg,image/png,image/gif" />

                                @if(auth()->user()->photo)
                                    <div class="mt-3 text-center">
                                        <img src="{{ asset(auth()->user()->photo) }}" alt="Foto do Usuário"
                                            class="img-thumbnail rounded-circle border border-secondary shadow"
                                            style="max-width: 120px;">
                                    </div>
                                @endif
                            </div>

                            <div class="d-flex justify-content-between mt-4">
                                <button type="button" class="btn btn-outline-secondary btn-lg rounded-3"
                                    onclick="window.location.href='{{ url()->previous() }}'">
                                    ← Voltar
                                </button>
                                <button type="submit" class="btn btn-primary btn-lg rounded-3 px-4">
                                    Atualizar
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

@endsection
