<%# locals: { research_outputs, questions, section  } %>
<% research_outputs.each do |research_output| %>
  <% section_has_common_answers = research_output.get_main().has_common_answers?(section[:id]) %>
  <% show_research_output_content = @show_unanswered || (!@show_unanswered && !research_output.get_answers_for_section(section[:id]).empty?) %>
  <% research_output_default_and_alone = research_output.is_default && research_outputs.length == 1 %>

  <% if !research_output_default_and_alone && 
        !section_has_common_answers && 
        show_research_output_content %>
  <div class="research-output">
    <h3><%= research_output[:fullname] %></h3>
  <% end %>
  <% questions.each do |question| %>
    <% answer = section_has_common_answers ? 
          @plan.answer(question[:id], false, research_output.get_main().id) : 
          @plan.answer(question[:id], false, research_output[:id]) %>
    <% blank = answer.present? ? answer.is_blank? : true %>
    <% options = answer.present? ? answer.question_options : [] %>

    <%  unless @show_unanswered == false && blank  %>
      <div class="question">
        <% if !@public_plan && @show_sections_questions%>
        <p>
          <%# Hack: for DOCX export - otherwise, bold highlighting of question inconsistent. %>
          <% if local_assigns[:export_format] && export_format == 'docx' %>
            <strong><h4><%=  sanitize question[:text].to_s, scrubber: TableFreeScrubber.new %></h4></strong>
          <% else %>
            <div class="bold"><h4><%=  sanitize question[:text].to_s, scrubber: TableFreeScrubber.new %></h4></div>
          <% end %>
          <br>
        </p>
        <br>
        <% end %>
        <%# case where question has not been answered sufficiently to display%>
        <% if @show_unanswered && (answer.blank? || (options.blank? && blank))%>
        <br>
        <p><%= _('Question not answered.') -%></p>
        <br><br>
        <br />
        <% else %>

        <%# case where Question has options %>
        <% if options.any? %>
          <ol>
          <% options.each do |opt| %>
            <li><%= opt.text %></li>
          <% end %>
          </ol>
        <% end %>
        <%# case for RDA answer display %>
        <% if question[:format].rda_metadata? && !blank %>
          <% ah = answer.answer_hash %>
          <% if ah['standards'].present? %>
          <ul>
            <% ah['standards'].each do |id, title| %>
            <li><%= title %></li>
            <% end %>
          </ul>
          <% end %>
          <p><%= sanitize ah['text'] %></p>
          <br>
        <%# case for displaying comments OR text %>
        <% elsif !blank %>
          <%= sanitize answer.text %>
          <br>
        <% end %>
        <br />
        <% end %>
      </div>
    <% end %>
  <% end %> <!-- questions.each -->

  <% if !section_has_common_answers && show_research_output_content %>
  </div> <!-- .research_output -->
  <% end %>
  <% if section_has_common_answers %>
  <% break %> <!-- break if is research output has common answers, only display the first -->
  <% end %>
<% end %><!-- research_outputs.each -->