<?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'] ?>/edit" class="btn btn-primary"><i data-lucide="edit-3" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> تعديل</a>
<a href="/sa/academies/<?= (int) $academy['id'] ?>/contracts/create" class="btn btn-outline"><i data-lucide="plus" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> إضافة عقد</a>
<a href="/sa/academies" 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
$typeLabels = ['internal' => 'داخلية', 'external' => 'خارجية', 'partnership' => 'شراكة'];
$typeColors = ['internal' => '#059669', 'external' => '#7C3AED', 'partnership' => '#0D7377'];
$aType = $academy['academy_type'] ?? 'internal';
$atColor = $typeColors[$aType] ?? '#6B7280';
?>

<!-- Academy Info -->
<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:64px;height:64px;border-radius:12px;background:linear-gradient(135deg, <?= $atColor ?>15, <?= $atColor ?>30);display:flex;align-items:center;justify-content:center;">
            <i data-lucide="graduation-cap" style="width:32px;height:32px;color:<?= $atColor ?>;"></i>
        </div>
        <div>
            <h2 style="margin:0 0 4px;font-size:20px;font-weight:700;"><?= e($academy['name_ar'] ?? '') ?></h2>
            <?php if (!empty($academy['name_en'])): ?>
            <div style="font-size:13px;color:#6B7280;margin-bottom:4px;" dir="ltr"><?= e($academy['name_en']) ?></div>
            <?php endif; ?>
            <div style="display:flex;gap:8px;flex-wrap:wrap;">
                <code style="font-size:11px;background:#F3F4F6;padding:2px 8px;border-radius:4px;"><?= e($academy['code'] ?? '') ?></code>
                <span style="padding:2px 10px;border-radius:10px;font-size:11px;font-weight:600;background:<?= $atColor ?>15;color:<?= $atColor ?>;"><?= e($typeLabels[$aType] ?? $aType) ?></span>
                <?php if ((int) ($academy['is_active'] ?? 0)): ?>
                <span style="padding:2px 10px;border-radius:10px;font-size:11px;font-weight:600;background:#05966915;color:#059669;">فعالة</span>
                <?php else: ?>
                <span style="padding:2px 10px;border-radius:10px;font-size:11px;font-weight:600;background:#DC262615;color:#DC2626;">معطلة</span>
                <?php endif; ?>
            </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($academy['discipline_name'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">مسؤول التواصل</div>
            <div style="font-size:14px;font-weight:600;"><?= e($academy['contact_person'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">هاتف التواصل</div>
            <div style="font-size:14px;font-weight:600;" dir="ltr"><?= e($academy['contact_phone'] ?? '-') ?></div>
        </div>
        <div>
            <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">البريد الإلكتروني</div>
            <div style="font-size:14px;font-weight:600;" dir="ltr"><?= e($academy['contact_email'] ?? '-') ?></div>
        </div>
    </div>

    <?php if (!empty($academy['description_ar'])): ?>
    <div style="padding:0 20px 20px;">
        <div style="font-size:12px;color:#9CA3AF;margin-bottom:4px;">الوصف</div>
        <div style="font-size:14px;line-height:1.8;color:#374151;"><?= nl2br(e($academy['description_ar'])) ?></div>
    </div>
    <?php endif; ?>
</div>

<!-- Contracts Section -->
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;align-items:center;">
        <h3 style="margin:0;font-size:16px;font-weight:600;">العقود</h3>
        <a href="/sa/academies/<?= (int) $academy['id'] ?>/contracts/create" class="btn btn-sm btn-primary">
            <i data-lucide="plus" style="width:14px;height:14px;vertical-align:middle;margin-left:4px;"></i> إضافة عقد
        </a>
    </div>

    <?php if (!empty($contracts)): ?>
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>رقم العقد</th>
                    <th>النوع</th>
                    <th>من</th>
                    <th>إلى</th>
                    <th>الحالة</th>
                    <th>إجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $contractTypeLabels = ['revenue_share' => 'نسبة إيرادات', 'fixed_rent' => 'إيجار ثابت', 'hybrid' => 'مختلط'];
                $statusLabels = ['pending_approval' => 'بانتظار الاعتماد', 'active' => 'فعال', 'expired' => 'منتهي', 'terminated' => 'ملغي'];
                $statusColors = ['pending_approval' => '#D97706', 'active' => '#059669', 'expired' => '#6B7280', 'terminated' => '#DC2626'];
                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>
                        <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>
                        <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>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php else: ?>
    <div style="padding:40px 20px;text-align:center;color:#9CA3AF;">
        <i data-lucide="file-text" style="width:36px;height:36px;color:#D1D5DB;margin-bottom:10px;"></i>
        <p>لا توجد عقود بعد.</p>
    </div>
    <?php endif; ?>
</div>

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