<commit_before>"use strict";

class HeaderSection {
	constructor() {
		this.title = "Pokémon Stuff"
		this.titleLink = "https://github.com/Armienn/pokemon#pok%C3%A9mon-stuff"
		this.subtitle = ""
		this.showLocal = false

		this.navGroups = {
			base: {
				all: {
					text: "<img src='static/pokeball-white.png' style='height:1.5rem;padding-top:0.6rem;' />", //⊖
					click: () => stuff.selectTab("all"),
					active: () => stuff.state.currentTab == "all",
					style: { fontSize: "1.5rem", paddingBottom: "0.2rem" }
				},
				custom: {
					text: "☷",
					click: () => stuff.optionsSection.toggle(),
					active: () => false,
					style: { fontSize: "1.3rem" }
				}
			},
			pokemons: {
			},
			modes: {
				table: {
					text: "▤",
					click: () => { stuff.state.mode = "table"; stuff.updatePokemons() },
					active: () => stuff.state.mode == "table",
					style: { fontSize: "2rem", fontWeight: "initial" }
				},
				grid: {
					text: "▦",
					click: () => { stuff.state.mode = "grid"; stuff.updatePokemons() },
					active: () => stuff.state.mode == "grid",
					style: { fontSize: "2rem", fontWeight: "initial" }
				}
			},
			colours: {
				day: {
					text: "☀",
					click: () => { stuff.settings.setColorScheme("day"); stuff.updateColors() },
					active: () => stuff.settings.colorScheme == "day",
					style: { fontSize: "1.2rem" }
				},
				night: {
					text: "☽",
					click: () => { stuff.settings.setColorScheme("night"); stuff.updateColors() },
					active: () => stuff.settings.colorScheme == "night",
					style: { fontSize: "1.2rem" }
				}
			}
		}

		this.sorts = {
			"ID": (a, b) => { return a.id - b.id },
			"HP": (a, b) => { return b.stats.hp - a.stats.hp },
			"Attack": (a, b) => { return b.stats.atk - a.stats.atk },
			"Defense": (a, b) => { return b.stats.def - a.stats.def },
			"Sp. Attack": (a, b) => { return b.stats.spa - a.stats.spa },
			"Sp. Defense": (a, b) => { return b.stats.spd - a.stats.spd },
			"Speed": (a, b) => { return b.stats.spe - a.stats.spe },
			"Total base stats": (a, b) => { return stuff.data.getTotalBaseStat(b) - stuff.data.getTotalBaseStat(a) },
			"Custom sort": (a, b) => { return b.stats.hp - a.stats.hp }
		}

		this.filters = {}

		this.titleElement = document.getElementById("main-title")
		this.subtitleElement = document.getElementById("sub-title")
		this.navListElement = document.getElementById("nav-list")
		this.filterAdderElement = document.getElementById("filter-adder")
		this.filterListElement = document.getElementById("filter-list")
		this.currentFilterList = document.getElementById("current-filter-list")
		this.customPokemonElement = document.getElementById("custom-pokemon-section")
		this.optionsElement = document.getElementById("options-section")
		this.optionsSubElement = document.getElementById("options-sub-section")
	}

	setup() {
		this.filters = {
			"Type": { type: "basic", filter: this.hasItemInFilter("types"), options: stuff.data.typeNames },
			"Ability": { type: "basic", filter: this.hasItemInFilter("ability", "abilities"), options: Object.keys(stuff.data.abilities) },
			"Move": { type: "basic", filter: this.hasItemInFilter("moves"), options: Object.keys(stuff.data.moves) },
			"Egg group": { type: "basic", filter: this.hasItemInFilter("eggGroups"), options: stuff.data.eggGroupNames },
			"Gender ratios": { type: "multi", filter: this.hasItemInFilter("ratio"), options: ["7:1", "3:1", "1:1", "1:3", "1:7", "—"] },
			"Generation": { type: "multi", filter: this.generationFilter, options: ["1", "2", "3", "4", "5", "6", "7"] },
			"Legendary": { type: "select", filter: this.legendaryFilter, options: ["Show only", "Don't show"] },
			"Nature": { type: "basic", filter: this.hasItemInFilter("nature"), options: Object.keys(stuff.data.natures) },
			"Learnt moves": { type: "basic", filter: this.hasItemInFilter("learntMoves"), options: Object.keys(stuff.data.moves) },
			"Gender": { type: "multi", filter: this.hasItemInFilter("gender"), options: ["♂", "♀", "—", "Undefined"] },
			"Shiny": { type: "select", filter: this.shinyFilter, options: ["Show only", "Don't show"] },
			"Hidden ability": { type: "select", filter: this.hiddenAbilityFilter, options: ["Show only", "Don't show"] },
			"Custom filter": { type: "custom" }
		}
	}

	show() {
		this.showTitle()
		this.showSubtitle()
		this.showNavList()
		this.filterAdderElement.innerHTML = ""
		if (stuff.state.externalInventory.load)
			this.showCompletionModeSwitcher()
		this.showSearch()
		this.showFilterSelect()
		this.showSortingChooser()
	}

