<?php
$page = 'contact';

// reCAPTCHA v3 — read the public site key so the frontend can request a token.
$mailConfig        = @include __DIR__ . '/mail-config.php';
$recaptchaSiteKey  = is_array($mailConfig) ? ($mailConfig['recaptcha_site_key'] ?? '') : '';

include 'inc/nav.php'; ?>

<!-- ════════════════════
     HERO
════════════════════ -->
<section class="sub_hero position-relative pt-80 pb-80 d-flex align-items-center overflow-hidden text-center bg-white">
  <div class="container">
    <div class="rv">
      <h1 class="display-5">We Are Here to Help <span>Contact GoogieHost</span></h1>
      <p class="sub_hero_text">
        No bots. No scripted replies. No 48-hour waits. Our support team has kept 2.7 million websites online since 2012. When something goes wrong with your site, someone who knows hosting picks up the conversation, not a chatbot trained to say "have you tried clearing your cache?
      </p>
    </div>

    <!-- Stat pills -->
    <div class="hero-stats d-flex align-items-center justify-content-center gap-3 flex-wrap">
      <div class="stat-pill d-flex align-items-center gap-2 bg-white">
        <span class="hf-icon1"><img src="assets/images/circle-check-big.png" alt="checkmark" style="width:18px"></span>
        <div class="sp-label">No bots ever</div>
      </div>
      <div class="stat-pill d-flex align-items-center gap-2 bg-white">
        <span class="hf-icon1"><img src="assets/images/circle-check-big.png" alt="checkmark" style="width:18px"></span>
        <div class="sp-label">24/7 infrastructure monitoring</div>
      </div>
      <div class="stat-pill d-flex align-items-center gap-2 bg-white">
        <span class="hf-icon1"><img src="assets/images/circle-check-big.png" alt="checkmark" style="width:18px"></span>
        <div class="sp-label">Knowledge base support</div>
      </div>
      <div class="stat-pill d-flex align-items-center gap-2 bg-white">
        <span class="hf-icon1"><img src="assets/images/circle-check-big.png" alt="checkmark" style="width:18px"></span>
        <div class="sp-label">Live chat soon</div>
      </div>
    </div>

  </div>
</section>


<?php include 'inc/stats-band.php'; ?>
  

<!-- ═══════════════════════════════════════
   §2  CONTACT CHANNELS
