<% # needs button_text passed in %>

<%= form_for(@group) do |f| %>
  <%= render partial: "layouts/errors", object: @group %>

  <fieldset>
    <legend><span><%= t('.provide_details') %></span></legend>
    <div class="clearfix">
      <%= f.label :name %>
      <div class="input">
        <%= f.text_field :name, class: "input-xlarge", autofocus: true %>
      </div>
    </div>

    <div class="clearfix">
      <%= f.label :narrative %>
      <div class="input">
        <%= f.text_field :narrative, class: "input-xxlarge" %>
      </div>
    </div>
  </fieldset>

 <% unless params[:action] == "edit" %>
  <fieldset>
    <legend><span><%= t('.initial_leader') %></span></legend>
    <div class="clearfix">
      <%= f.label :new_leader %>
      <div class="input">
      <% 
        users = User.order(:last_name)
        options = {}
        if !users.empty?
          options[User] = users.map { |u| [u.name, "#{u.id}"]}
        end
      %>        
      <%= render partial: "elements/owner_select", locals: { options: options } %>
      <%= f.hidden_field :new_leader %>
      </div>
    </div>
  </fieldset>
  <% end %>

  <div class="submit_bar actions">
    <%= f.submit button_text, class: "btn btn-primary" %> 
    <%= link_to t(:cancel), (@group.persisted? ? group_path : groups_path), class: "btn" %>
  </div>
<% end %>
