@extends('layouts.master')

@section('content')
<!-- DataTables -->
<link rel="stylesheet" href="{{ asset('/assets/') }}/css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/switch/rcswitcher.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/pnotify.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/sweetalert.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/sweet-alert-animations.css">

<div class="panel panel-default">
    <!-- Default panel contents -->
    <div class="panel-heading"></div>
        <header class="panel-heading" style="height:50px;">
            <div class="pull-left">
                {{$title}}
            </div>
            <div>
                <button class="btn btn-success btn-sm pull-right" data-toggle="modal" data-target="#id_add_user"><i class="fa fa-plus"></i> Add user</button>
            </div>
        </header>
    <div class="panel-body">
        <div class="clearfix"></div>
        <table class="table table-bordered" id="example">
            <thead>
                <tr>
                    <th>
                        #
                    </th>
                    <th>
                        Name
                    </th>
                    <th>
                        Email
                    </th>
                    <th>
                        Mobile
                    </th>
                    <th>
                        Address
                    </th>
                    <!-- <th width="5%">
                        Company
                    </th> -->
                    <th>
                        User type
                    </th>
                    <th>
                        Status
                    </th>
                    <th width="22%">
                        Action
                    </th>
                </tr>
            </thead>
            <tbody>
            @if($all)
            <?php $i=1;?>
            @foreach($all as $row)
                <tr>
                    <td>
                        {{$i++}}
                    </td>
                    <td>
                        {{$row->name}}
                    </td>
                    <td>
                        {{$row->email}}
                    </td>
                    <td>
                        {{$row->mob}}
                    </td>
                    <td>
                        {{$row->address}}
                    </td>
                    <!-- <td>
                        {{$row->company}}
                    </td> -->
                    <td>
                    @if($row->utype == 1)
                        <span class="label label-success">{{"Admin"}}</span>
                    @elseif($row->utype == 2)
                        <span class="label label-primary">{{"User"}}</span>
                    @elseif($row->utype == 3)
                        <span class="label label-default">{{"Client"}}</span>
                    @endif
                </td>
                    <td style="text-align: center;">
                    <input type="checkbox" name="status{{ $row->id }}" @if($row->active == 1) {{ 'checked' }} @endif data-id="{{ $row->id }}">
                    </td>
                    <td class="parent-action-cls">
                        <a href="{{ url('admin/user_profile') }}/{{ $row->id }}" class='btn btn-default btn-sm' data-toggle="tooltip" title="View" data-placement="top"><i class="fa fa-eye"></i></a>
                        @if(Auth::user()->utype==1)
                        <a href="#" class='btn btn-default btn-sm' data-toggle="tooltip" title="Edit" data-placement="top"><i class="fa fa-edit"></i></a>

                        <a href="#" class='btn btn-default btn-sm' onclick="return confirm('Are you sure to delete this item ?')" data-toggle="tooltip" title="Delete" data-placement="top"><i class="fa fa-trash-o"></i></a>

                        <input type="text" name="" class="hidden" value="{{ $row->id }}" />
                        <a class='btn btn-info btn-sm change-pass' data-toggle="modal" data-target="#change_password"><i class="fa fa-key"  data-toggle="tooltip" title="Change Password" data-placement="top" ></i> </a>

                        @endif
                    </td>
                </tr>

            @endforeach
            @endif
            </tbody>
        </table>
    </div>
