<?php

declare(strict_types=1);

// Simulate LiveComponent action request
$ch = curl_init('https://localhost/livecomponent/action');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
    'Content-Type: application/json',
    'X-Requested-With: XMLHttpRequest',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'id' => 'datatable:demo',
    'component' => 'datatable',
    'action' => 'sort',
    'params' => ['column' => 'name'],
    'data' => [
        'rows' => [],
        'sort' => ['column' => 'id', 'direction' => 'asc'],
        'page' => 1,
        'page_size' => 10,
        'total_rows' => 20,
        'total_pages' => 2,
        'selected_rows' => [],
        'filters' => [
            'id' => '',
            'name' => '',
            'email' => '',
            'role' => '',
            'status' => '',
        ],
    ],
    'version' => 1,
]));

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

echo "HTTP Status: $httpCode\n";
echo "Response:\n";
echo $response;
echo "\n";
