<?php require_once __DIR__ . '/includes/bootstrap.php';
$pageTitle = 'Requests | 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">Send a request</h1>
  </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 {
    $submissions = ugfx_read_json($ugfx['storage']['requests'], []);
    $submissions[] = [
        'name' => trim($_POST['name'] ?? ''),
        'email' => trim($_POST['email'] ?? ''),
        'artist' => trim($_POST['artist'] ?? ''),
        'song' => trim($_POST['song'] ?? ''),
        'message' => trim($_POST['message'] ?? ''),
        'created_at' => date('Y-m-d H:i:s')
    ];
    ugfx_write_json($ugfx['storage']['requests'], $submissions);
    $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">Your request has been sent to Underground FX.</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">Your 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"></div>
            <div class="col-md-6"><label class="form-label">Artist</label><input class="form-control" name="artist" required></div>
            <div class="col-md-6"><label class="form-label">Song title</label><input class="form-control" name="song" required></div>
            <div class="col-12"><label class="form-label">Shoutout / note</label><textarea class="form-control" rows="5" name="message"></textarea></div>
            <div class="col-12"><button class="btn ugfx-btn-primary">Send request</button></div>
          </form>
        </div>
      </div>
      <div class="col-lg-5">
        <div class="ugfx-card p-4">
          <div class="ugfx-micro-label">REQUESTS UPGRADE PATH</div>
          <h3>Your Request has been sent </h3>
          <p class="text-secondary">once an admin sees your request they will answer .</p>
          <div class="d-flex gap-2 flex-wrap">
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

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