<% title _('Editing profile for %{username}') % { username: @user.name(false) } %>
<div class="row">
  <div class="col-md-12">
    <h1>
      <%= _('Editing profile for %{username}') % { username: @user.name(false) } %>
      <%= link_to(_('View all users'), admin_index_users_path, class: 'btn btn-default pull-right', role: 'button') %>
    </h1>
  </div>
</div>

<div class="row">
  <div class="col-md-7">
    <%= form_for(@user, namespace: :superadmin, as: :user, url: super_admin_user_path(@user), html: {method: :put, id: 'super_admin_user_edit' }) do |f| %>
      <div class="form-group col-xs-12">
        <%= f.label(:email, _('Email'), class: 'control-label') %>
        <%= f.email_field(:email, class: "form-control", "aria-required": true) %>
      </div>

      <div class="form-group col-xs-12">
        <%= f.label(:firstname, _('First name'), class: 'control-label') %>
        <%= f.text_field(:firstname, class: "form-control", "aria-required": true) %>
      </div>

      <div class="form-group col-xs-12">
        <%= f.label(:surname, _('Last name'), class: 'control-label') %>
        <%= f.text_field(:surname, class: "form-control", "aria-required": true) %>
      </div>

      <div class="form-group col-xs-12" id="org-controls">
        <%= render partial: "shared/my_org", locals: {
            f: f,
            default_org: @user.org,
            orgs: Org.where(is_other: false).order("name"),
            allow_other_orgs: true,
            required: true } %>
      </div>

      <% if @departments.any? %>
      <div class="form-group col-xs-12">
        <% dept_id = @user.department.nil? ? -1 : @user.department.id  %>
        <%= f.label(:department_id, _('Department or school'), class: 'control-label') %>
        <%= select_tag(:department_id,
            options_from_collection_for_select(@departments, "id", "name", dept_id),
            include_blank: true,
            class: "form-control",
            name: 'user[department_id]') %>
      </div>
      <% end %>

      <% if Language.many? %>
        <div class="form-group col-xs-12">
          <% lang_id = @user.language.nil? ? Language.id_for(FastGettext.default_locale) : @user.language.id %>
          <%= f.label(:language_id, _('Language'), class: 'control-label') %>
          <%= select_tag(:super_admin_user_language_id,
              options_from_collection_for_select(Language.sorted_by_abbreviation, "id", "name", lang_id),
              class: "form-control", name: 'super_admin_user[language_id]') %>
        </div>
      <% end %>

      <div class="form-group col-xs-12">
        <%= f.button(_('Save'), class: 'btn btn-default', type: "submit", id: "personal_details_registration_form_submit") %>

        <%= link_to _('Archive'), archive_super_admin_user_path(id: @user.id),
            data: { method: :put, confirm: _("You are about to archive %{user_name}.  This will remove their personal information, but retain their plans, answers, and comments.  They will be unable to sign-in. Are you sure?") % {user_name: @user.name } },
            class: 'btn btn-default', role: 'button' %>
      </div>
    <% end %>
  </div>
  <div class="col-xs-5">
    <div class="row">
      <h2>
        <%= _('Merge Accounts') %>
      </h2>
      <div id='merge_form_container'>
        <p>
          <%= sanitize _("First, search for a user by email, then select them from the list.") %>
        </p>
        <%= form_tag(search_super_admin_user_path(@user), method: 'get', remote: true, class: 'form-inline', id: 'merge_form') do %>
          <div class="form-group">
            <div class="input-group">
              <span class="input-group-addon" id="search-addon">
                <span class="fa fa-search" aria-hidden="true"></span>
              </span>
            <%= text_field_tag(:email, nil, class: "form-control", placeholder: _("Email")) %>
            </div>
          </div>
          <%= submit_tag( _("Search"), class: 'btn btn-default', style: 'margin-top: 8px;') %>
        <% end %>
      </div>
    </div>
  </div>
</div>

<div class="row">
  <div class="col-md-12">
    <h2><%= _('Plans') % { username: @user.name(false) } %></h2>
    <!-- if the user has projects -->
  </div>
</div>
<div class="row">
  <div class="col-md-12">
    <%= paginable_renderise(
      partial: '/paginable/plans/org_admin_other_user',
      controller: 'paginable/plans',
      action: 'org_admin_other_user',
      scope: @plans,
      query_params: { sort_field: 'plans.updated_at', sort_direction: 'desc' }) %>
  </div>
  </div>
</div>
