<% page_title t('titles.schools'), @school.displayName, t('titles.users'), t('titles.users_import') %>

<% content_for :javascript do %>
<script>
// Needed by new_import.js, but it has no access to the Rails' asset pipeline
const CSV_PARSER_PATH = "<%= javascript_path 'csv_parser' %>",
      IMPORT_WORKER_PATH = "<%= javascript_path 'import_worker' %>";
</script>

<%= javascript_include_tag 'javascripts/import_tool' %>
<% end %>

<h1><%= t('new_import.title') %></h1>

<% unless @can_create_users %>
<p class="genericWarning"><%= t('new_import.cant_create_users') %></p>
<% end %>

<!-- The main container. Everything in the importer MUST be inside this DIV! -->
<div id="import">

<!-- Tabs -->
<nav>
    <button id="page1" class="tab"><%= t('new_import.source_tab') %></button>
    <button id="page2" class="tab"><%= t('new_import.import_tab') %></button>
</nav>

<!-- The source page -->
<section id="page1" class="hidden">

<p class="line-height-125p"><%= t('new_import.source_help') %></p>

<div class="flex-rows gap-10px">
    <div class="flex-cols gap-10px">
        <select id="source" class="padding-5px width-25p">
            <option value="manual"><%= t('new_import.manual_title') %></option>
            <option value="upload"><%= t('new_import.upload_title') %></option>
            <option value="unl"><%= t('new_import.unl_title') %></option>
        </select>

        <button id="downloadTemplate" class="btn popupToggle" data-template="downloadTemplatePopup">
            <%= t('new_import.buttons.download_template') %>... ▼
        </button>
    </div>

    <div class="sourceContents">
        <div id="manual" class="hidden">
            <p class="margin-0"><strong><%= t('new_import.manual_help') %></strong></p>
            <textarea rows="15" class="width-100p padding-5px"></textarea>
        </div>

        <div id="upload" class="hidden">
            <p class="margin-0"><strong><%= t('new_import.upload_help') %></strong></p>
            <input type="file" id="fileUpload" class="margin-top-5px">
        </div>

        <div id="unl" class="hidden">
            <% if @lists.empty? %>
            <p class="margin-0"><strong><%= t('new_import.unl_no_lists') %></strong></p>
            <% else %>
            <p class="margin-0 line-height-125p"><%= t('new_import.unl_help').html_safe %></p>

            <%
            created_by = t('new_import.unl_created_by')
            created_at = t('new_import.unl_created_at')
            members = t('new_import.unl_members')
            description = t('new_import.unl_description')
            %>

            <select class="margin-top-5px">
                <% @lists.each do |l| %>
                <%
                parts = [
                    "#{created_by}: #{l.creator}",
                    "#{created_at}: #{Time.at(l.created_at).strftime('%Y-%m-%d %H:%M:%S')}",
                    "#{members}: #{l.users.count}"
                ]

                unless l.description.nil? || l.description.empty?
                    parts << "#{description}: \"#{l.description}\""
                end
                %>
                <option value="<%= l.uuid %>"><%= parts.join('; ') %></option>
                <% end %>
            </select>
            <br><button id="loadUNL" class="margin-top-5px"><%=t('new_import.unl_load') %></button>
            <br><textarea rows="15" cols="50" class="padding-5px"></textarea>
            <% end %>
        </div>
    </div>

    <!-- Parser settings popup. The summary is filled in later. -->
    <details id="settings">
        <summary></summary>

        <div class="flex-rows gap-10px margin-left-20px margin-top-5px margin-bottom-20px">
            <div class="settingRow">
              <label><input type="checkbox" id="inferTypes"><%= t('new_import.infer_columns') %></label>
            </div>

            <div class="settingRow">
                <details class="margin-left-20px">
                    <summary class=""><%= t('new_import.buttons.show_infers') %></summary>
                    <p><%= t('new_import.infer_explanation') %></p>
                    <table class="inferTable margin-top-10px">
                        <thead><tr><th><%= t('new_import.infer_left') %></th><th><%= t('new_import.infer_right') %></th></tr></thead>
                        <tbody></tbody>
                    </table>
                </details>
            </div>

            <div class="settingRow">
                <label><input type="checkbox" id="trimValues" checked><%= t('new_import.trim') %></label>
            </div>

            <div class="settingRow">
                <fieldset class="margin-0"><legend><%= t('new_import.separator') %></legend>
                    <p class="margin-5px padding-0 padding-bottom-5px"><%= t('new_import.separator_help') %></p>

                    <div class="flex-rows">
                        <label><input type="radio" name="separator" id="comma"><%= t('new_import.comma') %></label>
                        <label><input type="radio" name="separator" id="semicolon"><%= t('new_import.semicolon') %></label>
                        <label><input type="radio" name="separator" id="tab" checked><%= t('new_import.tab') %></label>
                    </div>
                </fieldset>
            </div>
        </div>
    </details>

    <!-- Live preview -->
    <p class="margin-0"><strong><%= t('new_import.preview') %>:</strong></p>
    <div id="preview"></div>

    <div>
        <button id="readData" class="btn width-100p"><%= t('new_import.buttons.read_data') %></button>
    </div>
