<?php
/**
 * FAQ Page
 * Digital Product Store
 */

require_once __DIR__ . '/config/database.php';

$page_title = 'Frequently Asked Questions';

// Get FAQs
$faqs = get_faqs(true);

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

<div class="container py-5">
    <div class="text-center mb-5">
        <h1>Frequently Asked Questions</h1>
        <p class="text-muted">Find answers to common questions about our products and services</p>
    </div>
    
    <?php if (empty($faqs)): ?>
    <div class="text-center py-5">
        <i class="fas fa-question-circle fa-3x text-muted mb-3"></i>
        <p class="text-muted">No FAQs available at the moment.</p>
    </div>
    <?php else: ?>
    <div class="row justify-content-center">
        <div class="col-lg-8">
            <div class="accordion" id="faqAccordion">
                <?php foreach ($faqs as $index => $faq): ?>
                <div class="accordion-item border-0 mb-3 shadow-sm rounded-3 overflow-hidden">
                    <h2 class="accordion-header">
                        <button class="accordion-button <?php echo $index > 0 ? 'collapsed' : ''; ?>" type="button" data-bs-toggle="collapse" data-bs-target="#faq<?php echo $faq['id']; ?>">
                            <i class="fas fa-question-circle text-primary me-2"></i>
                            <?php echo htmlspecialchars($faq['question']); ?>
                        </button>
                    </h2>
                    <div id="faq<?php echo $faq['id']; ?>" class="accordion-collapse collapse <?php echo $index === 0 ? 'show' : ''; ?>" data-bs-parent="#faqAccordion">
                        <div class="accordion-body">
                            <?php echo $faq['answer']; ?>
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
    <?php endif; ?>
    
    <!-- Still have questions -->
    <div class="text-center mt-5">
        <h4>Still have questions?</h4>
        <p class="text-muted">Can't find the answer you're looking for? Please contact our support team.</p>
        <a href="<?php echo BASE_URL; ?>/contact.php" class="btn btn-primary">
            <i class="fas fa-envelope me-2"></i>Contact Support
        </a>
    </div>
</div>

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