<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>লোন রিপোর্ট - <?php echo e(config('app.name', 'Laravel')); ?></title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <!-- Select2 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <style>
        body {
            font-family: 'SolaimanLipi', 'Siyam Rupali', Arial, sans-serif;
            background-color: #f8f9fa;
        }
        .card {
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
            border: none;
        }
        .card-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 10px 10px 0 0 !important;
            padding: 15px 20px;
        }
        .stat-card {
            transition: transform 0.3s;
            border-left: 4px solid;
        }
        .stat-card:hover {
            transform: translateY(-5px);
        }
        .bg-primary-light {
            background-color: rgba(102, 126, 234, 0.1) !important;
            border-left-color: #667eea !important;
        }
        .bg-success-light {
            background-color: rgba(40, 167, 69, 0.1) !important;
            border-left-color: #28a745 !important;
        }
        .bg-warning-light {
            background-color: rgba(255, 193, 7, 0.1) !important;
            border-left-color: #ffc107 !important;
        }
        .bg-danger-light {
            background-color: rgba(220, 53, 69, 0.1) !important;
            border-left-color: #dc3545 !important;
        }
        .bg-info-light {
            background-color: rgba(23, 162, 184, 0.1) !important;
            border-left-color: #17a2b8 !important;
        }
        .table th {
            background-color: #f8f9fa;
            font-weight: 600;
            border-top: none;
        }
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
        }
        .btn-primary:hover {
            opacity: 0.9;
        }
        .filter-box {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }
        .total-box {
            font-size: 1.8rem;
            font-weight: bold;
            color: #2c3e50;
        }
        .currency {
            font-size: 0.9rem;
            color: #7f8c8d;
        }
        .badge-status {
            font-size: 0.75rem;
            padding: 0.35em 0.65em;
        }
        @media print {
            .no-print {
                display: none !important;
            }
            .card {
                box-shadow: none !important;
                border: 1px solid #dee2e6 !important;
            }
            .table {
                font-size: 12px;
            }
        }
        .select2-container--default .select2-selection--single {
            height: 38px;
            border: 1px solid #ced4da;
            border-radius: 0.25rem;
        }
        .select2-container--default .select2-selection--single .select2-selection__rendered {
            line-height: 36px;
        }
        .select2-container--default .select2-selection--single .select2-selection__arrow {
            height: 36px;
        }
        .loan-row {
            transition: all 0.3s;
        }
        .loan-row:hover {
            background-color: #f8f9fa;
            transform: scale(1.002);
        }
        .progress {
            height: 20px;
            border-radius: 10px;
        }
        .progress-bar {
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <div class="container-fluid py-4">
        <!-- Header -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h2 class="mb-1"><i class="fas fa-handshake me-2"></i>লোন রিপোর্ট</h2>
                        <p class="text-muted mb-0"><?php echo e(now()->format('d F Y, h:i A')); ?></p>
                    </div>
                    <div class="no-print">
                        <a href="<?php echo e(route('reports.summary')); ?>" class="btn btn-outline-primary me-2">
                            <i class="fas fa-chart-line me-1"></i> সারাংশ
                        </a>
                        <a href="<?php echo e(route('reports.monthly')); ?>" class="btn btn-outline-secondary">
                            <i class="fas fa-calendar-alt me-1"></i> মাসিক রিপোর্ট
                        </a>
                    </div>
                </div>
                <hr>
            </div>
        </div>

        <!-- Filter Section -->
        <div class="row mb-4 no-print">
            <div class="col-12">
                <div class="filter-box">
                    <form method="GET" action="<?php echo e(route('reports.loans')); ?>" class="row g-3">
                        <div class="col-md-4">
                            <label for="status" class="form-label">স্ট্যাটাস নির্বাচন করুন</label>
                            <select class="form-control" id="status" name="status">
                                <option value="all" <?php echo e($status == 'all' ? 'selected' : ''); ?>>সকল লোন</option>
                                <option value="active" <?php echo e($status == 'active' ? 'selected' : ''); ?>>সক্রিয় লোন</option>
                                <option value="approved" <?php echo e($status == 'approved' ? 'selected' : ''); ?>>অনুমোদিত লোন</option>
                                <option value="disbursed" <?php echo e($status == 'disbursed' ? 'selected' : ''); ?>>বিতরণকৃত লোন</option>
                                <option value="completed" <?php echo e($status == 'completed' ? 'selected' : ''); ?>>সম্পন্ন লোন</option>
                                <option value="defaulted" <?php echo e($status == 'defaulted' ? 'selected' : ''); ?>>ডিফল্ট লোন</option>
                                <option value="overdue" <?php echo e($status == 'overdue' ? 'selected' : ''); ?>>বকেয়া লোন</option>
                            </select>
                        </div>
                        <div class="col-md-4 d-flex align-items-end">
                            <button type="submit" class="btn btn-primary me-2">
                                <i class="fas fa-search me-1"></i> রিপোর্ট দেখুন
                            </button>
                            <button type="submit" name="download" value="1" class="btn btn-success">
                                <i class="fas fa-download me-1"></i> PDF ডাউনলোড
                            </button>
                        </div>
                        <div class="col-md-4 text-end d-flex align-items-end">
                            <a href="<?php echo e(route('reports.loans')); ?>" class="btn btn-outline-secondary">
                                <i class="fas fa-sync-alt me-1"></i> রিসেট ফিল্টার
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- Selected Status Info -->
        <div class="row mb-4">
            <div class="col-12">
                <?php
                    $status_text = [
                        'all' => 'সকল লোন',
                        'active' => 'সক্রিয় লোন',
                        'approved' => 'অনুমোদিত লোন',
                        'disbursed' => 'বিতরণকৃত লোন',
                        'completed' => 'সম্পন্ন লোন',
                        'defaulted' => 'ডিফল্ট লোন',
                        'overdue' => 'বকেয়া লোন'
                    ];
                ?>
                <div class="alert alert-info">
                    <h5 class="alert-heading mb-2">
                        <i class="fas fa-filter me-2"></i>
                        নির্বাচিত স্ট্যাটাস: 
                        <strong><?php echo e($status_text[$status] ?? 'সকল লোন'); ?></strong>
                    </h5>
                    <p class="mb-0">
                        <i class="fas fa-info-circle me-1"></i>
                        নিচের সারণীতে <?php echo e($status_text[$status] ?? 'সকল লোন'); ?> দেখানো হয়েছে।
                        মোট <?php echo e($loans->count()); ?>টি লোন পাওয়া গেছে।
                    </p>
                </div>
            </div>
        </div>

        <!-- Loan Summary Statistics -->
        <div class="row mb-4">
            <!-- Active Loans -->
            <div class="col-xl-2 col-lg-4 col-md-6 mb-4">
                <div class="card stat-card bg-primary-light">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="text-muted mb-1">সক্রিয় লোন</h6>
                                <h3 class="total-box"><?php echo e($total_active); ?></h3>
                                <small class="text-muted">
                                    <i class="fas fa-running me-1"></i>
                                    চলমান লোন
                                </small>
                            </div>
                            <div class="display-4 text-primary opacity-50">
                                <i class="fas fa-spinner"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Completed Loans -->
            <div class="col-xl-2 col-lg-4 col-md-6 mb-4">
                <div class="card stat-card bg-success-light">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="text-muted mb-1">সম্পন্ন লোন</h6>
                                <h3 class="total-box"><?php echo e($total_completed); ?></h3>
                                <small class="text-muted">
                                    <i class="fas fa-check-circle me-1"></i>
                                    পরিশোধ সম্পন্ন
                                </small>
                            </div>
                            <div class="display-4 text-success opacity-50">
                                <i class="fas fa-check"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Overdue Loans -->
            <div class="col-xl-2 col-lg-4 col-md-6 mb-4">
                <div class="card stat-card bg-danger-light">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="text-muted mb-1">বকেয়া লোন</h6>
                                <h3 class="total-box"><?php echo e($total_overdue); ?></h3>
                                <small class="text-muted">
                                    <i class="fas fa-clock me-1"></i>
                                    সময়োত্তীর্ণ
                                </small>
                            </div>
                            <div class="display-4 text-danger opacity-50">
                                <i class="fas fa-exclamation-triangle"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Total Loan Amount -->
            <div class="col-xl-3 col-lg-6 col-md-6 mb-4">
                <div class="card stat-card bg-warning-light">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h6 class="text-muted mb-1">মোট লোন পরিমাণ</h6>
                                <h3 class="total-box">
                                    <?php echo e(number_format($total_loan_amount, 2)); ?> <span class="currency">টাকা</span>
                                </h3>
                                <small class="text-muted">
                                    <i class="fas fa-money-bill-wave me-1"></i>
                                    সমস্ত লোন
                                </small>
                            </div>
                            <div class="display-4 text-warning opacity-50">
                                <i class="fas fa-hand-holding-usd"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Paid vs Due -->
            <div class="col-xl-3 col-lg-6 col-md-6 mb-4">
                <div class="card stat-card bg-info-light">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-6">
                                <h6 class="text-muted mb-1">পরিশোধিত</h6>
                                <h4 class="text-success">
                                    <?php echo e(number_format($total_paid_amount, 2)); ?> <small class="currency">টাকা</small>
                                </h4>
                                <small class="text-muted">
                                    <i class="fas fa-check-circle me-1"></i>
                                    মোট পরিশোধ
                                </small>
                            </div>
                            <div class="col-6">
                                <h6 class="text-muted mb-1">বকেয়া</h6>
                                <h4 class="text-danger">
                                    <?php echo e(number_format($total_due_amount, 2)); ?> <small class="currency">টাকা</small>
                                </h4>
                                <small class="text-muted">
                                    <i class="fas fa-clock me-1"></i>
                                    মোট বাকি
                                </small>
                            </div>
                        </div>
                        <?php if($total_loan_amount > 0): ?>
                            <?php
                                $paid_percentage = ($total_paid_amount / $total_loan_amount) * 100;
                                $due_percentage = ($total_due_amount / $total_loan_amount) * 100;
                            ?>
                        <div class="progress mt-3">
                            <div class="progress-bar bg-success" role="progressbar" 
                                 style="width: <?php echo e($paid_percentage); ?>%" 
                                 aria-valuenow="<?php echo e($paid_percentage); ?>" 
                                 aria-valuemin="0" 
                                 aria-valuemax="100">
                                <?php echo e(number_format($paid_percentage, 1)); ?>%
                            </div>
                            <div class="progress-bar bg-danger" role="progressbar" 
                                 style="width: <?php echo e($due_percentage); ?>%" 
                                 aria-valuenow="<?php echo e($due_percentage); ?>" 
                                 aria-valuemin="0" 
                                 aria-valuemax="100">
                                <?php echo e(number_format($due_percentage, 1)); ?>%
                            </div>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <!-- Loans Table -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <div class="d-flex justify-content-between align-items-center">
                            <h5 class="mb-0">
                                <i class="fas fa-list me-2"></i>
                                লোনের তালিকা (মোট: <?php echo e($loans->count()); ?>টি)
                            </h5>
                            <span class="badge bg-primary">
                                <i class="fas fa-filter me-1"></i> <?php echo e($status_text[$status] ?? 'সকল'); ?>

                            </span>
                        </div>
                    </div>
                    <div class="card-body">
                        <?php if(count($loans) > 0): ?>
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>লোন নম্বর</th>
                                            <th>সদস্যের নাম</th>
                                            <th>সদস্য আইডি</th>
                                            <th class="text-end">লোন পরিমাণ</th>
                                            <th class="text-end">বকেয়া</th>
                                            <th class="text-end">পরিশোধিত</th>
                                            <th>স্ট্যাটাস</th>
                                            <th>তারিখ</th>
                                            <th class="no-print">কার্যক্রম</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__currentLoopData = $loans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $loan): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?php
                                                // Calculate paid amount and percentage
                                                $loan_paid = $loan->loan_amount - $loan->remaining_balance;
                                                $paid_percentage = $loan->loan_amount > 0 ? ($loan_paid / $loan->loan_amount) * 100 : 0;
                                                
                                                // Status colors
                                                $status_colors = [
                                                    'pending' => 'warning',
                                                    'approved' => 'info',
                                                    'disbursed' => 'primary',
                                                    'active' => 'success',
                                                    'completed' => 'secondary',
                                                    'defaulted' => 'danger'
                                                ];
                                                $status_color = $status_colors[$loan->status] ?? 'secondary';
                                            ?>
                                            <tr class="loan-row">
                                                <td><?php echo e($key + 1); ?></td>
                                                <td>
                                                    <strong><?php echo e($loan->loan_number ?? 'N/A'); ?></strong>
                                                </td>
                                                <td>
                                                    <strong><?php echo e($loan->member->name ?? 'N/A'); ?></strong>
                                                    <?php if($loan->member && $loan->member->committee): ?>
                                                        <br>
                                                        <small class="text-muted">
                                                            <?php echo e($loan->member->committee->name ?? ''); ?>

                                                        </small>
                                                    <?php endif; ?>
                                                </td>
                                                <td><?php echo e($loan->member->member_id ?? 'N/A'); ?></td>
                                                <td class="text-end">
                                                    <strong class="text-warning"><?php echo e(number_format($loan->loan_amount, 2)); ?> টাকা</strong>
                                                </td>
                                                <td class="text-end">
                                                    <span class="text-danger"><?php echo e(number_format($loan->remaining_balance, 2)); ?> টাকা</span>
                                                </td>
                                                <td class="text-end">
                                                    <span class="text-success"><?php echo e(number_format($loan_paid, 2)); ?> টাকা</span>
                                                    <br>
                                                    <small class="text-muted"><?php echo e(number_format($paid_percentage, 1)); ?>%</small>
                                                </td>
                                                <td>
                                                    <span class="badge bg-<?php echo e($status_color); ?> badge-status">
                                                        <?php if($loan->status == 'pending'): ?>
                                                            <i class="fas fa-clock me-1"></i> পেন্ডিং
                                                        <?php elseif($loan->status == 'approved'): ?>
                                                            <i class="fas fa-check me-1"></i> অনুমোদিত
                                                        <?php elseif($loan->status == 'disbursed'): ?>
                                                            <i class="fas fa-money-check me-1"></i> বিতরণকৃত
                                                        <?php elseif($loan->status == 'active'): ?>
                                                            <i class="fas fa-running me-1"></i> সক্রিয়
                                                        <?php elseif($loan->status == 'completed'): ?>
                                                            <i class="fas fa-check-circle me-1"></i> সম্পন্ন
                                                        <?php elseif($loan->status == 'defaulted'): ?>
                                                            <i class="fas fa-exclamation-triangle me-1"></i> ডিফল্ট
                                                        <?php else: ?>
                                                            <?php echo e($loan->status); ?>

                                                        <?php endif; ?>
                                                    </span>
                                                </td>
                                                <td>
                                                    <?php if($loan->loan_date): ?>
                                                        <?php echo e(date('d/m/Y', strtotime($loan->loan_date))); ?>

                                                    <?php else: ?>
                                                        <?php echo e(date('d/m/Y', strtotime($loan->created_at))); ?>

                                                    <?php endif; ?>
                                                </td>
                                                <td class="no-print">
                                                    <div class="btn-group" role="group">
                                                        <a href="<?php echo e(route('reports.member.detailed', $loan->member->id ?? $loan->member_id)); ?>" 
                                                           class="btn btn-sm btn-outline-primary" 
                                                           title="সদস্য বিস্তারিত">
                                                            <i class="fas fa-user"></i>
                                                        </a>
                                                        <?php if($loan->remaining_balance > 0): ?>
                                                            <button type="button" 
                                                                    class="btn btn-sm btn-outline-warning" 
                                                                    title="বকেয়া লোন">
                                                                <i class="fas fa-clock"></i>
                                                            </button>
                                                        <?php endif; ?>
                                                    </div>
                                                </td>
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                    <tfoot class="table-active">
                                        <tr>
                                            <td colspan="4" class="text-end"><strong>মোট:</strong></td>
                                            <td class="text-end">
                                                <strong class="text-warning"><?php echo e(number_format($total_loan_amount, 2)); ?> টাকা</strong>
                                            </td>
                                            <td class="text-end">
                                                <strong class="text-danger"><?php echo e(number_format($total_due_amount, 2)); ?> টাকা</strong>
                                            </td>
                                            <td class="text-end">
                                                <strong class="text-success"><?php echo e(number_format($total_paid_amount, 2)); ?> টাকা</strong>
                                            </td>
                                            <td colspan="3"></td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        <?php else: ?>
                            <div class="text-center py-5">
                                <i class="fas fa-handshake fa-3x text-muted mb-3"></i>
                                <h5 class="text-muted">কোনো লোন পাওয়া যায়নি</h5>
                                <p class="text-muted">
                                    "<?php echo e($status_text[$status] ?? 'সকল লোন'); ?>" ক্যাটাগরিতে কোনো লোন নেই।
                                </p>
                                <a href="<?php echo e(route('reports.loans')); ?>?status=all" class="btn btn-primary">
                                    <i class="fas fa-list me-1"></i> সকল লোন দেখুন
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <!-- Status Summary -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-chart-pie me-2"></i>লোন স্ট্যাটাস সারাংশ</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-8">
                                <div class="table-responsive">
                                    <table class="table table-bordered">
                                        <thead>
                                            <tr>
                                                <th>স্ট্যাটাস</th>
                                                <th class="text-center">লোন সংখ্যা</th>
                                                <th class="text-center">মোট পরিমাণ</th>
                                                <th class="text-center">বকেয়া</th>
                                                <th class="text-center">পরিশোধিত</th>
                                                <th class="text-center">পরিশোধের হার</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                                $status_counts = [
                                                    'active' => $total_active,
                                                    'completed' => $total_completed,
                                                    'approved' => $total_approved ?? 0,
                                                    'disbursed' => $total_disbursed ?? 0,
                                                    'defaulted' => $total_defaulted ?? 0,
                                                    'overdue' => $total_overdue
                                                ];
                                                
                                                $status_names = [
                                                    'active' => 'সক্রিয়',
                                                    'completed' => 'সম্পন্ন',
                                                    'approved' => 'অনুমোদিত',
                                                    'disbursed' => 'বিতরণকৃত',
                                                    'defaulted' => 'ডিফল্ট',
                                                    'overdue' => 'বকেয়া'
                                                ];
                                            ?>
                                            
                                            <?php $__currentLoopData = $status_counts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status_key => $count): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php if($count > 0): ?>
                                                    <?php
                                                        // Calculate amounts for each status (simplified - in real app you'd query DB)
                                                        $status_amount = 0;
                                                        $status_due = 0;
                                                        $status_paid = 0;
                                                        
                                                        foreach($loans as $loan) {
                                                            if($loan->status == $status_key || ($status_key == 'overdue' && $loan->remaining_balance > 0)) {
                                                                $status_amount += $loan->loan_amount;
                                                                $status_due += $loan->remaining_balance;
                                                                $status_paid += ($loan->loan_amount - $loan->remaining_balance);
                                                            }
                                                        }
                                                        
                                                        $status_percentage = $status_amount > 0 ? ($status_paid / $status_amount) * 100 : 0;
                                                    ?>
                                                    <tr>
                                                        <td>
                                                            <span class="badge bg-<?php echo e($status_colors[$status_key] ?? 'secondary'); ?>">
                                                                <?php echo e($status_names[$status_key] ?? $status_key); ?>

                                                            </span>
                                                        </td>
                                                        <td class="text-center"><?php echo e($count); ?></td>
                                                        <td class="text-center text-warning"><?php echo e(number_format($status_amount, 2)); ?> টাকা</td>
                                                        <td class="text-center text-danger"><?php echo e(number_format($status_due, 2)); ?> টাকা</td>
                                                        <td class="text-center text-success"><?php echo e(number_format($status_paid, 2)); ?> টাকা</td>
                                                        <td class="text-center">
                                                            <div class="progress" style="height: 20px;">
                                                                <div class="progress-bar bg-success" role="progressbar" 
                                                                     style="width: <?php echo e($status_percentage); ?>%" 
                                                                     aria-valuenow="<?php echo e($status_percentage); ?>" 
                                                                     aria-valuemin="0" 
                                                                     aria-valuemax="100">
                                                                    <?php echo e(number_format($status_percentage, 1)); ?>%
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card h-100">
                                    <div class="card-body">
                                        <h6 class="text-center mb-3">লোন বিতরণ</h6>
                                        <div class="text-center">
                                            <?php
                                                $total_loans_count = $loans->count();
                                            ?>
                                            <?php if($total_loans_count > 0): ?>
                                                <?php $__currentLoopData = $status_counts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status_key => $count): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($count > 0): ?>
                                                        <?php
                                                            $percentage = ($count / $total_loans_count) * 100;
                                                        ?>
                                                        <div class="mb-2">
                                                            <div class="d-flex justify-content-between mb-1">
                                                                <span class="text-muted">
                                                                    <?php echo e($status_names[$status_key] ?? $status_key); ?>

                                                                </span>
                                                                <span class="text-muted"><?php echo e(number_format($percentage, 1)); ?>%</span>
                                                            </div>
                                                            <div class="progress">
                                                                <div class="progress-bar" 
                                                                     role="progressbar" 
                                                                     style="width: <?php echo e($percentage); ?>%; background-color: <?php echo e([
                                                                         'active' => '#28a745',
                                                                         'completed' => '#6c757d',
                                                                         'approved' => '#17a2b8',
                                                                         'disbursed' => '#007bff',
                                                                         'defaulted' => '#dc3545',
                                                                         'overdue' => '#ffc107'
                                                                     ][$status_key] ?? '#6c757d'); ?>;">
                                                                </div>
                                                            </div>
                                                        </div>
                                                    <?php endif; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php else: ?>
                                                <p class="text-muted">কোনো ডেটা নেই</p>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Action Buttons -->
        <div class="row mt-4 no-print">
            <div class="col-12">
                <div class="card">
                    <div class="card-body text-center">
                        <div class="btn-group" role="group">
                            <a href="<?php echo e(route('reports.loans')); ?>?status=active" class="btn btn-outline-success me-2">
                                <i class="fas fa-running me-1"></i> সক্রিয় লোন
                            </a>
                            <a href="<?php echo e(route('reports.loans')); ?>?status=completed" class="btn btn-outline-secondary me-2">
                                <i class="fas fa-check-circle me-1"></i> সম্পন্ন লোন
                            </a>
                            <a href="<?php echo e(route('reports.loans')); ?>?status=overdue" class="btn btn-outline-danger me-2">
                                <i class="fas fa-clock me-1"></i> বকেয়া লোন
                            </a>
                            <a href="<?php echo e(route('reports.summary')); ?>" class="btn btn-outline-primary me-2">
                                <i class="fas fa-chart-line me-1"></i> সারাংশ
                            </a>
                            <button onclick="window.print()" class="btn btn-primary">
                                <i class="fas fa-print me-1"></i> প্রিন্ট রিপোর্ট
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Report Info -->
        <div class="row mt-4">
            <div class="col-12 text-center">
                <hr>
                <p class="text-muted small">
                    <i class="fas fa-clock me-1"></i>
                    রিপোর্ট তৈরি হয়েছে: <?php echo e(now()->format('d F Y, h:i A')); ?>

                    | 
                    <i class="fas fa-user me-1"></i>
                    ব্যবহারকারী: <?php echo e(Auth::user()->name ?? 'অজানা'); ?>

                    |
                    <i class="fas fa-filter me-1"></i>
                    স্ট্যাটাস: <?php echo e($status_text[$status] ?? 'সকল'); ?>

                    |
                    <i class="fas fa-list me-1"></i>
                    মোট লোন: <?php echo e($loans->count()); ?>টি
                </p>
            </div>
        </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <!-- Font Awesome -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/js/all.min.js"></script>
    <!-- Select2 JS -->
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
    
    <script>
        $(document).ready(function() {
            // Select2 initialization
            $('#status').select2({
                placeholder: "স্ট্যাটাস নির্বাচন করুন",
                allowClear: true
            });

            // Auto submit form on status change if you want
            // $('#status').on('change', function() {
            //     this.form.submit();
            // });

            // Print function
            function printReport() {
                window.print();
            }

            // Format numbers with comma
            function formatNumber(num) {
                return new Intl.NumberFormat('bn-BD').format(num);
            }

            // Update all numbers on page
            document.querySelectorAll('.number-format').forEach(function(element) {
                const num = parseFloat(element.textContent);
                if (!isNaN(num)) {
                    element.textContent = formatNumber(num);
                }
            });

            // Highlight overdue loans
            document.querySelectorAll('.loan-row').forEach(function(row) {
                const statusBadge = row.querySelector('.badge');
                if (statusBadge && statusBadge.textContent.includes('সক্রিয়')) {
                    const dueAmount = parseFloat(row.querySelector('td:nth-child(6)').textContent.replace(/[^0-9.-]+/g, ""));
                    if (dueAmount > 0) {
                        row.style.backgroundColor = 'rgba(255, 193, 7, 0.1)';
                    }
                }
            });
        });
    </script>
</body>
</html>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/naowarin/somoti.naowarinternational.my.id/resources/views/reports/loan.blade.php ENDPATH**/ ?>