<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>بيان القوة الفعلية<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/reports" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px;margin-bottom:20px;">
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">إجمالي العاملين</div><div style="font-size:24px;font-weight:700;"><?= (int) ($totals['total_active'] ?? 0) ?></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">مؤمن عليهم</div><div style="font-size:24px;font-weight:700;color:#059669;"><?= (int) ($totals['insured_count'] ?? 0) ?></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">غير متفرغ</div><div style="font-size:24px;font-weight:700;color:#D97706;"><?= (int) ($totals['part_time_count'] ?? 0) ?></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">الشواغر</div><div style="font-size:24px;font-weight:700;color:#DC2626;"><?= (int) ($totals['vacancies'] ?? 0) ?></div></div>
</div>
<div class="card">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;display:flex;justify-content:space-between;align-items:center;">
        <h3 style="margin:0;font-size:16px;">بيان القوة الفعلية — <?= arabic_date(date('Y-m-d')) ?></h3>
        <button onclick="window.print()" class="btn btn-sm btn-outline-primary no-print">طباعة</button>
    </div>
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>الإدارة / القسم</th>
                    <th>مؤمن عليهم</th>
                    <th>غير متفرغ</th>
                    <th>أخرى</th>
                    <th>إجمالي العاملين</th>
                    <th>القدرة الاستيعابية</th>
                    <th>الشواغر</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($departments)): ?>
                <tr><td colspan="7" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد بيانات</td></tr>
                <?php else: ?>
                <?php foreach ($departments as $d): ?>
                <tr>
                    <td style="font-weight:600;"><?= e($d['name_ar'] ?? '') ?></td>
                    <td><?= (int) $d['insured_count'] ?></td>
                    <td><?= (int) $d['part_time_count'] ?></td>
                    <td><?= (int) $d['other_count'] ?></td>
                    <td style="font-weight:700;"><?= (int) $d['total_active'] ?></td>
                    <td><?= (int) ($d['staffing_capacity'] ?? 0) ?></td>
                    <td style="color:<?= (int) $d['vacancies'] > 0 ? '#DC2626' : '#059669' ?>;"><?= (int) $d['vacancies'] ?></td>
                </tr>
                <?php endforeach; ?>
                <tr style="font-weight:700;background:#F3F4F6;">
                    <td>الإجمالي</td>
                    <td><?= (int) ($totals['insured_count'] ?? 0) ?></td>
                    <td><?= (int) ($totals['part_time_count'] ?? 0) ?></td>
                    <td><?= (int) ($totals['other_count'] ?? 0) ?></td>
                    <td><?= (int) ($totals['total_active'] ?? 0) ?></td>
                    <td><?= (int) ($totals['capacity'] ?? 0) ?></td>
                    <td style="color:#DC2626;"><?= (int) ($totals['vacancies'] ?? 0) ?></td>
                </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
