<div class="mheader">
    <div>
%   if ($departure->{train_no} or $departure->{train_line}) {
      <span class="train-line <%= $linetype %>"><%= $departure->{train_type} %>
%     if ($linetype eq 'fern' and $icetype and $icetype->[1]) {
        <span class="trainsubtype" aria-hidden="true"><%= $icetype->[1] %></span>
%     }

      <%= $departure->{train_line} // $departure->{train_no} %></span>
      <span class="train-no"><%= $departure->{train_line} ? $departure->{train_no} : q{} %></span>
%   }
    </div>
    <div>
%   if ($departure->{origin}) {
      <span class="train-origin"><%= $departure->{origin} %></span>
      →
%   }
    <span class="train-dest"><%= $departure->{destination} // q{???} %></span>
    </div>
<!--
%   if ($departure->{is_cancelled}) {
      <div class="minfo">Fahrt fällt aus</div>
%   }
%   elsif (defined $departure->{delay} and $departure->{delay} > 0) {
      <div class="minfo">+<%= $departure->{delay} %>
%     if ($departure->{departure_is_cancelled}) {
        (endet hier)
%     }
      </div>
%   }
%   if (@{$departure->{replaced_by}}) {
%     for my $replacement (@{$departure->{replaced_by}}) {
        <span class="replaced">Ersatzzug: <%= $replacement %></span>
%     }
%   }
%   if (@{$departure->{replacement_for}}) {
%     for my $replacement (@{$departure->{replacement_for}}) {
        <span class="replacement">Ersatzzug für <%= $replacement %></span>
%     }
%   }
-->
    </div> <!-- mheader -->
    <div class="mfooter">
    <div class="dataline">
    <div>
    <div class="arrival">
%     if ($departure->{is_cancelled} and $departure->{sched_arrival}) {
        <span class="minfo">An: ––:––</span><br/>Plan: <%= $departure->{sched_arrival} %>
%     }
%     elsif ($departure->{arrival_is_cancelled}) {
        <span class="minfo">Beginnt hier</span><br/>Plan: <%= $departure->{sched_arrival} %>
%     }
%     elsif ($departure->{arrival}) {
%       if ($departure->{arrival} ne $departure->{sched_arrival}) {
          % if ($departure->{delay} < 0) {
            An: <span class="undelay"><%= $departure->{arrival} %></span>
          % }
          % else {
            An: <span class="minfo"><%= $departure->{arrival} %></span>
          % }
          <br/>Plan: <%= $departure->{sched_arrival} %>
%       }
%       else {
          An: <%= $departure->{arrival} %>
%       }
%     }
    </div>
    </div>
    <div>
    <div class="platform">
%   if ($departure->{arrival_is_cancelled} and $departure->{departure_is_cancelled}) {
      <span class="minfo">Fahrt fällt aus</span>
%   }
%   else {
%     my $left = '';
%     my $right = '';
%     if ($departure->{direction} and $departure->{direction} eq 'l') {
%       $left = '◀ ';
%     }
%     elsif ($departure->{direction} and $departure->{direction} eq 'r') {
%       $right = ' ▶';
%     }
%     if ($departure->{scheduled_platform} and $departure->{platform}
%         and $departure->{scheduled_platform} ne $departure->{platform}) {
        <span class="minfo"><%= $left %>Gleis <%= $departure->{platform} %><%= $right %></span>
%     }
%     elsif ($departure->{scheduled_platform} or $departure->{platform}) {
        <%= $left %>Gleis <%= $departure->{platform} // $departure->{scheduled_platform} %><%= $right %>
%     }
%   }
    </div>
    </div>
    <div>
    <div class="departure">
%     if ($departure->{is_cancelled} and $departure->{sched_departure}) {
        <span class="minfo">Ab: ––:––</span><br/>Plan: <%= $departure->{sched_departure} %>
%     }
%     elsif ($departure->{departure_is_cancelled}) {
        <span class="minfo">Endet hier</span><br/>Plan: <%= $departure->{sched_departure} %>
%     }
%     elsif ($departure->{departure}) {
%       if ($departure->{departure} ne $departure->{sched_departure}) {
          Ab: <span class="minfo"><%= $departure->{departure} %></span>
          <br/>Plan: <%= $departure->{sched_departure} %>
%       }
%       else {
          Ab: <%= $departure->{departure} %>
%       }
%     }
    </div>
    </div>
    </div> <!-- dataline -->
    <div class="verbose">
