

<?php $__env->startSection('title', 'EMI Cards | EMI CREDITS'); ?>

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

<?php $__env->startSection(
    'page-description',
    'Manage client EMI cards'
); ?>


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

<style>
/* =====================================================
   EMI CARD MODALS
   Unique classes - no existing CSS override
====================================================== */

.emi-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;

    align-items: center;
    justify-content: center;

    padding: 20px;

    background: rgba(15, 23, 42, 0.55);
}

.emi-modal-overlay.show {
    display: flex;
}

.emi-modal {
    width: 100%;
    max-width: 480px;

    background: #ffffff;

    border-radius: 14px;

    box-shadow:
        0 25px 70px rgba(0, 0, 0, 0.20);

    overflow: hidden;

    position: relative;

    animation: emiModalShow .18s ease-out;
}

@keyframes emiModalShow {
    from {
        opacity: 0;
        transform: translateY(8px) scale(.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.emi-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;

    padding: 18px 20px;

    border-bottom: 1px solid #edf1f6;
}

.emi-modal-header h3 {
    margin: 0;

    color: #273b59;

    font-size: 15px;
    font-weight: 800;
}

.emi-modal-close {
    width: 31px;
    height: 31px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 0;
    border-radius: 8px;

    background: #f1f5f9;
    color: #64748b;

    font-size: 20px;
    line-height: 1;

    cursor: pointer;
}

.emi-modal-close:hover {
    background: #e2e8f0;
    color: #273b59;
}

.emi-modal-body {
    padding: 20px;
}

.emi-form-group {
    margin-bottom: 15px;
}

.emi-form-label {
    display: block;

    margin-bottom: 7px;

    color: #64748b;

    font-size: 10px;
    font-weight: 800;

    text-transform: uppercase;
    letter-spacing: .4px;
}

.emi-form-control {
    width: 100%;
    height: 40px;

    box-sizing: border-box;

    padding: 0 11px;

    border: 1px solid #dce4ef;
    border-radius: 8px;

    outline: none;

    color: #344966;
    background: #ffffff;

    font-size: 11px;
}

.emi-form-control:focus {
    border-color: #1769e0;
    box-shadow: 0 0 0 3px rgba(23, 105, 224, .08);
}

.emi-modal-info-box {
    padding: 13px;

    background: #f8fafc;

    border: 1px solid #e7edf4;
    border-radius: 8px;

    color: #64748b;

    font-size: 10px;
    line-height: 1.6;
}

.emi-modal-info-box strong {
    color: #344966;
}

.emi-modal-warning-box {
    padding: 12px;

    background: #fff7e8;

    border: 1px solid #fde68a;
    border-radius: 8px;

    color: #92400e;

    font-size: 10px;
    line-height: 1.5;
}

.emi-modal-footer {
    display: flex;

    align-items: center;
    justify-content: flex-end;

    gap: 8px;

    padding: 15px 20px;

    border-top: 1px solid #edf1f6;
}

.emi-cancel-btn,
.emi-save-btn {
    min-height: 35px;

    padding: 0 14px;

    border-radius: 7px;

    font-size: 10px;
    font-weight: 800;

    cursor: pointer;
}

.emi-cancel-btn {
    border: 1px solid #dce4ef;

    background: #ffffff;
    color: #64748b;
}

.emi-cancel-btn:hover {
    background: #f8fafc;
}

.emi-save-btn {
    border: 0;

    background: #1769e0;
    color: #ffffff;
}

.emi-save-btn:hover {
    background: #1258be;
}


/* =====================================================
   PAGINATION
====================================================== */

.pagination-area {
    padding: 14px 17px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 10px;
}

.pagination-info {
    color: #9aa6b6;
    font-size: 10px;
    font-weight: 600;
}

.pagination-links {
    display: flex;
    align-items: center;
    gap: 6px;
}

.page-btn {
    min-width: 36px;
    height: 36px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 0 10px;

    box-sizing: border-box;

    border: 1px solid #dce4ef;
    border-radius: 8px;

    background: #ffffff;
    color: #64748b;

    font-size: 11px;
    font-weight: 800;

    text-decoration: none;

    line-height: 1;
}

.page-btn:hover {
    border-color: #1769e0;
    color: #1769e0;
    background: #f8fbff;
}

.page-btn.active {
    border-color: #1769e0;

    background: #1769e0;
    color: #ffffff;
}

.page-btn.disabled {
    background: #f8fafc;
    color: #cbd5e1;

    cursor: default;
}

.page-btn.disabled:hover {
    border-color: #dce4ef;
    color: #cbd5e1;
    background: #f8fafc;
}


/* =====================================================
   MOBILE MODAL
====================================================== */

@media (max-width: 600px) {

    .emi-modal-overlay {
        padding: 14px;
    }

    .emi-modal {
        max-width: 100%;
        border-radius: 12px;
    }

    .emi-modal-header {
        padding: 15px 16px;
    }

    .emi-modal-header h3 {
        font-size: 14px;
    }

    .emi-modal-body {
        padding: 16px;
    }

    .emi-modal-footer {
        padding: 13px 16px;
    }

    .emi-modal-footer button {
        flex: 1;
    }

    .pagination-area {
        align-items: center;
    }

    .pagination-info {
        font-size: 9px;
    }

    .pagination-links {
        gap: 4px;
    }

    .page-btn {
        min-width: 34px;
        height: 34px;

        padding: 0 8px;

        font-size: 10px;
    }
}
</style>
<?php $__env->stopPush(); ?>



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

<div class="emi-page">


    

    <?php if(session('success')): ?>

        <div class="alert-box alert-success">
            ✓ <?php echo e(session('success')); ?>

        </div>

    <?php endif; ?>


    <?php if(session('error')): ?>

        <div class="alert-box alert-error">
            ✕ <?php echo e(session('error')); ?>

        </div>

    <?php endif; ?>


    <?php if($errors->any()): ?>

        <div class="alert-box alert-error">

            <strong>
                Please check:
            </strong>

            <ul style="margin:5px 0 0 18px;">

                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                    <li>
                        <?php echo e($error); ?>

                    </li>

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

            </ul>

        </div>

    <?php endif; ?>



    

    <div class="page-heading">

        <h2>
            EMI Card Management
        </h2>

        <p>
            Generate, activate, block and manage client EMI cards.
        </p>

    </div>



    

    <div class="stats-grid">

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

            <div class="stat-label">
                Active Cards
            </div>

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

            </div>

        </div>


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

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

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

            </div>

        </div>


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

            <div class="stat-label">
                Blocked Cards
            </div>

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

            </div>

        </div>


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

            <div class="stat-label">
                Expired Cards
            </div>

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

            </div>

        </div>

    </div>



    

    <div class="generate-bar">

        <div>

            <div class="generate-title">
                Generate New EMI Card
            </div>

            <div class="generate-description">

                Eligible clients must have completed
                Personal Details, verified KYC and Job Details.

            </div>

        </div>


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

            <button
                type="button"
                class="primary-btn"
                onclick="openGenerateModal()"
            >
                + Generate EMI Card
            </button>

        <?php else: ?>

            <span class="badge badge-expired">
                No Eligible Clients
            </span>

        <?php endif; ?>

    </div>



    

    <div class="filter-card">

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

            <input
                type="text"
                name="search"
                value="<?php echo e($search); ?>"
                class="filter-input"
                placeholder="Search client name, email, mobile or card number..."
            >


            <select
                name="status"
                class="filter-select"
            >

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

                <option
                    value="pending"
                    <?php if($status === 'pending'): echo 'selected'; endif; ?>
                >
                    Pending
                </option>

                <option
                    value="active"
                    <?php if($status === 'active'): echo 'selected'; endif; ?>
                >
                    Active
                </option>

                <option
                    value="blocked"
                    <?php if($status === 'blocked'): echo 'selected'; endif; ?>
                >
                    Blocked
                </option>

                <option
                    value="expired"
                    <?php if($status === 'expired'): echo 'selected'; endif; ?>
                >
                    Expired
                </option>

            </select>


            <button
                type="submit"
                class="filter-btn"
            >
                Search
            </button>


            <?php if($search !== '' || $status): ?>

                <a
                    href="<?php echo e(route('admin.emi-cards')); ?>"
                    class="clear-btn"
                >
                    Clear
                </a>

            <?php endif; ?>

        </form>

    </div>



    

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

        <div
            class="table-card"
            style="margin-bottom:18px;"
        >

            <div class="table-header">

                <h3>
                    Eligible Clients
                </h3>

                <span class="result-count">

                    <?php echo e($eligibleClientCount); ?>

                    available

                </span>

            </div>


            <div class="table-wrap">

                <table>

                    <thead>

                        <tr>

                            <th>
                                Client
                            </th>

                            <th>
                                Verification
                            </th>

                            <th>
                                Action
                            </th>

                        </tr>

                    </thead>


                    <tbody>

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

                            <tr>

                                <td>

                                    <div class="client">

                                        <div class="client-avatar">

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


                                        </div>


                                        <div>

                                            <span class="client-name">

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


                                            </span>


                                            <span class="client-email">

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


                                                <?php if($client->mobile): ?>

                                                    ·
                                                    <?php echo e($client->mobile); ?>


                                                <?php endif; ?>

                                            </span>

                                        </div>

                                    </div>

                                </td>


                                <td>

                                    <span class="badge badge-active">
                                        <span class="dot"></span>
                                        Personal
                                    </span>

                                    <span class="badge badge-active">
                                        <span class="dot"></span>
                                        KYC
                                    </span>

                                    <span class="badge badge-active">
                                        <span class="dot"></span>
                                        Job
                                    </span>

                                </td>


                                <td>

                                    <button
                                        type="button"
                                        class="small-btn approve-btn"
                                        onclick="openGenerateModal(
                                            <?php echo e($client->id); ?>,
                                            <?php echo \Illuminate\Support\Js::from($client->name)->toHtml() ?>
                                        )"
                                    >
                                        + Generate Card
                                    </button>

                                </td>

                            </tr>

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

                    </tbody>

                </table>

            </div>

        </div>

    <?php endif; ?>



    

    <div class="table-card">

        <div class="table-header">

            <h3>
                EMI Cards
            </h3>

            <span class="result-count">

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

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

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


            </span>

        </div>


        <div class="table-wrap">

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

                <table>

                    <thead>

                        <tr>

                            <th>Client</th>

                            <th>Card Number</th>

                            <th>Limit</th>

                            <th>Available</th>

                            <th>Payment</th>

                            <th>Expiry</th>

                            <th>Status</th>

                            <th>Loans</th>

                            <th>Actions</th>

                        </tr>

                    </thead>


                    <tbody>

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

                            <?php

                                $user = $card->user;

                                $name =
                                    $user->name
                                    ?? 'Unknown Client';

                                $email =
                                    $user->email
                                    ?? '';

                                $initial =
                                    strtoupper(
                                        substr(
                                            $name,
                                            0,
                                            1
                                        )
                                    );


                                $hasPaidPayment =
                                    $user
                                        ? $user->payments()
                                            ->where(
                                                'status',
                                                'paid'
                                            )
                                            ->exists()
                                        : false;


                                $isExpired =
                                    $card->expires_at &&
                                    $card->expires_at->isPast();

                            ?>


                            <tr>


                                

                                <td>

                                    <div class="client">

                                        <div class="client-avatar">
                                            <?php echo e($initial); ?>

                                        </div>

                                        <div>

                                            <span class="client-name">
                                                <?php echo e($name); ?>

                                            </span>

                                            <?php if($email): ?>

                                                <span class="client-email">
                                                    <?php echo e($email); ?>

                                                </span>

                                            <?php endif; ?>

                                        </div>

                                    </div>

                                </td>



                                

                                <td>

                                    <span class="card-number">
                                        <?php echo e($card->card_number); ?>

                                    </span>

                                </td>



                                

                                <td>

                                    <span class="money">
                                        <?php echo e(money((float)($card->card_limit ?? 0))); ?>

                                    </span>

                                </td>



                                

                                <td>

                                    <span class="money">
                                        <?php echo e(money((float)($card->available_limit ?? 0))); ?>

                                    </span>


                                    <?php if($card->status === 'active'): ?>

                                        <div class="available">
                                            Available
                                        </div>

                                    <?php endif; ?>

                                </td>



                                

                                <td>

                                    <?php if($hasPaidPayment): ?>

                                        <span class="payment-paid">
                                            ✓ Paid
                                        </span>

                                    <?php else: ?>

                                        <span class="payment-pending">
                                            ⏳ Pending
                                        </span>

                                    <?php endif; ?>

                                </td>



                                

                                <td>

                                    <?php if($card->expires_at): ?>

                                        <span
                                            style="
                                                color:
                                                <?php echo e($isExpired
                                                        ? '#be123c'
                                                        : '#64748b'); ?>;
                                                font-size:10px;
                                                font-weight:800;
                                                white-space:nowrap;
                                            "
                                        >
                                            <?php echo e($card->expires_at->format('d M Y')); ?>

                                        </span>

                                    <?php else: ?>

                                        -

                                    <?php endif; ?>

                                </td>



                                

                                <td>

                                    <?php if($isExpired): ?>

                                        <span class="badge badge-expired">

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

                                            Expired

                                        </span>

                                    <?php else: ?>

                                        <?php switch($card->status):

                                            case ('pending'): ?>

                                                <span class="badge badge-pending">

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

                                                    Pending

                                                </span>

                                                <?php break; ?>


                                            <?php case ('active'): ?>

                                                <span class="badge badge-active">

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

                                                    Active

                                                </span>

                                                <?php break; ?>


                                            <?php case ('blocked'): ?>

                                                <span class="badge badge-blocked">

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

                                                    Blocked

                                                </span>

                                                <?php break; ?>


                                            <?php case ('expired'): ?>

                                                <span class="badge badge-expired">

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

                                                    Expired

                                                </span>

                                                <?php break; ?>


                                            <?php default: ?>

                                                <span class="badge badge-expired">
                                                    <?php echo e(ucfirst($card->status)); ?>

                                                </span>

                                        <?php endswitch; ?>

                                    <?php endif; ?>

                                </td>



                                

                                <td>

                                    <?php if($user && method_exists($user, 'loans')): ?>

                                        <?php

                                            $activeLoanCount =
                                                $user->loans()
                                                    ->whereIn(
                                                        'status',
                                                        [
                                                            'approved',
                                                            'disbursed',
                                                            'active',
                                                            'overdue'
                                                        ]
                                                    )
                                                    ->count();

                                        ?>


                                        <?php if($activeLoanCount > 0): ?>

                                            <span class="badge badge-active">

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

                                                <?php echo e($activeLoanCount); ?> Active

                                            </span>

                                        <?php else: ?>

                                            <span class="badge badge-expired">
                                                No Active Loan
                                            </span>

                                        <?php endif; ?>

                                    <?php else: ?>

                                        <span class="badge badge-expired">
                                            —
                                        </span>

                                    <?php endif; ?>

                                </td>



                                

                                <td>

                                    <div class="action-buttons">


                                        

                                        <a
                                            href="<?php echo e(route(
                                                'admin.emi-cards.show',
                                                $card
                                            )); ?>"
                                            class="small-btn view-btn"
                                        >
                                            View
                                        </a>



                                        

                                        <?php if(
                                            $card->status === 'pending' &&
                                            !$isExpired
                                        ): ?>


                                            

                                            <button
                                                type="button"
                                                class="small-btn limit-btn"
                                                onclick="openLimitModal(
                                                    <?php echo e($card->id); ?>,
                                                    <?php echo \Illuminate\Support\Js::from($name)->toHtml() ?>,
                                                    <?php echo e($card->card_limit ?? 0); ?>

                                                )"
                                            >
                                                Limit
                                            </button>



                                            

                                            <?php if($hasPaidPayment): ?>

                                                <?php if((float)$card->card_limit > 0): ?>

                                                    <form
                                                        method="POST"
                                                        action="<?php echo e(route(
                                                            'admin.emi-cards.approve',
                                                            $card
                                                        )); ?>"
                                                        style="display:inline;"
                                                    >

                                                        <?php echo csrf_field(); ?>

                                                        <button
                                                            type="submit"
                                                            class="small-btn approve-btn"
                                                            onclick="
                                                                return confirm(
                                                                    'Approve and activate this EMI Card?'
                                                                )
                                                            "
                                                        >
                                                            ✓ Activate
                                                        </button>

                                                    </form>

                                                <?php else: ?>

                                                    <span class="small-btn disabled-btn">
                                                        Set Limit
                                                    </span>

                                                <?php endif; ?>

                                            <?php else: ?>

                                                <span class="small-btn disabled-btn">
                                                    Payment Pending
                                                </span>

                                            <?php endif; ?>

                                        <?php endif; ?>



                                        

                                        <?php if(
                                            $card->status === 'active' &&
                                            !$isExpired
                                        ): ?>

                                            <form
                                                method="POST"
                                                action="<?php echo e(route(
                                                    'admin.emi-cards.block',
                                                    $card
                                                )); ?>"
                                                style="display:inline;"
                                            >

                                                <?php echo csrf_field(); ?>

                                                <button
                                                    type="submit"
                                                    class="small-btn block-btn"
                                                    onclick="
                                                        return confirm(
                                                            'Are you sure you want to block this EMI Card?'
                                                        )
                                                    "
                                                >
                                                    Block
                                                </button>

                                            </form>

                                        <?php endif; ?>



                                        

                                        <?php if($card->status === 'blocked'): ?>

                                            <?php if(!$isExpired): ?>

                                                <form
                                                    method="POST"
                                                    action="<?php echo e(route(
                                                        'admin.emi-cards.activate',
                                                        $card
                                                    )); ?>"
                                                    style="display:inline;"
                                                >

                                                    <?php echo csrf_field(); ?>

                                                    <button
                                                        type="submit"
                                                        class="small-btn approve-btn"
                                                        onclick="
                                                            return confirm(
                                                                'Activate this blocked EMI Card?'
                                                            )
                                                        "
                                                    >
                                                        ✓ Activate
                                                    </button>

                                                </form>

                                            <?php else: ?>

                                                <span class="small-btn disabled-btn">
                                                    Expired
                                                </span>

                                            <?php endif; ?>

                                        <?php endif; ?>



                                        

                                        <?php if($card->status === 'expired'): ?>

                                            <span class="small-btn disabled-btn">
                                                Expired
                                            </span>

                                        <?php endif; ?>


                                    </div>

                                </td>

                            </tr>

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

                    </tbody>

                </table>


            <?php else: ?>

                <div class="empty">

                    <div
                        style="
                            font-size:30px;
                            margin-bottom:8px;
                        "
                    >
                        💳
                    </div>

                    No EMI cards found.

                </div>

            <?php endif; ?>

        </div>



        

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

            <div class="pagination-area">

                <div class="pagination-info">

                    Page
                    <?php echo e($cards->currentPage()); ?>

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


                </div>


                <div class="pagination-links">


                    

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

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

                    <?php else: ?>

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

                    <?php endif; ?>



                    

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

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

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

                            </span>

                        <?php else: ?>

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

                            </a>

                        <?php endif; ?>

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



                    

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

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

                    <?php else: ?>

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

                    <?php endif; ?>

                </div>

            </div>

        <?php endif; ?>


    </div>


