// EU-27 membership helper — used to gate which customs documents we render
// on a shipment cell. Phase 1A (OPEN-023, NP/Vasyl Shpak 2026-06-01): intra-EU
// (CZ→EU) is treated like DOMESTIC — NO invoice object, NO items[]/HS, NO
// Customs Declaration (sending the invoice object for intra-EU even causes
// errors). Customs data (invoice + items[] + Customs Declaration) is required
// ONLY for non-EU shipments (CZ→UA). So 'eu' classifies the same as 'domestic'
// for the customs-skip decision (bulk wizard Step 2 + invoice gating).
//
// UMD-style export so both Node (BE, Electron main) and browser contexts
// (Chrome extension content script, Electron renderer) can use it.
(function (root) {
  // EU-27 member states as of 2026 (ISO 3166-1 alpha-2). UK left in 2020;
  // Norway / Switzerland / Iceland / Liechtenstein are EEA/EFTA, NOT EU.
  var EU_MEMBERS = [
    'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR',
    'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL',
    'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'
  ];
  var EU_SET = Object.create(null);
  for (var i = 0; i < EU_MEMBERS.length; i++) EU_SET[EU_MEMBERS[i]] = true;

  function isEU(countryCode) {
    if (!countryCode) return false;
    return EU_SET[String(countryCode).toUpperCase()] === true;
  }

  // Three-tier classification used by the orders-list cell renderer and the
  // bulk wizard pre-flight summary.
  //   'domestic' — sender == recipient country
  //   'eu'       — both EU members but different countries
  //   'non-eu'   — recipient outside EU
  // Returns null if either argument is missing.
  function shipmentClass(senderCC, recipientCC) {
    if (!senderCC || !recipientCC) return null;
    var s = String(senderCC).toUpperCase();
    var r = String(recipientCC).toUpperCase();
    if (s === r) return 'domestic';
    if (isEU(s) && isEU(r)) return 'eu';
    return 'non-eu';
  }

  var api = { EU_MEMBERS: EU_MEMBERS, isEU: isEU, shipmentClass: shipmentClass };
  if (typeof module !== 'undefined' && module.exports) module.exports = api;
  else { root.NP = root.NP || {}; root.NP.eu = api; }
})(typeof self !== 'undefined' ? self : this);