═══════════════════════════════════════ -->
<section class="channels pb-80 pt-80">
  <div class="container">
    <div class="trust-head reveal text-center">
      <h2 class="trust-h2 display-6 fw-bold mb-3 section_heading text-center">Four ways to get help. Pick <span>yours.</span></h2>
      <p class="section_para text-start mb-5 text-center mx-auto">Every channel connects you to the same team. The difference is speed and complexity. Quick question? Use live chat. Site down emergency? Call the hotline. Want a paper trail? Submit a ticket.</p>
    </div>

    <div class="channel-grid row g-4">

      <!-- LIVE CHAT -->
      <div class="col-md-6">
        <div class="feature-light-card h-100">
          <!-- <div class="ch-strip" style="background:#3c47fb"></div> -->
          <div class="ch-body">
            <div class="ch-icon-row">
              <div class="ch-icon">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#3c47fb" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                  <path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z" />
                </svg>
              </div>
              <div class="ch-badge" style="background:#ECFDF5;color:var(--green3)">● Online now</div>
            </div>
            <div class="ch-title">Live Chat</div>
            <div class="ch-desc">
              The fastest way to get an answer. Connect with a real support engineer in under 2 minutes during business hours. Best for <strong>quick questions, WordPress issues, DNS setup, and SSL problems</strong> you need solved right now.
            </div>
            <div class="ch-metric">
              <div class="cm-label">Avg. first response</div>
              <div class="cm-value" style="color:#3c47fb">Under 2 min</div>
            </div>
          </div>
          <button class="submit-btn" style="background:#3c47fb">
            <i class="fa-solid fa-message"></i>
            Open Live Chat Now
          </button>
        </div>
      </div>
      <div class="col-md-6">
        <!-- SUPPORT TICKET -->
        <div class="feature-light-card h-100">
          <div class="ch-body">
            <div class="ch-icon-row">
              <div class="ch-icon">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#3c47fb" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                  <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
                  <path d="M14 2v6h6" />
                  <path d="M16 13H8" />
                  <path d="M16 17H8" />
                  <path d="M10 9H8" />
                </svg>
              </div>
              <div class="ch-badge" style="background:#EFF6FF;color:var(--blue2)">47 min median</div>
            </div>
            <div class="ch-title">Support Ticket</div>
            <div class="ch-desc">
              For anything that needs a paper trail or technical investigation. Submit screenshots, error logs, and server details. Best for <strong>database errors, email issues, cPanel access problems, and migration help</strong> where context matters.
            </div>
            <div class="ch-metric">
              <div class="cm-label">Tickets resolved same day</div>
              <div class="cm-value" style="color:#10B981">94% in 24 hrs</div>
            </div>
          </div>
          <a href="https://client.googiehost.com/submitticket.php?step=2&deptid=2" class=" submit-btn">
            <i class="fa-solid fa-paper-plane"></i>
            Submit a Support Ticket
          </a>
        </div>
      </div>
      <div class="col-md-6">
        <!-- KNOWLEDGE BASE -->
        <div class="feature-light-card h-100">
          <!-- <div class="ch-strip" style="background:#FFFBEB"></div> -->
          <div class="ch-body">
            <div class="ch-icon-row">
              <div class="ch-icon">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#3c47fb" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                  <path d="M12 7v14" />
                  <path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z" />
                </svg>
              </div>
              <div class="ch-badge" style="background:#FFFBEB;color:var(--amber3)">2,400+ articles</div>
            </div>
            <div class="ch-title">Knowledge Base</div>
            <div class="ch-desc">
              Before you write a ticket, check here first 80% of questions are already answered in detail. Step-by-step guides for <strong>WordPress installation, SSL configuration, email setup, PHP settings, and cPanel navigation.</strong>.
            </div>
            <div class="ch-metric">
              <div class="cm-label">Articles published</div>
              <div class="cm-value" style="color:#f59e0b">2,400+ guides</div>
            </div>
          </div>
          <a href="https://googiehost.com/blog/" class="submit-btn">
            <i class="fa-solid fa-bars-staggered"></i>
            Browse Knowledge Base
          </a>
        </div>
      </div>
      <div class="col-md-6">
        <!-- STATUS PAGE -->
        <div class="feature-light-card h-100">
          <!-- <div class="ch-strip" style="background:#8B5CF6"></div> -->
          <div class="ch-body">
            <div class="ch-icon-row">
              <div class="ch-icon">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#3c47fb" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                  <path d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2" />
                </svg>
              </div>
              <div class="ch-badge" style="background:#EDE9FE;color:#5B21B6">All systems go</div>
            </div>
            <div class="ch-title">Status Page</div>
            <div class="ch-desc">
              Real-time uptime monitoring for all 12 global data centers. If your site is slow or down,<strong>check here before submitting a ticket,</strong> you'll see immediately whether it's a platform issue or something specific to your account.
            </div>
            <div class="ch-metric">
              <div class="cm-label">Current platform uptime</div>
              <div class="cm-value" style="color:#8B5CF6">98.95% this month</div>
            </div>
          </div>
          <a href="/" class="submit-btn">
            <i class="fa-solid fa-rocket"></i>
            View Live Status
          </a>
        </div>
      </div>
    </div>
  </div>
</section>

<!-- ═══════════════════════════════════════
   §3  CONTACT FORM
