<?php
declare(strict_types=1);
require_once __DIR__ . '/../lib.php';

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

try {
    $pdo = hw_db();
    
    // Get all active product categories
    $stmt = $pdo->query('
        SELECT id, name, description, slug
        FROM product_categories
        WHERE active = 1
        ORDER BY name ASC
    ');
    
    $categories = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo json_encode([
        'success' => true,
        'categories' => $categories,
        'count' => count($categories)
    ]);
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'error' => 'Failed to load categories: ' . $e->getMessage()
    ]);
}
