{% extends "base.html" %}
{% block title %}{{ super() }} stac/{{ data['path'] }} {% endblock %}
{% block crumbs %}{{ super() }}
/ <a href="{{ config['server']['url'] }}/stac">SpatioTemporal Asset Catalog</a>
{% for link in get_breadcrumbs(data['path']) %}
/ <a class="crumbs-path" href="{{config['server']['url'] }}/stac/{{ link['href'] }}">{{ link['title'] }}</a>
{% endfor %}
{% endblock %}

{% block extrahead %}
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"/>
    <script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
{% endblock %}

{% block body %}
    <section id="item">
      <div class="row">
        <div class="col-sm">
          <h2>Item {{ data['id'] }}</h2>
        </div>
      </div>
      <div class="row">
        <div class="col-md-6 col-sm-12">
          <div class="row">
            <div class="col-sm-12">
              <div id="items-map"></div>
              <div id="assets">
                <h4>Assets</h4>
                <table class="striped">
                  <thead>
                    <tr>
                      <th>URL</th>
                    </tr>
                  </thead>
                  <tbody>
                  {% for k, link in data['assets'].items() %}
                  <tr itemprop="dataset" itemscope itemtype="https://schema.org/Dataset">
                    <td data-label="name">
                      <meta itemprop="url" content="{{ link['href'] }}"/>
                      <a title="{{ link['href'] }}" href="{{ link['href'] }}">
                      <span itemprop="name">{{ link['href'] | get_path_basename }}</span></a>
                    </td>
                  </tr>
                  {% endfor %}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
        <div class="col-md-6 col-sm-12">
            <table class="striped">
              <thead>
              <tr>
                <th>Property</th>
                <th>Value</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>id</td>
                <td>{{ data.id }}</td>
              </tr>
              {% for k, v in data['properties'].items() %}
              <tr>
                <td>{{ k }}</td>
                {% if k == 'links' %}
                <td>
                    <ul>
                        {% for l in v %}
                        <li><a href="{{ l['href'] }}">{{ l['title'] }}</a></li>
                        {% endfor %}
                    </ul>
                </td>
                {% else %}
                  <td>{{ v }}</td>
                {% endif %}
              </tr>
              {% endfor %}
            </tbody>
            </table>
        </div>
     </div>
      </tbody>
      </div>
    </section>
{% endblock %}

{% block extrafoot %}
    <script>
    //var map = L.map('items-map').setView([{{ 45 }}, {{ -75 }}], 2);
    var map = L.map('items-map').setView([{{ 0 }}, {{ 0 }}], 1);
    map.addLayer(new L.TileLayer(
        '{{ config['server']['map']['url'] }}', {
            maxZoom: 18,
            attribution: '{{ config['server']['map']['attribution'] }}'
        }
    ));
    var geojson_data = {{ data |to_json }};
    var items = new L.GeoJSON(geojson_data);

    map.addLayer(items);
    map.fitBounds(items.getBounds(), {maxZoom: 10});
    </script>
{% endblock %}
