<?php
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/seo.php';

$propertyId = !empty($_GET['property']) ? (int)$_GET['property'] : null;
$prefillSubject = $_GET['subject'] ?? ($_GET['service'] ?? '');
$propertyTitle = '';
if ($propertyId) {
    $stmt = db()->prepare('SELECT title FROM properties WHERE id = ?');
    $stmt->execute([$propertyId]);
    $propertyTitle = $stmt->fetchColumn() ?: '';
}

$seo = [
    'title' => 'Contact Us | ' . SITE_NAME,
    'description' => 'Get in touch with Kigali Yacu Properties by phone, WhatsApp, email or our contact form for any buying, selling or investment enquiry.',
    'path' => '/contact',
];
include __DIR__ . '/includes/header.php';
?>
<section class="section-pad-sm">
  <div class="container">
    <?= breadcrumb_html([['name' => 'Contact', 'url' => '/contact']]) ?>
    <div class="section-head center">
      <div class="eyebrow" style="justify-content:center;"><?= e(t('contact.eyebrow')) ?></div>
      <h1><?= e(t('contact.h1')) ?></h1>
      <p><?= e(t('contact.lede')) ?></p>
    </div>

    <div class="grid grid-3 mb-8">
      <a href="<?= e(tel_link()) ?>" class="card text-center" style="padding:var(--space-7);">
        <span class="icon-wrap" style="width:56px;height:56px;border-radius:999px;background:var(--color-cream);display:flex;align-items:center;justify-content:center;color:var(--color-accent-dark);margin:0 auto var(--space-4);"><?= icon('phone', 24) ?></span>
        <h3 style="font-size:var(--fs-md);">Call Us</h3>
        <p class="text-muted"><?= e(setting('phone', SITE_PHONE)) ?></p>
      </a>
      <a href="<?= e(whatsapp_link('Hello! I would like to get in touch with Kigali Yacu Properties.')) ?>" target="_blank" rel="noopener" class="card text-center" style="padding:var(--space-7);">
        <span class="icon-wrap" style="width:56px;height:56px;border-radius:999px;background:var(--color-cream);display:flex;align-items:center;justify-content:center;color:var(--color-accent-dark);margin:0 auto var(--space-4);"><?= icon('whatsapp', 24) ?></span>
        <h3 style="font-size:var(--fs-md);">WhatsApp</h3>
        <p class="text-muted">Chat with an advisor now</p>
      </a>
      <a href="mailto:<?= e(setting('email', SITE_EMAIL)) ?>" class="card text-center" style="padding:var(--space-7);">
        <span class="icon-wrap" style="width:56px;height:56px;border-radius:999px;background:var(--color-cream);display:flex;align-items:center;justify-content:center;color:var(--color-accent-dark);margin:0 auto var(--space-4);"><?= icon('mail', 24) ?></span>
        <h3 style="font-size:var(--fs-md);">Email</h3>
        <p class="text-muted"><?= e(setting('email', SITE_EMAIL)) ?></p>
      </a>
    </div>

    <div class="grid grid-2" style="grid-template-columns:1.2fr 1fr;align-items:start;">
      <div class="form-card reveal">
        <h3>Send Us a Message</h3>
        <form data-ajax action="/api/contact.php" method="post">
          <input type="text" name="website" class="visually-hidden" tabindex="-1" autocomplete="off">
          <?php if ($propertyId): ?><input type="hidden" name="property_id" value="<?= (int)$propertyId ?>"><?php endif; ?>
          <div class="field-row mb-4">
            <div class="field"><label for="name">Full Name</label><input type="text" id="name" name="name" required></div>
            <div class="field"><label for="email">Email</label><input type="email" id="email" name="email" required></div>
          </div>
          <div class="field-row mb-4">
            <div class="field"><label for="phone">Phone / WhatsApp</label><input type="tel" id="phone" name="phone" required></div>
            <div class="field">
              <label for="service_interest">Service Interested In</label>
              <select id="service_interest" name="service_interest">
                <option value="Buy Property" <?= $prefillSubject === 'buy' ? 'selected' : '' ?>>Buy Property</option>
                <option value="Sell Property" <?= $prefillSubject === 'sell' ? 'selected' : '' ?>>Sell Property</option>
                <option value="Buy & Build" <?= $prefillSubject === 'buy-and-build' ? 'selected' : '' ?>>Buy &amp; Build</option>
                <option value="Property Valuation" <?= $prefillSubject === 'valuation' ? 'selected' : '' ?>>Property Valuation</option>
                <option value="New Development">New Development</option>
                <option value="Land Investment">Land Investment</option>
                <option value="General Inquiry">General Inquiry</option>
              </select>
            </div>
          </div>
          <div class="field-row mb-4">
            <div class="field">
              <label for="preferred_contact">Preferred Contact Method</label>
              <select id="preferred_contact" name="preferred_contact">
                <option value="Phone Call">Phone Call</option>
                <option value="WhatsApp">WhatsApp</option>
                <option value="Email">Email</option>
              </select>
            </div>
            <div class="field"><label for="preferred_visit_date">Preferred Visit Date</label><input type="date" id="preferred_visit_date" name="preferred_visit_date"></div>
          </div>
          <?php if ($propertyTitle): ?><input type="hidden" name="subject" value="<?= e($propertyTitle) ?>"><?php endif; ?>
          <div class="field mb-5">
            <label for="message">Message</label>
            <textarea id="message" name="message" required><?= $propertyTitle ? 'I am interested in "' . e($propertyTitle) . '". Could you share more details?' : '' ?></textarea>
          </div>
          <div class="flex flex-col gap-3">
            <button type="submit" name="cta_type" value="Book a Property Visit" class="btn btn-accent btn-block">Book a Property Visit</button>
            <button type="submit" name="cta_type" value="Schedule a Consultation" class="btn btn-primary btn-block">Schedule a Consultation</button>
            <button type="submit" name="cta_type" value="Request a Call Back" class="btn btn-outline btn-block">Request a Call Back</button>
          </div>
        </form>
      </div>
      <div class="reveal">
        <div class="map-frame mb-6">
          <iframe src="https://maps.google.com/maps?q=Kigali,Rwanda&z=13&output=embed" loading="lazy" title="Kigali Yacu Properties office map"></iframe>
        </div>
        <h4>Office Hours</h4>
        <p class="text-muted text-sm"><?= e(setting('office_hours', 'Monday – Saturday, 8:00 AM – 6:00 PM (Kigali time)')) ?></p>
        <h4 class="mt-4">Address</h4>
        <p class="text-muted text-sm"><?= e(setting('address', SITE_ADDRESS)) ?></p>
      </div>
    </div>
  </div>
</section>
<?php include __DIR__ . '/includes/footer.php'; ?>
