/* eslint-disable */
// Pricing helpers — dual-pricing in XCG and USD.
//
// The Caribbean guilder (XCG, successor to ANG) is pegged at 1 USD = 1.79 XCG.
// Prices on the site are quoted in XCG (the local currency) with a USD
// equivalent shown alongside for international readers.

const XCG_PER_USD = 1.79;

function xcgToUsd(xcg, round = 1) {
  const v = xcg / XCG_PER_USD;
  return Math.round(v / round) * round;
}

function fmtNum(n) {
  return Math.round(n).toLocaleString('en-US');
}

// Returns "XCG 1,250 · USD 700" — used inline anywhere a single price displays.
function formatPrice(xcg, { round = 1 } = {}) {
  return 'XCG ' + fmtNum(xcg) + ' · USD ' + fmtNum(xcgToUsd(xcg, round));
}

// Returns just "USD 700" — for use after an XCG number was rendered separately
// (e.g. in big-numerical price cards where USD sits as a secondary line).
function usdLine(xcg, { round = 1 } = {}) {
  return 'USD ' + fmtNum(xcgToUsd(xcg, round));
}

// Range formatter, e.g. 18000–24000 → "XCG 18,000 – 24,000 · USD 10,100 – 13,400"
function formatRange(minXcg, maxXcg, { round = 100 } = {}) {
  const minU = xcgToUsd(minXcg, round);
  const maxU = xcgToUsd(maxXcg, round);
  return 'XCG ' + fmtNum(minXcg) + ' – ' + fmtNum(maxXcg)
       + ' · USD ' + fmtNum(minU) + ' – ' + fmtNum(maxU);
}

Object.assign(window, { XCG_PER_USD, xcgToUsd, fmtNum, formatPrice, usdLine, formatRange });