	showTitle() {
		var element = this.titleElement
		if (stuff.collection.spreadsheetId) {
			var title = stuff.collection.collectorUrl ? "<a href=\"" + stuff.collection.collectorUrl + "\">" + stuff.collection.collectorName + "</a>'s " : stuff.collection.collectorName + "'s "
			title += stuff.collection.spreadsheetId ? "<a href=\"https://docs.google.com/spreadsheets/d/" + stuff.collection.spreadsheetId + "\">Pokémon</a> " : "Pokémon "
			title += "<a href=\"https://armienn.github.io/pokemon/\">Stuff</a>"
			element.innerHTML = title
		}
		else {
			element.innerHTML = ""
			if (this.titleLink) {
				element = newTag("a", this.titleElement)
				element.href = this.titleLink
			}
			element.innerHTML = this.title
		}
		document.title = element.textContent
	}

	showSubtitle() {
		if (stuff.collection.collectorFriendCode)
			this.subtitleElement.innerText = "FC: " + stuff.collection.collectorFriendCode
		else
			this.subtitleElement.innerText = this.subtitle
		if (this.subtitleElement.innerText)
			this.subtitleElement.style.display = ""
		else
			this.subtitleElement.style.display = "none"
	}

	showNavList() {
		this.navListElement.innerHTML = ""
		for (var group in this.navGroups) {
			var groupElement = newTag("li", this.navListElement)
			for (var entry in this.navGroups[group]) {
				var element = this.navGroups[group][entry]
				if (typeof element === "string")
					newTag("span", groupElement, { text: element })
				else
					this.setupNavListElement(element, groupElement)
			}
		}
	}

	setupNavListElement(entry, groupElement) {
		let element = newTag("li", groupElement, entry)
		element.className = entry.active() ? "active" : "inactive"
		element.onclick = () => {
			this.customPokemonElement.style.display = "none"
			entry.click()
			this.showNavList()
		}
	}

