@extends('layouts.admin')

@push('css')
<link href="{{ asset('vendors/daterangepicker/daterangepicker.css') }}" rel="stylesheet" type="text/css">
@endpush

@push('js')
<script src="{{ asset('vendors/moment/min/moment-with-locales.min.js') }}"></script>
<script src="{{ asset('vendors/daterangepicker/daterangepicker.js') }}"></script>
<script src="{{ asset('js/admin/auditoria/index.js') }}"></script>
@endpush

@section('content')
<!-- Breadcrumb -->
<nav class="hk-breadcrumb" aria-label="breadcrumb">
    <ol class="breadcrumb breadcrumb-light bg-transparent">
        <li class="breadcrumb-item active" aria-current="page">Logs de Auditoria</li>
    </ol>
</nav>
<!-- /Breadcrumb -->
<div class="container">
    <!-- Title -->
    <div class="hk-pg-header">
        <h4 class="hk-pg-title"><span class="pg-title-icon"><span class="feather-icon"><i data-feather="align-left"></i></span></span>
            Logs de Auditoria
        </h4>
    </div>
    <!-- /Title -->
    <div class="row">
        <div class="col-xl-12">
            <section class="hk-sec-wrapper">
                @alerts
                @endalerts

                <form>
                    <div class="row">
                        <div class="col">
                            <div class="form-inline float-right mx-2">
                                <button class="btn btn-outline-primary" type="submit">Filtrar</button>
                                <button id="btn-limpar" class="btn btn-outline-secondary mx-1" type="button">Limpar</button>
                            </div>
                            <div class="form-inline float-right mx-2">
                                <label for="evento" class="mr-1">Evento</label>
                                <select name="evento" class="form-control">
                                    <option value="">Todos</option>
                                    <option value="created" {{ $evento == 'created' ? 'selected' : '' }}>Inclusão</option>
                                    <option value="updated" {{ $evento == 'updated' ? 'selected' : '' }}>Edição</option>
                                    <option value="deleted" {{ $evento == 'deleted' ? 'selected' : '' }}>Exclusão</option>
                                </select>
                            </div>
                            <div class="form-inline float-right mx-2">
                                <label for="intervalo" class="mr-1">Intervalo</label>
                                <input type="text" autocomplete="off" value="{{ $intervalo }}" name="intervalo" class="form-control intervalo @error('intervalo') is-invalid @enderror" value="{{ old('vencimento') }}">
                            </div>
                        </div>
                    </div>
                </form>

                <table class="table mt-3">
                    <thead>
                        <tr>
                            <th>Data/hora</th>
                            <th>Tipo</th>
                            <th>Objeto</th>
                            <th>Evento</th>
                            <th>Usuário</th>
                            <th class="w-25">Ação</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($logs as $log)
                        <tr>
                            <td>
                                {{ $log->created_at->format('d/m/Y H:i:s') }}
                            </td>
                            <td>
                                {{ $log->auditable_type_readable }}
                            </td>
                            <td>
                                {{ str_limit($log->description, 50) }}
                            </td>
                            <td>
                                {{ Str::ucfirst($log->event_readable) }}
                            </td>
                            <td>
                                {{ $log->user->name }}
                            </td>
                            <td>
                                @button([
                                'route' => 'admin.auditoria.show',
                                'routeParams' => ['log' => $log],
                                'class' => 'btn-primary',
                                'label' => 'Detalhes',
                                'icon' => 'eye'
                                ])
                                @endbutton
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
                {{ $logs->links() }}
            </section>
        </div>
    </div>
</div>
@endsection