var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Sales/Summary/utils.ts
var utils_exports = {};
__export(utils_exports, {
  calculatePriceDetails: () => calculatePriceDetails,
  calculateSubtotal: () => calculateSubtotal,
  calculateTaxFee: () => calculateTaxFee
});
module.exports = __toCommonJS(utils_exports);
var import_decimal = __toESM(require("decimal.js"));
var calculateSubtotal = (items) => {
  if (!(items == null ? void 0 : items.length)) {
    return "0.00";
  }
  const subtotal = items.reduce((sum, item) => {
    const price = new import_decimal.default(item.price || 0);
    const quantity = new import_decimal.default(item.quantity || 1);
    return sum.plus(price.times(quantity));
  }, new import_decimal.default(0));
  return subtotal.toFixed(2);
};
var calculateTaxFee = (shopInfo, items) => {
  if (!(items == null ? void 0 : items.length)) {
    return "0.00";
  }
  const { is_price_include_tax, tax_rate } = shopInfo || {};
  console.log("shopInfo>>>", is_price_include_tax, tax_rate);
  const totalTaxFee = items.reduce((sum, item) => {
    const price = new import_decimal.default(item.price || 0);
    const taxRate = new import_decimal.default(tax_rate || 0).div(100);
    const productTaxRate = price.times(taxRate).times((item == null ? void 0 : item.is_charge_tax) || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
    return sum.plus(productTaxRate);
  }, new import_decimal.default(0));
  return totalTaxFee;
};
var calculatePriceDetails = (shopInfo, items) => {
  const subtotal = new import_decimal.default(calculateSubtotal(items));
  const totalTaxFee = new import_decimal.default(calculateTaxFee(shopInfo, items));
  console.log("totalTaxFee", totalTaxFee.toFixed(2));
  const total = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subtotal : subtotal.plus(totalTaxFee);
  return {
    subtotal: subtotal.toFixed(2),
    total: total.toFixed(2),
    taxTitle: shopInfo == null ? void 0 : shopInfo.tax_title,
    totalTaxFee: totalTaxFee.toFixed(2),
    isPriceIncludeTax: shopInfo == null ? void 0 : shopInfo.is_price_include_tax
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  calculatePriceDetails,
  calculateSubtotal,
  calculateTaxFee
});
