// URL-based detection of Shoptet admin pages. Works without DOM access
// so it can be called from Electron main process on navigation events.
(function (root) {
  // Shoptet admin slugs depend on the admin's UI language, each spelled in that
  // language — so the same page has a different path per language:
  //   EN /admin/orders-listing/      + /admin/order-detail/
  //   CZ /admin/prehled-objednavek/  + /admin/objednavky-detail/   ("přehled objednávek")
  //   SK /admin/prehlad-objednavok/  + /admin/objednavok-detail/   ("prehľad objednávok")
  //   HU /admin/rendeles-lista/                                    ("rendelés lista")
  // These URL slugs are a FAST PATH only — the caller (maybeInjectPageUi) has a
  // language-agnostic DOM fallback (#orders-listing table / order contact-modify
  // testids), so an unlisted admin language still injects. Recognising the common
  // slugs just avoids the extra DOM probe (Samuel 2026-07-07: SK/HU admins).
  function isOrdersListPage(pathname) {
    if (!pathname) return false;
    if (isOrderDetailPage(pathname)) return false;
    return pathname.indexOf('/admin/orders') !== -1
      || /\/admin\/(prehl[ae]d-objednav[eo]k|rendeles-lista)/.test(pathname);
  }
  function isOrderDetailPage(pathname) {
    if (!pathname) return false;
    // Shoptet's real slug is SINGULAR: /admin/order-detail/ (EN/myshoptet);
    // the check used the plural "orders-detail", which never matched — so the
    // order-detail overlay (Create / Change branch / Cancel — Req-F-018/019)
    // never injected (Samuel 2026-06-18). Match EN singular/plural + the CZ
    // ("objednavky-detail") and SK ("objednavok-detail") spellings via objedn[aá]v\w*.
    return /\/admin\/(orders?-detail|objedn[aá]v\w*-detail)/.test(pathname);
  }
  function isHtmlCodePage(pathname) {
    return !!pathname && pathname.indexOf('/admin/html-code') !== -1;
  }
  function isShippingMethodsPage(pathname) {
    return !!pathname && pathname.indexOf('/admin/billing-and-shipping') !== -1;
  }
  function isLoginPage(pathname) {
    return !!pathname && pathname.indexOf('/admin/login') !== -1;
  }
  function isAdminPage(pathname) {
    return !!pathname && pathname.indexOf('/admin') !== -1 && !isLoginPage(pathname);
  }

  // DOM-based check — usable inside page context only.
  function isShoptetAdminDom() {
    return !!document.querySelector('meta[name="author"][content*="Shoptet"]')
      || !!document.querySelector('[class*="shoptet"]')
      || !!document.querySelector('script[src*="shoptet"]');
  }

  var api = {
    isOrdersListPage: isOrdersListPage,
    isOrderDetailPage: isOrderDetailPage,
    isHtmlCodePage: isHtmlCodePage,
    isShippingMethodsPage: isShippingMethodsPage,
    isLoginPage: isLoginPage,
    isAdminPage: isAdminPage,
    isShoptetAdminDom: isShoptetAdminDom
  };
  if (typeof module !== 'undefined' && module.exports) module.exports = api;
  else { root.NP = root.NP || {}; root.NP.shoptetDetect = api; }
})(typeof self !== 'undefined' ? self : this);
