<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/config.php';
$map_settings = get_map_settings();
$map_q = !empty($map_settings['address_query']) ? $map_settings['address_query'] : $map_settings['latitude'] . ',' . $map_settings['longitude'];
include BASE_PATH . '/include/header.php';

// Fetch services for the dropdown
$conn = get_db_connection();
$appointment_services = [];
if ($conn && !$conn->connect_error) {
    $appointment_result = $conn->query("SELECT name FROM services ORDER BY name ASC");
    if ($appointment_result) {
        while ($row = $appointment_result->fetch_assoc()) {
            if (!empty($row['name'])) {
                $appointment_services[] = $row['name'];
            }
        }
        $appointment_result->free();
    }
}
?>

<main id="content">
    <!-- Hero Section -->
    <section class="subpage-hero">
        <div class="container">
            <h1>Contact <span>Us</span></h1>
            <p>“The Best Solution For Chimney & Fireplace Services” — Get in touch with our licensed experts today.</p>
        </div>
    </section>

    <!-- Breadcrumbs -->
    <div class="breadcrumb-container">
        <div class="container">
            <a href="/"><i class="fas fa-home"></i> Home</a> / <span>Contact Us</span>
        </div>
    </div>

    <!-- Contact Content Section -->
    <section class="section-padding bg-light">
        <div class="container">
            <div class="row g-5">
                <!-- Contact Info -->
                <div class="col-lg-5">
                    <div class="pro-card h-100">
                        <h2 class="section-title">Get in Touch</h2>
                        <p class="text-muted mb-5">Whatever is happening with your chimney, you have someone that will
                            sweep away the competition. Crest Chimney offers the help you need from a licensed and
                            insured crew.</p>

                        <div class="contact-method mb-4 d-flex align-items-center gap-4">
                            <div class="faq-icon" style="width: 60px; height: 60px; font-size: 1.5rem;">
                                <i class="fas fa-phone-alt"></i>
                            </div>
                            <div>
                                <h5 class="mb-1">Phone Number</h5>
                                <a href="tel:<?php echo get_phone_number_tel(); ?>"
                                    class="text-decoration-none fw-bold fs-5 text-dark"><?php echo get_phone_number(); ?></a>
                            </div>
                        </div>

                        <div class="contact-method mb-4 d-flex align-items-center gap-4">
                            <div class="faq-icon" style="width: 60px; height: 60px; font-size: 1.5rem;">
                                <i class="fas fa-envelope"></i>
                            </div>
                            <div>
                                <h5 class="mb-1">Email Address</h5>
                                <a href="mailto:<?php echo get_email(); ?>"
                                    class="text-decoration-none fw-bold fs-5 text-dark"><?php echo get_email(); ?></a>
                            </div>
                        </div>

                        <div class="contact-method d-flex align-items-center gap-4">
                            <div class="faq-icon" style="width: 60px; height: 60px; font-size: 1.5rem;">
                                <i class="fas fa-map-marker-alt"></i>
                            </div>
                            <div>
                                <h5 class="mb-1">Service Area</h5>
                                <p class="mb-0 fw-bold fs-5 text-dark">Serving the Local Area</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Contact Form -->
                <div class="col-lg-7">
                    <div class="pro-card">
                        <h2 class="section-title">Send a Message</h2>
                        <p class="text-muted mb-4">Fill out the form below and our team will get back to you within 24
                            hours.</p>

                        <form action="/submit-appointment.php" method="POST">
                            <div class="row g-4">
                                <div class="col-md-6">
                                    <label class="form-label fw-bold text-uppercase small text-muted">First Name</label>
                                    <input type="text" name="fname" class="form-control py-3 rounded-3"
                                        placeholder="John" required>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label fw-bold text-uppercase small text-muted">Last Name</label>
                                    <input type="text" name="lname" class="form-control py-3 rounded-3"
                                        placeholder="Smith" required>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label fw-bold text-uppercase small text-muted">Phone
                                        Number</label>
                                    <input type="tel" name="phone" class="form-control py-3 rounded-3"
                                        placeholder="(123) 456-7890" required>
                                </div>
                                <div class="col-md-6">
                                    <label class="form-label fw-bold text-uppercase small text-muted">Email
                                        Address</label>
                                    <input type="email" name="email" class="form-control py-3 rounded-3"
                                        placeholder="email@example.com" required>
                                </div>
                                <div class="col-12">
                                    <label class="form-label fw-bold text-uppercase small text-muted">Service
                                        Need</label>
                                    <select name="service" class="form-select py-3 rounded-3" required>
                                        <option value="">- Select Service -</option>
                                        <?php foreach ($appointment_services as $service): ?>
                                            <option value="<?php echo htmlspecialchars($service); ?>">
                                                <?php echo htmlspecialchars($service); ?>
                                            </option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                                <div class="col-12">
                                    <label class="form-label fw-bold text-uppercase small text-muted">Address</label>
                                    <input type="text" name="address" class="form-control py-3 rounded-3"
                                        placeholder="1234 Street Name" required>
                                </div>
                                <div class="col-12">
                                    <button type="submit" class="btn-pro w-100">Send Message</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Map Section -->
    <section class="section-padding">
        <div class="container">
            <div class="pro-card p-0 overflow-hidden" style="height: 450px;">
                <iframe
                    src="https://www.google.com/maps?q=<?php echo urlencode($map_q); ?>&hl=en&z=<?php echo $map_settings['zoom']; ?>&output=embed"
                    width="100%" height="100%" style="border:0;" allowfullscreen="" loading="lazy"
                    referrerpolicy="no-referrer-when-downgrade"></iframe>
            </div>
        </div>
    </section>
</main>

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