<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تعيينات الورديات<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<!-- نموذج التعيين -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;font-weight:600;">تعيين وردية لموظف</div>
    <form method="POST" action="/hr/shifts/assign" style="padding:20px;display:flex;gap:12px;flex-wrap:wrap;align-items:end;">
        <?= csrf_field() ?>
        <div style="flex:1;min-width:200px;">
            <label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">الموظف</label>
            <select name="employee_id" class="form-control" required>
                <option value="">— اختر موظف —</option>
                <?php foreach ($employees as $emp): ?>
                <option value="<?= (int) $emp['id'] ?>"><?= e($emp['full_name_ar']) ?> (<?= e($emp['employee_number']) ?>)</option>
                <?php endforeach; ?>
            </select>
        </div>
        <div style="min-width:160px;">
            <label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">الوردية</label>
            <select name="shift_id" class="form-control" required>
                <option value="">— اختر وردية —</option>
                <?php foreach ($shifts as $s): ?>
                <option value="<?= (int) $s['id'] ?>"><?= e($s['name_ar']) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div style="min-width:140px;">
            <label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">تاريخ البداية</label>
            <input type="date" name="start_date" value="<?= date('Y-m-d') ?>" class="form-control">
        </div>
        <div style="min-width:140px;">
            <label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">تاريخ النهاية</label>
            <input type="date" name="end_date" value="" class="form-control">
            <small style="color:#6B7280;font-size:11px;">اتركه فارغ لتعيين دائم</small>
        </div>
        <div style="min-width:140px;">
            <label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">النمط</label>
            <select name="rotation_pattern" class="form-control">
                <option value="fixed">ثابت</option>
                <option value="rotating">دوري</option>
            </select>
        </div>
        <button type="submit" class="btn btn-primary">تعيين</button>
    </form>
</div>

<!-- جدول التعيينات -->
<div class="card">
    <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 if (empty($assignments)): ?>
                <tr><td colspan="6" style="text-align:center;padding:40px;color:#9CA3AF;">لا يوجد تعيينات</td></tr>
                <?php else: ?>
                <?php foreach ($assignments as $a): ?>
                <tr>
                    <td><?= e($a['employee_name']) ?></td>
                    <td><code><?= e($a['employee_number']) ?></code></td>
                    <td><?= e($a['shift_name']) ?></td>
                    <td><?= e($a['start_date'] ?? '-') ?></td>
                    <td><?= e($a['end_date'] ?? 'دائم') ?></td>
                    <td><?= ($a['rotation_pattern'] ?? 'fixed') === 'rotating' ? 'دوري' : 'ثابت' ?></td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