</div>





<div
    id="generateModal"
    class="emi-modal-overlay"
    onclick="closeGenerateModal(event)"
>

    <div
        class="emi-modal"
        onclick="event.stopPropagation()"
    >


        <div class="emi-modal-header">

            <h3>
                Generate EMI Card
            </h3>


            <button
                type="button"
                class="emi-modal-close"
                onclick="closeGenerateModal()"
            >
                ×
            </button>

        </div>


        <form
            method="POST"
            action="<?php echo e(route(
                'admin.emi-cards.generate'
            )); ?>"
        >

            <?php echo csrf_field(); ?>


            <div class="emi-modal-body">


                <div class="emi-form-group">

                    <label class="emi-form-label">
                        Select Client
                    </label>


                    <select
                        name="user_id"
                        id="generateClient"
                        class="emi-form-control"
                        required
                    >

                        <option value="">
                            Select eligible client
                        </option>


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

                            <option
                                value="<?php echo e($client->id); ?>"
                            >
                                <?php echo e($client->name); ?>

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

                            </option>

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

                    </select>

                </div>


                <div class="emi-modal-info-box">

                    <strong>
                        New EMI Card
                    </strong>

                    <br><br>

                    Status:
                    <strong>
                        Pending
                    </strong>

                    <br>

                    Loan Limit:
                    <strong>
                        <?php echo e(money(0)); ?>

                    </strong>

                    <br>

                    Card will be activated only after
                    payment and admin approval.

                </div>


            </div>


            <div class="emi-modal-footer">


                <button
                    type="button"
                    class="emi-cancel-btn"
                    onclick="closeGenerateModal()"
                >
                    Cancel
                </button>


                <button
                    type="submit"
                    class="emi-save-btn"
                >
                    Generate Card
                </button>


            </div>


        </form>


    </div>

