"use strict";(self.webpackChunkLHCReactAPP=self.webpackChunkLHCReactAPP||[]).push([[941],{5941:function(e,t,a){a.r(t);var n,r=a(3029),i=a(2901),s=a(6822),o=a(3954),c=a(5361),d=a(6540),p=a(1225),h=a(5580);function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(l=function(){return!!e})()}var m=(0,p.Ng)((function(e){return{chatwidget:e.chatwidget}}))(n=function(e){function t(e){return(0,r.A)(this,t),a=this,n=t,i=[e],n=(0,o.A)(n),(0,s.A)(a,l()?Reflect.construct(n,i||[],(0,o.A)(a).constructor):n.apply(a,i));var a,n,i}return(0,c.A)(t,e),(0,i.A)(t,[{key:"getDocument",value:function(e){return e.contentWindow?e.contentWindow.document:e.contentDocument?e.contentDocument:e.document?e.document:null}},{key:"insertCssRemoteFile",value:function(e,t){var a=null;if(t.id&&t.href&&null!==(a=e.getElementById(t.id)))a.href=t.href;else{var n=e.getElementsByTagName("head")[0],r=e.createDocumentFragment(),i=e.createElement("link");for(var s in i.rel="stylesheet",i.crossOrigin="*",t)i[s]=t[s];r.appendChild(i),n.appendChild(r)}}},{key:"insertJSFile",value:function(e,t,a,n){var r=e.getElementsByTagName("head")[0],i=e.createDocumentFragment(),s=e.createElement("script");s.type="text/javascript",void 0!==a&&!0!==a||(s.async=!0),s.crossOrigin="*",s.src=t,n&&(delete n.src,void 0!==n.async&&delete n.async,Object.keys(n).forEach((function(e){s.setAttribute(e,n[e])}))),i.appendChild(s),r.appendChild(i)}},{key:"prepareIframe",value:function(e){var t=this,a=this.getDocument(e);a.getElementsByTagName("head")[0].innerHTML='<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />';var n=a.getElementsByTagName("html")[0];n.setAttribute("lang","en"),n.setAttribute("dir","ltr");var r=document.implementation.createDocumentType("html","","");return a.doctype?a.replaceChild(r,a.doctype):a.insertBefore(r,a.childNodes[0]),this.props["data-css"]&&JSON.parse(this.props["data-css"]).forEach((function(e){t.insertCssRemoteFile(a,e)})),this.props["data-js"]&&JSON.parse(this.props["data-js"]).forEach((function(e){t.insertJSFile(a,e.src,!!e.async&&e.async,e)})),a.body.innerHTML=this.props["data-body"],a}},{key:"prependURL",value:function(){var e=[],t="?",a=this.props.chatwidget.get("jsVars");return Object.keys(a).forEach((function(t){e.push("jsvar["+t+"]="+encodeURIComponent(a[t]))})),e.length>0&&(t=t+"&"+e.join("&")),this.props.chatwidget.hasIn(["chatData","id"])&&(t=t+"&chat_id="+this.props.chatwidget.getIn(["chatData","id"])+"&hash="+this.props.chatwidget.getIn(["chatData","hash"])+"&msg_id="+this.props["data-id"]),t}},{key:"componentDidMount",value:function(){var e=this,t=document.createElement("iframe");if(this.props["data-form"]&&(t.src=this.props["data-form"]+this.prependURL()),t.onload=function(){if(!e.props["data-form"])for(var a=e.prepareIframe(t).body.getElementsByClassName("lhc-iframe-close"),n=0;n<a.length;n++)a[n].addEventListener("click",(function(){(0,h.X)({id:e.props.chatwidget.getIn(["chatData","id"]),hash:e.props.chatwidget.getIn(["chatData","hash"]),msg_id:e.props["data-id"]},{action:"iframe_close"}).then((function(){e.props.updateMessage(e.props["data-id"])}))}));var r=document.getElementById("messages-scroll");if(null!==r&&(r.scrollTop=r.scrollHeight+1e3),!e.props["data-form"]&&e.props["data-js-body"]){var i=documentFrame.createElement("script");i.textContent=e.props["data-js-body"],documentFrame.head.appendChild(i)}},t.onerror=function(){console.log("Something wrong happened")},this.props["data-style"]&&(t.style=this.props["data-style"]),this.props["data-iframe"]){var a=JSON.parse(this.props["data-iframe"]);if(a.one_per_chat&&1==a.one_per_chat&&a["iframe-identifier"])for(var n=document.getElementsByClassName(a["iframe-identifier"]),r=function(t){n[t].parentNode&&(0,h.X)({id:e.props.chatwidget.getIn(["chatData","id"]),hash:e.props.chatwidget.getIn(["chatData","hash"]),msg_id:n[t].getAttribute("data-msg-id")},{action:"iframe_close"}).then((function(){e.props.updateMessage(n[t].getAttribute("data-msg-id"))}))},i=0;i<n.length;i++)r(i);a["iframe-identifier"]&&(t.className=a["iframe-identifier"]),t.setAttribute("data-msg-id",this.props["data-id"])}document.getElementById("iframe-msg-"+this.props["data-id"]).appendChild(t)}},{key:"render",value:function(){return this.props.t,d.createElement("div",{id:"iframe-msg-"+this.props["data-id"]})}}])}(d.Component))||n;t.default=m}}]);
//# sourceMappingURL=941.4a7e68cf912c762c1ece.js.map