<?php
$message_status = '';

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit_contact'])) {
    $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'] ?? ''));

    $to = "admin@mytechcertificate.com";
    $headers = "From: " . $email . "\r\n";
    $headers .= "Reply-To: " . $email . "\r\n";
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n";

    $email_body = "
    <h2>Contact Request from Website</h2>
    <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 Form: " . $subject, $email_body, $headers)) {
        $message_status = '<div style="color: #155724; background-color: #d4edda; border-color: #c3e6cb; margin-bottom: 20px; padding: 15px; border: 1px solid transparent; border-radius: 4px;">Your message has been sent successfully. We will get back to you soon.</div>';
    } else {
        $message_status = '<div style="color: #721c24; background-color: #f8d7da; border-color: #f5c6cb; margin-bottom: 20px; padding: 15px; border: 1px solid transparent; border-radius: 4px;">There was an error sending your message. Please try again later.</div>';
    }
}
?>
<?php include __DIR__ . '/header.php'; ?>

<div class="bg-gray-50 py-12 md:py-20" style="background-color: #f9fafb; padding-top: 50px; padding-bottom: 50px; font-family: 'Inter', sans-serif;">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8" style="max-width: 1200px; margin: 0 auto;">
        
        <div class="text-center mb-12" style="text-align: center; margin-bottom: 50px;">
            <h1 class="text-3xl md:text-5xl font-extrabold text-gray-900 mb-4" style="font-size: 2.5rem; font-weight: bold; color: #111;">Contact Us</h1>
            <p class="text-lg text-gray-600 max-w-2xl mx-auto" style="color: #555; font-size: 1.1rem; max-width: 600px; margin: 0 auto;">
                Have questions or need assistance? We're here to help. Reach out to us using the form or contact details below.
            </p>
        </div>

        <?php if (!empty($message_status)) { echo $message_status; } ?>

        <div style="display: flex; flex-wrap: wrap; gap: 30px; justify-content: center;">
            
            <!-- Contact Details -->
            <div style="flex: 1; min-width: 300px; background: #fff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); border: 1px solid #eaeaea;">
                <h2 style="font-size: 1.5rem; font-weight: bold; margin-bottom: 20px; color: #111;">Get in Touch</h2>
                
                <div style="margin-bottom: 25px; display: flex; align-items: flex-start; gap: 15px;">
                    <div style="background: #f0f4ff; padding: 12px; border-radius: 50%; color: #0056b3;">
                        <svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path></svg>
                    </div>
                    <div>
                        <h3 style="font-size: 1.1rem; font-weight: bold; margin: 0 0 5px; color: #333;">Phone & WhatsApp</h3>
                        <p style="margin: 0; color: #666; font-size: 1rem;"><a href="tel:+16816772366" style="color: #0056b3; text-decoration: none;">+1(681)677-2366</a></p>
                    </div>
                </div>

                <div style="margin-bottom: 25px; display: flex; align-items: flex-start; gap: 15px;">
                    <div style="background: #f0f4ff; padding: 12px; border-radius: 50%; color: #0056b3;">
                        <svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg>
                    </div>
                    <div>
                        <h3 style="font-size: 1.1rem; font-weight: bold; margin: 0 0 5px; color: #333;">Email</h3>
                        <p style="margin: 0; color: #666; font-size: 1rem;"><a href="mailto:admin@mytechcertificate.com" style="color: #0056b3; text-decoration: none;">admin@mytechcertificate.com</a></p>
                    </div>
                </div>

                <div style="margin-bottom: 25px; display: flex; align-items: flex-start; gap: 15px;">
                    <div style="background: #f0f4ff; padding: 12px; border-radius: 50%; color: #0056b3;">
                        <svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path><path d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path></svg>
                    </div>
                    <div>
                        <h3 style="font-size: 1.1rem; font-weight: bold; margin: 0 0 5px; color: #333;">Business Address</h3>
                        <p style="margin: 0; color: #666; font-size: 1rem; line-height: 1.5;">
                            <strong>SureCertificate</strong><br>
                            123 Business Avenue, Suite 100,<br>
                            New York, NY 10001, USA
                        </p>
                    </div>
                </div>

            </div>

             <!-- Contact Form -->
            <div style="flex: 2; min-width: 300px; background: #fff; padding: 30px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); border: 1px solid #eaeaea;">
                <h2 style="font-size: 1.5rem; font-weight: bold; margin-bottom: 20px; color: #111;">Send us a Message</h2>
                <form action="" method="POST" style="display: flex; flex-direction: column; gap: 20px;">
                    <div style="display: flex; gap: 20px; flex-wrap: wrap;">
                        <div style="flex: 1; min-width: 200px;">
                            <label for="name" style="display: block; font-weight: 600; margin-bottom: 5px; color: #444;">Your Name *</label>
                            <input type="text" id="name" name="name" required style="width: 100%; border-box: box-sizing; padding: 12px; border: 1px solid #ccc; border-radius: 6px; outline: none; transition: border-color 0.3s;" onfocus="this.style.borderColor='#0056b3'" onblur="this.style.borderColor='#ccc'" placeholder="John Doe">
                        </div>
                        <div style="flex: 1; min-width: 200px;">
                            <label for="email" style="display: block; font-weight: 600; margin-bottom: 5px; color: #444;">Your Email *</label>
                            <input type="email" id="email" name="email" required style="width: 100%; border-box: box-sizing; padding: 12px; border: 1px solid #ccc; border-radius: 6px; outline: none; transition: border-color 0.3s;" onfocus="this.style.borderColor='#0056b3'" onblur="this.style.borderColor='#ccc'" placeholder="john@example.com">
                        </div>
                    </div>
                    
                    <div style="display: flex; gap: 20px; flex-wrap: wrap;">
                        <div style="flex: 1; min-width: 200px;">
                            <label for="phone" style="display: block; font-weight: 600; margin-bottom: 5px; color: #444;">Phone Number</label>
                            <input type="tel" id="phone" name="phone" style="width: 100%; border-box: box-sizing; padding: 12px; border: 1px solid #ccc; border-radius: 6px; outline: none; transition: border-color 0.3s;" onfocus="this.style.borderColor='#0056b3'" onblur="this.style.borderColor='#ccc'" placeholder="+1 (123) 456-7890">
                        </div>
                        <div style="flex: 1; min-width: 200px;">
                            <label for="subject" style="display: block; font-weight: 600; margin-bottom: 5px; color: #444;">Subject *</label>
                            <input type="text" id="subject" name="subject" required style="width: 100%; border-box: box-sizing; padding: 12px; border: 1px solid #ccc; border-radius: 6px; outline: none; transition: border-color 0.3s;" onfocus="this.style.borderColor='#0056b3'" onblur="this.style.borderColor='#ccc'" placeholder="How can we help?">
                        </div>
                    </div>

                    <div>
                        <label for="message" style="display: block; font-weight: 600; margin-bottom: 5px; color: #444;">Your Message *</label>
                        <textarea id="message" name="message" rows="5" required style="width: 100%; border-box: box-sizing; padding: 12px; border: 1px solid #ccc; border-radius: 6px; outline: none; transition: border-color 0.3s; resize: vertical;" onfocus="this.style.borderColor='#0056b3'" onblur="this.style.borderColor='#ccc'" placeholder="Write your message here..."></textarea>
                    </div>

                    <div>
                        <button type="submit" name="submit_contact" style="background-color: #111; color: white; padding: 14px 28px; border: none; border-radius: 6px; font-weight: bold; font-size: 1rem; cursor: pointer; transition: background-color 0.3s;" onmouseover="this.style.backgroundColor='#333'" onmouseout="this.style.backgroundColor='#111'">Send Message</button>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>

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