<div>
    @component('common.breadcrumb', ['addBtn' => false, 'permission_create' => 'Company_work_permit_view','breadcrumb_show' => $breadcrumb_show])
        @slot('breadcrumb_title')
            <h3>{{ $componentName }} | {{ $pageTitle }}</h3>
        @endslot
        <li class="breadcrumb-item">Empresa</li>
        <li class="breadcrumb-item active">Solicitudes de permisos laborales</li>

    @endcomponent

    @include('common.searchbox')
    <div class="container-fluid">
        <div class="row layout-top-spacing">
            <div class="col-sm-12">
                <div class="card">
                    <div class="card-body">
                        <div class="card-header">
                            <h4>{{ $company_name }} | Plan: <b>{{ $company_plan_name }}</b></h4>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row justify-content-center">
            <div class="col-lg-4 col-md-4 col-sm-12">
                <div class="form-group">
                    <select class="form-select" wire:model="status_work_permit">
                        <option value="">Todos los estados de Permiso de Trabajo</option>
                        @foreach (DataTypeStatusStandard() as $key => $value)
                            <option value="{{ $key }}">{{ $value }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="col-lg-4 col-md-4 col-sm-12">
                <div class="form-group">
                    <select class="form-select" wire:model="status_support_work_permit">
                        <option value="">Todos los estados de Soporte de Permiso de Trabajo</option>
                        @foreach (DataTypeStatusSupportWorkPermit() as $key => $value)
                            <option value="{{ $key }}">{{ $value }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
        </div><!-- row -->
        @livewire('company_-work-permit-detail-controller',['work_permit_id' => $work_permit_id])
        <div class="row justify-content-between file-content mb-2">
            <div class="col-sm-12">
                <div class="card">
                    <div class="table-responsive">
                        <table class="table">
                            <thead class="bg-primary">
                                <tr>
                                    <th scope="col">NOMBRE @include('common.orderby', ['column' => 'name'])</th>
                                    <th scope="col" class="text-center">APELLIDO @include('common.orderby', ['column' => 'last_name'])</th>
                                    <th scope="col" class="text-center">DOCUMENTO @include('common.orderby', ['column' => 'document'])</th>
                                    <th scope="col" class="text-center">CARGO</th>
                                    <th scope="col" class="text-center">TIPO SOLICITUD</th>
                                    <th scope="col" class="text-center"># RADICADO</th>
                                    <th scope="col" class="text-center">ESTADO SOLICITUD</th>
                                    <th scope="col" class="text-center">SOPORTE</th>
                                    <th scope="col" class="text-center">ACCIONES</th>
                                </tr>
                            </thead>
                            <tbody>
                                @if ($users->count() > 0)
                                    @foreach ($users as $item)
                                        <tr>
                                            <td>{{ $item->first_name }}</td>
                                            <td class="text-left">{{ $item->last_name }}</td>
                                            <td class="text-left">{{ $item->document }}</td>
                                            <td>
                                                @if(!empty($item->job_position_id))
                                                    {{ $this->jobPositionName($item->job_position_id) }}
                                                @endif
                                            </td>
                                            <td class="text-center">
                                                {{ $item->type_work_permit_name}}
                                            </td>
                                            <td class="text-center">
                                                {{ $item->register_code }}
                                            </td>
                                            <td class="text-center">
                                                <span class="py-1 px-2  {{ $item->status_work_permit == 0 ? 'bg-warning' : ($item->status_work_permit == 1 ? 'bg-success' : 'bg-danger') }}">
                                                    {{ DataTypeStatusStandard($item->status_work_permit) }}
                                                    <i class="fas {{ $item->status_work_permit == 0 ? 'fa-clock' : ($item->status_work_permit == 1 ? 'fa-check' : 'fa-times') }}"></i>
                                                </span>
                                            </td>
                                            <td class="text-center">
                                                @if ($item->support_document_required == 1)
                                                    @if ($item->support_document == NULL)
                                                        @if ($item->status_support_document == 2)
                                                            <span class="badge badge-danger">Se solicito correción</span>
                                                        @elseif ($item->status_support_document == 0)
                                                            <span class="badge badge-warning">Soporte pendiente</span>
                                                        @endif
                                                    @else
                                                        @if($item->status_support_document == 2)
                                                            <span class="badge badge-danger">Soporte rechazado</span>
                                                        @elseif($item->status_support_document == 1)
                                                            <span class="badge badge-success">Soporte aceptado</span>
                                                        @else
                                                            <span class="badge badge-warning">Soporte sin revisar</span>
                                                        @endif
                                                    @endif
                                                @else
                                                    <span class="badge badge-success">No requerido</span>
                                                @endif

                                            </td>

                                            <td class="text-center">
                                                @if ($item->status == "ACTIVO")
                                                    @can('Company_work_permit_view')
                                                        <a href="javascript:void(0)" wire:click.prevent="openWP({{ $item->work_permit_id }})" class="btn btn-sm btn-outline-primary">
                                                            <i class="fas fa-eye"></i>
                                                        </a>
                                                        <!-- ver todos los permisos de este usuario -->
                                                        <a href="{{ route('permisos-laborales-empleado', $item->id) }}"
                                                            class="btn btn-sm btn-outline-primary" title="Ver todos los permisos laborales de este usuario">
                                                            <i class="fas fa-user-clock"></i>
                                                        </a>
                                                    @endcan
                                                @endif
                                            </td>
                                        </tr>
                                    @endforeach
                                @else
                                    <tr>
                                        <td colspan="9" class="text-center">
                                            No hay registros disponibles
                                        </td>
                                    </tr>
                                @endif
                            </tbody>
                        </table>
                        {{ $users->links() }}
                    </div>

                </div>
            </div>
        </div>

    </div>
</div>
@include('common.scriptsCompStandar')
