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

<?php $__template->section('title'); ?>سجل العهدة<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<!-- Balance Card -->
<div class="card" style="margin-bottom:15px;background:#F0FDF4;border:1px solid #BBF7D0;">
    <div style="padding:20px;display:flex;justify-content:space-between;align-items:center;">
        <div>
            <div style="font-size:13px;color:#065F46;">رصيد العهدة الحالي</div>
            <div style="font-size:28px;font-weight:700;color:#059669;"><?= money($balance) ?></div>
        </div>
        <div style="font-size:13px;color:#6B7280;"><?= e($treasury['name_ar']) ?></div>
    </div>
</div>

<!-- Log Table -->
<div class="card">
    <div style="padding:12px 20px;border-bottom:1px solid #E5E7EB;font-weight:600;">سجل الحركات</div>
    <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>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($log)): ?>
                    <tr><td colspan="6" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد حركات</td></tr>
                <?php else: ?>
                    <?php foreach ($log as $entry):
                        $isDebit = in_array($entry['action'], ['collection', 'settlement_in']);
                        $actionLabel = \App\Modules\Treasury\Services\CustodyService::getActionLabel($entry['action']);
                    ?>
                    <tr>
                        <td style="font-size:12px;color:#6B7280;"><?= e($entry['created_at']) ?></td>
                        <td style="font-size:12px;font-weight:600;"><?= e($actionLabel) ?></td>
                        <td style="font-weight:600;color:<?= $isDebit ? '#059669' : '#DC2626' ?>;">
                            <?= $isDebit ? '+' : '-' ?><?= money($entry['amount']) ?>
                        </td>
                        <td style="font-weight:600;"><?= money($entry['balance_after']) ?></td>
                        <td style="font-size:12px;"><?= e($entry['description_ar'] ?? '') ?></td>
                        <td style="font-size:11px;color:#9CA3AF;font-family:monospace;">
                            <?= e($entry['reference_type'] ?? '') ?>#<?= (int) ($entry['reference_id'] ?? 0) ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
