

<?php $__env->startSection('title', 'Admin Dashboard'); ?>

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

<section class="container py-3">

    <div class="row g-3">

        <!-- SIDEBAR -->

        <div class="col-12">
            <h3 class="fw-bold mb-0">
                Admin Dashboard
            </h3>
        </div>

        <div class="col-md-3 d-none d-md-block">

            <div class="sidebar">

                <a href="#dashboard-tab" class="active">

                    <i class="fa fa-chart-line"></i>

                    Dashboard

                </a>

                <a href="#users-tab">

                    <i class="fa fa-users"></i>

                    Users

                </a>

                <form method="POST"
                      action="<?php echo e(route('admin.logout')); ?>">

                    <?php echo csrf_field(); ?>

                    <button class="btn btn-primary-custom w-100 mt-3">

                        Logout

                    </button>

                </form>

            </div>

        </div>

        <!-- CONTENT -->

        <div class="col-md-9">
            
            <!-- ADMIN PROFILE -->

<div class="card-custom p-4 mb-4 card-active"
     id="profile-tab">

    <div class="row align-items-center profile-main gy-4">

        <div class="col-12 col-md-12 col-lg-7 col-xl-8">

            <div class="row align-items-center">

                <div class="col-auto">

                    <div class="profile-img">

                        <img src="<?php echo e(asset('assets/images/profile-img.png')); ?>"
                             alt="Admin"
                             class="img-fluid rounded-circle" />

                    </div>

                </div>

                <div class="col">

                    <h4 class="fw-bold mb-1">

                        <?php echo e(auth()->user()->name ?? 'Admin'); ?>


                    </h4>

                    <p class="text-muted mb-2">

                        <i class="fa-regular fa-envelope me-2"></i>

                        <?php echo e(auth()->user()->email ?? 'admin@gmail.com'); ?>


                    </p>

                    <div class="d-flex flex-wrap gap-2">

                        <span class="badge bg-success">

                            ADMIN

                        </span>

                        <span class="badge bg-light text-dark border">

                            Member since
                            <?php echo e(auth()->user()->created_at
                                ? auth()->user()->created_at->format('Y')
                                : 'N/A'); ?>


                        </span>

                    </div>

                    <div class="profile-right-btn-block d-inline-flex d-lg-none mt-2">

                        <form method="POST"
                              action="<?php echo e(route('admin.logout')); ?>">

                            <?php echo csrf_field(); ?>

                            <button class="btn btn-primary-custom profile-right-btn">

                                Logout

                            </button>

                        </form>

                    </div>

                </div>

            </div>

        </div>

        <div class="col-12 col-md-12 col-lg-5 col-xl-4 text-lg-end text-center">

            <div class="profile-right-btn-block d-none d-lg-flex justify-content-end">

                <form method="POST"
                      action="<?php echo e(route('admin.logout')); ?>">

                    <?php echo csrf_field(); ?>

                    <button class="btn btn-primary-custom profile-right-btn">

                        Logout

                    </button>

                </form>

            </div>

        </div>

    </div>

</div>

            <!-- DASHBOARD -->

            <!--<div class="card-custom p-4 mb-4 card-active "-->
            <!--     id="dashboard-tab">-->

            <!--    <div class="row g-3">-->

            <!--        <div class="col-md-4">-->

            <!--            <div class="card-custom text-center p-4">-->

            <!--                <h6>Total Users</h6>-->

            <!--                <h2><?php echo e($totalUsers); ?></h2>-->

            <!--            </div>-->

            <!--        </div>-->

            <!--        <div class="col-md-4">-->

            <!--            <div class="card-custom text-center p-4">-->

            <!--                <h6>Total Loans</h6>-->

            <!--                <h2><?php echo e($totalLoans); ?></h2>-->

            <!--            </div>-->

            <!--        </div>-->

            <!--        <div class="col-md-4">-->

            <!--            <div class="card-custom text-center p-4">-->

            <!--                <h6>Approved Loans</h6>-->

            <!--                <h2><?php echo e($approvedLoans); ?></h2>-->

            <!--            </div>-->

            <!--        </div>-->

            <!--    </div>-->

            <!--</div>-->
            
             <div class="row mb-4 g-2 g-md-3">

                <div class="col-4 col-sm-4 col-md-4">
                    <div class="card-custom px-2 py-3 p-md-4 text-center">
                        <h6>Total Users</h6>
                        <div class="fw-semibold mt-2"><?php echo e($totalUsers); ?></div>
                    </div>
                </div>

                <div class="col-4 col-sm-4 col-md-4">
                    <div class="card-custom px-2 py-3 p-md-4 text-center">
                        <h6>Total Loans</h6>
                        <div class="fw-semibold mt-2">
                            <?php echo e($totalLoans); ?>

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

                <div class="col-4 col-sm-4 col-md-4">
                    <div class="card-custom px-2 py-3 p-md-4 text-center">
                        <h6>Approved Loans</h6>
                        <div class="fw-semibold mt-2">
                            <?php echo e($approvedLoans); ?>

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

            </div>

            <!-- USERS -->

            <div class="card-custom mb-4"
                 id="users-tab">

                <div class="p-3 border-bottom">

                    <h5 class="fw-semibold mb-0">

                        Users List

                    </h5>

                </div>

                <div class="table-responsive">

                    <table class="table align-middle loan-table">

                        <thead>

                            <tr>

                                <th>Name</th>

                                <th>Email</th>

                                <th>Phone</th>

                                <th>Total Loans</th>

                                <th class="text-end">

                                    Action

                                </th>

                            </tr>

                        </thead>

                        <tbody>

                            <?php $__empty_1 = true; $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>

                            <tr>

                               <td>
                                    <?php echo e(optional($user->loanApplications->first())->full_name ?? 'N/A'); ?>

                                </td>

                                <td>

                                    <?php echo e($user->email); ?>


                                </td>

                                <td>

                                    <?php echo e($user->phone); ?>


                                </td>

                                <td>

                                    <?php echo e(\App\Models\LoanApplication::where('user_id', $user->id)->count()); ?>


                                </td>

                                <td class="text-end">

                                    <a href="<?php echo e(route(
                                        'admin.user.loans',
                                        $user->id
                                    )); ?>"
                                       class="btn btn-primary-custom">

                                        View Loans

                                    </a>

                                </td>

                            </tr>

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

                            <tr>

                                <td colspan="5"
                                    class="text-center py-4">

                                    No users found

                                </td>

                            </tr>

                            <?php endif; ?>

                        </tbody>

                    </table>

                </div>

            </div>

        </div>

    </div>

</section>

<script>

const sidebarLinks = document.querySelectorAll(".sidebar a");
const cards = document.querySelectorAll(".card-custom");

sidebarLinks.forEach((link) => {

    link.addEventListener("click", function (e) {

        e.preventDefault();

        sidebarLinks.forEach((item) =>
            item.classList.remove("active")
        );

        this.classList.add("active");

        cards.forEach((card) =>
            card.classList.remove("card-active")
        );

        const targetId = this.getAttribute("href")
            .substring(1);

        const targetCard = document.getElementById(targetId);

        if (targetCard) {

            targetCard.classList.add("card-active");

            window.scrollTo({

                top: targetCard.offsetTop - 90,

                behavior: "smooth",
            });
        }
    });
});

</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/neefc25/public_html/kapstono/resources/views/admin/dashboard.blade.php ENDPATH**/ ?>