<?php
use App\Modules\Settings\Services\BrandingService;

$clubNameAr = BrandingService::clubNameAr();
$clubNameEn = BrandingService::clubNameEn();
$clubSubtitle = BrandingService::subtitle();
$logoUrl = BrandingService::logo();
?>
<?php $__template->layout('Layout.print'); ?>
<?php $__template->section('title'); ?>استمارة تسجيل النشاط الرياضي — <?= e($registration['registration_number']) ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<style>
    @media print { body { margin: 0; } .no-print { display: none !important; } }
    .reg-form { width: 210mm; min-height: 297mm; margin: 0 auto; padding: 15mm 20mm; font-family: 'Cairo', Arial, sans-serif; direction: rtl; font-size: 13px; color: #1A1A2E; }
    .reg-form .header { text-align: center; margin-bottom: 20px; border-bottom: 3px solid #1A1A2E; padding-bottom: 15px; }
    .reg-form .header img { max-height: 50px; margin-bottom: 8px; }
    .reg-form .header h1 { font-size: 20px; margin: 5px 0 3px; }
    .reg-form .header h2 { font-size: 14px; color: #6B7280; margin: 0; font-weight: 400; }
    .reg-form .form-title { text-align: center; font-size: 18px; font-weight: 700; margin: 15px 0; padding: 8px; background: #F3F4F6; border-radius: 6px; }
    .reg-form .info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin-bottom: 20px; }
    .reg-form .info-row { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px dotted #D1D5DB; }
    .reg-form .info-row .label { font-weight: 600; min-width: 120px; color: #374151; }
    .reg-form .info-row .value { flex: 1; }
    .reg-form .photo-section { float: left; margin: 0 0 15px 15px; }
    .reg-form .photo-section img { width: 100px; height: 120px; object-fit: cover; border: 2px solid #1A1A2E; border-radius: 6px; }
    .reg-form .photo-section .no-photo { width: 100px; height: 120px; border: 2px solid #D1D5DB; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: #9CA3AF; font-size: 11px; }
    .reg-form .fee-table { width: 100%; border-collapse: collapse; margin: 15px 0; }
    .reg-form .fee-table th, .reg-form .fee-table td { border: 1px solid #D1D5DB; padding: 8px 12px; text-align: right; }
    .reg-form .fee-table th { background: #F3F4F6; font-weight: 600; }
    .reg-form .fee-table .total-row { background: #EFF6FF; font-weight: 700; }
    .reg-form .signatures { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-top: 40px; text-align: center; }
    .reg-form .signatures .sig-box { border-top: 1px solid #1A1A2E; padding-top: 8px; margin-top: 50px; }
    .reg-form .qr-section { position: absolute; bottom: 20mm; left: 20mm; }
    .reg-form .reg-number { position: absolute; top: 15mm; left: 20mm; font-size: 12px; direction: ltr; color: #6B7280; }
</style>

<div class="no-print" style="text-align:center;padding:10px;">
    <button onclick="window.print()" style="padding:8px 20px;background:#2563EB;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:14px;">طباعة</button>
    <a href="/sa/registration/<?= (int) $registration['id'] ?>" style="margin-right:10px;color:#6B7280;font-size:14px;">رجوع</a>
</div>

<div class="reg-form" style="position:relative;">
    <div class="reg-number"><?= e($registration['registration_number']) ?></div>

    <!-- Header -->
    <div class="header">
        <?php if ($logoUrl): ?><img src="<?= e($logoUrl) ?>" alt="Logo"><?php endif; ?>
        <h1><?= e($clubNameAr) ?></h1>
        <h2><?= e($clubSubtitle) ?></h2>
    </div>

    <div class="form-title">استمارة تسجيل النشاط الرياضي</div>

    <!-- Photo -->
    <div class="photo-section">
        <?php if ($registration['photo_path']): ?>
        <img src="/<?= e($registration['photo_path']) ?>" alt="صورة اللاعب">
        <?php else: ?>
        <div class="no-photo">لا توجد صورة</div>
        <?php endif; ?>
    </div>

    <!-- Player Data -->
    <div class="info-grid">
        <div class="info-row"><span class="label">الاسم:</span><span class="value"><?= e($registration['full_name_ar']) ?></span></div>
        <div class="info-row"><span class="label">النوع:</span><span class="value"><?= $registration['player_type'] === 'member' ? 'عضو' : 'غير عضو' ?></span></div>
        <div class="info-row"><span class="label">الرقم القومي:</span><span class="value" style="direction:ltr;text-align:right;"><?= e($registration['player_nid'] ?? '—') ?></span></div>
        <div class="info-row"><span class="label">تاريخ الميلاد:</span><span class="value"><?= e($registration['date_of_birth'] ?? '—') ?></span></div>
        <div class="info-row"><span class="label">النوع:</span><span class="value"><?= ($registration['gender'] ?? '') === 'male' ? 'ذكر' : (($registration['gender'] ?? '') === 'female' ? 'أنثى' : '—') ?></span></div>
        <div class="info-row"><span class="label">الهاتف:</span><span class="value" style="direction:ltr;text-align:right;"><?= e($registration['phone'] ?? '—') ?></span></div>
        <div class="info-row"><span class="label">ولي الأمر:</span><span class="value"><?= e($registration['guardian_name'] ?? '—') ?></span></div>
        <div class="info-row"><span class="label">هاتف ولي الأمر:</span><span class="value" style="direction:ltr;text-align:right;"><?= e($registration['guardian_phone'] ?? '—') ?></span></div>
        <div class="info-row"><span class="label">الرقم التسلسلي:</span><span class="value" style="direction:ltr;text-align:right;"><?= e($registration['registration_serial'] ?? '—') ?></span></div>
    </div>

    <div style="clear:both;"></div>

    <!-- Activity Info -->
    <?php if ($group): ?>
    <div style="margin:15px 0;padding:12px;background:#F0FDF4;border:1px solid #BBF7D0;border-radius:6px;">
        <strong>النشاط:</strong> <?= e($group['discipline_name'] ?? '') ?> — <?= e($group['name_ar']) ?>
        <?php if (!empty($group['program_name'])): ?><br><strong>البرنامج:</strong> <?= e($group['program_name']) ?><?php endif; ?>
    </div>
    <?php endif; ?>

    <!-- Fee Table -->
    <table class="fee-table">
        <thead>
            <tr><th>البند</th><th style="width:120px;">المبلغ</th></tr>
        </thead>
        <tbody>
            <tr><td>رسوم التسجيل (<?= $registration['player_type'] === 'member' ? 'عضو' : 'غير عضو' ?>)</td><td><?= money((float) $registration['registration_fee']) ?></td></tr>
            <tr><td>رسوم الكارت</td><td><?= money((float) $registration['card_fee']) ?></td></tr>
            <tr><td>رسوم الاستمارة</td><td><?= money((float) $registration['form_fee']) ?></td></tr>
            <?php if ((float) ($registration['subscription_amount'] ?? 0) > 0): ?>
            <tr><td>اشتراك النشاط (شهري)</td><td><?= money((float) $registration['subscription_amount']) ?></td></tr>
            <?php endif; ?>
            <tr class="total-row"><td>الإجمالي</td><td><?= money((float) $registration['total_fees']) ?></td></tr>
        </tbody>
    </table>

    <!-- Signatures -->
    <div class="signatures">
        <div><div class="sig-box">توقيع اللاعب / ولي الأمر</div></div>
        <div><div class="sig-box">مسؤول التسجيل</div></div>
        <div><div class="sig-box">مدير النشاط الرياضي</div></div>
    </div>

    <!-- QR -->
    <div class="qr-section"><?= $qrSvg ?></div>

    <!-- Date -->
    <div style="position:absolute;bottom:20mm;right:20mm;font-size:12px;color:#6B7280;">
        التاريخ: <?= date('Y-m-d') ?>
    </div>
</div>
<?php $__template->endSection(); ?>
