<div>
    @component('common.breadcrumb', ['addBtn' => true, 'permission_create' => 'User_create','breadcrumb_show' => $breadcrumb_show])
        @slot('breadcrumb_title')
            <h3>{{ $componentName }} | {{ $pageTitle }}</h3>
        @endslot
        <li class="breadcrumb-item">Usuarios</li>
        <li class="breadcrumb-item active">Roles</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="table-responsive">
                        <table class="table">
                        @if ($data->count())
                            <thead class="bg-primary">
                                <tr>
                                    <th scope="col">DOCUMENTO @include('common.orderby', ['column' => 'document'])</th>
                                    <th scope="col">NOMBRE @include('common.orderby', ['column' => 'first_name'])</th>
                                    <th scope="col">EMPRESA</th>
                                    <th scope="col">EMAIL</th>
                                    <th scope="col">PERFIL</th>
                                    <th scope="col">ESTADO @include('common.orderby', ['column' => 'status'])</th>
                                    <th scope="col">IMAGEN</th>
                                    <th scope="col" class="text-center">ACCIONES</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($data as $item)
                                <tr class="middle">
                                    <td>{{ $item->document }}</td>
                                    <td>{{ $item->first_name }} {{$item->last_name}}</td>
                                    <td>{{ $company = CompanyUser($item->id) }}</td>
                                    <td>{{ $item->email }}</td>
                                    <td>
                                        @if(!empty($item->getRoleNames()))
                                        @foreach($item->getRoleNames() as $val)
                                            <strong class="text-secondary">{{ $val }}</strong>
                                        @endforeach
                                    @endif
                                    </td>
                                    <td>
                                        <span class="badge {{ $item->status  == 'ACTIVO' ? 'badge-success' : 'badge-danger' }} text-uppercase">
                                            {{$item->status}}
                                        </span>
                                    </td>
                                    <td class="text-center">
                                        <img src="{{ asset('storage/users/' .$item->imagen) }}" alt="imagen"  class="rounded img-h-50">
                                    </td>
                                    <td class="text-center">
                                        @can('User_update')
                                        <a href="javascript:void(0)" wire:click="Edit({{ $item->id }}, '{{ $company }}')"
                                            class="btn btn-outline-primary" title="Editar">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        @endcan
                                        @can('User_delete')
                                        <a href="javascript:void(0)" onclick="Confirm('{{ $item->id }}')"
                                            class="btn btn-outline-danger " title="Eliminar">
                                            <i class="fas fa-trash"></i>
                                        </a>
                                        @endcan
                                        <a href="javascript:void(0)" onclick="SenEmailinfoAccount({{ $item->id }})"
                                            class="btn btn-outline-info " title="Enviar correo informativo">
                                            <i class="fa fa-envelope"></i>
                                        </a>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                            @else
                                <tr>
                                    <td colspan="8" class="text-center alert alert-danger"><strong>No se encuentran registos </strong></td>
                                </tr>
                            @endif
                        </table>
                        {{ $data->links() }}
                    </div>
                </div>
            </div>
        </div>
        @include('livewire.users.form')
    </div>
</div>
@include('common.scriptsCompStandar')
<script>
    document.addEventListener('DOMContentLoaded', function() {
        window.livewire.on('user-withCompanies', msg => {
            noty(msg)
        })
    });
    function SenEmailinfoAccount(id)
    {
        swal.fire({
            title: 'CONFIRMAR',
            text: '¿Confirmas enviar un correo con la información de la cuenta?. Se generará una contraseña nueva para este usuario.',
            icon: 'warning',
            showCancelButton: true,
            cancelButtonText: 'CERRAR',
            customClass: {
                confirmButton: 'btn btn-success',
                cancelButton: 'btn btn-danger'
        },

            confirmButtonText: 'ACEPTAR',
        }).then(function(result){
            if(result.value)
            {
                window.livewire.emit('send_email_info_account',id)
                swal.close()
            }
        })
    }
</script>
