<script>
// Rules and strings for the password validator
const PASSWORD_RULES = [
<% rules.each do |r| %>
    {
        type: "<%= r[:type] %>",
        <% if r.include?(:operator) %>
        operator: "<%= r[:operator].html_safe %>",
        <% end %>
        <% if r.include?(:length) %>
        length: "<%= r[:length] %>",
        <% end %>
        <% if r.include?(:regexp) %>
        regexp: new RegExp(/<%= r[:regexp] %>/),
        <% end %>
        <% if r[:type] == 'complexity_check' %>
        min_matches: <%= r[:min_matches] %>,
        regexps: [
        <% r[:regexps].each do |r| %>
            new RegExp(/<%= raw r %>/),
        <% end %>
        ],
        <% end %>
        message: "<%= t("activeldap.errors.messages.password_validation.#{r[:message_id]}") %>",
    },
<% end %>
];

const COMMON_PASSWORDS = "<%= raw Puavo::COMMON_PASSWORDS %>";

const CONFIRM_MISMATCH = "<%= t('flash.password.confirmation_failed') %>",
      PASSWORD_CONTAINS_NAME = "<%= t('activeldap.errors.messages.password_validation.contains_name') %>",
      PASSWORD_IS_COMMON = "<%= t('activeldap.errors.messages.password_validation.common') %>";

initializePasswordValidator("<%= password_field_id %>", "<%= confirm_field_id %>", <%= raw name_field_ids %>, "<%= callback %>");
</script>