</div>
<!-- Modal Add User -->
<div class="modal fade" id="id_add_user" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel">Add user</h4>
      </div>
      <div class="modal-body">

        <form action="{{url('admin/add_user')}}" method="POST">

            {{ csrf_field() }}
            <div class="form-group">
                <label for="exampleInputEmail1">Name*</label>
                <input type="text" name="name" class="form-control" id="" placeholder="Name" required="">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Employee ID*</label>
                <input type="text" name="e_id" class="form-control" id="exampleInputEmail1" placeholder="Employee ID" required="">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Designation*</label>
                <input type="text" name="designation" class="form-control" id="exampleInputEmail1" placeholder="Designation" required="">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Email address*</label>
                <input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="Email" required="">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Mobile*</label>
                <input type="text" name="mob" class="form-control" id="" placeholder="Mobile" required="">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Address*</label>
                <input type="text" name="address" class="form-control" id="" placeholder="Address" required="">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Company</label>
                <select class="form-control" name="company" placeholder="Company">
                    <option>Select A Company</option>
                    @foreach($client_list as $client)
                        <option value="{{ $client->id }}">{{ $client->name }}</option>
                    @endforeach
                </select>
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">Website</label>
                <input type="text" name="website" class="form-control" id="" placeholder="Website">
            </div>
            <div class="form-group">
                <label for="exampleInputEmail1">User type*</label>
                <select class="form-control" name="user_type">
                    <option value="2">User</option>
                    <option value="1">Admin</option>
                    <option value="3">Client</option>
                </select>
            </div>
            <div class="form-group">
                <label for="permission">Assign User Role* </label>
                <select class="form-control" name="role" required="">
                    <option disabled selected value>Choose One</option>
                    @foreach($roles as $info)
                    <option value="{{ $info->id }}">{{ $info->display_name }}</option>
                    @endforeach
                </select>
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">Password*</label>
                <input type="password" name="password" class="form-control" id="exampleInputPassword1" placeholder="Password" value="123456" required="">
            </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
      </form>  
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>

<!-- Change password start -->
<div class="modal fade" id="change_password" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel">Change password</h4>
      </div>
      <div class="modal-body">

        <form action="{{url('admin/change_user_pass')}}" method="POST">

            {{ csrf_field() }}

            <input type="hidden" name="user_id" value="" class="change-pass-user-id">
            
            <div class="form-group">
                <label for="exampleInputPassword1">Password</label>
                <input type="password" name="password" class="form-control" id="exampleInputPassword1" placeholder="Password" required="">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">Confirm Password</label>
                <input type="password" name="password_confirmation" class="form-control" id="exampleInputPassword1" placeholder="Password" required="">
            </div>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
      </form>  
    </div>
  </div>
</div>
<!-- Change password end -->

@stop

@section('style')
<style>
    .modal-dialog {
      width: 40% !important;
      height: 40% !important;
    }

    .modal-content {
      height: auto;
      min-height: 40% !important;
      border-radius: 0;
    }
</style>
@stop

@section('script')
<script src="{{ asset('/assets/') }}/js/jquery.dataTables.min.js"></script>
<script src="{{ asset('/assets/') }}/js/dataTables.bootstrap.min.js"></script>
<script src="{{ asset('/assets/') }}/switch/rcswitcher.js"></script>
<script src="{{ asset('/assets/') }}/alert/sweetalert.min.js"></script>
<script src="{{ asset('/assets/') }}/alert/pnotify.js"></script>
<script src="{{ asset('/assets/') }}/alert/notify.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
            $('[data-toggle="tooltip"]').tooltip();
            $("input[type='checkbox']").rcSwitcher();
        });

$(document).ready(function() {
    $('body').on('hidden.bs.modal', '.modal', function () {
      $(this).removeData('bs.modal');
    });
    var table=$("#example").DataTable({
         "searching": true,
         "lengthChange": true,
         "ordering": true,
         stateSave: true       
    });

    $("input[type='checkbox']").rcSwitcher().on({'toggle.rcSwitcher': function( e, dataObj, changeType ){
                var id = $(this).data('id');
                var urll="{{ url('admin/user_active') }}/"+id;
                var msg_success = 'Status Updated Successfully.';
                var msg_error = 'Something went wrong!';
                $.ajax({
                    url:urll,
                    success: function(data){
                      notify('success',msg_success);
                       
                    },
                    error: function (data) {
                        notify('error',msg_error);
                    }
                });
            }
        });
    $('.change-pass').click(function(event) {
            
            var id = $(this).parent('.parent-action-cls').children('input').val();
            $('.change-pass-user-id').val(id);
            
        });

});
</script>
@stop
@if ($message = Session::get('success'))
    <script type="text/javascript">
        $(document).ready(function(){
            var msg = "{{ $message }}";
            notify('success',msg);
        });
    </script>
@endif