{% load i18n %}
<div class="panel panel-primary">
  <div class="panel-heading">Hosts from {{ project.farm.name }} ({{ project.farm.source }})</div>
  <table class="table">
    <tr>
      <th>&nbsp;</th>
      <th>Name</th>
      <th>&nbsp;</th>
    {% if project.farm.editable %}
      <th>&nbsp;</th>
    {% endif %}
    </tr>
  {% for host in project.farm.host_set.all %}
    <tr>
      <td><input type="checkbox" value="{{ host.name }}:[0-9]*" v-model="selectedHosts"></td>
      <td><a href="{% url 'host-detail' host.name %}">{{ host.name }}</a></td>
      <td>
        <a
          @click="setSilenceDataset"
          class="btn btn-warning btn-xs"
          data-instance="{{host.name}}:[0-9]*"
          data-project="{{project.name}}"
          data-service="{{project.service.name}}"
          style="display: inline-block;"
        >{% trans "Silence" %}</a>
      </td>
      {% if project.farm.editable %}
      <td>
        <form method="post" action="{% url 'host-delete' host.id %}" onsubmit="return confirm('{% trans "Delete this host?" %}');">
          {% csrf_token %}
        <button name="delete" type="submit" class="btn btn-danger btn-xs">{% trans "Delete" %}</button>
        </form>
      </td>
      {% endif %}
    </tr>
  {% endfor %}
  </table>

  <div class="panel-footer">
    <a
      @click="silenceSelectedHosts"
      class="btn btn-warning"
      data-project="{{project.name}}"
      data-service="{{project.service.name}}"
      style="display: inline-block;"
      v-if="selectedHosts.length"
    >{% trans "Silence selected hosts" %}</a>
{% if project.farm %}
  {% if project.farm.editable %}
    <a href="{% url 'hosts-add' project.farm.id %}" class="btn btn-primary">
      {% trans "Register Hosts" %}
    </a>
    <a href="{% url 'farm-update' project.farm.id %}" class="btn btn-default">
      {% trans "Edit Farm" %}
    </a>
  {% else %}
    <form method="post" action="{% url 'farm-convert' project.farm.id %}" onsubmit="return confirm('Convert this farm to local?')" style="display: inline">
      {% csrf_token %}
      <input name="next" type="hidden" value="{{ request.get_full_path }}" />
      <button class="btn btn-warning">
        <span class="glyphicon glyphicon-cloud-download" aria-hidden="true"></span>
        {% trans "Convert to Local Farm" %}
      </button>
    </form>
    <form method="post" action="{% url 'farm-refresh' project.farm.id %}" style="display: inline">
      {% csrf_token %}
      <input name="next" type="hidden" value="{{ request.get_full_path }}" />
      <button type="submit" class="btn btn-warning">
        <span class="glyphicon glyphicon-cloud-download" aria-hidden="true"></span>
        {% trans "Sync Farm" %}
      </button>
    </form>
  {% endif %}
  <form method="post" action="{% url 'farm-unlink' project.id %}" onsubmit="return confirm('{% trans "Unlink this farm?" %}')" style="display: inline">
    {% csrf_token %}
    <button type="submit" class="btn btn-danger">
      {% if source.remote %}
        <span class="glyphicon glyphicon-cloud-download" aria-hidden="true"></span>
      {% endif %}
      {% trans "Unlink Farm" %}
    </button>
  </form>
{% else %}
    <a href="{% url 'farm-new' project.id %}" class="btn btn-primary">{% trans "Register Farm" %}</a>
{% for name, source in sources %}
    <a href="{% url 'farm-link' project.id name %}" class="btn btn-default">
      {% if source.remote %}
        <span class="glyphicon glyphicon-cloud-download" aria-hidden="true"></span>
      {% endif %}
      {% trans "Link Farm" %} {{ name }}
    </a>
{% endfor %}
{% endif %}
  </div>
</div>