</div>

</section>

<!-- The data manipulation and import table -->
<section id="page2" class="hidden">

<template id="template_selectExistingUIDsPopup">
    <div class="popupContainer">
        <button id="selectDupesAll"><%= t('new_import.buttons.everyone') %></button>
        <button id="selectDupesThisSchool"><%= t('new_import.buttons.everyone_in_this_school') %></button>
        <button id="selectDupesOtherSchools"><%= t('new_import.buttons.everyone_in_other_schools') %></button>
    </div>
</template>

<template id="template_selectRowsPopup">
    <div class="popupContainer">
        <button id="selectAll"><%= t('new_import.buttons.select_all') %></button>
        <button id="deselectAll"><%= t('new_import.buttons.deselect_all') %></button>
        <button id="invertSelection"><%= t('new_import.buttons.invert_selection') %></button>
        <label class="margin-top-10px"><%= t('new_import.need_to_import_first') %>:</label>
        <button id="selectIdle"><%= t('new_import.buttons.select_unprocessed_rows') %></button>
        <button id="selectSuccessfull"><%= t('new_import.buttons.select_successfull_rows') %></button>
        <button id="selectPartiallySuccessfull"><%= t('new_import.buttons.select_partially_successfull_rows') %></button>
        <button id="selectFailed"><%= t('new_import.buttons.select_failed_rows') %></button>
    </div>
</template>

<template id="template_analyzePopup">
    <div class="popupContainer">
        <button id="analyzeDuplicates"><%= t('new_import.buttons.compare_attributes') %></button>
    </div>
</template>

<template id="template_exportPopup">
    <div class="popupContainer">
        <fieldset class="margin-0 padding-5px"><legend><%= t('new_import.tools.export.target') %></legend>
            <div class="flex-rows">
                <label><input type="radio" name="type" id="all" checked><%= t('new_import.tools.export.all_rows') %></label>
                <label><input type="radio" name="type" id="selected"><%= t('new_import.tools.export.selected_rows') %></label>
                <label><input type="radio" name="type" id="unselected"><%= t('new_import.tools.export.unselected_rows') %></label>
            </div>
        </fieldset>

        <p class="margin-0 margin-top-10px"><%= t('new_import.tools.export.pdf_warning') %></p>

        <button id="exportCSV">CSV</button>
        <button id="exportPDF">PDF</button>
        <button id="exportPDFWithPasswords"><%= t('new_import.buttons.export_pdf_with_passwords') %></button>
    </div>
</template>

<template id="template_usernameListPopup">
    <div class="popupContainer">
        <label><input type="checkbox" id="onlySelection" checked><%= t('new_import.tools.username_list.selection_only') %></label>
        <label for="unlDescription"><%= t('new_import.tools.username_list.list_title') %>:</label>
        <input type="text" maxlength="100" id="unlDescription">
        <button id="doIt" class="margin-top-10px"><%= t('new_import.tools.username_list.create_list') %></button>
    </div>
</template>

