<?php
include '../db.php';

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

try {
    $query = "
        SELECT 
            im.id,
            im.modifier_group_id,
            im.name,
            im.short_name,
            im.price_adjustment,
            im.cost_adjustment,
            im.is_default,
            im.is_active,
            im.sort_order,
            im.prep_time_adjustment,
            img.display_name as group_name
        FROM item_modifiers im
        JOIN item_modifier_groups img ON im.modifier_group_id = img.id
        ORDER BY img.sort_order, im.sort_order, im.name
    ";
    
    $result = $conn->query($query);
    $modifiers = [];
    
    while ($modifier = $result->fetch_assoc()) {
        $modifiers[] = $modifier;
    }
    
    echo json_encode(['success' => true, 'modifiers' => $modifiers]);
    
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
}
?>
