import { audioPath } from "./path.js";

let what = document.querySelector('[commandfor="signal"]');
let guardian = document.createElement("audio");
let dialog = document.getElementById("signal");
let funny = document.getElementById("funny");
let invis;

guardian.src = `${audioPath}sanctuary_guardian.ogg`;
guardian.preload = "";
what.appendChild(guardian);

function codzombies(mutations) {
	if (dialog.open) {
		guardian.play();
		if (funny) {
			funny.style.opacity = 0;
			invis = setTimeout(() => {
				funny.style.opacity = 1;
			}, 2200);
		}
	} else {
		guardian.pause();
		guardian.currentTime = 0;
		clearTimeout(invis);
	}
}

const observer = new MutationObserver(codzombies);
observer.observe(dialog, {
	attributes: true,
});