═══════════════════════════════════════ -->
<section class="form-section pb-80 pt-80">
  <div class="container">
    <h2 class="display-6 fw-bold text-dark section_heading text-center">
      Tell us exactly what's <span>broken.</span>
    </h2>

    <p class="section_para mx-auto text-center mb-5">
      The more detail you include, the faster we can fix it.
    </p>

    <div class="row g-4">

      <!-- Left context -->
      <div class="col-md-6">
        <div class="form-context up">
          <!-- SLA grid — real numbers -->
          <div class="sla-grid">
            <div class="mosaic-card bg-white">
              <div class="sla-n">47<span style="font-size:.5em">min</span></div>
              <div class="sla-label"><strong>Median response</strong>Measured across 1500+ tickets last 12 months</div>
            </div>
            <div class="mosaic-card bg-white">
              <div class="sla-n">94<span style="font-size:.5em">%</span></div>
              <div class="sla-label"><strong>Resolved in 24hrs</strong>No ticket left unanswered overnight</div>
            </div>
            <div class="mosaic-card bg-white">
              <div class="sla-n">4.9<span style="font-size:.5em">★</span></div>
              <div class="sla-label"><strong>Customer satisfaction</strong>From 12,847 verified Trustpilot reviews</div>
            </div>
            <div class="mosaic-card bg-white">
              <div class="sla-n">0</div>
              <div class="sla-label"><strong>Bots in our support team</strong>Every reply is written by a human</div>
            </div>
          </div>

          <!-- Who's on duty -->
          <div class="duty-strip d-flex align-items-center justify-content-between gap-3 p-3 bg-white">
            <div class="duty-avs d-flex align-items-center">
              <div class="dav d-flex align-items-center justify-content-center" style="background:#3B82F6">RC</div>
              <div class="dav d-flex align-items-center justify-content-center" style="background:#10B981">AS</div>
              <div class="dav d-flex align-items-center justify-content-center" style="background:#F59E0B">MG</div>
              <div class="dav d-flex align-items-center justify-content-center" style="background:#8B5CF6">PP</div>
              <div class="dav d-flex align-items-center justify-content-center" style="background:#EF4444">RS</div>
            </div>
            <div class="duty-text">
              <div class="dt-main fw-bold">Support team on duty right now</div>
              <div class="dt-sub">Ranjan, Priya, Aman and 4 more</div>
            </div>
            <div class="duty-live ms-auto d-flex align-items-end flex-column gap-1">
              <div class="dl-dot d-flex align-items-center gap-2">
                <div class="dl-d"></div>
                <div class="dl-txt">Live</div>
              </div>
              <div class="dl-time">Avg wait today: <strong style="color:var(--ink)">3 min</strong></div>
            </div>
          </div>
        </div>
      </div>

      <!-- RIGHT SIDE FORM -->
      <div class="col-md-6">
        <div class="form-card">

          <div class="form-card-top p-4">
            <div class="fct-title fw-bold mb-1">What do you need help with?</div>
            <div class="fct-sub">Pick the closest topic we'll route your message to the right specialist.</div>
          </div>

          <!-- ✅ FORM START -->
          <form method="POST" action="contact-handler.php" onsubmit="return handleSubmit(event)">

            <div class="form-fields">

              <div class="field-row">
                <div class="field">
                  <label>Your name</label>
                  <input type="text" name="name" placeholder="James Anderson" required>
                </div>
                <div class="field">
                  <label>Email address</label>
                  <input type="email" name="email" placeholder="james@yoursite.com" required>
                </div>
              </div>

              <div class="field">
                <label>Your website URL</label>
                <input type="url" name="website" placeholder="https://yourwebsite.com">
              </div>

              <div class="field">
                <label>Describe the problem</label>
                <textarea name="message" placeholder="write a message" required></textarea>
              </div>

              <!-- ✅ FIXED BUTTON -->
              <button type="submit" class="submit-btn w-100 p-3 d-flex align-items-center justify-content-center position-relative">
                <i class="fa-solid fa-paper-plane"></i>
                Send to Support Team
              </button>

              <div class="submit-note text-center text-mute mt-3">
                We'll reply to your email · No account needed · Average reply: 47 minutes
              </div>

            </div>
          </form>
          <!-- ✅ FORM END -->

        </div>
      </div>

    </div>
  </div>
</section>

<!-- ═══════════════════════════════════════
   §4  KNOW BEFORE YOU WRITE
