<div class="body-content">
    <div class="contacts">
        <div class="contacts-box">
            <div class="contacts-body">
                <div class="contacts-box">
                    <div class="contact-row p-0 border-0">
                        <div class="table-responsive">
                            <table class="table">
                                <thead>
                                <tr>
                                    <th scope="col">
                                        <div class="form-check">
                                            <input class="form-check-input custom-control-input" type="checkbox" name="example1" id="selectall">
                                            <label class="form-check-label" for="selectall">
                                                {{ __('employees.name') }}
                                            </label>
                                        </div>
                                    </th>
                                    <th scope="col"><i class="fal fa-envelope me-1"></i>  {{ __('employees.email') }} </th>
                                    <th scope="col"><i class="fal fa-phone me-1"></i> {{ __('employees.phone') }} </th>
                                    <th scope="col"><i class="fal fa-envelope me-1"></i> {{ __('users.role') }} </th>
                                    <th scope="col"><i class="fal fa-bolt me-1"></i> {{ __('employees.sector_id') }} </th>
                                    <th scope="col" colspan="2"><i class="fal fa-user me-1"></i> {{ __('dashboard.created_at') }} </th>
                                    <th></th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr class="search-tr">
                                    <td>
                                        <input type="text" name="name" value="{{ $request->name ?? '' }}" class="form-control" placeholder="Name">
                                    </td>
                                    <td>
                                        <input type="text" name="email" value="{{ $request->email ?? '' }}" class="form-control" placeholder="Company">
                                    </td>
                                    <td>
                                        <input type="text" name="phone" value="{{ $request->phone ?? '' }}" class="form-control" placeholder="Role">
                                    </td>
                                    <td>
                                        <select name="role" id="" class="form-control form-select">
                                            <option value="">{{__('dashboard.all')}}</option>
                                            @foreach($roles as $row)
                                                <option {{($request->role ?? '') == $row ? 'selected' : ''}} value="{{$row}}">{{__('users.roles.'.$row)}}</option>
                                            @endforeach
                                        </select>
                                    </td>
                                    <td>
                                        <select name="sector_id" id="" class="form-control form-select">
                                            <option value="">{{__('dashboard.all')}}</option>
                                            @foreach($sectors as $row)
                                                <option {{($request->sector_id ?? '') == $row->id ? 'selected' : ''}} value="{{$row->id}}">{{ $row->title }}</option>
                                            @endforeach
                                        </select>
                                    </td>
                                    <td>
                                        <input type="text" placeholder="{{ __('dashboard.date_from') }}" name="date_from" value="{{ $request->date_from ?? '' }}" class="date_from form-control">
                                    </td>
                                    <td>
                                        <input type="text" placeholder="{{ __('dashboard.date_to') }}" name="date_to" value="{{ $request->date_to ?? '' }}" class="date_to form-control">
                                    </td>
                                    <td>
                                        <button class="search-btn search"> <i class="fal fa-search"></i> </button>
                                    </td>
                                </tr>
                                @foreach($users as $row)
                                    <tr>
                                        <td>
                                            <div class="form-check d-flex align-items-center">
                                                <input class="form-check-input custom-control-input selectOne deleteCheck" name="id[]" type="checkbox" value="{{$row->id}}" id="customCheck{{$row->id}}">
                                                <label class="form-check-label" for="customCheck{{$row->id}}">
                                                    <div class="main-inf">
                                                        <h6 class="com-name"> {{$row->name}} </h6>
                                                    </div>
                                                </label>
                                            </div>
                                        </td>
                                        <td> <div class="text"> {{$row->email}} </div> </td>
                                        <td> <a href="tel:{{$row->phone}}" class="text"> {{$row->phone}} </a> </td>
                                        <td> <div class="text"> {{__('users.roles.'.$row->role)}} </td>
                                        <td> <div class="text sector_txt" style="white-space: normal; ">
                                                @foreach($row->sectors as $keySector=>$sector)
                                                    {{ $sector->sector->currentDescription->title }}
                                                    @if (count($row->sectors) != $keySector + 1)
                                                        ,
                                            @endif
                                            @endforeach
                                        </td>
                                        <td colspan="2"> <div class="text"> {{ \Carbon\Carbon::parse($row->created_at)->format('Y/m/d') }} </td>
                                        <td>
                                            <div class="dropdown">
                                                <button class="btn bg-transparent border-0 p-0 dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                                    <i class="fas fa-ellipsis"></i>
                                                </button>
                                                <ul class="dropdown-menu">
                                                    @if(auth()->user()->canAccess('employees','target'))
                                                        <a href="{{route('targets.index','employee='.$row->name)}}" action="" class="dropdown-item" title="{{ __('employees.all_target') }}">  {{ __('employees.all_target') }} </a>
                                                    @endif
                                                    @if(auth()->user()->canAccess('deals','index'))
                                                        <a href="{{route('deals.index').'?employee='.$row->name}}" class="dropdown-item" title="{{ __('dashboard.edit') }}">  {{ __('deals.head') }} </a>
                                                    @endif
                                                    @if(auth()->user()->canAccess('employees','update'))
                                                        <a href="#0" onclick="openModel(this)" action="{{ route ('employees.edit', $row->id) }}" class="dropdown-item" title="{{ __('dashboard.edit') }}"> <i class="bi bi-pen ml-1"></i> {{ __('dashboard.edit') }} </a>
                                                    @endif
                                                    @if(auth()->user()->canAccess('employees','delete'))
                                                        @if($row->deleted_at ?? null)
                                                            <a href="{{ route ('employees.restore', $row->id) }}" data-method="put" class="dropdown-item rowAction" title="{{ __('dashboard.restore') }}"> <i class="bi bi-pen ml-1"></i> {{ __('dashboard.restore') }} </a>
                                                        @else
                                                            <a href="{{ route ('employees.destroy', $row->id) }}" data-method="delete" class="dropdown-item rowAction" title="{{ __('dashboard.trash') }}"> <i class="bi bi-slash-circle ml-1"></i> {{ __('dashboard.trash') }} </a>
                                                        @endif
                                                    @endif
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach

                                @if( count( $users ) && $users->hasPages() )
                                    <tr> <td> {{ $users->links() }} </td> </tr>
                                @endif
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="{{url('')}}/assets/admin/js/related.js"></script>
