<?php
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?>عقود الأكاديمية: <?= e($academy['name_ar'] ?? '') ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/academies/<?= (int) $academy['id'] ?>/contracts/create" class="btn btn-primary"><i data-lucide="plus" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> إضافة عقد</a>
<a href="/sa/academies/<?= (int) $academy['id'] ?>" 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'];
?>

<?php if (!empty($contracts)): ?>
<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>رقم العقد</th>
                    <th>النوع</th>
                    <th>تاريخ البداية</th>
                    <th>تاريخ النهاية</th>
                    <th>نسبة النادي</th>
                    <th>نسبة الأكاديمية</th>
                    <th>الحالة</th>
                    <th>إجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($contracts as $contract):
                    $cStatus = $contract['status'] ?? 'pending_approval';
                    $csColor = $statusColors[$cStatus] ?? '#6B7280';
                ?>
                <tr>
                    <td><code style="font-size:12px;"><?= e($contract['contract_number'] ?? '') ?></code></td>
                    <td><?= e($contractTypeLabels[$contract['contract_type'] ?? ''] ?? $contract['contract_type'] ?? '-') ?></td>
                    <td style="font-size:13px;"><?= e($contract['start_date'] ?? '-') ?></td>
                    <td style="font-size:13px;"><?= e($contract['end_date'] ?? '-') ?></td>
                    <td style="text-align:center;"><?= number_format((float) ($contract['club_commission_pct'] ?? 0), 1) ?>%</td>
                    <td style="text-align:center;"><?= number_format((float) ($contract['academy_share_pct'] ?? 0), 1) ?>%</td>
                    <td>
                        <span style="padding:3px 10px;border-radius:10px;font-size:11px;font-weight:600;background:<?= $csColor ?>15;color:<?= $csColor ?>;">
                            <?= e($statusLabels[$cStatus] ?? $cStatus) ?>
                        </span>
                    </td>
                    <td>
                        <div style="display:flex;gap:6px;">
                            <a href="/sa/academy-contracts/<?= (int) $contract['id'] ?>" class="btn btn-sm btn-outline" title="عرض">
                                <i data-lucide="eye" style="width:14px;height:14px;"></i>
                            </a>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
<?php else: ?>
<div class="card" style="padding:60px 20px;text-align:center;">
    <div style="margin-bottom:15px;">
        <i data-lucide="file-text" style="width:48px;height:48px;color:#D1D5DB;"></i>
    </div>
    <h3 style="color:#6B7280;margin:0 0 8px;">لا توجد عقود</h3>
    <p style="color:#9CA3AF;font-size:14px;margin:0 0 20px;">لم يتم إضافة عقود لهذه الأكاديمية بعد.</p>
    <a href="/sa/academies/<?= (int) $academy['id'] ?>/contracts/create" class="btn btn-primary">
        <i data-lucide="plus" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> إضافة عقد
    </a>
</div>
<?php endif; ?>

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