{% extends 'layouts/base.html' %}
{% load i18n %}
{% load static %}

{% block content %}
  {% include 'header.html' %}
  <main id="main-content">
    {% include 'partials/notifications/notifications_block.html' %}
    <section>
      <div>
        {% include 'organizations/organization_page_tabs.html' with view='organization_detail' %}
        <h1>{{ organization.name }}</h1>
        {% include 'partials/organization_properties_table.html' %}
        {% with organization.name as name %}
          <div class="horizontal-view">
            {% if perms.tools.can_change_organization %}
              {% if miauw_api_enabled %}
                <a href="{% url 'organization_edit' organization.id %}" class="button">
                  {% blocktranslate %}Edit {{ name }}{% endblocktranslate %}
                </a>
              {% endif %}
            {% endif %}
            {% if perms.tools.can_switch_organization %}
              <a href="{% url 'switch_client' %}?organization_id={{ organization.id }}"
                 class="button ghost">{% blocktranslate %}Use KAT as {{ name }}{% endblocktranslate %}</a>
            {% endif %}
          </div>
        {% endwith %}
      </div>
    </section>
    {% if miauw_api_enabled %}
      <section>
        <div>
          <table>
            <thead>
              <tr>
                <th>{% translate 'Member name' %}</th>
                <th>{% translate 'Signal username' %}</th>
                <th colspan="3">{% translate 'Actions' %}</th>
              </tr>
            </thead>
            <tbody>
              {% for member in organization_members %}
                <tr>
                  <td>{{ member.member_name }}</td>
                  <td>{{ member.signal_username|default:"-" }}</td>
                  {% if actions_allowed.signal_group_add_member and member.signal_username %}
                    {% if member.is_in_signal_group %}
                      <td class="confirmation">{% translate 'Added to group.' %}</td>
                    {% else %}
                      <td>
                        <div>
                          {% translate 'Add to signal group' as text %}
                          {% include 'partials/form/single_action_form.html' with btn_text=text action='signal_group_add_member' key='signal_username' value=member.signal_username %}
                        </div>
                      </td>
                    {% endif %}
                  {% else %}
                    <td class="warning">{% translate "Can't add member to signal group" %}</td>
                  {% endif %}
                  <td>
                    <a href="{% url 'organization_member_edit' member.id %}">{% translate 'Edit' %}</a>
                  </td>
                </tr>
              {% endfor %}
            </tbody>
          </table>
        </div>
      </section>
    {% endif %}
  </main>
{% endblock %}

{% block html_at_end_body %}
  {{ block.super }}
  <script src="{% static '/js/checkboxToggler.js' %}" nonce="{{ request.csp_nonce }}"></script>
{% endblock %}
