(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(d.type,d.props,d.key,null,d.__v):d)){if(d.__=n,d.__b=n.__b+1,null===(p=y[c])||p&&d.key==p.key&&d.type===p.type)y[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={},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&&(log("Parent: Received event emission: "+o),o in e.events&&e.events[o].call(e,r))},this.parent.addEventListener("message",this.listener,!1),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(){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,log("Child: Registering API"),log("Child: Awaiting messages..."),this.child.addEventListener("message",(function(t){if(sanitize(t,e.parentOrigin)){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){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),log("Parent: Received handshake reply from Child"),r.parent.removeEventListener("message",e,!1),r.childOrigin=i.origin,log("Parent: Saving Child origin",r.childOrigin),t(new ParentAPI(r))):(log("Parent: Invalid handshake reply"),a("Failed handshake")))}),!1);var s=function(){i++,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=_,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 s(t){return o=5,d((function(){return{current:t}}),[])}function d(e,n){var r=m(t++,7);return k(r.__H,n)&&(r.__=e(),r.__H=n,r.__h=e),r.__}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]=e&&(n.current=r,t.apply(void 0,arguments))}}var Button=function(t){var e,n=t.settings,r=t.visibility,o=t.loading,i=t.showApp,a=_slicedToArray(l(!1),2),s=a[0],_=a[1],c=useThrottle((function(){s||(_(!0),i(n.wcchatID))}),1e3),u=n.available_agent?n.tabTooltip:n.tabOffline;y((function(){r.button||_(!1)}),[r]);var p=n.show_tab&&isPermittedDomain(n),d={get buttonClasses(){var t=[styles.button_main];return p?(r.button?t.push(styles.slideIn):t.push(styles.slideOut),"left"===n.tabPosition&&t.push(styles.button_left),"right"===n.tabPosition&&t.push(styles.button_right),o&&s&&t.push(styles.initLoadMain),t.join(" ")):(t.push(styles.window_hidden),t.join(" "))},get iconClasses(){var t=[styles.button_icon];return o&&s&&t.push(styles.initLoadBtn),t.join(" ")}};return a$1("button",{className:null!==(e=d.buttonClasses)&&void 0!==e?e:styles.window_hidden,style:"background-color: ".concat(n.tabColor),onClick:c},n.tabImageURL&&a$1("img",{src:n.tabImageURL,alt:n.altText,className:styles.image_tab}),a$1("span",{className:d.iconClasses},!o&&a$1("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 511.999 511.999"},a$1("path",{d:"M372.29 50.758H28.831C12.933 50.758 0 63.691 0 79.588v206.056c0 15.897 12.933 28.831 28.831 28.831h22.271v76.71a12.08 12.08 0 0020.619 8.541l85.251-85.25h17.104c6.671 0 12.078-5.407 12.078-12.078 0-6.672-5.409-12.079-12.078-12.079 0 0-22.69.016-22.927.04a12.03 12.03 0 00-7.722 3.498l-68.169 68.169s-.021-60.392-.06-60.705c-.545-6.166-5.717-11.002-12.024-11.002H28.831a4.679 4.679 0 01-4.674-4.674V79.588a4.679 4.679 0 014.674-4.674H372.29a4.679 4.679 0 014.674 4.674v79.055c0 6.671 5.409 12.078 12.078 12.078s12.078-5.407 12.078-12.078V79.588c0-15.897-12.933-28.83-28.83-28.83z"}),a$1("path",{d:"M483.169 198.492H242.754c-15.897 0-28.831 12.933-28.831 28.831v140.57c0 15.897 12.933 28.831 28.831 28.831h150.514l60.98 60.98a12.075 12.075 0 0013.163 2.618 12.08 12.08 0 007.456-11.159v-52.44h8.301c15.897 0 28.831-12.933 28.831-28.831v-140.57c.001-15.897-12.932-28.83-28.83-28.83zm4.675 169.401a4.68 4.68 0 01-4.674 4.674h-20.376c-6.356 0-11.554 4.912-12.031 11.147-.031.264-.051 36.29-.051 36.29l-43.854-43.855c-.046-.046-.094-.089-.14-.135a9.54 9.54 0 00-.489-.445 12.02 12.02 0 00-7.951-3.003H242.754a4.679 4.679 0 01-4.674-4.674v-140.57a4.679 4.679 0 014.674-4.674H483.17a4.68 4.68 0 014.674 4.674v140.571z"}),a$1("path",{d:"M362.964 285.53c-6.667 0-12.078 5.411-12.078 12.078s5.411 12.078 12.078 12.078c6.668 0 12.078-5.411 12.078-12.078s-5.411-12.078-12.078-12.078zm-52.492-154.919H90.65c-6.67 0-12.078 5.407-12.078 12.078s5.409 12.078 12.078 12.078h219.822c6.67 0 12.078-5.407 12.078-12.078s-5.408-12.078-12.078-12.078zm-136.397 79.854H90.65c-6.67 0-12.078 5.407-12.078 12.078 0 6.671 5.409 12.078 12.078 12.078h83.425c6.671 0 12.078-5.407 12.078-12.078s-5.408-12.078-12.078-12.078zm132.762 75.065c-6.666 0-12.078 5.411-12.078 12.078s5.412 12.078 12.078 12.078c6.668 0 12.078-5.411 12.078-12.078s-5.41-12.078-12.078-12.078zm112.242 0c-6.667 0-12.078 5.411-12.078 12.078s5.411 12.078 12.078 12.078c6.668 0 12.078-5.411 12.078-12.078s-5.411-12.078-12.078-12.078z"})),o&&a$1("svg",{width:"1em",height:"1em",viewBox:"0 0 1024 1024",className:styles.button_icon_rotate},a$1("path",{d:"M988 548c-19.9 0-36-16.1-36-36c0-59.4-11.6-117-34.6-171.3a440.45 440.45 0 0 0-94.3-139.9a437.71 437.71 0 0 0-139.9-94.3C629 83.6 571.4 72 512 72c-19.9 0-36-16.1-36-36s16.1-36 36-36c69.1 0 136.2 13.5 199.3 40.3C772.3 66 827 103 874 150c47 47 83.9 101.8 109.7 162.7c26.7 63.1 40.2 130.2 40.2 199.3c.1 19.9-16 36-35.9 36z",fill:"currentColor"}))),a$1("span",{className:styles.button_text},a$1("span",null,o?"Cargando":u)))},Button$1=mapStateToProps$3(Button),mapStateToProps$2=preact_2((function(t){return{get instances(){return Object.keys(t).map((function(e){return t[e]}))}}}),actions),ButtonList=function(t){return a$1(y$1,null,t.instances.map((function(t){var e=t.settings,n=t.visibility,r=t.loading;return a$1(Button$1,{settings:e,visibility:n,loading:r})})))},ButtonList$1=mapStateToProps$2(ButtonList),mapStateToProps$1=preact_2((function(){return{}}),actions),ChatWindow=function(t){var e=t.settings,n=t.visibility,r=_slicedToArray(l(!1),2),o=r[0],i=r[1],a={get windowClasses(){var t=[styles.window_main];return o||t.push(styles.window_hidden),n.app||t.push(styles.window_main_disabled),"left"===e.tabPosition&&t.push(styles.window_left),"right"===e.tabPosition&&t.push(styles.window_right),n.faq&&t.push(styles.show_faqs),t.join(" ")},get frameClasses(){var t=[styles.frame_main];return n.app&&(i(!0),t.push(styles.slideIn)),!n.app&&o&&t.push(styles.slideOut),"left"===e.tabPosition&&t.push(styles.frame_left),"right"===e.tabPosition&&t.push(styles.frame_right),t.join(" ")}};return a$1("div",{className:a.windowClasses},a$1("div",{className:a.frameClasses,id:e.wcchatID}))},ChatWindow$1=mapStateToProps$1(ChatWindow),mapStateToProps=preact_2((function(t){return{get instances(){return Object.keys(t).map((function(e){return t[e]}))}}}),actions),WindowList=function(t){return a$1(y$1,null,t.instances.map((function(t){var e=t.settings,n=t.visibility,r=t.loading;return a$1(ChatWindow$1,{settings:e,visibility:n,loading:r})})))},WindowList$1=mapStateToProps(WindowList),App=function(){return a$1(preact_3,{store:store},a$1(y$1,null,a$1(ButtonList$1,null),a$1(WindowList$1,null)))},setImmediate=function(t){return setTimeout(t,0)},ChatManager=function(){return{init:function(t){var e=store.getState();if(0===Object.keys(e).length){var n=document.getElementById("wcx-chat");N(a$1(App,null),n)}if(void 0===e[t.wcchatID]){var r={button:t.show_tab&&isPermittedDomain(t),app:!1},o=getCookie("".concat(t.wcchatID,"_wcx-chat-visibility"));if(store.setState(Object.assign(Object.assign({},e),_defineProperty({},t.wcchatID,{settings:t,visibility:r,loading:!1}))),!o){var i=new CustomEvent("wcxChatReady");if(document.dispatchEvent(i),!t.automatic_chat)return}if(t.automatic_chat&&t.automatic_chat_time>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)})();