<% content_for :extra_password_js do %>
<%= javascript_include_tag 'password_validator' %>
<% end %>

<% content_for :title do %><%= t('.title') %><% end %>

<% content_for :password_tabs do %>
<ul>
  <li class="current"><%= t('password.edit.link_own_password') %></li>

  <li>
    <%= link_to password_path(:lang => @language, :changing => @changing) do %>
      <%= t('password.own.link_other_password') %>
    <% end %>
  </li>
</ul>
<% end %>

<% if @expired %>
<p class="genericWarning"><%= t('password.current_password_too_old') %></p>
<% end %>

<p class="genericWarning"><%= t('password.attempts_are_logged_own') %></p>

<% if @banner %>
<div class="genericNotice"><%= @banner.html_safe %></div>
<% end %>

<% school_id = params['school_id'] || @primary_school_id || -1 %>

<%= form_for(@user, :url => password_path, :html => { :method => :put })  do |f| %>
  <% if params.include?('hidetabs') || @reduced_ui %>
  <input type="hidden" id="hidetabs" name="hidetabs" value="1">
  <% end %>

  <% if school_id %>
  <input type="hidden" id="primary_school_id" name="primary_school_id" value="<%= school_id %>">
  <% end %>

  <table class="editForm">
    <tr>
      <th><%= label :login, :uid, t('activeldap.attributes.user.uid') %></th>
      <td id="username">
        <% if @domain %>
        <div class="passwordDomainContainer">
        <%= text_field :login, :uid, :value => @changing, :autofocus => (@changing.nil? || @changing.empty?) ? true : false, :required => "required" %>
        <span><%= Array(@domain).map { |d| "<strong>#{d}</strong>" }.join(t('password.edit.domain_or')).html_safe %></span>
        </div>
        <% else %>
        <%= text_field :login, :uid, :value => @changing, :autofocus => (@changing.nil? || @changing.empty?) ? true : false, :required => "required" %>
        <% end %>
        <span class="field_error"></span>
      </td>
    </tr>

    <tr>
      <th><%= label :login, :password, t('.password') %></th>
      <td><%= password_field :login, :password, :autofocus => (@changing.nil? || @changing.empty?) ? false : true, :required => "required" %></td>
    </tr>

    <tr>
      <th><%= f.label :new_password, t('activeldap.attributes.user.new_password') %></th>
      <td>
        <%= show_password_requirements(@organisation_name, school_id) %>
        <%= password_field :user, :new_password, :value => "", :required => "required" %>
      </td>
    </tr>

    <tr>
      <th><%= f.label :new_password_confirmation, t('activeldap.attributes.user.new_password_confirmation') %></th>
      <td><%= password_field :user, :new_password_confirmation, :value => "", :required => "required" %></td>
    </tr>

    <tr class="buttonRow">
      <td colspan="2">
        <input type="hidden" name="changing" value="<%= @changing %>"/>
        <input type="hidden" name="lang" value="<%= @language %>"/>
        <%= f.submit t('link.change_password'), class: 'btn', id: "submit" %>
      </td>
    </tr>
  </table>
<% end %>

<% content_for :password_validator do %>
<%= setup_password_validator(@organisation_name,
                             school_id,
                             'user_new_password',
                             'user_new_password_confirmation',
                             ['login_uid']) %>
<% end %>

<%= render('username_validator') %>

<script>
document.addEventListener("DOMContentLoaded", function() {
    setupUsernameValidation("table.editForm td#username input", "table.editForm td#username span.field_error");
});
</script>
