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/plus/saleDetail/utils.ts
var utils_exports = {};
__export(utils_exports, {
  formatLocalizedDateTime: () => formatLocalizedDateTime,
  getLocalizedDateFormat: () => getLocalizedDateFormat,
  getLocalizedDateTimeFormat: () => getLocalizedDateTimeFormat,
  showDiscountScanFailMessage: () => showDiscountScanFailMessage
});
module.exports = __toCommonJS(utils_exports);
var import_utils = require("@pisell/utils");
var import_dayjs = __toESM(require("dayjs"));
function getLocalizedDateFormat() {
  var _a, _b;
  const locale = ((_b = (_a = import_utils.locales).getLocale) == null ? void 0 : _b.call(_a)) || "en";
  const isChineseLocale = String(locale).toLowerCase().startsWith("zh");
  return isChineseLocale ? "YYYY/MM/DD" : "DD/MM/YYYY";
}
function getLocalizedDateTimeFormat() {
  return `${getLocalizedDateFormat()} HH:mm`;
}
function formatLocalizedDateTime(value, emptyText = "-") {
  if (value === void 0 || value === null || value === "") return emptyText;
  const date = (0, import_dayjs.default)(value);
  return date.isValid() ? date.format(getLocalizedDateTimeFormat()) : String(value);
}
function showDiscountScanFailMessage(val, scene = "goodpass") {
  const reasonKey = val == null ? void 0 : val.unavailableReasonKey;
  const reasonMap = {
    total_credits: import_utils.locales.getText("pisell2.text.goodpass.limit.total_credits"),
    per_user_limit: import_utils.locales.getText(
      "pisell2.text.goodpass.limit.per_user_limit"
    ),
    max_per_day: import_utils.locales.getText("pisell2.text.goodpass.limit.max_per_day"),
    max_per_week: import_utils.locales.getText("pisell2.text.goodpass.limit.max_per_week"),
    max_per_month: import_utils.locales.getText("pisell2.text.goodpass.limit.max_per_month")
  };
  if (reasonKey && reasonMap[reasonKey]) {
    return reasonMap[reasonKey];
  }
  if ((val == null ? void 0 : val.type) === "server") {
    return scene === "goodpass" ? import_utils.locales.getText("pisell2.text.goodpass.code-invalid") : import_utils.locales.getText("pisell2.voucher.code-invalid");
  }
  const unavailableReasonMap = {
    time_limit: import_utils.locales.getText("pisell2.text.goodpass.code-invalid-expired")
  };
  if ((val == null ? void 0 : val.unavailableReason) && unavailableReasonMap[val.unavailableReason]) {
    return unavailableReasonMap[val.unavailableReason];
  }
  return scene === "goodpass" ? import_utils.locales.getText("pisell2.text.goodpass.code-invalid-cart") : import_utils.locales.getText("pisell2.voucher.code-invalid-cart");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  formatLocalizedDateTime,
  getLocalizedDateFormat,
  getLocalizedDateTimeFormat,
  showDiscountScanFailMessage
});
