var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/salesSdk/utils/buildCustomOrderProductFromCustomiseItem.ts
var buildCustomOrderProductFromCustomiseItem_exports = {};
__export(buildCustomOrderProductFromCustomiseItem_exports, {
  buildCustomOrderProductFromCustomiseItem: () => buildCustomOrderProductFromCustomiseItem
});
module.exports = __toCommonJS(buildCustomOrderProductFromCustomiseItem_exports);
var import_utils = require("@pisell/utils");
function parseUnitPrice(input) {
  const raw = Number.parseFloat(String(input.priceValue ?? "").trim());
  const abs = Number.isFinite(raw) ? Math.abs(raw) : 0;
  const signed = input.priceType === "deduction" ? -abs : abs;
  return signed.toFixed(2);
}
function buildCustomOrderProductFromCustomiseItem(input) {
  var _a;
  const productName = ((_a = input.productName) == null ? void 0 : _a.trim()) || import_utils.locales.getText("pisell2.customise-item.default-product-name");
  const unitPrice = parseUnitPrice(input);
  const quantity = Math.max(1, Math.floor(Number(input.quantity) || 1));
  return {
    product_id: null,
    product_variant_id: 0,
    order_detail_id: null,
    num: quantity,
    selling_price: unitPrice,
    original_price: unitPrice,
    tax_fee: "0.00",
    is_charge_tax: 0,
    discount_list: [],
    product_option_item: [],
    product_bundle: [],
    note: "",
    metadata: {
      discountable_flag: input.vouchersApplicable ? 1 : 0,
      origin: {
        title: productName,
        name: productName,
        isCustomItem: true
      }
    },
    _origin: {
      title: productName,
      name: productName,
      isCustomItem: true,
      price: unitPrice
    }
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildCustomOrderProductFromCustomiseItem
});
