@extends('layouts.app', ['pageSlug' => 'userlist'])
@push('style')
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
@endpush
@section('content')
<meta name="csrf-token" content="{{ csrf_token() }}" />
<script type="text/javascript">

$(document).ready(function(){
    
      // DataTable
      // var  category= $('#searchBycategory').val();
      // alert(category);
      var usertable=$('#users').DataTable({
         processing: true,
         serverSide: true,
       
         //ajax: "{{route('getQues')}}",
           // Read values
         ajax: {
       'url':"{{route('getUsers')}}",
       
       'data': function(d){
          // Read values
          d.category = $('#searchByrole').val();
         // var name = $('#searchByName').val();
 
        
       }
    }, 
         columns: [
            { data: 'id' },
            { data: 'name' },
             { data: 'email' },
             { data: 'role' },
             { data: 'status' },
              { data: 'chat' },
            { data: 'action' },
            
         ]
      });
   
    $('#searchByrole').change(function(){
  //alert();
    usertable.draw();
  });
  
    });

function trailextend($id){
 // alert($id);
  $.confirm({
    title: 'Prompt!',
    content: '' +
    '<form action="" class="formName">' +
    '<div class="form-group">' +
    '<label>Dates to be extends</label>' +
    '<input type="number" placeholder="Enter How many dates to be extends count" class="name form-control" required min="1"/>' +
    '</div>' +
    '</form>',
    buttons: {
        formSubmit: {
            text: 'Submit',
            btnClass: 'btn-blue',
            action: function () {
                var trailcount = this.$content.find('.name').val();
                var id=$id;
                if(!trailcount){
                    $.alert('provide a valid name');
                    return false;
                }
                
                 $.ajax({
 type: "POST",
 url: "{{ route('updatetrails.post') }}",
 data: {
 "trailcount": trailcount,
  "_token": "{{ csrf_token() }}",
  "id":id
 },
 cache: false,
 success: function(data) {
 //alert(data);
 $.alert(data);
 },
 error: function(xhr, status, error) {
 console.error(xhr);
 }
 });
            }
        },
        cancel: function () {
            //close
        },
    },
    onContentReady: function () {
        // bind to events
        var jc = this;
        this.$content.find('form').on('submit', function (e) {
            // if the user submits the form by pressing enter in the field.
            e.preventDefault();
            jc.$$formSubmit.trigger('click'); // reference the button and click it
        });
    }
});
}
function chathistory($uid){

  $('#to_user').val($uid);
  $('#chat').val(''); 

  $.ajax({
 type: "GET",
 url: "chat_history/{id}",
 data: {
  "id": $uid},
 cache: false,
 success: function(data) {
 //alert(data);
 $('.chathistory').html(data);
 //$.alert(data);
 },
 error: function(xhr, status, error) {
 console.error(xhr);
 }
 });

}
function chatstore(){
  //alert('hi');
 var to_user =$('#to_user').val();
 var msg=$('#chat').val();
    $.ajax({
 type: "POST",
 url: "{{ route('chatstore.post') }}",
 data: {
  "msg": msg,
  "_token": "{{ csrf_token() }}",
  "to_user":to_user
 },
 cache: false,
 success: function(data) {
 //alert(data);
 $('#myModal').modal('hide');
 $.alert(data);
 },
 error: function(xhr, status, error) {
 console.error(xhr);
 }
 });
}
</script>
<div class="container">
  <!-- chat msg Start  -->
               <!--  <div class="page-content page-container" id="page-content">
    <div class="padding">
        <div class="row container d-flex justify-content-center">
            <div class="col-md-4">
                <div class="box box-warning direct-chat direct-chat-warning">
                    <div class="box-header with-border">
                        <h3 class="box-title">Chat Messages</h3>
                        <div class="box-tools pull-right"> <span data-toggle="tooltip" title="" class="badge bg-yellow" data-original-title="3 New Messages">20</span> <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i> </button> <button type="button" class="btn btn-box-tool" data-toggle="tooltip" title="" data-widget="chat-pane-toggle" data-original-title="Contacts"> <i class="fa fa-comments"></i></button> <button type="button" class="btn btn-sm" data-widget="remove"><i class="fa fa-times"></i> </button> </div>
                    </div>
                    <div class="box-body">
                        <div class="direct-chat-messages">
                            <div class="direct-chat-msg">
                                <div class="direct-chat-info clearfix"> <span class="direct-chat-name pull-left">Timona Siera</span> <span class="direct-chat-timestamp pull-right">23 Jan 2:00 pm</span> </div> <img class="direct-chat-img" src="https://img.icons8.com/color/36/000000/administrator-male.png" alt="message user image">
                                <div class="direct-chat-text"> For what reason would it be advisable for me to think about business content? </div>
                            </div>
                            <div class="direct-chat-msg right">
                                <div class="direct-chat-info clearfix"> <span class="direct-chat-name pull-right">Sarah Bullock</span> <span class="direct-chat-timestamp pull-left">23 Jan 2:05 pm</span> </div> <img class="direct-chat-img" src="https://img.icons8.com/office/36/000000/person-female.png" alt="message user image">
                                <div class="direct-chat-text"> Thank you for your believe in our supports </div>
                            </div>
                            <div class="direct-chat-msg">
                                <div class="direct-chat-info clearfix"> <span class="direct-chat-name pull-left">Timona Siera</span> <span class="direct-chat-timestamp pull-right">23 Jan 5:37 pm</span> </div> <img class="direct-chat-img" src="https://img.icons8.com/color/36/000000/administrator-male.png" alt="message user image">
                                <div class="direct-chat-text"> For what reason would it be advisable for me to think about business content? </div>
                            </div>
                            <div class="direct-chat-msg right">
                                <div class="direct-chat-info clearfix"> <span class="direct-chat-name pull-right">Sarah Bullock</span> <span class="direct-chat-timestamp pull-left">23 Jan 6:10 pm</span> </div> <img class="direct-chat-img" src="https://img.icons8.com/office/36/000000/person-female.png" alt="message user image">
                                <div class="direct-chat-text"> I would love to. </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <form action="#" method="post">
                            <div class="input-group"> <input type="text" name="message" placeholder="Type Message ..." class="form-control"> <span class="input-group-btn"> <button type="button" class="btn btn-warning btn-flat">Send</button> </span> </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>  -->
