<?php

include('../elements/functions.php');

if (isset($_SESSION['token'])) {
    $token = $_SESSION['token'];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$user_id = $_POST['id'];

$url = "https://172.16.10.143:9999/api/v1/configurator/user/";
$result = make_get_request($url, ["Authorization: $token"]);
$response = json_decode($result, true);
$_SESSION["response"]=$response ;
if (isset($response['items']) && is_array($response['items'])) {
    $user_list = array_map(function($user) {
        return [
            'pid' => $user['pid'] ?? '-',
            'firstname' => $user['firstname'] ?? '-',
            'lastname' => $user['lastname'] ?? '-',
            'email' => $user['email'] ?? '-',
            'access_level' => $user['access_level'] ?? '-', // Example, adjust as needed
            'category' => $user['category'] ?? '-', // Example, adjust as needed
            'category_id' => $user['cetegory_id'] ?? '-' 
        ];
    }, $response['items']);

} 
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="api.php" method="POST">
        <input name="id"  type="text">
        <button type="submit">submit</button>
    </form>
    <?php foreach($user_list as $user): ?>
    uid:
    <h4><?php echo htmlspecialchars($user['pid']); ?></h4>
    name:
    <h4><?php echo htmlspecialchars($user['firstname']); ?></h4>
    lastname:
    <h4><?php echo htmlspecialchars($user['lastname']); ?></h4>
    email:
    <h4><?php echo htmlspecialchars($user['email']); ?></h4>
    acess_level:
    <h4><?php echo htmlspecialchars($user['acess_level']); ?></h4>
    category:
    <h4><?php echo htmlspecialchars($user['category']); ?></h4>
    categ_id:
    <h4><?php echo htmlspecialchars($user['category_id']); ?></h4>
    <?php endforeach ?>
</body>
</html>