<% my_module_undefined = !defined? my_module or my_module.blank? %>

<div>
  <em>
    <%= t("projects.reports.elements.modals.module_contents_inner.instructions") %>
  </em>
</div>

<div class="checkbox-tree">
  <ul data-hook="module-content-list">
    <li>
      <%= form.check_box :module_all, label: t("projects.reports.elements.modals.module_contents_inner.check_all") %>
      <ul>

        <% if my_module_undefined or my_module.protocol.steps.exists? %>
          <li>
            <%= form.check_box :module_steps, label: t("projects.reports.elements.modals.module_contents_inner.steps") %>
            <ul>
              <li>
                <%= form.check_box :module_completed_steps, label: t("projects.reports.elements.modals.module_contents_inner.completed_steps") %>
              </li>
              <li>
                <%= form.check_box :module_uncompleted_steps, label: t("projects.reports.elements.modals.module_contents_inner.uncompleted_steps") %>
              </li>
            </ul>
          </li>
        <% else %>
          <div>
            <em>
              <%= t("projects.reports.elements.modals.module_contents_inner.no_steps") %>
            </em>
          </div>
        <% end %>

        <% if my_module_undefined or (my_module.results.select { |r| r.active? }).exists? %>
          <li>
            <%= form.check_box :module_results, label: t("projects.reports.elements.modals.module_contents_inner.results") %>
            <ul data-hook="result-types-list">
              <% if my_module_undefined or (my_module.results.select { |r| r.is_asset && r.active? }).exists? %>
                <li>
                  <%= form.check_box :module_result_assets, label: t("projects.reports.elements.modals.module_contents_inner.result_assets") %>
                </li>
              <% end %>
              <% if my_module_undefined or (my_module.results.select { |r| r.is_table && r.active? }).exists? %>
                <li>
                  <%= form.check_box :module_result_tables, label: t("projects.reports.elements.modals.module_contents_inner.result_tables") %>
                </li>
              <% end %>
              <% if my_module_undefined or (my_module.results.select { |r| r.is_text && r.active? }).exists? %>
                <li>
                  <%= form.check_box :module_result_texts, label: t("projects.reports.elements.modals.module_contents_inner.result_texts") %>
                </li>
              <% end %>

            </ul>
          </li>
        <% else %>
          <div>
            <em>
              <%= t("projects.reports.elements.modals.module_contents_inner.no_results") %>
            </em>
          </div>
        <% end %>

        <li>
          <%= form.check_box :module_activity, label: t("projects.reports.elements.modals.module_contents_inner.activity") %>
        </li>
        <% # List all repositories, no matter whether rows are assigned or not %>
        <% Repository.where(team: @project.team).order(created_at: :asc).select(:id, :name).find_each do |repository| %>
          <li>
            <%= form.check_box "module_repository_#{repository.id}", label: repository.name.capitalize, data: { id: repository.id } %>
          </li>
        <% end %>
      </ul>
    </li>
  </ul>
</div>