═══════════════════════════════════════ -->
<section class="pt-80 pb-80">
  <div class="container">
    <h2 class="display-6 fw-bold text-dark section_heading text-center">80% of problems are answered right here <span>broken.</span></h2>
    <p class="section_para mx-auto text-center mb-5">
      The more detail you include, the faster we can fix it. Our support engineers don't ask for information twice give us the full picture and we'll get straight to the solution.
    </p>

    <div class="row g-3">
      <div class="col-md-3">
        <div class="feature-light-card p-4 h-100">
          <div class="dr2-icon dii-blue" style="background:#EFF6FF">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#2563EB" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
              <path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z" />
              <path d="M2 12.65l9.17 4.16a2 2 0 0 0 1.66 0L22 12.65" />
              <path d="M2 17.65l9.17 4.16a2 2 0 0 0 1.66 0L22 17.65" />
            </svg>
          </div>
          <div class="feature-title-light">Install WordPress</div>
          <div class="feature-text-light mb-0">One-click Softaculous install, manual upload, or migration from another host. Step-by-step with screenshots.</div>
        </div>
      </div>
      <div class="col-md-3">
        <div class="feature-light-card p-4 h-100">
          <div class="dr2-icon dii-green" style="background:#ECFDF5">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#10B981" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
              <rect width="18" height="11" x="3" y="11" rx="2" ry="2" />
              <path d="M7 11V7a5 5 0 0 1 10 0v4" />
            </svg>
          </div>
          <div class="feature-title-light">Fix SSL Errors</div>
          <div class="feature-text-light mb-0">Mixed content warnings, certificate not trusted, HTTPS redirect loops, all covered with exact .htaccess fixes.</div>
        </div>
      </div>
      <div class="col-md-3">
        <div class="feature-light-card p-4 h-100">
          <div class="dr2-icon dii-violet">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#C2410C" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
              <circle cx="12" cy="12" r="10" />
              <line x1="12" x2="12" y1="8" y2="12" />
              <line x1="12" x2="12.01" y1="16" y2="16" />
            </svg>
          </div>
          <div class="feature-title-light">500 / 403 Errors</div>
          <div class="feature-text-light mb-0">The two most common server errors. Usually a PHP version mismatch, plugin conflict, or .htaccess issue. Diagnose in 5 minutes.</div>
          <!-- <div class="shc-link">Read guide →</div> -->
        </div>
      </div>
      <div class="col-md-3">
        <div class="feature-light-card p-4 h-100">
          <div class="dr2-icon dii-amber" style="background:#FFFBEB">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#D97706" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
              <rect width="20" height="16" x="2" y="4" rx="2" />
              <path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" />
            </svg>
          </div>
          <div class="feature-title-light">Email Not Working</div>
          <div class="feature-text-light mb-0">Set up business email on your domain. Configure Outlook, Gmail, Apple Mail, or any IMAP/SMTP client in minutes.</div>
          <!-- <div class="shc-link">Read guide →</div> -->
        </div>
      </div>
    </div>
  </div>
</section>

<?php

$faqs = [
  [
    'cat' => 'support',
    'question' => "
How do I contact GoogieHost support?",
    'answer' => "Submit a support ticket directly from your hosting dashboard or use the contact form on this page. Select the relevant department Technical Support, Billing, or General Inquiry and our team will respond within 24 hours on business days.",
  ],
  [
    'cat' => 'support',
    'question' => "How long does GoogieHost take to respond to support tickets?",
    'answer' => "Support tickets are typically responded to within 24 hours on business days. Tickets submitted with complete account details, domain information, and a clear issue description are resolved faster sometimes within a few hours.",
  ],
  [
    'cat' => 'support',
    'question' => "Is there live chat support available?",
    'answer' => "GoogieHost currently provides support via the ticketing system, knowledge base, and community forum. For the fastest resolution on technical issues, submit a detailed support ticket directly from your DirectAdmin dashboard.",
  ],
  [
    'cat' => 'support',
    'question' => "Where can I find self-help guides for GoogieHost hosting?",
    'answer' => "The GoogieHost knowledge base contains step-by-step guides covering free hosting setup, WordPress installation, SSL activation, DirectAdmin usage, domain and DNS configuration, FTP access, and MySQL database management available 24/7 without submitting a ticket.",
  ],
  [
    'cat' => 'support',
    'question' => "Can I contact GoogieHost for a hosting provider review or listing?",
    'answer' => "Yes. GoogieHost reviews 200+ hosting providers and is open to reviewing new brands. Use the contact form on this page, select Partnership from the department dropdown, and include your hosting brand details. Our editorial review team will respond with the process and requirements.",
  ],
  [
    'cat' => 'support',
    'question' => "I forgot my GoogieHost account password. Who do I contact?",
    'answer' => "Use the password reset option on the GoogieHost login page, this is the fastest way to regain access. If you are unable to reset your password via email, submit a support ticket with your registered account email address and our team will assist you.",
  ],
  [
    'cat' => 'support',
    'question' => "How do I report abuse or a suspended account?",
    'answer' => "For abuse reports or suspended account inquiries, submit a support ticket selecting Technical Support from the department dropdown. Include your account email, domain name, and a description of the issue. Our team reviews all suspension and abuse-related tickets on priority.",
  ],
  [
    'cat' => 'support',
    'question' => "Can I get phone support for my GoogieHost hosting account?",
    'answer' => "GoogieHost currently provides support through its ticketing system and knowledge base. Phone support is not available at this time. Ticket-based support allows our team to properly investigate hosting issues, access account details securely, and provide documented solutions.",
  ],
];
?>

