<?php
session_start();
include __DIR__ . '/includes/header.php';
include __DIR__ . '/includes/sidebar.php';

$contactFile = __DIR__ . '/data/contact_messages.txt';

/* Handle form submission */
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = trim($_POST['name']);
    $email = trim($_POST['email']);
    $message = trim($_POST['message']);

    if ($name && $email && $message) {
        $entry = implode('|', [
            uniqid(),
            $name,
            $email,
            $message,
            date('Y-m-d H:i:s')
        ]) . "\n";

        file_put_contents($contactFile, $entry, FILE_APPEND);
        $successMessage = "<div class='msg success'>Your message has been sent! We'll get back to you soon.</div>";
    } else {
        $errorMessage = "<div class='msg error'>Please fill in all fields.</div>";
    }
}
?>

<div class="main-wrap">
    <div class="content-panel">

        <!-- PAGE HEADER -->
        <div class="contact-banner">
            <h1 class="contact-banner-text">📨 Contact Us</h1>
            <p class="contact-subtext">We’d love to hear from you!</p>
        </div>

        <div class="vinyl-divider center-divider"></div>

        <!-- CONTACT FORM -->
        <div class="content-box">
            <?= $successMessage ?? '' ?>
            <?= $errorMessage ?? '' ?>

            <h3 class="section-title center-text">Send a Message</h3>

            <form method="POST" class="form">

                <input type="text" name="name" class="input-field" placeholder="Your Name" required>

                <input type="email" name="email" class="input-field" placeholder="Your Email" required>

                <textarea name="message" class="input-field" placeholder="Your Message" rows="5" required></textarea>

                <button type="submit" class="button radio-static">Send Message</button>
            </form>
        </div>

        <div class="vinyl-divider center-divider"></div>

        <!-- CONTACT INFO -->
        <div class="neon-card contact-info-card center-text">
            <h3 class="section-title">📡 Station Info</h3>

            <p class="about-text">
                <strong>Email:</strong> contact@oldiesandmore.com<br>
                <strong>Phone:</strong> (555) 123‑4567
            </p>

            <p class="about-text">
                We’re always happy to hear from listeners, partners, and fellow music lovers.
            </p>
        </div>

        <div class="vinyl-divider center-divider"></div>

        <!-- BACK BUTTON -->
        <div class="content-box center-text">
            <a href="index.php" class="button radio-static">⬅ Back to Home</a>
        </div>
<?php include __DIR__ . '/includes/footer.php'; ?>
    </div>
</div>


