<!-- Project title = default title is the template title plus date of creation -->
<div class="dmp_details_body">

  <!--
    we have two div for the plan details
    one is for editing and one is for viewing
    one is always hidden and we switch between them with javascript in application.js
  -->

  <!-- the editing div -->
  <div class="edit-plan-details <%= unless @editing then "project-hide" end %>">
      <!-- edit pro ject button -->
      <div class="div_left">
        <p>
        <%= raw _("Please fill in the basic project details below and click 'Update' to save")%>
        </p>
      </div>
      <div class="div_right">
        <a href='#' class='btn btn-primary show-edit-toggle'><%= _('Cancel') %></a> 
      </div>

      <div class="div_clear"> </div>

      <%= semantic_form_for @plan, :url => {:controller => :plans, :action => :update }, :html=>{:method=>:put} do |f| %>
        <%= f.inputs do %>
          <div class="dmp_details">

            <!-- If not first time login in or editing project details -->
            <table class="dmp_details_table">
              <tr>
                <td class="first"><%= _('Plan name') %></td>
                <td>
                  <%= f.text_field :title, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('If applying for funding, state the name exactly as in the grant proposal.') %>
                </td>
              </tr>
              <tr>
                <td class="first"><%= _('ID') %></td>
                <td>
                  <%= f.text_field :identifier, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('A pertinent ID as determined by the funder and/or institution.') %>
                </td>
              </tr>
              <tr>
                <td class="first"><%= _('Grant number') %></td>
                <td>
                  <%= f.text_field :grant_number, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('Grant reference number if applicable [POST-AWARD DMPs ONLY]') %>
                </td>
              </tr>
              <tr>
                <td class="first"><%= _('Principal Investigator/Researcher') %></td>
                <td>
                  <%= f.text_field :principal_investigator, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('Name of Principal Investigator(s) or main researcher(s) on the project.') %>
                </td>
              </tr>
              <tr>
                <td class="first"><%= _('Principal Investigator/Researcher ID') %></td>
                <td>
                  <%= f.text_field :principal_investigator_identifier, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('E.g ORCID http://orcid.org/.') %>
                </td>
              </tr>
              <tr>
                <td class="first"><%= _('Plan data contact') %></td>
                <td>
                  <%= f.text_field :data_contact, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => _('Name (if different to above), telephone and email contact details') %>
                </td>
              </tr>
              <tr>
                <td class="first"><%= _('Description') %></td>
                <td>
                  <%= f.text_area :description, { :rows => 7, :class => 'text_area has-tooltip', 'data-toggle' => "tooltip", 'data-html' => "true", 'title'=> _("<div class='tooltip_box'><h4>Questions to consider:</h4><ul><li>- What is the nature of your research project?</li><li>- What research questions are you addressing? </li><li>- For what purpose are the data being collected or created? </li></ul><h4>Guidance:</h4><p>Briefly summarise the type of study (or studies) to help others understand the purposes for which the data are being collected or created.</p></div>")} %>
                </td>
              </tr>
            </table>
          </div>
        <% end %>
        <!-- submit buttons -->
        <%= f.actions do %>
          <div class="move_2_right">
            <%= f.submit _('Save'), :class => 'btn btn-primary' %>
            <a href='#' class='btn btn-primary show-edit-toggle'><%= _('Cancel') %></a>
          </div>
        <%end%>
      <%end%>
  </div>


  <!-- the viewing div -->
  <div class="show-plan-details <%= if @editing then "project-hide" end %> ">
      <div class="div_left">
        <p> <%= _('This page gives you an overview of your plan. It tells what your plan is based on and gives an overview of the questions that you will be asked.')%> </p>
      </div>

      <!-- edit plan button -->
      <div class="div_right">
        <a href='#' class='btn btn-primary show-edit-toggle'><%= _('Edit plan details') %></a>
      </div>

      <!-- display plan details -->
      <div class="dmp_details">
        <table class="dmp_details_table">
          <tr>
            <td class="first"><%= _('Plan name') %></td>
            <td><%= @plan.title %></td>
          </tr>

          <tr>
            <td class="first"><%= _('ID') %></td>
            <td>
              <% if !@plan.identifier.nil? && @plan.identifier != "" then %>
                <%= @plan.identifier %>
              <%else%>
                -
              <%end%>
            </td>
          </tr>

          <tr>
            <td class="first"><%= _('Grant number') %></td>
            <td>
              <% if !@plan.grant_number.nil? && @plan.grant_number!= "" then %>
                <%= @plan.grant_number %>
              <%else%>
                -
              <%end%>
            </td>
          </tr>
          <tr>
            <td class="first"><%= _('Principal Investigator/Researcher') %></td>
            <td><% if !@plan.principal_investigator.nil? && @plan.principal_investigator != "" then %>
              <%= @plan.principal_investigator %>
            <%else%>
              -
            <%end%>
            </td>
          </tr>
          <% if !@plan.principal_investigator_identifier.nil? && @plan.principal_investigator_identifier != "" then %>
            <tr>
              <td class="first"><%= _('Principal Investigator/Researcher ID') %></td>
              <td>
                <%= @plan.principal_investigator_identifier %>
              </td>
            </tr>
          <%end%>
          <tr>
            <td class="first"><%= _('Plan data contact') %></td>
            <td><% if !@plan.data_contact.nil? && @plan.data_contact != "" then%>
              <%= @plan.data_contact %>
            <%else%>
              -
            <%end%>
            </td>
          </tr>
          <tr>
            <td class="first"><%= _('Description') %></td>
            <td><% if !@plan.description.nil? && @plan.description != "" then%>
              <%= @plan.description %>
            <%else%>
              -
            <%end%>
            </td>
          </tr>
        </table>
      </div>
  </div>


  <!-- Selection of guidance groups -->
  <div class="accordion" id="plan-guidance-accordion">
      <div class="accordion-group">
          <div class="accordion-heading">
              <a class="accordion-toggle" data-toggle="collapse" data-parent="#plan-guidance-accordion" href="#guidance-choices">
                  <h3>Guidance Choices<span class="plus-laranja"> </span></h3>
              </a>
          </div>
          <div id="guidance-choices" class="accordion-project collapse">
              <div class="accordion-inner">
                <%= form_tag( update_guidance_choices_plan_path(@plan), method: :put) do %>
                  <table id="dmp_table" class="dmp_table tablesorter">
                    <tbody>
                        <% all_guidance_groups.each do |group| %>
                          <tr>
                          <td class="dmp_td_medium">
                            <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %>
                            <%= group.name %>
                          </td>
                          </tr> 
                        <% end %>
                      </tr>
                    </tbody>
                  </table>
                  <%= submit_tag _('Save'), class: "btn btn-primary"%>
                <% end %>
              </div>
          </div>
      </div>
  </div>

  <div class="div_clear"></div>

	<h3><%= _('This plan is based on:')%></h3>

	<table class="dmp_details_table">
    <tbody>
      <%if based_on.present? %> 
        <tr>
          <td class="first"><%= _('Funder') %></td>
          <td><%= based_on.org.name %></td>
        </tr>
      <%end%>
      <%if plan.template.org.name.present? %> 
        <tr>
          <td class="first"><%= _('Institution') %></td>
          <td><%= plan.template.org.name %></td>
        </tr>
      <%end%>
    </tbody>
	</table>

  <div class="div_clear"></div>

	<!-- If project has phases-->
  <% phases = plan.template.phases %>
		<% if phases.count == 1 %>
			<% phases.each do |phase| %>
				<div class="move_2_right">
					<%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary'  %>
					<a href="#<%= phases[0].id %>-export-dialog" data-toggle="modal" class='btn btn-primary'><%= _('Export') %></a>
				</div>
				<%= render :partial => "plans/export", locals: {plan: plan, phase: phases[0] } %>
				<div class="div_clear"></div>
				<p><%= raw phase.description %></p>
				<% if phase.sections.any? %>
					<table class="dmp_table">
						<thead>
						    <tr>
						      	<th class="dmp_th_medium"><%= _('Sections')%></th>
						      	<th class="dmp_th_big"><%= _('Questions')%></th>
		   					</tr>
	   					</thead>
	   					<tbody>
	   						<% phase.sections.each do |section| %>
								<tr >
									<th class="dmp_th_border" >
										<p><%= section.title %></p>
									</th>
	        				<td class="dmp_td_border" >
										<% if section.questions.any? %>
											<ul class="question_ul">
												<% section.questions.each do |ques|%>
													<li>
														<%= raw ques.text %>
													</li>
												<%end%>
											</ul>
										<%end%>
									</td>
								</tr>
							<%end%>
						</tbody>
					</table>
				<%end%> <!-- end of if phase.sections.any? -->
			<%end%> <!-- end of phases.each do |phase| -->
    <%else%>   <!-- phases.count > 1 -->
			<div class="project_description">
				<%= raw plan.template.description %>
			</div>
			<% phases.each do |phase| %>
				<div class="accordion" id="project-accordion">
					<div class="accordion-group">
						<div class="accordion-heading">
							<a class="accordion-toggle" data-toggle="collapse" data-parent="#project-accordion" href="#<%= phase.id %>">
								<h3><%= phase.title %><span class="plus-laranja"> </span></h3>
							</a>
						</div>
						<div id="<%= phase.id %>" class="accordion-project collapse">
							<div class="accordion-inner">
								<div class="div_right">
									<%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary'  %>
									<a href="#<%= phase.id %>-export-dialog" data-toggle="modal" class='btn btn-primary'><%= _('Export') %></a>
								</div>
								<%= render :partial => "plans/export", locals: {plan: plan, phase: phase} %>
								<div class="div_clear"></div>
									<p><%= raw phase.description %>
								</p>

								<% if phase.sections.any? %>
									<table class="dmp_table">
										<thead>
										    <tr>
										      	<th class="dmp_th_medium"><%= _('Sections')%></th>
										      	<th class="dmp_th_big"><%= _('Questions')%></th>
						   					</tr>
					   					</thead>
					   					<tbody>
					   						<% phase.sections.each do |section| %>
												<tr >
													<th class="dmp_th_border" >
														<p><%= section.title %></p>
													</th>
					        				<td class="dmp_td_border" >
														<% if section.questions.any? %>
															<ul class="question_ul">
																<% section.questions.each do |ques|%>
																	<li>
																		- <%= raw ques.text %>
																	</li>
																<%end%>
															</ul>
														<%end%>
													</td>
												</tr>
											<%end%>
										</tbody>
									</table>
								<%end%> <!-- end of if phase.sections.any? -->
							</div>
						</div>
					</div>
				</div>
			<%end%><!-- end of phases.each
		<%end%> <!-- end of if phases.count == 1 -->
</div>
