<div>
    <x-adminlte-card title="USUARIOS" class="m-2" theme="dark" icon="fas fa-id-card">
        <div class="col-12">                                         
            <div class="row">
                <div class="col-12">
                    <div class="card-body">
                        <div id="example1_wrapper" class="dataTables_wrapper dt-bootstrap4">
                            <div class="row">
                                <div class="col-sm-12">
                                    <!-- <a href="#" data-href="" class="btn btn-info" data-toggle="modal" data-target="#addUser" data-placement="top" title="Agregar Usuario">
                                        <span class="fas fa-plus-square"></span>
                                    </a> -->
                                    <br>
                                    <table id="tabla_usuarios" class="table table-hover align-middle dataTable dtr-inline collapsed" aria-describedby="example1_info">
                                        <thead class="text-center px-4 py-4 text-nowrap bg-gray">
                                            <tr >
                                                <th>ID</th>
                                                <th style="width: 20%">NOMBRE</th>
                                                <th style="width: 10%">USERNAME</th>
                                                <th style="width: 15%">CORREO</th>
                                                <th>ROL</th>
                                                <th>ESTADO</th>
                                                <th>EDITAR</th>
                                                <th>DESACTIVAR</th>
                                                <th>RESTABLECER CONTRASEÑA</th>
                                            </tr>
                                        </thead>
                                        <tbody class="">
                                            @foreach($dataUsers as $dataUser)
                                            <tr class="text-center">
                                                <td>{{ $dataUser->id-1 }}</td>
                                                <td class="text-left">{{ $dataUser->name }}</td>
                                                <td>{{ $dataUser->username }}</td>
                                                <td class="text-left">{{ $dataUser->email }}</td>
                                                @if($dataUser->rol == 'stuser'|| $dataUser->rol == 'user')
                                                    <td><span class="badge bg-secondary">Usuario</span></td>
                                                @else
                                                    <td><span class="badge bg-info">Admin</span></td>
                                                @endif

                                                @if($dataUser->estado == 1)
                                                    <td><span class="badge bg-success">Activo</span></td>
                                                @else
                                                    <td><span class="badge bg-secondary">Inactivo</span></td>
                                                @endif
                                                <td>
                                                    <form wire:click="editUser({{$dataUser->id}})">
                                                        <buttom name="edit" id="edit" class="btn btn-warning" data-placement="top" title="Editar Usuario">
                                                            <i class="fas fa-edit"></i>
                                                        </buttom>
                                                    </form>
                                                </td>

                                                @if($dataUser->estado == 1)
                                                    <td>
                                                        <form wire:submit.prevent="deleteUser({{ $dataUser->id }})">
                                                            @csrf
                                                            <button class="btn btn-danger" title="Desactivar" type="submit">
                                                            <i class="fas fa-ban"></i>  
                                                            </button>
                                                        </form>
                                                    </td>
                                                @else 
                                                    <td>
                                                        <form wire:submit.prevent="enableUser({{ $dataUser->id }})">
                                                            @csrf
                                                            <button class="btn btn-success" title="Activar" type="submit">
                                                            <i class="fas fa-check"></i>
                                                            </button>
                                                        </form>
                                                    </td>
                                                @endif

                                                <td>
                                                    <form wire:submit.prevent="resetUser({{ $dataUser->id }})">
                                                        @csrf
                                                        <button class="btn btn-info" title="Restablecer" type="submit">
                                                        <i class="fas fa-key"></i>
                                                        </button>
                                                    </form>
                                                </td>
                                            </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </x-adminlte-card>

    <div wire:ignore.self class="modal fade show" name="editUser" id="editUser" aria-modal="true" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">EDITANDO USUARIO</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <form wire:submit.prevent="updateUser({{ $userId }})">
                    <div class="modal-body">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-8">
                                    <div class="row">
                                        <div class="col-md-12">
                                            {{-- Nombre y Apellido --}}
                                            <label>NOMBRES Y APELLIDOS <strong style="color:red">*</strong></label>
                                            <x-adminlte-input wire:model="nombre" type="text" name="nombre" id="nombre" placeholder="Ingrese nombre" label-class="text-lightblue">
                                                <x-slot name="prependSlot">
                                                    <div class="input-group-text">
                                                        <i class="fas fa-user text-dark"></i>
                                                    </div>
                                                </x-slot>
                                            </x-adminlte-input>
                                            @error('nombre')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="row">
                                        <div class="col-md-12">
                                            {{-- USERNAME --}}
                                            <label>NOMBRE DE USUARIO <strong style="color:red">*</strong></label>
                                            <x-adminlte-input wire:model="username" type="text" name="username" id="username" placeholder="Ingrese nombre de usuario" readonly="readonly" label-class="text-lightblue">
                                                <x-slot name="prependSlot">
                                                    <div class="input-group-text">
                                                        <i class="fas fa-user text-dark"></i>
                                                    </div>
                                                </x-slot>
                                            </x-adminlte-input>
                                            @error('username')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="row">
                                        <div class="col-md-12">
                                            {{-- Correo --}}
                                            <label>CORREO <strong style="color:red">*</strong></label>
                                            <x-adminlte-input wire:model="email" type="text" name="email" id="email" placeholder="Ingrese Giro" label-class="text-lightblue">
                                                <x-slot name="prependSlot">
                                                    <div class="input-group-text">
                                                        <i class="fas fa-user text-dark"></i>
                                                    </div>
                                                </x-slot>
                                            </x-adminlte-input>
                                            @error('email')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="row">
                                        <div class="col-md-12">
                                            {{-- DNI --}}
                                            <label>DOC. NAC. IDENTIDAD <strong style="color:red">*</strong></label>
                                            <x-adminlte-input wire:model="numdoc" type="text" name="numdoc" id="numdoc" placeholder="Ingrese dni" readonly="readonly" label-class="text-lightblue">
                                                <x-slot name="prependSlot">
                                                    <div class="input-group-text">
                                                        <i class="fas fa-user text-dark"></i>
                                                    </div>
                                                </x-slot>
                                            </x-adminlte-input>
                                            @error('numdoc')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="row">
                                        <div class="col-md-12">
                                            {{-- ROL --}}
                                            <label>ROL <strong style="color:red">*</strong></label>
                                            <x-adminlte-select wire:model="rol" value="{{ $rol }}" name="rol" id="rol" label-class="text-lightblue">
                                                <x-slot name="prependSlot">
                                                    <div class="input-group-text">
                                                        <i class="fas fa-id-card text-dark"></i>
                                                    </div>
                                                </x-slot>
                                                <option value="user">USUARIO</option>
                                                <option value="admin">ADMINISTRADOR</option>
                                            </x-adminlte-select>
                                            @error('rol')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="row">
                                        <div class="col-md-12">
                                            {{-- ESTADO --}}
                                            <label>ESTADO <strong style="color:red">*</strong></label>
                                            <x-adminlte-select wire:model="estadoUser" value="{{ $estadoUser }}" name="estadoUser" id="estadoUser" label-class="text-lightblue">
                                                <x-slot name="prependSlot">
                                                    <div class="input-group-text">
                                                        <i class="fas fa-id-card text-dark"></i>
                                                    </div>
                                                </x-slot>
                                                <option value="1">HABILITADO</option>
                                                <option value="0">DESHABILITADO</option>
                                            </x-adminlte-select>
                                            @error('estadoUser')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="button" class="btn btn-default" onclick="javascript:window.history.back();">Cerrar</button>
                        <button type="submit" class="btn btn-primary">Guardar Cambios</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
