/**
 * @file
 */
(function (Drupal, cookies, once, drupalSettings) {
  Drupal.behaviors.tocEmrBrand = {
    attach: function (context) {
      /**
       * Sets and hides the brand mascot.
       */
      once('tocEmrBrand', 'html', context).forEach( function () {
        const maxMascotCount = 3;
        const body = document.body;
        let mascotCount = parseInt(cookies.get('mascot', {path: '/'}));
        if (mascotCount === undefined || !mascotCount || isNaN(mascotCount)) {
          mascotCount = 0;
        }
        if (mascotCount < maxMascotCount) {
          setTimeout(function() {
            body.classList.add('brd-img-on');
            setTimeout(function() {
              body.classList.remove('brd-img-on');
            }, 3000);
          }, 300);
          mascotCount += 1;
          cookies.set('mascot', mascotCount, {path: '/'});
        }
      });
    }
  }
})(Drupal, window.Cookies, once, drupalSettings);
