<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>طلب سلفة جديد<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/loans" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<form method="POST" action="/hr/loans">
    <?= csrf_field() ?>
    <div class="card" style="margin-bottom:20px;">
        <div style="padding:16px;display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:16px;">
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">الموظف <span style="color:#DC2626;">*</span></label>
                <select name="employee_profile_id" class="form-control" required><option value="">-- اختر --</option>
                <?php foreach ($employees as $emp): ?><option value="<?= (int) $emp['id'] ?>" <?= old('employee_profile_id') == $emp['id'] ? 'selected' : '' ?>><?= e($emp['first_name_ar'] . ' ' . $emp['last_name_ar']) ?></option><?php endforeach; ?>
                </select>
            </div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">نوع السلفة</label>
                <select name="loan_type" class="form-control">
                    <option value="salary_advance" <?= old('loan_type') === 'salary_advance' ? 'selected' : '' ?>>سلفة راتب</option>
                    <option value="personal_loan" <?= old('loan_type') === 'personal_loan' ? 'selected' : '' ?>>قرض شخصي</option>
                    <option value="emergency_loan" <?= old('loan_type') === 'emergency_loan' ? 'selected' : '' ?>>قرض طوارئ</option>
                </select>
            </div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">المبلغ <span style="color:#DC2626;">*</span></label><input type="text" name="loan_amount" value="<?= e(old('loan_amount') ?? '') ?>" class="form-control" placeholder="0.00" required></div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">عدد الأقساط <span style="color:#DC2626;">*</span></label><input type="number" name="number_of_installments" value="<?= e(old('number_of_installments') ?? '1') ?>" class="form-control" min="1" max="60" required></div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">تاريخ الطلب</label><input type="date" name="request_date" value="<?= e(old('request_date') ?? date('Y-m-d')) ?>" class="form-control"></div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">بداية الخصم</label><input type="date" name="start_deduction_date" value="<?= e(old('start_deduction_date') ?? date('Y-m-01', strtotime('+1 month'))) ?>" class="form-control"></div>
            <div style="grid-column:1/-1;"><label style="display:block;margin-bottom:4px;font-size:13px;">السبب</label><textarea name="reason" class="form-control" rows="2"><?= e(old('reason') ?? '') ?></textarea></div>
            <div style="grid-column:1/-1;"><label style="display:block;margin-bottom:4px;font-size:13px;">ملاحظات</label><textarea name="notes" class="form-control" rows="2"><?= e(old('notes') ?? '') ?></textarea></div>
        </div>
    </div>
    <div style="display:flex;gap:10px;justify-content:flex-end;">
        <a href="/hr/loans" class="btn btn-secondary">إلغاء</a>
        <button type="submit" class="btn btn-primary">تقديم الطلب</button>
    </div>
</form>
<?php $__template->endSection(); ?>