<template id="template_downloadTemplatePopup">
    <div class="popupContainer">
        <p class="margin-0 margin-top-10px"><%= t('new_import.tools.download_template.title') %></p>

        <fieldset class="margin-0 padding-5px"><legend><%= t('new_import.tools.download_template.columns') %></legend>
            <div class="flex-cols gap-10px">
                <div class="flex-rows">
                    <label><input type="checkbox" id="first" checked><%= t('new_import.columns.first') %></label>
                    <label><input type="checkbox" id="last" checked><%= t('new_import.columns.last') %></label>
                    <label><input type="checkbox" id="uid" checked><%= t('new_import.columns.uid') %></label>
                    <label><input type="checkbox" id="role" checked><%= t('new_import.columns.role') %></label>
                    <label><input type="checkbox" id="password" checked><%= t('new_import.columns.password') %></label>
                    <label><input type="checkbox" id="eid"><%= t('new_import.columns.eid') %></label>
                </div>

                <div class="flex-rows">
                    <label><input type="checkbox" id="rawgroup"><%= t('new_import.columns.rawgroup') %></label>
                    <label><input type="checkbox" id="licenses"><%= t('new_import.columns.licenses') %></label>
                    <label><input type="checkbox" id="group" checked><%= t('new_import.columns.group') %></label>
                    <label><input type="checkbox" id="phone"><%= t('new_import.columns.phone') %></label>
                    <label><input type="checkbox" id="email"><%= t('new_import.columns.email') %></label>
                    <label><input type="checkbox" id="pnumber"><%= t('new_import.columns.pnumber') %></label>
                </div>
            </div>
        </fieldset>

        <fieldset class="margin-0 padding-5px"><legend><%= t('new_import.separator') %></legend>
            <div class="flex-rows">
                <label><input type="radio" name="template_separator" id="template_comma" checked><%= t('new_import.comma') %> (CSV)</label>
                <label><input type="radio" name="template_separator" id="template_semicolon"><%= t('new_import.semicolon') %> (CSV)</label>
                <label><input type="radio" name="template_separator" id="template_tab"><%= t('new_import.tab') %> (TSV)</label>
            </div>
        </fieldset>

        <button><%= t('new_import.buttons.download_template_file') %></button>
    </div>
</template>

<div class="flex-rows gap-10px margin-top-10px ">
    <!-- Control buttons -->
    <div id="controls">
        <div class="row">
            <button id="selectRows" class="btn popupToggle" data-template="selectRowsPopup">
                <%= t('new_import.buttons.select_rows') %>... ▼
            </button>

            <button id="analyze" class="btn popupToggle" data-template="analyzePopup">
                <%= t('new_import.buttons.analyze') %>... ▼
            </button>

            <button id="selectExistingUIDs" class="btn popupToggle" data-template="selectExistingUIDsPopup">
                <%= t('new_import.buttons.select_existing_uids') %>... ▼
            </button>

            <button id="export" class="btn popupToggle" data-template="exportPopup">
                <%= t('new_import.buttons.export') %>... ▼
            </button>

            <button id="unl" class="btn popupToggle" data-template="usernameListPopup">
                <%= t('new_import.buttons.username_list') %>... ▼
            </button>

            <button id="deleteSelectedRows" class="btn btn-danger"><%= t('new_import.buttons.delete_selected_rows') %></button>

        </div>

        <div class="row">
            <button id="beginImport" class="btn"><%= t('new_import.buttons.begin') %></button>
            <!--<button id="beginImportSelected" class="btn"><%= t('new_import.buttons.begin_selected') %></button>//-->
            <button id="retryFailed" class="btn"></i><%= t('new_import.buttons.begin_failed') %></button>
            <button id="stopImport" class="btn" disabled><%= t('new_import.buttons.stop') %></button>

            <div class="margin-left-10px">
                <label><%= t('new_import.mode.label') %>: <select id="mode">
                    <% if @can_create_users %>
                    <option value="0"><%= t('new_import.mode.create_new_update_existing') %></option>
                    <option value="1"><%= t('new_import.mode.create_new_skip_existing') %></option>
                    <% else %>
                    <option value="0" disabled><%= t('new_import.mode.create_new_update_existing') %></option>
                    <option value="1" disabled><%= t('new_import.mode.create_new_skip_existing') %></option>
                    <% end %>
                    <option value="2"><%= t('new_import.mode.skip_new_update_existing') %></option>
                </select></label>
            </div>
        </div>

        <!--
        <div class="row">
            <span><input type="checkbox" id="checkOnlySelectedRows"><label for="checkOnlySelectedRows">Tarkista vain valitut rivit virheiden ja ongelmien varalta</label></span>
            <button id="detectProblemsNow" class="btn">Tarkista nyt</button>
        </div>
        //-->
    </div>

    <!-- Errors and warnings -->
    <div id="problems"></div>

    <!-- Status message, progress bar -->
    <div id="status">
        <div id="rowCounts">...</div>
        <div class="flex-rows gap-5px flex-grow-2">
            <div id="message" class="hidden"></div>
            <progress max="0" value="0" class="hidden"></progress>
        </div>
    </div>

    <!-- The import table -->
    <div id="output"><p><%= t('new_import.no_data') %></p></div>
