{% extends "base.html" %}

{% block content %}

  <h4 style="text-align: center;">Cluster/SSDP</h4>
  {% if not fhdhr.config.dict["fhdhr"]["discovery_address"] %}
    <p style="text-align: center;">Discovery Address must be set for Cluster/SSDP</p>
  {% else %}

    <div style="text-align: center;">
      <button onclick="location.href='/api/cluster?method=scan&redirect=/cluster'" type="button">Force Scan</button>
      <button onclick="location.href='/api/cluster?method=alive&redirect=/cluster'" type="button">Send Alive</button>
      <button onclick="location.href='/api/cluster?method=disconnect&redirect=/cluster'" type="button">Disconnect</button>
    </div>
    <br>

    <div class="container">
      <table class="table-medium center action-col">
        <tbody>
          <tr>
            <th>Name</th>
            <th>Location</th>
            <th>Joined</th>
            <th>Options</th>
          </tr>

          {% for location in locations_list %}
            <tr>
              <td>{{ location["name"] }}</td>
              <td>{{ location["location"] }}</td>
              <td>{{ location["joined"] }}</td>
              <td>
                {% if location["joined"] in ["True", "False"] %}
                  <button onclick="location.href='{{ location["location"] }}'" type="button">Visit</button>
                {% endif %}
                {% if location["joined"] == "True" %}
                  <button onclick="location.href='/api/cluster?method=del&location={{ location["url_query"] }}&redirect=/cluster'" type="button">Remove</button>
                {% elif location["joined"] == "False" %}
                  <button onclick="location.href='/api/cluster?method=add&location={{ location["url_query"] }}&redirect=/cluster'" type="button">Add</button>
                {% endif %}
                </td>
              </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  {% endif %}

{% endblock %}
