{% extends 'tom_common/base.html' %}
{% load comments bootstrap4 tom_common_extras targets_extras observation_extras dataproduct_extras static cache tom_education_extras %}
{% block title %}Target {{ object.name }}{% endblock %}
{% block additional_css %}
<link rel="stylesheet" href="{% static 'tom_targets/css/main.css' %}">
<link rel="stylesheet" href="{% static 'tom_education/css/targets.css' %}">
{% endblock %}
{% block content %}
<h2>{{ object.name }} details
  {% if object.extra_fields.active %}
  <span class="badge badge-pill badge-info">Active</span>
  {% else %}
  <span class="badge badge-pill badge-secondary">Inactive</span>
  {% endif %}
  </h2>
<div class="row">
  <div class="col-md-8">
    <div class="card">
     <div class="collapse" id="collapseExample">
        <div class="card-body">
          <div class="row" style="font-size:80%;">
            <div class="col">
              <a href="{% url 'tom_education:target_update' pk=target.id %}" title="Update target" class="btn  btn-outline-primary">Update Target</a>
              <a href="{% url 'tom_targets:delete' pk=target.id %}" title="Delete target" class="btn  btn-outline-danger">Delete Target</a>
              <dl class="row">
                {% for key, value in target.as_dict.items %}
                {% if value and key != 'name' %}
                <dt class="col-sm-6">{% verbose_name target key %}</dt>
                <dd class="col-sm-6">{{ value|truncate_number }}</dd>
                {% endif %}
                {% if key == 'ra' %}
                  <dt class="col-sm-6">&nbsp;</dt>
                  <dd class="col-sm-6">{{ value|deg_to_sexigesimal:"hms" }}</dd>
                {% endif%}
                {% if key == 'dec' %}
                  <dt class="col-sm-6">&nbsp;</dt>
                  <dd class="col-sm-6">{{ value|deg_to_sexigesimal:"dms" }}</dd>
                {% endif%}
                {% endfor %}
              </dl>

              </div>
            <div class="col">
              <dl class="row">
              {% for key, value in target.extra_fields.items %}
                {% if key in display_extras %}
                  <dt class="col-sm-6">{{ key }}</dt>
                  <dd class="col-sm-6">{{ value }}</dd>
                {% endif %}
              {% endfor %}
              </dl>
              {% if target.tags.items %}
              <h4>Tags</h4>
              <dl class="row">
              {% for key, value in target.tags.items %}
                <dt class="col-sm-6">{{ key }}</dt>
                <dd class="col-sm-6">{{ value }}</dd>
              {% endfor %}
              </dl>
              {% endif %}
              </div>
          </div>
        </div>
      </div>
    </div>
    {% dataproduct_other_for_target object %}
    {% dataproduct_thumbs_for_target object %}
  </div>

  <div class="col-md-4">
    <div class="btn-group-vertical">
      <a href="{% url 'tom_observations:create' facility='LCO' %}?target_id={{ object.id }}" class="btn  btn-outline-primary">Observe</a>
      <a class="btn btn-outline-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">Target Info</a>
      <a class="btn btn-outline-primary" href="{% url 'tom_education:target_data' object.pk %}">Data</a>
       <a href="{% url 'targets:detail' pk=target.id %}?update_status=True" title="Update status of observations for target" class="btn btn-outline-primary">Update Observations Status</a>
     </div>
    <h4>Observations</h4>
    <table class="table table-striped">
  <thead><tr><th>Status</th><th>Scheduled</th></tr></thead>
  <tbody>
  {% for observation in object.observationrecord_set.all %}
    <tr>
      <td>{% status_icon observation.status %}</td>
      <td><a href="{% url 'tom_observations:detail' observation.id %}">
        {% if observation.scheduled_start %}
        {{ observation.scheduled_start }}
        {% else %}
        Pending
        {% endif %}
      </a></td>
    </tr>
  {% endfor %}
</table>
  </div>
</div>

{% endblock %}
