(() => { const notice = document.getElementById('cookieInfo'); if (!notice) return; const mode = notice.dataset.cookieMode || 'info'; const storageKey = 'govipe_cookie_notice_seen_v2'; const understood = document.getElementById('cookieUnderstood'); const accept = document.getElementById('affiliateCookieAccept'); const decline = document.getElementById('affiliateCookieDecline'); const cleanDecisionFromAddress = () => { try { const url = new URL(window.location.href); if (!url.searchParams.has('affiliate_consent')) return; url.searchParams.delete('affiliate_consent'); window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`); } catch (_) {} }; const rememberGeneralNotice = () => { try { window.localStorage.setItem(storageKey, 'yes'); } catch (_) {} }; const sendAffiliateDecision = (decision) => { rememberGeneralNotice(); try { const url = new URL(window.location.href); url.searchParams.set('affiliate_consent', decision); window.location.assign(url.toString()); } catch (_) { notice.classList.remove('is-visible'); } }; cleanDecisionFromAddress(); if (mode === 'affiliate') { window.setTimeout(() => notice.classList.add('is-visible'), 180); accept?.addEventListener('click', () => sendAffiliateDecision('accept')); decline?.addEventListener('click', () => sendAffiliateDecision('decline')); return; } let alreadySeen = false; try { alreadySeen = window.localStorage.getItem(storageKey) === 'yes'; } catch (_) {} if (!alreadySeen) { window.setTimeout(() => notice.classList.add('is-visible'), 450); } understood?.addEventListener('click', () => { rememberGeneralNotice(); notice.classList.remove('is-visible'); }); })();