@extends('layouts.app')

@section('content')
@include('admin.adminheader')
<div class='container'>
    <div class="page-title-box">
                <div class="row align-items-center">
                    <div class="col-sm-6">
                        <h4 class="page-title">Users</h4>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-right">
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Admin</a></li>
                            <li class="breadcrumb-item active">Users</li>
                        </ol>
                    </div>
                </div>
                <!-- end row -->
            </div>
    
<div class='row d-flex justify-content-center mt-5'>
        <div class='col-md-12 mb-3 text-end'>
        <a  data-bs-toggle="modal" data-bs-target="#addclosermodal" class='btn btn-primary text-white text-small'><i class="fa fa-plus-circle" aria-hidden="true"></i>
        Add New User</a> 
        </div>
</div>
  
    
        <div class='row d-flex justify-content-center'>
            <div class='col-md-12 mt-5'>
            @if (Session::has('success'))
                <div class='alert alert-success alert-dismissible fade show' role='alert'>
                {{ Session::get('sucess') }}
                </div>
                @endif
              
            <table id="datatable" class="table table-striped data-table" style="width:100%">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Email</th>
                        <th>Phone</th>
                        <th>Address</th>
                        <th>Action</th>

                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>

      <!-- Add User form Modal -->
      <div class="modal fade" id="addclosermodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add New User</h5>
      </div>
      
      <div class="modal-body">
      <form method="POST" action="{{ route('admin-add-user') }}">
                        @csrf
                    <div class='row'>
                        <div class='col-md-6'>
                            <div class="form-group mb-3">
                                        <input id="first_name" type="text" class="form-control @error('first_name') is-invalid @enderror" name="first_name" placeholder='First Name' value="{{ old('first_name') }}" autocomplete="first_name" autofocus>
                                        @error('first_name')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                            </div>
                        </div>
                        <div class='col-md-6'>
                            <div class="form-group mb-3">
                                    <input id="last_name" type="text" class="form-control @error('last_name') is-invalid @enderror" name="last_name" placeholder='Last Name' value="{{ old('last_name') }}" autocomplete="last_name" autofocus>
                                    @error('last_name')
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                            </div>
                        </div>
                    </div>
                    <div class='row'>
                        <div class='col-md-6'>
                            <div class="form-group mb-3">     
                                    <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" placeholder='Email' name="email" value="{{ old('email') }}" autocomplete="email">
                                    @error('email')
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                            </div>
                        </div>
                        <div class='col-md-6'>
                            <div class="form-group mb-3">
                                    <input id="phone" type="tel" class="form-control @error('phone') is-invalid @enderror" name="phone" placeholder='Phone' value="{{ old('phone') }}" autocomplete="phone" oninput="handleInput()" onkeypress="return validateInput()" autofocus>
                                    @error('phone')
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                            </div>
                        </div>
                    </div>
                        <div class="form-group mb-3">
                                <input id="address" type="text" class="form-control @error('address') is-invalid @enderror" name="address" placeholder='Address' value="{{ old('address') }}" autocomplete="address" autofocus>
                                @error('address')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                        </div>
                        <div class="form-group mb-3 password-div">
                                <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" placeholder='Password' name="password" autocomplete="new-password">
                                <i id='showpswd' class="fa fa-eye-slash" onclick="showpwd()" aria-hidden="true"></i>

                                @error('password')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                        </div>
                        <div class="form-group mb-3">
                                <input id="password-confirm" type="password" class="form-control" placeholder='Confirm Password' name="password_confirmation" autocomplete="new-password">
                        </div>
                        <div class="form-group mb-0">
                                <button type="submit" class="btn btn-primary w-100 success-btn">
                                    {{ __('Register') }}
                                </button>
                        </div>
                    </form>
</div>

    <script type="text/javascript">
  $(function () {
      
    var table = $('#datatable').DataTable({
        processing: true,
        serverSide: true,
        ajax: "{{ route('allusers') }}",
        columns: [
            {data: 'id', name: 'id'},
            {data: 'first_name'},
            {data: 'last_name'},
            {data: 'email', name: 'email'},
            {data: 'phone', name: 'phone'},
            {data: 'address', name: 'address'},
            {data: 'action', name: 'action', orderable: false, searchable: false},

        ]
    });
      
  });
</script>
<script>
function showpwd() {
    var icon = document.getElementById("showpswd");
  var x = document.getElementById("password");

  if (x.type === "password") {
    x.type = "text";
    icon.classList.remove('fa-eye-slash');
    icon.classList.add('fa-eye');
  } else {
    x.type = "password";
    icon.classList.remove('fa-eye');
    icon.classList.add('fa-eye-slash');
  }
}
</script>

@endsection

  