<?php
$page_title       = "Contact Us | Cinderella Charity Ball Arlington";
$page_description = "Get in touch with the Cinderella Charity Ball. Questions about donations, sponsorships, candidate applications, or the Ladies' Auxiliary — we're here to help.";

/* ── Form Processing ── */
$form_sent  = false;
$form_error = '';
$form_data  = ['name' => '', 'email' => '', 'phone' => '', 'subject' => '', 'message' => ''];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

  /* Honeypot — silent bail */
  if (!empty($_POST['website'])) {
    header('Location: /contact.php');
    exit;
  }

  /* Sanitize */
  $form_data['name']    = trim(strip_tags($_POST['name']    ?? ''));
  $form_data['email']   = trim($_POST['email']   ?? '');
  $form_data['phone']   = trim(strip_tags($_POST['phone']   ?? ''));
  $form_data['subject'] = trim(strip_tags($_POST['subject'] ?? 'General Inquiry'));
  $form_data['message'] = trim(strip_tags($_POST['message'] ?? ''));

  $valid_email = filter_var($form_data['email'], FILTER_VALIDATE_EMAIL);

  if (!$form_data['name'] || !$valid_email || !$form_data['message']) {
    $form_error = 'Please fill in all required fields with a valid email address.';
  } else {

    $to      = 'askus@cinderellacharityball.com';
    $subject = 'Website Contact: ' . $form_data['subject'];
    $body    = "Name: {$form_data['name']}\nEmail: {$form_data['email']}\nPhone: {$form_data['phone']}\nSubject: {$form_data['subject']}\n\nMessage:\n{$form_data['message']}";
    $headers = implode("\r\n", [
      'From: noreply@cinderellacharityball.com',
      'Reply-To: ' . $form_data['email'],
      'Content-Type: text/plain; charset=UTF-8',
      'X-Mailer: PHP/' . phpversion(),
    ]);

    if (mail($to, $subject, $body, $headers)) {

      /* Auto-response to sender */
      $auto_subj    = 'Thank you for contacting the Cinderella Charity Ball';
      $auto_body    = "Dear {$form_data['name']},\n\nThank you for reaching out to the Cinderella Charity Ball. We have received your message and a member of our team will be in touch shortly.\n\nIf your inquiry is urgent, you may also reach us at:\ncinderellacharityball@gmail.com\n\nWarm regards,\nLadies' Auxiliary of Arlington\nCinderella Charity Ball\nPO Box 152336, Arlington, TX 76015";
      $auto_headers = "From: noreply@cinderellacharityball.com\r\nReply-To: askus@cinderellacharityball.com";
      mail($form_data['email'], $auto_subj, $auto_body, $auto_headers);

      $form_sent = true;
      $form_data = ['name' => '', 'email' => '', 'phone' => '', 'subject' => '', 'message' => ''];
    } else {
      $form_error = 'Sorry, there was a problem sending your message. Please email us directly at cinderellacharityball@gmail.com or call us.';
    }
  }
}

/* Pre-fill subject from URL param */
$pre_subject = htmlspecialchars($_GET['subject'] ?? '');

include 'includes/header.php';
?>

<!-- ============================================================
     PAGE HERO
     ============================================================ -->
<section class="page-hero">
  <div class="page-hero-bg" style="background-image:url('/image/imgi_9_2026CCB-Candidates12-19-25-700x300.jpg');" role="img" aria-label="Cinderella Charity Ball community gathering"></div>
  <div class="page-hero-overlay" aria-hidden="true"></div>
  <div class="page-hero-inner">
    <nav class="breadcrumb" aria-label="Breadcrumb">
      <a href="/">Home</a>
      <i class="fas fa-chevron-right" aria-hidden="true"></i>
      <span aria-current="page">Contact</span>
    </nav>
    <div class="page-hero-tag"><i class="fas fa-envelope" aria-hidden="true"></i> Get in Touch</div>
    <h1>Contact Us</h1>
    <p class="page-hero-desc">Questions about donations, sponsorships, candidate applications, or the Ladies' Auxiliary? We're here to help — reach out anytime.</p>
  </div>
</section>


<!-- ============================================================
     CONTACT SECTION
     ============================================================ -->
