<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 class="column_name">
                                        <div class="header-content" >
                                            <input class="form-check-input custom-control-input" type="checkbox" name="example1" style="border-radius:15px" id="selectall">
                                            <label class="form-check-label" for='selectall'>{{ __('employees.name') }}</label>
                                            <div class="header-actions" data-field="name">
                                                <button class="arrow-btn" title="{{ __('dashboard.sort_desc') }}">▾</button>
                                                <button class="dots-btn">⋮</button>
                                                <div class="dropdown-filter">
                                                    <ul>
                                                        <li data-order="ASC">{{ __('dashboard.sort_asc') }}</li>
                                                        <li data-order="DESC">{{ __('dashboard.sort_desc') }}</li>
                                                        <li data-order="reset">{{ __('dashboard.reset') }}</li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </th>
                                    <th  class="column_email">
                                        <div class="header-content" >
                                            <span>{{ __('employees.email') }}</span>
                                            <div class="header-actions" data-field="email">
                                                <button class="arrow-btn" title="{{ __('dashboard.sort_desc') }}">▾</button>
                                                <button class="dots-btn">⋮</button>
                                                <div class="dropdown-filter">
                                                    <ul>
                                                        <li data-order="ASC">{{ __('dashboard.sort_asc') }}</li>
                                                        <li data-order="DESC">{{ __('dashboard.sort_desc') }}</li>
                                                        <li data-order="reset">{{ __('dashboard.reset') }}</li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </th>
                                    <th class="column_phone">
                                        <div class="header-content" >
                                            <span>{{ __('employees.phone') }}</span>
                                            <div class="header-actions" data-field="phone">
                                                <button class="arrow-btn" title="{{ __('dashboard.sort_desc') }}">▾</button>
                                                <button class="dots-btn">⋮</button>
                                                <div class="dropdown-filter">
                                                    <ul>
                                                        <li data-order="ASC">{{ __('dashboard.sort_asc') }}</li>
                                                        <li data-order="DESC">{{ __('dashboard.sort_desc') }}</li>
                                                        <li data-order="reset">{{ __('dashboard.reset') }}</li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </th>
                                    <th class="column_role">
                                        <div class="header-content" >
                                            <span>{{ __('users.role') }}</span>
                                            <div class="header-actions" data-field="role">
                                                <button class="arrow-btn" title="{{ __('dashboard.sort_desc') }}">▾</button>
                                                <button class="dots-btn">⋮</button>
                                                <div class="dropdown-filter">
                                                    <ul>
                                                        <li data-order="ASC">{{ __('dashboard.sort_asc') }}</li>
                                                        <li data-order="DESC">{{ __('dashboard.sort_desc') }}</li>
                                                        <li data-order="reset">{{ __('dashboard.reset') }}</li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </th>
                                    <th  class="column_sector_id">
                                        <div class="header-content" >
                                            <span>{{ __('employees.sector_id') }}</span>

                                        </div>
                                    </th>
                                    <th colspan="2" class="column_created_at">
                                        <div class="header-content" >
                                            <span>{{ __('dashboard.created_at') }}</span>
                                            <div class="header-actions" data-field="created_at">
                                                <button class="arrow-btn" title="{{ __('dashboard.sort_desc') }}">▾</button>
                                                <button class="dots-btn">⋮</button>
                                                <div class="dropdown-filter">
                                                    <ul>
                                                        <li data-order="ASC">{{ __('dashboard.sort_asc') }}</li>
                                                        <li data-order="DESC">{{ __('dashboard.sort_desc') }}</li>
                                                        <li data-order="reset">{{ __('dashboard.reset') }}</li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </th>
                                    <th>
                                        <div class="header">
                                            <button class="dots-btn">⋮</button>
                                            <div class="dropdown-columns">
                                                <ul>
                                                    <li ><input type="checkbox" class="hidden_column" {{ auth()->user()->disabledColumn('name','employees') ? 'checked' : '' }} onclick="ToggleItem(this)" data-module="employees" data-column="name" >{{__('users.name')}}</li>
                                                    <li ><input type="checkbox" class="hidden_column" {{ auth()->user()->disabledColumn('email','employees') ? 'checked' : '' }} onclick="ToggleItem(this)" data-module="employees" data-column="email" >{{ __('users.email') }}</li>
                                                    <li ><input type="checkbox" class="hidden_column" {{ auth()->user()->disabledColumn('phone','employees') ? 'checked' : '' }} onclick="ToggleItem(this)" data-module="employees" data-column="phone" >{{ __('users.phone') }}</li>
                                                    <li ><input type="checkbox" class="hidden_column" {{ auth()->user()->disabledColumn('role','employees') ? 'checked' : '' }} onclick="ToggleItem(this)" data-module="employees" data-column="role" >{{ __('users.role') }}</li>
                                                    <li ><input type="checkbox" class="hidden_column" {{ auth()->user()->disabledColumn('sector_id','employees') ? 'checked' : '' }} onclick="ToggleItem(this)" data-module="employees" data-column="sector_id" >{{ __('employees.sector_id') }}</li>
                                                    <li ><input type="checkbox" class="hidden_column" {{ auth()->user()->disabledColumn('created_at','employees') ? 'checked' : '' }} onclick="ToggleItem(this)" data-module="employees" data-column="created_at" >{{ __('dashboard.created_at') }}</li>
                                                </ul>
                                            </div>
                                        </div>
                                    </th>
                                </tr>
                                <tr class="search-tr">
                                    <td class="column_name">
                                        <input type="hidden" name="orderBy" id="orderBy" value='{{ $request->orderBy ? json_encode($request->orderBy) : '{"key":"id","value":"DESC"}' }}'>
                                        <input type="text" name="name" value="{{ $request->name ?? '' }}" class="form-control" placeholder="Name">
                                    </td>
                                    <td class="column_email">
                                        <input type="text" name="email" value="{{ $request->email ?? '' }}" class="form-control" placeholder="E-mail">
                                    </td>
                                    <td class="column_phone">
                                        <input type="text" name="phone" value="{{ $request->phone ?? '' }}" class="form-control" placeholder="Phone">
                                    </td>
                                    <td class="column_role">
                                        <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 class="column_sector_id">
                                        <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 class="column_created_at">
                                        <input type="text" placeholder="{{ __('dashboard.date_from') }}" name="date_from" value="{{ $request->date_from ?? '' }}" class="date_from form-control">
                                    </td>
                                    <td class="column_created_at">
                                        <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>
                                </thead>
                                <tbody>
                                @foreach($users as $row)
                                    <tr>
                                        <td class="column_name">
                                            <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}}" >
                                                <label class="form-check-label" for="customCheck{{$row->id}}">
                                                    <div class="main-inf">
                                                        <h6 class="com-name" @if(auth()->user()->canAccess('employees','show')) style="cursor: pointer" onclick="openModel(this)" action="{{ route ('employees.show', $row->id) }}" @endif> {{$row->name}} </h6>
                                                    </div>
                                                </label>
                                            </div>
                                        </td>
                                        <td class="column_email"> <div class="text"> {{$row->email}} </div> </td>
                                        <td class="column_phone"> <a href="tel:{{$row->phone}}" class="text"> {{$row->phone}} </a> </td>
                                        <td class="column_role"> <div class="text"> {{__('users.roles.'.$row->role)}} </td>
                                        <td class="column_sector_id"> <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" class="column_created_at"> <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') && $row->lock == 0)
                                                        <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($row->lock)
                                                        <a href="{{ route('employees.lock', $row->id) }}"
                                                           class="dropdown-item"
                                                           title="{{ __('dashboard.unlock') }}">
                                                            <i class="bi bi-unlock-fill"></i>
                                                            {{ __('dashboard.unlock') }}
                                                        </a>
                                                    @else
                                                        <a href="{{ route('employees.lock', $row->id) }}"
                                                           class="dropdown-item"
                                                           title="{{ __('dashboard.lock') }}">
                                                            <i class="bi bi-lock-fill"></i>
                                                            {{ __('dashboard.lock') }}
                                                        </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>
