<?php require_once __DIR__ . '/includes/bootstrap.php';
$pageTitle = 'Contact | Underground FX Radio';
$currentPage = basename(__FILE__);
include __DIR__ . '/includes/header.php';
?>
<section class="ugfx-page-hero">
  <div class="container-xxl">
    <div class="ugfx-kicker"><i class="bi bi-lightning-charge-fill"></i> Underground FX Radio</div>
    <h1 class="page-title">Contact the station</h1>
    <p class="page-copy">One of the admins will contact you back Shortly.</p>
  </div>
</section>

<?php
$success = false;
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!ugfx_verify_csrf((string)($_POST['csrf_token'] ?? ''))) {
        $error = 'Security check failed. Please refresh and try again.';
    } else {
    $items = ugfx_read_json($ugfx['storage']['contact'], []);
    $items[] = [
        'name' => trim($_POST['name'] ?? ''),
        'email' => trim($_POST['email'] ?? ''),
        'subject' => trim($_POST['subject'] ?? ''),
        'message' => trim($_POST['message'] ?? ''),
        'created_at' => date('Y-m-d H:i:s')
    ];
    ugfx_write_json($ugfx['storage']['contact'], $items);
    $success = true;
    }
}
?>
<section class="section-pad pt-3">
  <div class="container-xxl">
    <div class="row g-4">
      <div class="col-lg-7">
        <div class="ugfx-card p-4">
          <?php if ($success): ?><div class="alert alert-success">Message saved into the new contact queue.</div><?php endif; ?>
          <?php if ($error !== ""): ?><div class="alert alert-danger"><?= htmlspecialchars($error) ?></div><?php endif; ?>
          <form method="post" class="row g-3">
            <input type="hidden" name="csrf_token" value="<?= htmlspecialchars(ugfx_csrf_token()) ?>">
            <div class="col-md-6"><label class="form-label">Name</label><input class="form-control" name="name" required></div>
            <div class="col-md-6"><label class="form-label">Email</label><input class="form-control" type="email" name="email" required></div>
            <div class="col-12"><label class="form-label">Subject</label><input class="form-control" name="subject" required></div>
            <div class="col-12"><label class="form-label">Message</label><textarea class="form-control" rows="6" name="message" required></textarea></div>
            <div class="col-12"><button class="btn ugfx-btn-primary">Send message</button></div>
          </form>
        </div>
      </div>
      <div class="col-lg-5"><div class="ugfx-card p-4"><h3>Launch contact shell</h3><p class="text-secondary mb-0">.</p></div></div>
    </div>
  </div>
</section>

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