<?php
$isEdit    = isset($lab) && $lab;
$pageTitle = $isEdit ? 'Edit Laboratory' : 'Add Laboratory';
include __DIR__ . '/../shared/header.php';
?>

<div class="page-header">
  <div class="page-title"><?= $isEdit ? '<i class="bi bi-pencil me-2"></i>Edit Laboratory' : '<i class="bi bi-plus-circle me-2"></i>Add Laboratory' ?></div>
  <a href="<?= APP_URL ?>/index.php?page=labs" class="btn btn-outline-secondary"><i class="bi bi-arrow-left me-1"></i>Back</a>
</div>

<div class="row"><div class="col-lg-7">
  <div class="card"><div class="card-body">
    <form method="POST">
      <input type="hidden" name="csrf_token" value="<?= csrfToken() ?>">
      <div class="mb-3">
        <label class="form-label">Laboratory Name <span class="text-danger">*</span></label>
        <input type="text" name="lab_name" class="form-control" value="<?= e($lab['lab_name'] ?? '') ?>" required>
      </div>
      <div class="mb-3">
        <label class="form-label">Lab Code <span class="text-danger">*</span></label>
        <input type="text" name="lab_code" class="form-control" value="<?= e($lab['lab_code'] ?? '') ?>" maxlength="10" required placeholder="e.g. MRQL">
      </div>
      <div class="mb-3">
        <label class="form-label">Department <span class="text-danger">*</span></label>
        <input type="text" name="department" class="form-control" value="<?= e($lab['department'] ?? '') ?>" required>
      </div>
      <div class="mb-4">
        <label class="form-label">Description</label>
        <textarea name="description" class="form-control" rows="3"><?= e($lab['description'] ?? '') ?></textarea>
      </div>
      <div class="d-flex gap-2">
        <button type="submit" class="btn btn-primary"><i class="bi bi-check-lg me-1"></i><?= $isEdit ? 'Update' : 'Create' ?> Laboratory</button>
        <a href="<?= APP_URL ?>/index.php?page=labs" class="btn btn-outline-secondary">Cancel</a>
      </div>
    </form>
  </div></div>
</div></div>

<?php include __DIR__ . '/../shared/footer.php'; ?>
