<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تفاصيل راتب: <?= e($profile->first_name_ar . ' ' . $profile->last_name_ar) ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/hr/payroll/runs/<?= (int) $run['id'] ?>/slip" class="btn btn-primary">قسيمة الراتب</a>
<a href="/hr/payroll/periods/<?= (int) $run['period_id'] ?>" 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:18px;font-weight:700;"><?= number_format((float) $run['basic_salary'], 2) ?></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">الإجمالي</div><div style="font-size:18px;font-weight:700;color:#059669;"><?= number_format((float) $run['gross_earnings'], 2) ?></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">الخصومات</div><div style="font-size:18px;font-weight:700;color:#DC2626;"><?= number_format((float) $run['total_deductions'], 2) ?></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:#2563EB;"><?= number_format((float) $run['net_salary'], 2) ?></div></div>
</div>

<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-bottom:20px;">
    <div class="card">
        <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;color:#059669;">الاستحقاقات</h3></div>
        <div class="table-responsive">
            <table class="data-table">
                <thead><tr><th>المكون</th><th>المبلغ</th></tr></thead>
                <tbody>
                    <?php foreach ($earnings as $e): ?>
                    <tr><td><?= e($e['component_name']) ?></td><td style="font-weight:600;"><?= number_format((float) $e['amount'], 2) ?></td></tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="card">
        <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;color:#DC2626;">الخصومات</h3></div>
        <div class="table-responsive">
            <table class="data-table">
                <thead><tr><th>المكون</th><th>المبلغ</th></tr></thead>
                <tbody>
                    <?php foreach ($deductions as $d): ?>
                    <tr><td><?= e($d['component_name']) ?></td><td style="font-weight:600;color:#DC2626;"><?= number_format((float) $d['amount'], 2) ?></td></tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php if ($insurance): ?>
<div class="card" style="margin-bottom:20px;">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;">التأمينات الاجتماعية</h3></div>
    <div style="padding:16px;display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:16px;">
        <div><span style="color:#6B7280;font-size:13px;">حصة الموظف</span><div style="font-weight:600;"><?= number_format((float) $insurance['total_employee_share'], 2) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">حصة صاحب العمل</span><div style="font-weight:600;"><?= number_format((float) $insurance['total_employer_share'], 2) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">الأساسي المؤمن عليه</span><div><?= number_format((float) $insurance['basic_insurable_salary'], 2) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">المتغير المؤمن عليه</span><div><?= number_format((float) $insurance['variable_insurable_salary'], 2) ?></div></div>
    </div>
</div>
<?php endif; ?>

<?php if ($tax): ?>
<div class="card" style="margin-bottom:20px;">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;">ضريبة الدخل</h3></div>
    <div style="padding:16px;display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:16px;">
        <div><span style="color:#6B7280;font-size:13px;">الدخل الخاضع للضريبة</span><div style="font-weight:600;"><?= number_format((float) ($tax['gross_taxable_monthly'] ?? 0), 2) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">الإعفاءات</span><div><?= number_format(((float) ($tax['personal_exemption'] ?? 0)) + ((float) ($tax['insurance_exemption'] ?? 0)), 2) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">مبلغ الضريبة</span><div style="font-weight:700;color:#DC2626;"><?= number_format((float) ($tax['monthly_tax'] ?? 0), 2) ?></div></div>
    </div>
</div>
<?php endif; ?>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
