<?php
/**
 * AJAX Get FAQs by Category
 * File: ajax/get-faqs.php
 */

require_once '../app/Core/init.php';

header('Content-Type: application/json');

$category = $_GET['category'] ?? '';

if (empty($category)) {
    echo json_encode(['success' => false, 'message' => 'Category required']);
    exit;
}

try {
    $faqModel = new Faq();
    
    if ($category === 'featured') {
        // Get featured FAQs
        $faqs = $faqModel->getFeatured(20);
    } else {
        // Get FAQs by category
        $faqs = $faqModel->getByCategory($category);
    }
    
    echo json_encode([
        'success' => true,
        'faqs' => $faqs,
        'count' => count($faqs)
    ]);
    
} catch (Exception $e) {
    error_log("Get FAQs error: " . $e->getMessage());
    echo json_encode([
        'success' => false,
        'message' => 'Error loading FAQs'
    ]);
}