<?php 
require_once 'includes/db.php';
require_once 'includes/header.php'; 

$msg = '';
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit_contact'])) {
    $name = trim($_POST['name']);
    $email = trim($_POST['email']);
    $phone = trim($_POST['phone']);
    $subject = trim($_POST['subject']);
    $message = trim($_POST['message']);

    $to = "bsestrust@gmail.com";
    $headers = "From: " . $email . "\r\n";
    $headers .= "Reply-To: " . $email . "\r\n";
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
    
    $full_message = "<h3>New Contact Query</h3>
        <p><strong>Name:</strong> {$name}</p>
        <p><strong>Email:</strong> {$email}</p>
        <p><strong>Phone:</strong> {$phone}</p>
        <p><strong>Subject:</strong> {$subject}</p>
        <p><strong>Message:</strong><br/>" . nl2br($message) . "</p>";
        
    if(mail($to, "Contact Us Query: $subject", $full_message, $headers)) {
        $msg = "<div class='alert alert-success'>Thank you for contacting us. We will get back to you soon.</div>";
    } else {
        $msg = "<div class='alert alert-danger'>Sorry, there was an issue sending your message. Please try again later.</div>";
    }
}
?>

<div class="container my-5">
    <div class="row">
        <div class="col-12 text-center mb-5">
            <h2 class="section-title" style="color: var(--primary-green);">Contact Us</h2>
            <p class="text-muted fs-5">We would love to hear from you!</p>
        </div>
    </div>
    
    <div class="row g-5">
        <div class="col-md-5">
            <div class="card h-100 shadow border-0 p-4" style="border-radius: 15px; background: var(--light-bg);">
                <h4 class="fw-bold mb-4" style="color: var(--primary-blue);">Get in Touch</h4>
                <div class="d-flex mb-4">
                    <div class="bg-white rounded-circle d-flex align-items-center justify-content-center shadow-sm" style="width: 50px; height: 50px; min-width: 50px;">
                        <i class="fas fa-map-marker-alt fs-4" style="color: var(--primary-saffron);"></i>
                    </div>
                    <div class="ms-3">
                        <h5>Office Address</h5>
                        <p class="text-muted mb-0">Regd. Office: 60 Futa Road, Samar Garden Colony, Meerut (UP) – 250002</p>
                    </div>
                </div>
                <div class="d-flex mb-4">
                    <div class="bg-white rounded-circle d-flex align-items-center justify-content-center shadow-sm" style="width: 50px; height: 50px; min-width: 50px;">
                        <i class="fas fa-envelope fs-4" style="color: var(--primary-saffron);"></i>
                    </div>
                    <div class="ms-3">
                        <h5>Email Us</h5>
                        <p class="text-muted mb-0">bsestrust@gmail.com</p>
                    </div>
                </div>
                <div class="d-flex mb-4">
                    <div class="bg-white rounded-circle d-flex align-items-center justify-content-center shadow-sm" style="width: 50px; height: 50px; min-width: 50px;">
                        <i class="fas fa-phone-alt fs-4" style="color: var(--primary-saffron);"></i>
                    </div>
                    <div class="ms-3">
                        <h5>Call Us</h5>
                        <p class="text-muted mb-0">+91-9012020817, +91-9084873729</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-7">
            <div class="card shadow border-0 p-4" style="border-radius: 15px;">
                <h4 class="fw-bold mb-4" style="color: var(--primary-green);">Send a Message</h4>
                <?php echo $msg; ?>
                <form action="" method="POST">
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label fw-bold">Your Name</label>
                            <input type="text" name="name" class="form-control" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">Your Email</label>
                            <input type="email" name="email" class="form-control" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">Phone Number</label>
                            <input type="text" name="phone" class="form-control" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">Subject</label>
                            <input type="text" name="subject" class="form-control" required>
                        </div>
                        <div class="col-12">
                            <label class="form-label fw-bold">Message</label>
                            <textarea name="message" class="form-control" rows="5" required></textarea>
                        </div>
                        <div class="col-12 mt-4">
                            <button type="submit" name="submit_contact" class="btn btn-lg w-100 fw-bold text-white shadow" style="background-color: var(--primary-green);">Send Message <i class="fas fa-paper-plane ms-2"></i></button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

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