!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={3209:(e,t,r)=>{r.d(t,{Mw:()=>s,OP:()=>o,UT:()=>c,Yh:()=>i,eM:()=>a,fJ:()=>u,q9:()=>n});const n=100n,o=2,i=3,s=1n,u=0,c=100,a={AMOUNT:"Amount",RATE:"Rate"}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}(()=>{r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})}})(),(()=>{r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var n={};r.r(n),r.d(n,{amountFromCents:()=>u,amountToCents:()=>s,currencyAmountFromCents:()=>c,formatDiscount:()=>f,parsePrice:()=>a});var o=r(3209);const i={USD:"$",EUR:"€",GBP:"£",CAD:"C$",AUD:"A$",NZD:"NZ$",CHF:"CHF",ARS:"AR$",BRL:"R$",MXN:"MX$"};function s(e){if(null==e)throw new Error("amount is required");let t=String(e).trim();if(t.includes(",")&&t.includes(".")?t=t.replace(/,/g,""):t.includes(",")&&!t.includes(".")&&(t=t.replace(",",".")),!/^\d+(\.\d+)?$/.test(t))throw new Error(`Invalid money format: "${e}"`);const[r,n=""]=t.split("."),i=`${n}000`,s=i[0]??"0",u=i[1]??"0",c=i[2]??"0",a=n.length>o.Yh?n.slice(o.Yh):"",f=/[1-9]/.test(a);let l=BigInt(r)*o.q9+BigInt(s+u);return(c>"5"||"5"===c||"5"===c&&f)&&(l+=o.Mw),Number(l)}function u(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error("cents must be a safe integer Number (or pass BigInt/string).");t=BigInt(e)}else{if("string"!=typeof e)throw new Error("cents must be a bigint, number, or numeric string.");{const r=e.trim();if(!/^\d+$/.test(r))throw new Error("cents string must contain digits only (e.g., '1234').");t=BigInt(r)}}if(t<o.fJ)throw new Error("cents must be non-negative.");const r=t/o.q9,n=t%o.q9;return`${r.toString()}.${n.toString().padStart(o.OP,"0")}`}function c(e,t="USD"){let r="!ERROR";if("number"!=typeof e||!Number.isInteger(e))return console.error("ERROR - currencyAmountFromCents: cents must be an integer number"),r;try{const n=u(e);r=`${i[t]??"$"}${n}`}catch(e){console.error(`ERROR - currencyAmountFromCents: ${e}`)}return r}const a=e=>{if(null==e)throw new Error("priceString is required");let t=String(e).trim();if(t.includes("-"))throw new Error("Negative amounts are not allowed");if(t=t.replace(/[^\d.,]/g,""),!t)throw new Error(`Invalid price: "${e}"`);return s(t)},f=(e,t)=>t===o.eM.AMOUNT?c(e):t===o.eM.RATE?e/o.UT+"%":"";return n})()));
//# sourceMappingURL=money.js.map