<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">

<meta
    name="viewport"
    content="width=device-width,initial-scale=1,maximum-scale=1,viewport-fit=cover"
>

<meta
    name="csrf-token"
    content="<?php echo e(csrf_token()); ?>"
>

<title>Loan Details | EMI CREDITS</title>

<style>

*{
    box-sizing:border-box;
}

html,
body{
    margin:0;
    padding:0;
    background:#eaf0f6;
    color:#172b43;
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Arial,
        sans-serif;
}

a{
    text-decoration:none;
    color:inherit;
}

button,
input,
select,
textarea{
    font-family:inherit;
}

.app{
    max-width:520px;
    min-height:100vh;
    margin:auto;
    background:#f5f7fb;
    padding-bottom:88px;
}


/* =====================================================
   TOP BAR
===================================================== */

.top{
    height:72px;
    background:#fff;
    border-bottom:1px solid #e8edf3;
    display:flex;
    align-items:center;
    gap:11px;
    padding:0 15px;
    position:sticky;
    top:0;
    z-index:20;
}

.back{
    width:38px;
    height:38px;
    border-radius:12px;
    background:#f2f5f9;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:21px;
    color:#304861;
}

.title{
    flex:1;
    min-width:0;
}

.title strong{
    display:block;
    font-size:16px;
    font-weight:900;
}