<section class="contact-section" aria-labelledby="contact-heading">
  <div class="container">
    <div class="contact-layout">

      <!-- ── Contact Form ── -->
      <div class="contact-form-wrap reveal-left">
        <h2 id="contact-heading">Send Us a Message</h2>
        <p>We typically respond within 1–2 business days. For urgent campaign matters, please email us directly.</p>

        <?php if ($form_sent) : ?>
        <div class="alert alert-success" role="alert">
          <i class="fas fa-check-circle" aria-hidden="true"></i>
          <div>
            <strong>Message sent!</strong> Thank you for reaching out. We've received your message and will be in touch soon. A confirmation has been sent to your email.
          </div>
        </div>
        <?php endif; ?>

        <?php if ($form_error) : ?>
        <div class="alert alert-error" role="alert">
          <i class="fas fa-exclamation-circle" aria-hidden="true"></i>
          <div><?php echo htmlspecialchars($form_error); ?></div>
        </div>
        <?php endif; ?>

        <form method="POST" action="/contact.php" novalidate>

          <!-- Honeypot (hidden from humans) -->
          <div class="form-honeypot" aria-hidden="true">
            <input type="text" name="website" tabindex="-1" autocomplete="off">
          </div>

          <div class="form-row">
            <div class="form-group">
              <label class="form-label" for="name">Full Name <span class="req" aria-label="required">*</span></label>
              <input
                class="form-input"
                type="text" id="name" name="name"
                value="<?php echo htmlspecialchars($form_data['name']); ?>"
                placeholder="Jane Smith"
                autocomplete="name"
                required
                aria-required="true"
              >
            </div>
            <div class="form-group">
              <label class="form-label" for="email">Email Address <span class="req" aria-label="required">*</span></label>
              <input
                class="form-input"
                type="email" id="email" name="email"
                value="<?php echo htmlspecialchars($form_data['email']); ?>"
                placeholder="jane@example.com"
                autocomplete="email"
                required
                aria-required="true"
              >
            </div>
          </div>

          <div class="form-row">
            <div class="form-group">
              <label class="form-label" for="phone">Phone Number</label>
              <input
                class="form-input"
                type="tel" id="phone" name="phone"
                value="<?php echo htmlspecialchars($form_data['phone']); ?>"
                placeholder="(817) 555-0100"
                autocomplete="tel"
              >
            </div>
            <div class="form-group">
              <label class="form-label" for="subject">I'm contacting about…</label>
              <select class="form-select" id="subject" name="subject">
                <?php
                $subjects = [
                  ''                       => 'Select a topic',
                  'General Inquiry'        => 'General Inquiry',
                  'Donations'              => 'Donations',
                  'Sponsorship'            => 'Sponsorship Opportunities',
                  'Candidate Applications' => 'Candidate Applications',
                  'auxiliary'              => "Joining the Ladies' Auxiliary",
                  'Membership Dues'        => 'Membership Dues / Renewal',
                  'Media Inquiry'          => 'Media / Press Inquiry',
                  'Tickets'                => 'Ball Tickets',
                  'Technical Support'      => 'Website / Technical Issue',
                ];
                foreach ($subjects as $val => $label) :
                  $selected = ($form_data['subject'] === $val || $pre_subject === $val) ? 'selected' : '';
                ?>
                <option value="<?php echo htmlspecialchars($val); ?>" <?php echo $selected; ?>><?php echo htmlspecialchars($label); ?></option>
                <?php endforeach; ?>
              </select>
            </div>
          </div>

          <div class="form-group">
            <label class="form-label" for="message">Message <span class="req" aria-label="required">*</span></label>
            <textarea
              class="form-textarea"
              id="message" name="message"
              placeholder="Tell us how we can help you…"
              rows="6"
              required
              aria-required="true"
            ><?php echo htmlspecialchars($form_data['message']); ?></textarea>
          </div>

          <button type="submit" class="form-submit">
            <i class="fas fa-paper-plane" aria-hidden="true"></i> Send Message
          </button>

          <p class="form-notice">
            <i class="fas fa-lock" aria-hidden="true"></i>
            Your information is private and will never be shared or sold.
          </p>

        </form>
      </div><!-- .contact-form-wrap -->


      <!-- ── Contact Info Sidebar ── -->
      <aside class="contact-info-wrap reveal-right">

        <div class="contact-info-card">
          <h4>Contact Information</h4>

          <div class="contact-info-item">
            <div class="ci-icon"><i class="fas fa-envelope" aria-hidden="true"></i></div>
            <div>
              <p class="ci-lbl">General Inquiries</p>
              <a href="mailto:askus@cinderellacharityball.com" class="ci-val">askus@cinderellacharityball.com</a>
            </div>
          </div>

          <div class="contact-info-item">
            <div class="ci-icon"><i class="fas fa-heart" aria-hidden="true"></i></div>
            <div>
              <p class="ci-lbl">Donations</p>
              <a href="mailto:cinderellacharityball@gmail.com" class="ci-val">cinderellacharityball@gmail.com</a>
            </div>
          </div>

          <div class="contact-info-item">
            <div class="ci-icon"><i class="fas fa-map-marker-alt" aria-hidden="true"></i></div>
            <div>
              <p class="ci-lbl">Mailing Address</p>
              <p class="ci-val">
                Ladies Auxiliary of Arlington, Inc.<br>
                PO Box 152336<br>
                Arlington, TX 76015
              </p>
            </div>
          </div>

          <div class="contact-info-item">
            <div class="ci-icon"><i class="fas fa-calendar-alt" aria-hidden="true"></i></div>
            <div>
              <p class="ci-lbl">Next Ball</p>
              <p class="ci-val">April 10, 2027 · Arlington Convention Center at Loews Hotel</p>
            </div>
          </div>

        </div>

        <!-- Social Links -->
        <div class="contact-info-card">
          <h4>Follow Us</h4>
          <div class="contact-info-item">
            <div class="ci-icon" style="background:#e7f0fd; color:#1877f2;"><i class="fab fa-facebook-f" aria-hidden="true"></i></div>
            <div>
              <p class="ci-lbl">Facebook</p>
              <a href="https://www.facebook.com/CinderellaCharityBall" target="_blank" rel="noopener" class="ci-val">@CinderellaCharityBall</a>
            </div>
          </div>
          <div class="contact-info-item">
            <div class="ci-icon" style="background:#fce7f3; color:#c13584;"><i class="fab fa-instagram" aria-hidden="true"></i></div>
            <div>
              <p class="ci-lbl">Instagram</p>
              <a href="https://www.instagram.com/cinderellacharityball" target="_blank" rel="noopener" class="ci-val">@cinderellacharityball</a>
            </div>
          </div>
        </div>

        <!-- FAQ Quick Link -->
        <div class="sidebar-card" style="border-top:4px solid var(--blue-primary);">
          <h4 style="font-size:.9rem; font-family:var(--font-serif); font-weight:600; color:var(--text-dark); display:flex; align-items:center; gap:8px;">
            <i class="fas fa-question-circle" style="color:var(--blue-primary);"></i> Common Questions
          </h4>
          <ul class="sidebar-list">
            <li><i class="fas fa-arrow-right"></i> <a href="/support.php#faq-heading" style="color:var(--blue-primary);">Are donations tax-deductible?</a></li>
            <li><i class="fas fa-arrow-right"></i> <a href="/support.php#faq-heading" style="color:var(--blue-primary);">How can I donate?</a></li>
            <li><i class="fas fa-arrow-right"></i> <a href="/support.php#sponsorship" style="color:var(--blue-primary);">Sponsorship opportunities</a></li>
            <li><i class="fas fa-arrow-right"></i> <a href="/about.php#apply-heading" style="color:var(--blue-primary);">How to apply as a candidate</a></li>
          </ul>
        </div>

      </aside>

    </div>
  </div>
