{% load molly_utils %}{% load i18n %}{% if entity.metadata.ldb %}
<!--googleoff: all-->
<div class="section" id="ldb-{{ entity.identifier_scheme }}-{{ entity.identifier_value }}">
  <div class="header">
    <h2>{{ entity.title }} ({% if board %}{% trans board %}{% else %}{% trans "departures" %}{% endif %}) - {{ entity.metadata.ldb.generatedAt|localize_utc|date:"H:i:s" }}</h2>
  </div>
  
  {% if entity.metadata.ldb.nrccMessages.message %}
  <ul class="content-list">
    {% for message in entity.metadata.ldb.nrccMessages.message %}
      <li>{{ message|sanitize_html }}</li>
    {% endfor %}
  </ul>
  {% endif %}

  <table class="content">
    <thead>
      <tr>
        <th>
            {% ifequal board "arrivals" %}
                {% trans "Origin" %}
            {% else %}
                {% trans "Destination" %}
            {% endifequal %}
	</th>
        {% if entity.metadata.ldb.platformAvailable %}
        <th>{% trans "Plat." %}</th>
        {% endif %}
        <th>{% trans "Scheduled" %}</th>
        <th>{% trans "Expected" %}</th>
      </tr>
    </thead>
    <tbody>
      {% if entity.metadata.ldb.error %}
        <tr>
          <td colspan="{% if entity.metadata.ldb.platformAvailable %}4{% else %}3{% endif %}">
            <p>{% trans "There is currently a problem retrieving live departure information from the National Rail web site." %}</p>
            <p>{% blocktrans with entity.identifiers.crs as crs %}Departure information may still be accessed<a href="http://pda.ojp.nationalrail.co.uk/en/pj/ldbboard/dep/{{ crs }}">directly from their web site</a>.{% endblocktrans %}</p>
          </td>
        </tr>
      {% else %}
        {% for service in entity.metadata.ldb.trainServices.service %}
          <tr{% if service.problems %} class="delayed-service"{% endif %}>
            <td>
              <a href="{{ entity.get_absolute_url }}service?id={{ service.serviceID|urlencode }}" class="subtle-link" rel="nofollow">
                {# This isn't that straight-forward - trains can split and go to multiple destinations #}
                {% ifequal board "arrivals" %}
                  {% for location in service.origin.location %}
                    {% if not forloop.first and not forloop.last %}, {% endif %}
                    {% if not forloop.first and forloop.last %} &amp; {% endif %}
                    {% if not forloop.first %}<br />{% endif %}
                    {{ location.locationName }}
                    {% if location.via %}<br /><small>{{ location.via }}</small>{% if not forloop.last %}<br />{% endif %}{% endif %}
                  {% endfor %}
                {% else %}
                  {% for location in service.destination.location %}
                    {% if not forloop.first and not forloop.last %}, {% endif %}
                    {% if not forloop.first and forloop.last %} &amp; {% endif %}
                    {% if not forloop.first %}<br />{% endif %}
                    {{ location.locationName }}
                    {% if location.via %}<br /><small>{{ location.via }}</small>{% if not forloop.last %}<br />{% endif %}{% endif %}
                  {% endfor %}
                {% endifequal %}
                {% if service.isCircularRoute %}<br /><small>({% trans "Circular Route" %})</small>{% endif %}</a>
            </td>
            {% if entity.metadata.ldb.platformAvailable %} 
            <td>{{ service.platform }}</td>
            {% endif %}
            {% ifequal board "arrivals" %}
              <td>{{ service.sta }}</td>
              <td>{{ service.eta }}</td>
            {% else %}
              <td>{{ service.std }}</td>
              <td>{{ service.etd }}</td>
            {% endifequal %}
          </tr>
        {% empty %}
          <tr>
            <td colspan="{% if entity.metadata.ldb.platformAvailable %}4{% else %}3{% endif %}">
                {% ifequal board "arrivals" %}
                    {% trans "There are currently no scheduled arrivals." %}
                {% else %}
                    {% trans "There are currently no scheduled departures." %}
                {% endifequal%}
	    </td>
          </tr>
        {% endfor %}
      {% endif %}
    </tbody>
  </table>
  <div class="note powered-by">
    {% for attribution in attributions %}
      <a href="{{ attribution.url }}">
	  <small>{% trans "For more information" %}</small><br>
	  <img src="{{ attribution.picture }}" alt="{{ attribution.title }}" />
      </a>
    {% endfor %}
  </div>
  <ul class="link-list">
    {% if board %}
      {% ifequal board "departures" %}
        <li><a class="ldb-board" href="?board=arrivals">{% trans "View arrivals board" %}</a></li>
      {% else %}
        <li><a class="ldb-board" href="?board=departures">{% trans "View departures board" %}</a></li>
      {% endifequal %}
    {% else %}
      <li><a class="ldb-board" href="?board=arrivals">{% trans "View arrivals board" %}</a></li>
    {% endif %}
  </ul>
</div>
<!--googleon: all-->
{% endif %}
