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

<?php $__template->section('page_actions'); ?>
<?php if (can('hr.attendance.manage')): ?>
<a href="/hr/shifts/create" class="btn btn-primary"><i data-lucide="plus" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> وردية جديدة</a>
<?php endif; ?>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<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>
                    <th>الإجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($shifts)): ?>
                <tr><td colspan="7" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد ورديات</td></tr>
                <?php else: ?>
                <?php foreach ($shifts as $shift): ?>
                <tr>
                    <td style="font-weight:600;"><?= e($shift['name_ar'] ?? '—') ?></td>
                    <td style="direction:ltr;text-align:center;"><?= e($shift['start_time'] ?? '—') ?></td>
                    <td style="direction:ltr;text-align:center;"><?= e($shift['end_time'] ?? '—') ?></td>
                    <td style="text-align:center;font-weight:600;"><?= e($shift['working_hours'] ?? '—') ?></td>
                    <td style="text-align:center;"><?= (int) ($shift['grace_period'] ?? 0) ?> دقيقة</td>
                    <td style="text-align:center;">
                        <?php if (!empty($shift['is_night_shift'])): ?>
                        <span style="display:inline-block;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#EFF6FF;color:#2563EB;">
                            <i data-lucide="moon" style="width:12px;height:12px;vertical-align:middle;margin-left:3px;"></i> نعم
                        </span>
                        <?php else: ?>
                        <span style="display:inline-block;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#F3F4F6;color:#6B7280;">
                            <i data-lucide="sun" style="width:12px;height:12px;vertical-align:middle;margin-left:3px;"></i> لا
                        </span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if (can('hr.attendance.manage')): ?>
                        <div style="display:flex;gap:4px;">
                            <a href="/hr/shifts/<?= (int) $shift['id'] ?>/edit" class="btn btn-sm btn-outline" style="font-size:12px;padding:4px 10px;">
                                <i data-lucide="edit" style="width:13px;height:13px;vertical-align:middle;"></i> تعديل
                            </a>
                        </div>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<script>document.addEventListener('DOMContentLoaded', function() { if (typeof lucide !== 'undefined') lucide.createIcons(); });</script>
<?php $__template->endSection(); ?>