<!-- chat msg end  -->
    <div class="row ">
        <div class="col-md-12">

          @if(session()->has('message'))
            <p class="btn btn-success btn-block btn-sm custom_message text-left">{{ session()->get('message') }}</p>
          @endif

          <div class="card ">
            <div class="card-header">
                <div class="row">
                    <div class="col-8">
                        <h4 class="card-title">User List</h4>
                    </div>
                    <div class="col-4 text-right">
                        <a href="{{ route('adduser') }}" class="btn btn-sm btn-primary">Add User</a>
                    </div>
                </div>
            </div>
            <div class="card-body">
                  <div class="row">
                    <div class="col-4">
                    <select id="searchByrole" class="form-control">
                   
            <option value=''>search Role</option>
            
               <option value="admin">Admin</option>
            <option value="adminuser">Adminuser</option>
             <option value="user">User</option>
            </select>
                    </div>
                    </div>
                <div class="">
                  <table class="table table-bordered" id="users">
    <thead>
       <tr>
                            <th >No</th>
                            <th >Name</th>
                            <th >Email</th>
                           <th>Role</th>
                            <th>Status</th>
                            <th>Chat</th>
                            <th >ACTION</th>
                        </tr>
    </thead>
    <tbody>
      
    </tbody>
  </table>
                   
                </div>
              
            </div>
            <!-- chat msg test start  -->
          <!-- Trigger the modal with a button -->
  <!-- <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">Open Modal</button> -->

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Chat History</h4>
        </div>
        <div class="modal-body">
        <div class="chathistory">
        <!--  <div class="direct-chat-msg">
                                <div class="direct-chat-info clearfix"> <span class="direct-chat-name pull-left">Timona Siera</span> <span class="direct-chat-timestamp pull-right">23 Jan 5:37 pm</span> </div> <img class="direct-chat-img" src="https://img.icons8.com/color/36/000000/administrator-male.png" alt="message user image">
                                <div class="direct-chat-text"> For what reason would it be advisable for me to think about business content? </div>
                            </div>
         <div class="direct-chat-msg right">
                                <div class="direct-chat-info clearfix"> <span class="direct-chat-name pull-right">Sarah Bullock</span> <span class="direct-chat-timestamp pull-left">23 Jan 6:10 pm</span> </div> <img class="direct-chat-img" src="https://img.icons8.com/office/36/000000/person-female.png" alt="message user image">
                                <div class="direct-chat-text"> I would love to. </div>
                            </div> -->
        </div>
         <form action="#" method="post" onsubmit="chatstore();return false;">
         <div class="row">
                    <div class="col-8"> 
         <input type="hidden" name="to_user" id="to_user" value="">
  <div class="form-group">
   <textarea class="form-control" id="chat" name="msg" placeholder="Type Message here" required=""></textarea>
    
