

<?php $__env->startSection('title', 'Applications | NEX Finsev'); ?>

<?php $__env->startSection('page-title', 'Applications'); ?>

<?php $__env->startSection(
    'page-description',
    'Manage and review client applications'
); ?>

<?php $__env->startPush('styles'); ?>
<link rel="stylesheet" href="<?php echo e(asset('admin/css/applications.css')); ?>">
<?php $__env->stopPush(); ?>





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


<!-- =====================================================
     PAGE HEADING
====================================================== -->

<div class="page-heading">

    <h2>
        Client Applications
    </h2>

    <p>
        Track application progress, KYC and payment status.
    </p>

</div>



<!-- =====================================================
     STATISTICS
====================================================== -->

<div class="stats-grid">


    <div class="stat-card stat-blue">

        <div class="stat-label">
            Total Applications
        </div>

        <div class="stat-value">
            <?php echo e($totalApplications); ?>

        </div>

        <div class="stat-description">
            Registered client applications
        </div>

    </div>


    <div class="stat-card stat-orange">

        <div class="stat-label">
            Pending KYC
        </div>

        <div class="stat-value">
            <?php echo e($pendingKyc); ?>

        </div>

        <div class="stat-description">
            Awaiting verification
        </div>

    </div>


    <div class="stat-card stat-green">

        <div class="stat-label">
            KYC Verified
        </div>

        <div class="stat-value">
            <?php echo e($verifiedKyc); ?>

        </div>

        <div class="stat-description">
            Verified applications
        </div>

    </div>


    <div class="stat-card stat-purple">

        <div class="stat-label">
            Payment Completed
        </div>

        <div class="stat-value">
            <?php echo e($paidApplications); ?>

        </div>

        <div class="stat-description">
            Successfully paid
        </div>

    </div>


</div>



<!-- =====================================================
     FILTER
====================================================== -->

<div class="filter-card">


    <div class="filter-title">

        Search & Filter Applications

    </div>


    <form
        method="GET"
        action="<?php echo e(route('admin.applications')); ?>"
        class="filter-form"
    >


        <div class="field">

            <label>
                Search
            </label>

            <input
                type="text"
                name="search"
                value="<?php echo e($search); ?>"
                placeholder="Name, email or mobile..."
            >

        </div>


        <div class="field">

            <label>
                KYC Status
            </label>

            <select name="kyc_status">

                <option value="">
                    All KYC
                </option>

                <option
                    value="pending"
                    <?php echo e($kycStatus === 'pending'
                        ? 'selected'
                        : ''); ?>

                >
                    Pending
                </option>

                <option
                    value="verified"
                    <?php echo e($kycStatus === 'verified'
                        ? 'selected'
                        : ''); ?>

                >
                    Verified
                </option>

                <option
                    value="rejected"
                    <?php echo e($kycStatus === 'rejected'
                        ? 'selected'
                        : ''); ?>

                >
                    Rejected
                </option>

            </select>

        </div>


        <div class="field">

            <label>
                Payment Status
            </label>

            <select name="payment_status">

                <option value="">
                    All Payments
                </option>

                <option
                    value="paid"
                    <?php echo e($paymentStatus === 'paid'
                        ? 'selected'
                        : ''); ?>

                >
                    Paid
                </option>

                <option
                    value="pending"
                    <?php echo e($paymentStatus === 'pending'
                        ? 'selected'
                        : ''); ?>

                >
                    Pending
                </option>

                <option
                    value="failed"
                    <?php echo e($paymentStatus === 'failed'
                        ? 'selected'
                        : ''); ?>

                >
                    Failed
                </option>

            </select>

        </div>


        <button
            type="submit"
            class="search-btn"
        >

            🔎 Search

        </button>


        <a
            href="<?php echo e(route('admin.applications')); ?>"
            class="reset-btn"
        >

            Reset

        </a>


    </form>

</div>



<!-- =====================================================
     APPLICATION TABLE
====================================================== -->

