<?php $__template->layout('Layout.main'); ?>

<?php $__template->section('title'); ?>المطابقات البنكية<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/accounting/bank-reconciliation/create" class="btn btn-primary">+ مطابقة جديدة</a>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<div class="card">
    <div class="table-responsive">
        <table class="data-table" style="width:100%;">
            <thead>
                <tr>
                    <th>الحساب البنكي</th>
                    <th>تاريخ المطابقة</th>
                    <th>رصيد الكشف</th>
                    <th>رصيد الدفاتر</th>
                    <th>الفرق</th>
                    <th>الحالة</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($reconciliations as $r): ?>
                    <?php
                    $statusColor = match($r['status']) {
                        'draft' => '#F59E0B',
                        'in_progress' => '#0284C7',
                        'completed' => '#059669',
                        'approved' => '#0D7377',
                        default => '#6B7280',
                    };
                    $statusLabel = match($r['status']) {
                        'draft' => 'مسودة',
                        'in_progress' => 'جاري العمل',
                        'completed' => 'مكتملة',
                        'approved' => 'معتمدة',
                        default => $r['status'],
                    };
                    ?>
                    <tr>
                        <td><?= e($r['bank_account_name'] ?? '—') ?></td>
                        <td><?= e($r['reconciliation_date']) ?></td>
                        <td style="direction:ltr;text-align:right;"><?= money($r['statement_balance']) ?></td>
                        <td style="direction:ltr;text-align:right;"><?= money($r['book_balance']) ?></td>
                        <td style="direction:ltr;text-align:right;font-weight:600;color:<?= bccomp((string)$r['difference'], '0.00', 2) === 0 ? '#059669' : '#DC2626' ?>;"><?= money($r['difference']) ?></td>
                        <td><span style="color:<?= $statusColor ?>;font-weight:600;"><?= $statusLabel ?></span></td>
                        <td><a href="/accounting/bank-reconciliation/<?= (int)$r['id'] ?>" class="btn btn-sm btn-outline">عرض</a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($reconciliations)): ?>
                    <tr><td colspan="7" style="text-align:center;color:#6B7280;padding:30px;">لا توجد مطابقات</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
