<!DOCTYPE html>
<html>
<head>
	<title><%= $title %></title>
	<meta charset="utf-8">
% if ($self->stash('refresh_interval')) {
	<meta http-equiv="refresh" content="<%= $self->stash('refresh_interval') %>"/>
% }

	%= stylesheet '/infoscreen.css'
	%= javascript '/jquery-2.1.1.min.js'
	%= javascript '/collapse.js'
</head>
<body>

% if (my $error = stash 'error') {
<div class="error">Received an error from the backend service:</div>
<div>
<pre>
%= $error
</pre>
</div>
% }

<div class="displayclean">
<ul>
% for my $departure (@{$raw}) {
%   my $linetype = q{};
%   if ($departure->can('type')) {
%     given ($departure->type) {
%       when ($_ =~ m{ (?: enbahn $ ) | Tram | STR }ix) { $linetype = 'tram' }
%       when ('S-Bahn')       { $linetype = 'sbahn' }
%       when ([qw[NE Niederflurbus SB Bus]]) { $linetype = 'bus' }
%       when ('U-Bahn')       { $linetype = 'ubahn' }
%     }
%   }
    <li>
    <span class="line <%= $linetype %>">
    %= $departure->line
    </span> <!-- line -->
    <span class="moreinfo">
    <div class="mheader">
    <span class="train-line"><%= $departure->line %></span>
    :
    <span class="train-route">
%   if ($departure->can('lineref') and $departure->lineref) {
%=    $departure->lineref->route
%   }
%   else {
%=    $departure->destination
%   }
    </span> <!-- train-route -->
    </div> <!-- mheader -->
%   if ($departure->isa('Travel::Status::DE::EFA::Result')) {
      Fahrplan:
      <table class="scheduled">
%     for my $stop ($departure->route_pre) {
        <tr class="routepre"><td class="time">
%       if (not defined $stop->arr_time) {
          <%= $stop->dep_time %>
%       }
%       elsif (not defined $stop->dep_time) {
          <%= $stop->arr_time %>
%       }
%       elsif ( $stop->arr_time eq $stop->dep_time ) {
          <%= $stop->dep_time %>
%       }
%       else {
          <%= $stop->arr_time %> → <%= $stop->dep_time %>
%       }
        </td>
        <td class="stop"><%= $stop->name %></td></tr>
%     }
      <tr class="routenow"><td class="time">
%     if ($departure->can('sched_time')) {
        <%= $departure->sched_time %>
%     }
%     else {
        <%= $departure->time %>
%     }
      </td>
      <td class="stop"><%= $id_name %> <%= $id_stop %></td></tr>
%     for my $stop ($departure->route_post) {
        <tr class="routepost"><td class="time">
%       if (not defined $stop->arr_time) {
          <%= $stop->dep_time %>
%       }
%       elsif (not defined $stop->dep_time) {
          <%= $stop->arr_time %>
%       }
%       elsif ( $stop->arr_time eq $stop->dep_time ) {
          <%= $stop->dep_time %>
%       }
%       else {
          <%= $stop->arr_time %> → <%= $stop->dep_time %>
%       }
        </td>
        <td class="stop"><%= $stop->name %></td></tr>
%     }
      </table>
%   }
%   elsif ($departure->isa('Travel::Status::DE::URA::Result')) {
      Fahrplan:
      <table class="scheduled">
%     for my $stop ($departure->route_pre) {
        <tr class="routepre"><td class="time">
%=        $stop->[0]->strftime('%H:%M:%S')
        </td>
        <td class="stop"><%= $stop->[1] %></td></tr>
%     }
      <tr class="routenow"><td class="time">
        <%= $departure->time %>
      </td>
      <td class="stop"><%= $id_name %> <%= $id_stop %></td></tr>
%     for my $stop ($departure->route_post) {
        <tr class="routepost"><td class="time">
%=      $stop->[0]->strftime('%H:%M:%S')
        </td>
        <td class="stop"><%= $stop->[1] %></td></tr>
%     }
      </table>
%   }
    </span> <!-- moreinfo -->
    <span class="route">
%   if ($departure->can('route_interesting') and $departure->route_interesting) {
%=    join(' - ', map { ref($_) ? $_->name_suf : $_ } ($departure->route_interesting));
%   }
%   elsif ($departure->can('lineref') and $departure->lineref) {
%=    $departure->lineref->route
%   }
    </span> <!-- route -->
    <span class="dest">
%=  $departure->destination
    </span> <!-- dest -->
    <span class="countdown">
%   if ($departure->can('delay') and $departure->delay) {
      <span class="delay"> (+<%= $departure->delay %>) </span>
%   }
%   if ($departure->can('is_cancelled') and $departure->is_cancelled) {
      <span class="delay"> FÄLLT AUS </span>
%   }
%   else {
%     if ($departure->can('countdown')) {
%       if ($departure->countdown > 0) {
          <%= $departure->countdown %> min
%       }
%       else {
          sofort
%       }
%     }
%   }
    </span> <!-- countdown -->
    <span class="time">
%=  $departure->time
    </span>
    </li>
% }
</ul>
</div>

</body>
</html>