@extends('backend.layouts.app')

@section('title', __('User Management'))



@section('content')
    <div class="card user-screen">
        <div class="card-body">
            <div class="text-center">
                <h3 class="card-title font-weight-bold">{{ __('string.user.search.title') }}</h3>
                <p>{{ __('string.user.search.description') }}</p>
            </div><!--col-->
            <div class="row mt-4">
                <div class="col">
                    {!! Form::open(['route' => 'admin.user.index', 'method' => 'get', 'id' => 'form-search-user',
                        'class' => 'mb-3'])
                    !!}
                        <div class="d-flex">
                                {!! Form::text('user_name', request()->get('user_name'),
                    ['class'=>'form-control input-control', 'placeholder'=>__('string.user.search.placeholder')]) !!}
                            <!-- {!! Form::text(
                                'classification_search',
                                request()->get('classification_search'),
                                ['class'=>'form-control input-control', 'placeholder'=>__('string.classification.search.placeholder')]
                            ) !!} -->
                            {!! Form::button( __('string.user.button.search'),
                            ['class' => 'btn btn-success ml-3 search-user']) !!}
                        </div>
                    <span class="error-search text-red"></span>
                    {!! Form::close() !!}
                    <div class="table-responsive {{!empty($users) && $users->count() > 10 ? 'scroll' : ''}}">
                        <table class="table" aria-label="list-user">
                            <thead>
                            <tr>
                                <th scope="col" class="w-20">
                                    <a href="{{ route('admin.user.index', [
                                        'user_name' => request()->get('user_name'),
                                        'classification_search' => request()->get('classification_search'),
                                        'id' => !empty($params['id']) && $params['id'] == 'asc' ? 'desc' : 'asc'
                                        ]) }}"
                                    >
                                        {{ __('string.user.table.id') }}
                                        @if (empty(request()->get('name')) and empty(request()->get('classification')))
                                            <em class="{{ setIconSort($params['id']) }}"></em>
                                        @endif
                                    </a>
                                </th>
                                <th scope="col" class="w-30">
                                    <a href="{{ route('admin.user.index', [
                                        'user_name' => request()->get('user_name'),
                                        'classification_search' => request()->get('classification_search'),
                                        'name' => !empty($params['name']) && $params['name'] == 'asc' ? 'desc' : 'asc'
                                        ]) }}"
                                    >
                                        {{ __('string.user.table.name') }}
                                        @if (!empty(request()->get('name')))
                                            <em class="{{ setIconSort($params['name']) }}"></em>
                                        @endif
                                    </a>
                                </th>
                                <th scope="col" class="w-30">
                                    <a href="{{ route('admin.user.index', [
                                        'user_name' => request()->get('user_name'),
                                        'classification_search' => request()->get('classification_search'),
                                        'classification' => !empty($params['classification']) && $params['classification'] == 'asc' ? 'desc' : 'asc'
                                        ]) }}"
                                    >
                                        <!-- {{ __('string.user.table.classification') }}
                                        @if (!empty(request()->get('classification')))
                                            <em class="{{ setIconSort($params['classification']) }}"></em>
                                        @endif -->
                                    </a>
                                </th>
                                <th scope="col" class="text-center">{{ __('string.user.table.menu') }}</th>
                            </tr>
                            </thead>
                            <tbody>
                                @forelse($users as $user)
                                    <tr>
                                        <td>{{ $user->username }}</td>
                                        <td>{{ $user->name }}</td>
                                        <td>{{ $user->classification }}</td>
                                        <td class="text-center">
                                            <div class="btn-group">
                                                @if (($user->id == auth()->id()) || auth()->user()->isAdmin)
                                                <a href="{{ route('admin.checkin.history', ['user' => $user->id]) }}"
                                                    class="btn btn-secondary btn-sm">
                                                    {{ __('string.user.button.history') }}
                                                </a>
                                                @endif
                                                @role(config('boilerplate.access.role.admin'))
                                                <button type="button"
                                                class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split"
                                                        data-toggle="dropdown"
                                                        aria-expanded="false">
                                                </button>
                                                <div class="dropdown-menu">
                                                    @if (Storage::disk('public')->exists('images/face-capture/' . $user->id . '/center.png')
                                                        and Storage::disk('public')->exists('images/face-capture/' . $user->id . '/left.png')
                                                        and Storage::disk('public')->exists('images/face-capture/' . $user->id . '/right.png') )
                                                        <a href="{{
                                                                route('admin.user.capture-face.form', ['user' => $user->id])
                                                            }}"
                                                            class="dropdown-item btn btn-dark btn-sm">
                                                            {{ __('string.user.button.camera') }}
                                                        </a>
                                                    @endif
                                                    <a href="{{ route('admin.user.edit', ['user' => $user->id])}}"
                                                       class="dropdown-item btn btn-primary btn-sm">
                                                        {{ __('string.user.button.edit') }}
                                                    </a>
                                                    <button type="submit"
                                                            class="dropdown-item btn btn-danger btn-sm btn-delete-user"
                                                            data-id="{{ $user->id }}"
                                                            data-name="{{ $user->name }}"
                                                            data-username="{{ $user->username }}"
                                                            data-toggle="modal" data-target="#modalDeleteUser">
                                                        {{ __('string.user.button.delete') }}
                                                    </button>
                                                </div>
                                                @else
                                                    @if($user->id == auth()->id())
                                                        <button type="button"
                                                        class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split"
                                                                data-toggle="dropdown"
                                                                aria-expanded="false">
                                                        </button>
                                                        <div class="dropdown-menu">
                                                            <a href="{{
                                                                    route('admin.user.capture-face.form', ['user' => $user->id])
                                                                }}"
                                                                class="dropdown-item btn btn-dark btn-sm">
                                                                {{ __('string.user.button.camera') }}
                                                            </a>
                                                        </div>
                                                    @endif
                                                @endrole
                                            </div>
                                        </td>
                                    </tr>
                                @empty
                                    <tr class="text-center">
                                        <td colspan="3">{{ __('string.user.search.no_data') }}</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                    <!-- @role(config('boilerplate.access.role.admin'))
                        <div class="text-right">
                            <a href='{{ route('admin.user.create') }}' class="btn btn-success btn-md">
                                <em class="fas fa-plus"></em> {{ __('string.user.button.add') }}
                            </a>
                        </div>
                    @endrole -->
                </div><!--col-->
            </div><!--row-->
        </div><!--card-body-->
    </div><!--card-->
    @include('backend.user.modal_delete')
@endsection

@push('after-scripts')
    <script src="{{ mix('js/user.js') }}"></script>
@endpush
