(function(){"use strict";function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_unsupportedIterableToArray(t,e)||_nonIterableRest()}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _iterableToArrayLimit(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],r=!0,o=!1,i=void 0;try{for(var a,s=t[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==s.return||s.return()}finally{if(o)throw i}}return n}}function _unsupportedIterableToArray(t,e){if(t){if("string"==typeof t)return _arrayLikeToArray(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(t,e):void 0}}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n3)for(n=[n],i=3;i0?v$1(f.type,f.props,f.key,null,f.__v):f)){if(f.__=n,f.__b=n.__b+1,null===(p=v[c])||p&&f.key==p.key&&f.type===p.type)v[c]=void 0;else for(u=0;u3)for(n=[n],i=3;i4?e.protocol:window.location.protocol,r=e.host.length?"80"===e.port||"443"===e.port?e.hostname:e.host:window.location.host;return e.origin||n+"//"+r},sanitize=function(t,e){return t.origin===e&&("object"==typeof t.data&&("postmate"in t.data&&(t.data.type===messageType&&!!{"handshake-reply":1,call:1,emit:1,reply:1,request:1}[t.data.postmate])))},resolveValue=function(t,e){var n="function"==typeof t[e]?t[e]():t[e];return Postmate.Promise.resolve(n)},ParentAPI=function(){function t(t){var e=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},"production"!==process.env.NODE_ENV&&(log("Parent: Registering API"),log("Parent: Awaiting messages...")),this.listener=function(t){var n=((t||{}).data||{}).value||{},r=n.data,o=n.name;"emit"===t.data.postmate&&("production"!==process.env.NODE_ENV&&log("Parent: Received event emission: "+o),o in e.events&&e.events[o].call(e,r))},this.parent.addEventListener("message",this.listener,!1),"production"!==process.env.NODE_ENV&&log("Parent: Awaiting event emissions from Child")}var e=t.prototype;return e.get=function(t){var e=this;return new Postmate.Promise((function(n){var r=generateNewMessageId();e.parent.addEventListener("message",(function t(o){o.data.uid===r&&"reply"===o.data.postmate&&(e.parent.removeEventListener("message",t,!1),n(o.data.value))}),!1),e.child.postMessage({postmate:"request",type:messageType,property:t,uid:r},e.childOrigin)}))},e.call=function(t,e){this.child.postMessage({postmate:"call",type:messageType,property:t,data:e},this.childOrigin)},e.on=function(t,e){this.events[t]=e},e.destroy=function(){"production"!==process.env.NODE_ENV&&log("Parent: Destroying Postmate instance"),window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},t}(),ChildAPI=function(){function t(t){var e=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,"production"!==process.env.NODE_ENV&&(log("Child: Registering API"),log("Child: Awaiting messages...")),this.child.addEventListener("message",(function(t){if(sanitize(t,e.parentOrigin)){"production"!==process.env.NODE_ENV&&log("Child: Received request",t.data);var n=t.data,r=n.property,o=n.uid,i=n.data;"call"!==t.data.postmate?resolveValue(e.model,r).then((function(e){return t.source.postMessage({property:r,postmate:"reply",type:messageType,uid:o,value:e},t.origin)})):r in e.model&&"function"==typeof e.model[r]&&e.model[r].call(e,i)}}))}return t.prototype.emit=function(t,e){"production"!==process.env.NODE_ENV&&log('Child: Emitting Event "'+t+'"',e),this.parent.postMessage({postmate:"emit",type:messageType,value:{name:t,data:e}},this.parentOrigin)},t}(),Postmate=function(){function t(t){var e=t.container,n=void 0===e?void 0!==n?n:document.body:e,r=t.model,o=t.url;return this.parent=window,this.frame=document.createElement("iframe"),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=r||{},this.sendHandshake(o)}return t.prototype.sendHandshake=function(e){var n,r=this,o=resolveOrigin(e),i=0;return new t.Promise((function(t,a){r.parent.addEventListener("message",(function e(i){return!!sanitize(i,o)&&("handshake-reply"===i.data.postmate?(clearInterval(n),"production"!==process.env.NODE_ENV&&log("Parent: Received handshake reply from Child"),r.parent.removeEventListener("message",e,!1),r.childOrigin=i.origin,"production"!==process.env.NODE_ENV&&log("Parent: Saving Child origin",r.childOrigin),t(new ParentAPI(r))):("production"!==process.env.NODE_ENV&&log("Parent: Invalid handshake reply"),a("Failed handshake")))}),!1);var s=function(){i++,"production"!==process.env.NODE_ENV&&log("Parent: Sending handshake attempt "+i,{childOrigin:o}),r.child.postMessage({postmate:"handshake",type:messageType,model:r.model},o),i===maxHandshakeRequests&&clearInterval(n)},_=function(){s(),n=setInterval(s,500)};r.frame.attachEvent?r.frame.attachEvent("onload",_):r.frame.onload=_,"production"!==process.env.NODE_ENV&&log("Parent: Loading frame",{url:e}),r.frame.src=e}))},t}();function setCookie(t,e,n){var r=new Date;r.setTime(r.getTime()+24*n*60*60*1e3);var o=t+"="+e+"; "+("expires="+r.toUTCString());document.cookie=o}function getCookie(t){for(var e=t+"=",n=document.cookie.split(";"),r=0;r=r.__.length&&r.__.push({}),r.__[t]}function l(t){return o=1,p(w$1,t)}function p(e,n,r){var o=m(t++,2);return o.t=e,o.__c||(o.__=[r?r(n):w$1(void 0,n),function(t){var e=o.t(o.__[0],t);o.__[0]!==e&&(o.__=[e,o.__[1]],o.__c.setState({}))}],o.__c=u),o.__}function y(e,r){var o=m(t++,3);!n.__s&&k(o.__H,r)&&(o.__=e,o.__H=r,u.__H.__h.push(o))}function x(){i.forEach((function(t){if(t.__P)try{t.__H.__h.forEach(g),t.__H.__h.forEach(j),t.__H.__h=[]}catch(e){t.__H.__h=[],n.__e(e,t.__v)}})),i=[]}n.__b=function(t){u=null,c&&c(t)},n.__r=function(e){f&&f(e),t=0;var n=(u=e.__c).__H;n&&(n.__h.forEach(g),n.__h.forEach(j),n.__h=[])},n.diffed=function(t){e&&e(t);var o=t.__c;o&&o.__H&&o.__H.__h.length&&(1!==i.push(o)&&r===n.requestAnimationFrame||((r=n.requestAnimationFrame)||function(t){var e,n=function(){clearTimeout(r),b&&cancelAnimationFrame(e),setTimeout(t)},r=setTimeout(n,100);b&&(e=requestAnimationFrame(n))})(x)),u=void 0},n.__c=function(t,e){e.some((function(t){try{t.__h.forEach(g),t.__h=t.__h.filter((function(t){return!t.__||j(t)}))}catch(r){e.some((function(t){t.__h&&(t.__h=[])})),e=[],n.__e(r,t.__v)}})),a&&a(t,e)},n.unmount=function(t){v&&v(t);var e=t.__c;if(e&&e.__H)try{e.__H.__.forEach(g)}catch(t){n.__e(t,e.__v)}};var b="function"==typeof requestAnimationFrame;function g(t){var e=u;"function"==typeof t.__c&&t.__c(),u=e}function j(t){var e=u;t.__c=t.__(),u=e}function k(t,e){return!t||t.length!==e.length||e.some((function(e,n){return e!==t[n]}))}function w$1(t,e){return"function"==typeof e?e(t):e}function C(t,e){for(var n in e)t[n]=e[n];return t}function S(t,e){for(var n in t)if("__source"!==n&&!(n in e))return!0;for(var r in e)if("__source"!==r&&t[r]!==e[r])return!0;return!1}function E(t){this.props=t}(E.prototype=new p$1).isPureReactComponent=!0,E.prototype.shouldComponentUpdate=function(t,e){return S(this.props,t)||S(this.state,e)};var w=n.__b;n.__b=function(t){t.type&&t.type.__f&&t.ref&&(t.props.ref=t.ref,t.ref=null),w&&w(t)};var A=n.__e;function O(){this.__u=0,this.t=null,this.__b=null}function L(t){var e=t.__.__c;return e&&e.__e&&e.__e(t)}function D(){this.u=null,this.o=null}n.__e=function(t,e,n){if(t.then)for(var r,o=e;o=o.__;)if((r=o.__c)&&r.__c)return null==e.__e&&(e.__e=n.__e,e.__k=n.__k),r.__c(t,e);A(t,e,n)},(O.prototype=new p$1).__c=function(t,e){var n=e.__c,r=this;null==r.t&&(r.t=[]),r.t.push(n);var o=L(r.__v),i=!1,a=function(){i||(i=!0,n.componentWillUnmount=n.__c,o?o(s):s())};n.__c=n.componentWillUnmount,n.componentWillUnmount=function(){a(),n.__c&&n.__c()};var s=function(){if(!--r.__u){if(r.state.__e){var t=r.state.__e;r.__v.__k[0]=function t(e,n,r){return e&&(e.__v=null,e.__k=e.__k&&e.__k.map((function(e){return t(e,n,r)})),e.__c&&e.__c.__P===n&&(e.__e&&r.insertBefore(e.__e,e.__d),e.__c.__e=!0,e.__c.__P=r)),e}(t,t.__c.__P,t.__c.__O)}var e;for(r.setState({__e:r.__b=null});e=r.t.pop();)e.forceUpdate()}},_=!0===e.__h;r.__u++||_||r.setState({__e:r.__b=r.__v.__k[0]}),t.then(a,a)},O.prototype.componentWillUnmount=function(){this.t=[]},O.prototype.render=function(t,e){if(this.__b){if(this.__v.__k){var n=document.createElement("div"),r=this.__v.__k[0].__c;this.__v.__k[0]=function t(e,n,r){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach((function(t){"function"==typeof t.__c&&t.__c()})),e.__c.__H=null),null!=(e=C({},e)).__c&&(e.__c.__P===r&&(e.__c.__P=n),e.__c=null),e.__k=e.__k&&e.__k.map((function(e){return t(e,n,r)}))),e}(this.__b,n,r.__O=r.__P)}this.__b=null}var o=e.__e&&a$1(y$1,null,t.fallback);return o&&(o.__h=null),[a$1(y$1,null,e.__e?null:t.children),o]};var F=function(t,e,n){if(++n[1]===n[0]&&t.o.delete(e),t.props.revealOrder&&("t"!==t.props.revealOrder[0]||!t.o.size))for(n=t.u;n;){for(;n.length>3;)n.pop()();if(n[1]0)return void setTimeout((function(){actions(store).showApp(store.getState(),t.wcchatID);var e=new CustomEvent("wcxChatReady");document.dispatchEvent(e)}),1e3*t.automatic_chat_time);(r=JSON.parse(o)).app&&setImmediate((function(){actions(store).showApp(store.getState(),t.wcchatID)}))}var a=new CustomEvent("wcxChatReady");document.dispatchEvent(a)},getInstances:function(){var t=store.getState();return Object.keys(t).map((function(t){return{showApp:function(){var e=store.getState();return actions(store).showApp(e,t)},id:t,getState:function(){return store.getState()[t]},setUserData:function(e){var n=store.getState()[t];if(n){var r=n.connection;r&&r.call("setUserData",JSON.stringify(e))}},setFields:function(e){var n=store.getState()[t];if(n){var r=n.connection;r&&r.call("setFields",JSON.stringify(e))}},onReady:function(t){document.addEventListener("ready",t)},finishChatSession:function(){var e=store.getState()[t];if(e){var n=e.connection;n&&n.call("finishChatSession")}},refreshVisibility:function(){var e=isPermittedDomain(store.getState()[t].settings),n=document.querySelector(".".concat(styles.button_main));if(n){if(e&&n.classList.contains(styles.window_hidden))return void n.classList.remove(styles.window_hidden);if(!e&&!n.classList.contains(styles.window_hidden))return void n.classList.add(styles.window_hidden)}}}}))}}};void 0===window.wcxChat&&(window.wcxChat=ChatManager(),Object.defineProperty(window,"_wcchat",{get:function(){return _slicedToArray(window.wcxChat.getInstances(),1)[0]}}));var container=document.createElement("div");container.id="wcx-chat",document.body.appendChild(container);var event=new CustomEvent("wcxChatLoaded");document.dispatchEvent(event)})();