<div class="permissions-list">
  {% for perm in current_perms.clone() %}
  {{ perm | safe }}
  {% endfor %}
  <button
    class="button button--secondary button--small"
    popovertarget="permissions-editor-{{ target }}"
    popovertargetaction="toggle"
    type="button"
  >
    Edit
  </button>
</div>
<dialog
  class="dialog padded padded--lg"
  id="permissions-editor-{{ target }}"
  popover="auto"
>
  <form action="{{ update_endpoint }}" method="post">
    <table class="table">
      <thead>
        <tr>
          <th scope="col">Table</th>
          <th scope="col">Reader</th>
          <th scope="col">Writer</th>
          {% if include_owner %}
          <th scope="col">Owner</th>
          {% endif %}
        </tr>
      </thead>
      <tbody>
        {% for rel in all_rels %}
        <tr>
          <td>{{ rel.relname }}</td>
          <td style="text-align: center;">
            <input
              type="checkbox"
              name="{{ rel.oid.0 }}"
              value="reader"
              {%- if current_perms.contains(&(
                RelPermissionKind::Reader,
                rel.relname.clone(),
                rel.oid,
              ).into()) %}
              checked="true"
              {%- endif %}
            >
          </td>
          <td style="text-align: center;">
            <input
              type="checkbox"
              name="{{ rel.oid.0 }}"
              value="writer"
              {%- if current_perms.contains(&(
                RelPermissionKind::Writer,
                rel.relname.clone(),
                rel.oid,
              ).into()) %}
              checked="true"
              {%- endif %}
            >
          </td>
          {% if include_owner %}
          <td style="text-align: center;">
            <input
              type="checkbox"
              name="{{ rel.oid.0 }}"
              value="owner"
              {%- if current_perms.contains(&(
                RelPermissionKind::Owner,
                rel.relname.clone(),
                rel.oid,
              ).into()) %}
              checked="true"
              {%- endif %}
            >
          </td>
          {% endif %}
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% for (k, v) in hidden_inputs %}
    <input type="hidden" name="{{ k }}" value="{{ v }}">
    {% endfor %}
    <button
      class="button button--primary"
      style="margin-top: 16px;"
      type="submit"
    >
      Save
    </button>
  </form>
</dialog>
