<?php 
require 'config/db.php';
include 'includes/header.php'; 

$msg = "";
$msgClass = "";

// HANDLE FORM SUBMISSION
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = trim($_POST['name']);
    $email = trim($_POST['email']);
    $subject = trim($_POST['subject']);
    $message = trim($_POST['message']);
    
    if(!empty($name) && !empty($email) && !empty($message)) {
        try {
            $stmt = $pdo->prepare("INSERT INTO contact_messages (name, email, subject, message) VALUES (?, ?, ?, ?)");
            if ($stmt->execute([$name, $email, $subject, $message])) {
                $msg = "Message sent! We will contact you shortly.";
                $msgClass = "success-msg";
            } else {
                $msg = "Error sending message.";
                $msgClass = "error-msg";
            }
        } catch (Exception $e) {
            $msg = "System Error: " . $e->getMessage();
            $msgClass = "error-msg";
        }
    } else {
        $msg = "Please fill all fields.";
        $msgClass = "error-msg";
    }
}
?>

<style>
    .contact-container { display: flex; flex-wrap: wrap; gap: 40px; background: #fff; padding: 40px; border-radius: 12px; box-shadow: 0 5px 20px rgba(0,0,0,0.05); margin-top: 30px; }
    .contact-info-box { flex: 1; min-width: 300px; }
    .contact-method { display: flex; align-items: center; margin-bottom: 20px; padding: 15px; background: #f9f9f9; border-radius: 8px; border-left: 4px solid #3498db; }
    .contact-method i { font-size: 24px; color: #3498db; margin-right: 15px; width: 30px; text-align: center; }
    
    .contact-form-box { flex: 1.5; min-width: 300px; }
    .form-group { margin-bottom: 20px; }
    .form-group label { display: block; font-weight: bold; margin-bottom: 5px; color: #444; }
    .form-control { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 5px; font-size: 16px; box-sizing: border-box; }
    
    .success-msg { background: #d4edda; color: #155724; padding: 15px; border-radius: 5px; margin-bottom: 20px; border: 1px solid #c3e6cb; }
    .error-msg { background: #f8d7da; color: #721c24; padding: 15px; border-radius: 5px; margin-bottom: 20px; border: 1px solid #f5c6cb; }
</style>

<div class="container" style="padding-bottom: 50px;">
    
    <div style="text-align: center; padding: 40px 0 20px;">
        <h1>Get in Touch</h1>
        <p style="color: #666;">Have a question? Send us a message and we'll get back to you.</p>
    </div>

    <div class="contact-container">
        
        <div class="contact-info-box">
            <h2>Quick Support</h2>
            <p style="margin-bottom: 30px; color:#666;">For fastest reply, use WhatsApp.</p>

            <div class="contact-method" style="border-left-color: #25D366;">
                <i class="fab fa-whatsapp" style="color: #25D366;"></i>
                <div><strong>WhatsApp</strong><br><a href="https://wa.me/15852502693" target="_blank">+1 (585) 250-2693</a></div>
            </div>

            <div class="contact-method" style="border-left-color: #0088cc;">
                <i class="fab fa-telegram" style="color: #0088cc;"></i>
                <div><strong>Telegram</strong><br><a href="https://t.me/digibossx" target="_blank">@digibossx</a></div>
            </div>

            <div class="contact-method" style="border-left-color: #e74c3c;">
                <i class="fas fa-envelope" style="color: #e74c3c;"></i>
                <div><strong>Email</strong><br><a href="mailto:contact@prosubscriptionoffers.com">contact@prosubscriptionoffers.com</a></div>
            </div>
        </div>

        <div class="contact-form-box">
            <h2>Send Message</h2>
            
            <?php if($msg): ?>
                <div class="<?php echo $msgClass; ?>"><?php echo $msg; ?></div>
            <?php endif; ?>

            <form method="POST">
                <div class="form-group">
                    <label>Your Name</label>
                    <input type="text" name="name" class="form-control" required placeholder="John Doe">
                </div>

                <div class="form-group">
                    <label>Email Address</label>
                    <input type="email" name="email" class="form-control" required placeholder="john@example.com">
                </div>

                <div class="form-group">
                    <label>Subject</label>
                    <select name="subject" class="form-control">
                        <option>General Inquiry</option>
                        <option>Order Support</option>
                        <option>Reseller Inquiry</option>
                        <option>Other</option>
                    </select>
                </div>

                <div class="form-group">
                    <label>Message</label>
                    <textarea name="message" rows="5" class="form-control" required placeholder="How can we help?"></textarea>
                </div>

                <button type="submit" class="btn btn-buy" style="width: auto; padding: 12px 30px;">Send Message</button>
            </form>
        </div>

    </div>
</div>

<?php include 'includes/footer.php'; ?>