document.addEventListener("DOMContentLoaded", function () {
	const toolbar = document.querySelector("#press-toolbar");
	if (!toolbar) return;
	const toolbarButtons = toolbar.querySelectorAll("button");
	const ressourcesGridContentWrapper = document.querySelector(
		".ressources-grid-content-wrapper"
	);

	function setActiveTab(currentButton) {
		toolbarButtons.forEach((button) => {
			button.setAttribute("aria-selected", "false");
		});

		currentButton.setAttribute("aria-selected", "true");
		ressourcesGridContentWrapper.setAttribute(
			"data-active-tab",
			currentButton.getAttribute("data-tab")
		);
	}

	function initToolbar() {
		toolbarButtons.forEach((button) => {
			button.addEventListener("click", function () {
				setActiveTab(button);
			});
		});
	}
	initToolbar();
});
