<?php

require_once __DIR__ . '/../app/config/config.php';
require_once __DIR__ . '/../app/config/database.php';
require_once __DIR__ . '/../app/helpers/functions.php';
require_once __DIR__ . '/../app/helpers/auth.php';
require_once __DIR__ . '/../app/helpers/cart.php';

$pageTitle = 'Contact | LOVE-U Essentials';
$pageDescription = 'Contact LOVE-U Essentials for product enquiries, orders, delivery support, and customer care.';

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

if (is_post()) {
    if (!verify_csrf()) {
        $error = 'Invalid request. Please refresh and try again.';
    } else {
        $name = trim($_POST['name'] ?? '');
        $email = trim($_POST['email'] ?? '');
        $phone = trim($_POST['phone'] ?? '');
        $subject = trim($_POST['subject'] ?? '');
        $message = trim($_POST['message'] ?? '');

        if ($name === '' || $email === '' || $message === '') {
            $error = 'Please enter your name, email, and message.';
        } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $error = 'Please enter a valid email address.';
        } else {
            $success = 'Thank you. Your message has been received. We will get back to you soon.';

            /*
                Later we can save contact messages into database or send email.
                For now, this confirms the contact form flow.
            */
        }
    }
}

require_once __DIR__ . '/includes/header.php';
?>

<section class="shop-hero">
    <div class="container">
        <div class="eyebrow">Customer Care</div>
        <h1>Contact Us</h1>
        <p>Need help with a product, order, delivery, or gift purchase? Send us a message and we’ll assist you.</p>
    </div>
</section>

<section class="section">
    <div class="container checkout-layout">
        <div class="checkout-form">
            <h2>Send a Message</h2>

            <?php if ($success): ?>
                <div class="admin-alert admin-alert-success"><?= e($success); ?></div>
            <?php endif; ?>

            <?php if ($error): ?>
                <div class="admin-alert admin-alert-error"><?= e($error); ?></div>
            <?php endif; ?>

            <form method="POST">
                <?= csrf_field(); ?>

                <div class="checkout-grid">
                    <div class="checkout-field">
                        <label>Name *</label>
                        <input type="text" name="name" required>
                    </div>

                    <div class="checkout-field">
                        <label>Email *</label>
                        <input type="email" name="email" required>
                    </div>

                    <div class="checkout-field">
                        <label>Phone</label>
                        <input type="text" name="phone">
                    </div>

                    <div class="checkout-field">
                        <label>Subject</label>
                        <input type="text" name="subject">
                    </div>
                </div>

                <div class="checkout-field">
                    <label>Message *</label>
                    <textarea name="message" required></textarea>
                </div>

                <button type="submit" class="btn">Submit Message</button>
            </form>
        </div>

        <aside class="checkout-summary">
            <h2>Support Details</h2>

            <p style="line-height:1.8; color:#555;">
                <strong>Brand:</strong> LOVE-U Essentials<br>
                <strong>Support:</strong> Product enquiries, order support, delivery questions, gift orders, and customer care.
            </p>

            <hr style="border:none; border-top:1px solid #e2d8cc; margin:22px 0;">

            <h2>Quick Help</h2>

            <p style="line-height:1.8; color:#555;">
                For order-related enquiries, include your order number if available.
                For product questions, mention the product name so we can assist faster.
            </p>

            <a href="<?= e(BASE_URL); ?>/public/faq.php" class="btn btn-light" style="width:100%;">View FAQ</a>
        </aside>
    </div>
</section>

<?php require_once __DIR__ . '/includes/footer.php'; ?>