<% content_for :javascripts do %>
  <%= javascript_include_tag 'provider/create_application' %>
  <%= render_js_module_loader %>
<% end %>

<% if @account %>
  <%= render '/buyers/accounts/menu' %>
<% end %>

<h2>New Application</h2>

<%= metadata_new_app(@buyer, @provider) %>
<%= semantic_form_for @cinstance, :url =>  admin_buyers_account_applications_path(@buyer), :builder => Fields::FormBuilder do |form| %>

  <%= form.semantic_errors %>
  <%= form.inputs do %>
    <%= form.input :plan, :as => :plan_selector,
                          :collection => @plans, :include_blank => false,
                          :label => ApplicationPlan.model_name.human,
                          :default_plan => @plans.respond_to?(:default) ? @plans.default : @plans.first %>

    <% if current_account.settings.service_plans.allowed? %>
      <%= form.input :service_plan_id, as: :select, collection: [], label: ServicePlan.model_name.human,
        hint: link_to('Create a service plan', admin_services_path, id: 'link-help-new-application-service') %>
    <% else %>

    <% end %>

    <%= form.user_defined_form %>
  <% end %>

  <%= form.buttons do %>
    <%= form.commit_button button_html: {id: 'submit-new-app' } %>
  <% end %>
<% end %>

<script type="text/javascript">

  System.import('applications/new.es6').then(function (m) {
    m.default()
  });
</script>
