"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get formatDisplayPrice () {
        return formatDisplayPrice;
    },
    get getFormattedInvoiceItemCoverageAmount () {
        return getFormattedInvoiceItemCoverageAmount;
    },
    get getFormattedInvoiceItemNetCost () {
        return getFormattedInvoiceItemNetCost;
    },
    get getInvoiceItemDiscountPriceDisplay () {
        return getInvoiceItemDiscountPriceDisplay;
    },
    get getInvoiceItemPriceDisplay () {
        return getInvoiceItemPriceDisplay;
    },
    get getInvoiceSummaryDisplay () {
        return getInvoiceSummaryDisplay;
    },
    get round () {
        return round;
    }
});
const _estoolkit = require("es-toolkit");
const _decimal = /*#__PURE__*/ _interop_require_default(require("decimal.js"));
const _invoice = require("./invoice");
const _invoiceItem = require("./invoiceItem");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const round = (value, decimals = 2)=>{
    return new _decimal.default(value).toNearest(new _decimal.default(10).pow(-decimals)).toNumber();
};
const formatDisplayPrice = (value)=>{
    if (value === undefined) {
        return undefined;
    }
    const floatValue = typeof value === 'number' ? value : parseFloat(value.toString());
    if (isNaN(floatValue)) {
        return undefined;
    }
    return floatValue.toLocaleString('en-US', {
        minimumFractionDigits: 2,
        maximumFractionDigits: 2
    });
};
const getInvoiceSummaryDisplay = (invoice)=>{
    const summary = (0, _invoice.getInvoiceSummary)(invoice);
    return (0, _estoolkit.mapValues)(summary, (value)=>formatDisplayPrice(value));
};
const getInvoiceItemPriceDisplay = (invoiceItem)=>{
    const rawPriceValue = (0, _invoiceItem.getInvoiceItemTotalPrice)(invoiceItem);
    const unformattedPrice = isNaN(parseFloat(rawPriceValue.toString())) ? undefined : rawPriceValue;
    return formatDisplayPrice(unformattedPrice);
};
const getInvoiceItemDiscountPriceDisplay = (invoiceItem)=>{
    return formatDisplayPrice(isNaN(parseFloat(invoiceItem?.discount?.amount?.toString() || '')) ? undefined : (0, _invoiceItem.getInvoiceItemTotalDiscountedPrice)(invoiceItem));
};
const getFormattedInvoiceItemCoverageAmount = (item)=>{
    if (!item?.product?.insurable || !item.insurancePlanItems?.length) {
        return formatDisplayPrice(0);
    }
    const coverage = (0, _invoiceItem.getItemTotalInsuranceCoverageAmount)(item);
    return formatDisplayPrice(-coverage);
};
const getFormattedInvoiceItemNetCost = (item)=>{
    const netCost = (0, _invoiceItem.getInvoiceItemNetCost)(item);
    return formatDisplayPrice(netCost);
};

//# sourceMappingURL=display.js.map