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

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

$template_id = isset($_GET['template_id']) ? intval($_GET['template_id']) : 0;

if ($template_id <= 0) {
    echo json_encode(['success' => false, 'message' => 'Invalid template ID']);
    exit;
}

try {
    $stmt = $conn->prepare("SELECT * FROM modifier_template_options WHERE template_id = ? ORDER BY sort_order, name");
    $stmt->bind_param("i", $template_id);
    $stmt->execute();
    $result = $stmt->get_result();
    
    $options = [];
    while ($row = $result->fetch_assoc()) {
        $options[] = $row;
    }
    
    echo json_encode([
        'success' => true,
        'options' => $options
    ]);
    
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
}
?>
