document.addEventListener('DOMContentLoaded', function () {
  var cookieNotice = document.getElementById('cookie-notice');
  var acceptCookies = document.getElementById('accept-cookies');
  var rejectCookies = document.getElementById('reject-cookies');

  // 检查Cookie
  function checkCookie() {
    var cookieAccepted = getCookie('cookieAccepted');
    var cookieRejected = getCookie('cookieRejected');

    if (cookieAccepted === 'true') {
      // 如果接受了Cookie，则不显示通知
      cookieNotice.style.display = 'none';
    } else if (cookieRejected === 'true') {
      // 如果拒绝了Cookie，则显示通知，但设置一天后再次询问
      setTimeout(function () {
        cookieNotice.style.display = 'block';
      }, 24 * 60 * 60 * 1000); // 24小时后显示
    } else {
      // 如果没有Cookie，则立即显示通知
      cookieNotice.style.display = 'block';
    }
  }

  // 接受Cookie
  acceptCookies.addEventListener('click', function () {
    setCookie('cookieAccepted', 'true', 365);
    cookieNotice.style.display = 'none';
  });

  // 拒绝Cookie
  rejectCookies.addEventListener('click', function () {
    setCookie('cookieRejected', 'true', 1);
    cookieNotice.style.display = 'none';
  });

  // 设置Cookie
  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 + "=" + (value || "") + expires + "; path=/";
  }

  // 获取Cookie
  function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) == ' ') c = c.substring(1, c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
  }

  // 检查Cookie并显示/隐藏通知
  checkCookie();
});