</div>
</section>

</div>  <!-- the main import container div -->

<!-- Templates -->
<template id="template_importTable">
    <table class="importTable">
        <thead>
            <tr class="stickyTop">
                <th></th>
                <th class="state">
                    <span id="legendToggle"><%= t('new_import.table.row_state') %></span>
                    <div id="legend">
                        <ul>
                            <li><div class="idle"></div> <%= t('new_import.table.legend.idle') %></li>
                            <li><div class="processing"></div> <%= t('new_import.table.legend.processing') %></li>
                            <li><div class="success"></div> <%= t('new_import.table.legend.success') %></li>
                            <li><div class="partialSuccess"></div> <%= t('new_import.table.legend.partial_success') %></li>
                            <li><div class="failed"></div> <%= t('new_import.table.legend.failed') %></li>
                        </ul>
                    </div>
                </th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</template>

<template id="template_tableRow">
    <tr>
        <th class="checkbox"><input type="checkbox" title="<%= t('new_import.table.select_row') %>"></th>
        <th class="state"></th>
    </tr>
</template>

<template id="template_columnHeader">
    <th class="stickyTop">
        <div class="flex-cols flex-vcenter">
            <select id="type" title="<%= t('new_import.column_title') %>" class="flex-grow-2">
                <option value=""><%= t('new_import.columns.skip') %></option>
                <option value="first"><%= t('new_import.columns.first') %></option>
                <option value="last"><%= t('new_import.columns.last') %></option>
                <option value="uid"><%= t('new_import.columns.uid') %></option>
                <option value="role"><%= t('new_import.columns.role') %></option>
                <option value="password"><%= t('new_import.columns.password') %></option>
                <option value="eid"><%= t('new_import.columns.eid') %></option>
                <option value="group"><%= t('new_import.columns.group') %></option>
                <option value="rawgroup"><%= t('new_import.columns.rawgroup') %></option>
                <option value="licenses"><%= t('new_import.columns.licenses') %></option>
                <option value="phone"><%= t('new_import.columns.phone') %></option>
                <option value="email"><%= t('new_import.columns.email') %></option>
                <option value="pnumber"><%= t('new_import.columns.pnumber') %></option>
            </select>

            <button id="controls" class="controls" title="<%= t('new_import.column_tools') %>">&#xe822;</button>
        </div>
    </th>
</template>

<!-- A variant of the template above, used in preview tables -->
<template id="template_previewColumnHeader">
    <th>
        <div class="colType"><%= t('new_import.columns.skip') %></div>
    </th>
</template>

<template id="template_columnMenu">
    <div class="columnMenu">
        <ul>
            <!-- List all menu entries here, unused ones are removed before the menu is displayed -->
            <li><a id="fill_column"><i class="icon icon-pencil margin-right-5px"></i><%= t('new_import.menu.fill_column') %></a></li>
            <li><a id="fill_selection"><i class="icon icon-pencil margin-right-5px"></i><%= t('new_import.menu.fill_selection') %></a></li>
            <li><a id="set_role"><i class="icon icon-pencil margin-right-5px"></i><%= t('new_import.menu.set_role') %></a></li>
            <li><a id="generate_usernames"><i class="icon icon-pencil margin-right-5px"></i><%= t('new_import.menu.generate_usernames') %></a></li>
            <li><a id="fix_usernames"><i class="icon icon-exchange margin-right-5px "></i><%= t('new_import.menu.fix_usernames') %></a></li>
            <li><a id="parse_groups"><i class="icon icon-pencil margin-right-5px"></i><%= t('new_import.menu.parse_groups') %></a></li>
            <li><a id="generate_passwords"><i class="icon icon-pencil margin-right-5px"></i><%= t('new_import.menu.generate_passwords') %></a></li>
            <li><a id="add_to_group"><i class="icon icon-pencil margin-right-5px"></i><%= t('new_import.menu.add_to_group') %></a></li>
            <li><a id="clear_column"><i class="icon icon-cancel margin-right-5px"></i><%= t('new_import.menu.clear_column') %></a></li>
            <li><a id="clear_selection"><i class="icon icon-cancel margin-right-5px"></i><%= t('new_import.menu.clear_selection') %></a></li>
            <li class="separator"></li>
            <li><a id="insert_column"><i class="icon icon-plus margin-right-5px"></i><%= t('new_import.menu.insert_column') %></a></li>
            <li class="separator"></li>
            <li><a id="delete_column" class="danger"><i class="icon icon-trash margin-right-5px"></i><%= t('new_import.menu.delete_column') %></a></li>
        </ul>
    </div>
