<?php
$departments = db()->query("SELECT id, name FROM departments ORDER BY name")->fetchAll();
$positions = db()->query("SELECT id, name FROM positions ORDER BY name")->fetchAll();
?>
<div class="row">
  <div class="col-md-6 mb-3"><label class="form-label">Nombre completo</label><input name="full_name" class="form-control" required value="<?= e($item['full_name'] ?? '') ?>"></div>
  <div class="col-md-3 mb-3"><label class="form-label">Cédula</label><input name="document_number" class="form-control" required value="<?= e($item['document_number'] ?? '') ?>"></div>
  <div class="col-md-3 mb-3"><label class="form-label">Fecha ingreso</label><input type="date" name="hire_date" class="form-control" required value="<?= e($item['hire_date'] ?? date('Y-m-d')) ?>"></div>

  <div class="col-md-4 mb-3"><label class="form-label">Departamento</label>
    <select name="department_id" class="form-select">
      <option value="">Seleccione</option>
      <?php foreach ($departments as $d): ?>
      <option value="<?= e($d['id']) ?>" <?= (($item['department_id'] ?? '') == $d['id']) ? 'selected' : '' ?>><?= e($d['name']) ?></option>
      <?php endforeach; ?>
    </select>
  </div>
  <div class="col-md-4 mb-3"><label class="form-label">Cargo</label>
    <select name="position_id" class="form-select">
      <option value="">Seleccione</option>
      <?php foreach ($positions as $p): ?>
      <option value="<?= e($p['id']) ?>" <?= (($item['position_id'] ?? '') == $p['id']) ? 'selected' : '' ?>><?= e($p['name']) ?></option>
      <?php endforeach; ?>
    </select>
  </div>
  <div class="col-md-4 mb-3"><label class="form-label">Salario</label><input type="number" step="0.01" name="salary" class="form-control" required value="<?= e($item['salary'] ?? '0') ?>"></div>

  <div class="col-md-4 mb-3"><label class="form-label">Correo</label><input type="email" name="email" class="form-control" value="<?= e($item['email'] ?? '') ?>"></div>
  <div class="col-md-4 mb-3"><label class="form-label">Teléfono</label><input name="phone" class="form-control" value="<?= e($item['phone'] ?? '') ?>"></div>
  <div class="col-md-4 mb-3"><label class="form-label">Estado</label>
    <select name="status" class="form-select">
      <?php foreach (['active'=>'Activo','inactive'=>'Inactivo'] as $k=>$v): ?>
      <option value="<?= e($k) ?>" <?= (($item['status'] ?? 'active') == $k) ? 'selected' : '' ?>><?= e($v) ?></option>
      <?php endforeach; ?>
    </select>
  </div>
  <div class="col-12 mb-3"><label class="form-label">Dirección</label><input name="address" class="form-control" value="<?= e($item['address'] ?? '') ?>"></div>
</div>
