<%= javascript 'compute_resource', 'lookup_keys'%>
<% title @compute_resource.name %>

<% title_actions display_link_if_authorized(_("Associate VMs"),
                                            hash_for_associate_compute_resource_path(:compute_resource_id => @compute_resource).merge(:auth_object => @compute_resource, :permission => 'edit_compute_resources'),
                                            :title => _("Associate VMs to Foreman hosts"), :method => :put, :class=>"btn btn-default"),
   link_to_if_authorized(_('Edit'), hash_for_edit_compute_resource_path(@compute_resource).merge(:auth_object => @compute_resource), :class => "btn btn-default")  %>

<ul class="nav nav-tabs" data-tabs="tabs">
  <li class="active"><a href="#primary" data-toggle="tab"><%= _("Compute Resource") %></a></li>
  <li><a href="#vms" data-toggle="tab"><%= _("Virtual Machines") %></a></li>
  <% if @compute_resource.capabilities.include?(:image) %>
    <li><a href="#images" data-toggle="tab"><%= _("Images") %></a></li>
  <% end %>
    <li><a href="#compute_profiles" data-toggle="tab"><%= _("Compute profiles") %></a></li>
</ul>

<div class="tab-content">
  <div class="tab-pane active" id="primary">
    <table class="table table-bordered table-striped">
      <thead>
        <tr>
          <th><%= _("Details") %></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><%= _("Provider") %></td>
          <td><%= @compute_resource.provider_friendly_name %></td>
        </tr>
        <% unless @compute_resource.description.empty? %>
          <tr>
            <td><%= _("Description") %></td>
            <td><%= @compute_resource.description %></td>
          </tr>
        <% end %>
        <% # optional extra display elements based on type %>
        <%= render "compute_resources/show/#{@compute_resource.provider.downcase}" %>
      </tbody>
    </table>
  </div>
  <div id="vms" class="tab-pane" data-url=<%= compute_resource_vms_path(@compute_resource) %>>
    <p id="spinner">
      <%= image_tag '/assets/spinner.gif' %>
      <%= _('Loading virtual machines information ...') %>
    </p>
  </div>
  <% if @compute_resource.capabilities.include?(:image) %>
    <div id="images" class="tab-pane">
      <%= title_actions(display_link_if_authorized(_("New Image"), hash_for_new_compute_resource_image_path(:compute_resource_id => @compute_resource.id), :class => "btn btn-success", :data=>{:target=>"full-page"})) %>
      <div id="images_list" data-url=<%= compute_resource_images_path(@compute_resource) %>>
        <p id="spinner">
          <%= image_tag '/assets/spinner.gif' %>
          <%= _('Loading Images information') %> ...
        </p>
      </div>
    </div>
  <% end %>
  <div id="compute_profiles" class="tab-pane">
    <table class="table table-bordered table-striped table-two-pane">
      <thead>
        <tr>
          <th><%= _("Compute profile") %></th>
          <th><%= _("VM Attributes") %></th>
        </tr>
      </thead>
      <tbody>
        <% ComputeProfile.where(nil).each do |compute_profile| %>
          <% compute_attribute = ComputeAttribute.where(:compute_profile_id => compute_profile.id, :compute_resource_id => @compute_resource.id).first %>
          <% which_path = if compute_attribute.try(:id)
                            edit_compute_profile_compute_attribute_path(compute_profile.to_param, compute_attribute.id)
                          else
                            new_compute_profile_compute_resource_compute_attribute_path(compute_profile.to_param, @compute_resource.to_param)
                          end %>
          <tr>
            <td><%= link_to(compute_profile.name, which_path, :class => compute_attribute.try(:id) ? '' : 'new_two_pane') %></td>
            <td>
              <% set = @compute_resource.compute_attributes.where(:compute_profile_id => compute_profile.id).first %>
              <%= set ? set.name : content_tag(:span, _("unspecified"), :class => 'gray') %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
</div>
