<?php use App\Helpers\Helper; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
  <div>
    <h1 class="admin-page-title mb-1">Edit Building</h1>
    <p class="text-muted small mb-0"><?= Helper::e($building['name']) ?></p>
  </div>
  <a href="<?= APP_URL ?>/admin/buildings" class="btn btn-outline-secondary btn-sm">
    <i class="bi bi-arrow-left me-1"></i>Back
  </a>
</div>

<div class="row justify-content-center">
  <div class="col-lg-7">
    <div class="form-card">
      <div class="form-section-title">Building Information</div>
      <form method="POST" action="<?= APP_URL ?>/admin/buildings/<?= $building['id'] ?>/edit">
        <?= Helper::csrf() ?>
        <div class="row g-3">
          <div class="col-md-6">
            <label class="form-label fw-600">Property <span class="text-danger">*</span></label>
            <select name="property_id" class="form-select" required>
              <?php foreach ($properties as $p): ?>
              <option value="<?= $p['id'] ?>" <?= $p['id']==$building['property_id']?'selected':'' ?>><?= Helper::e($p['name']) ?></option>
              <?php endforeach; ?>
            </select>
          </div>
          <div class="col-md-6">
            <label class="form-label fw-600">Building Name <span class="text-danger">*</span></label>
            <input type="text" name="name" class="form-control" value="<?= Helper::e($building['name']) ?>" required>
          </div>
          <div class="col-md-4">
            <label class="form-label fw-600">Code</label>
            <input type="text" name="code" class="form-control" value="<?= Helper::e($building['code']??'') ?>">
          </div>
          <div class="col-md-4">
            <label class="form-label fw-600">Floors</label>
            <input type="number" name="floors" class="form-control" value="<?= $building['floors'] ?>" min="1" max="50">
          </div>
          <div class="col-md-4">
            <label class="form-label fw-600">Status</label>
            <select name="status" class="form-select">
              <?php foreach (['active','inactive','under_construction'] as $s): ?>
              <option value="<?= $s ?>" <?= $building['status']===$s?'selected':'' ?>><?= ucfirst(str_replace('_',' ',$s)) ?></option>
              <?php endforeach; ?>
            </select>
          </div>
          <div class="col-12">
            <label class="form-label fw-600">Description</label>
            <textarea name="description" class="form-control" rows="3"><?= Helper::e($building['description']??'') ?></textarea>
          </div>
        </div>
        <div class="d-flex gap-2 mt-4">
          <button type="submit" class="btn btn-primary px-4"><i class="bi bi-save me-2"></i>Update Building</button>
          <a href="<?= APP_URL ?>/admin/buildings" class="btn btn-outline-secondary">Cancel</a>
        </div>
      </form>
    </div>
  </div>
</div>