<div class="table-card">


    <div class="table-header">

        <h3>
            Applications
        </h3>


        <span class="result-count">

            Showing

            <?php echo e($applications->firstItem() ?? 0); ?>


            -

            <?php echo e($applications->lastItem() ?? 0); ?>


            of

            <?php echo e($applications->total()); ?>


        </span>

    </div>



    <div class="table-wrap">


        <?php if($applications->count()): ?>


            <table>


                <thead>

                    <tr>

                        <th>
                            Client
                        </th>

                        <th>
                            Application
                        </th>

                        <th>
                            KYC
                        </th>

                        <th>
                            Payment
                        </th>

                        <th>
                            Employment
                        </th>

                        <th>
                            Progress
                        </th>

                        <th>
                            Action
                        </th>

                    </tr>

                </thead>


                <tbody>


                    <?php $__currentLoopData = $applications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $application): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>


                        <?php

                            /*
                            |--------------------------------------------------------------------------
                            | Application data
                            |--------------------------------------------------------------------------
                            */

                            $profile =
                                $application->clientProfile;

                            $kyc =
                                $application->clientKyc;

                            $employment =
                                $application->clientEmployment;

                            $payment =
                                $application->payments
                                    ->sortByDesc('created_at')
                                    ->first();


                            /*
                            |--------------------------------------------------------------------------
                            | Completion
                            |--------------------------------------------------------------------------
                            */

                            $profileDone =
                                $profile !== null;

                            $kycDone =
                                $kyc &&
                                $kyc->status === 'verified';

                            $employmentDone =
                                $employment !== null;

                            $paymentDone =
                                $payment &&
                                $payment->status === 'paid';


                            $completed = 0;


                            if ($profileDone) {
                                $completed++;
                            }


                            if ($kycDone) {
                                $completed++;
                            }


                            if ($employmentDone) {
                                $completed++;
                            }


                            if ($paymentDone) {
                                $completed++;
                            }


                            $progress = round(
                                ($completed / 4) * 100
                            );

                        ?>


                        <tr>


                            <!-- CLIENT -->

                            <td>

                                <div class="client">


                                    <div class="client-avatar">

                                        <?php echo e(strtoupper(
                                                substr(
                                                    $application->name,
                                                    0,
                                                    1
                                                )
                                            )); ?>


                                    </div>


                                    <div>

                                        <span class="client-name">

                                            <?php echo e($application->name); ?>


                                        </span>


                                        <span class="client-email">

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


                                        </span>

                                    </div>


                                </div>

                            </td>



                            <!-- APPLICATION -->

                            <td>

                                <?php if($profileDone): ?>

                                    <span class="badge badge-green">

                                        <span class="dot"></span>

                                        Started

                                    </span>

                                <?php else: ?>

                                    <span class="badge badge-gray">

                                        <span class="dot"></span>

                                        Not Started

                                    </span>

                                <?php endif; ?>

                            </td>



                            <!-- KYC -->

                            <td>

                                <?php if(
                                    $kyc &&
                                    $kyc->status === 'verified'
                                ): ?>

                                    <span class="badge badge-green">

                                        <span class="dot"></span>

                                        Verified

                                    </span>


                                <?php elseif(
                                    $kyc &&
                                    $kyc->status === 'rejected'
                                ): ?>

                                    <span class="badge badge-red">

                                        <span class="dot"></span>

                                        Rejected

                                    </span>


                                <?php elseif($kyc): ?>

                                    <span class="badge badge-orange">

                                        <span class="dot"></span>

                                        Pending

                                    </span>


                                <?php else: ?>

                                    <span class="badge badge-gray">

                                        Not Submitted

                                    </span>

                                <?php endif; ?>

                            </td>



                            <!-- PAYMENT -->

                            <td>

                                <?php if(
                                    $payment &&
                                    $payment->status === 'paid'
                                ): ?>

                                    <span class="badge badge-green">

                                        <span class="dot"></span>

                                        Paid

                                    </span>


                                <?php elseif(
                                    $payment &&
                                    in_array(
                                        $payment->status,
                                        [
                                            'created',
                                            'pending'
                                        ]
                                    )
                                ): ?>

                                    <span class="badge badge-orange">

                                        <span class="dot"></span>

                                        Pending

                                    </span>


                                <?php elseif(
                                    $payment &&
                                    in_array(
                                        $payment->status,
                                        [
                                            'failed',
                                            'cancelled',
                                            'cancelled_by_user'
                                        ]
                                    )
                                ): ?>

                                    <span class="badge badge-red">

                                        <span class="dot"></span>

                                        Failed

                                    </span>


                                <?php else: ?>

                                    <span class="badge badge-gray">

                                        Not Paid

                                    </span>

                                <?php endif; ?>

                            </td>



                            <!-- EMPLOYMENT -->

                            <td>

                                <?php if($employmentDone): ?>

                                    <span class="badge badge-green">

                                        <span class="dot"></span>

                                        Completed

                                    </span>

                                <?php else: ?>

                                    <span class="badge badge-gray">

                                        Pending

                                    </span>

                                <?php endif; ?>

                            </td>



                            <!-- PROGRESS -->

                            <td>

                                <div class="progress">

                                    <div
                                        class="progress-bar"
                                        style="
                                            width: <?php echo e($progress); ?>%;
                                        "
                                    ></div>

                                </div>


                                <div class="progress-text">

                                    <?php echo e($progress); ?>% Complete

                                </div>

                            </td>



                            <!-- ACTION -->

                            <td>

                                <a
                                    href="<?php echo e(route(
                                        'admin.clients.show',
                                        $application
                                    )); ?>"
                                    class="view-btn"
                                >

                                    View

                                </a>

                            </td>


                        </tr>


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


                </tbody>


            </table>


        <?php else: ?>


            <div class="empty">

                No applications found.

            </div>


        <?php endif; ?>


    </div>



    <!-- PAGINATION -->

   <?php if($applications->hasPages()): ?>

    <div class="pagination-area">

        <div class="pagination-info">
            Page <?php echo e($applications->currentPage()); ?>

            of <?php echo e($applications->lastPage()); ?>

        </div>

        <div class="pagination-links">

            
            <?php if($applications->onFirstPage()): ?>

                <span class="pagination-btn disabled">
                    ‹
                </span>

            <?php else: ?>

                <a
                    href="<?php echo e($applications->previousPageUrl()); ?>"
                    class="pagination-btn"
                    aria-label="Previous page"
                >
                    ‹
                </a>

            <?php endif; ?>


            
            <?php $__currentLoopData = $applications->getUrlRange(1, $applications->lastPage()); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $page => $url): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                <?php if($page == $applications->currentPage()): ?>

                    <span class="pagination-btn active">
                        <?php echo e($page); ?>

                    </span>

                <?php else: ?>

                    <a
                        href="<?php echo e($url); ?>"
                        class="pagination-btn"
                    >
                        <?php echo e($page); ?>

                    </a>

                <?php endif; ?>

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


            
            <?php if($applications->hasMorePages()): ?>

                <a
                    href="<?php echo e($applications->nextPageUrl()); ?>"
                    class="pagination-btn"
                    aria-label="Next page"
                >
                    ›
                </a>

            <?php else: ?>

                <span class="pagination-btn disabled">
                    ›
                </span>

            <?php endif; ?>

        </div>

    </div>

<?php endif; ?>


</div>


<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\emi-card\resources\views/admin/applications/index.blade.php ENDPATH**/ ?>