<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تقارير التسجيل الرياضي<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/registration" class="btn btn-outline"><i data-lucide="arrow-right" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> مكتب التسجيل</a>
<?php $__template->endSection(); ?>

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

<!-- Filters -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;">
        <form method="GET" style="display:flex;align-items:end;gap:15px;flex-wrap:wrap;">
            <div class="form-group" style="margin:0;min-width:150px;">
                <label class="form-label" style="font-size:12px;">من تاريخ</label>
                <input type="date" name="from" value="<?= e($dateFrom) ?>" class="form-input" style="direction:ltr;">
            </div>
            <div class="form-group" style="margin:0;min-width:150px;">
                <label class="form-label" style="font-size:12px;">إلى تاريخ</label>
                <input type="date" name="to" value="<?= e($dateTo) ?>" class="form-input" style="direction:ltr;">
            </div>
            <button type="submit" class="btn btn-primary" style="padding:9px 20px;"><i data-lucide="filter" style="width:14px;height:14px;vertical-align:middle;margin-left:4px;"></i> عرض</button>
        </form>
    </div>
</div>

<!-- Summary Cards -->
<div style="display:grid;grid-template-columns:repeat(auto-fit, minmax(160px, 1fr));gap:15px;margin-bottom:20px;">
    <div class="card" style="padding:16px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">إجمالي التسجيلات</div>
        <div style="font-size:22px;font-weight:800;color:#1A1A2E;margin-top:4px;"><?= (int) ($summary['total_registrations'] ?? 0) ?></div>
    </div>
    <div class="card" style="padding:16px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">مكتمل</div>
        <div style="font-size:22px;font-weight:800;color:#059669;margin-top:4px;"><?= (int) ($summary['completed'] ?? 0) ?></div>
    </div>
    <div class="card" style="padding:16px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">بانتظار الدفع</div>
        <div style="font-size:22px;font-weight:800;color:#D97706;margin-top:4px;"><?= (int) ($summary['pending'] ?? 0) ?></div>
    </div>
    <div class="card" style="padding:16px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">ملغى</div>
        <div style="font-size:22px;font-weight:800;color:#DC2626;margin-top:4px;"><?= (int) ($summary['cancelled'] ?? 0) ?></div>
    </div>
    <div class="card" style="padding:16px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">إجمالي الإيرادات</div>
        <div style="font-size:22px;font-weight:800;color:#2563EB;margin-top:4px;"><?= money((float) ($summary['total_revenue'] ?? 0)) ?></div>
    </div>
    <div class="card" style="padding:16px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">أعضاء</div>
        <div style="font-size:22px;font-weight:800;color:#7C3AED;margin-top:4px;"><?= (int) ($summary['member_count'] ?? 0) ?></div>
    </div>
    <div class="card" style="padding:16px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">غير أعضاء</div>
        <div style="font-size:22px;font-weight:800;color:#6B7280;margin-top:4px;"><?= (int) ($summary['nonmember_count'] ?? 0) ?></div>
    </div>
    <div class="card" style="padding:16px;text-align:center;">
        <div style="font-size:12px;color:#6B7280;">كروت صادرة</div>
        <div style="font-size:22px;font-weight:800;color:#059669;margin-top:4px;"><?= (int) ($summary['cards_issued'] ?? 0) ?></div>
    </div>
</div>

<!-- Daily Breakdown -->
<?php if (!empty($dailyBreakdown)): ?>
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;font-size:16px;font-weight:600;">التفصيل اليومي</h3>
    </div>
    <table style="width:100%;border-collapse:collapse;font-size:13px;">
        <thead>
            <tr style="background:#F9FAFB;">
                <th style="padding:10px 15px;text-align:right;font-weight:600;color:#6B7280;">التاريخ</th>
                <th style="padding:10px 15px;text-align:right;font-weight:600;color:#6B7280;">عدد التسجيلات</th>
                <th style="padding:10px 15px;text-align:right;font-weight:600;color:#6B7280;">الإيرادات</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($dailyBreakdown as $day): ?>
            <tr style="border-top:1px solid #F3F4F6;">
                <td style="padding:10px 15px;direction:ltr;text-align:right;"><?= e($day['reg_date']) ?></td>
                <td style="padding:10px 15px;"><?= (int) $day['total'] ?></td>
                <td style="padding:10px 15px;font-weight:600;color:#059669;"><?= money((float) $day['revenue']) ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php endif; ?>

<script>document.addEventListener('DOMContentLoaded', function() { if (typeof lucide !== 'undefined') lucide.createIcons(); });</script>
<?php $__template->endSection(); ?>