</div>





<div
    id="limitModal"
    class="emi-modal-overlay"
    onclick="closeLimitModal(event)"
>

    <div
        class="emi-modal"
        onclick="event.stopPropagation()"
    >


        <div class="emi-modal-header">

            <h3>
                Update Loan Limit
            </h3>


            <button
                type="button"
                class="emi-modal-close"
                onclick="closeLimitModal()"
            >
                ×
            </button>

        </div>


        <form
            method="POST"
            id="limitForm"
        >

            <?php echo csrf_field(); ?>

            <?php echo method_field('PUT'); ?>


            <div class="emi-modal-body">


                <div
                    style="
                        margin-bottom:14px;
                        color:#64748b;
                        font-size:11px;
                    "
                >

                    Client:

                    <strong
                        id="limitClientName"
                        style="color:#273b59;"
                    ></strong>

                </div>


                <div class="emi-form-group">

                    <label class="emi-form-label">
                        Loan Limit
                    </label>


                    <input
                        type="number"
                        name="card_limit"
                        id="cardLimit"
                        class="emi-form-control"
                        min="0"
                        step="0.01"
                        required
                    >

                </div>


                <div class="emi-modal-warning-box">

                    Changing the loan limit does not
                    activate the card.

                    <br>

                    Payment and admin approval are still
                    required.

                </div>


            </div>


            <div class="emi-modal-footer">


                <button
                    type="button"
                    class="emi-cancel-btn"
                    onclick="closeLimitModal()"
                >
                    Cancel
                </button>


                <button
                    type="submit"
                    class="emi-save-btn"
                >
                    Save Limit
                </button>


            </div>


        </form>


    </div>

