"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Amenities = void 0;
var _locale = require("@mirai/locale");
var _ui = require("@mirai/ui");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _Amenities = require("./Amenities.l10n");
var style = _interopRequireWildcard(require("./Amenities.module.css"));
var _helpers = require("../../../../../helpers");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const Amenities = _ref => {
  let {
    amenities = [],
    highlight = false,
    preview = false
  } = _ref;
  const {
    isMobile
  } = (0, _ui.useDevice)();
  const {
    translate
  } = (0, _locale.useLocale)();
  const values = amenities.filter(function () {
    let item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return !highlight && !item.highlight || highlight && item.highlight;
  }).slice(0, preview ? 3 : undefined);
  const oversized = !isMobile && highlight && !preview;
  return values.length ? /*#__PURE__*/_react.default.createElement(_ui.View, {
    row: oversized,
    className: (0, _ui.styles)(oversized ? style.oversized : preview ? style.list : style.columns)
  }, values.sort(function () {
    let a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    let b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    if (a.exclusive === b.exclusive) return 0;
    return a.exclusive ? -1 : 1;
  }).map(function () {
    let {
      exclusive,
      id,
      text
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    let index = arguments.length > 1 ? arguments[1] : undefined;
    return /*#__PURE__*/_react.default.createElement(_ui.View, {
      key: index,
      row: !oversized,
      className: style.content
    }, highlight || preview ? /*#__PURE__*/_react.default.createElement(_ui.Icon, {
      accent: oversized,
      value: exclusive ? _helpers.ICON.PREMIUM : _helpers.ICON[id] || _helpers.ICON.AMENITY,
      headline: true,
      level: oversized ? 2 : 3
    }) : /*#__PURE__*/_react.default.createElement(_ui.Text, {
      small: true
    }, "\u2022"), /*#__PURE__*/_react.default.createElement(_ui.Text, {
      action: true,
      className: (0, _ui.styles)(style.text, (oversized || !preview) && style.textDoubleLine),
      "aria-label": text
    }, text), !highlight && exclusive && /*#__PURE__*/_react.default.createElement(_ui.Tooltip, {
      text: translate(_Amenities.L10N.LABEL_ONLY_FOR_ROOM)
    }, /*#__PURE__*/_react.default.createElement(_ui.Icon, {
      value: _helpers.ICON.PREMIUM
    })));
  })) : null;
};
exports.Amenities = Amenities;
Amenities.propTypes = {
  amenities: _propTypes.default.arrayOf(_propTypes.default.shape({
    exclusive: _propTypes.default.bool,
    highlight: _propTypes.default.bool,
    id: _propTypes.default.number,
    text: _propTypes.default.string
  })),
  highlight: _propTypes.default.bool,
  preview: _propTypes.default.bool
};
Amenities.displayName = 'Mirai:Core:Rates:Item:Amenities';
//# sourceMappingURL=Amenities.js.map