{
  "version": 3,
  "sources": ["/cdn/shop/t/230/assets/rxapp-market-rate.js?cb=6631"],
  "sourcesContent": ["/* Rx-button currency fix (2026-09-16, per rxapp spec).\n\n   data-price on .btnPrescription/.btnAddToCart is the frame price \u2014 Shopify\n   Markets already converts it to the buyer's presentment currency server-side.\n   data-prescription-addon is our lens surcharge, always in shop currency\n   (USD), never converted by Shopify. The old render mixed the two (adding\n   converted frame price + raw USD addon) and formatted with the shop's\n   money_format, which hardcodes the shop's own currency symbol \u2014 wrong\n   number AND wrong symbol for any buyer whose currency differs from the\n   shop's.\n\n   Fix: multiply only the addon by rxapp's own buyer-market rate\n   (Shopify.currency.rate is off by ~5-6% \u2014 it omits the market's price\n   adjustment). One fetch per page load; variant switches (hg-product-\n   swatches.js) reuse the cached rate via window.__rxappUpdateRxButtons(). */\n(function () {\n  'use strict';\n\n  var SHOP_CURRENCY = document.documentElement.getAttribute('data-shop-currency');\n  window.__rxapp = window.__rxapp || {};\n\n  function formatMoney(cents, currency) {\n    try {\n      return new Intl.NumberFormat('en-US', { style: 'currency', currency: currency }).format(cents / 100);\n    } catch (e) {\n      return (currency || '') + ' ' + (cents / 100).toFixed(2);\n    }\n  }\n  window.__rxappFormatMoney = formatMoney;\n\n  function activeCurrency() {\n    return (window.Shopify && Shopify.currency && Shopify.currency.active) || SHOP_CURRENCY;\n  }\n\n  /* Native \"Add to Cart\" price \u2014 the number is already correct (Markets\n     converts it), only the currency symbol needs fixing. No rate needed. */\n  function updatePlainPrices() {\n    var cur = activeCurrency();\n    document.querySelectorAll('.btnAddToCart strong[data-price]').forEach(function (el) {\n      el.textContent = formatMoney(parseInt(el.getAttribute('data-price'), 10) || 0, cur);\n    });\n  }\n  window.__rxappUpdatePlainPrices = updatePlainPrices;\n\n  /* Frame-only base (2026-10-14). rxapp prices an Rx order from the frame\n     price without lenses \u2014 a variant metafield named in rxapp settings.\n     snippets/add-buttons.liquid renders the same rule server-side plus a\n     \"variantId:cents,\u2026\" map in the button's data-frame-only (shop currency\n     only, valid values only). window.__rxapp.frameOnly (dollars, from rxapp)\n     is the fallback. Without this the shop-currency recompute below would put\n     the full-price \"from\" back over the correct server render. */\n  function frameOnlyCents(btn, priceCents) {\n    var variantId = btn.getAttribute('data-variant-id');\n    var map = {};\n    (btn.getAttribute('data-frame-only') || '').split(',').forEach(function (pair) {\n      var p = pair.split(':');\n      if (p.length === 2) map[p[0]] = parseInt(p[1], 10);\n    });\n    var c = map[variantId];\n    if (c == null) {\n      var d = window.__rxapp.frameOnly && window.__rxapp.frameOnly[variantId];\n      c = d != null ? Math.round(parseFloat(d) * 100) : null;\n    }\n    return c > 0 && c < priceCents ? c : priceCents;\n  }\n\n  /* Rx button \u2014 needs the market rate for the addon portion.\n     window.__rxapp.marketRate: undefined = still loading, null = no\n     adjustment available (shop-currency fallback), {rate,currency} = ready. */\n  function updateRxButtons() {\n    var info = window.__rxapp.marketRate;\n    document.querySelectorAll('.btnPrescription[data-prescription-addon]').forEach(function (btn) {\n      var strong = btn.querySelector('strong');\n      if (!strong) return;\n      var price = parseInt(btn.getAttribute('data-price'), 10) || 0;\n      var addon = parseInt(btn.getAttribute('data-prescription-addon'), 10) || 0;\n\n      if (info === undefined) {\n        /* currency differs from shop's and the rate hasn't arrived yet \u2014\n           hide the number rather than show a wrong one. visibility, not\n           emptying: the server-rendered text keeps the button's width, so\n           it doesn't collapse and re-grow when the rate lands */\n        strong.style.visibility = 'hidden';\n        return;\n      }\n      strong.style.visibility = '';\n      var cur, fromCents;\n      if (info === null) {\n        cur = SHOP_CURRENCY;\n        fromCents = frameOnlyCents(btn, price) + addon;\n      } else {\n        cur = info.currency;\n        fromCents = price + Math.round(addon * info.rate);\n      }\n      strong.textContent = formatMoney(fromCents, cur);\n    });\n  }\n  window.__rxappUpdateRxButtons = updateRxButtons;\n\n  function fetchRate() {\n    var btn = document.querySelector('.btnPrescription[data-variant-id]');\n    var variantId = btn ? btn.getAttribute('data-variant-id') : null;\n    if (!variantId) {\n      window.__rxapp.marketRate = null;\n      updateRxButtons();\n      return;\n    }\n    var country = (window.Shopify && Shopify.country) || '';\n    fetch('/apps/rxapp/market-rate?variant=' + encodeURIComponent(variantId) + '&country=' + encodeURIComponent(country))\n      .then(function (r) { return r.json(); })\n      .then(function (json) {\n        window.__rxapp.marketRate = (json && json.data) || null;\n      })\n      .catch(function () {\n        window.__rxapp.marketRate = null;\n      })\n      .then(updateRxButtons);\n  }\n\n  updatePlainPrices();\n\n  if (activeCurrency() === SHOP_CURRENCY) {\n    /* Same currency \u2014 today's shop-currency render is already correct. */\n    window.__rxapp.marketRate = null;\n    updateRxButtons();\n  } else {\n    updateRxButtons(); /* hides the number while the fetch is in flight */\n    fetchRate();\n  }\n})();\n"],
  "mappings": "CAeC,UAAY,CACX,aAEA,IAAI,cAAgB,SAAS,gBAAgB,aAAa,oBAAoB,EAC9E,OAAO,QAAU,OAAO,SAAW,CAAC,EAEpC,SAAS,YAAY,MAAO,SAAU,CACpC,GAAI,CACF,OAAO,IAAI,KAAK,aAAa,QAAS,CAAE,MAAO,WAAY,SAAU,QAAS,CAAC,EAAE,OAAO,MAAQ,GAAG,CACrG,OAAS,EAAG,CACV,OAAQ,UAAY,IAAM,KAAO,MAAQ,KAAK,QAAQ,CAAC,CACzD,CACF,CACA,OAAO,mBAAqB,YAE5B,SAAS,gBAAiB,CACxB,OAAQ,OAAO,SAAW,QAAQ,UAAY,QAAQ,SAAS,QAAW,aAC5E,CAIA,SAAS,mBAAoB,CAC3B,IAAI,IAAM,eAAe,EACzB,SAAS,iBAAiB,kCAAkC,EAAE,QAAQ,SAAU,GAAI,CAClF,GAAG,YAAc,YAAY,SAAS,GAAG,aAAa,YAAY,EAAG,EAAE,GAAK,EAAG,GAAG,CACpF,CAAC,CACH,CACA,OAAO,yBAA2B,kBASlC,SAAS,eAAe,IAAK,WAAY,CACvC,IAAI,UAAY,IAAI,aAAa,iBAAiB,EAC9C,IAAM,CAAC,GACV,IAAI,aAAa,iBAAiB,GAAK,IAAI,MAAM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