// Shoptet's country codebook is GLOBAL (platform-wide) — an e-shop only enables
// a subset for delivery, but the numeric country id is the same everywhere
// (verified: the /admin/countries/ CountriesListing JSON and the order-detail
// #deliveryCountryId <select> agree — CZ=43, DE=44, PL=136, SK=151, UA=170…).
//
// We need this map because the surfaces that expose the country id do NOT expose
// its ISO code:
//   - /admin/countries/ CountriesListing → { id, name } (no ISO; `code` = currency)
//   - order detail #deliveryCountryId <option value=id>name</option> (no ISO)
// …while everything we route on (NP branch country, BC i18n) keys on ISO. So map
// id <-> ISO here, locale-independently (name-based mapping would break on a
// non-English admin: "Česká republika" vs "Czech Republic").
//
// Covers EU-27 + UA (Phase 1/1B scope) + a few common non-EU. IDs lifted from a
// verified #deliveryCountryId option list. Extend as NP enables more countries;
// an id absent here resolves to ISO null (caller logs + skips gating, but the
// raw id is still usable for the write-back).
(function (root) {
  var ISO_TO_ID = {
    CZ: 43, SK: 151, DE: 44, PL: 136, UA: 170,
    AT: 8, BE: 14, BG: 16, HR: 73, CY: 42, DK: 46, EE: 50, FI: 54, FR: 55,
    GR: 67, HU: 75, IE: 77, IT: 83, LV: 103, LT: 101, LU: 102, MT: 114,
    NL: 126, PT: 139, RO: 141, SI: 150, ES: 52, SE: 148,
    GB: 57, CH: 33, NO: 127, US: 172
  };
  var ID_TO_ISO = {};
  for (var iso in ISO_TO_ID) {
    if (Object.prototype.hasOwnProperty.call(ISO_TO_ID, iso)) {
      ID_TO_ISO[ISO_TO_ID[iso]] = iso;
    }
  }

  function isoForCountryId(id) {
    if (id == null) return null;
    return ID_TO_ISO[String(id).trim()] || null;
  }
  function countryIdForIso(iso) {
    if (!iso) return null;
    var v = ISO_TO_ID[String(iso).trim().toUpperCase()];
    return v == null ? null : v;
  }

  var api = {
    ISO_TO_ID: ISO_TO_ID,
    ID_TO_ISO: ID_TO_ISO,
    isoForCountryId: isoForCountryId,
    countryIdForIso: countryIdForIso
  };
  if (typeof module !== 'undefined' && module.exports) module.exports = api;
  else { root.NP = root.NP || {}; root.NP.shoptetCountryIds = api; }
})(typeof self !== 'undefined' ? self : this);
