<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>طلب إجازة #<?= (int) $leaveRequest->id ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/leaves" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<?php $sl = ['pending'=>'معلق','approved'=>'موافق','rejected'=>'مرفوض','cancelled'=>'ملغي','taken'=>'تم أخذها']; ?>
<?php $sc = ['pending'=>'#FEF3C7;color:#92400E','approved'=>'#DEF7EC;color:#03543F','rejected'=>'#FDE8E8;color:#9B1C1C','cancelled'=>'#E5E7EB;color:#374151','taken'=>'#DBEAFE;color:#1E40AF']; ?>

<div class="card" style="margin-bottom:20px;">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;font-size:16px;display:flex;align-items:center;gap:8px;">
            <i data-lucide="calendar" style="width:18px;height:18px;color:#6B7280;"></i> تفاصيل الطلب
            <span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:<?= $sc[$leaveRequest->status] ?? '#E5E7EB;color:#374151' ?>;"><?= e($sl[$leaveRequest->status] ?? $leaveRequest->status) ?></span>
        </h3>
    </div>
    <div style="padding:16px;display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px;">
        <div><span style="color:#6B7280;font-size:13px;">الموظف</span><div><a href="/hr/employees/<?= (int) $profile->id ?>"><?= e($profile->first_name_ar . ' ' . $profile->last_name_ar) ?></a></div></div>
        <div><span style="color:#6B7280;font-size:13px;">نوع الإجازة</span><div style="font-weight:600;"><?= e($leaveType['name_ar'] ?? '-') ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">من</span><div><?= e($leaveRequest->start_date) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">إلى</span><div><?= e($leaveRequest->end_date) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">عدد الأيام</span><div style="font-weight:600;"><?= number_format((float) $leaveRequest->total_days, 1) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">نصف يوم</span><div><?= $leaveRequest->half_day ? 'نعم' : 'لا' ?></div></div>
        <?php if ($leaveRequest->reason): ?>
        <div style="grid-column:1/-1;"><span style="color:#6B7280;font-size:13px;">السبب</span><div><?= e($leaveRequest->reason) ?></div></div>
        <?php endif; ?>
        <?php if ($approver): ?>
        <div><span style="color:#6B7280;font-size:13px;">بواسطة</span><div><?= e($approver['name']) ?></div></div>
        <?php endif; ?>
    </div>
</div>

<?php if ($balance): ?>
<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(140px,1fr));gap:16px;">
        <div><span style="color:#6B7280;font-size:13px;">المستحق</span><div style="font-weight:600;"><?= number_format((float) ($balance['entitled_days'] ?? 0), 1) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">المستخدم</span><div style="font-weight:600;"><?= number_format((float) ($balance['used_days'] ?? 0), 1) ?></div></div>
        <div><span style="color:#6B7280;font-size:13px;">المتبقي</span><div style="font-weight:700;font-size:18px;color:#059669;"><?= number_format((float) ($balance['remaining_days'] ?? 0), 1) ?></div></div>
    </div>
</div>
<?php endif; ?>

<?php if ($leaveRequest->status === 'pending'): ?>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
    <form method="POST" action="/hr/leaves/<?= (int) $leaveRequest->id ?>/approve"><?= csrf_field() ?><button type="submit" class="btn btn-primary">موافقة</button></form>
    <form method="POST" action="/hr/leaves/<?= (int) $leaveRequest->id ?>/reject" style="display:flex;gap:8px;align-items:end;">
        <?= csrf_field() ?>
        <input type="text" name="rejection_reason" placeholder="سبب الرفض..." class="form-control" style="min-width:200px;">
        <button type="submit" class="btn btn-danger">رفض</button>
    </form>
    <form method="POST" action="/hr/leaves/<?= (int) $leaveRequest->id ?>/cancel" onsubmit="return confirm('هل أنت متأكد؟');"><?= csrf_field() ?><button type="submit" class="btn btn-secondary">إلغاء الطلب</button></form>
</div>
<?php endif; ?>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
