<% if (@exchange_data.error?) %>
    <%= @exchange_data.error_message %>
<% end %>

<div id="results">

  <div id="result_info" class="results_container">
    <h3>Summary</h3>

    <div id="parameters">
      <ul>
        <li class="parameter">
          <span class="param_name">Operation: </span>
          <span class="param_value"><%= @operation %></span>
        </li>

        <li class="parameter">
          <span class="param_name">Time taken: </span>
          <span class="param_value"><%= @elapsed.to_s %>s</span>
        </li>

        <li class="parameter">
          <span class="param_name">Total number of 2-cycles: </span>
          <span class="param_value"><%= @exchange_data.total_two_cycles.to_s %></span>
        </li>

        <li class="parameter">
          <span class="param_name">Total number of  3-cycles: </span>
          <span class="param_value"><%= @exchange_data.total_three_cycles.to_s %></span>
        </li>
      </ul>
      <div class="clear_both"></div>
    </div>
  </div>

  <div class="clear_both"></div>

  <div id="exchanges" class="results_container">
    <h3>Detailed output</h3>

    <h4>Exchanges</h4>

    <div id="exchange_container">
      <% @exchange_data.exchanges.each do |exchange| %>
          <div class="exchange_data">
            <h5><%= exchange.description %></h5>

            <div class="exchange">
              <div class="pair odd">
                <div class="pair_label">exchanges:</div>
                <div class="pair_value">
                  <ul class="exchange_list">
                    <% exchange.cycles.each do |cycle_entry| %>
                        <li>
                        <a class="cycle" rel="#details<%= cycle_entry.id %>" href="#">[<span class="<%= cycle_entry.any_back_arcs? ? "color_backarc" : "" %>">
                             <%= cycle_entry.patients_as_string %>
                            </span>]</a>
                        </li>
                    <% end %>
                    </ul>
                    <div class="clear_both"></div>
                    </div>
            </div>
            <div class="clear_both"></div>
            <div class="pair even">
              <div class="pair_label">weight:</div>
              <div class="pair_value"><%= exchange.weight %> </div>
            </div>
            <div class="clear_both"></div>
            <div class="pair odd">
              <div class="pair_label">total transplants:</div>
              <div class="pair_value"><%= exchange.total_transplants %> </div>
            </div>
            <div class="clear_both"></div>
            <div class="pair even">
              <div class="pair_label">three-ways:</div>
              <div class="pair_value"><%= exchange.three_way_exchanges %> </div>
            </div>
            <div class="clear_both"></div>
            <div class="pair odd">
              <div class="pair_label">two-ways:</div>
              <div class="pair_value"><%= exchange.two_way_exchanges %>
              <%= "(#{exchange.effective_two_ways})" %></div>
            </div>
            <div class="clear_both"></div>
          </div>
          </div>
      <% end %>
    </div>

    <h4>All Cycles</h4>
    <div id="all_cycles_container">

       <% three_cycles = []; two_cycles = [];
          @exchange_data.all_cycles.keys.sort.each do |key|
			value = @exchange_data.all_cycles[key]
            if(value.patients.size == 2)
              two_cycles << value
            else
              three_cycles << value
            end
          end %>

        <h5>2 Cycles</h5>
        <div class="cycle_display">
          <% two_cycles.each do |cycle| %>
            <a class="cycle" rel="#details<%= cycle.id %>" href="#">[<%= cycle.patients_as_string %>]</a>
          <% end %>
        </div>

        <h5>3 Cycles</h5>
        <div class="cycle_display">
          <% three_cycles.each do |cycle| %>
            <a class="cycle" rel="#details<%= cycle.id %>" href="#">[<%= cycle.patients_as_string %>]</a>
          <% end %>
        </div>
    </div>
	
	<div id="details">	
	<% @exchange_data.all_cycles.each do |key,cycle_entry| %>
		<div class="cycle_details" id="details<%= cycle_entry.id %>">
			<div class="pair odd">
			  <div class="pair_label">id:</div>
			  <div class="pair_value">[<%= cycle_entry.id %>]</div>
			</div>
			<div class="pair even">
			  <div class="pair_label">cycle:</div>
			  <div class="pair_value">[<%= cycle_entry.patients_as_string %>]</div>
			</div>
			<div class="pair odd">
			  <div class="pair_label">patient(donor):</div>
			  <div class="pair_value"><%= cycle_entry.patients_with_donors_as_string %></div>
			</div>
			 <div class="pair even">
			  <div class="pair_label">back arcs:</div>
			  <div class="pair_value"><%= cycle_entry.back_arcs %></div>
			</div>
			<div class="pair odd">
			  <div class="pair_label">weight:</div>
			  <div class="pair_value"><%= cycle_entry.weight %></div>
			</div>
			<div class="pair even">
			  <div class="pair_label">actual back arcs:</div>
			  <div class="pair_value"><%= cycle_entry.patient_back_arcs_as_string(@exchange_data.all_cycles) %></div>
			</div>
		  </div>
	<% end %>
	</div>
    
</div>
</div>
