<%# locals: { research_outputs, sections  } %>
<% research_outputs.each do |research_output| %>
  <% 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 %>
  <% research_output_fragment = research_output.json_fragment %>

  <% if !research_output_default_and_alone && 
        show_research_output_content %>
    <div class="research-output">
      <h2><%= research_output_fragment.data['title'] %> : <%= research_output_fragment.data['description'] %></h2>
  <% end %>
    <% sections.each do |section| %>
      <% section_has_common_answers = research_output.get_main().has_common_answers?(section[:id]) %>
      <% if @show_sections_questions %>
        <br>
        <h3><%= section[:title] %></h3>
        <br>
      <% end %>
      <% section[: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 : [] %>
        <% fragment = answer.present? ? answer.madmp_fragment : nil %>
        <%  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 %>
              <%# case where Question has options %>
              <% if options.any? %>
                <ul>
                <% options.each do |opt| %>
                  <li><%= opt.text %></li>
                <% end %>
                </ul>
              <% end %>
              <% 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>
              <% elsif question[:format].structured? && fragment.present? %>
                <%= render partial: 'shared/export/display_madmp_fragment', 
                            locals: {
                                fragment: fragment,
                                schema: fragment.madmp_schema,
                                classname: fragment.classname
                            } %>
              <%# case for displaying comments OR text %>
              <% elsif !blank %>
                <%= sanitize answer.text %>
                <br>
              <% else %>
                <br>
                <p><%= _('Question not answered.') -%></p>
                <br><br>
                <br />
              <% end %>
              <br />
            <% end %>
          </div>
        <% end %>
      <% end %> <!-- questions.each -->

    <% end %>

  <% if !research_output_default_and_alone && 
        show_research_output_content %>
  </div> <!-- .research_output -->
  <% end %>

<% end %>