<?php
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?>تفاصيل العقد: <?= e($contract['contract_number'] ?? '') ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<?php if (($contract['status'] ?? '') === 'pending_approval'): ?>
<form method="POST" action="/sa/academy-contracts/<?= (int) $contract['id'] ?>/approve" style="display:inline;">
    <?= csrf_field() ?>
    <button type="submit" class="btn btn-primary" onclick="return confirm('هل تريد اعتماد هذا العقد؟')">
        <i data-lucide="check-circle" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> اعتماد العقد
    </button>
</form>
<?php endif; ?>
<a href="/sa/academies/<?= (int) $contract['academy_id'] ?>/contracts" class="btn btn-outline"><i data-lucide="arrow-right" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> رجوع</a>
<?php $__template->endSection(); ?>

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

<?php
$contractTypeLabels = ['revenue_share' => 'نسبة إيرادات', 'fixed_rent' => 'إيجار ثابت', 'hybrid' => 'مختلط'];
$statusLabels = ['pending_approval' => 'بانتظار الاعتماد', 'active' => 'فعال', 'expired' => 'منتهي', 'terminated' => 'ملغي'];
$statusColors = ['pending_approval' => '#D97706', 'active' => '#059669', 'expired' => '#6B7280', 'terminated' => '#DC2626'];
$cStatus = $contract['status'] ?? 'pending_approval';
$csColor = $statusColors[$cStatus] ?? '#6B7280';
?>

<!-- Contract Detail -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:20px;display:flex;align-items:center;gap:20px;border-bottom:1px solid #E5E7EB;">
        <div style="width:56px;height:56px;border-radius:12px;background:linear-gradient(135deg, <?= $csColor ?>15, <?= $csColor ?>30);display:flex;align-items:center;justify-content:center;">
            <i data-lucide="file-signature" style="width:28px;height:28px;color:<?= $csColor ?>;"></i>
        </div>
        <div>
            <h2 style="margin:0 0 4px;font-size:20px;font-weight:700;">عقد رقم <?= e($contract['contract_number'] ?? '') ?></h2>
            <div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;">
                <span style="font-size:13px;color:#6B7280;">الأكاديمية: <strong><?= e($contract['academy_name'] ?? '') ?></strong></span>
                <span style="padding:3px 10px;border-radius:10px;font-size:11px;font-weight:600;background:<?= $csColor ?>15;color:<?= $csColor ?>;">
                    <?= e($statusLabels[$cStatus] ?? $cStatus) ?>
                </span>
            </div>
        </div>
    </div>

    <div style="padding:20px;display:grid;grid-template-columns:repeat(auto-fit, minmax(220px, 1fr));gap:20px;">
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">نوع العقد</div>
            <div style="font-size:14px;font-weight:600;"><?= e($contractTypeLabels[$contract['contract_type'] ?? ''] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">تاريخ البداية</div>
            <div style="font-size:14px;font-weight:600;"><?= e($contract['start_date'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">تاريخ النهاية</div>
            <div style="font-size:14px;font-weight:600;"><?= e($contract['end_date'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">نسبة النادي</div>
            <div style="font-size:14px;font-weight:600;"><?= number_format((float) ($contract['club_commission_pct'] ?? 0), 1) ?>%</div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">نسبة الأكاديمية</div>
            <div style="font-size:14px;font-weight:600;"><?= number_format((float) ($contract['academy_share_pct'] ?? 0), 1) ?>%</div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">الإيجار الشهري</div>
            <div style="font-size:14px;font-weight:600;"><?= number_format((float) ($contract['fixed_monthly_rent'] ?? 0), 2) ?> ج.م</div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">مبلغ التأمين</div>
            <div style="font-size:14px;font-weight:600;"><?= number_format((float) ($contract['deposit_amount'] ?? 0), 2) ?> ج.م</div>
        </div>
        <?php if (!empty($contract['approved_at'])): ?>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">تاريخ الاعتماد</div>
            <div style="font-size:14px;font-weight:600;"><?= e($contract['approved_at'] ?? '-') ?></div>
        </div>
        <?php endif; ?>
    </div>
</div>

<!-- Contract PDF -->
<?php if (!empty($contract['contract_pdf_path'])): ?>
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;font-size:16px;font-weight:600;">ملف العقد</h3>
    </div>
    <div style="padding:20px;">
        <a href="/<?= e($contract['contract_pdf_path']) ?>" target="_blank" class="btn btn-outline">
            <i data-lucide="file-text" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> تحميل ملف العقد (PDF)
        </a>
    </div>
</div>
<?php endif; ?>

<!-- Notes -->
<?php if (!empty($contract['notes'])): ?>
<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>
    <div style="padding:20px;font-size:14px;line-height:1.8;color:#374151;">
        <?= nl2br(e($contract['notes'])) ?>
    </div>
</div>
<?php endif; ?>

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