<style>
  .faq-a-inner {
    padding: 0 22px 20px 34px;
  }
</style>


<section class="faq-section pt-80 pb-80 position-relative">
  <div class="faq-wrap container">

    <div class="faq-header text-center">
      <div class="faq-header-left">
        <h2 class="faq-title display-6 fw-bold section_heading">Everything about <span class="hl">free web hosting</span></h2>
        <p class="section_para mx-auto mb-5">We understand you have questions, so we've provided clear answers below. You won't find any marketing fluff or hidden fine print here, just the honest, direct information you need to make an informed decision without any unnecessary complexity or confusion about our free website hosting.</p>
      </div>
    </div>
    <div class="faq-grid" id="faq-grid">
      <?php foreach ($faqs as $index => $faq): ?>
        <?php
        $cat = htmlspecialchars($faq['cat'] ?? 'features');
        $question = htmlspecialchars($faq['question'] ?? '');
        $answer = $faq['answer'] ?? '';
        ?>
        <article class="faq-item cat-<?= $cat ?>"
          data-cat="<?= $cat ?>"
          data-faq-index="<?= (int) $index ?>"
          data-q="<?= htmlspecialchars(strtolower(strip_tags($faq['question'] ?? ''))) ?>">

          <button class="faq-q"
            type="button"
            aria-expanded="false">

            <span class="faq-q-text">
              <?= $question ?>
            </span>

            <span class="faq-toggle" aria-hidden="true"><i class="fa-solid fa-plus"></i></span>
          </button>

          <div class="faq-a">
            <div class="faq-a-inner">
              <?= $answer ?>
            </div>
          </div>

        </article>
      <?php endforeach; ?>
    </div>

    <div class="faq-cta">
      <div class="faq-cta-left">
        <strong>Still have questions?</strong>
        <span>Our team replies in under an hour on the Pro plan, or browse 400+ articles in our knowledge base.</span>
      </div>
      <div class="faq-cta-btns">
        <a href="/contact.php" class="text-decoration-none"><button class="btn-chat" type="button">Contact Us<i class="fa-solid fa-arrow-right ms-3"></i></button></a>
        <a href="https://googiehost.com/blog/"><button class="btn-kb" type="button">Browse Knowledge Base<i class="fa-solid fa-arrow-right ms-3"></i></button></a>
      </div>
    </div>
  </div>
</section>


