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/data/formResourceToReservationTables.ts
var formResourceToReservationTables_exports = {};
__export(formResourceToReservationTables_exports, {
  formResourceItemToReservationRow: () => formResourceItemToReservationRow,
  formResourceListToFormRecordIds: () => formResourceListToFormRecordIds,
  formResourceListToReservationTableRows: () => formResourceListToReservationTableRows,
  mergeResourceRowsWithBookingRows: () => mergeResourceRowsWithBookingRows
});
module.exports = __toCommonJS(formResourceToReservationTables_exports);
function normalizeMainField(raw) {
  if (raw == null || typeof raw !== "string") return "";
  const first = raw.split(" ## ")[0];
  return (first == null ? void 0 : first.trim()) ?? "";
}
function normalizeFormResourceRecordId(item) {
  const raw = item.id;
  if (typeof raw === "number" && Number.isFinite(raw)) {
    const n = Math.trunc(raw);
    if (n > 0) return String(n);
    return null;
  }
  if (typeof raw === "string") {
    const t = raw.trim();
    if (!t || t === "0") return null;
    const n = Number(t);
    if (Number.isFinite(n) && n > 0) return String(Math.trunc(n));
    if (/^\d+$/.test(t)) return t;
  }
  return null;
}
function formResourceListToFormRecordIds(list) {
  if (!Array.isArray(list) || list.length === 0) return [];
  const ids = [];
  for (const raw of list) {
    const s = normalizeFormResourceRecordId(raw);
    if (s == null) continue;
    const n = Number(s);
    if (Number.isFinite(n) && n > 0) ids.push(Math.trunc(n));
  }
  return ids;
}
function formResourceItemToReservationRow(item) {
  if (item == null || typeof item !== "object") return null;
  const id = normalizeFormResourceRecordId(item);
  if (id == null) return null;
  const name = normalizeMainField(item.main_field);
  return {
    id,
    code: name || id,
    main_field: typeof item.main_field === "string" ? item.main_field : void 0,
    cardStatus: "available",
    area: typeof item.form_code === "string" && item.form_code.trim() ? item.form_code : void 0,
    capacityLabel: item.capacity != null && String(item.capacity).trim() !== "" ? String(item.capacity) : void 0
  };
}
function formResourceListToReservationTableRows(list) {
  if (!Array.isArray(list) || list.length === 0) return [];
  const rows = [];
  for (const raw of list) {
    const row = formResourceItemToReservationRow(raw);
    if (row) rows.push(row);
  }
  return rows;
}
function mergeResourceRowsWithBookingRows(resourceRows, bookingRows) {
  if (resourceRows.length === 0) return [];
  const byId = /* @__PURE__ */ new Map();
  for (const r of bookingRows) {
    byId.set(r.id, r);
  }
  return resourceRows.map((base) => {
    const b = byId.get(base.id);
    if (!b) return base;
    return {
      ...base,
      cardStatus: b.cardStatus,
      guestName: b.guestName,
      guestPhone: b.guestPhone,
      time: b.time,
      timeEnd: b.timeEnd,
      partySize: b.partySize,
      startsInMinutes: b.startsInMinutes,
      priceDisplay: b.priceDisplay,
      isPaid: b.isPaid,
      delayMinutes: b.delayMinutes,
      lateMinutes: b.lateMinutes,
      elapsedLabel: b.elapsedLabel,
      progress: b.progress,
      progressTone: b.progressTone,
      topAccentOrange: b.topAccentOrange,
      nextGuest: b.nextGuest,
      nextTime: b.nextTime,
      slots: b.slots,
      moreCount: b.moreCount,
      barSlots: b.barSlots,
      barRemainingLabel: b.barRemainingLabel,
      floorMapSourceBookings: b.floorMapSourceBookings,
      floorMapReferenceDay: b.floorMapReferenceDay,
      hostReservedStatus: b.hostReservedStatus,
      hostIsTimeout: b.hostIsTimeout
    };
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  formResourceItemToReservationRow,
  formResourceListToFormRecordIds,
  formResourceListToReservationTableRows,
  mergeResourceRowsWithBookingRows
});
