@extends('layouts.admin.theme')

@section('title', env('APP_NAME') . ' :: Lista - Identificador de Usuarios')

@section('content')
<div class="card shadow-sm">
    <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
        <h5 class="my-2 ">Lista de Identificador de Usuarios</h5>
    </div>

    <div class="card-body">
        <div class="card-subtitle mt-4 text-body-secondary">
            @include('components.buttons._newButton', ['url' => 'admin.gerador-id.create', 'text' => 'Novo'])
            <button class="mobile-btn-atualizar btn btn-lg btn-primary d-inline text-white m-2"
                onclick="javascript:window.location.href='{{ route('admin.gerador-id.logs.logsUsuario') }}'">
                <i class="fa-solid fa-user-secret"></i> {{ __('Logs de Usuários') }}
            </button>
        </div>

        @include('errors.messageFlash')

        <div class="mt-4">
            <form method="GET" action="{{ route('admin.gerador-id.index') }}" class="mb-3">
                <div class="input-group">
                    <input type="text" name="busca" value="{{ request('busca') }}" class="form-control"
                        placeholder="Buscar ...">
                    <button class="btn btn-primary" type="submit">Buscar</button>
                    <a href="{{ route('admin.gerador-id.index') }}" class="btn btn-outline-secondary">Limpar</a>
                </div>
            </form>
        </div>

        <div class="table-responsive mt-5">
            <table class="table table-bordered table-hover table-striped align-middle text-center">
                @include('components.tables._thead', ['thead' => ['ID Gerado', 'Nome', 'CPF', 'N° Documento Sei', 'Ramal', 'Telefone', 'Status', 'link', '#']])
                <tbody>
                    @forelse($registros as $registro)
                    <tr class="{{ $registro->status == 1 ? 'table-secondary' : '' }}">
                        <td>{{ $registro->id_gerado }}</td>
                        <td>{{ $registro->nome_completo }}</td>
                        <td>{{ $registro->cpf }}</td>
                        <td>{{ $registro->doc_sei }}</td>
                        <td>{{ $registro->ramal }}</td>
                        <td>{{ $registro->telefone }}</td>
                        <td>{{ $registro->status == 0 ? 'Ativo' : 'Inativo' }}</td>
                        <td>
                            @if ($registro->link)
                            <a href="{{ $registro->link }}" target="_blank"
                                class="btn btn-sm btn-outline-primary" title="Abrir Link">
                                <i class="fas fa-link"></i>
                            </a>
                            @else
                            <span class="text-muted small">—</span>
                            @endif
                        </td>
                        <td class="text-center align-middle p-0">
                            <div class="d-flex justify-content-center align-items-center py-1">
                                <button class="btn btn-sm btn-primary me-2" data-bs-toggle="modal"
                                    data-bs-target="#modalEditar{{ $registro->id }}" title="Editar">
                                    <i class="fas fa-edit"></i>
                                </button>

                                <form action="{{ route('admin.gerador-id.toggleStatus', $registro->id) }}"
                                    method="POST" class="m-0">
                                    @csrf
                                    @method('PATCH')
                                    <button type="submit"
                                        class="btn btn-sm {{ $registro->status == 0 ? 'btn-danger' : 'btn-success' }}"
                                        title="{{ $registro->status == 0 ? 'Inativar' : 'Ativar' }}">
                                        <i
                                            class="fas {{ $registro->status == 0 ? 'fa-arrow-down' : 'fa-arrow-up' }}"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>

                    <div class="modal fade" id="modalEditar{{ $registro->id }}" tabindex="-1"
                        aria-labelledby="modalEditarLabel{{ $registro->id }}" aria-hidden="true">
                        <div class="modal-dialog modal-lg">
                            <div class="modal-content border-0 shadow-lg">
                                <form action="{{ route('admin.gerador-id.update', $registro->id) }}" method="POST"
                                    class="needs-validation" novalidate>
                                    @csrf
                                    @method('PUT')

                                    <div class="modal-header bg-primary text-white">
                                        <h5 class="modal-title" id="modalEditarLabel{{ $registro->id }}">Editar
                                            Identificador</h5>
                                        <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"
                                            aria-label="Fechar"></button>
                                    </div>

                                    <div class="modal-body">
                                        <div class="mb-4">
                                            <div class="d-flex align-items-center mb-3">
                                                <div class="bg-primary rounded-circle py-1 px-2 me-3">
                                                    <i class="fas fa-user text-white"></i>
                                                </div>
                                                <h5 class="mb-0 text-primary">Editar Identificação</h5>
                                            </div>
                                            <hr class="mt-0 mb-4">

                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-floating">
                                                        <input type="text" class="form-control"
                                                            name="nome_completo"
                                                            id="nome_completo_{{ $registro->id }}"
                                                            value="{{ $registro->nome_completo }}" placeholder=" "
                                                            required>
                                                        <label for="nome_completo_{{ $registro->id }}"
                                                            class="fw-semibold small">
                                                            <i class="fas fa-user me-1 text-muted"></i> Nome
                                                            Completo <span class="text-danger">*</span>
                                                        </label>
                                                    </div>
                                                </div>

                                                <div class="col-md-12 mt-3">
                                                    <div class="form-floating">
                                                        <input type="text" class="form-control" name="cpf"
                                                            id="cpf_{{ $registro->id }}"
                                                            value="{{ $registro->cpf }}" placeholder=" " required>
                                                        <label for="cpf_{{ $registro->id }}"
                                                            class="fw-semibold small">
                                                            <i class="fas fa-id-card me-1 text-muted"></i> CPF <span
                                                                class="text-danger">*</span>
                                                        </label>
                                                    </div>
                                                </div>

                                                <div class="col-md-12 mt-3">
                                                    <div class="form-floating">
                                                        <input type="text" class="form-control" name="doc_sei"
                                                            id="doc_sei_{{ $registro->id }}"
                                                            value="{{ $registro->doc_sei }}" placeholder=" "
                                                            required>
                                                        <label for="doc_sei_{{ $registro->id }}"
                                                            class="fw-semibold small">
                                                            <i class="fas fa-file-alt me-1 text-muted"></i> N°
                                                            Documento SEI <span class="text-danger">*</span>
                                                        </label>
                                                    </div>
                                                </div>

                                                <div class="col-md-6 mt-3">
                                                    <div class="form-floating">
                                                        <input type="text" class="form-control" name="ramal"
                                                            id="ramal_{{ $registro->id }}"
                                                            value="{{ $registro->ramal }}" placeholder=" ">
                                                        <label for="ramal_{{ $registro->id }}"
                                                            class="fw-semibold small">
                                                            <i class="fas fa-phone-office me-1 text-muted"></i>
                                                            Ramal
                                                        </label>
                                                    </div>
                                                </div>

                                                <div class="col-md-6 mt-3">
                                                    <div class="form-floating">
                                                        <input type="text" class="form-control"
                                                            name="telefone" id="telefone_{{ $registro->id }}"
                                                            value="{{ $registro->telefone }}" placeholder=" ">
                                                        <label for="telefone_{{ $registro->id }}"
                                                            class="fw-semibold small">
                                                            <i class="fas fa-mobile-alt me-1 text-muted"></i>
                                                            Telefone
                                                        </label>
                                                    </div>
                                                </div>

                                                <div class="col-md-12 mt-3">
                                                    <div class="form-floating">
                                                        <input type="url" class="form-control" name="link"
                                                            id="link_{{ $registro->id }}"
                                                            value="{{ $registro->link }}" placeholder=" ">
                                                        <label for="link_{{ $registro->id }}"
                                                            class="fw-semibold small">
                                                            <i class="fa-solid fa-link"></i> Link
                                                        </label>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="modal-footer bg-white border-top-0 py-3">
                                        <div class="d-flex justify-content-between w-100">
                                            <button type="button" class="btn btn-outline-secondary"
                                                data-bs-dismiss="modal">
                                                <i class="fas fa-times me-1"></i> Cancelar
                                            </button>
                                            <button type="submit" class="btn btn-primary px-4">
                                                <i class="fas fa-save me-1"></i> Salvar Alterações
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    @empty
                    <tr>
                        <td colspan="8">* Nenhum registro encontrado!</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        {{-- Paginação --}}
        <div class="d-flex justify-content-center mt-3">
            {!! $registros->links() !!}
        </div>
    </div>
</div>
@endsection