.title span{
    display:block;
    margin-top:3px;
    font-size:13px;
    color:#8997a8;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

.badge{
    padding:7px 8px;
    border-radius:8px;
    font-size:13px;
    font-weight:900;
    text-transform:uppercase;
    white-space:nowrap;
}

.pending{
    background:#fff5dc;
    color:#9a6700;
}

.approved{
    background:#edf5ff;
    color:#1769e0;
}



.completed{
    background:#eef1f5;
    color:#53667d;
}

.overdue{
    background:#fff0f1;
    color:#b42332;
}

.closed{
    background:#f0f2f5;
    color:#475569;
}

.rejected,
.cancelled{
    background:#fff0f1;
    color:#b42332;
}


/* =====================================================
   CONTENT
===================================================== */

.content{
    padding:14px;
}

.flash{
    padding:11px 12px;
    border-radius:10px;
    margin-bottom:12px;
    font-size:13px;
    font-weight:800;
    line-height:1.5;
}

.flash.success{
    background:#eaf8f0;
    color:#287646;
    border:1px solid #ccebd9;
}

.flash.error{
    background:#fff0f1;
    color:#a52834;
    border:1px solid #f0ccd1;
}


/* =====================================================
   HERO
===================================================== */

.hero{
    background:
        linear-gradient(
            135deg,
            #1769e0,
            #0d4fa8
        );

    color:#fff;
    border-radius:16px;
    padding:18px;
    margin-bottom:12px;
    box-shadow:
        0 8px 22px rgba(23,105,224,.18);
}

.eyebrow{
    font-size:13px;
    font-weight:900;
    text-transform:uppercase;
    letter-spacing:1px;
    opacity:.75;
}

.loan-number{
    margin-top:5px;
    font-size:15px;
    font-weight:900;
}

.amount-label{
    margin-top:18px;
    font-size:13px;
    opacity:.75;
}

.amount{
    margin-top:3px;
    font-size:28px;
    line-height:1.1;
    font-weight:950;
}

.hero-sub{
    margin-top:7px;
    font-size:13px;
    opacity:.78;
}

.hero-grid{
    display:grid;
    grid-template-columns:repeat(3,1fr);
    gap:7px;
    margin-top:18px;
}

.hero-stat{
    padding:10px 8px;
    border:1px solid rgba(255,255,255,.18);
    background:rgba(255,255,255,.08);
    border-radius:10px;
}

.hero-stat span{
    display:block;
    font-size:13px;
    opacity:.7;
}

.hero-stat strong{
    display:block;
    margin-top:4px;
    font-size:14px;
}


/* =====================================================
   CARD
===================================================== */

.card{
    background:#fff;
    border:1px solid #e7ecf2;
    border-radius:10px;
    margin-bottom:12px;
    overflow:hidden;
    box-shadow:
        0 2px 8px rgba(20,40,70,.04);
}

.head{
    min-height:48px;
    padding:12px 14px;
    border-bottom:1px solid #edf1f5;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
}

.head strong{
    font-size:14px;
    font-weight:900;
    color:#172b43;
}

.head span{
    font-size:13px;
    color:#8997a8;
    font-weight:700;
}

.body{
    padding:14px;
}


/* =====================================================
   LOAN SUMMARY
===================================================== */

.grid{
    display:grid;
    grid-template-columns:repeat(2,1fr);
    gap:8px;
}

.stat{
    padding:11px;
    border:1px solid #edf1f5;
    border-radius:10px;
    background:#fafbfd;
}

.stat span{
    display:block;
    font-size:13px;
    color:#8997a8;
}

.stat strong{
    display:block;
    margin-top:4px;
    font-size:14px;
    color:#293f58;
}

.green{
    color:#198754 !important;
}

.orange{
    color:#b26b00 !important;
}

.blue{
    color:#1769e0 !important;
}


/* =====================================================
   PROGRESS
===================================================== */

.progress{
    margin-top:14px;
}

.progress-top{
    display:flex;
    justify-content:space-between;
    gap:10px;
    font-size:13px;
    color:#738397;
    margin-bottom:5px;
}

.track{
    height:7px;
    background:#e8edf3;
    border-radius:20px;
    overflow:hidden;
}

.fill{
    height:100%;
    background:#1769e0;
    border-radius:20px;
}


/* =====================================================
   LOAN INFORMATION
===================================================== */

.info-grid{
    display:grid;
    grid-template-columns:repeat(2,1fr);
    gap:8px;
}

.info{
    padding:10px;
    border:1px solid #edf1f5;
    border-radius:10px;
    background:#fafbfd;
}

.info span{
    display:block;
    font-size:13px;
    color:#8997a8;
}

.info strong{
    display:block;
    margin-top:4px;
    font-size:13px;
    color:#304861;
    word-break:break-word;
}


/* =====================================================
   NOTICE
===================================================== */

.notice{
    padding:12px;
    border-radius:10px;
    background:#fff7e8;
    border:1px solid #f1dfb7;
    color:#8b610b;
    font-size:13px;
    line-height:1.6;
}

.notice.red{
    background:#fff0f1;
    border-color:#f0ccd1;
    color:#a52834;
}

.notice.green{
    background:#eaf8ef;
    border-color:#ccebd9;
    color:#287646;
}


/* =====================================================
   DESKTOP EMI TABLE
===================================================== */

.emi-desktop{
    display:block;
    width:100%;
}

.schedule{
    width:100%;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
}

.emi-table{
    width:100%;
    border-collapse:collapse;
    min-width:650px;
}

.emi-table th{
    background:#f7f9fc;
    color:#738397;
    text-align:left;
    padding:9px 8px;
    font-size:13px;
    text-transform:uppercase;
    white-space:nowrap;
}

.emi-table td{
    padding:10px 8px;
    border-top:1px solid #edf1f5;
    font-size:13px;
    color:#445a72;
    white-space:nowrap;
}

.emi-table strong{
    color:#293f58;
}

.text-end{
    text-align:right !important;
}


/* =====================================================
   EMI STATUS
===================================================== */

.emi-status{
    display:inline-block;
    padding:5px 7px;
    border-radius:7px;
    font-size:13px;
    font-weight:900;
    text-transform:uppercase;
    white-space:nowrap;
}

.emi-status.paid{
    background:#eaf8f0;
    color:#198754;
}

.emi-status.emi-pending{
    background:#fff5dc;
    color:#9a6700;
}

.emi-status.emi-overdue{
    background:#fff0f1;
    color:#b42332;
}

.emi-status.partial{
    background:#edf5ff;
    color:#1769e0;
}

.emi-status.emi-cancelled{
    background:#f3f4f6;
    color:#667085;
}


/* =====================================================
   DESKTOP PAY BUTTON
===================================================== */

.emi-pay-btn{
    min-width:110px;
    min-height:34px;
    padding:7px 12px;
    border:0;
    border-radius:8px;
    background:#2563eb !important;
    border-color:#2563eb !important;
    color:#fff !important;
    font-size:13px;
    font-weight:900;
    cursor:pointer;
    white-space:nowrap;
}

.emi-pay-btn:hover{
    background:#1d4ed8 !important;
}

.emi-paid{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-height:34px;
    padding:7px 11px;
    border-radius:8px;
    background:#eaf8ef;
    color:#198754;
    font-size:13px;
    font-weight:900;
}


/* =====================================================
   MOBILE EMI CARDS
===================================================== */

.emi-mobile{
    display:none;
}

.emi-mobile-card{
    background:#fff;
    border:1px solid #e4eaf1;
    border-radius:10px;
    padding:13px;
    margin-bottom:10px;
    box-shadow:
        0 3px 10px rgba(20,40,70,.05);
}

.emi-mobile-card:last-child{
    margin-bottom:0;
}

.emi-mobile-top{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:10px;
    padding-bottom:12px;
    border-bottom:1px solid #edf1f5;
}

.emi-number{
    font-size:15px;
    font-weight:900;
    color:#172b43;
}

.emi-due{
    margin-top:5px;
    font-size:13px;
    color:#8997a8;
}

.emi-due strong{
    color:#53677f;
    font-weight:800;
}

.emi-mobile-values{
    display:grid;
    grid-template-columns:repeat(3,1fr);
    gap:7px;
    padding:13px 0;
}

.emi-mobile-value{
    min-width:0;
}

.emi-mobile-value span{
    display:block;
    margin-bottom:4px;
    font-size:13px;
    color:#8997a8;
}

.emi-mobile-value strong{
    display:block;
    font-size:14px;
    color:#172b43;
    white-space:nowrap;
}

.emi-mobile-value.outstanding strong{
    color:#dc3545;
}

.emi-mobile-action{
    width:100%;
}

.emi-mobile-action form{
    width:100%;
    margin:0;
}

.emi-mobile-pay-btn{
    width:100%;
    min-height:45px;
    border:0;
    border-radius:10px;
    background:#2563eb;
    color:#fff;
    font-size:14px;
    font-weight:900;
    cursor:pointer;
    box-shadow:
        0 4px 10px rgba(37,99,235,.20);
}

.emi-mobile-pay-btn:hover{
    background:#1d4ed8;
}

.emi-mobile-pay-btn:active{
    transform:scale(.98);
}

.emi-mobile-paid{
    width:100%;
    min-height:43px;
    display:flex;
    align-items:center;
    justify-content:center;
    border-radius:10px;
    background:#eaf8ef;
    color:#198754;
    font-size:14px;
    font-weight:900;
}


/* =====================================================
   EMPTY
===================================================== */

.empty{
    text-align:center;
    padding:25px;
    color:#8997a8;
    font-size:13px;
}

.empty strong{
    display:block;
    color:#53677f;
    font-size:14px;
    margin-bottom:3px;
}


/* =====================================================
   ACTIONS
===================================================== */

.actions{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:8px;
}

.btn{
    display:flex;
    align-items:center;
    justify-content:center;
    min-height:40px;
    border-radius:10px;
    font-size:13px;
    font-weight:900;
}

.light{
    background:#fff;
    border:1px solid #dfe6ee;
    color:#53667f;
}

.bluebtn{
    background:#1769e0;
    color:#fff;
}


/* =====================================================
   BOTTOM NAV
===================================================== */

.nav{
    position:fixed;
    bottom:0;
    left:50%;
    transform:translateX(-50%);
    width:100%;
    max-width:520px;
    height:62px;
    background:#fff;
    border-top:1px solid #e6ebf1;
    display:grid;
    grid-template-columns:repeat(4,1fr);
    z-index:50;
    padding:
        3px
        6px
        calc(4px + env(safe-area-inset-bottom));
    box-shadow:
        0 -8px 24px rgba(31,41,55,.05);
}

.nav a{
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:3px;
    color:#94a3b8;
    font-size:13px;
    font-weight:800;
}

.nav a.active{
    color:#1769e0;
}

.icon{
    font-size:14px;
}


/* =====================================================
   MOBILE RESPONSIVE
===================================================== */

@media(max-width:699px){

    .emi-desktop{
        display:none;
    }

    .emi-mobile{
        display:block;
    }

    .card{
        border-radius:13px;
    }

    .head{
        padding:11px 13px;
    }

    .head strong{
        font-size:14px;
    }

    .content{
        padding:12px;
    }

    .hero{
        padding:16px;
    }

}


/* =====================================================
   SMALL PHONES
===================================================== */

@media(max-width:380px){

    .hero-grid{
        grid-template-columns:1fr 1fr;
    }

    .info-grid{
        grid-template-columns:1fr;
    }

    .actions{
        grid-template-columns:1fr;
    }

    .emi-mobile-values{
        gap:5px;
    }

    .emi-mobile-value strong{
        font-size:13px;
    }

    .emi-number{
        font-size:14px;
    }

    .emi-mobile-card{
        padding:12px;
    }

}


/* =====================================================
   DESKTOP
===================================================== */

@media(min-width:700px){

    body{
        background:#e5ebf2;
    }

    .app{
        box-shadow:
            0 0 50px rgba(31,41,55,.08);
    }

}


</style>

</head>

<body>

<div class="app">

<?php

    $status = strtolower((string) $loan->status);

    $statusClass = match($status) {
        'pending' => 'pending',
        'approved' => 'approved',
        'active',
        'disbursed' => 'active',
        'completed' => 'completed',
        'closed' => 'closed',
        'overdue' => 'overdue',
        'rejected' => 'rejected',
        'cancelled' => 'cancelled',
        default => 'approved'
    };

    $total = (float) $loan->total_payable;

   $outstanding = $status === 'rejected'
    ? 0
    : (float)$loan->outstanding_amount;

    $paid = max(
        0,
        $total - $outstanding
    );

    $percent = $total > 0
        ? min(
            100,
            max(
                0,
                ($paid / $total) * 100
            )
        )
        : 0;

    $installments = $loan->installments
        ->sortBy('installment_number');

?>


<!-- =====================================================
     TOP
====================================================== -->

<header class="top">

    <a
        href="<?php echo e(route('client.loans')); ?>"
        class="back"
    >
        ‹
    </a>

    <div class="title">

        <strong>
            Loan Details
        </strong>

        <span>
            <?php echo e($loan->loan_number); ?>

        </span>

    </div>

    <span class="badge <?php echo e($statusClass); ?>">

        <?php echo e(ucfirst(str_replace('_',' ', $loan->status))); ?>


    </span>

</header>


<main class="content">


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

    <div class="flash success">

        ✓ <?php echo e(session('success')); ?>


    </div>

<?php endif; ?>


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

    <div class="flash error">

        ⚠ <?php echo e(session('error')); ?>


    </div>

<?php endif; ?>


<!-- =====================================================
     HERO
====================================================== -->

<section class="hero">

    <div class="eyebrow">
        Loan Account
    </div>

    <div class="loan-number">
        <?php echo e($loan->loan_number); ?>

    </div>

    <div class="amount-label">
        Total Payable
    </div>

    <div class="amount">
        <?php echo e(money($total)); ?>

    </div>

    <div class="hero-sub">
        0% interest · Processing fee included
    </div>

    <div class="hero-grid">

        <div class="hero-stat">

            <span>
                Loan Amount
            </span>

            <strong>
                <?php echo e(money((float)$loan->loan_amount)); ?>

            </strong>

        </div>

        <div class="hero-stat">

            <span>
                Monthly EMI
            </span>

            <strong>
               <?php echo e(money((float)$loan->emi_amount)); ?>

            </strong>

        </div>

        <div class="hero-stat">

            <span>
                Outstanding
            </span>

            <strong>
                <?php echo e(money($outstanding)); ?>

            </strong>

        </div>

    </div>

</section>


<!-- =====================================================
     LOAN SUMMARY
====================================================== -->

<section class="card">

    <div class="head">

        <strong>
            Loan Summary
        </strong>

        <span>
            Financial details
        </span>

    </div>

    <div class="body">

        <div class="grid">

            <div class="stat">

                <span>
                    Interest Rate
                </span>

                <strong class="green">
                    <?php echo e(number_format((float) $loan->interest_rate, 2)); ?>%
                </strong>

            </div>


            <div class="stat">

                <span>
                    Interest Amount
                </span>

                <strong>
                    <?php echo e(money((float)$loan->interest_amount)); ?>

                </strong>

            </div>


            <div class="stat">

    <span>
        Processing Fee
    </span>

    <strong class="orange">
        <?php echo e(money((float)$loan->processing_fee)); ?>

    </strong>

    <?php if((float)$loan->processing_fee > 0): ?>

        <?php if($loan->processing_fee_paid_at): ?>

            <small
                style="
                    display:block;
                    margin-top:5px;
                    color:#198754;
                    font-size:11px;
                    font-weight:900;
                "
            >
                ✓ PAID
            </small>

            <small
                style="
                    display:block;
                    margin-top:2px;
                    color:#8997a8;
                    font-size:10px;
                "
            >
                <?php echo e($loan->processing_fee_paid_at->format('d M Y, h:i A')); ?>

            </small>

        <?php else: ?>

            <small
                style="
                    display:block;
                    margin-top:5px;
                    color:#b26b00;
                    font-size:11px;
                    font-weight:900;
                "
            >
                ● PAYMENT PENDING
            </small>

        <?php endif; ?>

    <?php else: ?>

        <small
            style="
                display:block;
                margin-top:5px;
                color:#198754;
                font-size:11px;
                font-weight:900;
            "
        >
            ✓ NO FEE
        </small>

    <?php endif; ?>

</div>


            <div class="stat">

                <span>
                    Tenure
                </span>

                <strong>
                    <?php echo e($loan->tenure_months); ?> Months
                </strong>

            </div>


            <div class="stat">

                <span>
                    Paid Amount
                </span>

                <strong class="green">
                   <?php echo e(money($paid)); ?>

                </strong>

            </div>


            <div class="stat">

                <span>
                    Outstanding
                </span>

                <strong class="blue">
                   <?php echo e(money($outstanding)); ?>

                </strong>

            </div>

        </div>


        <div class="progress">

            <div class="progress-top">

                <span>
                    Repayment Progress
                </span>

                <span>
                    <?php echo e(number_format($percent,0)); ?>%
                </span>

            </div>

            <div class="track">

                <div
                    class="fill"
                    style="width:<?php echo e($percent); ?>%"
                ></div>

            </div>

        </div>

    </div>

</section>


<!-- =====================================================
     LOAN TYPE & PRODUCT DETAILS
====================================================== -->

<?php if($loan->loanDetail): ?>

<section class="card">

    <div class="head">

        <strong>
            Loan Type & Product Details
        </strong>

        <span>
            <?php echo e($loan->loanDetail->loanType->name ?? '—'); ?>

        </span>

    </div>

    <div class="body">

        

        <div
            class="info"
            style="margin-bottom:8px;"
        >

            <span>
                Loan Type
            </span>

            <strong>
                <?php echo e($loan->loanDetail->loanType->name ?? '—'); ?>

            </strong>

        </div>


        

        <?php if(
            is_array($loan->loanDetail->details) &&
            count($loan->loanDetail->details)
        ): ?>

            <div class="info-grid">

                <?php $__currentLoopData = $loan->loanDetail->details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                    <?php if(!is_null($value) && $value !== ''): ?>

                        <div class="info">

                            <span>
                                <?php echo e(ucwords(
                                    str_replace(
                                        '_',
                                        ' ',
                                        $key
                                    )
                                )); ?>

                            </span>

                            <strong>

                                <?php if(is_array($value)): ?>

                                    <?php echo e(implode(', ', $value)); ?>


                                <?php else: ?>

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


                                <?php endif; ?>

                            </strong>

                        </div>

                    <?php endif; ?>

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

            </div>

        <?php else: ?>

            <div class="empty">

                No additional product details available.

            </div>

        <?php endif; ?>

    </div>

</section>

<?php endif; ?>


<!-- =====================================================
     LOAN INFORMATION
====================================================== -->

<section class="card">

    <div class="head">

        <strong>
            Loan Information
        </strong>

        <span>
            Timeline
        </span>

    </div>

    <div class="body">

        <div class="info-grid">

            <div class="info">

                <span>
                    EMI Card
                </span>

                <strong>
                    <?php echo e($loan->emiCard?->card_number ?? '—'); ?>

                </strong>

            </div>


            <div class="info">

                <span>
                    Applied On
                </span>

                <strong>
                    <?php echo e($loan->applied_at?->format('d M Y') ?? '—'); ?>

                </strong>

            </div>


            <div class="info">

                <span>
                    Approved On
                </span>

                <strong>
                    <?php echo e($loan->approved_at?->format('d M Y') ?? '—'); ?>

                </strong>

            </div>


            <div class="info">

                <span>
                    Disbursed On
                </span>

                <strong>
                    <?php echo e($loan->disbursed_at?->format('d M Y') ?? '—'); ?>

                </strong>

            </div>


            <div class="info">

                <span>
                    First EMI
                </span>

                <strong>
                    <?php echo e($loan->first_emi_date?->format('d M Y') ?? '—'); ?>

                </strong>

            </div>


            <?php if($loan->completed_at): ?>

                <div class="info">

                    <span>
                        Completed On
                    </span>

                    <strong>
                        <?php echo e($loan->completed_at->format('d M Y')); ?>

                    </strong>

                </div>

            <?php endif; ?>


            <?php if($loan->status === 'closed'): ?>

                <div class="info">

                    <span>
                        Closed On
                    </span>

                    <strong>
                        <?php echo e($loan->closed_at?->format('d M Y') ?? '—'); ?>

                    </strong>

                </div>


                <div class="info">

                    <span>
                        Closed By
                    </span>

                    <strong>
                        <?php echo e($loan->closer?->name ?? 'Admin'); ?>

                    </strong>

                </div>

            <?php endif; ?>

        </div>

    </div>

</section>


<!-- =====================================================
     CLOSED
====================================================== -->

<?php if($loan->status === 'closed'): ?>

<section class="card">

    <div class="body">

        <div class="notice green">

            <strong>
                Loan Closed
            </strong>

            <br>

            This loan has been closed by administration.

            <?php if($loan->closed_at): ?>

                Closed on
                <?php echo e($loan->closed_at->format('d M Y h:i A')); ?>.

                <br>

            <?php endif; ?>

            <?php if($loan->close_reason): ?>

                Reason:
                <?php echo e($loan->close_reason); ?>


            <?php endif; ?>

        </div>

    </div>

</section>

<?php endif; ?>


<!-- =====================================================
     REJECTED
====================================================== -->

<?php if(
    $loan->status === 'rejected'
    && $loan->rejection_reason
): ?>

<section class="card">

    <div class="body">

        <div class="notice red">

            <strong>
                Application Rejected
            </strong>

            <br>

            <?php echo e($loan->rejection_reason); ?>


        </div>

    </div>

</section>

<?php endif; ?>


<!-- =====================================================
     ADMIN NOTE
====================================================== -->

<?php if($loan->admin_notes): ?>

<section class="card">

    <div class="body">

        <div class="notice">

            <strong>
                Admin Note
            </strong>

            <br>

            <?php echo e($loan->admin_notes); ?>


        </div>

    </div>

</section>

<?php endif; ?>


<!-- =====================================================
     EMI SCHEDULE
====================================================== -->

<section class="card">

    <div class="head">

        <strong>
            EMI Schedule
        </strong>

        <span>
            <?php echo e($installments->count()); ?> installments
        </span>

    </div>


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


        <!-- =================================================
             DESKTOP TABLE
        ================================================== -->

        <div class="emi-desktop">

            <div class="schedule">

                <table class="emi-table">

                    <thead>

                        <tr>

                            <th>
                                #
                            </th>

                            <th>
                                Due Date
                            </th>

                            <th>
                                EMI
                            </th>

                            <th>
                                Paid
                            </th>

                            <th>
                                Outstanding
                            </th>

                            <th>
                                Status
                            </th>

                            <th class="text-end">
                                Action
                            </th>

                        </tr>

                    </thead>


                    <tbody>

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

                        <?php

                            $es = strtolower(
                                (string) $installment->status
                            );

                            $ec = match($es) {

                                'paid'
                                    => 'paid',

                                'overdue'
                                    => 'emi-overdue',

                                'partial'
                                    => 'partial',

                                'cancelled'
                                    => 'emi-cancelled',

                                default
                                    => 'emi-pending'

                            };

                        ?>


                        <tr>

                            <td>

                                <strong>
                                    <?php echo e($installment->installment_number); ?>

                                </strong>

                            </td>


                            <td>

                                <?php echo e($installment->due_date
                                        ? \Illuminate\Support\Carbon::parse(
                                            $installment->due_date
                                        )->format('d M Y')
                                        : '—'); ?>


                            </td>


                            <td>

                                <strong>
                                    <?php echo e(money((float)$installment->emi_amount)); ?>

                                </strong>

                            </td>


                            <td>

                               <?php echo e(money((float)$installment->paid_amount)); ?>


                            </td>


                            <td>

                               <?php echo e(money((float)$installment->outstanding_amount)); ?>


                            </td>


                            <td>

                                <span
                                    class="emi-status <?php echo e($ec); ?>"
                                >

                                    <?php echo e(ucfirst(
                                            str_replace(
                                                '_',
                                                ' ',
                                                $installment->status
                                            )
                                        )); ?>


                                </span>

                            </td>


                            <td class="text-end">

                                <?php if(
                                    in_array(
                                        $installment->status,
                                        ['paid','completed'],
                                        true
                                    )
                                ): ?>

                                    <span class="emi-paid">
                                        ✓ PAID
                                    </span>

                                <?php else: ?>

                                    <form
                                        method="POST"
                                        action="<?php echo e(route(
                                                'cashfree.emi.create',
                                                [
                                                    'loanId' =>
                                                        $loan->id,

                                                    'installmentId' =>
                                                        $installment->id,
                                                ]
                                            )); ?>"
                                    >

                                        <?php echo csrf_field(); ?>

                                        <button
                                            type="submit"
                                            class="emi-pay-btn"
                                        >

                                            💳

                                            <?php if(
                                                $installment->status
                                                === 'partial'
                                            ): ?>

                                                PAY BALANCE

                                            <?php else: ?>

                                                PAY EMI

                                            <?php endif; ?>

                                        </button>

                                    </form>

                                <?php endif; ?>

                            </td>

                        </tr>

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

                    </tbody>

                </table>

            </div>

        </div>


        <!-- =================================================
             MOBILE CARDS
        ================================================== -->

        <div class="emi-mobile">

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

            <?php

                $es = strtolower(
                    (string) $installment->status
                );

                $ec = match($es) {

                    'paid'
                        => 'paid',

                    'overdue'
                        => 'emi-overdue',

                    'partial'
                        => 'partial',

                    'cancelled'
                        => 'emi-cancelled',

                    default
                        => 'emi-pending'

                };

            ?>


            <div class="emi-mobile-card">


                <!-- HEADER -->

                <div class="emi-mobile-top">

                    <div>

                        <div class="emi-number">

                            EMI #
                            <?php echo e($installment->installment_number); ?>


                        </div>


                        <div class="emi-due">

                            Due:

                            <strong>

                                <?php echo e($installment->due_date
                                        ? \Illuminate\Support\Carbon::parse(
                                            $installment->due_date
                                        )->format('d M Y')
                                        : '—'); ?>


                            </strong>

                        </div>

                    </div>


                    <span
                        class="emi-status <?php echo e($ec); ?>"
                    >

                        <?php echo e(ucfirst(
                                str_replace(
                                    '_',
                                    ' ',
                                    $installment->status
                                )
                            )); ?>


                    </span>

                </div>


                <!-- VALUES -->

                <div class="emi-mobile-values">


                    <div class="emi-mobile-value">

                        <span>
                            EMI
                        </span>

                        <strong>

                           <?php echo e(money((float)$installment->emi_amount)); ?>


                        </strong>

                    </div>


                    <div class="emi-mobile-value">

                        <span>
                            Paid
                        </span>

                        <strong>

                            <?php echo e(money((float)$installment->paid_amount)); ?>


                        </strong>

                    </div>


                    <div
                        class="emi-mobile-value outstanding"
                    >

                        <span>
                            Outstanding
                        </span>

                        <strong>

                           <?php echo e(money((float)$installment->outstanding_amount)); ?>


                        </strong>

                    </div>


                </div>


                <!-- PAYMENT BUTTON -->

                <div class="emi-mobile-action">


                    <?php if(
                        in_array(
                            $installment->status,
                            ['paid','completed'],
                            true
                        )
                    ): ?>

                        <div class="emi-mobile-paid">

                            ✓ Payment Completed

                        </div>

                    <?php else: ?>


                        <form
                            method="POST"
                            action="<?php echo e(route(
                                    'cashfree.emi.create',
                                    [
                                        'loanId' =>
                                            $loan->id,

                                        'installmentId' =>
                                            $installment->id,
                                    ]
                                )); ?>"
                        >

                            <?php echo csrf_field(); ?>


                            <button
                                type="submit"
                                class="emi-mobile-pay-btn"
                            >

                                💳

                                <?php if(
                                    $installment->status
                                    === 'partial'
                                ): ?>

                                    PAY BALANCE

                                <?php else: ?>

                                    PAY EMI

                                <?php endif; ?>

                            </button>

                        </form>


                    <?php endif; ?>

                </div>

            </div>

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

        </div>


    <?php else: ?>

        <div class="empty">

            <strong>
                EMI schedule not generated yet.
            </strong>

            It will appear after the loan is disbursed.

        </div>

    <?php endif; ?>

