<commit_before>/* global $, APP, config */

import { toJid } from '../../../react/features/base/connection';
import {
    JitsiConnectionErrors
} from '../../../react/features/base/lib-jitsi-meet';

/**
 * Build html for "password required" dialog.
 * @returns {string} html string
 */
function getPasswordInputHtml() {
    const placeholder = config.hosts.authdomain
        ? 'user identity'
        : '<EMAIL>';

    return `
        <input name="username" type="text"
               class="input-control"
               placeholder=${placeholder} autofocus>
        <input name="password" type="password"
               class="input-control"
               data-i18n="[placeholder]dialog.userPassword">`;
}

/**
 * Generate cancel button config for the dialog.
 * @returns {Object}
 */
function cancelButton() {
    return {
        title: APP.translation.generateTranslationHTML('dialog.Cancel'),
        value: false
    };
}

/**
 * Auth dialog for JitsiConnection which supports retries.
 * If no cancelCallback provided then there will be
 * no cancel button on the dialog.
 *
 * @class LoginDialog
 * @constructor
 *
 * @param {function(jid, password)} successCallback
 * @param {function} [cancelCallback] callback to invoke if user canceled.
 */
function LoginDialog(successCallback, cancelCallback) {
    const loginButtons = [ {
        title: APP.translation.generateTranslationHTML('dialog.Ok'),
        value: true
    } ];
    const finishedButtons = [ {
        title: APP.translation.generateTranslationHTML('dialog.retry'),
        value: 'retry'
    } ];

    // show "cancel" button only if cancelCallback provided
    if (cancelCallback) {
        loginButtons.push(cancelButton());
        finishedButtons.push(cancelButton());
    }

    const connDialog = APP.UI.messageHandler.openDialogWithStates(
        states, // eslint-disable-line no-use-before-define
        {
            persistent: true,
            closeText: ''
        },
        null
    );

    const states = {
        login: {
            titleKey: 'dialog.passwordRequired',
            html: getPasswordInputHtml(),
            buttons: loginButtons,
            focus: ':input:first',
            // eslint-disable-next-line max-params
            submit(e, v, m, f) {
                e.preventDefault();
                if (v) {
                    const jid = f.username;
                    const password = <PASSWORD>;

                    if (jid && password) {
                        connDialog.goToState('connecting');
                        successCallback(toJid(jid, config.hosts), password);
                    }
                } else {
                    // User cancelled
                    cancelCallback();
                }
            }
        },
        connecting: {
            titleKey: 'dialog.connecting',
            html: '<div id="connectionStatus"></div>',
            buttons: [],
            defaultButton: 0
        },
        finished: {
            titleKey: 'dialog.error',
            html: '<div id="errorMessage"></div>',
            buttons: finishedButtons,
            defaultButton: 0,
            submit(e, v) {
                e.preventDefault();
                if (v === 'retry') {
                    connDialog.goToState('login');
                } else {
                    // User cancelled
                    cancelCallback();
                }
            }
        }
    };

    /**
     * Displays error message in 'finished' state which allows either to cancel
     * or retry.
     * @param error the key to the error to be displayed.
     * @param options the options to the error message (optional)
     */
    this.displayError = function(error, options) {

        const finishedState = connDialog.getState('finished');

        const errorMessageElem = finishedState.find('#errorMessage');

        let messageKey;
<commit_msg>fix(LoginDialog.web): 'states' is passed as undefined<commit_after>/* global $, APP, config */

import { toJid } from '../../../react/features/base/connection';
import {
    JitsiConnectionErrors
} from '../../../react/features/base/lib-jitsi-meet';

/**
 * Build html for "password required" dialog.
 * @returns {string} html string
 */
function getPasswordInputHtml() {
    const placeholder = config.hosts.authdomain
        ? 'user identity'
        : '<EMAIL>';

    return `
        <input name="username" type="text"
               class="input-control"
               placeholder=${placeholder} autofocus>
        <input name="password" type="password"
               class="input-control"
               data-i18n="[placeholder]dialog.userPassword">`;
}

/**
 * Generate cancel button config for the dialog.
 * @returns {Object}
 */
function cancelButton() {
    return {
        title: APP.translation.generateTranslationHTML('dialog.Cancel'),
        value: false
    };
}

/**
 * Auth dialog for JitsiConnection which supports retries.
 * If no cancelCallback provided then there will be
 * no cancel button on the dialog.
 *
 * @class LoginDialog
 * @constructor
 *
 * @param {function(jid, password)} successCallback
 * @param {function} [cancelCallback] callback to invoke if user canceled.
 */
function LoginDialog(successCallback, cancelCallback) {
    const loginButtons = [ {
        title: APP.translation.generateTranslationHTML('dialog.Ok'),
        value: true
    } ];
    const finishedButtons = [ {
        title: APP.translation.generateTranslationHTML('dialog.retry'),
        value: 'retry'
    } ];

    // show "cancel" button only if cancelCallback provided
    if (cancelCallback) {
        loginButtons.push(cancelButton());
        finishedButtons.push(cancelButton());
    }

    const states = {
        connecting: {
            buttons: [],
            defaultButton: 0,
            html: '<div id="connectionStatus"></div>',
            titleKey: 'dialog.connecting'
        },
        finished: {
            buttons: finishedButtons,
            defaultButton: 0,
            html: '<div id="errorMessage"></div>',
            titleKey: 'dialog.error',

            submit(e, v) {
                e.preventDefault();
                if (v === 'retry') {
                    // eslint-disable-next-line no-use-before-define
                    connDialog.goToState('login');
                } else {
                    // User cancelled
                    cancelCallback();
                }
            }
        },
        login: {
            buttons: loginButtons,
            focus: ':input:first',
            html: getPasswordInputHtml(),
            titleKey: 'dialog.passwordRequired',

            submit(e, v, m, f) { // eslint-disable-line max-params
                e.preventDefault();
                if (v) {
                    const jid = f.username;
                    const password = f.password;

                    if (jid && password) {
                        // eslint-disable-next-line no-use-before-define
                        connDialog.goToState('connecting');
                        successCallback(toJid(jid, config.hosts), password);
                    }
                } else {
                    // User cancelled
                    cancelCallback();
                }
            }
        }
    };
    const connDialog = APP.UI.messageHandler.openDialogWithStates(
        states,
        {
            closeText: '',
            persistent: true
        },
        null
    );

    /**
     * Displays error message in 'finished' state which allows either to cancel
     * or retry.
     * @param error the key to the error to be displayed.
     * @param options the options to the error message (optional)
     */
    this.displayError = function(error, options) {

        const finishedState = connDialog.getState('finished');

        const errorMessageElem = finishedState.find('#errorMessage');

        let messageKey;

{'fraction_non_alphanumeric': 0.11595852301466869, 'fraction_numerical': 0.0010116337885685382, 'mean_word_length': 1.7673198040587823, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6706575', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1969, 'n_words': 489}