<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>أجهزة البصمة<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<?php if (can('hr.biometric.manage')): ?>
<a href="/hr/biometric/devices/create" class="btn btn-primary" style="display:inline-flex;align-items:center;gap:6px;"><i data-lucide="plus" style="width:16px;height:16px;"></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>IP</th>
                    <th>المنفذ</th>
                    <th>الرقم التسلسلي</th>
                    <th>الموقع</th>
                    <th>آخر مزامنة</th>
                    <th>الحالة</th>
                    <th>إجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($devices)): ?>
                <tr><td colspan="9" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد أجهزة مسجلة</td></tr>
                <?php else: ?>
                <?php
                    $typeLabels = ['fingerprint' => 'بصمة إصبع', 'face' => 'بصمة وجه', 'card' => 'كارت'];
                ?>
                <?php foreach ($devices as $device): ?>
                <tr>
                    <td><?= e($device['device_name']) ?></td>
                    <td><?= e($typeLabels[$device['device_type']] ?? $device['device_type']) ?></td>
                    <td><?= e($device['ip_address'] ?? '-') ?></td>
                    <td><?= $device['port'] ? (int) $device['port'] : '-' ?></td>
                    <td><?= e($device['serial_number'] ?? '-') ?></td>
                    <td><?= e($device['location_description'] ?? '-') ?></td>
                    <td><?= $device['last_sync_at'] ? e($device['last_sync_at']) : '<span style="color:#9CA3AF;">لم تتم</span>' ?></td>
                    <td>
                        <?php if ($device['is_active']): ?>
                        <span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:#DEF7EC;color:#03543F;">فعال</span>
                        <?php else: ?>
                        <span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:#FDE8E8;color:#9B1C1C;">معطل</span>
                        <?php endif; ?>
                    </td>
                    <td style="white-space:nowrap;">
                        <?php if (can('hr.biometric.manage')): ?>
                        <a href="/hr/biometric/devices/<?= (int) $device['id'] ?>/edit" style="color:#2563EB;margin-left:8px;" title="تعديل"><i data-lucide="edit" style="width:16px;height:16px;"></i></a>
                        <?php if ($device['is_active']): ?>
                        <form method="POST" action="/hr/biometric/devices/<?= (int) $device['id'] ?>/delete" style="display:inline;" onsubmit="return confirm('هل أنت متأكد من تعطيل هذا الجهاز؟')">
                            <?= csrf_field() ?>
                            <button type="submit" style="border:none;background:none;cursor:pointer;color:#DC2626;padding:0;" title="تعطيل"><i data-lucide="power-off" style="width:16px;height:16px;"></i></button>
                        </form>
                        <?php endif; ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
