{% assign group = Group %}
{% assign groupId = 'Global' | PageParameter:'GroupId' | ToInteger %}
{% if groupId > 0 %}
    {% assign group = groupId | GroupById %}
{% else %}
    <div class="alert alert-warning">No group context found.</div>
    {% return %}
{% endif %}
{% assign gl = group.GroupLocations | Sort:'Order,Location.Name' %}
{% if gl == empty %}
    {% return %}
{% endif %}
{% assign accId = 'gl-acc-' | Append: group.Id %}
<div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title">Meeting Details</h3>
  </div>
  <div class="panel-body">
    <div class="panel-group" id="{{ accId }}" role="tablist" aria-multiselectable="true">
      {% for x in gl %}
        {% assign loc = x.Location %}
        {% assign schedules = x.Schedules | Sort:'Name' %}
        {% assign scount = schedules | Size %}
        {% assign cid = 'collapse-' | Append: x.Id %}
        {% assign hid = 'heading-' | Append: x.Id %}
        <div class="panel panel-default">
          <div class="panel-heading" role="tab" id="{{ hid }}" data-toggle="collapse" data-parent="#{{ accId }}" data-target="#{{ cid }}">
            <h4 class="panel-title" style="margin:0;">
              {% if loc and loc.Id %}
              {% comment %}Make sure to adjust this path to the relevant one for your environment{% endcomment %}
                <a href="https://rock.yourchurch.org/admin/checkin/named-locations?LocationId={{ loc.Id }}" title="Open location" onclick="event.stopPropagation();" class="text-muted">
                  <i class="fa fa-map-marker"></i>
                </a>&nbsp;
              {% endif %}
              <a class="collapsed" role="button" href="#{{ cid }}" aria-expanded="false" aria-controls="{{ cid }}">
                {{ loc.Name }}
              </a>
              {% if scount > 0 %}
                <span class="small text-muted pull-right">{{ scount }} schedule{% if scount != 1 %}s{% endif %}</span>
              {% endif %}
            </h4>
          </div>
          <div id="{{ cid }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="{{ hid }}">
            <div class="panel-body">
              {% if loc.FormattedAddress %}
                <div class="small text-muted">{{ loc.FormattedAddress }}</div>
              {% endif %}
              {% if schedules != empty %}
                <ul class="list-unstyled">
                  {% for s in schedules %}
                    {% comment %}Make sure to adjust this path to the relevant one for your environment{% endcomment %}
                    <li><i class="fa fa-calendar-o"></i> <a href="https://rock.yourchurch.org/admin/checkin/schedules?ScheduleId={{ s.Id }}">{{ s.Name }}</a></li>
                  {% endfor %}
                </ul>
              {% else %}
                <div class="text-muted">No schedules linked to this location.</div>
              {% endif %}
            </div>
          </div>
        </div>
      {% endfor %}
    </div>
  </div>
</div>