var h=Object.defineProperty;var u=(d,e,t)=>e in d?h(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t;var o=(d,e,t)=>u(d,typeof e!="symbol"?e+"":e,t);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const r of i)if(r.type==="childList")for(const s of r.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&n(s)}).observe(document,{childList:!0,subtree:!0});function t(i){const r={};return i.integrity&&(r.integrity=i.integrity),i.referrerPolicy&&(r.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?r.credentials="include":i.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(i){if(i.ep)return;i.ep=!0;const r=t(i);fetch(i.href,r)}})();class g{constructor(e){o(this,"iframe");o(this,"iframeWrap");o(this,"overlay");o(this,"localStoragePrefix","chatwidget_");o(this,"isWidgetOpen",!1);o(this,"isFrameLoaded",!1);o(this,"ymCounterId",null);o(this,"mobileScreenSize",650);o(this,"previousIsMobile",window.innerWidth<=this.mobileScreenSize);o(this,"cacheTest","test_active");o(this,"isOnBlackFridayLanding",window.location.pathname.includes("/rko-landings/black-friday-2025"));o(this,"handleScreenSizeChange",()=>{const e=window.innerWidth<=this.mobileScreenSize;e!==this.previousIsMobile&&(this.previousIsMobile=e,this.isOnBlackFridayLanding&&!this.isWidgetOpen&&this.iframeWrap&&(this.iframeWrap.style.bottom=e?"55px":"10px"),this.sendScreenInfoMessage())});o(this,"receiveMessage",e=>{if(e.data.eventName==="chatButtonAnimation"&&this.iframeWrap)for(const t in e.data.body.styles)this.iframeWrap.style[t]=e.data.body.styles[t];if(e.data.eventName==="chatButtonClicked"&&this.iframeWrap){this.isWidgetOpen=typeof e.data.body.isWidgetOpen=="boolean"?e.data.body.isWidgetOpen:this.isWidgetOpen,this.isWidgetOpen?(document.documentElement.style.overflow=window.innerWidth{var n;const e=document.createElement("div"),t=e.style;t.position="absolute",t.width="100%",t.height="100%",t.top="0",t.left="0",t.visibility="hidden",(n=this.iframeWrap)==null||n.appendChild(e),document.addEventListener("dragenter",()=>{this.isWidgetOpen&&(e.style.visibility="visible")}),document.addEventListener("dragleave",i=>{!i.clientX&&!i.clientY&&(e.style.visibility="hidden")}),document.addEventListener("dragover",i=>{this.isWidgetOpen&&i.preventDefault()}),document.addEventListener("drop",()=>{e.style.visibility="hidden"}),e.addEventListener("dragenter",()=>{this.postMessage("dragndrop",{isShowOverlay:!0})}),e.addEventListener("dragleave",()=>{this.postMessage("dragndrop",{isShowOverlay:!1})}),e.addEventListener("drop",i=>{var r;i.preventDefault(),i.stopPropagation(),this.postMessage("dragndrop",{isShowOverlay:!1,files:(r=i.dataTransfer)==null?void 0:r.files}),e.style.visibility="hidden"}),e.addEventListener("dragover",i=>{this.isWidgetOpen&&i.preventDefault()})});this.config=e,this.ymCounterId=e.ymCounterId}debounce(e,t){let n=null;return function(...i){n!==null&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,i)},t)}}sendScreenInfoMessage(){const e=window.innerWidth;this.postMessage("screenInfoMessage",{screenWidth:e})}sendParentUrlMessage(){const e=document.location.href;this.postMessage("parentUrlInfoMessage",{parentUrl:e})}sendYmCounterIdMessage(){this.postMessage("ymCounterIdMessage",{ymCounterId:this.ymCounterId})}sendIsBlackFridayLanding(){this.postMessage("isOnBlackFridayLanding",{isOnBlackFridayLanding:!0})}sendWasClickedInfo(){this.postMessage("chatButtonWasClicked",{chatButtonWasClicked:this.getDataFromLocalStorage("chat_button_was_clicked")})}postMessage(e,t){var n;(n=this.iframe)!=null&&n.contentWindow&&this.iframe.contentWindow.postMessage({eventName:e,body:t},"*")}setDataToLocalStorage(e,t){localStorage.setItem(`${this.localStoragePrefix}${e}`,t)}getDataFromLocalStorage(e){return localStorage.getItem(`${this.localStoragePrefix}${e}`)}getRandomUUID(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(+e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+e/4).toString(16))}async fetchRequest(e,t,n){var l;const i=new URL(this.config.widgetBundleUrl),r=`${i.protocol}//${i.host}`,s=await fetch(`${r}${e}`,{method:"POST",headers:{"X-RPC-Method":t,"Content-Type":"application/json","X-Request-Id":this.getRandomUUID()},body:JSON.stringify({jsonrpc:"2.0",id:this.getRandomUUID(),method:t,params:n})});if(!s.ok)throw new Error(`Запрос завершился с причиной: ${s.statusText}, код: ${s.status}`);const a=await s.json();if(s.status===200){if(!a.error)return a.result;if(a.error){let c;throw a.error.data?c=(l=a.error.data.errors[0])==null?void 0:l.message:c=a.error.message||"Произошла неизвестная ошибка",new Error(c)}}else throw new Error(`Запрос завершился со статусом: ${s.status} ${s.statusText}`);throw new Error("Произошла неизвестная ошибка при запросе")}openWidget(){this.iframeWrap&&this.isFrameLoaded&&this.postMessage("widgetOpenedFromParent",{isOpened:!0})}async mountWidget(){const e=window.location.href.split("?")[0],t=window.innerWidth<=this.mobileScreenSize;let n;try{n=await this.fetchRequest("/api/v1/jsonrpc/misc","get_init_options",{url:e})}catch(c){console.log(`Ошибка при получении начальных опций для виджета. Подробнее: ${c}`)}if(n&&typeof n.should_init=="boolean"&&!n.should_init)return;window.addEventListener("message",this.receiveMessage);const i=this.debounce(this.handleScreenSizeChange,200);window.addEventListener("resize",i);const r=document.createElement("div");this.iframeWrap=r;const s=r.style;s.display="none",s.boxSizing="border-box",s.width="100px",s.height="100px",s.position="fixed",s.zIndex="9999",s.bottom=this.isOnBlackFridayLanding&&t?"55px":"10px",s.right="25px",s.transition="width 0.5s ease-in-out";const a=document.createElement("iframe");this.iframe=a;const l=a.style;l.boxSizing="border-box",l.width="100%",l.height="100%",l.border="0",l.margin="0",l.padding="0",r.appendChild(a),a.addEventListener("load",()=>{s.display="block",this.sendYmCounterIdMessage(),this.isOnBlackFridayLanding&&this.sendIsBlackFridayLanding(),this.sendScreenInfoMessage(),this.sendParentUrlMessage(),this.sendWasClickedInfo(),this.initDndOverlay(),this.isFrameLoaded=!0}),a.src=this.config.widgetBundleUrl,document.body.appendChild(r)}}(async()=>{const d=document.currentScript;let e,t;if(d&&(e=d.getAttribute("data-widget-url"),t=d.getAttribute("data-ym-counter-id")),window.chatWidgetSDK||(window.chatWidgetSDK=new g({widgetBundleUrl:e||"",ymCounterId:t||null})),document.readyState==="complete")try{await window.chatWidgetSDK.mountWidget()}catch(n){console.error("Ошибка инициализации виджета Точка чат",n)}else document.addEventListener("readystatechange",async()=>{if(document.readyState==="complete")try{await window.chatWidgetSDK.mountWidget()}catch(n){console.error("Ошибка инициализации виджета Точка чат",n)}})})();