(()=>{var t=null,e=null,n="chatling-chat-iframe",l=null,i=null,o=null,r=null,a=null,c="chatling-open-chat-icon",s="chatling-close-chat-icon",d=null;null==d&&(d="1.2.3");var u=null,p=!1,h=640,y="chtl_cus",m="chtl_opened",v="chtl_chats",f="chtl_aghmc",g=null,b=null;function x(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"*";try{null!=e&&e.contentWindow.postMessage(t,n)}catch(t){p&&console.error("Error posting message:",t.message)}}function w(){try{return window.innerWidth}catch(t){return null}}function _(){var t=w();return null!==t&&t<h}function C(){try{e&&(e.style.display="none"),document.getElementById(n).style.display="none"}catch(t){}!function(){try{o?o.style.display="flex":document.getElementById(c).style.display="flex",r?r.style.display="none":document.getElementById(s).style.display="none"}catch(t){}}()}function k(){try{e?e.style.display="block":document.getElementById(n).style.display="block",S(m,!0,30),E("hide"),x({event_id:"chtl_chat_widget_opened"})}catch(t){}!function(){try{o?o.style.display="none":document.getElementById(c).style.display="none",_()||(r?r.style.display="flex":document.getElementById(s).style.display="flex")}catch(t){}}(),null!=u&&clearTimeout(u)}function E(t){var l;try{null!=a&&("hide"==t?(a.style.display="none",S(f,!0,30)):"show"==t&&!1===function(){try{if(e){if("block"==e.style.display)return!0}else if("block"==document.getElementById(n).style.display)return!0}catch(t){p&&console.error(t.message)}return!1}()&&!1==(1==(l=I(f))||"true"==l)&&(a.style.display="block"))}catch(t){p&&console.error(t.message)}}function A(){var t=I(v),e=[];if(null==t)return e;try{var n=atob(t);if(null==n||0==n.length)return e;var l=JSON.parse(n);return null==l?e:l}catch(t){return e}}function S(t,e,n){var l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"Strict",i="";if(n){var o=new Date;o.setTime(o.getTime()+24*n*60*60*1e3),i=";expires="+o.toUTCString()}var r=null;try{null!=(r=window.location.hostname)&&0!=r.length||(r=location.hostname)}catch(t){}null!=r&&r.length>0&&(document.cookie=t+"="+(e||"")+i+";path=/;domain=.".concat(r,";SameSite=").concat(l))}function I(t){var e=document.cookie,n=t+"=",l=e.indexOf("; "+n);if(-1==l){if(0!=(l=e.indexOf(n)))return null}else{l+=2;var i=document.cookie.indexOf(";",l);-1==i&&(i=e.length)}return decodeURI(e.substring(l+n.length,i))}window.addEventListener("message",(function(t){try{if("chtl_chat_minimized"===(null==t?void 0:t.data))C();else{var n;if(null==(null==t?void 0:t.data))return;var i=null==t||null===(n=t.data)||void 0===n?void 0:n.event_id;if(null==i)return;if("chtl_new_chat"==i){var o,r=null==t||null===(o=t.data)||void 0===o?void 0:o.data;if(null!=r)!function(t,e){var n=A();null==n&&(n=[]);(n=[]).push({chat_gid:t,customer_gid:e,created_at:Date.now()});var l=JSON.stringify(n),i=btoa(l);S(v,i,30)}(null==r?void 0:r.chat_gid,null)}else if("chtl_customer_info_collected"==i){var a,c,s=null==t||null===(a=t.data)||void 0===a||null===(c=a.data)||void 0===c?void 0:c.customer;if(null!=s)try{for(var d in s)null===s[d]&&delete s[d];var u=JSON.stringify(s),p=btoa(u);S(y,p,30)}catch(t){}}else if("chtl_loaded"==i){if(null!=e){var h,m;if(null!=l)if(1==(null===(h=l)||void 0===h||null===(m=h.collect_user_details)||void 0===m?void 0:m.enabled)){var f=I(y);null!=f&&x({event_id:"chtl_cust_load",cust:f,custgid:null})}_()&&x({event_id:"is_mobile",window_width:w()}),null!=g&&g.length>0&&x({event_id:"chtl_conversation_history",lcg:b,messages:g})}}else"chtl_chat_cleared"==i&&(k=v,document.cookie=k+"=; Max-Age=-99999999;")}}catch(t){}var k})),function(){var d=document.getElementById("chatling-embed-script");if(!d)return;if(!(t=d.getAttribute("data-id")))return;try{var h=function(){try{var t=A();return null==t||0==t.length?null:t[t.length-1]}catch(t){return null}}();null!=h&&(b=h.chat_gid)}catch(t){}var y={widget_id:t,lcg:b};fetch("https://api.chatling.ai/public/embed/chatbot/setup",{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(y)}).then((function(d){try{d.json().then((function(d){if(null!=d&&null!=(null==d?void 0:d.success)&&0!=d.success){var h=null==d?void 0:d.data;if(null!=h){try{var y=null==h?void 0:h.chat;if(null!=y){var v=null==y?void 0:y.messages;null!=v&&v.length>0&&(g=v)}}catch(t){}l=h,function(t){var e=t.chat_icon.url,n=t.position.value,l=t.position.x,d=t.position.y;if(null!=l)try{l=parseInt(l)}catch(t){}if(null!=d)try{d=parseInt(d)}catch(t){}var u=t.primary_color,h=t.chat_icon.border_radius,y=t.chat_icon.size,m=t.chat_icon.color;(i=document.createElement("div")).style.position="fixed",i.style.zIndex="9999999","bl"==n?(i.style.bottom="".concat(d,"px"),i.style.left="".concat(l,"px")):"tl"==n?(i.style.top="".concat(d,"px"),i.style.left="".concat(l,"px")):"tr"==n?(i.style.top="".concat(d,"px"),i.style.right="".concat(l,"px")):(i.style.bottom="".concat(d,"px"),i.style.right="".concat(l,"px"));(o=document.createElement("div")).setAttribute("id",c),o.style.display="flex",o.style.justifyContent="center",o.style.alignItems="center",o.style.cursor="pointer",o.style.backgroundColor="".concat(u),o.style.borderRadius="".concat(h);var v=document.createElement("div");v.style.height="".concat(y,"px"),v.style.width="".concat(y,"px"),v.style.cursor="pointer",v.style.borderRadius="".concat(h);var f=v.cloneNode(!0);if(null==e){v.style.display="flex",v.style.justifyContent="center",v.style.alignItems="center",v.style.backgroundColor="".concat(u);var g=document.documentElement;(g=document.createElementNS("http://www.w3.org/2000/svg","svg")).setAttribute("style","transition: width ease-in-out 0.05s; width: ".concat(y/2,"px; height: ").concat(y/2,"px;")),g.setAttribute("viewBox","0 0 820 760"),g.setAttribute("fill","none");var b=document.createElementNS("http://www.w3.org/2000/svg","path");b.setAttribute("d","M400 0C179.44 0 9.84565e-05 161.493 9.84565e-05 360C9.84565e-05 429.4 21.9601 496.613 63.5734 554.72C55.6934 641.88 34.5734 706.587 3.90677 737.24C-0.146568 741.293 -1.1599 747.493 1.4001 752.613C3.6801 757.187 8.33343 760 13.3334 760C13.9468 760 14.5734 759.96 15.2001 759.867C20.6001 759.107 146.04 741.04 236.76 688.693C288.293 709.48 343.173 720 400 720C620.56 720 800 558.507 800 360C800 161.493 620.56 0 400 0Z"),b.setAttribute("fill",m),g.appendChild(b),v.appendChild(g)}else v.style.backgroundImage="url(".concat(e,")"),v.style.backgroundSize="cover",v.style.backgroundRepeat="no-repeat",v.style.backgroundPosition="center";(r=o.cloneNode(!0)).setAttribute("id",s),f.style.display="flex",f.style.justifyContent="center",f.style.alignItems="center",f.style.backgroundColor="".concat(u);var x=document.documentElement;(x=document.createElementNS("http://www.w3.org/2000/svg","svg")).setAttribute("style","width: ".concat(.33*y,"px; height: ").concat(.33*y,"px;")),x.setAttribute("viewBox","0 0 537 537"),x.setAttribute("fill","none");var A=document.createElementNS("http://www.w3.org/2000/svg","path");A.setAttribute("d","M41.1666 495.834L496.167 40.8335"),A.setAttribute("stroke",m),A.setAttribute("stroke-width","81.6667"),A.setAttribute("stroke-linecap","round"),A.setAttribute("stroke-linejoin","round"),x.appendChild(A);var S=document.createElementNS("http://www.w3.org/2000/svg","path");S.setAttribute("d","M496.167 495.834L41.1666 40.8335"),S.setAttribute("stroke",m),S.setAttribute("stroke-width","81.6667"),S.setAttribute("stroke-linecap","round"),S.setAttribute("stroke-linejoin","round"),x.appendChild(S),f.appendChild(x),r.appendChild(f),o.style.display="flex",r.style.display="none",o.appendChild(v),i.appendChild(o),i.appendChild(r),document.body.appendChild(i),function(t){try{var e=null==t?void 0:t.attention_grabber;if(null==e)return;var n,l,o=null==e?void 0:e.delay,r=!1;if(_())r=null==e||null===(n=e.mobile)||void 0===n?void 0:n.enabled;else r=null==e||null===(l=e.desktop)||void 0===l?void 0:l.enabled;if(!0!==r)return;var c=null==e?void 0:e.messages;if(null==c||0==c.length)return;if(0==(c=c.filter((function(t){return null!=t&&(null!=(t=t.trim())&&0!=t.length)}))).length)return;var s=350,d=w();(a=document.createElement("div")).style.position="absolute",a.style.right="0px",a.style.bottom="70px",a.style.display="none",null!=d&&_()?(s>d&&(s=d-25),a.style.width="".concat(s,"px")):a.style.width="".concat(s,"px");var u=document.createElement("div");u.style.position="absolute",u.style.right="0px",u.style.top="-25px",u.style.zIndex="1",u.style.cursor="pointer",u.style.background="#ffffff",u.style.borderRadius="999px",u.style.padding="5px",u.style.border="1px solid #e7ebf0",u.style.display="flex",u.style.alignItems="center",u.style.justifyContent="center",u.setAttribute("id","cthl-hovering-message-close-btn");var h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("style","width: 8px; height: 8px;"),h.setAttribute("viewBox","0 0 16 16"),h.setAttribute("fill","none");var y=document.createElementNS("http://www.w3.org/2000/svg","path");y.setAttribute("d","M2 14L14 2M2 2L14 14"),y.setAttribute("stroke","#aeaeae"),y.setAttribute("stroke-width","3"),y.setAttribute("stroke-linecap","round"),y.setAttribute("stroke-linejoin","round"),h.appendChild(y),u.appendChild(h),a.appendChild(u);var m=document.createElement("div");m.style.cursor="pointer";var v=0;c.forEach((function(t){var e=document.createElement("div");e.style.padding="10px 15px",e.style.position="relative",e.style.borderRadius="5px",e.style.marginTop=0==v?"0px":"7px",e.style.backgroundColor="#ffffff",e.style.fontSize="14.5px",e.style.color="#000000",e.style.border="1px solid #e6e9ee",e.style.boxShadow="-2px 0px 10px rgba(0, 0, 0, 0.05)",e.style.mozBoxShadow="-2px 0px 10px rgba(0, 0, 0, 0.05)",e.innerHTML=t,v++,m.appendChild(e)})),m.addEventListener("click",(function(){k()})),i.appendChild(a),a.appendChild(m),u.addEventListener("click",(function(){E("hide")})),(null==o||o<0)&&(o=0),setTimeout((function(){E("show")}),1e3*o)}catch(t){p&&console.error(t.message)}}(t),v.addEventListener("click",(function(){k()})),f.addEventListener("click",(function(){C()}))}(h),function(l){var i=l.position.value,o=l.position.x,r=l.position.y;if(null!=o)try{o=parseInt(o)}catch(t){}if(null!=r)try{r=parseInt(r)}catch(t){}var a=l.chat_icon.size,c=20,s=l.chat_interface.width,d=s,u=700,p=u,h=r+a+c;null!=r&&(p=window.innerHeight-h-50)>u&&(p=u);(e=document.createElement("iframe")).src="https://embed.chatling.ai/widgets/".concat(t),e.style.display="none",e.style.border="none",e.style.position="fixed","bl"==i?(e.style.bottom="".concat(h,"px"),e.style.left="".concat(o,"px")):"tl"==i?(e.style.top="".concat(h,"px"),e.style.left="".concat(o,"px")):"tr"==i?(e.style.top="".concat(h,"px"),e.style.right="".concat(o,"px")):(e.style.bottom="".concat(h,"px"),e.style.right="".concat(o,"px"));e.style.height="80vh",e.style.minHeight="80px",e.style.maxHeight="".concat(p,"px"),e.style.zIndex="9999999",e.style.overflow="hidden",e.style.width="100%",e.style.maxWidth="".concat(d,"px"),e.style.borderRadius="15px",e.setAttribute("id",n),e.addEventListener("load",(function(){e.style.boxShadow="rgba(0, 0, 0, 0.01) 0px 5px 10px 0px, rgba(0, 0, 0, 0.1) 0px 7px 12px 0px"})),document.body.appendChild(e)}(h),function(t){var e="@media all and (max-width: 640px) {\n        #chatling-chat-iframe { \n            width: 100% !important;\n            max-width: initial !important;\n            right: 0px !important;\n            top: 0px !important;\n            left: 0 !important;\n            bottom: 0px !important;\n            max-height: initial !important;\n            height: 100% !important;\n            border-radius: 0px !important;\n        }\n    }",n=document.createElement("style");n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e));document.head.appendChild(n)}(),function(t){try{var e=null==t?void 0:t.auto_open;if(null!=e){var n=null==e?void 0:e.enable_on_desktop,l=null==e?void 0:e.enable_on_mobile,i=null==e?void 0:e.delay,o=null==e?void 0:e.behavior;if((null==i||i<0)&&(i=0),"open_once"==o&&function(){var t=I(m);if(1==t||"true"==t)return!0;return!1}())return;_()?l&&(u=setTimeout((function(){k()}),1e3*i)):n&&(u=setTimeout((function(){k()}),1e3*i))}}catch(t){}}(h)}}}))}catch(t){console.error("Error setting up chatbot:",t.message)}})).catch((function(t){console.error("Error loading chatbot:",t.message)}))}()})();