</div>
</div>
<div class="col-2">
  <button type="submit" class="btn btn-default" >Send</button>
  </div>
  </form>
        </div>
        <div class="modal-footer">
          <!-- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> -->
        </div>
      </div>
      
    </div>
  </div>
  
            <!-- chat msg test end  -->
        </div>
        </div>
    </div>
</div>
@endsection
<style type="text/css">
  .stretch-card>.card {
    width: 100%;
    min-width: 100%
}

body {
    background-color: #f9f9fa
}

.flex {
    -webkit-box-flex: 1;
    -ms-flex: 1 1 auto;
    flex: 1 1 auto
}

@media (max-width:991.98px) {
    .padding {
        padding: 1.5rem
    }
}

@media (max-width:767.98px) {
    .padding {
        padding: 1rem
    }
}

.padding {
    padding: 3rem
}

.box.box-warning {
    border-top-color: #f39c12
}

.box {
    position: relative;
    border-radius: 3px;
    background: #ffffff;
    border-top: 3px solid #d2d6de;
    margin-bottom: 20px;
    width: 100%;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1)
}

.box-header.with-border {
    border-bottom: 1px solid #f4f4f4
}

.box-header.with-border {
    border-bottom: 1px solid #f4f4f4
}

.box-header {
    color: #444;
    display: block;
    padding: 10px;
    position: relative
}

.box-header:before,
.box-body:before,
.box-footer:before,
.box-header:after,
.box-body:after,
.box-footer:after {
    content: "";
    display: table
}

.box-header {
    color: #444;
    display: block;
    padding: 10px;
    position: relative
}

.box-header>.fa,
.box-header>.glyphicon,
.box-header>.ion,
.box-header .box-title {
    display: inline-block;
    font-size: 18px;
    margin: 0;
    line-height: 1
}

.box-header>.box-tools {
    position: absolute;
    right: 10px;
    top: 5px
}

.box-header>.box-tools [data-toggle="tooltip"] {
    position: relative
}

.bg-yellow,
.callout.callout-warning,
.alert-warning,
.label-warning,
.modal-warning .modal-body {
    background-color: #f39c12 !important
}

.bg-yellow {
    color: #fff !important
}

.btn {
    border-radius: 3px;
    -webkit-box-shadow: none;
    box-shadow: none;
    border: 1px solid transparent
}

.btn-box-tool {
    padding: 5px;
    font-size: 12px;
    background: transparent;
    color: #97a0b3
}

.direct-chat .box-body {
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
    position: relative;
    overflow-x: hidden;
    padding: 0
}

.box-body {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 3px;
    border-bottom-left-radius: 3px;
    padding: 10px
}

.box-header:before,
.box-body:before,
.box-footer:before,
.box-header:after,
.box-body:after,
.box-footer:after {
    content: "";
    display: table
}

.direct-chat-messages {
    -webkit-transform: translate(0, 0);
    -ms-transform: translate(0, 0);
    -o-transform: translate(0, 0);
    transform: translate(0, 0);
    padding: 10px;
    height: 250px;
    overflow: auto
}

