<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
//
// Copyright (c) 2021 RealTime Fantasy Sports, Inc.
//
require_once("autoload.php");
require_once("../conf/basketball.cfg");
require_once("basketball-functions.php");

list($rtuser, $theme, $league) = BasketballPresentation::Initialize();
$team = $globals->team;

//IncludePlayerStats(NBA::Season); // FIXME - Get player stats from Redis

$theme->ResponsiveHeader($rtuser, IsSmartPhone());

?>
<style>
@media (max-width: 479px) { /* less that 480px */
   .table-schedule > tbody > tr > td { padding-left: 4px; padding-right:4px; }
   .table-schedule .col-tn-4 { padding-left:4px; padding-right:4px; }
}
</style>
<?

$DATE = ScrubString('DATE',10);
if (!$DATE) $DATE = 'TODAY';

$curr = strtotime($DATE);
//if ($curr < strtotime(NBA::OpeningGame) || $curr > strtotime(NBA::Season . "-11-30")) $curr = strtotime(NBA::OpeningGame);
$past = $curr < strtotime("today");

$prev = $curr - RTFSTime::OneDay;
$next = RTFSTime::AddDays($curr, 1);

echo '<div class="row" style="margin-top:20px; margin-bottom:20px;">';
echo '<div class="col-xs-4 col-tn-2 text-left">';
echo '<a class="btn btn-primary" href="' . BasketballPresentation::URL('nba-schedule.php') . '&DATE=' . RTFSTime::URL($prev) . '">';
echo '<span class="glyphicon glyphicon-chevron-left"></span><span class="hidden-tn"> ' . RTFSTime::NavButton($prev) . '</span></a>';
echo '</div>';

echo '<div class="col-xs-4 col-tn-8 text-center"><h1>';
echo RTFSTime::ShowDateDOW($curr+RTFSTime::OneHour*8);	// add 8 hours to it since it's set to midnight and timezone subtraction will move it back a day
echo '</h1></div>';

echo '<div class="col-xs-4 col-tn-2 text-right">';
echo '<a class="btn btn-primary" href="' . BasketballPresentation::URL('nba-schedule.php') . '&DATE=' . RTFSTime::URL($next) . '">';
echo '<span class="hidden-tn">' . RTFSTime::NavButton($next) . ' </span><span class="glyphicon glyphicon-chevron-right"></span></a>';
echo '</div>';
echo '</div>';

echo '<table class="table table-hover table-schedule"><thead>';
echo '<tr class="hidden-tn"><th></th><th class="hidden-tn">Away</th><th></th><th></th><th class="hidden-tn">Home</th><th>Time</th>';
echo '<th>Status</th></tr>';
echo '</thead><tbody>';

$schedule = BasketballGame::GetSchedule($curr);
foreach($schedule as $game) {
   echo '<tr game-id="' . $game->game_id . '">';
   echo '<td class="nba-logo"><img src="' . NBA::LogoURL($game->away) . '"></td>';
   echo '<td class="hidden-tn">' . NBA::Nickname($game->away) . '</td>';
   echo '<td>at</td>';
   echo '<td class="nba-logo"><img src="' . NBA::LogoURL($game->home) . '"></td>';
   echo '<td class="hidden-tn">' . NBA::Nickname($game->home) . '</td>';
   echo '<td style="white-space:nowrap;">' . RTFSTime::ShowTime($game->start_time) . '</td>';
   echo '<td>';
   if ($game->NotStarted()) {
      echo '<div class="' . (time() < $game->start_time ? "hidden-tn":"") . '">' . $game->Status() . '</div>';
   } else {
      echo '<div class="row"><div class="col-tn-4">' . $game->away . " " . $game->away_score . '</div><div class="col-tn-4">' . $game->home . " " . $game->home_score . '</div>';
      echo '<div class="col-tn-4">' . BasketballPresentation::NBAGameStatus($game) . '</div></div>';

   }
   echo '</td>';
   echo '</tr>';
}
echo '</tbody></table>';
$theme->ResponsiveFooter();
?>