	updateNavPokemonTabs() {
		this.navGroups.pokemons = {}
		if (!(stuff.collection.pokemons.length || stuff.collection.lookingFor.length))
			return
		var index = 0
		if (stuff.collection.local.length) {
			this.navGroups.pokemons[index] = "|"
			index++
			if (this.showLocal) {
				for (var i in stuff.collection.local) {
					var tab = stuff.collection.local[i]
					this.navGroups.pokemons[index] = {
						text: tab.title,<commit_msg>Forgot something<commit_after>"use strict";

class HeaderSection {
	constructor() {
		this.title = "Pokémon Stuff"
		this.titleLink = "https://github.com/Armienn/pokemon#pok%C3%A9mon-stuff"
		this.subtitle = ""
		this.showLocal = false

		this.navGroups = {
			base: {
				all: {
					text: "<img src='static/pokeball-white.png' style='height:1.5rem;padding-top:0.6rem;' />", //⊖
					click: () => stuff.selectTab("all"),
					active: () => stuff.state.currentTab == "all",
					style: { fontSize: "1.5rem", paddingBottom: "0.2rem" }
				},
				custom: {
					text: "☷",
					click: () => stuff.optionsSection.toggle(),
					active: () => false,
					style: { fontSize: "1.3rem" }
				}
			},
			pokemons: {
			},
			modes: {
				table: {
					text: "▤",
					click: () => { stuff.state.mode = "table"; stuff.updatePokemons() },
					active: () => stuff.state.mode == "table",
					style: { fontSize: "2rem", fontWeight: "initial" }
				},
				grid: {
					text: "▦",
					click: () => { stuff.state.mode = "grid"; stuff.updatePokemons() },
					active: () => stuff.state.mode == "grid",
					style: { fontSize: "2rem", fontWeight: "initial" }
				}
			},
			colours: {
				day: {
					text: "☀",
					click: () => { stuff.settings.setColorScheme("day"); stuff.updateColors() },
					active: () => stuff.settings.colorScheme == "day",
					style: { fontSize: "1.2rem" }
				},
				night: {
					text: "☽",
					click: () => { stuff.settings.setColorScheme("night"); stuff.updateColors() },
					active: () => stuff.settings.colorScheme == "night",
					style: { fontSize: "1.2rem" }
				}
			}
		}

		this.sorts = {
			"ID": (a, b) => { return a.id - b.id },
			"HP": (a, b) => { return b.stats.hp - a.stats.hp },
			"Attack": (a, b) => { return b.stats.atk - a.stats.atk },
			"Defense": (a, b) => { return b.stats.def - a.stats.def },
			"Sp. Attack": (a, b) => { return b.stats.spa - a.stats.spa },
			"Sp. Defense": (a, b) => { return b.stats.spd - a.stats.spd },
			"Speed": (a, b) => { return b.stats.spe - a.stats.spe },
			"Total base stats": (a, b) => { return stuff.data.getTotalBaseStat(b) - stuff.data.getTotalBaseStat(a) },
			"Custom sort": (a, b) => { return b.stats.hp - a.stats.hp }
		}

		this.filters = {}

		this.titleElement = document.getElementById("main-title")
		this.subtitleElement = document.getElementById("sub-title")
		this.navListElement = document.getElementById("nav-list")
		this.filterAdderElement = document.getElementById("filter-adder")
		this.filterListElement = document.getElementById("filter-list")
		this.currentFilterList = document.getElementById("current-filter-list")
		this.optionsElement = document.getElementById("options-section")
		this.optionsSubElement = document.getElementById("options-sub-section")
	}

	setup() {
		this.filters = {
			"Type": { type: "basic", filter: this.hasItemInFilter("types"), options: stuff.data.typeNames },
			"Ability": { type: "basic", filter: this.hasItemInFilter("ability", "abilities"), options: Object.keys(stuff.data.abilities) },
			"Move": { type: "basic", filter: this.hasItemInFilter("moves"), options: Object.keys(stuff.data.moves) },
			"Egg group": { type: "basic", filter: this.hasItemInFilter("eggGroups"), options: stuff.data.eggGroupNames },
			"Gender ratios": { type: "multi", filter: this.hasItemInFilter("ratio"), options: ["7:1", "3:1", "1:1", "1:3", "1:7", "—"] },
			"Generation": { type: "multi", filter: this.generationFilter, options: ["1", "2", "3", "4", "5", "6", "7"] },
			"Legendary": { type: "select", filter: this.legendaryFilter, options: ["Show only", "Don't show"] },
			"Nature": { type: "basic", filter: this.hasItemInFilter("nature"), options: Object.keys(stuff.data.natures) },
			"Learnt moves": { type: "basic", filter: this.hasItemInFilter("learntMoves"), options: Object.keys(stuff.data.moves) },
			"Gender": { type: "multi", filter: this.hasItemInFilter("gender"), options: ["♂", "♀", "—", "Undefined"] },
			"Shiny": { type: "select", filter: this.shinyFilter, options: ["Show only", "Don't show"] },
			"Hidden ability": { type: "select", filter: this.hiddenAbilityFilter, options: ["Show only", "Don't show"] },
			"Custom filter": { type: "custom" }
		}
	}

	show() {
		this.showTitle()
		this.showSubtitle()
		this.showNavList()
		this.filterAdderElement.innerHTML = ""
		if (stuff.state.externalInventory.load)
			this.showCompletionModeSwitcher()
		this.showSearch()
		this.showFilterSelect()
		this.showSortingChooser()
	}

	showTitle() {
		var element = this.titleElement
		if (stuff.collection.spreadsheetId) {
			var title = stuff.collection.collectorUrl ? "<a href=\"" + stuff.collection.collectorUrl + "\">" + stuff.collection.collectorName + "</a>'s " : stuff.collection.collectorName + "'s "
			title += stuff.collection.spreadsheetId ? "<a href=\"https://docs.google.com/spreadsheets/d/" + stuff.collection.spreadsheetId + "\">Pokémon</a> " : "Pokémon "
			title += "<a href=\"https://armienn.github.io/pokemon/\">Stuff</a>"
			element.innerHTML = title
		}
		else {
			element.innerHTML = ""
			if (this.titleLink) {
				element = newTag("a", this.titleElement)
				element.href = this.titleLink
			}
			element.innerHTML = this.title
		}
		document.title = element.textContent
	}

	showSubtitle() {
		if (stuff.collection.collectorFriendCode)
			this.subtitleElement.innerText = "FC: " + stuff.collection.collectorFriendCode
		else
			this.subtitleElement.innerText = this.subtitle
		if (this.subtitleElement.innerText)
			this.subtitleElement.style.display = ""
		else
			this.subtitleElement.style.display = "none"
	}

	showNavList() {
		this.navListElement.innerHTML = ""
		for (var group in this.navGroups) {
			var groupElement = newTag("li", this.navListElement)
			for (var entry in this.navGroups[group]) {
				var element = this.navGroups[group][entry]
				if (typeof element === "string")
					newTag("span", groupElement, { text: element })
				else
					this.setupNavListElement(element, groupElement)
			}
		}
	}

	setupNavListElement(entry, groupElement) {
		let element = newTag("li", groupElement, entry)
		element.className = entry.active() ? "active" : "inactive"
		element.onclick = () => {
			entry.click()
			this.showNavList()
		}
	}

	updateNavPokemonTabs() {
		this.navGroups.pokemons = {}
		if (!(stuff.collection.pokemons.length || stuff.collection.lookingFor.length))
			return
		var index = 0
		if (stuff.collection.local.length) {
			this.navGroups.pokemons[index] = "|"
			index++
			if (this.showLocal) {
				for (var i in stuff.collection.local) {
					var tab = stuff.collection.local[i]
					this.navGroups.pokemons[index] = {
						text: tab.title,
{'fraction_non_alphanumeric': 0.18671145949981335, 'fraction_numerical': 0.005375139977603583, 'mean_word_length': 3.635294117647059, 'pattern_counts': {'":': 44, '<': 17, '<?xml version=': 0, '>': 61, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6781580', 'n_tokens_mistral': 5326, 'n_tokens_neox': 4581, 'n_words': 864}