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,
  resolveSaleDetailCartItemCardStyle: () => resolveSaleDetailCartItemCardStyle,
  resolveSaleDetailShowContactInfo: () => resolveSaleDetailShowContactInfo,
  resolveSaleDetailTransactionHabit: () => resolveSaleDetailTransactionHabit,
  showDiscountScanFailMessage: () => showDiscountScanFailMessage
});
module.exports = __toCommonJS(utils_exports);
var import_utils = require("@pisell/utils");
var import_dayjs = __toESM(require("dayjs"));
function toOptionalBoolean(value) {
  if (value === true || value === 1 || value === "1") return true;
  if (value === false || value === 0 || value === "0") return false;
  return void 0;
}
function toOptionalNumber(value) {
  const next = Number(value);
  return Number.isFinite(next) ? next : void 0;
}
function resolveSaleDetailCartItemCardStyle(bookingConfig, kind) {
  var _a;
  const cartSettings = ((_a = bookingConfig == null ? void 0 : bookingConfig.config) == null ? void 0 : _a.cart_settings_tab) || {};
  const styleConfig = cartSettings[`${kind}_product_card_style`] || {};
  return {
    isShowImage: toOptionalBoolean(styleConfig.show_product_image) ?? true,
    isShowDelete: toOptionalBoolean(styleConfig.show_remove_button) ?? true
  };
}
function resolveSaleDetailShowContactInfo(bookingConfig) {
  var _a, _b;
  const cartSettings = ((_a = bookingConfig == null ? void 0 : bookingConfig.config) == null ? void 0 : _a.cart_settings_tab) || {};
  return Boolean((_b = cartSettings.display_contact_info) == null ? void 0 : _b.show_contact_info);
}
function resolveSaleDetailTransactionHabit(bookingConfig) {
  var _a, _b;
  const raw = ((_b = (_a = bookingConfig == null ? void 0 : bookingConfig.config) == null ? void 0 : _a.information_tab) == null ? void 0 : _b.transaction_habit_selection) || {};
  const rawType = String(raw.type || "").trim();
  const type = rawType === "pay_now_service_later" || rawType === "service_now_pay_later" ? rawType : void 0;
  return {
    type,
    buttonRows: toOptionalNumber(raw.button_rows)
  };
}
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,
  resolveSaleDetailCartItemCardStyle,
  resolveSaleDetailShowContactInfo,
  resolveSaleDetailTransactionHabit,
  showDiscountScanFailMessage
});
