<?php $__template->layout('Layout.main'); ?>
<?php $isEdit = $device !== null; ?>
<?php $__template->section('title'); ?><?= $isEdit ? 'تعديل جهاز البصمة' : 'إضافة جهاز بصمة' ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/biometric/devices" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<form method="POST" action="<?= $isEdit ? '/hr/biometric/devices/' . (int) $device['id'] : '/hr/biometric/devices' ?>">
    <?= 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>
                <input type="text" name="device_name" value="<?= e(old('device_name') ?? ($isEdit ? $device['device_name'] : '')) ?>" class="form-control" required>
            </div>
            <div>
                <label style="display:block;margin-bottom:4px;font-size:13px;">نوع الجهاز <span style="color:#DC2626;">*</span></label>
                <select name="device_type" class="form-control">
                    <?php $currentType = old('device_type') ?? ($isEdit ? $device['device_type'] : 'fingerprint'); ?>
                    <option value="fingerprint" <?= $currentType === 'fingerprint' ? 'selected' : '' ?>>بصمة إصبع</option>
                    <option value="face" <?= $currentType === 'face' ? 'selected' : '' ?>>بصمة وجه</option>
                    <option value="card" <?= $currentType === 'card' ? 'selected' : '' ?>>كارت</option>
                </select>
            </div>
            <div>
                <label style="display:block;margin-bottom:4px;font-size:13px;">عنوان IP</label>
                <input type="text" name="ip_address" value="<?= e(old('ip_address') ?? ($isEdit ? $device['ip_address'] : '')) ?>" class="form-control" placeholder="192.168.1.100">
            </div>
            <div>
                <label style="display:block;margin-bottom:4px;font-size:13px;">المنفذ (Port)</label>
                <input type="number" name="port" value="<?= e(old('port') ?? ($isEdit ? $device['port'] : '')) ?>" class="form-control" min="1" max="65535" placeholder="4370">
            </div>
            <div>
                <label style="display:block;margin-bottom:4px;font-size:13px;">الرقم التسلسلي</label>
                <input type="text" name="serial_number" value="<?= e(old('serial_number') ?? ($isEdit ? $device['serial_number'] : '')) ?>" class="form-control">
            </div>
            <div>
                <label style="display:block;margin-bottom:4px;font-size:13px;">وصف الموقع</label>
                <input type="text" name="location_description" value="<?= e(old('location_description') ?? ($isEdit ? $device['location_description'] : '')) ?>" class="form-control" placeholder="البوابة الرئيسية">
            </div>
            <div>
                <label style="display:block;margin-bottom:4px;font-size:13px;">الفرع</label>
                <select name="branch_id" class="form-control">
                    <option value="">-- بدون فرع --</option>
                    <?php $currentBranch = (int) (old('branch_id') ?? ($isEdit ? $device['branch_id'] : 0)); ?>
                    <?php foreach ($branches as $branch): ?>
                    <option value="<?= (int) $branch['id'] ?>" <?= $currentBranch === (int) $branch['id'] ? 'selected' : '' ?>><?= e($branch['name_ar']) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div>
                <label style="display:block;margin-bottom:4px;font-size:13px;">
                    <input type="checkbox" name="is_active" value="1" <?= (old('is_active') ?? ($isEdit ? $device['is_active'] : 1)) ? 'checked' : '' ?>> فعال
                </label>
            </div>
        </div>
    </div>
    <div style="display:flex;gap:10px;justify-content:flex-end;">
        <a href="/hr/biometric/devices" class="btn btn-secondary">إلغاء</a>
        <button type="submit" class="btn btn-primary"><?= $isEdit ? 'تحديث' : 'حفظ' ?></button>
    </div>
</form>
<?php $__template->endSection(); ?>
