<?php
$isEdit    = isset($company) && $company;
$pageTitle = $isEdit ? 'Edit Company' : 'Add Company';
include __DIR__ . '/../shared/header.php';
$c = $company ?? [];
?>

<div class="page-header">
  <div class="page-title"><?= $isEdit ? '<i class="bi bi-pencil me-2"></i>Edit Company' : '<i class="bi bi-plus-circle me-2"></i>Add Company' ?></div>
  <a href="<?= APP_URL ?>/index.php?page=companies" 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">Company Name <span class="text-danger">*</span></label>
        <input type="text" name="company_name" class="form-control" value="<?= e($c['company_name'] ?? '') ?>" required>
      </div>
      <div class="mb-3">
        <label class="form-label">Address</label>
        <textarea name="address" class="form-control" rows="3"><?= e($c['address'] ?? '') ?></textarea>
      </div>
      <div class="row g-3 mb-3">
        <div class="col-md-6">
          <label class="form-label">Phone</label>
          <input type="text" name="phone" class="form-control" value="<?= e($c['phone'] ?? '') ?>">
        </div>
        <div class="col-md-6">
          <label class="form-label">Email</label>
          <input type="email" name="email" class="form-control" value="<?= e($c['email'] ?? '') ?>">
        </div>
      </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' : 'Add' ?> Company</button>
        <a href="<?= APP_URL ?>/index.php?page=companies" class="btn btn-outline-secondary">Cancel</a>
      </div>
    </form>
  </div></div>
</div></div>

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