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/components/LineItem/utils/display.ts
var display_exports = {};
__export(display_exports, {
  getBookingDisplay: () => getBookingDisplay,
  isBookingDataSource: () => isBookingDataSource,
  toDisplayText: () => toDisplayText
});
module.exports = __toCommonJS(display_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_resolveLocalizedText = require("../../../../salesSdk/utils/resolveLocalizedText");
var import_utils = require("../../../utils");
var toDisplayText = (value) => {
  if (value === void 0 || value === null) return "";
  if (typeof value === "string" || typeof value === "number") return String(value);
  if (typeof value === "object") {
    return (0, import_resolveLocalizedText.resolveLocalizedText)(value);
  }
  return String(value);
};
var getQuantity = (value, fallback = 1) => {
  const quantity = Math.floor(Number(value));
  return Number.isFinite(quantity) && quantity > 0 ? quantity : fallback;
};
var isBookingDataSource = (dataSource) => {
  return Object.prototype.hasOwnProperty.call((dataSource == null ? void 0 : dataSource._extend) || {}, "product");
};
var getBookingTimeText = (booking) => {
  const start = (0, import_dayjs.default)(
    booking.start_time ? `${booking.start_date || ""} ${booking.start_time}` : booking.start_date
  );
  const end = (0, import_dayjs.default)(
    booking.end_time ? `${booking.end_date || ""} ${booking.end_time}` : booking.end_date
  );
  if (!start.isValid() || !end.isValid()) return "";
  const startTime = booking.start_time || start.format("HH:mm");
  const endTime = booking.end_time || end.format("HH:mm");
  const dateFormat = (0, import_utils.getLocalizedDateFormat)();
  if (start.isSame(end, "day")) {
    return `${start.format(dateFormat)} ${startTime}-${endTime}`;
  }
  return `${start.format(dateFormat)} ${startTime}-${end.format(dateFormat)} ${endTime}`;
};
var getBookingResources = (booking) => {
  const resources = Array.isArray(booking.resources) ? booking.resources : [];
  return resources.map((resource, index) => {
    var _a, _b;
    const formName = toDisplayText((_a = resource.metadata) == null ? void 0 : _a.form_name);
    const resourceName = toDisplayText((_b = resource.metadata) == null ? void 0 : _b.resource_name);
    return {
      id: String(resource.relation_id ?? resource.form_id ?? resource.id ?? index),
      label: resourceName || formName,
      formName,
      resourceName
    };
  }).filter((resource) => Boolean(resource.formName || resource.resourceName));
};
var getBookingDisplay = (booking, options = {}) => {
  var _a, _b, _c;
  const relatedProduct = ((_a = booking._extend) == null ? void 0 : _a.product) ?? null;
  const holders = booking.holders ?? [];
  const holderMaxCount = getQuantity(
    booking.holderMaxCount ?? ((_b = relatedProduct == null ? void 0 : relatedProduct._extend) == null ? void 0 : _b.displayQuantity) ?? (relatedProduct == null ? void 0 : relatedProduct.num) ?? booking.number
  );
  const isFormSubject = Boolean(options.isFormSubject ?? booking.isFormSubject);
  return {
    source: booking,
    bookingId: booking.booking_id,
    status: booking.appointment_status ?? booking.status,
    timeText: getBookingTimeText(booking),
    title: relatedProduct ? toDisplayText(relatedProduct.title) : toDisplayText((_c = booking.detail) == null ? void 0 : _c.product_title),
    bookingNumber: getQuantity(booking.number),
    resources: getBookingResources(booking),
    holders,
    holderMaxCount,
    showUnassignedHolder: isFormSubject && holders.length === 0,
    relatedProduct
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getBookingDisplay,
  isBookingDataSource,
  toDisplayText
});
