export function lookupAudit(audit: keyof typeof audits): boolean {
	if (!audits.hasOwnProperty(audit)) {
		return false;
	}

	const valid = audits[audit].validator(hidden);

	if (valid && !hidden.has(audit)) {
		audits[audit].trueAction(hidden);
	} else {
		audits[audit].falseAction(hidden);
	}

	return valid;
}

type Action = (x: typeof hidden) => void;

export function addAudit(
	name: string,
	validator: (x: typeof hidden) => boolean,
	trueAction: Action,
	falseAction: Action
) {
	audits[name] = {
		validator,
		trueAction,
		falseAction,
	};
}

export const audits: Record<
	string,
	{
		validator: (x: typeof hidden) => boolean;
		trueAction: Action;
		falseAction: Action;
	}
> = {};

export const hidden: Set<keyof typeof audits> = new Set();
