<%# Copyright (C) The Arvados Authors. All rights reserved.

SPDX-License-Identifier: AGPL-3.0 %>

<div class="modal modal-with-loading-spinner">
  <div class="modal-dialog">
    <div class="modal-content">

      <div class="modal-header">
        <button type="button" class="close" onClick="reset_form()" data-dismiss="modal" aria-hidden="true">&times;</button>
        <div>
          <div class="col-sm-6"> <h4 class="modal-title"><%= params[:title] || 'Choose project' %></h4> </div>
          <div class="spinner spinner-32px spinner-h-center col-sm-1" hidden="true"></div>
        </div>
        <br/>
      </div>

      <div class="modal-body">
        <div class="selectable-container" style="height: 15em; overflow-y: scroll">
          <% starred_projects = my_starred_projects current_user%>
          <% if starred_projects.andand.any? %>
            <% writable_projects = starred_projects.select(&:editable?) %>
            <% writable_projects.each do |projectnode| %>
              <% row_name = projectnode.friendly_link_name || 'New project' %>
              <div class="selectable project row"
                   style="padding-left: 1em; margin-right: 0px"
                   data-object-uuid="<%= projectnode.uuid %>">
                <i class="fa fa-fw fa-folder-o"></i> <%= row_name %> <i class="fa fa-fw fa-star"></i>
              </div>
            <% end %>
          <% end %>

          <% my_projects = my_wanted_projects_tree(current_user) %>
          <% my_projects[0].each do |projectnode| %>
            <% if projectnode[:object].uuid == current_user.uuid
                 row_name = "Home"
               else
                 row_name = projectnode[:object].friendly_link_name || 'New project'
               end %>
            <div class="selectable project row"
                 style="padding-left: <%= 1 + projectnode[:depth] %>em; margin-right: 0px"
                 data-object-uuid="<%= projectnode[:object].uuid %>">
              <i class="fa fa-fw fa-folder-o"></i> <%= row_name %>
            </div>
          <% end %>
        </div>

        <% if my_projects[1] or my_projects[2] or my_projects[0].size > 200 %>
          <div>Some of your projects are omitted. Add projects of interest to favorites.</div>
        <% end %>
      </div>

      <div class="modal-footer">
        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
        <button class="btn btn-primary" aria-hidden="true" data-enable-if-selection disabled><%= params[:action_name] || 'Select' %></button>
        <div class="modal-error hide" style="text-align: left; margin-top: 1em;">
        </div>
      </div>
    </div>
  </div>
</div>