<div class="filter-link"><svg class="filter-icon" enable-background="new 0 0 510.2 512" version="1.1" viewBox="0 0 510.2 512" xmlns="http://www.w3.org/2000/svg"><path d="m499.1 0c2.8 2.2 6.2 4 8.3 6.8 4.4 5.8 3.5 12.6-1.9 19.2-15.7 19.4-31.5 38.8-47.3 58.2-41.2 50.8-82.5 101.6-123.8 152.4-2 2.4-3.9 3.4-7.1 3.4-48.2-0.1-96.3-0.1-144.5 0-3.2 0-5.1-1-7.1-3.4-56.4-69.6-112.9-139.1-169.4-208.7-9.7-11.9-8.3-20.3 4.8-27.9h488z"/><path d="m206.1 512c-8.7-4-11.2-10.8-11.1-20.2 0.3-71.8 0.1-143.6 0.1-215.4v-6.2h120v5.5c0 57.6-0.1 115.3 0.1 172.9 0 8.7-3.3 14.4-11.1 18.2-29.9 14.6-59.6 29.6-89.4 44.4-0.3 0.1-0.4 0.5-0.6 0.7-2.7 0.1-5.3 0.1-8 0.1z"/></svg><span>Filter</span></div>

{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
{{ $sections := .Site.Params.mainSections }}

{{ $.Scratch.Set "authors" (slice ) }}
{{ $.Scratch.Set "noAuthors" 0 }}

{{ range where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
	{{ with .Params.authors }}
	{{ if eq ( printf "%T" . ) "[]string"  }}
		{{ if ( not ( in ($.Scratch.Get "authors") . ) ) }}
		{{ $.Scratch.Add "authors" . }}
		{{ end }}
	{{ else if ( printf "%T" . ) "[]string" }}
		{{ range . }}
		{{ if ( not ( in ($.Scratch.Get "authors") . ) ) }}
			{{ $.Scratch.Add "authors" . }}
		{{ end }}
		{{ end }}
	{{ end }}
	{{ else }}
	{{ $.Scratch.Add "noAuthors" 1 }}
	{{ end }}
{{ end }}

{{ $.Scratch.Set "cats" (slice ) }}
{{ $.Scratch.Set "nocat" 0 }}

{{ range where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
	{{ with .Params.categories }}
	{{ if eq ( printf "%T" . ) "[]string"  }}
		{{ if ( not ( in ($.Scratch.Get "cats") . ) ) }}
		{{ $.Scratch.Add "cats" . }}
		{{ end }}
	
	{{ end }}
	{{ else }}
	{{ $.Scratch.Add "nocat" 1 }}
	{{ end }}
{{ end }}


{{ $tags := $.Site.Taxonomies.tags.ByCount }}

{{ $.Scratch.Set "untagged" 0 }}
{{ range $pages }}
	{{ with .Params.tags }}{{ else }}{{ $.Scratch.Add "untagged" 1 }}{{ end }}
{{ end }}

<div class="filter-buttons-container">
	<div class="filter-buttons-container-header">
		<div><span id="selectedItemCount"></span> Items</div>
		<a href="" class="load-all">Load all Items</a>
	</div>
	<div class="filter-buttons">
	<button xx id="selectAllSections" onclick="htf.showAll('section')">
		All Sections
	</button>
	{{ range $sections }}
		<button xx class="sect-button filter-button" id="sect-{{ . | urlize }}" onclick="htf.checkFilter('{{ . | urlize }}', 'sect-')">
		{{ . | title }} <span id="ssect-{{ . | urlize }}"> -count-</span> | <span id="csect-{{ . | urlize }}"> -count-</span>
		</button>
	{{ end }}
	</div>

	<div class="filter-buttons">
	<button xx id="selectAllAuthors" onclick="htf.showAll('authors')">
		All Authors
	</button>

	{{ range .Site.Taxonomies.authors }}
	<button xx class="auth-button filter-button" id="auth-{{ .Page.Title | replaceRE "[.]" "_" | urlize }}" onclick="htf.checkFilter('{{ .Page.Title | replaceRE "[.]" "_" | urlize }}', 'auth-')">
		{{ .Page.Title }} <span id="sauth-{{ .Page.Title | replaceRE "[.]" "_" | urlize }}"> -count-</span> | <span id="cauth-{{ .Page.Title | replaceRE "[.]" "_" | urlize }}"> -count-</span>
	</button>
	{{ end }}

	{{ if gt ( $.Scratch.Get "noAuthors") 0 }}
	<button xx class="auth-button" id="auth-no-author" onclick="htf.checkFilter('no-author', 'auth-')">
		No Author <span id="sauth-no-author"> -count-</span> | <span id="cauth-no-author"> -count-</span>
	</button>
	{{ end }}
	</div>

	<div class="filter-buttons">
	<button xx id="selectAllCats" onclick="htf.showAll('cats')">
		All Categories
	</button>

	{{ range .Site.Taxonomies.categories }}
	<button xx class="cat-button filter-button" id="cat-{{ .Page.Title | replaceRE "[.]" "_" | urlize }}" onclick="htf.checkFilter('{{ .Page.Title | replaceRE "[.]" "_" | urlize }}', 'cat-')">
		{{ .Page.Title }} <span id="scat-{{ .Page.Title | replaceRE "[.]" "_" | urlize }}"> -count-</span> | <span id="ccat-{{ .Page.Title | replaceRE "[.]" "_" | urlize }}"> -count-</span>
	</button>
	{{ end }}

	{{ if gt ( $.Scratch.Get "nocat") 0 }}
	<button xx class="cat-button" id="cat-no-cat" onclick="htf.checkFilter('no-cat', 'cat-')">
		No Categories <span id="scat-no-cat"> -count-</span> | <span id="ccat-no-cat"> -count-</span>
	</button>
	{{ end }}
	</div>

	<div class="filter-buttons">
	<button xx class="" id="selectAllTags" onclick="htf.showAll('tags')">
		All Tags
	</button>
	{{ range $tags }}
		{{ if .Term }}
		<button xx class="tag-button filter-button" id="tag-{{ .Term | replaceRE "[.]" "_" | urlize }}" onclick="htf.checkFilter('{{ .Term | replaceRE "[.]" "_" | urlize }}', 'tag-')">
			<span>{{.Term | humanize | title }}</span>
			<span id="stags-{{ .Term | urlize }}"> -count-</span> | <span id="ctags-{{ .Term | urlize }}"> -count-</span>
		</button>
		{{ end }}
	{{ end }}
	{{ if gt ( $.Scratch.Get "untagged") 0 }}
	<button xx class="tag-button" id="tag-tfuntagged" onclick="htf.checkFilter('tfuntagged', 'tag-')">
		Untagged <span id="stags-tfuntagged"> -count-</span> | <span id="ctags-tfuntagged"> -count-</span>
	</button>
	{{ end }}
	</div>
</div>