function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React from 'react';
import classNames from 'classnames';
import { FLOOR_MAP_IMAGE_ELEMENT_KIND, findFloorMapRowByDataBinding, getFloorMapBindingPlaceholderReason, renderFloorMapFallbackPlaceholder } from '@pisell/materials';
import { locales } from '@pisell/utils';
import { RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND, RESERVATION_BOUND_TABLE_ELEMENT_KIND } from "./reservationMock";
import { displayRoomTitleFromRow, mapPisellReservationRowToFloorRoomCardData, ReservationFloorRoomCard } from "../floorRoomCard";
import "./ReservationCards.less";
var I18N_BOUND = 'pisell-reservation.room-kind-bound';
var I18N_CARD_HINT_SELECT_ROW = 'pisell-reservation.card-placeholder.hint-select-row';
var I18N_CARD_HINT_BIND_DATASOURCE = 'pisell-reservation.card-placeholder.hint-bind-datasource';
var I18N_CARD_HINT_NEW_SLOT = 'pisell-reservation.card-placeholder.hint-new-slot';
var I18N_CARD_HINT_ROW_NOT_FOUND = 'pisell-reservation.card-placeholder.hint-row-not-found';
export function findReservationRow(item, dataSources) {
  return findFloorMapRowByDataBinding(item, dataSources);
}
function getReservationPlaceholderCopy(item, dataSources) {
  var el = item._sceneElement;
  var kindLabel = locales.getText(I18N_BOUND);
  var nameText = (el === null || el === void 0 ? void 0 : el.name) != null ? String(el.name).trim() : '';
  var title = nameText || kindLabel;
  var reason = getFloorMapBindingPlaceholderReason(item, dataSources);
  var hint;
  switch (reason) {
    case 'missing_data_source_key':
      hint = locales.getText(I18N_CARD_HINT_BIND_DATASOURCE);
      break;
    case 'missing_record_id':
      hint = locales.getText(I18N_CARD_HINT_SELECT_ROW);
      break;
    case 'new_unsaved_slot':
      hint = locales.getText(I18N_CARD_HINT_NEW_SLOT);
      break;
    default:
      hint = locales.getText(I18N_CARD_HINT_ROW_NOT_FOUND);
  }
  var shape = item.elementKind === RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND || item.shape === 'circle' ? 'circle' : 'rect';
  return {
    title: title,
    hint: hint,
    shape: shape
  };
}
function ReservationNoDataPlaceholder(props) {
  var title = props.title,
    hint = props.hint,
    shape = props.shape;
  return /*#__PURE__*/React.createElement("div", {
    className: classNames('pisell-reservation-card-placeholder', shape === 'circle' && 'pisell-reservation-card-placeholder--circle')
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-reservation-card-placeholder-title"
  }, title), hint ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-reservation-card-placeholder-hint"
  }, hint) : null);
}
function boundTableCardShape(item) {
  return item.elementKind === RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND || item.shape === 'circle' ? 'circle' : 'rect';
}
function renderReservationBoundRoomCardInner(item, dataSources) {
  var _item$_sceneElement;
  var row = findReservationRow(item, dataSources);
  var cardShape = boundTableCardShape(item);
  if (!row) {
    var ph = getReservationPlaceholderCopy(item, dataSources);
    return /*#__PURE__*/React.createElement(ReservationNoDataPlaceholder, {
      title: ph.title,
      hint: ph.hint,
      shape: ph.shape
    });
  }
  var sceneName = ((_item$_sceneElement = item._sceneElement) === null || _item$_sceneElement === void 0 ? void 0 : _item$_sceneElement.name) != null ? String(item._sceneElement.name).trim() : undefined;
  var roomTitle = displayRoomTitleFromRow(row, sceneName);
  var data = mapPisellReservationRowToFloorRoomCardData(row, roomTitle || row.code || locales.getText(I18N_BOUND));
  var layoutH = item.height != null && Number.isFinite(item.height) && item.height > 0 ? item.height : item.width;
  return /*#__PURE__*/React.createElement(ReservationFloorRoomCard, {
    data: data,
    shellShape: cardShape,
    elementLayoutHeightPx: layoutH != null && Number.isFinite(layoutH) && layoutH > 0 && cardShape === 'circle' ? layoutH : undefined
  });
}
export function renderReservationTableCard(item, dataSources) {
  return renderReservationBoundRoomCardInner(item, dataSources);
}
export function renderReservationPartyCard(item, dataSources) {
  return renderReservationBoundRoomCardInner(item, dataSources);
}
export function renderReservationBarCard(item, dataSources) {
  return renderReservationBoundRoomCardInner(item, dataSources);
}
export function getReservationRenderItemByKind(dataSources) {
  var bound = function bound(item, _index, _options) {
    return renderReservationBoundRoomCardInner(item, dataSources);
  };
  return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FLOOR_MAP_IMAGE_ELEMENT_KIND, function (item, _index, _options) {
    return renderFloorMapFallbackPlaceholder(item);
  }), RESERVATION_BOUND_TABLE_ELEMENT_KIND, bound), RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND, bound), "reservationTable", bound), "reservationPartyBench", bound), "reservationBarSeat", bound);
}