{% extends ctx.module + "/base.j2" %}
{% set title = "Channels" %}
{% set nav = [("Plug: " + plug.name, ctx.url_for("plug", name=plug.name))] %}

{% block body -%}
<div class="container">
  <div class="columns is-desktop">
    <div class="column">
      <h3 class="title">Public channels</h3>
      {%- if public is none %}
      <p>No support for retrieving a list of channels.</p>
      {%- elif not public %}
      <p>No channels available.</p>
      {%- else %}
      <table class="table is-hoverable">
        <tbody>
        {%- for channel, name in zipped(public, titles) %}
          <tr>
            <td>
              <a href="{{ ctx.url_for("channel", plug=plug.name, source=channel.source) }}">{{ channel.source }}</a>
            </td>
            <td>{% if name %}{{ name }}{% endif %}</td>
            <td>
              {% if channels[channel] %}
              {{ channels[channel] | join("<br>") }}
              {% else %}
              <a href="{{ ctx.url_for("plug", name=plug.name).with_query({"source": channel.source}) }}" class="button is-small is-success">
                <i class="fas fa-fw fa-plus"></i> Add
              </a>
              {% endif %}
            </td>
          </tr>
        {%- endfor %}
        </tbody>
      </table>
      {%- endif %}
    </div>
    <div class="column">
      <h3 class="title">Private channels</h3>
      {%- if private is none %}
      <p>No support for retrieving a list of channels.</p>
      {%- elif not private %}
      <p>No channels available.</p>
      {%- else %}
      <table class="table is-hoverable">
        <tbody>
        {%- for channel, users in zipped(private, users) %}
          <tr>
            <td>
              <a href="{{ ctx.url_for("channel", plug=plug.name, source=channel.source) }}">{{ channel.source }}</a>
            </td>
            <td>{% for user in users %}{% if not loop.first %}, {% endif %}{{ user.real_name or user.username }}{% endfor %}</td>
            <td>
              {% if channels[channel] %}
              {{ channels[channel] | join("<br>") }}
              {% else %}
              <a href="{{ ctx.url_for("plug", name=plug.name).with_query({"source": channel.source}) }}" class="button is-small is-success">
                <i class="fas fa-fw fa-plus"></i> Add
              </a>
              {% endif %}
            </td>
          </tr>
        {%- endfor %}
        </tbody>
      </table>
      {%- endif %}
    </div>
  </div>
</div>
{%- endblock %}