</section>


<!-- =====================================================
     PENDING / APPROVED NOTICE
====================================================== -->

<?php if(
    in_array(
        $loan->status,
        ['pending','approved']
    )
): ?>

<section class="card">

    <div class="body">

        <div class="notice">

            <strong>

                <?php echo e($loan->status === 'pending'
                        ? 'Application Under Review'
                        : 'Loan Approved'); ?>


            </strong>

            <br>

            <?php echo e($loan->status === 'pending'
        ? 'Your application is waiting for admin review.'
        : (
            $loan->processing_fee_paid_at
                ? 'Your processing fee has been received. Your loan is ready for disbursement.'
                : 'Your loan is approved. Processing fee payment is pending.'
        )); ?>


        </div>

    </div>

</section>

<?php endif; ?>


<!-- =====================================================
     ACTIONS
====================================================== -->

<section class="card">

    <div class="body">

        <div class="actions">

            <a
                href="<?php echo e(route('client.loans')); ?>"
                class="btn light"
            >
                ← My Loans
            </a>


            <?php if($loan->emiCard): ?>

                <a
                    href="<?php echo e(route('client.emi-card')); ?>"
                    class="btn bluebtn"
                >
                    View EMI Card
                </a>

            <?php endif; ?>

        </div>

    </div>

</section>


</main>


<!-- =====================================================
     COMMON BOTTOM NAV
====================================================== -->

<?php echo $__env->make('client.partials.bottom-nav', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>


</div>

</body>
</html><?php /**PATH /home/eduintxshop/public_html/loan.eduintx.shop/resources/views/client/loans/show.blade.php ENDPATH**/ ?>