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

$rd = BrandingService::receiptDesign();
$clubNameAr = BrandingService::clubNameAr();
$clubNameEn = BrandingService::clubNameEn();
$logoUrl = BrandingService::logo();

$showLogo      = $rd['show_logo'];
$showWatermark = $rd['show_watermark'];
$watermarkText = $rd['watermark_text'];
$watermarkOp   = $rd['watermark_opacity'];
$headerColor   = $rd['header_color'];
$showFooter    = $rd['show_footer_print_info'];
?>
<?php $__template->layout('Layout.print'); ?>
<?php $__template->section('title'); ?>إيصال رقم <?= e($receipt['receipt_number']) ?><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<div style="max-width:700px;margin:0 auto;font-family:'Cairo',sans-serif;direction:rtl;position:relative;overflow:hidden;">

    <?php if ($showWatermark && $watermarkText): ?>
    <div style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%) rotate(-35deg);font-size:52px;font-weight:900;color:<?= e($headerColor) ?>;opacity:<?= e($watermarkOp) ?>;white-space:nowrap;pointer-events:none;z-index:0;">
        <?= e($watermarkText) ?>
    </div>
    <?php endif; ?>

    <div style="position:relative;z-index:1;">
        <?php if ($receipt['is_voided']): ?>
        <div style="text-align:center;color:#DC2626;font-size:24px;font-weight:700;border:3px solid #DC2626;padding:10px;margin-bottom:20px;">ملغى</div>
        <?php endif; ?>

        <div style="text-align:center;margin-bottom:30px;padding-bottom:16px;border-bottom:2px solid <?= e($headerColor) ?>;">
            <?php if ($showLogo && $logoUrl): ?>
                <div style="margin-bottom:10px;"><img src="<?= e($logoUrl) ?>" alt="Logo" style="max-height:45px;"></div>
            <?php endif; ?>
            <h2 style="margin:0;color:<?= e($headerColor) ?>;"><?= e($clubNameAr) ?></h2>
            <p style="margin:5px 0;color:#6B7280;"><?= e($clubNameEn) ?></p>
            <h3 style="margin:15px 0 5px;color:#1A1A2E;">إيصال تحصيل</h3>
        </div>

        <table style="width:100%;border-collapse:collapse;margin-bottom:20px;font-size:14px;">
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;width:30%;">رقم الإيصال</td>
                <td style="padding:8px;border:1px solid #E5E7EB;direction:ltr;text-align:right;font-weight:700;font-size:16px;"><?= e($receipt['receipt_number']) ?></td>
            </tr>
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;">التاريخ</td>
                <td style="padding:8px;border:1px solid #E5E7EB;"><?= e(substr($receipt['issued_at'], 0, 10)) ?></td>
            </tr>
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;">اسم العضو</td>
                <td style="padding:8px;border:1px solid #E5E7EB;font-weight:600;"><?= e($receipt['member_name']) ?></td>
            </tr>
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;">رقم العضوية</td>
                <td style="padding:8px;border:1px solid #E5E7EB;"><?= e($receipt['membership_number'] ?? '—') ?></td>
            </tr>
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;">البيان</td>
                <td style="padding:8px;border:1px solid #E5E7EB;"><?= e($receipt['description_ar'] ?? '—') ?></td>
            </tr>
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;">المبلغ (رقماً)</td>
                <td style="padding:8px;border:1px solid #E5E7EB;font-size:22px;font-weight:700;color:<?= e($headerColor) ?>;direction:ltr;text-align:right;"><?= money($receipt['amount']) ?></td>
            </tr>
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;">المبلغ (كتابةً)</td>
                <td style="padding:8px;border:1px solid #E5E7EB;font-size:13px;"><?= e($receipt['amount_in_words_ar'] ?? '') ?></td>
            </tr>
            <?php if ($receipt['payment_type'] ?? ''): ?>
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;">نوع الدفعة</td>
                <td style="padding:8px;border:1px solid #E5E7EB;"><?= e(\App\Modules\Payments\Models\Payment::getPaymentTypeLabel($receipt['payment_type'])) ?></td>
            </tr>
            <?php endif; ?>
            <?php if ($receipt['payment_method'] ?? ''): ?>
            <tr>
                <td style="padding:8px;border:1px solid #E5E7EB;background:#F9FAFB;font-weight:600;">طريقة الدفع</td>
                <td style="padding:8px;border:1px solid #E5E7EB;"><?= e(\App\Modules\Payments\Models\Payment::getPaymentMethodLabel($receipt['payment_method'])) ?></td>
            </tr>
            <?php endif; ?>
        </table>

        <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:30px;margin-top:50px;text-align:center;font-size:13px;">
            <div style="border-top:1px solid #000;padding-top:10px;">توقيع المستلم</div>
            <div style="border-top:1px solid #000;padding-top:10px;">أمين الخزينة<br><small><?= e($receipt['issued_by_name'] ?? '') ?></small></div>
            <div style="border-top:1px solid #000;padding-top:10px;">المدير المالي</div>
        </div>

        <?php if ($showFooter): ?>
        <div style="margin-top:30px;text-align:center;font-size:11px;color:#9CA3AF;">
            طبع بتاريخ: <?= date('Y-m-d H:i:s') ?> — عدد مرات الطباعة: <?= (int) ($receipt['print_count'] ?? 0) + 1 ?>
        </div>
        <?php endif; ?>
    </div>
</div>
<?php $__template->endSection(); ?>
