import { closeUserFeedback } from '../../popupManager';
import config from '../../config';
import global from '../../global';
/**
* @memberOf Useris
* @function init
* @description Initialization method of Useris.
* Please note thtat this method has to be called
* before any other methods and you should pass a configuration object.
*
* @param {Object} options configuration object
* @param {Object} [options.regexObject]
* Contains all the regular expressions for input validation
* (msisdn, pin, email, password and generic regex are allowed)
* @param {Object} [options.logger] A different logger by console (optional)
* @param {string} [options.domain=''] webapp domain
* @param {string} [options.country=''] country of the webapp
* @param {boolean} [options.enableAliasCheck=0] to activate the alias features (INDIAN case)
* @param {string} [options.aliasCheckUrl=''] api url of the alias
* @param {boolean} [options.disablePinInput=0] enable/disable the input PIN for the login (PT case)
* @param {boolean} [options.hybridnews=0] used in hybrid environment
* @param {string} [options.store_type=''] used in hybrid environment
* @param {string} [options.apikey=''] api key of the webapp
* @param {boolean} [options.enableGoogleCheckbox=0]
* enable/disable the Google Checkbox during the login flow
* @param {boolean} [options.identityFbEnabled=0] enable/disable Facebook users
* @param {boolean} [options.emailIdentityEnabled=0] enable/disable the email identity
* @param {boolean} [options.redirectRegisterToMipAtStart=0]
* enable/disable the smstemplate on addidentity
* @param {boolean} [options.operatorList=0] enable/disable the operator login selection
* @param {boolean} [options.addUsernameEnabled=0] enable/disable the add username feature
*
* @example
* Useris.init({
* domain: 'www.domain.com',
* country: 'ww',
* enableAliasCheck: 0,
* aliasCheckUrl: 'http://www.aliascheckurl.api/',
* disablePinInput: 0,
* hybridnews: 0,
* store_type: 'itunes',
* apikey: api_key,
* enableGoogleCheckbox: 0,
* emailIdentityEnabled: 1,
* identityFbEnabled: 1,
* redirectToMipRegisterAtStart: 0,
* logger: console,
* regexObject: {
* msisdn: '.',
* pin: '.',
* email: '.',
* password: '.',
* generic: '.',
* genericPassword: '.'
* }
* });
*/
export default (options) => {
const regexObject = {
msisdn: '.',
pin: '.',
email: '.',
password: '.',
generic: '.',
genericPassword: '.'
};
const popupClose = document.getElementById('user-feedback-close');
if (popupClose) {
popupClose.addEventListener('click', closeUserFeedback);
}
if (typeof options !== 'undefined') {
if (typeof options.regexObject === 'undefined') {
options.regexObject = regexObject;
}
if (typeof options.aliasCheckUrl !== 'undefined') {
if (options.aliasCheckUrl.indexOf('?') > 0) {
options.aliasCheckUrl = options.aliasCheckUrl.split('?')[0]; // eslint-disable-line prefer-destructuring
}
}
if (typeof options.logger !== 'undefined') {
global.setLogger(options.logger);
}
}
config.init(options);
};