<?php
/**
 * FAQs Page
 * Digital Marketplace
 */

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

$page_title = 'Frequently Asked Questions';

// Get FAQs
$faqs = get_faqs();

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

<section class="section">
    <div class="container">
        <div class="text-center mb-5" data-aos="fade-up">
            <h1><i class="fas fa-question-circle me-2"></i>Frequently Asked Questions</h1>
            <p class="text-muted">Find answers to common questions about our marketplace</p>
        </div>
        
        <?php if (empty($faqs)): ?>
            <div class="text-center py-5">
                <i class="fas fa-inbox 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" data-aos="fade-up">
                        <?php foreach ($faqs as $index => $faq): ?>
                        <div class="accordion-item">
                            <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 me-2 text-primary"></i>
                                    <?php echo sanitize($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 nl2br(sanitize($faq['answer'])); ?>
                                </div>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        
        <!-- Still have questions -->
        <div class="text-center mt-5" data-aos="fade-up">
            <h4>Still have questions?</h4>
            <p class="text-muted mb-4">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>
</section>

<style>
.accordion-item {
    background: var(--gradient-card);
    border: 1px solid var(--dark-lighter);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    overflow: hidden;
}

.accordion-button {
    background: transparent;
    color: var(--white);
    font-weight: 500;
    padding: 1.25rem;
}

.accordion-button:not(.collapsed) {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    box-shadow: none;
}

.accordion-button:focus {
    box-shadow: none;
    border-color: var(--primary);
}

.accordion-button::after {
    filter: invert(1);
}

.accordion-body {
    color: var(--gray-400);
    padding: 1.25rem;
    border-top: 1px solid var(--dark-lighter);
}
</style>

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