<?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 = 'FAQ | LOVE-U Essentials';
$pageDescription = 'Frequently asked questions about LOVE-U Essentials products, orders, shipping, returns, gifts, and customer accounts.';

$faqs = $pdo->query("
    SELECT *
    FROM faqs
    WHERE status = 'active'
    ORDER BY sort_order ASC, id ASC
")->fetchAll();

if (!$faqs) {
    $faqs = [
        [
            'question' => 'How do I place an order?',
            'answer' => 'Browse the shop, open a product, add it to your cart, and continue to checkout. Once payment integration is connected, you will be able to complete payment securely online.'
        ],
        [
            'question' => 'Do you offer gift orders?',
            'answer' => 'Yes. The checkout includes a gift option where you can add recipient details and a gift message.'
        ],
        [
            'question' => 'How is shipping calculated?',
            'answer' => 'Shipping is calculated during checkout. The current version includes a basic shipping rule, and advanced region-based shipping can be connected next.'
        ],
        [
            'question' => 'Can I create a customer account?',
            'answer' => 'Yes. You can register, login, view order history, manage your wishlist, and use your referral code.'
        ],
        [
            'question' => 'How do loyalty points work?',
            'answer' => 'Loyalty points are added after payment is marked as paid by the admin. The current rule is £1 equals 1 point.'
        ],
    ];
}

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

<section class="shop-hero">
    <div class="container">
        <div class="eyebrow">Help Centre</div>
        <h1>Frequently Asked Questions</h1>
        <p>Find answers about ordering, delivery, gifts, customer accounts, wishlist, and loyalty points.</p>
    </div>
</section>

<section class="section">
    <div class="container" style="max-width:900px;">
        <div class="checkout-form">
            <?php foreach ($faqs as $index => $faq): ?>
                <details class="accordion-item" <?= $index === 0 ? 'open' : ''; ?>>
                    <summary><?= e($faq['question']); ?></summary>
                    <p><?= nl2br(e($faq['answer'])); ?></p>
                </details>
            <?php endforeach; ?>
        </div>

        <div style="text-align:center; margin-top:30px;">
            <p style="color:#666;">Still need help?</p>
            <a href="<?= e(BASE_URL); ?>/public/contact.php" class="btn">Contact Us</a>
        </div>
    </div>
</section>

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