function post(n){return fetch(n.url,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(n.data)}).then(n=>n.json()).then(n=>n)}function createObjectStore(n,t,i){return openDB(n,t,{upgrade:n=>{db=n,i(n)}})}function createNavigationStore(n){const t=n.createObjectStore(STORE_NAME,{keyPath:"Id"});t.createIndex("CreatedOn","CreatedOn");store=t}function setPrevAndNext(){openDB(DB_NAME).then(n=>{n.get(STORE_NAME,hopNavigationInfo.HopNavigationId).then(n=>{let t=n.List,i={Previous:hopNavigationInfo.CurrentPosition>0?t[hopNavigationInfo.CurrentPosition-1]:null,Next:hopNavigationInfo.CurrentPosition<t.length-1?t[hopNavigationInfo.CurrentPosition+1]:null};setSliders(hopNavigationInfo,i)})})}function setSliders(n,t){let i=t.Next;if(i!=null){document.querySelector("#next-hop").textContent=i.Title;const t=document.querySelector("#nw-slide-dx");t.addEventListener("click",()=>{removeCookie(HOP_NAV_COOKIE_NAME,{path:document.location.pathname}),n.CurrentPosition++,setCookie(HOP_NAV_COOKIE_NAME,JSON.stringify(n),{expires:new Date((new Date).getTime()+COOKIE_EXP_TIME_MIN*6e4),path:i.Url}),document.location.href=i.Url});t.classList.remove("hidden");t.setAttribute("title",i.Url.indexOf("/a/")>-1?"Articolo successivo":"")}let r=t.Previous;if(r!=null){document.querySelector("#prev-hop").textContent=r.Title;const t=document.querySelector("#nw-slide-sx");t.addEventListener("click",()=>{removeCookie(HOP_NAV_COOKIE_NAME,{path:document.location.pathname}),n.CurrentPosition--,setCookie(HOP_NAV_COOKIE_NAME,JSON.stringify(n),{expires:new Date((new Date).getTime()+COOKIE_EXP_TIME_MIN*6e4),path:r.Url}),document.location.href=r.Url});t.classList.remove("hidden");t.setAttribute("title",r.Url.indexOf("/a/")>-1?"Articolo precedente":"")}}function clipText(){$clamp(document.querySelector("#prev-hop"),{clamp:2});$clamp(document.querySelector("#next-hop"),{clamp:2})}function addHours(n,t){return n.setHours(n.getHours()+t),n}function deleteOldData(){let n=addHours(new Date,-6);openDB(DB_NAME).then(t=>{t.getAllFromIndex("NavData","CreatedOn",IDBKeyRange.upperBound(n)).then(n=>{n.forEach(n=>t.delete("NavData",n.Id))})})}function getReferrer(){let n=document.location;if(document.referrer.indexOf(n.origin)===0){let t=document.referrer.replace(n.origin,"");if(t&&t.length>1&&t.indexOf("/a/")===-1)return t}let t=document.querySelector("#to-know-more-inv");return t?t.getAttribute("href"):document.querySelector(".category a").getAttribute("href")}function ready(n){document.readyState!=="loading"?n():document.addEventListener("DOMContentLoaded",n)}import{$clamp}from"../../js/clamp.js/clamp.min.js";import{openDB}from"../../node_modules/idb/build/index.js";import{getCookie,setCookie,removeCookie}from"../../node_modules/typescript-cookie/dist/typescript-cookie.min.mjs";const DB_NAME="NWHopNav",STORE_NAME="NavData",HOP_NAV_COOKIE_NAME="_nw_hop_nav",COOKIE_EXP_TIME_MIN=60;var db,store;let hopNavigationInfo;ready(function(){let n=getCookie(HOP_NAV_COOKIE_NAME);if(n)hopNavigationInfo=JSON.parse(n),setPrevAndNext(),deleteOldData();else{let n=getReferrer().trim(),r=document.querySelector("#fline .category a"),i=r.innerText.toUpperCase(),u=r.attributes.href.value,t=null;n===""||n==="/"?(t={Title:`Vai alla categoria: ${i}`,Url:u},n=u):t={Title:"Vai alla lista degli articoli",Url:n};let f=n.indexOf("ricerca-notizie")>-1?`/nwhopnav/NewsSearch${n.substr(n.indexOf("?"))}`:"/nwhopnav/HopNavigationData",e=document.referrer;post({url:f,data:{referrerLocalPath:n,categoryName:i,originalReferrer:e}}).then(r=>{r!=null&&(r.List=r.List.filter(n=>n.Url!=document.location.pathname),r.List.unshift({Title:document.querySelector("h1").innerText,Url:document.location.pathname}),r.List.unshift(t),r.List.push(t),r.CreatedOn=new Date(parseInt(r.CreatedOn.substr(6))),createObjectStore(DB_NAME,1,createNavigationStore).then(t=>{t.add(STORE_NAME,r),hopNavigationInfo={ReferrerLocalPath:n,HopNavigationId:r.Id,CategoryName:i,CurrentPosition:1},setCookie(HOP_NAV_COOKIE_NAME,JSON.stringify(hopNavigationInfo),{expires:new Date((new Date).getTime()+COOKIE_EXP_TIME_MIN*6e4),path:document.location.pathname}),setPrevAndNext()}))})}clipText()});
