@extends('layouts.main')
@section('content')

    @php
        //fetch users with pagination
        if (!empty($_GET['search'])) {
           $neenoe = request()->query('search');
           //where('title','like','%'.$search.'%')
           $users = DB::table('users')->where('status','active')->where('name','like','%'.$neenoe.'%')->orWhere('email','like','%'.$neenoe.'%')->orWhere('phone','like','%'.$neenoe.'%')->paginate(10);
        }else {
            $users = DB::table('users')->where('status','active')->paginate(10);
        }

        
    @endphp
    <div class="col-xl-12 col-md-12">
        <!-- DOM/Jquery table start -->
        <div class="row align-items-end">
            <div class="col-lg-7">
                <div class="page-header-title">
                    <div class="d-inline">
                        <div class="card-header">
                            <h5>Manage Active Users</h5>
                        </div>                       
                    </div>
                </div>
            </div>
            <div class="col-lg-5">
                <div class="page-header-breadcrumb">
                    <div class="col-sm-12">
                        <form method="GET">
                            @csrf
                             <div class="input-group input-group-success">
                                <input type="text" name="search" class="form-control" placeholder="Enter username/Trans ID">
                                <button class="input-group-addon">
                                    <i data-feather="search" class="menuicons icon-search f-15"></i>
                                </button>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h5>Manage Active Users</h5>
            </div>
            <div class="card-block">
                <div class="table-responsive dt-responsive">
                    <table id="dom-jqry" class="table table-striped table-bordered nowrap">
                        <thead>
                            <tr>
                                <th>Join Time</th>
                                <th>Full Name</th>
                               
                                <th>Username</th>
                                <th>Email</th>
                                <th>Phone</th>
                                <th>Balance</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if ($users->count() > 0)
                                @foreach ($users as $user)
                                    <tr>
                                        <td style="text-transform: capitalize">
                                            {{ \Carbon\Carbon::parse($user->created_at)->diffForHumans() }}
                                        </td>
                                      
                                        <td style="text-transform: capitalize">
                                            {{ $user->name }}
                                        </td>
                                        <td style="text-transform: lowercase">
                                            <a href="/users/user/{{ $user->id }}">
                                                <u>
                                                    {{ $user->username }}
                                                </u>
                                            </a>
                                        </td>
                                        <td style="text-transform: lowercase">
                                            {{ $user->email }}
                                            </td>
                                        <td>{{ $user->phone }}</td>
                                        <td>
                                            KES.{{ $user->balance }}
                                        </td>
                                        <td>
                                            <a href="{{ env('APP_URL') }}/users/user/{{ $user->id }}"
                                               
                                                class="btn btn-success btn-mini  f-18">
                                                <i class="menuicons" data-feather="eye"></i>
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach
                            @else
                                <tr>
                                    <td><p>No user Found</p></td>
                                </tr>
                            @endif



                        </tbody>
                    </table>
                </div>
                <div class="card-footer py-4">
                    <div class="row">
                        {!! $users->withQueryString()->links('pagination::bootstrap-5') !!}
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
@endsection
