let options = {"bot":"#fff","pos":"right","wid":"E","chat":"#efefef","name":"\u041c\u0430\u0440\u0438\u044f","post":"\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043e\u043b\u043b-\u0446\u0435\u043d\u0442\u0440\u0430","user":"#ffc10736","photo":"1.jpg","wcsrf":"34b1d35ab9","width":"450px","header":"#484545","display":"block","timeout":2,"welcome":"\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041c\u0430\u0440\u0438\u044f, \u044f \u043e\u043d\u043b\u0430\u0439\u043d \u043a\u043e\u043d\u0441\u0443\u043b\u044c\u0442\u0430\u043d\u0442","name_btn":"\u041e\u043d\u043b\u0430\u0439\u043d-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a!","chat_color":"black","name_color":"white","post_color":"white","show_timeout":1} 
    , url = '/widget/consultant/'
    , domen = 'https://pirozhki.top'
;

 domen = domen+url;
 generate();
//console.log(url, domen, options);

function incBody(url) {
    var script = document.createElement('script');
    script.src = url;
    document.getElementsByTagName('body')[0].appendChild(script);
    return script;

}
function link(url){
	var link = document.createElement('link');
	link.rel = 'stylesheet';
	link.type = 'text/css';
	link.href = url;
  var head = document.getElementsByTagName('head')[0];
  if (head){
        head.appendChild(link);
  } else {
        document.createElement('head');
        link(url);
  }
  return link;
}

function div(){
    let elem = document.createElement('div');
    return elem;
  }
  function img(){
    let elem = document.createElement('img');
    return elem;
  }


function generate(){
    styles = link(domen+'css/gen.css'); 
    styles.onload=function(){
      
    widget = div();
    widget.className='widget_c2020';
    widget.id = 'id_widget_c2020';
    widget.style.cssText = options.pos+':50px';

    box_application = div();
    box_application.className='box_application_c2020';
    box_application.id='box_online_c2020';
    box_application.style.width = options.width;
    widget.append(box_application);
    
    header = div();
    header.className = 'header_c2020';
    header.style.backgroundColor = options.header;
    header.id='id_header_c2020';
    img_consultant = div();
    img_consultant.className='img_consultant_c2020';
    img_consultant2 = img();
    img_consultant2.id = 'id_img_consultant_c2020';
    img_consultant2.src=domen+'img/'+options.photo;
    badge_indicator = document.createElement('span');
    badge_indicator.className = 'badge_indicator_c2020';
    img_consultant.appendChild(badge_indicator);
    img_consultant.appendChild(img_consultant2);
    header.appendChild(img_consultant);
    
    box_application.appendChild(header);
    
    name_consultant = div();
    block_div = div();
    name_consultant.className='name_consultant_c2020'
    name_consultant.id = 'id_name_consultant_c2020';
    name_consultant.style.color = options.name_color;
    name_consultant.textContent = options.name;
    el_div = div();
    el_div.id = 'id_post_c2020';
    el_div.className = 'style_post_c2020';
    el_div.style.color = options.post_color;
    el_div.textContent = options.post;
    block_div.appendChild(name_consultant);
    block_div.appendChild(el_div);
    header.appendChild(block_div);
    

    close_widget = div();
    close_widget.className = 'close_widget_c2020';
    close_widget.id = 'id_close_widget_c2020';
    close_widget.textContent='Закрыть';
    header.appendChild(close_widget);

    chat = div();
    chat.className = 'chat_c2020';
    chat.id = 'id_chat_c2020';
    chat.style.color = options.chat_color;
    chat.style.backgroundColor = options.chat;
    box_application.appendChild(chat);

    box_message = div();
    box_message.className = 'box_message_c2020';
    box_application.appendChild(box_message);

    box_area = div();
    box_area.className = 'box_area_c2020 flex';
    box_message.appendChild(box_area);
    
    chars_count = div();
    chars_count.className = 'chars_count_c2020';
    box_message.appendChild(chars_count);

    chat_area = document.createElement('textarea');
    chat_area.id = 'chat_area_c2020';
    chat_area.placeholder='Ваше сообщение';
    box_area.appendChild(chat_area);

    btn_send = div();
    btn_send.className = 'btn_send_c2020';
    box_area.appendChild(btn_send);

    widget_send = document.createElement('a');
    widget_send.href = '#';
    widget_send.className = 'widget_send_c2020';
    widget_send.id = 'id_widget_send_c2020';
    widget_send.textContent = 'Отправить';
    btn_send.appendChild(widget_send);
    box_message.appendChild(btn_send);
    
    btn = div();
    btn.className = 'btn_c2020';
    btn.id = 'id_btn_c2020';
    if (options.pos == 'right'){
      btn.style.cssText = ' margin: 10px 0 0 auto';
    } else {
      btn.style.cssText = ' margin: 10px auto 0 0';
    }
    img_show = div();
    img_show.className = 'img_show_c2020';
    pulse_pirozki = div();
    pulse_pirozki.className = 'pulse-pirozhki';
    img_question = document.createElement('img');
    img_question.setAttribute('src',domen+'img/question.svg');
    pulse_pirozki.appendChild(img_question);
    span = document.createElement('span');
    span.style.fontSize = '14px';
    span.style.fontWeight = 'bold';
    span.id = 'id_name_btn';
    span.textContent = options.name_btn;
    img_show.appendChild(pulse_pirozki);
    img_show.appendChild(span);
    btn.appendChild(img_show);
    widget.appendChild(btn);

    document.getElementsByTagName('body')[0].appendChild(widget);
	document.getElementById('id_widget_c2020').style.display = options.display;
	script = incBody (domen+'js/v2render.js');
    script.onload=function(){
    incBody (domen+'js/v2ajax.js'); 
    }
  }
    
} 