</template>

<template id="template_directCellEdit">
    <div class="flex-rows gap-5px">
        <div id="contents"></div>
        <div class="directButtons">
            <button id="save">OK (Enter)</button>
            <button id="close"><%= t('new_import.buttons.close') %></button>
        </div>
    </div>
</template>

<template id="template_directCellEditText">
    <input type="text" class="cellEdit width-100p">
</template>

<template id="template_selectRole">
    <label for="role"><%= t('new_import.tools.set_role.help') %></label>
    <select id="role" class="width-100p">
        <!-- The "admin" role has been omitted on purpose. Admins aren't meant to be mass-imported. -->
        <option value="student"><%= t('puavoEduPersonAffiliation_student') %></option>
        <option value="teacher"><%= t('puavoEduPersonAffiliation_teacher') %></option>
        <option value="staff"><%= t('puavoEduPersonAffiliation_staff') %></option>
        <option value="parent"><%= t('puavoEduPersonAffiliation_parent') %></option>
        <option value="visitor"><%= t('puavoEduPersonAffiliation_visitor') %></option>
        <option value="testuser"><%= t('puavoEduPersonAffiliation_testuser') %></option>
    </select>
</template>

<template id="template_selectGroup">
    <label for="abbr"><%= t('new_import.tools.set_group.help') %></label>
    <div class="flex-rows gap-5px">
        <select id="abbr"></select>   <!-- Filled in dynamically -->
        <button id="reload"><%= t('new_import.buttons.reload_groups') %></button>
    </div>
</template>

<template id="template_fillDialogCommon">
    <!-- List all possible headers and fill buttons. The unused are removed before the dialog is shown. -->
    <header data-for="set_role"><%= t('new_import.tools.set_role.title') %></header>
    <header data-for="set_group"><%= t('new_import.tools.set_group.title') %></header>
    <header data-for="generate_usernames"><%= t('new_import.tools.generate_usernames.title') %></header>
    <header data-for="fix_usernames"><%= t('new_import.tools.fix_usernames.title') %></header>
    <header data-for="parse_groups"><%= t('new_import.tools.parse_groups.title') %></header>
    <header data-for="generate_passwords"><%= t('new_import.tools.generate_passwords.title') %></header>
    <header data-for="fill_column"><%= t('new_import.tools.fill.title_column') %></header>
    <header data-for="fill_selection"><%= t('new_import.tools.fill.title_selection') %></header>
    <div id="columnDialog">
        <div id="contents"></div>
        <label><input type="checkbox" id="overwrite" checked><%= t('new_import.buttons.overwrite_existing') %></label>
        <div class="buttons">
            <button id="fill" data-for="set"><%= t('new_import.buttons.set') %></button>
            <button id="fill" data-for="add"><%= t('new_import.buttons.add') %></button>
            <button id="fill" data-for="generate"><%= t('new_import.buttons.generate') %></button>
            <button id="fill" data-for="fill"><%= t('new_import.buttons.fill') %></button>
            <button id="close"><%= t('new_import.buttons.close') %></button>
        </div>
    </div>
</template>

<template id="template_genericFill">
    <label for="value" id="column"><%= t('new_import.tools.fill.help_column') %></label>
    <label for="value" id="selection"><%= t('new_import.tools.fill.help_selection') %></label>
    <input type="text" id="value" class="margin-top-5px" value="">
</template>

