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/pisellReservation/floorMap/ReservationFloorMapHud.tsx
var ReservationFloorMapHud_exports = {};
__export(ReservationFloorMapHud_exports, {
  ReservationFloorMapHud: () => ReservationFloorMapHud,
  ReservationFloorMapHudStatsBar: () => ReservationFloorMapHudStatsBar,
  ReservationFloorMapHudTitleBar: () => ReservationFloorMapHudTitleBar,
  reservationFloorMapHudSeatStatsTotal: () => reservationFloorMapHudSeatStatsTotal
});
module.exports = __toCommonJS(ReservationFloorMapHud_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_icons = require("@ant-design/icons");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_reservationCards = require("./reservationCards");
var import_ReservationFloorMapHud = require("./ReservationFloorMapHud.less");
var I18N_TOTAL = "pisell-reservation.floor-hud.total";
var I18N_INTERACTIVE_TITLE = "pisell-reservation.floor-hud.interactive-title";
var I18N_STATUS_EMPTY = "pisell-reservation.room-status-empty";
var I18N_STATUS_RESERVED = "pisell-reservation.room-status-reserved";
var I18N_STATUS_OCCUPIED = "pisell-reservation.room-status-occupied";
var I18N_STATUS_LOCKED = "pisell-reservation.room-status-locked";
var I18N_STATUS_UNBOUND = "pisell-reservation.room-status-unbound";
function isSeatLikeElement(item) {
  const k = item.elementKind;
  if (!k || k === import_materials.FLOOR_MAP_IMAGE_ELEMENT_KIND || k === import_materials.FLOOR_MAP_STAGE_ELEMENT_KIND) {
    return false;
  }
  return true;
}
function computeHudSeatStats(items, dataSources) {
  let total = 0;
  let idle = 0;
  let booked = 0;
  let occupied = 0;
  let maintenance = 0;
  let unbound = 0;
  const ds = dataSources ?? {};
  for (const item of items) {
    if (!isSeatLikeElement(item)) continue;
    total += 1;
    const row = (0, import_reservationCards.findReservationRow)(item, ds);
    if (!row) {
      unbound += 1;
      continue;
    }
    switch (row.cardStatus) {
      case "available":
        idle += 1;
        break;
      case "booked":
        booked += 1;
        break;
      case "occupied":
      case "barBusy":
        occupied += 1;
        break;
      case "maintenance":
        maintenance += 1;
        break;
      default:
        idle += 1;
    }
  }
  return { total, idle, booked, occupied, maintenance, unbound };
}
function reservationFloorMapHudSeatStatsTotal(items, dataSources) {
  return computeHudSeatStats(items, dataSources).total;
}
function buildHudStatRows(stats) {
  const rows = [
    { label: import_utils.locales.getText(I18N_TOTAL), value: stats.total },
    { label: import_utils.locales.getText(I18N_STATUS_EMPTY), value: stats.idle },
    { label: import_utils.locales.getText(I18N_STATUS_RESERVED), value: stats.booked }
  ];
  if (stats.occupied > 0) {
    rows.push({
      label: import_utils.locales.getText(I18N_STATUS_OCCUPIED),
      value: stats.occupied
    });
  }
  if (stats.maintenance > 0) {
    rows.push({
      label: import_utils.locales.getText(I18N_STATUS_LOCKED),
      value: stats.maintenance
    });
  }
  if (stats.unbound > 0) {
    rows.push({
      label: import_utils.locales.getText(I18N_STATUS_UNBOUND),
      value: stats.unbound
    });
  }
  return rows;
}
function HudSeatStatInlineRows(props) {
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.rows.map((r, i) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, { key: r.label }, i > 0 ? /* @__PURE__ */ import_react.default.createElement(
    "span",
    {
      className: "pisell-reservation-floor-map-hud-sep",
      "aria-hidden": true
    },
    "·"
  ) : null, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-floor-map-hud-inline-item" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-floor-map-hud-label" }, r.label), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-floor-map-hud-value" }, r.value)))));
}
function ReservationFloorMapHudStatsBar(props) {
  const {
    items,
    dataSources,
    rightSlot,
    hideWhenNoSeats = true,
    className
  } = props;
  const stats = (0, import_react.useMemo)(
    () => computeHudSeatStats(items, dataSources),
    [items, dataSources]
  );
  const rows = (0, import_react.useMemo)(() => buildHudStatRows(stats), [stats]);
  if (hideWhenNoSeats && stats.total === 0) {
    return null;
  }
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        "pisell-reservation-floor-map-hud-stats-bar",
        className
      )
    },
    stats.total > 0 ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-floor-map-hud-inline-stats" }, /* @__PURE__ */ import_react.default.createElement(HudSeatStatInlineRows, { rows })) : /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-reservation-floor-map-hud-stats-bar-spacer",
        "aria-hidden": true
      }
    ),
    rightSlot
  );
}
function ReservationFloorMapHudTitleBar(props) {
  const { items, dataSources, actionMode, onAction, embedded, className } = props;
  const stats = (0, import_react.useMemo)(
    () => computeHudSeatStats(items, dataSources),
    [items, dataSources]
  );
  const rows = (0, import_react.useMemo)(() => buildHudStatRows(stats), [stats]);
  if (stats.total === 0) {
    if (actionMode === "collapse") {
      const collapseAria = import_utils.locales.getText(
        "pisell-reservation.hud-collapse-aria"
      );
      const regionLabel = import_utils.locales.getText(
        "pisell-reservation.hud-table-drawer-title"
      );
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)(
            "pisell-reservation-floor-map-hud",
            "pisell-reservation-floor-map-hud--interactive-title-bar",
            embedded && "pisell-reservation-floor-map-hud--embedded",
            "pisell-reservation-floor-map-hud-title-bar--minimal",
            className
          ),
          role: "region",
          "aria-label": regionLabel
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-floor-map-hud-title-bar-layout" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-floor-map-hud-heading" }, import_utils.locales.getText(I18N_INTERACTIVE_TITLE)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-floor-map-hud-title-bar-stats" }), /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            type: "button",
            className: "pisell-reservation-floor-map-hud-chevron-btn",
            "aria-expanded": true,
            "aria-label": collapseAria,
            onClick: (e) => {
              e.stopPropagation();
              onAction();
            }
          },
          /* @__PURE__ */ import_react.default.createElement(import_icons.DoubleLeftOutlined, { rotate: 90 })
        ))
      );
    }
    return null;
  }
  const actionAria = actionMode === "expand" ? import_utils.locales.getText("pisell-reservation.hud-expand-aria") : import_utils.locales.getText("pisell-reservation.hud-collapse-aria");
  const regionAria = import_utils.locales.getText(
    "pisell-reservation.hud-table-drawer-title"
  );
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        "pisell-reservation-floor-map-hud",
        "pisell-reservation-floor-map-hud--interactive-title-bar",
        embedded && "pisell-reservation-floor-map-hud--embedded",
        className
      ),
      role: "region",
      "aria-label": regionAria
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-floor-map-hud-title-bar-layout" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-floor-map-hud-heading" }, import_utils.locales.getText(I18N_INTERACTIVE_TITLE)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-floor-map-hud-title-bar-stats" }, /* @__PURE__ */ import_react.default.createElement(HudSeatStatInlineRows, { rows })), /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: "pisell-reservation-floor-map-hud-chevron-btn",
        "aria-expanded": actionMode === "collapse",
        "aria-label": actionAria,
        onClick: (e) => {
          e.stopPropagation();
          onAction();
        }
      },
      actionMode === "expand" ? /* @__PURE__ */ import_react.default.createElement(import_icons.DoubleLeftOutlined, { rotate: 90 }) : /* @__PURE__ */ import_react.default.createElement(import_icons.DoubleLeftOutlined, { rotate: -90 })
    ))
  );
}
function ReservationFloorMapHud(props) {
  const stats = (0, import_react.useMemo)(
    () => computeHudSeatStats(props.items, props.dataSources),
    [props.items, props.dataSources]
  );
  if (props.interactive && props.onRequestOpenTable) {
    const expanded = Boolean(props.tableDrawerOpen);
    if (stats.total === 0 && !expanded) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(
      ReservationFloorMapHudTitleBar,
      {
        items: props.items,
        dataSources: props.dataSources,
        actionMode: expanded ? "collapse" : "expand",
        onAction: () => {
          var _a;
          return expanded ? (_a = props.onRequestCloseTable) == null ? void 0 : _a.call(props) : props.onRequestOpenTable();
        }
      }
    );
  }
  if (stats.total === 0) {
    return null;
  }
  const rows = buildHudStatRows(stats);
  if (props.phoneLayout) {
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(
          "pisell-reservation-floor-map-hud",
          "pisell-reservation-floor-map-hud--phone-inline"
        ),
        role: "status"
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-floor-map-hud-inline-stats" }, /* @__PURE__ */ import_react.default.createElement(HudSeatStatInlineRows, { rows }))
    );
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-floor-map-hud", role: "status" }, /* @__PURE__ */ import_react.default.createElement("ul", { className: "pisell-reservation-floor-map-hud-list" }, rows.map((r) => /* @__PURE__ */ import_react.default.createElement("li", { key: r.label, className: "pisell-reservation-floor-map-hud-row" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-floor-map-hud-label" }, r.label), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-floor-map-hud-value" }, r.value)))));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ReservationFloorMapHud,
  ReservationFloorMapHudStatsBar,
  ReservationFloorMapHudTitleBar,
  reservationFloorMapHudSeatStatsTotal
});
