<?php
require_once '../ext/db.php'; 

// --- SEO CONFIGURATION ---
$pageTitle = "Contact Starent. | Get in Touch with Our Team";
$pageDesc = "Have a tip, a question, or a business inquiry? Contact the Starent. editorial team today. We'd love to hear from you.";
$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]";

// --- SCHEMA.ORG (JSON-LD) ---
$schemaData = [
    "@context" => "https://schema.org",
    "@graph" => [
        [
            "@type" => "NewsMediaOrganization",
            "@id" => $baseUrl . "/#organization",
            "name" => "Starent.",
            "url" => $baseUrl,
            "logo" => [
                "@type" => "ImageObject",
                "url" => $baseUrl . "/logo/logo-sterent.jpg"
            ],
            "contactPoint" => [
                "@type" => "ContactPoint",
                "email" => "support@starent.com",
                "contactType" => "customer service"
            ]
        ],
        [
            "@type" => "ContactPage",
            "@id" => $currentUrl,
            "url" => $currentUrl,
            "name" => $pageTitle,
            "description" => $pageDesc,
            "isPartOf" => ["@id" => $baseUrl . "/#website"],
            "mainEntity" => ["@id" => $baseUrl . "/#organization"]
        ]
    ]
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <title><?php echo $pageTitle; ?></title>
    <meta name="description" content="<?php echo $pageDesc; ?>">
    <link rel="canonical" href="<?php echo $currentUrl; ?>">
    <meta name="robots" content="index, follow">
    
    <meta property="og:type" content="website">
    <meta property="og:url" content="<?php echo $currentUrl; ?>">
    <meta property="og:title" content="<?php echo $pageTitle; ?>">
    <meta property="og:description" content="<?php echo $pageDesc; ?>">
    <meta property="og:site_name" content="Starent.">
    
    <meta property="twitter:card" content="summary">
    <meta property="twitter:title" content="<?php echo $pageTitle; ?>">
    <meta property="twitter:description" content="<?php echo $pageDesc; ?>">

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,300;0,400;0,700;1,400&family=Oswald:wght@400;500;700&family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    
    <link rel="stylesheet" href="/styles/home.css">

    <style>
        .contact-header {
            background: #f8fafc;
            padding: 60px 20px;
            text-align: center;
            border-bottom: 1px solid #e2e8f0;
        }

        .contact-header h1 {
            font-family: 'Oswald', sans-serif;
            font-size: 3rem;
            text-transform: uppercase;
            color: #1e293b;
            margin: 0 0 10px 0;
        }

        .contact-header p {
            color: #64748b;
            font-size: 1.1rem;
            max-width: 600px;
            margin: 0 auto;
        }

        .contact-wrapper {
            display: grid;
            grid-template-columns: 1fr 1.5fr; /* Info takes less space than form */
            gap: 50px;
            padding: 60px 0;
            max-width: 1000px;
            margin: 0 auto;
        }

        /* Left Side: Info */
        .info-card {
            background: #fff;
            padding: 30px;
            border: 1px solid #e2e8f0;
            border-radius: 4px;
            margin-bottom: 20px;
        }

        .info-card i {
            font-size: 1.5rem;
            color: #0ea5e9;
            margin-bottom: 15px;
            display: block;
        }

        .info-card h4 {
            font-family: 'Oswald', sans-serif;
            font-size: 1.3rem;
            margin: 0 0 10px 0;
            color: #1e293b;
        }

        .info-card p, .info-card a {
            color: #64748b;
            font-size: 0.95rem;
            line-height: 1.5;
            display: block;
        }
        
        .info-card a:hover { color: #0ea5e9; }

        /* Right Side: Form */
        .contact-form-container {
            background: #fff;
            padding: 40px;
            border: 1px solid #e2e8f0;
            box-shadow: 0 5px 20px rgba(0,0,0,0.03);
            border-radius: 4px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            font-family: 'Poppins', sans-serif;
            font-size: 0.85rem;
            font-weight: 600;
            color: #334155;
            margin-bottom: 8px;
        }

        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #cbd5e1;
            border-radius: 4px;
            font-family: 'Poppins', sans-serif;
            font-size: 0.95rem;
            transition: all 0.3s;
        }

        .form-control:focus {
            outline: none;
            border-color: #0ea5e9;
            box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
        }

        textarea.form-control {
            resize: vertical;
            min-height: 150px;
        }

        .btn-submit {
            background: #0ea5e9;
            color: white;
            border: none;
            padding: 15px 30px;
            font-family: 'Oswald', sans-serif;
            font-size: 1rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            cursor: pointer;
            width: 100%;
            transition: background 0.3s;
        }

        .btn-submit:hover {
            background: #0284c7;
        }
        
        .contact-message {
            margin-top: 15px;
            font-size: 0.9rem;
            font-weight: 600;
            text-align: center;
        }

        @media (max-width: 768px) {
            .contact-wrapper {
                grid-template-columns: 1fr;
                gap: 30px;
            }
            .contact-form-container {
                padding: 25px;
            }
        }
    </style>
    <?php include '../ext/header.php' ?>
    <script type="application/ld+json">
        <?php echo json_encode($schemaData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); ?>
    </script>
</head>
<body>
    <?php include '../ext/nav.php' ?>

    <div class="contact-header">
        <div class="container">
            <h1>Get In Touch</h1>
            <p>We want to hear from you. Send us your feedback, news tips, or advertising inquiries.</p>
        </div>
    </div>

    <div class="container">
        <div class="contact-wrapper">
            
            <div class="contact-info">
                <div class="info-card">
                    <i class="fas fa-envelope"></i>
                    <h4>General Inquiries</h4>
                    <p>For general questions and feedback:</p>
                    <a href="mailto:info@starent.co.za">info@starent.co.za</a>
                </div>

                <div class="info-card">
                    <i class="fas fa-newspaper"></i>
                    <h4>News Tips</h4>
                    <p>Got a scoop? Send it securely to our editors:</p>
                    <a href="mailto:art@starent.co.za">art@starent.co.za</a>
                </div>

                <div class="info-card">
                    <i class="fas fa-bullhorn"></i>
                    <h4>Advertising</h4>
                    <p>Partner with Starent. for your next campaign:</p>
                    <a href="mailto:info@starent.co.za">info@starent.co.za</a>
                </div>
            </div>

            <div class="contact-form-container">
                <form id="contactForm">
                    <div class="form-group">
                        <label for="name">Your Name</label>
                        <input type="text" id="name" name="name" class="form-control" placeholder="John Doe" required>
                    </div>

                    <div class="form-group">
                        <label for="email">Email Address</label>
                        <input type="email" id="email" name="email" class="form-control" placeholder="john@example.com" required>
                    </div>

                    <div class="form-group">
                        <label for="subject">Subject</label>
                        <select id="subject" name="subject" class="form-control">
                            <option value="General">General Inquiry</option>
                            <option value="Tip">Submit a News Tip</option>
                            <option value="Advertising">Advertising</option>
                            <option value="Bug">Report a Website Bug</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="message">Message</label>
                        <textarea id="message" name="message" class="form-control" placeholder="How can we help you?" required></textarea>
                    </div>

                    <button type="submit" class="btn-submit" id="submitBtn">Send Message</button>
                    <div id="formResponse" class="contact-message"></div>
                </form>
            </div>

        </div>
    </div>

    <?php include '../ext/footer.php' ?>

    <script>
    document.getElementById('contactForm').addEventListener('submit', function(e) {
        e.preventDefault();
        
        const btn = document.getElementById('submitBtn');
        const msgDiv = document.getElementById('formResponse');
        const formData = new FormData(this);
        
        // UI Loading
        const originalText = btn.innerText;
        btn.innerText = 'Sending...';
        btn.disabled = true;
        btn.style.opacity = '0.7';
        msgDiv.innerText = '';

        fetch('/ext/send_contact.php', {
            method: 'POST',
            body: formData
        })
        .then(response => response.json())
        .then(data => {
            if(data.status === 'success') {
                msgDiv.style.color = '#0ea5e9';
                msgDiv.innerText = "Thanks! We've received your message.";
                document.getElementById('contactForm').reset();
            } else {
                msgDiv.style.color = '#ef4444';
                msgDiv.innerText = data.message || "Something went wrong.";
            }
        })
        .catch(error => {
            msgDiv.style.color = '#ef4444';
            msgDiv.innerText = "Connection error. Please try again.";
        })
        .finally(() => {
            btn.innerText = originalText;
            btn.disabled = false;
            btn.style.opacity = '1';
        });
    });
    </script>
</body>
</html>