<%= form_for(@database, remote: true) do |f| %>
  <div class="row">
    <div class="col-sm-6">
      <div class="form-group">
        <%= f.label :friendly_name %>
        <%= f.text_field :friendly_name, autofocus: true, class: "form-control", placeholder: "Enter database name" %>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-sm-6">
      <div class="form-group">
        <%= f.label :adapter %>
        <%= f.select(:adapter, Database::DATABASE_TYPES,
                                            {prompt: "Please select"},
                                            {class: 'form-control'}) %>
      </div>
    </div>

    <div class="col-sm-6">
      <div class="form-group">
        <%= f.label :name %>
        <%= f.text_field :name, autofocus: true, class: "form-control" %>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-sm-6">
      <div class="form-group">
        <%= f.label :host %>
        <%= f.text_field :host, autofocus: true, class: "form-control", required: true %>
      </div>
    </div>

    <div class="col-sm-6">
      <div class="form-group">
        <%= f.label :username %>
        <%= f.text_field :username, autofocus: true, class: "form-control" %>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-sm-6">
      <div class="form-group">
        <%= f.label :port %>
        <%= f.number_field :port, autofocus: true, class: "form-control" %>
      </div>
    </div>

    <div class="col-sm-6">
      <div class="form-group">
        <%= f.label :password %>
        <%= f.password_field :password, autofocus: true, class: "form-control", value: @database.password %>
        <%= f.hidden_field :password_changed, value: false %>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-sm-11">
      <%= f.submit "Test connection", class: "btn btn-primary m-b pull-right", id: "test-database-connection" %>
      <% if @database.persisted? %>
        <%= link_to "Remove database", database_path(@database), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger m-b pull-right margin-right" %>
      <% end %>
    </div>
  </div>

  <div class="row">
    <div class="col-sm-8">
      <h4>Don't forget to <%= link_to "set the database permissions here", permissions_path %>, otherwise you won't be able to see any tables.</h4>
    </div>
    <div class="col-sm-3">
      <%= f.submit "Save", class: "btn btn-primary m-b pull-right" %>
    </div>
  </div>
<% end %>
