@extends('admin.layouts.app')

@section('title', 'Users')

@section('content')

@if (session('user_create_message'))
<div class="alert alert-success mb-2">
    {{ session('user_create_message') }}
</div>

@elseif (session('delete_user_msg'))
<div class="alert alert-success mb-2">
    {{ session('delete_user_msg') }}
</div>
@endif

<h1 class="mb-3">{{ awtTrans('الاعضاء') }}</h1>

<form action="{{ route('admin.user.bluck-delete') }}" method="post">
    @csrf
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary text-left">
                <button type="submit" style="display: none;" title="{{ awtTrans('delete') }}" class="btn btn-danger bluck-button btn-circle btn-sm">
                    <i class="fas fa-trash"></i>
                </button>
                <a href="{{ route('admin.users.create') }}" title="{{ awtTrans('add') }}" class="btn btn-primary btn-circle btn-sm">
                    <i class="fas fa-plus"></i>
                </a>
            </h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTableUsers" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>{{ awtTrans('Choose') }} </th>
                            <th>{{ awtTrans('Name Arabic') }} </th>
                            <th>{{ awtTrans('Name English') }} </th>
                            <th>{{ awtTrans('Job Title Arabic') }} </th>
                            <th>{{ awtTrans('Job Title English') }} </th>
                            <th>{{ awtTrans('Created At') }} </th>
                            <th>{{ awtTrans('Actions') }} </th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                        <th>{{ awtTrans('Choose') }} </th>
                            <th>{{ awtTrans('Name Arabic') }} </th>
                            <th>{{ awtTrans('Name English') }} </th>
                            <th>{{ awtTrans('Job Title Arabic') }} </th>
                            <th>{{ awtTrans('Job Title English') }} </th>
                            <th>{{ awtTrans('Created At') }} </th>
                            <th>{{ awtTrans('Actions') }} </th>
                        </tr>
                    </tfoot>
                    <tbody>
                        @if (! empty($users))
                        @foreach ($users as $user)
                        <tr id="row-{{ $user->id }}">
                            <td><input type="checkbox" name="ids[]" value="{{ $user->id }}" class="from-control bluck-delete"> </td>
                            <td>{{ $user->name_ar }}</td>
                            <td>{{ $user->name_en }}</td>
                            <td>{{ $user->job_title_ar }}</td>
                            <td>{{ $user->job_title_en }}</td>

                            <td>{{ $user->created_at->diffForHumans() }}</td>

                            <td>
                                <a href="{{ route('admin.users.destroy', $user->id) }}" data-id="{{$user->id}}" class="btn btn-danger btn-circle btn-sm item-delete">
                                    <i class="fas fa-trash"></i>
                                </a>

                                <a href="{{ route('admin.users.edit', $user->id) }}" class="btn btn-success btn-circle btn-sm">
                                    <i class="fas fa-edit"></i>
                                </a>
                            </td>

                        </tr>


                        @endforeach
                        @endif
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</form>

@endsection


@section('scripts')
<script>
    // Call the dataTables jQuery plugin
    $(document).ready(function() {
        $('#dataTableUsers').DataTable({
            'language': {
                'url': "{{ app()->getLocale() == 'ar' ? 'https://cdn.datatables.net/plug-ins/1.10.12/i18n/Arabic.json' : 'https://cdn.datatables.net/plug-ins/1.10.12/i18n/English.json' }}",
            },
        });
    });
</script>
@endsection