{% load i18n %}
{% load l10n %}
{% load extratags %}


<div class="container">
  <div class="row">
    <div class="col-md-9">
      {% with date=map.submission_time|date:"DATETIME_FORMAT" %}
      {% blocktrans %}Request submitted: {{ date }}{% endblocktrans %}
      {% endwith %}
      <br />
      {% if map.is_rendering or map.is_done%}
      {% with date=map.startofrendering_time|date:"DATETIME_FORMAT" duration=map.submission_time|timesince:map.startofrendering_time %}
      {% blocktrans %}Rendering started at {{ date }} {% endblocktrans %}
      {% blocktrans %}after {{duration}} in the queue{% endblocktrans %}
      {% endwith %}
      <br />
      {% endif %}
      {% if map.is_done or map.is_obsolete %}
      {% with date=map.endofrendering_time|date:"DATETIME_FORMAT" duration=map.startofrendering_time|timesince:map.endofrendering_time %}
      {% blocktrans %}Rendering completed at {{ date }} {% endblocktrans %}
      {% blocktrans %}after {{duration}} {% endblocktrans %}
      {% endwith %}
      <br />
      {% endif %}
      {% if map.is_cancelled %}
      {% with map.endofrendering_time|date:"DATETIME_FORMAT" as date %}
      {% blocktrans %}Rendering cancelled: {{ date }}{% endblocktrans %}
      {% endwith %}
      <br />
      {% endif %}
      {{ map.status|job_status_to_str:map.resultmsg }}
      <br />

      <div style="height: 2em"></div>

    {% if map.needs_waiting %}
      <div id="queue-progress" class="progress progress-striped active">
        <div class="bar" style="width: {{ progress }}%; text-align: right; padding-right: 10px;">
          {{ map.current_position_in_queue }} / {{ queue_size }}
        </div>
      </div>
    {% endif %}


    {% if map.is_waiting %}
      <a class="btn btn-large disabled tooltipped"
         data-placement="right"
         data-original-title="{% with map.submission_time|timesince as date %}
           {% blocktrans %}Pending, submitted {{ date }} ago{% endblocktrans %}
         {% endwith %}">
        <i class="fa fa-hourglas"></i> {% trans "Pending..." %}
      </a>

      {% ifequal nonce map.nonce %}
      <div style="height: 2em"></div>
      <form method="post" action="{% url "cancel" %}">
        <input type="hidden" name="id" value="{{ map.id }}" />
        <input type="hidden" name="nonce" value="{{ map.nonce }}" />
        <button type="submit" class="btn btn-large btn-danger tooltipped"
                data-placement="right"
                data-original-title="
                  {% blocktrans with map.current_position_in_queue as pos %}Cancel this queued request (position {{ pos }} in the queue){% endblocktrans %}">
          {% blocktrans %}<i class="fa fa-times"></i> Cancel{% endblocktrans %}
        </button>
      </form>

      {% endifequal %}
    {% endif %}

    {% if map.is_rendering %}
      <a class="btn btn-large disabled tooltipped"
         data-placement="right"
         data-original-title="
         {% with map.startofrendering_time|timesince:map.endofrendering_time as date %}
           {% blocktrans %}Rendering is in progress, started {{ date }} ago{% endblocktrans %}
         {% endwith %}">
        <i class="fa fa-repeat"></i> {% trans "Rendering..." %}
      </a>
    {% endif %}

    {% if not map.needs_waiting %}
      <form method="post" action="{% url "recreate" %}">
        <input type="hidden" name="id" value="{{ map.id }}" />
	<button class="btn btn-primary tooltipped" align="right"
                data-original-title="{% trans "Recreate map" %}"
		type="submit" {% if map.needs_waiting or not map.can_recreate %}disabled="disabled"{% endif %}>
          {% trans "Recreate" %} <i class="fa fa-repeat"></i>
	</button>
      </form>
      <p></p>
      <form method="post" action="{% url "reedit" %}">
        <input type="hidden" name="id" value="{{ map.id }}" />
	<button class="btn btn-primary tooltipped" align="right"
                data-original-title="{% trans "Reedit map" %}"
		type="submit" {% if map.needs_waiting or not map.can_recreate %}disabled="disabled"{% endif %}>
          {% trans "Reedit" %} <i class="fa fa-edit"></i>
	</button>
      </form>
    {% endif %}

    {% if map.is_done %}
      {% if map.has_output_files %}
        <div style="height: 2em"></div>
	<div class="card card-default">
	  <div class="card-header">{% trans "Downloads" %}</div>
	  <div id="download-icons" class="card-body">

	    {% for format,file in map.output_files.maps.items %}
	    <a href="{{ file.0 }}" title="{{ file.1 }}" class="btn btn-default">
	      {% if format == "pdf" %}
	      <span class="fa fa-file-pdf-o fa-5x"></span>
	      {% elif format == "png" %}
	      <span class="fa fa-file-image-o fa-5x"></span>
	      {% elif format == "8bit.png" %}
	      <span class="fa fa-file-image-o fa-5x"></span>
	      {% elif format == "jpg" %}
	      <span class="fa fa-file-image-o fa-5x"></span>
	      {% elif format == "svgz"%}
	      <span class="fa fa-file-code-o fa-5x"></span>
	      {% else %}
	      <span class="fa fa-file-o fa-5x"></span>
	      {% endif %}
	      <br>{{format|upper}}
	      <br>({{file.2|filesizeformat}})
	    </a>
	    {% endfor %}

	    {% if map.output_files.indeces|length %}
            {% for format,file in map.output_files.indeces.items %}
	    <a href="{{ file.0 }}" title="{{ file.1 }}" class="btn btn-default">
	      <span class="fa fa-file-text-o fa-5x"></span>
	      <br>{{format|upper}}
	      <br>({{file.2|filesizeformat}})
	    </a>
	    {% endfor %}
	    {% endif %}
	  </div>
	</div>

      {% elif map.get_errorlog %}
      <a class="btn btn-large tooltipped"
         href="{{map.get_errorlog}}"
         target="_blank"
         data-placement="right"
         data-original-title="{% trans "Something went wrong while processing this job." %}">
        <i class="fa fa-ban"></i> {% trans "Error log" %}
      </a>
      {% else %}
      <a class="btn btn-large disabled tooltipped"
         data-placement="right"
         data-original-title="{% trans "The generated files are no longer available." %}">
        <i class="fa fa-ban"></i> {% trans "Download" %}
      </a>
      {% endif %}

    {% endif %}

    {% if map.needs_waiting %}
    <span class="refresh-time pull-right">{% blocktrans %}Updating in <span>{{ refresh }}</span>s...{% endblocktrans %}</span>
    {% endif %}
    </div>
    <div class="col-md-3">
    {% if map.get_thumbnail %}
    <img class="thumbnail" src="{{ map.get_thumbnail }}" />
    {% endif %}
    </div>

  </div>
</div>