<template id="template_generateUsernames">
    <label><%= t('new_import.tools.generate_usernames.help') %></label>
    <div class="flex-rows gap-5px margin-top-10px">
        <label><input type="radio" name="method" id="drop">ä → a, ö → o, ü → u</label>
        <label><input type="radio" name="method" id="replace">ä → ae, ö → oe, ü → ue</label>
        <label title="<%= t('new_import.tools.generate_usernames.first_first_name_only_help') %>"><input type="checkbox" id="first_first_only"><%= t('new_import.tools.generate_usernames.first_first_name_only') %></label>
    </div>
</template>

<template id="template_fixUsernames">
    <p class="margin-top-0"><%= t('new_import.tools.fix_usernames.help') %></p>

    <p><%= t('new_import.tools.fix_usernames.preview') %></p>

    <div style="overflow: scroll; min-height: 15em; max-height: 15em;">
        <table class="fixUsernamesPreview width-100p">
            <thead>
                <tr>
                    <th><%= t('new_import.columns.first') %></th>
                    <th><%= t('new_import.columns.last') %></th>
                    <th><%= t('new_import.tools.fix_usernames.uid_change') %></th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</template>

<template id="template_parseGroups">
    <label><%= t('new_import.tools.parse_groups.help') %></label>
    <div id="parseGroupsTable">
        <table>
            <tbody></tbody>     <!-- Filled in dynamically -->
        </table>
    </div>
</template>

<template id="template_generatePasswords">
    <span class="margin-left-15px">
        <label><input type="radio" name="method" id="fixed"><%= t('new_import.tools.generate_passwords.fixed') %>:</label>
        <input type="text" class="margin-left-5px font-monospace" id="fixedPassword">
    </span>

    <fieldset class="margin-top-5px margin-bottom-0">
        <legend>
            <label for="random"><input type="radio" name="method" id="random" checked><%= t('new_import.tools.generate_passwords.random') %>:</label>
        </legend>

        <div class="flex-rows gap-5px margin-top-5px">
            <label><input type="checkbox" id="uppercase"><%= t('new_import.tools.generate_passwords.uppercase') %></label>
            <label><input type="checkbox" id="lowercase"><%= t('new_import.tools.generate_passwords.lowercase') %></label>
            <label><input type="checkbox" id="numbers"><%= t('new_import.tools.generate_passwords.numbers') %></label>
            <label><input type="checkbox" id="punctuation"><%= t('new_import.tools.generate_passwords.punct') %></label>
            <div class="flex-cols flex-vcenter">
                <label><%= t('new_import.tools.generate_passwords.length') %>:</label>
                <input type="range" id="length" class="flex-grow-2 margin-left-5px"><div id="lengthValue" class="padding-5px"></div>
            </div>
        </div>
    </fieldset>
</template>

<template id="template_errors">
    <div class="problems errors">
        <p><%= t('new_import.problems.errors_title') %></p>
        <ul></ul>       <!-- Filled in dynamically -->
    </div>
</template>

<template id="template_warnings">
    <div class="problems warnings">
        <p><%= t('new_import.problems.warnings_title') %></p>
        <ul></ul>       <!-- Filled in dynamically -->
    </div>
</template>

<script>
"use strict;"

