function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import dayjs from 'dayjs';
import Decimal from 'decimal.js';
var DEFAULT_LOCALES = ['en', 'zh_CN'];
var LABELS = {
  en: {
    contactName: 'Contact name',
    contactMobile: 'Contact Mobile',
    email: 'email',
    dineIn: 'Dine-in',
    takeAway: 'Take away',
    delivery: 'Delivery',
    pickUp: 'Pick-up',
    shopService: 'Dine-in',
    pickUpTime: 'Pick-up time',
    asap: 'ASAP',
    cash: 'Cash',
    eftpos: 'Eftpos',
    wallet: 'Wallet',
    giftCard: 'Gift card',
    remainingAmount: 'Remaining amount',
    redeemPoints: 'Redeem points',
    remainingPoints: 'Remaining points',
    table: 'Table',
    orderDiscount: 'Order discount',
    payProcessingFee: 'Pay processing fee',
    rounding: 'Rounding'
  },
  zh_CN: {
    contactName: '联系人姓名',
    contactMobile: '联系电话',
    email: '邮箱',
    dineIn: '堂食',
    takeAway: '外带',
    delivery: '配送',
    pickUp: '自提',
    shopService: '堂食',
    pickUpTime: '取餐时间',
    asap: '尽快',
    cash: '现金支付',
    eftpos: '刷卡支付',
    wallet: '钱包支付',
    giftCard: '礼品卡',
    remainingAmount: '剩余金额',
    redeemPoints: '本次使用积分',
    remainingPoints: '剩余积分',
    table: '桌台',
    orderDiscount: '整单折扣',
    payProcessingFee: '支付手续费',
    rounding: '抹零'
  },
  zh_HK: {
    contactName: '聯絡人姓名',
    contactMobile: '聯絡電話',
    email: '電郵',
    dineIn: '堂食',
    takeAway: '外帶',
    delivery: '配送',
    pickUp: '自取',
    shopService: '堂食',
    pickUpTime: '取餐時間',
    asap: '盡快',
    cash: '現金支付',
    eftpos: '刷卡支付',
    wallet: '錢包支付',
    giftCard: '禮品卡',
    remainingAmount: '剩餘金額',
    redeemPoints: '本次使用積分',
    remainingPoints: '剩餘積分',
    table: '桌台',
    orderDiscount: '整單折扣',
    payProcessingFee: '支付手續費',
    rounding: '抹零'
  }
};
export function buildSmallTicketData(params) {
  var order = params.order || {};
  var shopInfo = params.shopInfo || {};
  var locales = resolveLocales(shopInfo, params.locales);
  var productMap = params.productMap || {};
  return locales.reduce(function (data, locale) {
    data[locale] = buildLocaleData({
      order: order,
      shopInfo: shopInfo,
      locale: locale,
      productMap: productMap
    });
    return data;
  }, {});
}
export function hasSmallTicketData(value) {
  return !!value && _typeof(value) === 'object' && Object.keys(value).length > 0;
}
function buildLocaleData(params) {
  var order = params.order,
    shopInfo = params.shopInfo,
    locale = params.locale,
    productMap = params.productMap;
  var products = buildProducts(order, locale, productMap);
  var summary = getSummary(order);
  var currencySymbol = getCurrencySymbol(order, shopInfo);
  return {
    base_data: buildBaseData({
      order: order,
      shopInfo: shopInfo,
      locale: locale
    }),
    products: products,
    fees: buildFees({
      order: order,
      shopInfo: shopInfo,
      locale: locale,
      products: products,
      summary: summary,
      currencySymbol: currencySymbol
    }),
    customer: buildCustomer(order, locale),
    appointment: buildAppointment(order, locale),
    // delivery: buildDelivery(order, locale),
    resources: buildResources(order, locale),
    payment_data: buildPaymentData({
      order: order,
      locale: locale,
      currencySymbol: currencySymbol
    }),
    tickets: Array.isArray(order.tickets) ? order.tickets : [],
    source_shop: [],
    refund_data: [],
    expend_data: []
  };
}
function buildBaseData(params) {
  var _order$metadata;
  var order = params.order,
    shopInfo = params.shopInfo,
    locale = params.locale;
  var orderNumber = stringify(order.order_number || order.shop_full_order_number || order.shop_order_number || order.external_sale_number);
  return {
    shop_name: stringify(shopInfo.name || order.shop_name),
    note: stringify(order.note),
    shop_order_number: stringify(order.shop_order_number),
    order_number: orderNumber,
    shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
    shop_phone: stringify(shopInfo.phone || order.shop_phone),
    shop_address: stringify(shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
    original_payment_status: stringify(order.payment_status),
    is_repeat: 0,
    buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
    order_no: orderNumber,
    order_time: formatDateTime(order.created_at || order.sales_time || new Date(), locale)
  };
}
function buildProducts(order, locale, productMap) {
  var products = Array.isArray(order.products) ? order.products : [];
  return products.map(function (product) {
    var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric;
    var quantity = toNumber((_ref = (_ref2 = (_product$product_quan = product.product_quantity) !== null && _product$product_quan !== void 0 ? _product$product_quan : product.quantity) !== null && _ref2 !== void 0 ? _ref2 : product.num) !== null && _ref !== void 0 ? _ref : 1, 1);
    var originalPrice = (_ref3 = (_ref4 = (_ref5 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref5 !== void 0 ? _ref5 : product.payment_price) !== null && _ref4 !== void 0 ? _ref4 : product.price) !== null && _ref3 !== void 0 ? _ref3 : 0;
    var sellingPrice = (_ref6 = (_ref7 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.payment_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : originalPrice;
    var productTitle = resolveProductTitle({
      product: product,
      productMap: productMap,
      locale: locale
    });
    return _objectSpread(_objectSpread(_objectSpread({
      product_title: productTitle,
      product_quantity: quantity,
      selling_price: formatMoney(sellingPrice, getCurrencySymbol(order, null)),
      original_price: formatMoney(originalPrice, getCurrencySymbol(order, null)),
      total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), getCurrencySymbol(order, null)),
      extension_list: Array.isArray(product.extension_list) ? product.extension_list : []
    }, Array.isArray(product.options) ? {
      options: product.options.map(function (option) {
        return {
          name: getLocalizedValue(option.name || option.title, locale),
          value: getLocalizedValue(option.value || option.option || option.item, locale)
        };
      })
    } : {}), product.variant ? {
      variant: getLocalizedValue(product.variant, locale)
    } : {}), Array.isArray(product.combinations) ? {
      combinations: product.combinations
    } : {});
  });
}
function resolveProductTitle(params) {
  var _product$product, _product$product_id, _fallbackProduct$prod;
  var product = params.product,
    productMap = params.productMap,
    locale = params.locale;
  var ownTitle = getLocalizedValue(product.product_title || product.title || product.name || ((_product$product = product.product) === null || _product$product === void 0 ? void 0 : _product$product.title), locale);
  if (ownTitle) return ownTitle;
  var productId = (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product.id;
  var fallbackProduct = productId !== undefined && productId !== null ? productMap[productId] || productMap[String(productId)] : null;
  if (!fallbackProduct) return '';
  return getLocalizedValue(fallbackProduct.product_title || fallbackProduct.title || fallbackProduct.name || fallbackProduct.format_title || ((_fallbackProduct$prod = fallbackProduct.product) === null || _fallbackProduct$prod === void 0 ? void 0 : _fallbackProduct$prod.title), locale);
}
function buildFees(params) {
  var order = params.order,
    shopInfo = params.shopInfo,
    locale = params.locale,
    products = params.products,
    summary = params.summary,
    currencySymbol = params.currencySymbol;
  var fees = [];
  for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
    var _ref8, _surcharge$amount;
    var surcharge = _normalizeArray[_i];
    var value = (_ref8 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref8 !== void 0 ? _ref8 : surcharge.total_amount;
    if (!isNonZero(value)) continue;
    fees.push({
      item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
      value: formatMoney(value, currencySymbol)
    });
  }
  var discountAmount = summary.discount_amount || order.discount_amount || order.shop_discount;
  if (isNonZero(discountAmount)) {
    fees.push({
      item: label(locale, 'orderDiscount'),
      value: formatMoney(new Decimal(toMoneyNumber(discountAmount)).neg(), currencySymbol)
    });
  }
  var taxFee = summary.tax_fee || order.tax_fee;
  if (isNonZero(taxFee)) {
    fees.push({
      item: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
      value: formatMoney(taxFee, currencySymbol)
    });
  }
  var roundingAmount = summary.rounding_amount || order.rounding_amount;
  if (isNonZero(roundingAmount)) {
    fees.push({
      item: label(locale, 'rounding'),
      value: formatMoney(roundingAmount, currencySymbol)
    });
  }
  var payProcessingFee = summary.pay_service_charge_amount || order.pay_service_charge_amount;
  if (isNonZero(payProcessingFee)) {
    fees.push({
      item: label(locale, 'payProcessingFee'),
      value: formatMoney(payProcessingFee, currencySymbol)
    });
  }
  return {
    fees: fees,
    countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
      total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
      product_expect_amount: formatMoney(summary.product_expect_amount || summary.product_amount || order.product_expect_amount, currencySymbol),
      expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
      product_quantity: toNumber(summary.product_quantity || products.reduce(function (sum, product) {
        return sum + product.product_quantity;
      }, 0), 0),
      has_pay: formatMoney(sumPayments(order.payments), currencySymbol),
      payment_method: '',
      tax_title: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
      total_refund_amount: formatMoney(summary.total_refund_amount || order.total_refund_amount, currencySymbol)
    }, isNonZero(roundingAmount) ? {
      rounding_amount: formatMoney(roundingAmount, currencySymbol)
    } : {}), isNonZero(discountAmount) ? {
      order_total_discount: formatMoney(discountAmount, currencySymbol)
    } : {}), isNonZero(payProcessingFee) ? {
      pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
    } : {}), isNonZero(taxFee) ? {
      tax_fee: formatMoney(taxFee, currencySymbol)
    } : {})
  };
}
function buildCustomer(order, locale) {
  var _order$customer, _order$customer2, _order$customer3, _order$customer4;
  return [{
    item: label(locale, 'contactName'),
    value: normalizeCustomerDisplayValue(order.customer_name || ((_order$customer = order.customer) === null || _order$customer === void 0 ? void 0 : _order$customer.name) || ((_order$customer2 = order.customer) === null || _order$customer2 === void 0 ? void 0 : _order$customer2.display_name))
  }, {
    item: label(locale, 'contactMobile'),
    value: stringify(order.phone || ((_order$customer3 = order.customer) === null || _order$customer3 === void 0 ? void 0 : _order$customer3.phone))
  }, {
    item: label(locale, 'email'),
    value: stringify(order.email || ((_order$customer4 = order.customer) === null || _order$customer4 === void 0 ? void 0 : _order$customer4.email))
  }];
}
function normalizeCustomerDisplayValue(value) {
  var text = stringify(value).trim();
  if (!text) return 'Walk-In';
  if (text.toLowerCase() === 'select a customer') return 'Walk-In';
  return text;
}
function buildDelivery(order, locale) {
  var _order$metadata2;
  var serviceType = stringify(((_order$metadata2 = order.metadata) === null || _order$metadata2 === void 0 ? void 0 : _order$metadata2.service_type) || order.service_type || order.delivery_type);
  if (!serviceType) return [];
  var serviceTypeLabelKey = serviceTypeToLabelKey(serviceType);
  var items = [{
    item: '',
    value: label(locale, serviceTypeLabelKey),
    size: 2,
    align: 'left'
  }];
  if (serviceType === 'shop_server' || serviceType === 'shop_service') {
    items.push({
      item: label(locale, 'pickUpTime'),
      value: label(locale, 'asap')
    });
  }
  return items;
}
function buildAppointment(order, locale) {
  var _order$metadata3, _order$metadata4, _order$form_data;
  var tableName = order.table_name || ((_order$metadata3 = order.metadata) === null || _order$metadata3 === void 0 ? void 0 : _order$metadata3.table_name) || ((_order$metadata4 = order.metadata) === null || _order$metadata4 === void 0 || (_order$metadata4 = _order$metadata4.table) === null || _order$metadata4 === void 0 ? void 0 : _order$metadata4.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
  if (!tableName) return [];
  return [{
    item: label(locale, 'table'),
    value: getLocalizedValue(tableName, locale)
  }];
}
function buildResources(order, locale) {
  return normalizeArray(order.resources || order.resource_list).map(function (resource) {
    return {
      id: resource.id || resource.resource_id || '',
      code: '',
      title: getLocalizedValue(resource.title || resource.name, locale),
      form_title: getLocalizedValue(resource.form_title || resource.type || '', locale)
    };
  });
}
function buildPaymentData(params) {
  var payments = normalizeArray(params.order.payments);
  return payments.filter(function (payment) {
    return isPrintablePayment(payment);
  }).map(function (payment) {
    var _payment$amount;
    var items = [{
      item: paymentMethodName(payment, params.locale),
      value: formatMoney((_payment$amount = payment.amount) !== null && _payment$amount !== void 0 ? _payment$amount : payment.origin_amount, params.currencySymbol)
    }];
    var fundRecord = getFundRecord(payment);
    if (fundRecord) {
      items.push.apply(items, _toConsumableArray(buildFundRecordPaymentItems({
        payment: payment,
        fundRecord: fundRecord,
        locale: params.locale,
        currencySymbol: params.currencySymbol
      })));
    } else {
      var _ref9, _payment$remaining_am, _payment$metadata;
      var remainingAmount = (_ref9 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref9 !== void 0 ? _ref9 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
      if (remainingAmount !== undefined && remainingAmount !== null) {
        items.push({
          item: label(params.locale, 'remainingAmount'),
          value: formatMoney(remainingAmount, params.currencySymbol)
        });
      }
    }
    items.push({
      item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), params.locale),
      value: ''
    });
    return items;
  });
}
function buildFundRecordPaymentItems(params) {
  var payment = params.payment,
    fundRecord = params.fundRecord,
    locale = params.locale,
    currencySymbol = params.currencySymbol;
  var items = [];
  var usingBeforeValue = fundRecord.using_before_value;
  var usingAfterValue = fundRecord.using_after_value;
  if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
    var usedPoints = new Decimal(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
    items.push({
      item: label(locale, 'redeemPoints'),
      value: trimDecimal(usedPoints)
    });
    items.push({
      item: label(locale, 'remainingPoints'),
      value: trimDecimal(new Decimal(toMoneyNumber(usingAfterValue)))
    });
    return items;
  }
  if (usingAfterValue !== undefined && usingAfterValue !== null) {
    items.push({
      item: label(locale, 'remainingAmount'),
      value: formatMoney(usingAfterValue, currencySymbol)
    });
  }
  return items;
}
function getFundRecord(payment) {
  var fundRecord = payment.fund_record;
  if (!fundRecord || _typeof(fundRecord) !== 'object' || Array.isArray(fundRecord)) return null;
  if (!fundRecord.voucher_id && !fundRecord.code) return null;
  return fundRecord;
}
function isPointCardPayment(payment) {
  var _payment$fund_record;
  var code = stringify(payment.code || payment.payment_method).toUpperCase();
  var type = stringify(payment.type || ((_payment$fund_record = payment.fund_record) === null || _payment$fund_record === void 0 ? void 0 : _payment$fund_record.tag)).toLowerCase();
  return code === 'POINTCARD' || type === 'point_card';
}
function maskMachineCode(code) {
  var text = stringify(code);
  if (text.length <= 6) return text;
  return "".concat(text.slice(0, 2), "**").concat(text.slice(-4));
}
function trimDecimal(value) {
  return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
}
function getFundRecordPaymentName(payment, locale) {
  var fundRecord = getFundRecord(payment);
  if (!fundRecord) return '';
  var name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
  var code = maskMachineCode(fundRecord.code);
  if (!name && !code) return '';
  if (!code) return name;
  var fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
  return "".concat(name || fallbackName, "(").concat(code, ")");
}
function appendMachineCodeToName(name, payment) {
  var fundRecord = getFundRecord(payment);
  if (!(fundRecord !== null && fundRecord !== void 0 && fundRecord.code)) return name;
  return "".concat(name, "(").concat(maskMachineCode(fundRecord.code), ")");
}
function paymentMethodName(payment, locale) {
  var fundRecordName = getFundRecordPaymentName(payment, locale);
  if (fundRecordName) return fundRecordName;
  var raw = payment.name || payment.title || payment.payment_method_name || payment.method_name;
  if (raw) return appendMachineCodeToName(getLocalizedValue(raw, locale), payment);
  var code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
  if (code.includes('cash')) return label(locale, 'cash');
  if (code.includes('eftpos') || code.includes('card')) return label(locale, 'eftpos');
  if (code.includes('wallet')) return label(locale, 'wallet');
  if (code.includes('gift')) return label(locale, 'giftCard');
  return stringify(payment.code || payment.type || payment.payment_method || payment.method);
}
function getSummary(order) {
  return order.summary && _typeof(order.summary) === 'object' ? order.summary : order;
}
function getCurrencySymbol(order, shopInfo) {
  return stringify(order.currency_symbol || (shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.currency_symbol) || order.shop_symbol || '$') || '$';
}
function resolveLocales(shopInfo, locales) {
  var preferred = [].concat(_toConsumableArray(locales || []), [shopInfo.primary_locale], DEFAULT_LOCALES).filter(Boolean);
  return Array.from(new Set(preferred.map(normalizeLocaleKey)));
}
function normalizeLocaleKey(locale) {
  return locale.replace('-', '_');
}
function label(locale, key) {
  var _LABELS$locale;
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
}
function getLocalizedValue(value, locale) {
  var _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _value$locale;
  if (value === undefined || value === null) return '';
  if (_typeof(value) !== 'object') return stringify(value);
  var dashedLocale = locale.replace('_', '-');
  return stringify((_ref10 = (_ref11 = (_ref12 = (_ref13 = (_ref14 = (_ref15 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref15 !== void 0 ? _ref15 : value.default) !== null && _ref14 !== void 0 ? _ref14 : value.en) !== null && _ref13 !== void 0 ? _ref13 : value.zh_CN) !== null && _ref12 !== void 0 ? _ref12 : value['zh-CN']) !== null && _ref11 !== void 0 ? _ref11 : Object.values(value).find(function (item) {
    return typeof item === 'string' || typeof item === 'number';
  })) !== null && _ref10 !== void 0 ? _ref10 : '');
}
function serviceTypeToLabelKey(serviceType) {
  var normalized = serviceType.toLowerCase();
  if (normalized.includes('take')) return 'takeAway';
  if (normalized.includes('delivery')) return 'delivery';
  if (normalized.includes('pick')) return 'pickUp';
  if (normalized.includes('shop')) return 'shopService';
  return 'dineIn';
}
function buildShopAddress(shopInfo) {
  return [shopInfo.address_street, shopInfo.address_detail, shopInfo.city, shopInfo.province, shopInfo.country, shopInfo.zip].filter(Boolean).join(', ');
}
function formatDateTime(value, locale) {
  var date = dayjs(value);
  if (!date.isValid()) return stringify(value);
  if (locale === 'en') return date.format('HH:mm:ss DD/MM/YYYY');
  return date.format('YYYY/MM/DD HH:mm:ss');
}
function formatMoney(value, currencySymbol) {
  if (value instanceof Decimal) return "".concat(currencySymbol).concat(value.toFixed(2));
  if (typeof value === 'string' && value.trim().startsWith(currencySymbol)) return value;
  var amount = new Decimal(toMoneyNumber(value));
  return "".concat(currencySymbol).concat(amount.toFixed(2));
}
function sumPayments(payments) {
  return normalizeArray(payments).filter(function (payment) {
    return isPrintablePayment(payment);
  }).reduce(function (sum, payment) {
    var _payment$amount2;
    return sum.plus(toMoneyNumber((_payment$amount2 = payment.amount) !== null && _payment$amount2 !== void 0 ? _payment$amount2 : payment.origin_amount));
  }, new Decimal(0));
}
function isPrintablePayment(payment) {
  var status = stringify(payment.status).toLowerCase();
  if (!status) return true;
  return ['paid', 'success', 'succeeded', 'completed'].includes(status);
}
function normalizeArray(value) {
  return Array.isArray(value) ? value : [];
}
function isNonZero(value) {
  return !new Decimal(toMoneyNumber(value)).isZero();
}
function toMoneyNumber(value) {
  if (value instanceof Decimal) return value.toString();
  if (typeof value === 'number') return Number.isFinite(value) ? value : 0;
  if (typeof value !== 'string') return 0;
  var normalized = value.replace(/[^\d.-]/g, '');
  return normalized || 0;
}
function toNumber(value, fallback) {
  var numberValue = Number(value);
  return Number.isFinite(numberValue) ? numberValue : fallback;
}
function stringify(value) {
  if (value === undefined || value === null) return '';
  return String(value);
}