import { locales } from '@pisell/utils';
import dayjs from 'dayjs';
export function getLocalizedDateFormat() {
  var _locales$getLocale;
  var locale = ((_locales$getLocale = locales.getLocale) === null || _locales$getLocale === void 0 ? void 0 : _locales$getLocale.call(locales)) || 'en';
  var isChineseLocale = String(locale).toLowerCase().startsWith('zh');
  return isChineseLocale ? 'YYYY/MM/DD' : 'DD/MM/YYYY';
}
export function getLocalizedDateTimeFormat() {
  return "".concat(getLocalizedDateFormat(), " HH:mm");
}
export function formatLocalizedDateTime(value) {
  var emptyText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '-';
  if (value === undefined || value === null || value === '') return emptyText;
  var date = dayjs(value);
  return date.isValid() ? date.format(getLocalizedDateTimeFormat()) : String(value);
}

/**
 * 统一处理扫码失败的多语言提示文案。
 *
 * @param val 扫码接口返回结果
 * @param scene 使用场景，决定默认兜底文案
 * @returns 当前语言下的失败提示文案
 */
export function showDiscountScanFailMessage(val) {
  var scene = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'goodpass';
  var reasonKey = val === null || val === void 0 ? void 0 : val.unavailableReasonKey;
  var reasonMap = {
    total_credits: locales.getText('pisell2.text.goodpass.limit.total_credits'),
    per_user_limit: locales.getText('pisell2.text.goodpass.limit.per_user_limit'),
    max_per_day: locales.getText('pisell2.text.goodpass.limit.max_per_day'),
    max_per_week: locales.getText('pisell2.text.goodpass.limit.max_per_week'),
    max_per_month: locales.getText('pisell2.text.goodpass.limit.max_per_month')
  };
  if (reasonKey && reasonMap[reasonKey]) {
    return reasonMap[reasonKey];
  }
  if ((val === null || val === void 0 ? void 0 : val.type) === 'server') {
    return scene === 'goodpass' ? locales.getText('pisell2.text.goodpass.code-invalid') : locales.getText('pisell2.voucher.code-invalid');
  }
  var unavailableReasonMap = {
    time_limit: locales.getText('pisell2.text.goodpass.code-invalid-expired')
  };
  if (val !== null && val !== void 0 && val.unavailableReason && unavailableReasonMap[val.unavailableReason]) {
    return unavailableReasonMap[val.unavailableReason];
  }
  return scene === 'goodpass' ? locales.getText('pisell2.text.goodpass.code-invalid-cart') : locales.getText('pisell2.voucher.code-invalid-cart');
}