<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?><?= e($definition['name_ar']) ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<?php if (can('report.export')): ?>
<a href="/reports/export/<?= e($definition['report_code']) ?>?<?= http_build_query($filters) ?>" class="btn btn-outline">تصدير CSV</a>
<?php endif; ?>
<a href="/reports/print/<?= e($definition['report_code']) ?>?<?= http_build_query($filters) ?>" class="btn btn-outline" target="_blank">طباعة</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/reports/view/<?= e($definition['report_code']) ?>" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;">
        <div><label class="form-label" style="font-size:12px;">من</label><input type="date" name="date_from" value="<?= e($filters['date_from'] ?? '') ?>" class="form-input"></div>
        <div><label class="form-label" style="font-size:12px;">إلى</label><input type="date" name="date_to" value="<?= e($filters['date_to'] ?? '') ?>" class="form-input"></div>
        <div><label class="form-label" style="font-size:12px;">الفرع</label><select name="branch_id" class="form-select"><option value="">الكل</option><?php foreach ($branches as $b): ?><option value="<?= (int) $b['id'] ?>" <?= ($filters['branch_id'] ?? '') == $b['id'] ? 'selected' : '' ?>><?= e($b['name_ar']) ?></option><?php endforeach; ?></select></div>
        <button type="submit" class="btn btn-primary">عرض</button>
    </form>
</div>
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;">
        <strong><?= e($definition['name_ar']) ?></strong>
        <span style="color:#6B7280;">إجمالي: <?= (int) ($data['total'] ?? 0) ?> سجل</span>
    </div>
    <div class="table-responsive">
        <table class="data-table"><thead><tr>
            <?php foreach (($data['columns'] ?? []) as $label): ?><th><?= e($label) ?></th><?php endforeach; ?>
        </tr></thead><tbody>
            <?php foreach (($data['rows'] ?? []) as $row): ?>
            <tr><?php foreach (array_keys($data['columns'] ?? []) as $key): ?><td style="font-size:13px;"><?= e((string) ($row[$key] ?? '—')) ?></td><?php endforeach; ?></tr>
            <?php endforeach; ?>
            <?php if (empty($data['rows'])): ?><tr><td colspan="<?= count($data['columns'] ?? []) ?>" style="text-align:center;padding:40px;color:#6B7280;"><?= e($data['message'] ?? 'لا توجد بيانات') ?></td></tr><?php endif; ?>
        </tbody></table>
    </div>
</div>
<?php $__template->endSection(); ?>