<?php
error_reporting(-1);
function randomColorHex()
{
    return sprintf("#%06X", mt_rand(0, 0xFFFFFF));
}

function buyers_available_server($state)
{


$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.convoso.com/v1/user-activity/search?auth_token=ont1vnptxt1kif9nfaplpqsbbt6xwk9a&campaign_id=&queue_id=19309&user_id=&filter_by_skill_options='. $state.'&exclude_remote_users=Y',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Cookie: APIUBUNTUBACKEND=apiapp120'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
    // echo $response;
$msg= '';
    $firstData = json_decode($response, true);
    if (isset($firstData['data']['available_agents']) && $firstData['data']['available_agents'] > 0) {
        $msg .= '<div class="result">';
        $msg .= "<strong>(". $firstData['data']['available_agents'].") Agent Available</strong>";
        $msg .= "<strong>(". $firstData['data']['logged_in_agents'].") Agent Logged</strong>";
        $msg .= '</div>';
    } else {
        $msg .= '<div class="result rejected">';
        $msg .= "<strong>Agent Not Available</strong>";
        $msg .= '</div>';
    }

    return $msg;
}



// echo ASBON();
// exit;
$mm_state        = (isset($_GET['state']) && $_GET['state'] != '') ? $_GET['state'] : '';

$data = [
    "buyers_available_server_pcb" => buyers_available_server($mm_state),
];

header('Content-Type: application/json');
echo json_encode($data);