<?php
require_once '../data.php';

$select_time = "SELECT bola_1 FROM workingtime";
$query = mysqli_query($data, $select_time);

if(mysqli_num_rows($query) > 0) {
    $fetch_time = mysqli_fetch_assoc($query);
    $result_time = strtotime($fetch_time['bola_1']);
    $current_time = time();

    $remaining = $result_time - $current_time;

    if($remaining < 0) {
      $remaining += 24 * 3600;
    }

    $dataTime = array(
        array("time" => $remaining)
    );

    $jsonData = json_encode($dataTime);

    header('Content-Type: application/json');
    echo $jsonData;
    
}

?>