<?php
require_once 'config.php';
$page_title = "Contact Us | " . SITE_NAME . " Support";
$page_desc  = "Contact " . SITE_NAME . " for domain registration, web hosting, VPS hosting and email hosting support. We're available 24/7.";

$success = '';
$error   = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name    = htmlspecialchars(trim($_POST['name']    ?? ''));
    $email   = htmlspecialchars(trim($_POST['email']   ?? ''));
    $phone   = htmlspecialchars(trim($_POST['phone']   ?? ''));
    $subject = htmlspecialchars(trim($_POST['subject'] ?? ''));
    $message = htmlspecialchars(trim($_POST['message'] ?? ''));

    if (!$name || !$email || !$message) {
        $error = 'Please fill in all required fields.';
    } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $error = 'Please enter a valid email address.';
    } else {
        $to      = EMAIL_SALES;
        $headers = "From: $name <$email>\r\nReply-To: $email\r\nContent-Type: text/plain; charset=UTF-8\r\n";
        $body    = "Name: $name\nEmail: $email\nPhone: $phone\nSubject: $subject\n\nMessage:\n$message";
        if (mail($to, $subject ?: SITE_NAME . ' Website Enquiry', $body, $headers)) {
            $success = 'Thank you! Your message has been sent. We will get back to you within 24 hours.';
        } else {
            $error = 'Sorry, there was an error sending your message. Please try again or call us directly.';
        }
    }
}

include 'includes/header.php';
?>

<section class="dd-sub-banner-area">
  <div class="container">
    <div class="row d-flex align-items-center justify-content-center">
      <div class="col-lg-7 text-center">
        <div class="sub-banner-text">
          <h1>Contact Us</h1>
          <p>Our support team is available 24/7 to help you with any questions or issues.</p>
        </div>
      </div>
    </div>
  </div>
</section>

<section class="contact-section">
  <div class="container">
    <div class="row g-4">
      <!-- Info -->
      <div class="col-lg-4">
        <div class="contact-info-box">
          <h3>Get In Touch</h3>
          <p style="color:rgba(255,255,255,.8);font-size:14px;margin-bottom:24px;">We're here to help! Reach out to us through any of the following channels.</p>
          <div class="contact-info-item">
            <i class="fas fa-phone"></i>
            <div>
              <h5>Phone</h5>
              <p><a href="tel:<?= PHONE_RAW ?>"><?= PHONE_DISPLAY ?></a></p>
            </div>
          </div>
          <div class="contact-info-item">
            <i class="fas fa-envelope"></i>
            <div>
              <h5>Email</h5>
              <p><a href="mailto:<?= EMAIL_SALES ?>"><?= EMAIL_SALES ?></a></p>
            </div>
          </div>
          <div class="contact-info-item">
            <i class="fas fa-clock"></i>
            <div>
              <h5>Support Hours</h5>
              <p>24 hours a day, 7 days a week, 365 days a year</p>
            </div>
          </div>
          <div class="contact-info-item">
            <i class="fas fa-user"></i>
            <div>
              <h5>Client Area</h5>
              <p><a href="<?= CLIENT_AREA_URL ?>" target="_blank">portal.ddomains.in</a></p>
            </div>
          </div>
        </div>
      </div>
      <!-- Form -->
      <div class="col-lg-8">
        <div class="contact-form-box">
          <h3>Send Us a Message</h3>
          <?php if ($success): ?><div class="alert alert-success"><?= $success ?></div><?php endif; ?>
          <?php if ($error):   ?><div class="alert alert-danger"><?= $error ?></div><?php endif; ?>
          <form method="POST" action="contact.php">
            <div class="row g-3">
              <div class="col-md-6">
                <label class="form-label" style="font-size:14px;font-weight:600;">Full Name <span class="text-danger">*</span></label>
                <input type="text" class="form-control" name="name" value="<?= htmlspecialchars($_POST['name'] ?? '') ?>" placeholder="Your full name" required>
              </div>
              <div class="col-md-6">
                <label class="form-label" style="font-size:14px;font-weight:600;">Email Address <span class="text-danger">*</span></label>
                <input type="email" class="form-control" name="email" value="<?= htmlspecialchars($_POST['email'] ?? '') ?>" placeholder="your@email.com" required>
              </div>
              <div class="col-md-6">
                <label class="form-label" style="font-size:14px;font-weight:600;">Phone Number</label>
                <input type="tel" class="form-control" name="phone" value="<?= htmlspecialchars($_POST['phone'] ?? '') ?>" placeholder="+91 XXXXX XXXXX">
              </div>
              <div class="col-md-6">
                <label class="form-label" style="font-size:14px;font-weight:600;">Subject</label>
                <select class="form-control" name="subject">
                  <option value="">Select a topic…</option>
                  <option value="Domain Registration">Domain Registration</option>
                  <option value="Web Hosting">Web Hosting</option>
                  <option value="VPS Hosting">VPS Hosting</option>
                  <option value="Email Hosting">Email Hosting</option>
                  <option value="Technical Support">Technical Support</option>
                  <option value="Billing">Billing</option>
                  <option value="Other">Other</option>
                </select>
              </div>
              <div class="col-12">
                <label class="form-label" style="font-size:14px;font-weight:600;">Message <span class="text-danger">*</span></label>
                <textarea class="form-control" name="message" rows="5" placeholder="Tell us how we can help you…" required><?= htmlspecialchars($_POST['message'] ?? '') ?></textarea>
              </div>
              <div class="col-12">
                <button type="submit" class="btn-submit">Send Message <i class="fas fa-paper-plane ms-2"></i></button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</section>

<section class="feature-section bg-light-3">
  <div class="container">
    <div class="block-title text-center mb-4"><h2>Other Ways to Reach Us</h2></div>
    <div class="row justify-content-center g-4">
      <div class="col-md-4">
        <div class="single-service-box">
          <div class="service-icon"><i class="fas fa-comments"></i></div>
          <h4>Live Chat</h4>
          <p>Chat with our support agents instantly. Available on every page — look for the chat icon in the bottom right corner.</p>
        </div>
      </div>
      <div class="col-md-4">
        <div class="single-service-box">
          <div class="service-icon"><i class="fas fa-ticket-alt"></i></div>
          <h4>Support Ticket</h4>
          <p>Submit a support ticket from your client area for detailed technical assistance and we'll respond promptly.</p>
          <a href="<?= CLIENT_AREA_URL ?>" target="_blank" style="font-weight:700;color:var(--primary);">Open Client Area →</a>
        </div>
      </div>
      <div class="col-md-4">
        <div class="single-service-box">
          <div class="service-icon"><i class="fas fa-phone-alt"></i></div>
          <h4>Call Us</h4>
          <p>Prefer to speak directly? Call our support hotline and get immediate assistance from our experts.</p>
          <a href="tel:<?= PHONE_RAW ?>" style="font-weight:700;color:var(--primary);"><?= PHONE_DISPLAY ?></a>
        </div>
      </div>
    </div>
  </div>
</section>

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