<script>
  (() => {
    const grid = document.getElementById('faq-grid');
    const items = [...document.querySelectorAll('.faq-item')];
    const tabs = [...document.querySelectorAll('.filter-tab')];
    let currentCat = 'all';

    const isMobile = () => window.innerWidth <= 767;

    function resetItems() {
      items.forEach(item => {
        item.classList.remove('open', 'sibling-open');
        const trigger = item.querySelector('.faq-q');
        const toggle = item.querySelector('.faq-toggle');
        trigger.setAttribute('aria-expanded', 'false');
        toggle.textContent = '+';
      });
    }

    function visibleItems() {
      return items.filter(item => item.style.display !== 'none');
    }

    function toggleItem(item) {
      const wasOpen = item.classList.contains('open') || item.classList.contains('sibling-open');
      resetItems();

      if (wasOpen) {
        return;
      }

      const visible = visibleItems();
      const index = visible.indexOf(item);
      const siblingIndex = index % 2 === 0 ? index + 1 : index - 1;
      const sibling = visible[siblingIndex];

      item.classList.add('open');
      item.querySelector('.faq-q').setAttribute('aria-expanded', 'true');
      item.querySelector('.faq-toggle').textContent = '✕';

      if (!isMobile() && sibling) {
        sibling.classList.add('sibling-open');
        sibling.querySelector('.faq-q').setAttribute('aria-expanded', 'true');
        sibling.querySelector('.faq-toggle').textContent = '✕';
      }
    }

    function applyFilter(cat) {
      currentCat = cat;
      resetItems();

      items.forEach(item => {
        item.style.display = cat === 'all' || item.dataset.cat === cat ? '' : 'none';
      });

      tabs.forEach(tab => {
        tab.classList.toggle('active', tab.dataset.cat === cat);
      });
    }

    tabs.forEach(tab => {
      tab.addEventListener('click', () => applyFilter(tab.dataset.cat));
    });

    items.forEach(item => {
      item.querySelector('.faq-q').addEventListener('click', () => toggleItem(item));
    });

    window.addEventListener('resize', () => applyFilter(currentCat));

    applyFilter(currentCat);
    if (grid) {
      grid.dataset.ready = 'true';
    }
  })();
</script>

<?php if (!empty($recaptchaSiteKey)): ?>
<!-- ✅ Google reCAPTCHA v3 -->
<script src="https://www.google.com/recaptcha/api.js?render=<?= htmlspecialchars($recaptchaSiteKey, ENT_QUOTES) ?>"></script>
<?php endif; ?>

<!-- ✅ CONTACT FORM AJAX SUBMIT -->
<script>
  const RECAPTCHA_SITE_KEY = <?= json_encode($recaptchaSiteKey ?? '') ?>;

  // Ask reCAPTCHA v3 for a fresh token (returns '' if reCAPTCHA isn't configured/loaded).
  function getRecaptchaToken(action) {
    return new Promise((resolve) => {
      if (!RECAPTCHA_SITE_KEY || typeof grecaptcha === 'undefined') {
        return resolve('');
      }
      grecaptcha.ready(() => {
        grecaptcha.execute(RECAPTCHA_SITE_KEY, { action })
          .then(resolve)
          .catch(() => resolve(''));
      });
    });
  }

  async function handleSubmit(event) {
    event.preventDefault();
    const form = event.target;
    const btn = form.querySelector('.submit-btn');
    const note = form.querySelector('.submit-note');
    const originalBtn = btn.innerHTML;
    const originalNote = note ? note.innerHTML : '';

    btn.disabled = true;
    btn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Sending…';

    try {
      const formData = new FormData(form);

      // Attach a reCAPTCHA v3 token so the server can verify the submission.
      const token = await getRecaptchaToken('contact');
      if (token) {
        formData.set('recaptcha_token', token);
      }

      const res = await fetch(form.action, {
        method: 'POST',
        body: formData,
        headers: { 'X-Requested-With': 'XMLHttpRequest' }
      });
      const data = await res.json();

      if (note) {
        note.innerHTML = data.message;
        note.style.color = data.success ? '#16a34a' : '#dc2626';
      }
      if (data.success) {
        form.reset();
      }
    } catch (err) {
      if (note) {
        note.innerHTML = 'Network error — please try again.';
        note.style.color = '#dc2626';
      }
    } finally {
      btn.disabled = false;
      btn.innerHTML = originalBtn;
      // restore the default note after a few seconds
      setTimeout(() => { if (note) { note.innerHTML = originalNote; note.style.color = ''; } }, 8000);
    }
    return false;
  }
</script>

<?php include 'inc/footer.php'; ?>