document.addEventListener('DOMContentLoaded', () => {

// Setup extra translation strings for I18n library
I18n.translations[I18n.locale] = I18n.extend((I18n.translations[I18n.locale] || {}), {
    columns: {
        first: "<%= t('new_import.columns.first') %>",
        last: "<%= t('new_import.columns.last') %>",
        uid: "<%= t('new_import.columns.uid') %>",
        role: "<%= t('new_import.columns.role') %>",
        password: "<%= t('new_import.columns.password') %>",
        eid: "<%= t('new_import.columns.eid') %>",
        group: "<%= t('new_import.columns.group') %>",
        rawgroup: "<%= t('new_import.columns.rawgroup') %>",
        licenses: "<%= t('new_import.columns.licenses') %>",
        phone: "<%= t('new_import.columns.phone') %>",
        email: "<%= t('new_import.columns.email') %>",
        pnumber: "<%= t('new_import.columns.pnumber') %>",
    },

    group_type: {
        "teaching group": "<%= t('group_type.teaching group') %>",
        "course group": "<%= t('group_type.course group') %>",
        "year class": "<%= t('group_type.year class') %>",
        "administrative group": "<%= t('group_type.administrative group') %>",
        "archive users": "<%= t('group_type.archive users') %>",
        "other groups": "<%= t('group_type.other groups') %>",
    },

    parser: {
        title: "<%= t('new_import.parser.title') %>",
        infer: "<%= t('new_import.parser.infer') %>",
        trim: "<%= t('new_import.parser.trim') %>",
        commas: "<%= t('new_import.parser.commas') %>",
        semicolons: "<%= t('new_import.parser.semicolons') %>",
        tabs: "<%= t('new_import.parser.tabs') %>",
    },

    buttons: {
        reload_groups: "<%= t('new_import.buttons.reload_groups') %>",
        reloading: "<%= t('new_import.buttons.reloading') %>",
    },

    status: {
        no_data_to_display: "<%= t('new_import.status.no_data_to_display') %>",
        fetching_current_users: "<%= t('new_import.status.fetching_current_users') %>",
        comparing_data: "<%= t('new_import.status.comparing_data') %>",
        synchronising: "<%= t('new_import.status.synchronising') %>",
        complete: "<%= t('new_import.status.complete') %>",
        aborted: "<%= t('new_import.status.aborted') %>",
        stopping: "<%= t('new_import.status.stopping') %>",
        stopping_impatient: "<%= t('new_import.status.stopping_impatient') %>",
        stopped: "<%= t('new_import.status.stopped') %>",
        success: "<%= t('new_import.status.success') %>",
        partial_success: "<%= t('new_import.status.partial_success') %>",
        failed: "<%= t('new_import.status.failed') %>",
        total_rows: "<%= t('new_import.status.total_rows') %>",
        selected_rows: "<%= t('new_import.status.selected_rows') %>",
        importing_rows: "<%= t('new_import.status.importing_rows') %>",
        table_messages: "<%= t('new_import.status.table_messages') %>",
    },

    messages: {
        already_in_school: "<%= t('new_import.messages.already_in_school') %>",
    },

    alerts: {
        already_imported: "<%= t('new_import.alerts.already_imported') %>",
        no_file: "<%= t('new_import.alerts.no_file') %>",
        no_selected_rows: "<%= t('new_import.alerts.no_selected_rows') %>",
        no_matching_rows: "<%= t('new_import.alerts.no_matching_rows') %>",
        delete_everything: "<%= t('new_import.alerts.delete_everything') %>",
        delete_selected_rows: "<%= t('new_import.alerts.delete_selected_rows') %>",
        cant_remove_rows_after_stopping: "<%= t('new_import.alerts.cant_remove_rows_after_stopping') %>",
        delete_column: "<%= t('new_import.alerts.delete_column') %>",
        are_you_sure: "<%= t('general_confirm') %>",
        resume_previous: "<%= t('new_import.alerts.resume_previous') %>",
        need_one_first_name: "<%= t('new_import.alerts.need_one_first_name') %>",
        need_one_last_name: "<%= t('new_import.alerts.need_one_last_name') %>",
        need_one_raw_group: "<%= t('new_import.alerts.need_one_raw_group') %>",
        no_groups: "<%= t('new_import.alerts.no_groups') %>",
        could_not_generate_all_usernames: "<%= t('new_import.alerts.could_not_generate_all_usernames') %>",
        unconvertible_characters: "<%= t('new_import.alerts.unconvertible_characters') %>",
        first_five: "<%= t('new_import.alerts.first_five') %>",
        unconvertible_name: "<%= raw t('new_import.alerts.unconvertible_name') %>",
        could_not_parse_all_groups: "<%= t('new_import.alerts.could_not_parse_all_groups') %>",
        same_password: "<%= t('new_import.alerts.same_password') %>",
        too_short_password: "<%= t('new_import.alerts.too_short_password') %>",
        check_something: "<%= t('new_import.alerts.check_something') %>",
        no_data_to_import: "<%= t('new_import.alerts.no_data_to_import') %>",
        fix_errors_first: "<%= t('new_import.alerts.fix_errors_first') %>",
        cant_parse_server_response: "<%= t('new_import.alerts.cant_parse_server_response') %>",
        data_retrieval_failed_unknown: "<%= t('new_import.alerts.data_retrieval_failed_unknown') %>",
        data_retrieval_failed_known: "<%= t('new_import.alerts.data_retrieval_failed_known') %>",
        too_short_uid: "<%= t('new_import.alerts.too_short_uid') %>",
        invalid_uid: "<%= t('new_import.alerts.invalid_uid') %>",
        no_data_for_the_pdf: "<%= t('new_import.alerts.no_data_for_the_pdf') %>",
        still_no_data_for_the_pdf: "<%= t('new_import.alerts.still_no_data_for_the_pdf') %>",
        empty_rows_skipped: "<%= t('new_import.alerts.empty_rows_skipped') %>",
        no_failed_rows: "<%= t('new_import.alerts.no_failed_rows') %>",
        no_selected_rows: "<%= t('new_import.alerts.no_selected_rows') %>",
        no_duplicate_uids: "<%= t('new_import.alerts.no_duplicate_uids') %>",
        passwords_out_of_sync: "<%= raw t('new_import.alerts.passwords_out_of_sync') %>",
        list_created: "<%= t('new_import.alerts.list_created') %>",
        list_missing_users: "<%= t('new_import.alerts.list_missing_users') %>",
        list_failed: "<%= t('new_import.alerts.list_failed') %>",
        list_not_found: "<%= t('new_import.alerts.list_not_found') %>",
        list_missing_users: "<%= t('new_import.alerts.list_missing_users') %>",
        list_loading_failed: "<%= t('new_import.alerts.list_loading_failed') %>",
        download_template_nothing_selected: "<%= t('new_import.alerts.download_template_nothing_selected') %>",
        server_sent_invalid_filename: "<%= t('new_import.alerts.server_sent_invalid_filename') %>",
        pdf_generation_failed: "<%= t('new_import.alerts.pdf_generation_failed') %>",
    },

    errors: {
        multiple_columns: "<%= raw t('new_import.errors.multiple_columns') %>",
        required_column_missing: "<%= raw t('new_import.errors.required_column_missing') %>",
        need_uid_column_in_update_mode: "<%= t('new_import.errors.need_uid_column_in_update_mode') %>",
        need_something_to_update_in_update_mode: "<%= t('new_import.errors.need_something_to_update_in_update_mode') %>",
        empty_first: "<%= t('new_import.errors.empty_first') %>",
        empty_last: "<%= t('new_import.errors.empty_last') %>",
        empty_uid: "<%= t('new_import.errors.empty_uid') %>",
        duplicate_uid: "<%= t('new_import.errors.duplicate_uid') %>",
        invalid_uid: "<%= t('new_import.errors.invalid_uid') %>",
        short_uid: "<%= t('new_import.errors.short_uid') %>",
        missing_role: "<%= t('new_import.errors.missing_role') %>",
        no_role_mass_change: "<%= t('new_import.errors.no_role_mass_change') %>",
        duplicate_eid: "<%= t('new_import.errors.duplicate_eid') %>",
        eid_already_in_use: "<%= t('new_import.errors.eid_already_in_use') %>",
        invalid_email: "<%= t('new_import.errors.invalid_email') %>",
        duplicate_email: "<%= t('new_import.errors.duplicate_email') %>",
        email_already_in_use: "<%= t('new_import.errors.email_already_in_use') %>",
        automatic_emails: "<%= t('new_import.errors.automatic_emails') %>",
        invalid_phone: "<%= t('new_import.errors.invalid_phone') %>",
        duplicate_phone: "<%= t('new_import.errors.duplicate_phone') %>",
        phone_already_in_use: "<%= t('new_import.errors.phone_already_in_use') %>",
        common_password: "<%= t('new_import.errors.common_password') %>",
        no_group_column: "<%= t('new_import.errors.no_group_column') %>",
        no_password_column: "<%= raw t('new_import.errors.no_password_column') %>",
    },
});

const INITIAL_GROUPS = <%= raw JSON.pretty_generate(@initial_groups) %>;

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

initializeImporter({
    container: document.getElementById("import"),
    groups: INITIAL_GROUPS,
    organisationName: "<%= LdapOrganisation.current.cn %>",
    schoolId: <%= @school.id.to_i %>,
    schoolName: "<%= @school.cn %>",
    currentUserName: "<%= current_user.givenName %> <%= current_user.sn %> (<%= current_user.uid %>)",
    <% if @automatic_email_addresses %>
    automaticEmails: true,
    <% else %>
    automaticEmails: false,
    <% end %>
    <% if @can_create_users %>
    permitUserCreation: true,
    <% else %>
    permitUserCreation: false,
    <% end %>
    commonPasswords: COMMON_PASSWORDS,
});

});
</script>
