<%# locals{ question, research_output, guidance_groups_by_theme } %>
<% parent_id = guidance_groups_by_theme.object_id %>
<div id="<%= parent_id %>" class="panel-group" role="tablist" aria-multiselectable="true">
  <% guidance_groups_by_theme.each_pair do |guidance_group, theme_hash| %>
    <% guidances_output = [] %>
    <%# Do not show expand/collapse all links if there is only one item in theme_hash %>
    <% if theme_hash.length > 1 %>
    <div id="guidance-accordion-controls">
      <div class="accordion-controls" data-parent="<%= parent_id %>">
        <a href="#" data-toggle-direction="show"><%= _('expand all') %></a>
          <span>|</span>
        <a href="#" data-toggle-direction="hide"><%= _('collapse all') %></a>
      </div>
    </div>
    <% end %>
    <% theme_hash.each_pair do |theme, guidances| %>
      <% question_guidance_id = "#{question.object_id}-#{guidances.object_id}-research-output-#{research_output.id}" %>
      <%# if guidances with this theme have not been output %>
      <% if (guidances.map(&:id) - guidances_output).any? %>
        <div class="panel panel-default">
          <div
            class="heading-button"
            role="button"
            data-toggle="collapse"
            href="<%= "##{question_guidance_id}" %>"
            aria-expanded="false"
            aria-controls="<%= "##{question_guidance_id}" %>">
            <div class="panel-heading" role="tab" id="<%= "panel-heading-#{question_guidance_id}" %>">
              <h2 class="panel-title">
                <%= theme.title %>
                <i class="fa fa-plus pull-right" aria-hidden="true"></i>
              </h2>
            </div>
          </div>
          <div
            id="<%= "#{question_guidance_id}" %>"
            class="panel-collapse collapse"
            role="tabpanel"
            aria-labelledby="<%= "panel-heading-#{question_guidance_id}" %>">
            <div class="panel-body">
              <% multiple = false %>
              <% guidances.each do |guidance| %>
                <% if multiple %>
                  <hr>
                <% end %>
                <p>
                  <% unless guidances_output.include?(guidance.id) %>
                    <div class="display-readonly-textarea-content">
                      <%= sanitize(guidance.text) %>
                    </div>
                    <% guidances_output << guidance.id %>
                    <% multiple = true %>
                  <% end %>
                </p>
              <% end %>
            </div>
          </div>
        </div>
      <% end %>
    <% end %>
  <% end %>
</div>