</div>


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



<?php $__env->startPush('scripts'); ?>

<script>

/*
|--------------------------------------------------------------------------
| Generate Modal
|--------------------------------------------------------------------------
*/

function openGenerateModal(clientId = '')
{
    const modal =
        document.getElementById('generateModal');

    const select =
        document.getElementById('generateClient');


    if (select && clientId) {

        select.value = clientId;

    }


    if (modal) {

        modal.classList.add('show');

        document.body.style.overflow = 'hidden';

    }
}


function closeGenerateModal(event = null)
{
    if (
        event &&
        event.target &&
        event.target.id !== 'generateModal'
    ) {
        return;
    }


    const modal =
        document.getElementById('generateModal');


    if (modal) {

        modal.classList.remove('show');

        document.body.style.overflow = '';

    }
}



/*
|--------------------------------------------------------------------------
| Limit Modal
|--------------------------------------------------------------------------
*/

function openLimitModal(
    cardId,
    clientName,
    currentLimit
)
{
    const modal =
        document.getElementById('limitModal');

    const form =
        document.getElementById('limitForm');

    const name =
        document.getElementById('limitClientName');

    const input =
        document.getElementById('cardLimit');


    if (!modal || !form) {

        return;

    }


    form.action =
        "<?php echo e(url('/admin/emi-cards')); ?>"
        + "/"
        + cardId
        + "/limit";


    if (name) {

        name.textContent =
            clientName;

    }


    if (input) {

        input.value =
            currentLimit ?? 0;

    }


    modal.classList.add('show');

    document.body.style.overflow = 'hidden';
}


function closeLimitModal(event = null)
{
    if (
        event &&
        event.target &&
        event.target.id !== 'limitModal'
    ) {
        return;
    }


    const modal =
        document.getElementById('limitModal');


    if (modal) {

        modal.classList.remove('show');

        document.body.style.overflow = '';

    }
}



/*
|--------------------------------------------------------------------------
| Escape Key
|--------------------------------------------------------------------------
*/

document.addEventListener(
    'keydown',
    function(event)
    {
        if (event.key === 'Escape') {

            const generateModal =
                document.getElementById('generateModal');

            const limitModal =
                document.getElementById('limitModal');


            if (
                generateModal &&
                generateModal.classList.contains('show')
            ) {

                closeGenerateModal();

            }


            if (
                limitModal &&
                limitModal.classList.contains('show')
            ) {

                closeLimitModal();

            }

        }
    }
);

</script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/eduintxshop/public_html/loan.eduintx.shop/resources/views/admin/emi-cards/index.blade.php ENDPATH**/ ?>