<?php
require_once 'header.php';

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

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = trim($_POST['name']);
    $email = trim($_POST['email']);
    $phone = trim($_POST['phone']);
    $subject = trim($_POST['subject']);
    $message = trim($_POST['message']);
    
    if (empty($name) || empty($email) || empty($message)) {
        $error = 'Please fill in all required fields';
    } else {
        try {
            $stmt = $pdo->prepare("INSERT INTO contact_messages (name, email, phone, subject, message) VALUES (?, ?, ?, ?, ?)");
            $stmt->execute([$name, $email, $phone, $subject, $message]);
            $success = 'Thank you for contacting us. We will get back to you soon!';
        } catch(Exception $e) {
            $error = 'An error occurred. Please try again.';
        }
    }
}
?>

<!-- Page Header -->
<div class="page-header bg-primary text-white py-5 mt-5">
    <div class="container text-center">
        <h1>Contact Us</h1>
        <p class="lead">We're here to help and answer any questions you might have</p>
    </div>
</div>

<!-- Contact Section -->
<section class="contact py-5">
    <div class="container">
        <?php if($success): ?>
            <div class="alert alert-success"><?php echo $success; ?></div>
        <?php endif; ?>
        <?php if($error): ?>
            <div class="alert alert-danger"><?php echo $error; ?></div>
        <?php endif; ?>
        
        <div class="row">
            <div class="col-md-4 mb-4">
                <div class="contact-info">
                    <div class="info-box text-center p-4 mb-4 border rounded">
                        <i class="fas fa-map-marker-alt fa-3x text-primary mb-3"></i>
                        <h5>Visit Us</h5>
                        <p>12 Peace Street,<br>Off Babs Ayorinde,<br>Ayobo, Lagos Nigeria</p>
                    </div>
                    <div class="info-box text-center p-4 mb-4 border rounded">
                        <i class="fas fa-phone-alt fa-3x text-primary mb-3"></i>
                        <h5>Call Us</h5>
                        <p>+234 8108791465<br>+234 8103242761<br>+234 8169972569</p>
                    </div>
                    <div class="info-box text-center p-4 mb-4 border rounded">
                        <i class="fas fa-envelope fa-3x text-primary mb-3"></i>
                        <h5>Email Us</h5>
                        <p>info@svnscores.com<br>support@svnscores.com</p>
                    </div>
                </div>
            </div>
            <div class="col-md-8">
                <div class="contact-form card">
                    <div class="card-body">
                        <h3 class="mb-4">Send Us a Message</h3>
                        <form method="POST">
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Full Name *</label>
                                    <input type="text" name="name" class="form-control" required>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Email *</label>
                                    <input type="email" name="email" class="form-control" required>
                                </div>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">Phone</label>
                                <input type="tel" name="phone" class="form-control">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">Subject</label>
                                <select name="subject" class="form-control">
                                    <option value="General Inquiry">General Inquiry</option>
                                    <option value="Internet Service">Internet Service</option>
                                    <option value="Laptop Sales">Laptop Sales</option>
                                    <option value="Office Space">Office Space</option>
                                    <option value="CBT Solutions">CBT Solutions</option>
                                    <option value="Technical Support">Technical Support</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">Message *</label>
                                <textarea name="message" rows="5" class="form-control" required></textarea>
                            </div>
                            <button type="submit" class="btn btn-primary btn-lg">Send Message</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Map Section -->
<section class="map py-5 bg-light">
    <div class="container">
        <h3 class="text-center mb-4">Find Us Here</h3>
        <div class="map-container">
            <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3964.123456789012!2d3.375!3d6.525!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x103b8b2ae68280c1%3A0xdc9e87a367c3e9e4!2sLagos!5e0!3m2!1sen!2sng!4v1234567890123!5m2!1sen!2sng" 
                    width="100%" height="400" style="border:0;" allowfullscreen="" loading="lazy"></iframe>
        </div>
    </div>
</section>

<!-- Business Hours -->
<section class="business-hours py-5">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card text-center">
                    <div class="card-body">
                        <h3>Business Hours</h3>
                        <div class="row mt-4">
                            <div class="col-md-6">
                                <h5>Weekdays</h5>
                                <p>Monday - Friday: 8:00 AM - 8:00 PM</p>
                            </div>
                            <div class="col-md-6">
                                <h5>Weekends</h5>
                                <p>Saturday: 9:00 AM - 5:00 PM<br>Sunday: Closed</p>
                            </div>
                        </div>
                        <div class="alert alert-info mt-3">
                            <i class="fas fa-headset"></i> 24/7 Technical Support Available
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<?php
require_once 'footer.php';
?>