%     if ($departure->{trip_id}) {
%       if (stash('station_name')) {
        <a class="smallbutton" href="/map/<%= $departure->{trip_id} %>/<%= $departure->{train_line} // 0 %>?from=<%= stash('station_name') %>"><i class="material-icons" aria-hidden="true">map</i> Karte</a>
%       }
%       else {
        <a class="smallbutton" href="/map/<%= $departure->{trip_id} %>/<%= $departure->{train_line} // 0 %>"><i class="material-icons" aria-hidden="true">map</i> Karte</a>
%       }
%     }
%     if ($departure->{wr_link}) {
        <a class="smallbutton" href="/_wr/<%= $departure->{train_no} %>/<%= $departure->{wr_link} %>?e=<%= $departure->{direction} // '' %>"><i class="material-icons" aria-hidden="true">train</i> Wagenreihung
        </a>
%     }
%     elsif ($icetype and $icetype->[2] and ($linetype eq 'fern' or $departure->{train_type} =~ m{NJ})) {
        <a class="smallbutton" href="/wr/<%= $departure->{train_no} %>"><i class="material-icons" aria-hidden="true">train</i> Plan: <%= $icetype->[0] %></a>
%     }
%     elsif ($icetype and $icetype->[1] and $linetype eq 'fern') {
        <span class="disabledbutton"><i class="material-icons" aria-hidden="true">train</i> Plan: <%= $icetype->[0] %></span>
%     }
%     for my $link (@{$departure->{links}}) {
        <a class="smallbutton" href="<%= $link->[1] %>"><i class="material-icons" aria-hidden="true">warning</i> <%= $link->[0] %></a>
%     }
    </div>

%   if (my $u = $departure->{utilization}) {
      <div class="verbose">
%       my ($text, $icon1, $icon2) = utilization_icon($u);
        <%= $text %><span style="padding-right: 0.5em;">.</span> 1. <i class="material-icons" aria-hidden="true" style="padding-right: 0.5em; vertical-align: bottom;"><%= $icon1 %></i> 2. <i class="material-icons" aria-hidden="true" style="vertical-align: bottom;"><%= $icon2 %></i>
      </div>
%   }

