var EPCCookieConsent=(function (){
var settings=(typeof epcCookieSettings!=='undefined') ? epcCookieSettings:{};
var COOKIE_NAME=settings.cookieName||'epc_cookie_consent';
var COOKIE_DAYS=settings.cookieDays||365;
function setCookie(name, value, days){
var expires='';
if(days){
var date=new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires='; expires=' + date.toUTCString();
}
document.cookie=name + '=' + encodeURIComponent(value) + expires + '; path=/; SameSite=Lax';
}
function getCookie(name){
var match=document.cookie.match(new RegExp('(^|)' + name + '=([^;]+)'));
return match ? decodeURIComponent(match[2]):null;
}
function saveConsent(consent){
consent.timestamp=new Date().toISOString();
setCookie(COOKIE_NAME, JSON.stringify(consent), COOKIE_DAYS);
closeBanner();
closeModal();
activateScripts(consent);
document.dispatchEvent(new CustomEvent('epcCookieConsentUpdated', { detail: consent }));
}
function getConsent(){
var raw=getCookie(COOKIE_NAME);
if(!raw) return null;
try { return JSON.parse(raw); } catch (e){ return null; }}
function activateScripts(consent){
var blocked=document.querySelectorAll('script[type="text/plain"][data-cookiecategory]');
blocked.forEach(function (oldScript){
var category=oldScript.getAttribute('data-cookiecategory');
if(consent[category]){
var newScript=document.createElement('script');
for (var i=0; i < oldScript.attributes.length; i++){
var attr=oldScript.attributes[i];
if(attr.name==='type') continue;
if(attr.name==='data-src'){
newScript.setAttribute('src', attr.value);
}else{
newScript.setAttribute(attr.name, attr.value);
}}
newScript.type='text/javascript';
if(!oldScript.hasAttribute('data-src')){
newScript.text=oldScript.text;
}
oldScript.parentNode.replaceChild(newScript, oldScript);
}});
}
function openBanner(){
document.getElementById('epc-cookie-banner').classList.add('epc-visible');
}
function closeBanner(){
document.getElementById('epc-cookie-banner').classList.remove('epc-visible');
}
function openModal(){
var consent=getConsent();
document.getElementById('epc-cat-analytics').checked=consent ? !!consent.analytics:false;
document.getElementById('epc-cat-marketing').checked=consent ? !!consent.marketing:false;
document.getElementById('epc-cookie-modal-overlay').classList.add('epc-visible');
}
function closeModal(){
document.getElementById('epc-cookie-modal-overlay').classList.remove('epc-visible');
}
function acceptAll(){
saveConsent({ necessary: true, analytics: true, marketing: true });
}
function rejectAll(){
saveConsent({ necessary: true, analytics: false, marketing: false });
}
function savePreferences(){
saveConsent({
necessary: true,
analytics: document.getElementById('epc-cat-analytics').checked,
marketing: document.getElementById('epc-cat-marketing').checked
});
}
function init(){
var consent=getConsent();
if(consent){
activateScripts(consent);
}else{
openBanner();
}
document.getElementById('epc-cookie-modal-overlay').addEventListener('click', function (e){
if(e.target===this) closeModal();
});
}
document.addEventListener('DOMContentLoaded', init);
return {
acceptAll: acceptAll,
rejectAll: rejectAll,
savePreferences: savePreferences,
openModal: openModal,
closeModal: closeModal,
getConsent: getConsent
};})();