// Detect whether the current Shoptet page represents an authenticated admin
// session. Runs in page context. Uses multiple independent DOM markers so a
// minor Shoptet UI tweak can't silently flip us from "not logged in" to
// "logged in" or vice versa.
(function (root) {
  function isLoggedInAdmin() {
    try {
      if (!/\/admin(\/|$)/.test(location.pathname)) return false;
      if (/\/admin\/login/.test(location.pathname)) return false;

      // Signal 1: Shoptet admin user navigation block.
      if (document.querySelector('.headerNavigation__item--user')) return true;
      // Signal 2: any logout link.
      if (document.querySelector('a[href*="logout"]')) return true;
      // Signal 3: shop ID "ID: NNN" text in header (same locator the extension
      // uses for detection — authenticated pages always have it).
      var spans = document.querySelectorAll('header span, header a span');
      for (var i = 0; i < spans.length; i++) {
        if (/ID:\s*\d+/.test(spans[i].textContent)) return true;
      }
      return false;
    } catch (e) {
      return false;
    }
  }

  var IS_LOGGED_IN_SRC = '(' + isLoggedInAdmin.toString() + ')()';

  var api = {
    isLoggedInAdmin: isLoggedInAdmin,
    IS_LOGGED_IN_SRC: IS_LOGGED_IN_SRC
  };
  if (typeof module !== 'undefined' && module.exports) module.exports = api;
  else { root.NP = root.NP || {}; root.NP.shoptetAuthCheck = api; }
})(typeof self !== 'undefined' ? self : this);
