<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>ملخص السلف والقروض<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/reports" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<?php $sl = ['pending'=>'معلق','approved'=>'معتمد','rejected'=>'مرفوض','disbursed'=>'مصروف','repaying'=>'جاري السداد','settled'=>'مسدد']; ?>
<?php $sc = ['pending'=>'#FEF3C7;color:#92400E','approved'=>'#DBEAFE;color:#1E40AF','rejected'=>'#FDE8E8;color:#9B1C1C','disbursed'=>'#E0E7FF;color:#3730A3','repaying'=>'#D1FAE5;color:#065F46','settled'=>'#E5E7EB;color:#374151']; ?>

<?php if (!empty($statusSummary)): ?>
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px;margin-bottom:20px;">
    <?php foreach ($statusSummary as $s): ?>
    <div class="card" style="padding:16px;">
        <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">
            <span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:<?= $sc[$s['status']] ?? '#E5E7EB;color:#374151' ?>;"><?= e($sl[$s['status']] ?? $s['status']) ?></span>
            <span style="font-size:20px;font-weight:700;"><?= (int) $s['count'] ?></span>
        </div>
        <div style="font-size:13px;color:#6B7280;">المبلغ: <?= number_format((float) ($s['total_amount'] ?? 0), 2) ?></div>
        <div style="font-size:13px;color:#DC2626;">المتبقي: <?= number_format((float) ($s['total_remaining'] ?? 0), 2) ?></div>
    </div>
    <?php endforeach; ?>
</div>
<?php endif; ?>

<div class="card">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;">السلف النشطة (مصروفة / جاري السداد)</h3></div>
    <div class="table-responsive">
        <table class="data-table">
            <thead><tr><th>الرقم</th><th>الموظف</th><th>المبلغ</th><th>المتبقي</th><th>الحالة</th></tr></thead>
            <tbody>
                <?php if (empty($activeLoans)): ?>
                <tr><td colspan="5" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد سلف نشطة</td></tr>
                <?php else: ?>
                <?php foreach ($activeLoans as $l): ?>
                <tr>
                    <td><?= e($l['employee_number'] ?? '-') ?></td>
                    <td><a href="/hr/employees/<?= (int) $l['employee_profile_id'] ?>"><?= e($l['first_name_ar'] . ' ' . $l['last_name_ar']) ?></a></td>
                    <td style="font-weight:600;"><?= number_format((float) $l['loan_amount'], 2) ?></td>
                    <td style="font-weight:700;color:#DC2626;"><?= number_format((float) $l['remaining_amount'], 2) ?></td>
                    <td><span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:<?= $sc[$l['status']] ?? '#E5E7EB;color:#374151' ?>;"><?= e($sl[$l['status']] ?? $l['status']) ?></span></td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
