
  // LAZY LOADING
  lazy_load_group.push(
    {
      id: 'js-article-home',
      target: '#js-article-home',
      loadFn: function () {
        getTopAricleList();
      },
    },
    {
      id: 'js-article-small-top',
      target: '#js-article-small-top',
      loadFn: function () {
        articleTopMainSmall();
      },
    },
    {
      id: 'js-video-featured-',
      target: '#js-video-featured-',
      loadFn: function () {
        getFeaturedVideo();
      },
    },
    {
      id: 'js-new-article',
      target: '#js-new-article',
      loadFn: function () {
        getNewArticleHome();
      },
    },
    {
      id: 'js-product-hot-article',
      target: '#js-product-hot-article',
      loadFn: function () {
        productHot();
      },
    },
     {
        id: 'js-article-small-home',
        target: '#js-article-small-home',
        loadFn: function () {
          getBottomAricleList();
        },
      },
      {
        id: 'js-article-middle-right',
        target: '#js-article-middle-right',
        loadFn: function () {
          articleCatRight();
        },
      },
  
   
  )

  // SWIPER ARTICLE TOP
  function swiperArticle() {
    new Swiper(".swiper-article", {
      slidesPerView: 1,
      spaceBetween: 10,
      centeredSlides: true,
      loop: true,
      speed: 1000,
      autoplay: {
        delay: 2500,
        disableOnInteraction: false,
        pauseOnMouseEnter: "true",
      },
      pagination: {
        el: ".swiper-pagination",
        clickable: true,
      },
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
    });
  }
  swiperArticle();

  // GET ARTICLE TOP NEAR SWIPER
  function getTopAricleList() {
    var params = {
      action_type: 'list',
      type: 'article',
      featured: 1,
      show: 1
    }
    var target = "#js-article-home";
    Hura.Ajax.get("article", params).then(function (data) {
      var html = Hura.Template.parse(articleMainTop, data.list.splice(0, 3));
      Hura.Template.render(target, html);
    });
  }
  
  // GET ARTICLE TOP NEAR SWIPER
  function getBottomAricleList() {
    var params = {
      action_type: 'list',
      type: 'article',
      featured: 1,
      show: 8,
    }
    var target = "#js-article-small-home";
    Hura.Ajax.get("article", params).then(function (data) {
      var html = Hura.Template.parse(articleMainBottom, data.list.splice(0,3));
      Hura.Template.render(target, html);
    });
  }
 


  // GET ARTICLE COL LEFT 
  function articleTopMainSmall() {
    var params = {
      action_type: 'list',
      type: 'article',
      featured: 1,
      show: 18
    }
    var target = "#js-article-small-top";
    Hura.Ajax.get("article", params).then(function (data) {
      var html = Hura.Template.parse(articleMainSmall, data.list.splice(0, 3));
      Hura.Template.render(target, html);
    });
  }

  // GET FEATURED VIDEO
  function getFeaturedVideo() {
    var params = {
      action_type: "featured",
      type: "article",
      show: 10,
    };
    var smallTarget = "#js-video-featured-";
    Hura.Ajax.get("article", params).then(function (data) {
      var html = Hura.Template.parse(featureVideo, data.splice(0, 3));
      Hura.Template.render(smallTarget, html);
    });
  }

  // TIN MỚI NHẤT  
  function getNewArticleHome() {
    var params = {
      action_type: "featured",
      type: "article",
      show: 18,
    };

    var target = "#js-new-article";
    Hura.Ajax.get("article", params).then(function (data) {
      var html = Hura.Template.parse(newArticle, data.splice(0, 3));
      Hura.Template.render(target, html);
    });
  }
  
  // TIN TUYỂN DỤNG 
  function articleCatRight() {
   var params = {
      action_type: 'list',
      type: 'article',
      catId: 5,   
    };
    var target = "#js-article-middle-right";
    Hura.Ajax.get("article", params).then(function (data) {
   // console.log(data)
      var html = Hura.Template.parse(articleMiddleRight, data.list);
      Hura.Template.render(target, html);
    });
  }
 

  // GET PRODUCT NEWEST
  function productHot() {
    var params = {
      action_type: "product-list",
      hotType: "saleoff",
      sort: "order",
    };

    var target = "#js-product-hot-article";
    Hura.Ajax.get("product", params).then(function (data) {
      //console.log(data.list);
      var html = Hura.Template.parse(productHotArticle, data.list.splice(0, 5));
      Hura.Template.render(target, html);
    });
  }

  



  function run_anchor() {
        var all = document.getElementById("js-find_toc").getElementsByTagName("*");
        var nodes = []; 
        for(var i = all.length; i--; nodes.unshift(all[i]));
        var result = document.createElement("ol");
        buildRec(nodes, result, 2);

         $("<div class='archor-text-group' id='js-toc_container'><div class='toc_title d-flex align-items-center justify-content-between gap-8'><b class='text-18 font-weight-700 d-flex align-items-center text-fint-toc'><img src='/static/assets/default/images/art-detial.png'><span>Nội dung chính</span></b></div><div id='js-outp'>" + result.outerHTML + "</div></div>").insertAfter('#js-first-paragraph');
        
        $("#js-outp a").each(function(){
            if($(this).text().trim()!=''){
                var anchor_name = convertToSlug($(this).text());
                $(this).attr("onclick", `scrollRec('${anchor_name}')`);
            }
        });

        setTimeout(function(){
          $("#js-toggle").click(function(){
              $(this).parents("#js-toc_container").find("#js-outp").toggle();
          });
  		}, 500)
    }
  
  	function scrollRec(id) {
  		document.getElementById(id).scrollIntoView({behavior:'smooth'});
  	}
  
    function buildRec(nodes, elm, lv) {
        var node;
        //console.log(elm);
        // filter
        do {
            node = nodes.shift();
        } while(node && !(/^h[123]$/i.test(node.tagName)));
        // process the next node
        if(node) {
            var ul, li, cnt;
            var curLv = parseInt(node.tagName.substring(1));
            //console.log(curLv);
            var stt = 0;
            if(curLv == lv) { // same level append an il
                cnt = 0;
            } else if(curLv < lv && 1<2) { // walk up then append il
                cnt = 0;
                do {
                    elm = elm.parentNode.parentNode;
                    cnt--;
                } while(cnt > (curLv - lv));
            } else if(curLv > lv) { // create children then append il
                cnt = 0;
                do {
                    li = elm.lastChild;
                    if(li == null)
                        li = elm.appendChild(document.createElement("li"));
                        elm = li.appendChild(document.createElement("ol"));
                        cnt++;
                } while(cnt < (curLv - lv) && 1<2);
            }

            li = elm.appendChild(document.createElement("li"));
            // replace the next line with archor tags or whatever you want
            li.innerHTML = '<a href="javascript:;">'+ node.innerText +'</a>';
            // recursive call
            buildRec(nodes, elm, lv + cnt);
        }
    }

    function convertToSlug(Text){
		let newText = Text;
        return newText
            .toLowerCase()
            .replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a")
            .replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e")
            .replace(/ì|í|ị|ỉ|ĩ/g, "i")
            .replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, "o")
            .replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u")
            .replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y")
            .replace(/đ/g, "d")
            .replace(/\u0300|\u0301|\u0303|\u0309|\u0323/g, "")
            .replace(/\u02C6|\u0306|\u031B/g, "")
            .replace(/[^\w ]+/g,'')
            .replace(/ +/g,'-')
        ;
    }  
  
  run_anchor();
        
    $("#js-find_toc h2, #js-find_toc h3").each(function(){
      if($(this).text().trim()!=''){       
        var anchor_name = convertToSlug($(this).text());
        $(this).attr("id",anchor_name);
  		$(this).css("scroll-margin-top","80px");
      }
    });

