"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _isEmpty = _interopRequireDefault(require("lodash/fp/isEmpty"));
var _map = _interopRequireDefault(require("lodash/fp/map"));
var _provider = _interopRequireWildcard(require("../../atom/provider"));
var _tooltip = _interopRequireDefault(require("../../atom/tooltip"));
var _inputSwitch = _interopRequireDefault(require("../../atom/input-switch"));
var _style = _interopRequireDefault(require("./style.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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); }
const Settings = (props, legacyContext) => {
  const translate = (0, _provider.GetTranslateFromContext)(legacyContext);
  const {
    label,
    description,
    moreInfoAriaLabel,
    ...settings
  } = props;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.settings
  }, /*#__PURE__*/_react.default.createElement(_inputSwitch.default, _extends({}, settings, {
    'aria-label': label
  })), /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.label,
    tabIndex: 0
  }, label), (0, _isEmpty.default)(description) ? null : /*#__PURE__*/_react.default.createElement(_tooltip.default, {
    TooltipContent: description,
    closeToolTipInformationTextAriaLabel: translate('close_tooltip_information'),
    "data-testid": "user-preferences-tooltip",
    "aria-label": moreInfoAriaLabel,
    iconContainerClassName: _style.default.infoIconTooltip,
    fontSize: 12
  }));
};
Settings.propTypes = process.env.NODE_ENV !== "production" ? {
  ..._inputSwitch.default.propTypes,
  label: _propTypes.default.string.isRequired,
  description: _propTypes.default.string
} : {};
Settings.contextTypes = {
  translate: _provider.default.childContextTypes.translate
};
const UserPreferences = props => {
  const {
    preferences,
    moreInfoAriaLabel,
    groupAriaLabel
  } = props;
  return /*#__PURE__*/_react.default.createElement("form", null, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.preferences,
    role: "group",
    "aria-label": groupAriaLabel,
    tabIndex: 0
  }, (0, _map.default)(settings => /*#__PURE__*/_react.default.createElement(Settings, _extends({}, settings, {
    key: settings.label,
    moreInfoAriaLabel: moreInfoAriaLabel
  })), preferences)));
};
UserPreferences.propTypes = process.env.NODE_ENV !== "production" ? {
  preferences: _propTypes.default.arrayOf(_propTypes.default.shape(Settings.propTypes)),
  moreInfoAriaLabel: _propTypes.default.string,
  groupAriaLabel: _propTypes.default.string
} : {};
var _default = exports.default = UserPreferences;
//# sourceMappingURL=index.js.map