const d={sm:640,md:768,lg:992,xl:1200};let h;window.innerWidth>=d.xl?h=132:window.innerWidth<d.xl?h=76:h=56;let g=0,p=null,b=!1;window.innerWidth<d.xl&&(b=!0);window.addEventListener("DOMContentLoaded",function(){b?$.get("/load-mobile-menu",{},function(t,e,n){$("#menuBar").html(t),document.querySelectorAll(".arrow-sidebar").forEach(function(i){i.addEventListener("click",function(s){s.stopPropagation(),s.preventDefault(),this.classList.toggle("active"),this.parentElement.nextElementSibling.classList.toggle("hidden")})})}):$.get("/load-category-menu",{},function(t,e,n){$("#category-navbar").html(t)})});window.addEventListener("DOMContentLoaded",function(){$("[data-ajax-url]").each(function(){let t=$(this);$.get(t.data("url"),{},function(e,n,o){t.html(e)})})});window.addEventListener("DOMContentLoaded",function(){let t=!1;function e(){window.innerWidth>d.xl?t||(t=!0,$(".slider-international-customer").slick({dots:!1,infinite:!0,speed:500,slidesToScroll:1,slidesToShow:5,responsive:[{breakpoint:769,settings:{slidesToShow:2,slidesToScroll:2}}],prevArrow:"<button type='button' class='slick-prev pull-left !hidden lg:!block' aria-label='Prev'><i class='fal fa-chevron-left'></i></button>",nextArrow:"<button type='button' class='slick-next pull-right !hidden lg:!block' aria-label='Next'><i class='fal fa-chevron-right'></i></button>"})):t&&($(".slider-international-customer").slick("unslick"),t=!1)}e(),window.addEventListener("resize",e);let n=!1;function o(){window.innerWidth>d.xl?n||(n=!0,$(".slider-customer").slick({dots:!1,infinite:!0,speed:500,slidesToScroll:1,slidesToShow:5,responsive:[{breakpoint:769,settings:{slidesToShow:2,slidesToScroll:2}}],prevArrow:"<button type='button' class='slick-prev pull-left !hidden lg:!block' aria-label='Prev'><i class='fal fa-chevron-left'></i></button>",nextArrow:"<button type='button' class='slick-next pull-right !hidden lg:!block' aria-label='Next'><i class='fal fa-chevron-right'></i></button>"})):n&&($(".slider-customer").slick("unslick"),n=!1)}o(),window.addEventListener("resize",o);let i=!1;function s(){window.innerWidth>d.xl?i||(i=!0,$(".slider-brand").slick({dots:!1,infinite:!0,speed:500,slidesToScroll:1,slidesToShow:5,responsive:[{breakpoint:992,settings:{slidesToShow:4,slidesToScroll:4}}],prevArrow:"<button type='button' class='slick-prev pull-left !hidden lg:!block' aria-label='Prev'><i class='fal fa-chevron-left'></i></button>",nextArrow:"<button type='button' class='slick-next pull-right !hidden lg:!block' aria-label='Next'><i class='fal fa-chevron-right'></i></button>"})):i&&($(".slider-brand").slick("unslick"),i=!1)}s(),window.addEventListener("resize",s);let l=!1;function r(){window.innerWidth>d.xl?l||(l=!0,$(".slider-products").slick({dots:!1,infinite:!0,speed:500,slidesToScroll:1,slidesToShow:$(".slider-products").data("slides-to-show")?$(".slider-products").data("slides-to-show"):5,touchThreshold:10,responsive:[{breakpoint:1024,settings:{slidesToShow:4,slidesToScroll:4}},{breakpoint:770,settings:{slidesToShow:3,slidesToScroll:3}},{breakpoint:640,settings:{slidesToShow:2,slidesToScroll:2}}],prevArrow:"<button type='button' class='slick-prev pull-left !hidden lg:!block' aria-label='Prev'><i class='fal fa-chevron-left'></i></button>",nextArrow:"<button type='button' class='slick-next pull-right !hidden lg:!block' aria-label='Next'><i class='fal fa-chevron-right'></i></button>"}).on("afterChange",function(c,a,u,f){u!==g&&(g=u,p||(x(),p=!0))}).on("beforeChange",function(c,a,u,f){p=null})):l&&($(".slider-products").slick("unslick"),l=!1)}r(),window.addEventListener("resize",r),$(".slider-banner").slick({dots:!0,infinite:!0,speed:500,arrows:!0,prevArrow:"<button type='button' class='slick-prev pull-left'><i class='fal fa-chevron-left' aria-label='Prev'></i></button>",nextArrow:"<button type='button' class='slick-next pull-right'><i class='fal fa-chevron-right' aria-label='Next'></i></button>"}),$(".slider-outstanding-news").slick({dots:!1,infinite:!0,speed:500,prevArrow:"<button type='button' class='slick-prev pull-left' aria-label='Prev'><i class='fal fa-chevron-left'></i></button>",nextArrow:"<button type='button' class='slick-next pull-right' aria-label='Next'><i class='fal fa-chevron-right'></i></button>"}),$(".slider-main-news").slick({dots:!1,infinite:!0,speed:500,autoplay:!1,arrows:!0,slidesToScroll:1,slidesToShow:3,responsive:[{breakpoint:1024,settings:{slidesToShow:2,slidesToScroll:2}},{breakpoint:769,settings:{slidesToShow:1,slidesToScroll:1}}],prevArrow:"<button type='button' class='slider-hover-button slider-hover-button--prev'><i class='text-lg text-dark fal fa-chevron-left'></i></button>",nextArrow:"<button type='button' class='slider-hover-button slider-hover-button--next'><i class='text-lg text-dark fal fa-chevron-right'></i></button>"}),$(".slider-category-news").slick({dots:!1,infinite:!0,speed:500,autoplaySpeed:3e3,arrows:!0,prevArrow:"<button type='button' class='left-0 top-1/2 -translate-y-full pull-left absolute lg:left-auto lg:translate-y-0 lg:!right-[28%] lg:top-0 z-10 xl:flex xl:items-center xl:justify-center xl:border-2 xl:border-slate-700 xl:rounded-full xl:w-[38px] xl:h-[38px] xl:hover:bg-slate-700 group'><i class='text-slate-700 hover:text-slate-500 xl:group-hover:text-white text-4xl xl:text-xl fal fa-chevron-left'></i></button>",nextArrow:"<button type='button' class='right-0 top-1/2 -translate-y-full pull-right absolute lg:left-auto lg:translate-y-0 lg:!right-[23%] lg:top-0 z-10 xl:flex xl:items-center xl:justify-center xl:border-2 xl:border-slate-700 xl:rounded-full xl:w-[38px] xl:h-[38px] xl:hover:bg-slate-700 group'><i class='text-slate-700 hover:text-slate-500 xl:group-hover:text-white text-4xl xl:text-xl fal fa-chevron-right'></i></button>"}),$(".slider-single").slick({slidesToShow:1,slidesToScroll:1,infinite:!1,arrows:!0,fade:!1,adaptiveHeight:!0,useTransform:!0,speed:500,cssEase:"cubic-bezier(0.77, 0, 0.18, 1)",prevArrow:"<button type='button' class='large-detail-slide-btn slick-prev pull-left !translate-x-[5px]'  aria-label='Previous'><i class='text-3xl text-primary fal fa-chevron-left'></i></button>",nextArrow:"<button type='button' class='large-detail-slide-btn slick-next pull-right !translate-x-[-9px]' aria-label='Next'><i class='text-3xl text-primary fal fa-chevron-right'></i></button>"}),$(".slider-nav").on("init",function(c,a){$(".slider-nav .slick-slide.slick-current").addClass("is-active")}).slick({slidesToShow:10,slidesToScroll:1,infinite:!1,dots:!1,focusOnSelect:!0,swipeToSlide:!0,arrows:!1,responsive:[{breakpoint:d.md,settings:{slidesToShow:7}}]}),$(".slider-single").on("afterChange",function(c,a,u){$(".slider-nav").slick("slickGoTo",u);var f='.slider-nav .slick-slide[data-slick-index="'+u+'"]';$(".slider-nav .slick-slide.is-active").removeClass("is-active"),$(f).addClass("is-active")}),$(".slider-nav").on("click",".slick-slide",function(c){c.preventDefault();var a=$(this).data("slick-index");$(".slider-single").slick("slickGoTo",a)}),$(".slick-next").click(function(){$(".slider-single").slick("slickNext")}),$(".slick-prev").click(function(){$(".slider-single").slick("slickPrev")})});window.addEventListener("DOMContentLoaded",y);function y(){document.querySelectorAll(".js-toggle").forEach(t=>{const e=t.getAttribute("data-toggle-target");e||(document.body.innerText=`Cần thêm data-toggle-target cho: ${t.outerHTML}`),t.onclick=()=>{if(!document.querySelector(e))return document.body.innerText=`Không tìm thấy phần tử "${e}"`;const n=document.querySelector(e).classList.contains("hide");requestAnimationFrame(()=>{document.querySelector(e).classList.toggle("hide",!n),document.querySelector(e).classList.toggle("show",n),t.classList.toggle("hide",!n),t.classList.toggle("show",n)})}})}y();const v=document.querySelector("#category-navbar");function w(){if(window.location.pathname!=="/"&&window.location.pathname!=="/main-news/"&&window.location.pathname!=="/t/"||window.innerWidth<d.xl)return;(document.documentElement.scrollTop||document.body.scrollTop)>50?v.style.display="none":v.style.display="block"}window.addEventListener("DOMContentLoaded",w);window.onscroll=w;window.addEventListener("DOMContentLoaded",()=>{const t=document.querySelectorAll(".toggleButton");t&&t.forEach(e=>{e&&e.addEventListener("click",function(){const n=e.querySelector("span").textContent==="Xem tất cả";e.querySelector("span").textContent=n?"Thu gọn":"Xem tất cả";const o=n?"fa-chevron-up":"fa-chevron-down";e.querySelector("i").classList=`text-sm fas ${o}`})})});window.addEventListener("DOMContentLoaded",()=>{const t=document.querySelectorAll(".js-toggle-btn");t&&t.forEach(e=>{e&&e.addEventListener("click",function(){const o=e.querySelector("i").classList.contains("fa-angle-up")?"fa-angle-down":"fa-angle-up";e.querySelector("i").classList=`fa ${o}`})})});document.addEventListener("DOMContentLoaded",function(){let t;const e=document.querySelectorAll(".js-dialog-button"),n=document.querySelectorAll(".js-dialog-close"),o=document.querySelector("#js-btn-confirm");if(!e||!n)return;function i(l){l.style.opacity=1,l.style.visibility="visible",document.documentElement.style.overflowY="hidden"}function s(l){l.style.opacity=0,l.style.visibility="hidden",document.documentElement.style.overflowY=""}e.forEach(l=>{l.addEventListener("click",function(){const r=this.getAttribute("data-dialog-id"),c=document.querySelector(`#${r}`);c&&(t=l.dataset.id,i(c))})}),n.forEach(l=>{l.addEventListener("click",function(){const r=this.getAttribute("data-dialog-id"),c=document.querySelector(`#${r}`);c&&s(c)})}),window.addEventListener("click",function(l){e.forEach(r=>{const c=r.getAttribute("data-dialog-id"),a=document.querySelector(`#${c}`);a&&l.target==a&&s(a)})}),o&&o.addEventListener("click",function(){const l=this.getAttribute("data-dialog-id"),r=document.querySelector(`#${l}`);r&&fetch("/remove_cart/"+t).then(function(){s(r),location.href="/cart/"}).catch(function(){location.href="/cart/"})})});document.addEventListener("DOMContentLoaded",function(){const t=document.querySelectorAll("#storeList .js-showroom-btn"),e=document.getElementById("district"),n=document.getElementById("mapIframe");if(!t||!e||!n)return;t[0].classList.add("text-white","bg-gradient");function o(s){n.src=s}function i(s){const l=s.currentTarget;t.forEach(c=>c.classList.remove("text-white","bg-gradient","active")),l.classList.add("text-white","bg-gradient","active");const r=l.getAttribute("data-iframe-link");o(r)}t.forEach(s=>{s.addEventListener("click",i)}),e.addEventListener("change",function(){const s=e.value;t.forEach(r=>{r.style.display="none"}),t.forEach(r=>{(r.getAttribute("data-place")===s||s==="all")&&(r.style.display="flex")});const l=Array.from(t).filter(r=>r.style.display!=="none");l.length>0&&l[0].click()})});document.addEventListener("DOMContentLoaded",function(){const t=document.getElementById("score-rating");if(!t)return;function e(){document.querySelectorAll('input[name="rating"]').forEach(o=>{o.addEventListener("change",i=>{const s=document.querySelector('input[name="rating"]:checked').value;t.innerHTML=s})})}e()});document.addEventListener("DOMContentLoaded",function(){const t=document.getElementById("scroll-top-btn");function e(){window.scrollY>100?t.style.display="flex":t.style.display="none"}e(),window.addEventListener("scroll",e),t.addEventListener("click",()=>{window.scrollTo({top:0,behavior:"smooth"})})});document.addEventListener("DOMContentLoaded",function(){const t=document.querySelector("#header-pc"),e=document.querySelector("#search-btn-mobile"),n=document.querySelector("#search-input-mobile"),o=document.querySelector("#clear-search-btn");!t||!e||!n||!o||(e.addEventListener("click",function(){t.style.display="none",n.style.display="flex"}),o.addEventListener("click",function(){t.style.display="flex",n.style.display="none"}))});document.addEventListener("DOMContentLoaded",function(){const t=document.querySelector("#search-btn-on-dialog"),e=document.querySelector("#menuBar"),n=document.querySelector("#header-pc"),o=document.querySelector("#search-input-mobile");!t||!e||!n||!o||t.addEventListener("click",function(){e.classList.remove("show"),e.classList.add("hide"),n.style.display="none",o.style.display="flex"})});document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".arrow-sidebar").forEach(function(e){e.addEventListener("click",function(n){n.stopPropagation(),n.preventDefault(),this.classList.toggle("active"),this.parentElement.nextElementSibling.classList.toggle("hidden")})})});document.addEventListener("DOMContentLoaded",function(){const t=document.querySelectorAll(".js-input-quantity"),e=document.querySelectorAll(".js-decrease-quantity-btn");document.querySelectorAll(".js-increase-quantity-btn").forEach(function(o){o.addEventListener("click",function(){const i=this.parentElement.querySelector(".js-input-quantity"),s=parseInt(i.value,10);i.value=s+1,i.dispatchEvent(new Event("change"))})}),e.forEach(function(o){o.addEventListener("click",function(){const i=this.parentElement.querySelector(".js-input-quantity"),s=parseInt(i.value,10);s>1&&(i.value=s-1,i.dispatchEvent(new Event("change")))})}),t.forEach(function(o){o.addEventListener("change",function(){const i=parseInt(o.value,10);i<1||isNaN(i)?o.value=old_value:(o.value=i,fetch("/cart/"+o.dataset.id+"/"+i).then(function(){location.href="/cart/"}).catch(function(){location.href="/cart/"}))})})});document.addEventListener("DOMContentLoaded",function(){const t=document.getElementById("popover-btn"),e=document.getElementById("popover"),n=document.getElementById("backdrop"),o=document.getElementById("close-popover-btn");if(!t||!e||!n)return;function i(){const l=t.getBoundingClientRect(),r=10,c=l.top+window.scrollY-h-r;window.scrollTo({top:c,behavior:"smooth"})}t.addEventListener("click",function(){window.innerWidth<d.lg||i()});let s=tippy(t,{theme:"light",content:e,placement:"top-start",interactive:!0,trigger:"click",animation:"scale",duration:300,arrow:!0,onShow(l){n.classList.toggle("hidden"),e.classList.toggle("hidden")},onHide(l){e.classList.add("hidden"),n.classList.add("hidden")}});o.addEventListener("click",function(){s.hide()})});document.addEventListener("DOMContentLoaded",function(){const t=document.querySelector("#footer-service"),e=document.querySelector("#footer-product");!t||!e||window.innerWidth<=1024&&(t.classList.add("toggle-box","hide"),e.classList.add("toggle-box","hide"))});document.addEventListener("DOMContentLoaded",function(){const t=()=>{document.documentElement.style.setProperty("--window-height",`${window.innerHeight}px`)};window.addEventListener("resize",t),t()});document.addEventListener("DOMContentLoaded",function(){const t=document.querySelectorAll(".small-image-list");!t||!$(".slider-products")||t.forEach(function(e){e.addEventListener("wheel",function(i){i.stopPropagation(),this.scrollLeft+=i.deltaY,i.preventDefault()}),["touchstart","touchmove","mousemove"].forEach(function(i){e.addEventListener(i,function(s){$(".slider-products").slick("slickSetOption","swipe",!1,!1)})}),["touchend","mouseover"].forEach(function(i){e.addEventListener(i,function(s){$(".slider-products").slick("slickSetOption","swipe",!0,!1)})})})});function x(){document.querySelectorAll(".product-item").forEach((e,n)=>{const o=e.querySelectorAll(".small-image-list img"),i=e.querySelectorAll(".small-image-list li"),s=e.querySelector(".large-image"),l=e.querySelectorAll(".product-url");!o||!s||!i||!l||o.forEach(function(r,c){r.addEventListener("mouseover",function(){const a=this.dataset.origin;s.src=a;const u=this.dataset.url;l.forEach(function(f){f.href=u}),i.forEach(function(f){f.classList.remove("border-primary")}),i[c].classList.remove("border-slate-200"),i[c].classList.add("border-primary")})})})}x();document.addEventListener("DOMContentLoaded",function(){const t=document.getElementById("js-gallery-single-height");t&&setTimeout(function(){const e=t.offsetHeight;document.querySelectorAll(".gallery-single-image").forEach(function(o){o.style.setProperty("--max-height-gallery-single-image",`${e}px`)})},0)});$(document).ready(function(){m(".kos-search-form"),m(".kos-search-form-mobile")});function m(t){const e=$(t),n=e.find(".search-box"),o=e.find(".clear-search");let i;o.click(function(){e.find("input").val(""),n.addClass("hidden"),$(this).addClass("hidden")}),e.on("input",function(){o.removeClass("hidden"),clearTimeout(i),n.find(".search-box-list").html(""),i=setTimeout(function(){const s=e.find("input").val();$.trim(s)!==""?$.ajax({url:"/products/live_search",data:{s},dataType:"json",method:"GET",success:function(l){let r;$.each(l,function(c,a){r=$("#search-product-template").html(),r=$(r),r.find("img").attr("src",a.thumbnail),r.find("a").attr("href",a.url),r.find(".product-name").html(a.name),r.find(".product-price").html(a.formatted_price),n.find(".search-box-list").append(r)}),r?(n.find(".search-view-all").removeClass("hidden").attr("href","/products/search?s="+s),n.find(".search-view-all span").text("Xem tất cả kết quả")):(n.find(".search-view-all span").text("Không tìm thấy kết quả"),n.find(".search-view-all").removeClass("hidden").attr("href","javascript:void(0)")),n.removeClass("hidden")},error:function(l){console.error("Error fetching data:",l)}}):n.addClass("hidden")},500)})}
