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/components/productCard/lineItem/components/TimeRange/index.tsx
var TimeRange_exports = {};
__export(TimeRange_exports, {
  default: () => TimeRange_default
});
module.exports = __toCommonJS(TimeRange_exports);
var import_react = __toESM(require("react"));
var import_dayjs = __toESM(require("dayjs"));
var import_zh_cn = require("dayjs/locale/zh-cn");
var import_en = require("dayjs/locale/en");
var import_zh_tw = require("dayjs/locale/zh-tw");
var import_ja = require("dayjs/locale/ja");
var import_pt = require("dayjs/locale/pt");
var import_utils = require("@pisell/utils");
var import_iconfont = __toESM(require("../../../../iconfont"));
var import_useEngineContext = __toESM(require("../../../../../hooks/useEngineContext"));
var import_timeRange = require("../../../cartSkuCard/components/timeRange/index.less");
var localeTypes = {
  "en-US": "en",
  "zh-CN": "zh-cn",
  "zh-HK": "zh-tw",
  ja: "ja",
  pt: "pt"
};
var PREFIX = "pisell-cart-sku-card";
var formatMultiDayDate = (start, end, isEn) => {
  const format = isEn ? "ddd, DD/MM/YYYY" : "YYYY-MM-DD，ddd";
  return `${start.format(format)} ~ ${end.format(format)}`;
};
var formatBookingTime = (booking, locale) => {
  const start = (0, import_dayjs.default)(
    (booking == null ? void 0 : booking.start_time) ? `${(booking == null ? void 0 : booking.start_date) || ""} ${booking.start_time}` : booking == null ? void 0 : booking.start_date
  );
  const end = (0, import_dayjs.default)(
    (booking == null ? void 0 : booking.end_time) ? `${(booking == null ? void 0 : booking.end_date) || ""} ${booking.end_time}` : booking == null ? void 0 : booking.end_date
  );
  if (!start.isValid() || !end.isValid()) return "";
  const isEn = locale === "en-US" || locale === "en";
  const durationType = (booking == null ? void 0 : booking.sub_type) || (booking == null ? void 0 : booking.duration_type);
  const startTime = (booking == null ? void 0 : booking.start_time) || start.format("HH:mm");
  const endTime = (booking == null ? void 0 : booking.end_time) || end.format("HH:mm");
  if (durationType === "days" && !start.isSame(end, "day")) {
    const duration2 = end.diff(start, "day");
    return `${formatMultiDayDate(start, end, isEn)} (${duration2}${import_utils.locales.getText(
      "pisell2.product.card.day"
    )(duration2)})`;
  }
  const dateFormat = isEn ? "DD/MM/YYYY" : "YYYY-MM-DD";
  const dateTime = start.isSame(end, "day") ? isEn ? `${startTime} ~ ${endTime} ${start.format(dateFormat)}` : `${start.format(dateFormat)} ${startTime} ~ ${endTime}` : isEn ? `${startTime} ${start.format(dateFormat)} ~ ${endTime} ${end.format(dateFormat)}` : `${start.format(dateFormat)} ${startTime} ~ ${end.format(dateFormat)} ${endTime}`;
  if (!durationType) return dateTime;
  if (durationType === "minutes" || durationType === "flexible") {
    const duration2 = end.diff(start, "minute");
    const hours = Math.floor(duration2 / 60);
    const minutes = duration2 % 60;
    return `${dateTime} (${import_utils.locales.getText("pisell2.product.card.hour.minute")(
      hours,
      minutes
    )})`;
  }
  const duration = end.diff(start, durationType);
  return `${dateTime} (${duration})`;
};
var LineItemTimeRange = (props) => {
  var _a, _b, _c, _d, _e, _f, _g;
  const { dataSource = {} } = props;
  const context = (0, import_useEngineContext.default)();
  const locale = ((_e = (_d = (_c = (_b = (_a = context.appHelper.utils) == null ? void 0 : _a.getApp) == null ? void 0 : _b.call(_a)) == null ? void 0 : _c.locales) == null ? void 0 : _d.getLocale) == null ? void 0 : _e.call(_d)) || ((_g = (_f = context.appHelper.utils) == null ? void 0 : _f.storage) == null ? void 0 : _g.get("umi_locale")) || (dataSource == null ? void 0 : dataSource.locale) || "en-US";
  const serviceTime = (0, import_react.useMemo)(() => {
    import_dayjs.default.locale(localeTypes[locale]);
    return formatBookingTime(dataSource, locale);
  }, [dataSource, locale]);
  if (!serviceTime) return null;
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}__time-range` }, /* @__PURE__ */ import_react.default.createElement(import_iconfont.default, { className: "time-icon", type: "pisell2-clock" }), serviceTime);
};
var TimeRange_default = LineItemTimeRange;
