var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellReservation/components/bookingDetailModal/bookingDetailHostActions.ts
var bookingDetailHostActions_exports = {};
__export(bookingDetailHostActions_exports, {
  buildEditBookingResourceSnapshot: () => buildEditBookingResourceSnapshot,
  getSalesHostModule: () => getSalesHostModule,
  isCompletedBookingRaw: () => isCompletedBookingRaw,
  isSameResourceType: () => isSameResourceType,
  orderCurrencySymbol: () => orderCurrencySymbol,
  parseBookingProducts: () => parseBookingProducts,
  resolveAppointmentStatusTag: () => resolveAppointmentStatusTag,
  resolveBookingDateTime: () => resolveBookingDateTime,
  resolveBookingIdForHostActions: () => resolveBookingIdForHostActions,
  resolveOrderIdForHostActions: () => resolveOrderIdForHostActions,
  resolveResourceIdFromRow: () => resolveResourceIdFromRow,
  updateLocalOrder: () => updateLocalOrder
});
module.exports = __toCommonJS(bookingDetailHostActions_exports);
var import_utils = require("@pisell/utils");
function resolveOrderIdForHostActions(bookingRaw) {
  const order = bookingRaw.order;
  const id = (order == null ? void 0 : order.id) ?? (order == null ? void 0 : order.order_id) ?? bookingRaw.order_id;
  if (id == null || id === "") return void 0;
  if (typeof id === "number" && Number.isFinite(id)) return id;
  const s = String(id).trim();
  if (!s) return void 0;
  const n = Number(s);
  return Number.isFinite(n) && String(n) === s ? n : s;
}
function resolveBookingIdForHostActions(bookingRaw) {
  const id = bookingRaw.id;
  if (id == null || id === "") return void 0;
  if (typeof id === "number" && Number.isFinite(id)) return id;
  const s = String(id).trim();
  if (!s) return void 0;
  const n = Number(s);
  return Number.isFinite(n) && String(n) === s ? n : s;
}
function resolveBookingDateTime(bookingRaw, atKey, dateKey, timeKey) {
  const at = bookingRaw[atKey];
  if (at != null && String(at).trim() !== "") return String(at).trim();
  const date = bookingRaw[dateKey];
  const time = bookingRaw[timeKey];
  if (date == null || time == null) return void 0;
  const dateText = String(date).trim();
  const timeText = String(time).trim();
  if (!dateText || !timeText) return void 0;
  return `${dateText} ${timeText}`;
}
function resolveResourceIdFromRow(row) {
  if (!(row == null ? void 0 : row.id)) return void 0;
  const id = String(row.id).trim();
  return id || void 0;
}
function buildEditBookingResourceSnapshot(selected) {
  var _a, _b, _c, _d, _e;
  const raw = ((_a = selected.resource) == null ? void 0 : _a.raw) && typeof selected.resource.raw === "object" ? selected.resource.raw : selected.row;
  const id = ((_b = selected.resource) == null ? void 0 : _b.id) ?? (raw == null ? void 0 : raw.id);
  if (id == null || String(id).trim() === "") return void 0;
  return {
    ...raw,
    id,
    form_id: ((_c = selected.resource) == null ? void 0 : _c.form_id) ?? (raw == null ? void 0 : raw.form_id),
    code: ((_d = selected.resource) == null ? void 0 : _d.code) ?? (raw == null ? void 0 : raw.code),
    main_field: ((_e = selected.resource) == null ? void 0 : _e.main_field) ?? (raw == null ? void 0 : raw.main_field)
  };
}
function getResourceFormId(resource) {
  if ((resource == null ? void 0 : resource.form_id) == null) return void 0;
  const formId = String(resource.form_id).trim();
  return formId || void 0;
}
function isSameResourceType(source, target) {
  const sourceFormId = getResourceFormId(source);
  const targetFormId = getResourceFormId(target);
  if (!sourceFormId || !targetFormId) return true;
  return sourceFormId === targetFormId;
}
function getSalesHostModule(pisellos) {
  var _a;
  return (_a = pisellos == null ? void 0 : pisellos.getModule) == null ? void 0 : _a.call(
    pisellos,
    "sales"
  );
}
function updateLocalOrder(action, orderId) {
  if (orderId == null || typeof action !== "function") return;
  action({
    type: "webpos.updateLocalOrderApi",
    data: {
      order_id: orderId
    }
  });
}
function isCompletedBookingRaw(bookingRaw) {
  const s = String(bookingRaw.status ?? "").trim().toLowerCase();
  const a = String(bookingRaw.appointment_status ?? "").trim().toLowerCase();
  return s === "completed" || a === "completed";
}
function parseBookingProducts(bookingRaw) {
  const p = bookingRaw.products;
  if (!Array.isArray(p)) return [];
  return p.filter((x) => x && typeof x === "object");
}
function orderCurrencySymbol(order) {
  if (!order) return "$";
  const s = order.currency_symbol;
  if (s != null && String(s).trim() !== "") return String(s).trim();
  return "$";
}
function resolveAppointmentStatusTag(bookingRaw) {
  const rawStatus = String((bookingRaw == null ? void 0 : bookingRaw.appointment_status) ?? "").trim();
  const statusMap = {
    new: {
      label: import_utils.locales.getText("pisell2.text.status.new"),
      tone: "new"
    },
    confirmed: {
      label: import_utils.locales.getText("pisell2.text.status.confirmed"),
      tone: "confirmed"
    },
    arrived: {
      label: import_utils.locales.getText("pisell2.text.status.arrived"),
      tone: "arrived"
    },
    started: {
      label: import_utils.locales.getText("pisell2.text.status.started"),
      tone: "started"
    },
    cancelled: {
      label: import_utils.locales.getText("pisell2.text.status.cancelled"),
      tone: "cancelled"
    },
    no_show: {
      label: import_utils.locales.getText("pisell2.text.status.no_show"),
      tone: "no-show"
    },
    completed: {
      label: import_utils.locales.getText("pisell2.text.status.completed"),
      tone: "completed"
    }
  };
  return statusMap[rawStatus] ?? statusMap.new;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildEditBookingResourceSnapshot,
  getSalesHostModule,
  isCompletedBookingRaw,
  isSameResourceType,
  orderCurrencySymbol,
  parseBookingProducts,
  resolveAppointmentStatusTag,
  resolveBookingDateTime,
  resolveBookingIdForHostActions,
  resolveOrderIdForHostActions,
  resolveResourceIdFromRow,
  updateLocalOrder
});
