(function(){
  var MIN_TIME = 5200;
  function buildLoader(){
    var loader=document.querySelector('.premium-page-loader');
    if(loader) return loader;
    loader=document.createElement('div');
    loader.className='premium-page-loader';
    var word='NOTORIOUS';
    var letters=word.split('').map(function(ch,i){return '<span style="animation-delay:'+ (i*0.25).toFixed(3) +'s">'+ch+'</span>';}).join('');
    loader.innerHTML='<div class="premium-loader-box"><div class="premium-loader-word">'+letters+'</div><div class="premium-loader-line"></div><div class="premium-loader-sub">Market & Coffee · 24/7</div></div>';
    document.body.appendChild(loader);
    return loader;
  }
  function show(ms, cb){
    var loader=buildLoader();
    loader.classList.remove('show');
    void loader.offsetWidth;
    loader.classList.add('show');
    setTimeout(function(){
      if(cb){ cb(); return; }
      loader.classList.remove('show');
    }, ms || MIN_TIME);
  }
  function init(){
    show(MIN_TIME);
    document.addEventListener('click', function(e){
      var a=e.target.closest && e.target.closest('a[href]');
      if(!a) return;
      var href=a.getAttribute('href') || '';
      if(!href || href.charAt(0)==='#' || href.startsWith('tel:') || href.startsWith('mailto:') || href.startsWith('sms:') || href.startsWith('javascript:') || href.includes('wa.me') || a.target==='_blank') return;
      var url;
      try{ url=new URL(href, window.location.href); }catch(err){ return; }
      if(url.origin!==window.location.origin && !href.startsWith('../') && !href.endsWith('.html')) return;
      e.preventDefault();
      show(3600, function(){ window.location.href=url.href; });
    }, true);
  }
  if(document.readyState==='loading') document.addEventListener('DOMContentLoaded', init); else init();
})();
