"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FieldOccupation = void 0;
var _dataSources = require("@mirai/data-sources");
var _locale = require("@mirai/locale");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _FieldOccupation = require("./FieldOccupation.l10n");
var _prepareRoom = require("../../../helpers/prepareRoom");
var _helpers = require("../../helpers");
var _Field = require("../Field");
var _Occupation = require("../Occupation");
var _Occupation2 = require("../Occupation/Occupation.constants");
const _excluded = ["compacted", "error", "hideLabel", "hotels", "inline", "tabIndex", "value", "visible", "warning", "withWarning", "onPress", "onSubmit"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
const FieldOccupation = exports.FieldOccupation = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
  let {
      compacted,
      error,
      hideLabel,
      hotels = [],
      inline,
      tabIndex,
      value,
      visible,
      warning,
      withWarning,
      onPress,
      onSubmit
    } = _ref,
    others = _objectWithoutProperties(_ref, _excluded);
  const {
    translate
  } = (0, _locale.useLocale)();
  const {
    value: {
      config: {
        hotels: dataSource,
        lodgingDenomination: individual
      } = {}
    }
  } = (0, _dataSources.useStore)();
  const {
    minRooms = 1,
    testId
  } = others;
  const type = (0, _helpers.getAccommodationType)({
    dataSource,
    hotels,
    individual
  });
  const caption = (0, _helpers.getOccupationSummary)(value || [...Array(minRooms)].map(() => (0, _prepareRoom.prepareRoom)(others.dataSource)), translate, type);
  return /*#__PURE__*/_react.default.createElement(_Field.Field, _extends({}, others, {
    caption: caption,
    compacted: compacted,
    error: error,
    forceRender: true,
    icon: _helpers.ICON.PEOPLE,
    inline: inline,
    label: !hideLabel ? translate(_FieldOccupation.L10N.LABEL_WHO) : undefined,
    tabIndex: tabIndex,
    visible: visible,
    warning: warning,
    onPress: onPress,
    testId: testId ? "".concat(testId, "-field") : undefined
  }), /*#__PURE__*/_react.default.createElement(_Occupation.Occupation, _extends({}, others, {
    ref: ref,
    type: type,
    value: value,
    warning: withWarning,
    onSubmit: onSubmit,
    className: undefined,
    style: undefined
  })));
});
FieldOccupation.displayName = 'Mirai:Core:FieldOccupation';
FieldOccupation.propTypes = {
  compacted: _propTypes.default.bool,
  error: _propTypes.default.bool,
  hotels: _propTypes.default.array,
  hideLabel: _propTypes.default.bool,
  inline: _propTypes.default.bool,
  tabIndex: _propTypes.default.any,
  value: _propTypes.default.arrayOf(_propTypes.default.arrayOf(_Occupation2.SHAPE.VALUE)),
  visible: _propTypes.default.bool,
  warning: _propTypes.default.bool,
  withWarning: _propTypes.default.bool,
  onPress: _propTypes.default.func,
  onSubmit: _propTypes.default.func
};
//# sourceMappingURL=FieldOccupation.js.map