<div class="row">
  <div class="col-md-12">
    <% if template_hash[:template][:phases].present? && template_hash[:template][:phases].length > 1 %>
      <div id="sections-accordion-controls">
        <div class="accordion-controls" data-parent="phases_accordion">
          <a href="#" data-toggle-direction="show"><%= _('expand all') %></a>
          <span>|</span>
          <a href="#" data-toggle-direction="hide"><%= _('collapse all') %></a>
        </div>
      </div>
    <% end %>
  </div>
</div>
<div class="row">
  <div class="col-md-12">
    <div class="panel-group" id="phases_accordion" role="tablist">
      <!-- If template has phases-->
      <% if template_hash[:template][:phases].present? %>
        <% i = 0 %>
        <% template_hash[:template][:phases].each do |phase_no, phase_hash| %>
          <% phase = phase_hash[:data] %>
            <div class="panel panel-default">
              <div class="heading-button" role="button" data-toggle="collapse"
                   data-parent="phases_accordion"
                   href="#collapsePhase<%= phase.id %>"
                   aria-expanded="<%= i == 0 ? 'true' : 'false' %>"
                   aria-controls="#collapsePhase<%= phase.id %>">
                   
                <div class="panel-heading" role="tab" id="<%= "headingPhase#{phase.id}" %>">
                  <div class="panel-title pull-left">
                    <%= phase.title %>
                  </div>
                  <div class="pull-right">
                    <i class="fa fa-plus pull-right" aria-hidden="true"></i>
                  </div>
                  <div class="clearfix"></div>
                </div>
              </div>
              <div id="<%= "collapsePhase#{phase.id}" %>" class="panel-collapse collapse<%= i == 0 ? 'in' : '' %>" role="tabpanel" aria-labelledby="<%= "headingPhase#{phase.id}" %>"<%= i == 0 ? 'aria-expanded="true"' : '' %>>
                <div class="panel-body">
                  <%= render partial: 'org_admin/templates/show_phases_sections', locals: { phase: phase, phase_hash: phase_hash, template: template, current: current } %>
                </div>
              </div>
            </div>
            <% i += 1 %>
        <% end %>
      <% end %>
    </div>
  </div>
</div>