'use strict';if(!Array.from){Array.from=function(){var toStr=Object.prototype.toString;var isCallable=function isCallable(fn){return typeof fn==='function'||toStr.call(fn)==='[object Function]';};var toInteger=function toInteger(value){var number=Number(value);if(isNaN(number)){return 0;}
if(number===0||!isFinite(number)){return number;}
return(number>0?1:-1)*Math.floor(Math.abs(number));};var maxSafeInteger=Math.pow(2,53)-1;var toLength=function toLength(value){var len=toInteger(value);return Math.min(Math.max(len,0),maxSafeInteger);};return function from(arrayLike){var C=this;var items=Object(arrayLike);if(arrayLike==null){throw new TypeError('Array.from requires an array-like object - not null or undefined');}
var mapFn=arguments.length>1?arguments[1]:void undefined;var T;if(typeof mapFn!=='undefined'){if(!isCallable(mapFn)){throw new TypeError('Array.from: when provided, the second argument must be a function');}
if(arguments.length>2){T=arguments[2];}}
var len=toLength(items.length);var A=isCallable(C)?Object(new C(len)):new Array(len);var k=0;var kValue;while(k<len){kValue=items[k];if(mapFn){A[k]=typeof T==='undefined'?mapFn(kValue,k):mapFn.call(T,kValue,k);}else{A[k]=kValue;}
k+=1;}
A.length=len;return A;};}();}
var tabsList=document.querySelector(".js-tabs-list");var tabs=tabsList!==null?Array.from(tabsList.querySelectorAll("button")):[];var tabSelect=document.querySelector(".js-tab-select");var getParameterByName=function getParameterByName(name,url){if(!url)url=window.location.href;name=name.replace(/[\[\]]/g,'\\$&');var regex=new RegExp('[?&]'+name+'(=([^&#]*)|&|#|$)'),results=regex.exec(url);if(!results)return null;if(!results[2])return '';return decodeURIComponent(results[2].replace(/\+/g,' '));};var updateQueryString=function updateQueryString(key,value){var url=arguments.length>2&&arguments[2]!==undefined?arguments[2]:location.href;if(!url)url=window.location.href;var re=new RegExp("([?&])"+key+"=.*?(&|#|$)(.*)","gi"),hash;if(re.test(url)){if(typeof value!=='undefined'&&value!==null)return url.replace(re,'$1'+key+"="+value+'$2$3');else{hash=url.split('#');url=hash[0].replace(re,'$1$3').replace(/(&|\?)$/,'');if(typeof hash[1]!=='undefined'&&hash[1]!==null)url+='#'+hash[1];return url;}}else{if(typeof value!=='undefined'&&value!==null){var separator=url.indexOf('?')!==-1?'&':'?';hash=url.split('#');url=hash[0]+separator+key+'='+value;if(typeof hash[1]!=='undefined'&&hash[1]!==null)url+='#'+hash[1];return url;}else return url;}};var removeURLParameter=function removeURLParameter(parameter){var url=arguments.length>1&&arguments[1]!==undefined?arguments[1]:location.href;var urlparts=url.split("?");if(urlparts.length>=2){var prefix=encodeURIComponent(parameter)+"=";var pars=urlparts[1].split(/[&;]/g);for(var i=pars.length;i-->0;){if(pars[i].lastIndexOf(prefix,0)!==-1){pars.splice(i,1);}}
return urlparts[0]+(pars.length>0?"?"+pars.join("&"):"");}
return url;};var mapTabClicks=function mapTabClicks(arr){arr.map(function(a){a.addEventListener('click',function(e){e.preventDefault();location.href=updateQueryString("type",a.getAttribute("data-newstype"),removeURLParameter("results"));});});};var handleSelectChange=function handleSelectChange(el){el.onchange=function(){location.href=updateQueryString("tag",el.value,removeURLParameter("results"));};};var generateActiveElements=function generateActiveElements(tabsArr,selectEl){var type=getParameterByName('type');var tag=getParameterByName('tag');if(type===null){tabsArr.map(function(a){a.parentNode.classList.add("tabs-list__item--inactive");});tabsArr[0].parentNode.classList.remove("tabs-list__item--inactive");}else{tabsArr.map(function(a){if(a.getAttribute('data-newstype')===type){a.parentNode.classList.remove('tabs-list__item--inactive');}else{a.parentNode.classList.add('tabs-list__item--inactive');}});}
if(tag===null){selectEl.value='';}else{selectEl.value=tag;}};generateActiveElements(tabs,tabSelect);handleSelectChange(tabSelect);mapTabClicks(tabs);