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

if (!empty($_POST['order']) && is_array($_POST['order'])) {
    foreach ($_POST['order'] as $position => $id) {
        $stmt = $pdo->prepare("UPDATE event_participants SET sort_order = ? WHERE id = ?");
        $stmt->execute([$position + 1, $id]);
    }
    echo json_encode(["status" => "success"]);
} else {
    echo json_encode(["status" => "error", "message" => "Invalid data"]);
}
