(function ( $ ) {

var methods = {

init: function(settings) {

// Settings
var options = $.extend( {
‘baseUrl’: ‘https://clients.aihelps.com/module2’,

‘id’: 0,
‘title’: null,
‘city’: null,
‘street’: null,
‘phone’: null,
‘logo’ : null,
‘coverImage’: null,
‘address’: null,
// sex: ‘Both’,
‘groups’ : false,
‘services’: true,
‘personalAccount’: true,
‘cancel’: true,
‘sendSMS’ : true,

‘socials’ : {
‘facebook’: true,
‘instagram’: false,
‘vkontakte’: true,
‘google’: true,
‘twitter’: true,
‘linkedin’: true
},
‘language’ : ‘en’,
‘position’ : ‘point’,
‘theme’: null, // РїРѕ умолчанию тема GREEN
‘styles’: {
wrapperBorder: ‘3px solid #676767’,
wrapperColor: ‘rgba(0,0,0,0.8)’, // уровень затмения РІРѕРєСЂСѓРі приложения — серый фон РІРѕРєСЂСѓРі формы модуля
backgroundBody: null, //цвет фона модуля
backgroundHeader: null, //цвет фона верхнего панели — хедера
buttonBackgroundColor: null, //цвет кнопок в списке
buttonBorder: null, //граница кнопок в списке
textColor: null, //цвет текста РїРѕ программе — РїРѕ умолчанию берется РёР· темы
descriptionTextColor: null, //цвет текста описания товара, мастера и тп
priceTextColor: null, // цвет текста цен
backgroundHeaderImage: null, //изображение для панели и блока каждого салона
serviceIcon: null, //фото услуги
masterIcon: null, //фото мастера
groupIcon: null, //фото группы
folderIcon: null,
sexIconFemale: null,
sexIconMale: null,
},
‘initBefore’ : null,
‘initAfter’ : null,
‘about’ :{}

}, settings);

if (options.initBefore && typeof(options.initBefore) === «function») {
options.initBefore();
}

// Check 1
if (!options.id) {
alert(‘ERROR, please, input ID of your company !’);
return;
}

var $this = $(this);

methods.load($this, options);
},

load: function($this, options) {

var iframe = document.createElement(‘iframe’);

iframe.style.minHeight = ‘500px’;
iframe.style.minWidth = ‘320px’;
iframe.style.maxWidth = ‘100%’;
iframe.style.backgroundColor = ‘#ffffff’;
iframe.style.borderWidth = ‘0’;

var strJSON = encodeURIComponent(JSON.stringify(options));

iframe.src = options.baseUrl + ‘?options=’ + strJSON;

if (options.position == ‘point’) {

iframe.style.display = «flex»;
iframe.style.height = ‘100%’;
iframe.style.width = ‘100%’;
$this.append(iframe);

} else if (options.position == ‘center-popup’) {

var wrapper = document.createElement(‘div’);

wrapper.style.position = ‘fixed’;
wrapper.style.zIndex = ‘10000’;
wrapper.style.height = ‘100%’;
wrapper.style.width = ‘100%’;
wrapper.style.left = ‘0’;
wrapper.style.top = ‘0’;
wrapper.style.overflowX = ‘hidden’;
wrapper.style.overflowY = ‘auto’;
wrapper.style.background = options.styles.wrapperColor + ‘ none repeat scroll 0 0’;
wrapper.style.flexDirection = ‘column’;
wrapper.style.justifyContent = ‘center’;
wrapper.style.display = ‘none’;

document.body.insertBefore(wrapper, document.body.firstChild);

iframe.style.height = ‘80%’;
iframe.style.width = ‘500px’;
iframe.style.margin = ‘0 auto’;
iframe.style.border = options.styles.wrapperBorder;
iframe.style.borderRadius = ‘5px’;

wrapper.appendChild(iframe);

$this.on(‘click’, function() {
wrapper.style.display = ‘flex’;
});

$(wrapper).on(‘click’, function() {
wrapper.style.display = ‘none’;
});

} else if (options.position == ‘right-slide’) {

var wrapper = document.createElement(‘div’);

wrapper.style.position = ‘fixed’;
wrapper.style.zIndex = ‘10000’;
wrapper.style.height = ‘100%’;
wrapper.style.width = ‘100%’;
wrapper.style.left = ‘0’;
wrapper.style.top = ‘0’;
wrapper.style.overflowX = ‘hidden’;
wrapper.style.overflowY = ‘auto’;
wrapper.style.background = options.styles.wrapperColor + ‘ none repeat scroll 0 0’;
wrapper.style.flexDirection = ‘column’;
wrapper.style.justifyContent = ‘center’;
wrapper.style.display = ‘none’;

document.body.insertBefore(wrapper, document.body.firstChild);

var container = document.createElement(‘div’);

container.style.zIndex = ‘10001’;
container.style.right = ‘-500px’;
container.id = ‘aihelps’;
container.style.position = ‘fixed’;
container.style.height = ‘100%’;
container.style.width = ‘500px’;
container.style.display = ‘block’;
container.style.boxShadow = ‘0 0 5px #000’;
container.style.transitionProperty = ‘right’;
container.style.transitionDuration = ‘0.8s’;
container.style.transitionTimingFunction = ‘cubic-bezier(0, 1, 0.5, 1)’;

document.body.insertBefore(container, document.body.firstChild);

var button = document.createElement(‘a’);

button.style.display = ‘none’;
button.style.position = ‘absolute’;
button.style.top = ’24px’;
button.style.left = ‘-68px’;
button.style.backgroundColor = ‘#313131’;
button.style.backgroundImage = ‘url(‘ + options.baseUrl + ‘images/close.png)’;
button.style.backgroundRepeat = ‘no-repeat’;
button.style.backgroundPosition = ‘center center’;
button.style.width = ’40px’;
button.style.height = ’40px’;
button.style.borderRadius = ‘50%’;
button.style.cursor = ‘pointer’;

container.appendChild(button);

iframe.style.height = ‘100%’;
iframe.style.width = ‘100%’;
iframe.style.border = ‘0’;
container.appendChild(iframe);

$this.on(‘click’, function() {

button.style.display = ‘block’;
wrapper.style.display = ‘block’;
container.style.right = ‘0’;
});

$(button).on(‘click’, function() {

button.style.display = ‘none’;
wrapper.style.display = ‘none’;
container.style.right = ‘-500px’;
});

$(wrapper).on(‘click’, function() {

button.style.display = ‘none’;
wrapper.style.display = ‘none’;
container.style.right = ‘-500px’;
});

} else if (options.position == ‘left-slide’) {

var wrapper = document.createElement(‘div’);

wrapper.style.position = ‘fixed’;
wrapper.style.zIndex = ‘10000’;
wrapper.style.height = ‘100%’;
wrapper.style.width = ‘100%’;
wrapper.style.left = ‘0’;
wrapper.style.top = ‘0’;
wrapper.style.overflowX = ‘hidden’;
wrapper.style.overflowY = ‘auto’;
wrapper.style.background = options.styles.wrapperColor + ‘ none repeat scroll 0 0’;
wrapper.style.flexDirection = ‘column’;
wrapper.style.justifyContent = ‘center’;
wrapper.style.display = ‘none’;

document.body.insertBefore(wrapper, document.body.firstChild);

var container = document.createElement(‘div’);

container.style.zIndex = ‘10001’;
container.style.left = ‘-500px’;
container.id = ‘aihelps’;
container.style.position = ‘fixed’;
container.style.height = ‘100%’;
container.style.width = ‘500px’;
container.style.display = ‘block’;
container.style.boxShadow = ‘0 0 5px #000’;
container.style.transitionProperty = ‘right’;
container.style.transitionDuration = ‘0.8s’;
container.style.transitionTimingFunction = ‘cubic-bezier(0, 1, 0.5, 1)’;

document.body.insertBefore(container, document.body.firstChild);

var button = document.createElement(‘a’);

button.style.display = ‘none’;
button.style.position = ‘absolute’;
button.style.top = ’24px’;
button.style.right = ‘-68px’;
button.style.backgroundColor = ‘#313131’;
button.style.backgroundImage = ‘url(‘ + options.baseUrl + ‘images/close.png)’;
button.style.backgroundRepeat = ‘no-repeat’;
button.style.backgroundPosition = ‘center center’;
button.style.width = ’40px’;
button.style.height = ’40px’;
button.style.borderRadius = ‘50%’;
button.style.cursor = ‘pointer’;

container.appendChild(button);

iframe.style.height = ‘100%’;
iframe.style.width = ‘100%’;
iframe.style.border = ‘0’;
container.appendChild(iframe);

$this.on(‘click’, function() {

button.style.display = ‘block’;
wrapper.style.display = ‘block’;
container.style.left = ‘0’;
});

$(button).on(‘click’, function() {

button.style.display = ‘none’;
wrapper.style.display = ‘none’;
container.style.left = ‘-500px’;
});

$(wrapper).on(‘click’, function() {

button.style.display = ‘none’;
wrapper.style.display = ‘none’;
container.style.left = ‘-500px’;
});
}

if (options.initAfter && typeof(options.initAfter) === «function») {
options.initAfter();
}
},

update: function() {},

destroy: function() {}
}

$.fn.aihelps = function (method) {

if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call( arguments, 1));
} else if (typeof method == ‘object’ || ! method) {
return methods.init.apply(this, arguments);
} else {
$.error(‘Method not found.’);
}
}

}( jQuery ));