function initTopSlider(){function e(){for(let t=0;t<u;t++)r[t].style.display=t>=n&&t<n+f?"flex":"none"}function h(){n=(n+1)%(u-f+1);e()}function c(){setCookie("HideTopSlider","true",600);t.style.display="none"}const t=document.getElementById("sliderContainer"),i=document.getElementById("sliderContent"),r=i?i.children:[],u=r.length,f=5;let n=0;t.style.display="block";e();const o=document.getElementById("btnCloseSlider"),s=document.getElementById("btnNextSlide");o&&o.addEventListener("click",c);s&&s.addEventListener("click",h)}document.addEventListener("DOMContentLoaded",function(){if(window.location.pathname!=="/"&&!window.location.pathname.toLowerCase().includes("/default")&&getCookie("HideTopSlider")!=="true"){const t=document.getElementById("topSlider");if(t){const n=new XMLHttpRequest;n.open("GET","/NewsV2/GetTopNews",!0);n.setRequestHeader("Accept","application/json");n.onload=function(){if(n.status===200)try{const i=JSON.parse(n.responseText);if(!Array.isArray(i))return;let r=`<div class="topslider-container relative w-100-100 overflow z-1 ht85" id="sliderContainer"><div class="topslider-content listutility3" id="sliderContent">${i.map((n,t)=>`<div class="topslide ht85" style="display: none;"><img src="${n.ImageUrl}" alt="Article ${t+1}"><a class="topslide-content lh-1-3 overflow" href="${n.Url}" target="_blank">${n.Title}</a></div>`).join("")}</div><button class="close-topslider white cursor" id="btnCloseSlider">Đóng ✕</button><button class="slider-next white cursor" id="btnNextSlide">›</button></div>`;t.innerHTML=r;initTopSlider()}catch(i){console.error("Lỗi phân tích JSON:",i)}else console.error("Lỗi khi gọi API:",n.statusText)};n.onerror=function(){console.error("Lỗi kết nối đến máy chủ.")};n.send()}}})