<%# locals: { research_outputs, questions, section  } %>
<% questions.each do |question| %>
  <div class="question">
    <% question_displayed = false %>

    <% research_outputs.each do |research_output| %>
      <% section_has_common_answers = research_output.get_main().has_common_answers?(section[:id]) %>
      <% 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  %>

        <% if !@public_plan && @show_sections_questions && question_displayed == false %>
        <p>
          <%# Hack: for DOCX export - otherwise, bold highlighting of question inconsistent. %>
          <% if local_assigns[:export_format] && export_format == 'docx' %>
            <strong><h3><%=  sanitize question[:text].to_s, scrubber: TableFreeScrubber.new %></h3></strong>
          <% else %>
            <div class="bold"><h3><%=  sanitize question[:text].to_s, scrubber: TableFreeScrubber.new %></h3></div>
          <% end %>
          <br>
        </p>
        <br>
        <% end %>
        <% question_displayed = true %>

        <% if !section_has_common_answers %>
          <h4><%= research_output.fullname %></h4>
        <% end %>
        
        <%# case where question has not been answered sufficiently to display%>
        <% if @show_unanswered && (answer.blank? || (options.blank? && blank))%>
        <p>
          <br>
          <i><%= _('Question not answered.') -%></i>
          <br><br>
        </p>
        <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 %>
          <p>
            <%= sanitize answer.text %>
            <br>
          </p>
        <% end %>
        <br />
        <% end %>
      <% end %>
      <% if section_has_common_answers %>
        <% break %> <!-- break if is research output has common answers, only display the first -->
      <% end %>
    <% end %> <!-- research_outputs.each -->

  </div>
<% end %><!-- questions.each -->