
<?php $__env->startSection('content'); ?>

    <div id="main">
        <header class="mb-3">
            <a href="#" class="burger-btn d-block d-xl-none">
                <i class="bi bi-justify fs-3"></i>
            </a>
            <div class="container mt-5">
                <div class="d-flex justify-content-between">
                    <div></div>
                    <div class="ms-auto">
                        <style>
                            .border7{
                               border:  1px solid #fff!important
                            }
                        </style>
                       

                        <div class="dropdown">
                        <span class=""
                                id="dropdownMenuButtonSec" data-bs-toggle="dropdown"
                                aria-haspopup="true" aria-expanded="false">
                             <img class="border7" src="<?php echo e(url('assets/images/faces/8.jpg')); ?>" height="50" width="50" style="border-radius: 50px;">
                        </span>
                        <div class="dropdown-menu" style="min-width:150px !important; padding: 7px !important; height: 120px;" aria-labelledby="dropdownMenuButtonSec">

                            <li><a href="<?php echo e(url('update/profile')); ?>">
                            <i class="fa fa-edit" aria-hidden="true" style="color:;"></i>

                            <span> Update Profile</span>
                       </a></li>
                            <hr>
                              <li>
                        <a href="<?php echo e(url('auth/logout')); ?>" class='sidebar-link'>
                            <i class="fa fa-sign-out" aria-hidden="true" style="color: #d1342c;"></i>

                            <span>Logout</span>
                        </a>
                    </li>
                    <hr>
                              <li></li>

                        </div>
                    </div>

                    </div>
                </div>
            </div>

        </header>

        <?php if(session('success')): ?>
                <div class="alert alert-success"><i class="bi bi-check-circle"></i> <?php echo e(session('success')); ?></div>
            <?php endif; ?>
            <?php if(session('error')): ?>
                <div class="alert alert-danger"><i class="bi bi-exclamation-triangle"></i>
                    <?php echo e(session('error')); ?>

                </div>
            <?php endif; ?>
        <?php if(Auth::user()->role ==2): ?>

        <?php
        $sub = App\Models\Subscription::where('user_id',Auth::user()->id)->where('status',1)->first();
       if($sub)
       {
        $endDate = \Carbon\Carbon::parse($sub->end_date);

        // Calculate the number of days remaining
        $daysRemaining = now()->diffInDays($endDate);

        $pc= App\Models\Package::where('id',$sub->package)->first();
       }

        $wallet = App\Models\Wallet::where('user_id',Auth::user()->id)->first();



        ?>
            <div class="page-heading">
                <h3>Welcome Back <?php echo e(Auth::user()->name); ?></h3>
            </div>

             <?php if(session('success')): ?>
                <div class="alert alert-success"><i class="bi bi-check-circle"></i> <?php echo e(session('success')); ?></div>
            <?php endif; ?>
            <?php if(session('error')): ?>
                <div class="alert alert-danger"><i class="bi bi-exclamation-triangle"></i>
                    <?php echo e(session('error')); ?>

                </div>
            <?php endif; ?>

            <?php if(session('success')): ?>
                <div class="alert alert-success"><i class="bi bi-check-circle"></i> <?php echo e(session('success')); ?></div>
            <?php endif; ?>
            <?php if(session('error')): ?>
                <div class="alert alert-danger"><i class="bi bi-exclamation-triangle"></i>
                    <?php echo e(session('error')); ?>

                </div>
            <?php endif; ?>
            <div class="page-content">
                <section class="row">
                    <div class="col-12 col-lg-12">
                        <div class="row">



                        <div class="row">
                            <div class="col-12 col-xl-6">
                                <div class="card">
                                    <div class="card-header">
                                        <h4>Account Balance</h4>
                                    </div>
                                    <div class="card-body">
                                        <div class="row">

                                                <div class="">
                                                    <h6 class="mb-0">Ksh <?php echo e($wallet->amount); ?> <span class="btn btn-info btn-sm"  data-bs-toggle="modal" data-bs-target="#topModalCenter">Top Up</span></h6>
                                                </div><br><br>
                                                <div class="d-flex align-items-center">
                                                    <p class="mb-0">Service days remaining</p>
                                                        </p>
                                                </div>
                                                <div class="d-flex align-items-center">
                                                  <?php if($sub): ?>
                                                    <span class="badge bg-success"> <?php echo e($daysRemaining); ?> days until (<?php echo e($sub->end_date); ?>)</span>
                                                    <?php else: ?>
                                                     <span class="badge bg-danger">Subscription Expired</span>
                                                    <?php endif; ?>
                                                </div>
                                                <br><br>
                                                <div class="">
                                                    <p class="">The approximate number of days during which services will be provided based on the amount on the account balance
                                                    </p>
                                                </div>

                                        </div>


                                    </div>
                                </div>
                            </div>


                            <div class="col-12 col-xl-6">
                                <div class="card">
                                    <div class="card-header">
                                        <h4>My Service
                                        </h4>
                                    </div>
                                    <div class="card-body">
                                        <div class="row">
                                            <div class="col-12">
                                                <div class="d-flex align-items-center">
                                                   <table class="table table-striped" id="">
                                                        <thead>
                                                        <tr>
                                                            <th>Service</th>
                                                            <th>Plan</th>
                                                            <th>Status</th>
                                                            <th>Price</th>

                                                        </tr>
                                                        </thead>
                                                        <tbody>

                                                            <?php if($sub): ?>

                                                        <tr>

                                                        <td>Internet</td>
                                                           <td><?php echo e($pc->name); ?></td>
                                                           <td>
                                                            <?php if($online_status == 'online'): ?>
                                                            <span class="badge bg-success"><?php echo e('online'); ?></span></td>
                                                            <?php endif; ?>
                                                             <?php if($online_status == 'offline'): ?>
                                                            <span class="badge bg-danger"><?php echo e('offline'); ?></span></td>
                                                            <?php endif; ?>

                                                           <td>Ksh <?php echo e(number_format($pc->price,2)); ?></td>

                                                        </tr>
                                                        <?php endif; ?>



                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>

                    </div>
                </section>
                <div class="page-heading">
                    <h3></h3>
                    <hr>
                </div>
                <section class="row">
                    <div class="col-12 col-lg-9">
                        <div class="row">

                            <div class="row">


                            </div>
                        </div>

                    </div>
                </section>
            </div>

            <div class="modal fade" id="topModalCenter" tabindex="-1" role="dialog"
                 aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered modal-dialog-centered modal-dialog-scrollable"
                     role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalCenterTitle">Top your up subscription
                            </h5>
                            <button type="button" class="close" data-bs-dismiss="modal"
                                    aria-label="Close">
                                <i data-feather="x"></i>
                            </button>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-md-6 col-12">
                                    <div class="form-group">
                                        <label for="first-name-column">Phone</label>
                                        <input type="text" id="first-name-column" class="form-control <?php $__errorArgs = ['phone'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                               placeholder="Phone" name="phone" value="<?php echo e(Auth::user()->phone); ?>">
                                        <?php $__errorArgs = ['phone'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <span class="invalid-feedback" role="alert">
                                                            <strong><?php echo e($message); ?></strong>
                                                        </span>
                                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                    </div>
                                </div>
                                <div class="col-md-6 col-12">
                                    <div class="form-group">
                                        <label for="first-name-column">Amount</label>
                                        <input type="text" id="first-name-column" class="form-control <?php $__errorArgs = ['amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                               placeholder="Amount" name="amount" value="">
                                        <?php $__errorArgs = ['amount'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <span class="invalid-feedback" role="alert">
                                                            <strong><?php echo e($message); ?></strong>
                                                        </span>
                                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                    </div>
                                </div>
                                <p>Or go to lipa na mpesa paybill <br>
                                    paybill number: 247247 <br>
                                    account number: 206206
                                </p>

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-light-secondary"
                                        data-bs-dismiss="modal">
                                    <span class="" style="color: #2f3742">Close</span>
                                </button>
                                <button type="button" class="btn btn-primary ml-1"
                                        data-bs-dismiss="modal">

                                    <span style="color:#fff;">Accept</span>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

        <?php endif; ?>

        <?php if(Auth::user()->role == 1): ?>
        <div class="page-heading">
            <h3>Statistics</h3>
        </div>
        <div class="page-content">
            <section class="row">
                <div class="col-12 col-lg-12">
                    <div class="row">
                        <div class="col-6 col-lg-3 col-md-6">
                            <div class="card">
                                <div class="card-body px-3 py-4-5">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="stats-icon purple">
                                                <i class="fa fa-users" aria-hidden="true"></i>

                                            </div>
                                        </div>
                                        <div class="col-md-8">
                                            <h6 class="text-muted font-semibold">All Users</h6>
                                            <h6 class="font-extrabold mb-0"><?php echo e($users); ?></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-6 col-lg-3 col-md-6">
                            <div class="card">
                                <div class="card-body px-3 py-4-5">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <a href="<?php echo e(url('users?status=1')); ?>">
                                            <div class="stats-icon blue">
                                                <i class="iconly-boldProfile"></i>
                                            </div>
                                        </a>
                                        </div>
                                        
                                        <div class="col-md-8">
                                            <a href="<?php echo e(url('users?status=1')); ?>">
                                            <h6 class="text-muted font-semibold">Active Users</h6>
                                            <h6 class="font-extrabold mb-0"><?php echo e($totalActiveUsers); ?></h6>
                                             </a>
                                        </div>
                                   
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-6 col-lg-3 col-md-6">
                            <div class="card">
                                <div class="card-body px-3 py-4-5">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="stats-icon green">
                                               <i class="fa fa-money" aria-hidden="true"></i>

                                            </div>
                                        </div>
                                        <div class="col-md-8">
                                            <h6 class="text-muted font-semibold">Total Earnings</h6>
                                            <h6 class="font-extrabold mb-0">Ksh <?php echo e($total_earnings); ?></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                          <div class="col-6 col-lg-3 col-md-6">
                            <div class="card">
                                <div class="card-body px-3 py-4-5">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="stats-icon red">
                                               <i class="fa fa-money" aria-hidden="true"></i>

                                            </div>
                                        </div>
                                        <div class="col-md-8">
                                            <h6 class="text-muted font-semibold">Earnings This Month</h6>
                                            <h6 class="font-extrabold mb-0">Ksh <?php echo e($earning_month); ?></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-6 col-lg-3 col-md-6">
                            <div class="card">
                                <div class="card-body px-3 py-4-5">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="stats-icon blue">
                                                <i class="fa fa-users" aria-hidden="true"></i>
                                            </div>
                                        </div>
                                        <div class="col-md-8">
                                            <h6 class="text-muted font-semibold">Hotspot Users</h6>
                                            <h6 class="font-extrabold mb-0"><?php echo e($totalHotspotUsers); ?></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-6 col-lg-3 col-md-6">
                            <div class="card">
                                <div class="card-body px-3 py-4-5">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="stats-icon green">
                                                <i class="iconly-boldAdd-User"></i>
                                            </div>
                                        </div>
                                        <div class="col-md-8">
                                            <h6 class="text-muted font-semibold">PPOE Users</h6>
                                            <h6 class="font-extrabold mb-0"><?php echo e($totalpppoeUsers); ?></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-6 col-lg-3 col-md-6">
                            <div class="card">
                                <div class="card-body px-3 py-4-5">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="stats-icon red">
                                                <i class="fa fa-wifi" aria-hidden="true"></i>

                                            </div>
                                        </div>
                                        <div class="col-md-8">
                                            <h6 class="text-muted font-semibold">Online Users</h6>
                                            <h6 class="font-extrabold mb-0"><?php echo e($onlineUsers); ?></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-6 col-lg-3 col-md-6">
                            <div class="card">
                                <div class="card-body px-3 py-4-5">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="stats-icon green">
                                                <i class="fa fa-ticket" aria-hidden="true"></i>

                                            </div>
                                        </div>
                                        <div class="col-md-8">
                                            <h6 class="text-muted font-semibold">Open Tickets</h6>
                                            <h6 class="font-extrabold mb-0"><?php echo e($open_tickets); ?></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <div class="card-header">
                                                                        <?php
                                        $currentYear = date('Y');
                                    ?>
                                    <h4>Monthly Earnings Year <?php echo e($currentYear); ?> </h4>
                                </div>
                                <div class="card-body">
                                    <div id="chart"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>
                    <?php if(Auth::user()->role == 3): ?>
                        <div class="page-heading">
                            <h3>Statistics</h3>
                        </div>
                        <div class="page-content">
                            <section class="row">
                                <div class="col-12 col-lg-12">
                                    <div class="row">




                                        <div class="col-6 col-lg-3 col-md-6">
                                            <div class="card">
                                                <div class="card-body px-3 py-4-5">
                                                    <div class="row">
                                                        <div class="col-md-4">
                                                            <div class="stats-icon green">
                                                                <i class="fa fa-ticket" aria-hidden="true"></i>

                                                            </div>
                                                        </div>
                                                        <div class="col-md-8">
                                                            <h6 class="text-muted font-semibold">Open Tickets</h6>
                                                            <h6 class="font-extrabold mb-0"><?php echo e($open_tickets); ?></h6>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                    </div>
                                    <div class="row">
                                        <div class="col-12">
                                            <div class="card">
                                                <div class="card-header">

                                                    <h4>Open Tickets</h4>
                                                    <a href="<?php echo e(url('tickets/create')); ?>" class="btn btn-primary pull-right"><i class="fa fa-plus" aria-hidden="true"></i>
                                                        New Ticket</a>
                                                </div>
                                                <div class="card-body">

                                                                        <div class="card-body">
                                                                            <table class="table table-striped" id="table1">
                                                                                <thead>
                                                                                <tr>
                                                                                    <th>User</th>
                                                                                    <th>Region</th>
                                                                                    <th>Location</th>
                                                                                    <th>Subject</th>
                                                                                    <th>Message</th>
                                                                                    <th>Status</th>


                                                                                    <th>Actions</th>
                                                                                </tr>
                                                                                </thead>
                                                                                <tbody>
                                                                                <?php $__currentLoopData = $tickets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ticket): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                                                    <tr>
                                                                                        <?php
                                                                                            $user = App\Models\User::where('id',$ticket->user_id)->first();


                                                                                            $region = App\Models\Region::where('id',$user->region)->first();


                                                                                        ?>
                                                                                        <td><?php echo e($user->name); ?></td>
                                                                                        <?php if($region): ?>
                                                                                            <td><?php echo e($region->name); ?></td>
                                                                                        <?php else: ?>
                                                                                            <td>N/A</td>
                                                                                        <?php endif; ?>
                                                                                        <td><?php echo e($user->location); ?></td>
                                                                                        <td><?php echo e($ticket->subject); ?></td>
                                                                                        <td><?php echo e($ticket->message); ?></td>

                                                                                        <?php if($ticket->status == 1): ?>
                                                                                            <td>
                                                                                                <span class="badge bg-success">Success</span>
                                                                                            </td>
                                                                                        <?php else: ?>

                                                                                            <td>
                                                                                                <span class="badge bg-warning">Pending</span>
                                                                                            </td>

                                                                                        <?php endif; ?>

                                                                                        <td>
                                                                                            <div class="btn-group mb-1">
                                                                                                <div class="dropdown">
                                                                                                    <button class="btn btn-secondary btn-sm dropdown-toggle me-1" type="button"
                                                                                                            id="dropdownMenuButtonSec" data-bs-toggle="dropdown"
                                                                                                            aria-haspopup="true" aria-expanded="false">
                                                                                                        Actions
                                                                                                    </button>
                                                                                                    <div class="dropdown-menu" style="min-width:10px !important;" aria-labelledby="dropdownMenuButtonSec">

                                                                                                        <a class="dropdown-item" href="<?php echo e(url('tickets/view',$ticket->id)); ?>"><i class="fa fa-eye" aria-hidden="true" style="color: #7c8db5;"></i>
                                                                                                            view</a>

                                                                                                        <a class="dropdown-item" href="<?php echo e(url('tickets/edit',$ticket->id)); ?>"><i class="fa fa-pencil-square-o" aria-hidden="true" style="color: #7c8db5;"></i>
                                                                                                            Edit</a>
                                                                                                        <a class="dropdown-item" href="<?php echo e(url('tickets/mark/solved',$ticket->id)); ?>"><i class="fa fa-pencil-square-o" aria-hidden="true" style="color: #7c8db5;"></i>
                                                                                                            Mark Resolved</a>
                                                                                                        <a class="dropdown-item" href="<?php echo e(url('tickets/delete',$ticket->id)); ?>"><i class="fa fa-trash" aria-hidden="true" style="color: #7c8db5;"></i>
                                                                                                            Delete</a>

                                                                                                    </div>
                                                                                                </div>
                                                                                            </div>
                                                                                        </td>

                                                                                    </tr>

                                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                                                </tbody>
                                                                            </table>
                                                                        </div>
                                                                    </div>


                                                        </div>
                                            </div>
                                        </div>
                                    </div>
                    <?php endif; ?>

                    <script>
    fetch('<?php echo e(route('payments.api')); ?>')
        .then(response => {
            if (!response.ok) {

                throw new Error('Network response was not ok');
            }
            return response.json();
        })
        .then(data => {
            
                var options  = {

                    annotations: {
                        position: 'back'
                    },
                    dataLabels: {
                        enabled: false
                    },
                    chart: {
                        toolbar: {
                            show: false,
                        },
                        type: 'line',
                        height: 300
                    },
                    fill: {
                        opacity: 1
                    },
                    plotOptions: {
                    },
                    series: [{
                        name: 'Earnings',
                        type: 'column',
                        data: data.totals
                    }],
                    stroke: {
                        width: [0, 1, 2],
                        curve: 'straight'
                    },
                    colors: ['#57caeb'],

                    xaxis: {
                        categories: data.months,
                        labels: {
                            hideOverlappingLabels: true,
                        },
                    },
                }

                var chart = new ApexCharts(document.querySelector("#chart"), options);
                chart.render();

        })
        .catch(error => {
        });
</script>


<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\xampp\htdocs\swiftnet\resources\views/dashboard/index.blade.php ENDPATH**/ ?>