<?php include __DIR__ . '/../includes/header.php'; ensure_can_manage_master_data(); ?>
<div class="table-wrap" style="max-width:760px">
  <h4 class="mb-3">Postulación</h4>
  <form method="post" action="<?= e(base_url($action)) ?>">
    <?php if (!empty($item['id'])): ?><input type="hidden" name="id" value="<?= (int)$item['id'] ?>"><?php endif; ?>
    <div class="mb-3"><label class="form-label">Vacante</label><select name="vacancy_id" class="form-select"><?php foreach (db()->query("SELECT id,title FROM recruitment_vacancies ORDER BY title") as $row): ?><option value="<?= (int)$row['id'] ?>" <?= ((int)($item['vacancy_id'] ?? 0) === (int)$row['id']) ? 'selected' : '' ?>><?= e($row['title']) ?></option><?php endforeach; ?></select></div>
    <div class="mb-3"><label class="form-label">Candidato</label><select name="candidate_id" class="form-select"><?php foreach (db()->query("SELECT id,full_name FROM recruitment_candidates ORDER BY full_name") as $row): ?><option value="<?= (int)$row['id'] ?>" <?= ((int)($item['candidate_id'] ?? 0) === (int)$row['id']) ? 'selected' : '' ?>><?= e($row['full_name']) ?></option><?php endforeach; ?></select></div>
    <div class="mb-3"><label class="form-label">Etapa</label><select name="stage" class="form-select"><?php foreach (['Postulado','Entrevista','Oferta','Contratado','Descartado'] as $opt): ?><option value="<?= e($opt) ?>" <?= (($item['stage'] ?? '') === $opt) ? 'selected' : '' ?>><?= e($opt) ?></option><?php endforeach; ?></select></div>
    <div class="mb-3"><label class="form-label">Puntaje</label><input type="number" name="score" class="form-control" value="<?= e($item['score'] ?? '0') ?>"></div>
    <div class="mb-3"><label class="form-label">Observación</label><textarea name="notes" class="form-control" rows="3"><?= e($item['notes'] ?? '') ?></textarea></div>
    <div class="d-flex gap-2"><button class="btn btn-primary">Guardar</button><a class="btn btn-outline-secondary" href="<?= e(base_url('recruitment/index.php')) ?>">Volver</a></div>
  </form>
</div>
<?php include __DIR__ . '/../includes/footer.php'; ?>