%   if ($departure->{moreinfo} and @{$departure->{moreinfo}}) {
      Meldungen:
      <ul>
%     for my $pair (@{$departure->{moreinfo}}) {
        <li>
%       if ($pair->[0]->isa('DateTime')) {
%         if ($pair->[0]->day != $dt_now->day) {
%           $pair->[0]->set_locale('de_DE');
%=          $pair->[0]->strftime('%a %H:%M')
%         }
%         else {
%=          $pair->[0]->strftime('%H:%M')
%         }
%       }
%       else {
%=        $pair->[0]
%         if (length($pair->[0]) > 25) {
            <br/>
%         }
%       }
        <span class="reason">
%=      $pair->[1]
        </span>
        </li>
%     }
%     if ($departure->{route_info}) {
        <li><%= $departure->{route_info} %></li>
%     }
      </ul>
%   }
%   if ($departure->{route_pre_diff} and $departure->{route_post_diff}) {
      Fahrtverlauf:
      <ul class="mroute">
%       for my $stop (@{$departure->{route_pre_diff}}) {
          <li>
          <a href="<%= url_for('station', station => $stop->{name})->query({detailed => param('detailed')}) %>#<%= ($departure->{train_type} // q{x}) . ($departure->{train_no} // q{x}) %>" class="
%         if ($stop->{isAdditional}) {
            additional-stop
%         }
%         elsif ($stop->{isCancelled}) {
            cancelled-stop
%         }
%         elsif ($self->is_important($stop->{name})) {
            important-stop
%         }
%         else {
            generic-stop
%         }
%         if ($stop->{rt_dep}) {
            "><%= $stop->{sched_dep}->strftime('%H:%M') %> (heute <%= $stop->{rt_dep}->strftime('%H:%M') %>) <%= $stop->{name} %></a>
%         }
%         else {
            "><%= $stop->{sched_dep} ? $stop->{sched_dep}->strftime('%H:%M') : q{} %> <%= $stop->{name} %></a>
%         }
          </li>
%       }
%       if (stash('station_name')) {
          <li class="<%= $departure->{is_cancelled} ? 'cancelled-stop' : q{} %>"><%= $departure->{sched_departure} // $departure->{sched_arrival} // q{} %>
%           if ($departure->{sched_departure}) {
%             if ($departure->{departure} ne $departure->{sched_departure}) {
                (heute <%= $departure->{departure} %>)
%             }
%           }
%           elsif ($departure->{arrival}) {
%             if ($departure->{arrival} ne $departure->{sched_arrival}) {
                (heute <%= $departure->{arrival} %>)
%             }
%           }
            <strong><%= stash('station_name') %></strong>
          </li>
%       }
%       for my $stop (@{$departure->{route_post_diff}}) {
          <li>
          <a href="<%= url_for('station', station => $stop->{name})->query({detailed => param('detailed')}) %>#<%= ($departure->{train_type} // q{x}) . ($departure->{train_no} // q{x}) %>" class="
%         if ($stop->{isAdditional}) {
            additional-stop
%         }
%         elsif ($stop->{isCancelled}) {
            cancelled-stop
%         }
%         elsif ($self->is_important($stop->{name})) {
            important-stop
%         }
%         else {
            generic-stop
%         }
%         if ($stop->{rt_arr}) {
            "><%= $stop->{sched_arr}->strftime('%H:%M') %> (heute <%= $stop->{rt_arr}->strftime('%H:%M') %>) <%= $stop->{name} %></a>
%         }
%         else {
            "><%= $stop->{sched_arr} ? $stop->{sched_arr}->strftime('%H:%M') : q{} %> <%= $stop->{name} %></a>
%         }
          </li>
%       }
      </ul> <!-- mroute -->
%   }
%   if ($departure->{has_cycle}) {
      <div class="db-attr"><a href="https://lib.finalrewind.org/dbdb/db_umlauf/<%= $departure->{train_no} %>.svg">Umlaufplan</a>
        (ggf. fehlerhaft)</div>
%   }
%   if ($details->{commonAttr}) {
%     if ($details->{attrVariants} and (not $details->{commonAttr}{vmax} or not $details->{commonAttr}{brakingPercentage})) {
        <div class="db-attr">
          Attribute:
          <ul>
%           for my $attr (@{$details->{attrVariants} // [] }) {
              <li><%= include '_train_attr', attr => $attr, with_station => 1 %></li>
%           }
          </ul>
        </div>
%     }
%     else {
        <div class="db-attr">
%=        include '_train_attr', attr => $details->{commonAttr}, with_station => 0
        </div>
%     }
%   }
%   if ($details and not $departure->{arrival}) {
%     if (my $s = $details->{route}{preStart}) {
        Zug wird voraussichtlich aus <%= $s %> eingesetzt.<br/><br/>
%     }
%     if (@{$departure->{cycle_from} // []}) {
        Bildung möglicherweise aus
        <ul>
%         for my $t (@{$departure->{cycle_from}}) {
%           my ($train_no, $train) = @{$t};
%           my $tt = $train->{type} // $train->{rawType} // 'Zug';
%           $tt =~ s{ .*|[0-9]}{};
            <li><%= $tt %> <%= $train_no %>
%             if ($train->{route}{start} and $train->{route}{end}) {
                <%= $train->{route}{start} %> → <%= $train->{route}{end} %>
%             }
            </li>
%         }
        </ul>
%     }
%   }
%   elsif ($details and not $departure->{departure}) {
%     if (my $e = $details->{route}{postEnd}) {
        Zug wird voraussichtlich in <%= $e %> abgestellt.<br/><br/>
%     }
%     if (@{$departure->{cycle_to} // []}) {
        Weiterfahrt möglicherweise als
        <ul>
%         for my $t (@{$departure->{cycle_to}}) {
%           my ($train_no, $train) = @{$t};
%           my $tt = $train->{type} // $train->{rawType} // 'Zug';
%           $tt =~ s{ .*|[0-9]}{};
            <li><%= $tt %> <%= $train_no %>
%             if ($train->{route}{start} and $train->{route}{end}) {
                <%= $train->{route}{start} %> → <%= $train->{route}{end} %>
%             }
            </li>
%         }
        </ul>
%     }
%   }
%   if ($icetype and not param('detailed')) {
      <div class="verbose">
        <a href="<%= url_for->query(detailed => 1) %>">Mehr Details</a>
      </div>
%   }
    </div> <!-- mfooter -->