/**
 * Northfield Theatre — Cookie Consent
 *
 * Handles accept/settings buttons and sets a cookie to remember choice.
 *
 * @package Northfield_Theatre
 * @since 1.0.0
 */

(function () {
	'use strict';

	function init() {
		var banner = document.getElementById('cookie-consent');
		var acceptBtn = document.getElementById('cookie-accept');
		var settingsBtn = document.getElementById('cookie-settings');

		if (!banner) return;

		function acceptCookies() {
			document.cookie = 'northfield_cookies_accepted=1; path=/; max-age=' + (365 * 24 * 60 * 60) + '; SameSite=Lax';
			banner.hidden = true;
		}

		if (acceptBtn) {
			acceptBtn.addEventListener('click', acceptCookies);
		}

		if (settingsBtn) {
			settingsBtn.addEventListener('click', function () {
				// For the demo, settings just accepts essential cookies only.
				document.cookie = 'northfield_cookies_accepted=essential; path=/; max-age=' + (365 * 24 * 60 * 60) + '; SameSite=Lax';
				banner.hidden = true;
			});
		}
	}

	if (document.readyState === 'loading') {
		document.addEventListener('DOMContentLoaded', init);
	} else {
		init();
	}
})();
