function setViewedWindows(campaignId) {
    const storedObject = JSON.parse(localStorage.getItem(`adventCalendar-${campaignId}`));

    if (storedObject && Array.isArray(storedObject)) {
        storedObject.forEach(date => {
            document.querySelector(`#advent-calendar>.days-grid>a[data-date="${date}"]`)?.classList.add('viewed');
            document.querySelector(`#advent-calendar-placed>.days-grid>a[data-date="${date}"]`)?.classList.add('viewed');
        });
    }
}

function addAdventListeners(campaignId) {
    document.querySelectorAll('.days-grid>a').forEach(dayWindow => {
        dayWindow.addEventListener('click', _e => {
            addWindowToStorageAndRedirect(dayWindow.dataset.date, campaignId);
        });
    });
}

function addWindowToStorageAndRedirect(date, campaignId) {
    const storedObject = JSON.parse(localStorage.getItem(`adventCalendar-${campaignId}`));

    if (!storedObject || !Array.isArray(storedObject)) {
        localStorage.setItem(`adventCalendar-${campaignId}`, JSON.stringify([date]));
    } else if (!storedObject.includes(date)) {
        localStorage.setItem(`adventCalendar-${campaignId}`, JSON.stringify([...storedObject, date]));
    }
}
