@extends('layouts.app')

@section('title')
    {{ $pageInfo['title'] }}
@endsection


@section('admin-content')
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>{{ $pageInfo['title'] }}</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">{{ __('Dashboard') }}</a></li>
                        <li class="breadcrumb-item active"><a href="{{ $pageInfo['path'] }}">{{ $pageInfo['title'] }}</a>
                        </li>
                    </ol>
                </div>
            </div>
        </div>
    </section>

    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="header-title float-left">{{ $pageInfo['title'] }}</h4>
                            <div class="clearfix"></div>
                            <div class="data-tables">
                                @include('backend.layouts.partials.messages')
                                <div class="table-responsive">
                                    <table id="dataTable" class="text-center">
                                        <thead class="bg-light text-capitalize">
                                            <tr>
                                                <th width="5%">{{ __('User') }}</th>
                                                <th width="5%">{{ __('Ip Address') }}</th>
                                                <th width="5%">{{ __('Action') }}</th>
                                                <th width="15%">{{ __('Activity') }}</th>
                                                <th width="5%">Browser</th>
                                                <th width="15%">User Agent</th>
                                                <th width="5%">Tanggal</th>
                                                <th width="5%">Waktu</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($data as $item)
                                                <tr>
                                                    <td>
                                                        {{ $item->user ? $item->user->username : preg_replace('/\).*$/', '', explode('(', $item->activity)[1]) }}
                                                    </td>
                                                    <td>{{ $item->ip_address }}</td>
                                                    <td>
                                                        @php
                                                            $color = 'info';
                                                            if ($item->action == 'Create') {
                                                                $color = 'success';
                                                            } elseif ($item->action == 'Update') {
                                                                $color = 'warning';
                                                            } elseif ($item->action == 'Delete' || $item->action == 'Error') {
                                                                $color = 'danger';
                                                            }
                                                        @endphp
                                                        <div class="badge badge-{{ $color }} text-white">
                                                            {{ $item->action }}
                                                        </div>
                                                    </td>
                                                    <td>{{ $item->activity }}</td>
                                                    <td>{{ $item->browser }}</td>
                                                    <td>{{ $item->user_agent }}</td>
                                                    <td>{{ $item->created_at }}</td>
                                                    <td>{{ $item->created_at->diffForHumans() }}</td>
                                                </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

@section('scripts')
    <script>
        $(document).ready(function () {
            if ($('#dataTable').length) {
                $('#dataTable').DataTable({
                    responsive: false,
                    dom: 'Bfrtip',
                    buttons: [
                        'excel', 'pdf', 'print'
                    ],
                    order: [[6, 'desc']]
                });
            }
        });
    </script>
@endsection
