<%= render 'menu' %>

<h2 data-help="applicaton-show">
  <%= h @cinstance.display_name %>
</h2>

<div class="operations" style="padding-bottom: 5px;">
  <%= link_to 'Edit', edit_admin_buyers_application_path(@cinstance), :class => 'action edit' %>
  <%= delete_application_link(@cinstance) %>
</div>

<div id="twoCol" class='equal-width'>
  <div class="left">

    <div class="wide_dashboard_bubble round">
      <table class="list">
        <%= fields_definitions_rows(@cinstance, %w{name}) %>
        <tr>
          <th>Service</th>
          <td><%= link_to @cinstance.service.name, edit_admin_service_path(@cinstance.service) %></td>
        </tr>
      </table>
    </div>

    <div class="wide_dashboard_bubble round">
      <h3>State</h3>
      <div id="cinstance_state">
        <%= render 'state' %>
      </div>
    </div>

    <% if can?(:see, :end_users) && @cinstance.end_users_allowed? %>
    <div class="wide_dashboard_bubble round">
      <h3>EndUsers required?</h3>
      <div id="cinstance_end_user_required">
        <%- if @cinstance.end_user_required? %>
          <strong>yes</strong>
          <%= action_link_to "don't require",
                             admin_buyers_application_path(@cinstance, :cinstance => {:end_user_required => false}),
                             :method => :put, data: {:confirm => "The application will stop rate limiting EndUsers, are you sure you want to do it?"} %>
        <%- else %>
          <strong>no</strong>
          <%= action_link_to :require,
                             admin_buyers_application_path(@cinstance, :cinstance => {:end_user_required => true}),
                             :method => :put, data: {:confirm => "Requiring EndUsers implies changes on the integration with 3scale's backend (adding the user_id parameter), are you sure you want to do it?"} %>
        <%- end %>
      </div>
    </div>
    <%- end %>


    <div class="wide_dashboard_bubble round">
      <h3>API Credentials</h3>
      <%= render :partial => 'provider/admin/keys/widget',
                 :locals => {:cinstance => @cinstance} %>
    </div>

    <% if @cinstance.service.referrer_filters_required? %>
    <div class="wide_dashboard_bubble round">
      <%= render :partial => 'provider/admin/referrer_filters/widget',
                 :locals => {:cinstance => @cinstance} %>
    </div>
    <% end %>

    <div class="wide_dashboard_bubble round">
      <h3>Usage in last 30 Days</h3>
      <%- cache [ 'v1', 'cinstance', 'sparklines', @cinstance.service, @cinstance ] do %>
        <%= render 'stats/sparklines', :cinstance => @cinstance, :metrics => @cinstance.service.metrics.top_level %>
      <%- end %>
    </div>

    <div class="wide_dashboard_bubble round">
      <h3>Current Utilization</h3>
      <%= render :partial => 'buyers/applications/utilization', :locals => {:utilization => @utilization, :cinstance => @cinstance} %>
    </div>

    <br class='clear' />
  </div>

  <div class="right_narrow">
    <%= render :partial => 'plan', :locals => { :contract => @cinstance } %>

    <%# HACK: this condition really hurts - more than dancing CanCan %>
    <% if can?( :manage, :plans) && @cinstance.available_application_plans.size > 0 && !current_account.master?-%>
      <%= render 'change_plan'  %>
    <% end -%>
  </div>
</div>

<br class="clear" />