.direct-chat-messages,
.direct-chat-contacts {
    -webkit-transition: -webkit-transform .5s ease-in-out;
    -moz-transition: -moz-transform .5s ease-in-out;
    -o-transition: -o-transform .5s ease-in-out;
    transition: transform .5s ease-in-out
}

.direct-chat-msg {
    margin-bottom: 10px
}

.direct-chat-msg,
.direct-chat-text {
    display: block
}

.direct-chat-info {
    display: block;
    margin-bottom: 2px;
    font-size: 12px
}

.direct-chat-timestamp {
    color: #999
}

.btn-group-vertical>.btn-group:after,
.btn-group-vertical>.btn-group:before,
.btn-toolbar:after,
.btn-toolbar:before,
.clearfix:after,
.clearfix:before,
.container-fluid:after,
.container-fluid:before,
.container:after,
.container:before,
.dl-horizontal dd:after,
.dl-horizontal dd:before,
.form-horizontal .form-group:after,
.form-horizontal .form-group:before,
.modal-footer:after,
.modal-footer:before,
.modal-header:after,
.modal-header:before,
.nav:after,
.nav:before,
.navbar-collapse:after,
.navbar-collapse:before,
.navbar-header:after,
.navbar-header:before,
.navbar:after,
.navbar:before,
.pager:after,
.pager:before,
.panel-body:after,
.panel-body:before,
.row:after,
.row:before {
    display: table;
    content: ""
}

.direct-chat-img {
    border-radius: 50%;
    float: left;
    width: 40px;
    height: 40px
}

.direct-chat-text {
    border-radius: 5px;
    position: relative;
    padding: 5px 10px;
    background: #d2d6de;
    border: 1px solid #d2d6de;
    margin: 5px 0 0 50px;
    color: #444
}

.direct-chat-msg,
.direct-chat-text {
    display: block
}

.direct-chat-text:before {
    border-width: 6px;
    margin-top: -6px
}

.direct-chat-text:after,
.direct-chat-text:before {
    position: absolute;
    right: 100%;
    top: 15px;
    border: solid transparent;
    border-right-color: #d2d6de;
    content: ' ';
    height: 0;
    width: 0;
    pointer-events: none
}

.direct-chat-text:after {
    border-width: 5px;
    margin-top: -5px
}

.direct-chat-text:after,
.direct-chat-text:before {
    position: absolute;
    right: 100%;
    top: 15px;
    border: solid transparent;
    border-right-color: #d2d6de;
    content: ' ';
    height: 0;
    width: 0;
    pointer-events: none
}

:after,
:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box
}

.direct-chat-msg:after {
    clear: both
}

.direct-chat-msg:after {
    content: "";
    display: table
}

.direct-chat-info {
    display: block;
    margin-bottom: 2px;
    font-size: 12px
}

.right .direct-chat-img {
    float: right
}

.direct-chat-warning .right>.direct-chat-text {
    background: #f39c12;
    border-color: #f39c12;
    color: #fff
}

.right .direct-chat-text {
    margin-right: 50px;
    margin-left: 0
}

.box-footer {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 3px;
    border-bottom-left-radius: 3px;
    border-top: 1px solid #f4f4f4;
    padding: 10px;
    background-color: #fff
}

.box-header:before,
.box-body:before,
.box-footer:before,
.box-header:after,
.box-body:after,
.box-footer:after {
    content: "";
    display: table
}

.input-group-btn {
    position: relative;
    font-size: 0;
    white-space: nowrap
}

.input-group-btn:last-child>.btn,
.input-group-btn:last-child>.btn-group {
    z-index: 2;
    margin-left: -1px
}

.btn-warning {
    color: #fff;
    background-color: #f0ad4e;
    border-color: #eea236
}

</style>
<style>
        h1 {
            color:green;
        }
        .badge {
            position: relative;
            top: -37px;
            left: 26px;
            border: 1px solid black;
            border-radius: 50%;
        }
        button {
            margin:5px;
        }
        .chathistory
{
    max-height: 313px;
    overflow-y: scroll;
}
    </style>