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

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

<?php $__template->section('page_actions'); ?>
<?php if (can('accounting.bank_account.manage')): ?>
<a href="/accounting/bank-accounts/create" class="btn btn-primary">+ حساب بنكي جديد</a>
<?php endif; ?>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:15px;">
    <div style="padding:15px 20px;">
        <div style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;">
            <div style="flex:2;">
                <label class="form-label" style="font-size:12px;">بحث</label>
                <input type="text" id="ba-search" class="form-input" placeholder="اسم الحساب، البنك، رقم الحساب...">
            </div>
        </div>
    </div>
</div>
<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 id="ba-tbody">
                <?php foreach ($accounts as $acc): ?>
                    <tr data-search="<?= e($acc['account_name_ar'] . ' ' . ($acc['account_name_en'] ?? '') . ' ' . $acc['bank_name_ar'] . ' ' . ($acc['bank_name_en'] ?? '') . ' ' . $acc['account_number'] . ' ' . ($acc['iban'] ?? '') . ' ' . $acc['currency']) ?>">
                        <td style="font-weight:600;"><?= e($acc['account_name_ar']) ?><?= (int)$acc['is_default'] ? ' <span style="color:#0D7377;font-size:11px;">(افتراضي)</span>' : '' ?></td>
                        <td><?= e($acc['bank_name_ar']) ?></td>
                        <td style="direction:ltr;text-align:right;"><?= e($acc['account_number']) ?></td>
                        <td><?= e($acc['currency']) ?></td>
                        <td style="direction:ltr;text-align:right;font-weight:600;"><?= money($acc['current_balance']) ?></td>
                        <td><span style="color:<?= (int)$acc['is_active'] ? '#059669' : '#DC2626' ?>;font-weight:600;"><?= (int)$acc['is_active'] ? 'نشط' : 'موقف' ?></span></td>
                        <td><?php if (can('accounting.bank_account.manage')): ?><a href="/accounting/bank-accounts/<?= (int)$acc['id'] ?>/edit" class="btn btn-sm btn-outline">تعديل</a><?php endif; ?></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($accounts)): ?>
                    <tr><td colspan="7" style="text-align:center;color:#6B7280;padding:30px;">لا توجد حسابات بنكية</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<script>
(function(){
    var s=document.getElementById('ba-search'),rows=document.querySelectorAll('#ba-tbody tr[data-search]');
    function f(){var q=(s.value||'').toLowerCase();rows.forEach(function(r){
        r.style.display=!q||(r.getAttribute('data-search')||'').toLowerCase().indexOf(q)!==-1?'':'none';});}
    if(s)s.addEventListener('input',f);
})();
</script>
<?php $__template->endSection(); ?>
