{% from "_macros.html" import icon %}
{#
  The share panel on a detail page.

  Sharing grants *reading*. Two people editing one note with no history and no
  merge is worse than the inconvenience of copying it, so there is no "can edit"
  here and the copy is deliberate rather than missing.

  Only the owner sees this at all: someone a thing was shared with cannot share
  it onward, which keeps "who can see this" answerable by asking one person.
#}
{% if is_owner and can_share %}
<section class="card">
  <h2 class="card__title">
    Shared with
    {% if shared_users or shared_groups %}
    <span class="badge badge--leaf">{{ shared_users|length + shared_groups|length }}</span>
    {% else %}
    <span class="badge">nobody</span>
    {% endif %}
  </h2>
  <p class="card__lede">
    They will be able to read this, and their models will find it. They cannot
    change it or share it on.
  </p>

  {% if groups %}
  <div class="field">
    <label class="field__label">Groups</label>
    <div class="checkbox-row">
      {% for group in groups %}
      <label class="checkbox">
        <input type="checkbox" name="share_group" value="{{ group.id }}"
               {{ 'checked' if group.id in shared_groups }}>
        <span>{{ group.name }}</span>
      </label>
      {% endfor %}
    </div>
  </div>
  {% endif %}

  {% if people %}
  <div class="field">
    <label class="field__label">People</label>
    <div class="checkbox-row">
      {% for person in people %}
      <label class="checkbox">
        <input type="checkbox" name="share_user" value="{{ person.id }}"
               {{ 'checked' if person.id in shared_users }}>
        <span>{{ person.name }}</span>
      </label>
      {% endfor %}
    </div>
  </div>
  {% endif %}

  {% if not groups and not people %}
  <p class="muted text-sm">There is nobody else on this instance yet.</p>
  {% endif %}
</section>
{% elif not is_owner %}
<div class="alert">
  {{ icon("users", "alert__icon") }}
  <span>Shared with you. You can read this but not change it.</span>
</div>
{% endif %}