</section>


<!-- ============================================================
     PARTNER LOGOS
     ============================================================ -->
<section style="background:var(--white); padding:60px 0; border-top:1px solid var(--gray-200);" aria-label="Partner organizations">
  <div class="container">
    <p style="text-align:center; font-size:.78rem; font-weight:700; letter-spacing:.12em; text-transform:uppercase; color:var(--gray-400); margin-bottom:28px;">Our Partners</p>
    <div style="display:flex; justify-content:center; align-items:center; gap:48px; flex-wrap:wrap;">
      <img src="/image/imgi_3_ladiesauxiliary_logo-300x246.jpg" alt="Ladies' Auxiliary of Arlington" style="height:64px; width:auto; object-fit:contain; opacity:.7; transition:opacity .2s;" onmouseover="this.style.opacity=1" onmouseout="this.style.opacity=.7">
      <img src="/image/imgi_4_BGC-logoa.jpg" alt="Boys & Girls Clubs of Greater Tarrant County" style="height:64px; width:auto; object-fit:contain; opacity:.7; transition:opacity .2s;" onmouseover="this.style.opacity=1" onmouseout="this.style.opacity=.7">
      <img src="/image/Logo/logo.jpg" alt="Cinderella Charity Ball" style="height:64px; width:auto; object-fit:contain; opacity:.7; transition:opacity .2s;" onmouseover="this.style.opacity=1" onmouseout="this.style.opacity=.7">
    </div>
  </div>
</section>

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