{% load i18n %}
{% load arrowfilter %}
<div class="row">
  <div class="col-md-4">
    <dl id="home_name_and_description">
      <dt>{% trans "System" %}:</dt>
      <dd><i class="fa fa-{{ os_type_icon }}"></i> {{ instance.system }}</dd>
      <dt style="margin-top: 5px;">
        {% trans "Name" %}:
        {% if is_operator %}
          <a href="#" class="vm-details-home-edit-name-click"><i class="fa fa-pencil"></i></a>
        {% endif %}
      </dt>
      <dd>
        <div class="vm-details-home-edit-name-click">
          <small class="vm-details-home-edit-name">{{ instance.name }}</small>
        </div>
        <div class="js-hidden vm-details-home-rename-form-div" id="vm-details-home-rename">
          <form action="{{ op.rename.get_url }}" method="POST">
            {% csrf_token %}
            <div class="input-group">
              <input type="text" name="new_name" value="{{ instance.name }}" class="form-control input-sm"/>
              <span class="input-group-btn">
                <button type="submit" class="btn btn-success btn-sm vm-details-rename-submit
                  {% if not is_operator %}disabled{% endif %}" title="{% trans "Rename" %}">
                  <i class="fa fa-pencil"></i>
                </button>
              </span>
            </div>
          </form>
        </div>
      </dd>
      <dt style="margin-top: 5px;">
        {% trans "Description" %}:
        {% if is_operator %}
          <a href="#" class="vm-details-home-edit-description-click"><i class="fa fa-pencil"></i></a>
        {% endif %}
      </dt>
      <dd>
        {% csrf_token %}
        <div class="vm-details-home-edit-description-click">
          <div class="vm-details-home-edit-description">{{ instance.description|linebreaks }}</div>
        </div>
        <div id="vm-details-home-description" class="js-hidden">
          <form method="POST">
            <textarea name="new_description" class="form-control">{{ instance.description }}</textarea>
            <button type="submit" class="btn btn-xs btn-success vm-details-description-submit
              {% if not is_operator %}disabled{% endif %}">
              <i class="fa fa-pencil"></i> {% trans "Update" %}
            </button>
          </form>
        </div>
      </dd>
    </dl>

    <div id="home_expiration_and_lease">
      <h4>
        {% trans "Expiration" %}
{#        {% if instance.is_expiring %}<i class="fa fa-warning-sign text-danger"></i>{% endif %}#}
        <span id="vm-details-renew-op">
          {% with op=op.renew %}{% if op %}
            <a href="{{op.get_url}}" class="btn btn-xs operation operation-{{ op.op }}
              {% if op.disabled %}btn-default disabled{% else %}btn-{{op.effect}}{% endif %}">
              <i class="fa fa-{{op.icon}}"></i>
              {{op.name}}
            </a>
          {% endif %}{% endwith %}
        </span>
      </h4>
      <dl>
        <dt>{% trans "Suspended at:" %}</dt>
        <dd>
          <span title="{{ instance.time_of_suspend }}">
            <i class="fa fa-moon-o"></i> {{ instance.time_of_suspend|arrowfilter:LANGUAGE_CODE }}
          </span>
        </dd>
        <dt>{% trans "Destroyed at:" %}</dt>
        <dd>
          <span title="{{ instance.time_of_delete }}">
            <i class="fa fa-times"></i> {{ instance.time_of_delete|arrowfilter:LANGUAGE_CODE }}
          </span>
        </dd>
      </dl>
    </div>

    <div style="font-weight: bold;">{% trans "Tags" %}</div>
    <div id="vm-details-tags" style="margin-bottom: 20px;">
      <div id="vm-details-tags-list">
        {% if instance.tags.all %}
          {% for t in instance.tags.all %}
            <div class="label label-primary label-tag" style="display: inline-block">
              {{ t }}
              {% if is_operator %}
                <a href="#" class="vm-details-remove-tag"><i class="fa fa-times"></i></a>
              {% endif %}
            </div>
          {% endfor %}
        {% else %}
          <small>{% trans "No tag added." %}</small>
        {% endif %}
      </div>
      <form action="" method="POST">
        {% csrf_token %}
        <div class="input-group" id="vm-details-tags-form">
          <input type="text" class="form-control input-sm input-tags" name="new_tag" id="vm-details-tags-input"/>
          <!--<div class="input-group-addon">
            <i class="fa fa-question"></i>
          </div>-->
          <div class="input-group-btn">
            <input type="submit" class="btn btn-default btn-sm input-tags
            {% if not is_operator %}disabled{% endif %}" value="{% trans "Add tag" %}"/>
          </div>
        </div>
      </form>
    </div><!-- id:vm-details-tags -->
    {% if request.user.is_superuser %}
    <dl>
      <dt>{% trans "Node" %}:</dt>
      <dd>
        {% if instance.node %}
          <a href="{{ instance.node.get_absolute_url }}">
            {{ instance.node.name }}
          </a>
        {% else %}
          -
        {% endif %}
      </dd>
    {% endif %}
    </dl>
    <dl>
      <dt>{% trans "Template" %}:</dt>
      <dd>
        {% if instance.template %}
          {% if can_link_template %}
          <a href="{{ instance.template.get_absolute_url }}">
            {{ instance.template.name }}
          </a>
          {% else %}
            {{ instance.template.name }}
          {% endif %}
        {% else %}
          -
        {% endif %}
      </dd>
    </dl>

    {% if op.mount_store %}
      <dl>
        <dt>{% trans "Store" %}</dt>
        <dd>{{ op.mount_store.description }}</dd>
        <dd>
          <div class="operation-wrapper">
            <a href="{{ op.mount_store.get_url }}" class="btn btn-info btn-xs operation"
            {% if op.mount_store.disabled %}disabled{% endif %}>
              <i class="fa fa-{{op.mount_store.icon}}"></i>
              {{ op.mount_store.name }}
            </a>
          </div>
        </dd>
      </dl>
    {% endif %}
    {% if op.install_keys %}
      <dl>
        <dt>{% trans "SSH keys" %}</dt>
        <dd>{{ op.install_keys.description }}</dd>
        <dd>
          <div class="operation-wrapper">
            <a href="{{ op.install_keys.get_url }}" class="btn btn-info btn-xs operation"
            {% if op.install_keys.disabled %}disabled{% endif %}>
              <i class="fa fa-{{op.install_keys.icon}}"></i>
              {{ op.install_keys.name }}
            </a>
          </div>
        </dd>
      </dl>
    {% endif %}
  </div>
  <div class="col-md-8">
    {% if graphite_enabled %}
    <div class="text-center graph-buttons">
      {% include "dashboard/_graph-time-buttons.html" %}
    </div>
    <div class="graph-images text-center">
      <img src="{% url "dashboard.views.vm-graph" instance.pk "cpu" graph_time %}"
       alt="{% trans "CPU usage" %}"/>
      <img src="{% url "dashboard.views.vm-graph" instance.pk "memory" graph_time %}"
       alt="{% trans "Memory usage" %}"/>
      <img src="{% url "dashboard.views.vm-graph" instance.pk "network" graph_time %}"
       alt="{% trans "Network usage" %}"/>
    </div>
    {% endif %}
  </div>
</div>
