"use strict";

exports.__esModule = true;
exports.default = exports.GlobalErrorMessageLabel = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactIntl = require("react-intl");
var _styles = require("@material-ui/core/styles");
var _sharedMessages = _interopRequireDefault(require("../../../../sharedMessages"));
var _Grid = _interopRequireDefault(require("@material-ui/core/Grid"));
var _ListItemText = _interopRequireDefault(require("@material-ui/core/ListItemText"));
var _List = _interopRequireDefault(require("@material-ui/core/List"));
var _ListItem = _interopRequireDefault(require("@material-ui/core/ListItem"));
var _ListItemIcon = _interopRequireDefault(require("@material-ui/core/ListItemIcon"));
var _LookupDisplayValue = _interopRequireDefault(require("./LookupDisplayValue"));
var _ActionModal = _interopRequireDefault(require("./ActionModal"));
var _reactRedux = require("react-redux");
var _globalErrorMessages = require("../../../../selectors/globalErrorMessages");
var _globalErrorMessages2 = require("../../../../actions/globalErrorMessages");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    grid: {
      maxHeight: "40vh",
      overflowY: "auto"
    }
  };
});
var useMessageStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    label: {
      fontSize: theme.typography.fontSize,
      color: theme.palette.grey.dark,
      fontFamily: theme.typography.fontFamily
    }
  };
});
var GlobalErrorMessageLabel = exports.GlobalErrorMessageLabel = function GlobalErrorMessageLabel(_ref) {
  var children = _ref.children;
  var classes = useMessageStyles();
  return /*#__PURE__*/_react.default.createElement("span", {
    className: classes.label
  }, children);
};
__signature__(GlobalErrorMessageLabel, "useMessageStyles{classes}", function () {
  return [useMessageStyles];
});
__signature__(GlobalErrorMessageLabel, "useMessageStyles{classes}", function () {
  return [useMessageStyles];
});
var GlobalErrorMessagesModal = function GlobalErrorMessagesModal(_ref2) {
  var _msg$messages;
  var children = _ref2.children;
  var classes = useStyles();
  var _useIntl = (0, _reactIntl.useIntl)(),
    formatMessage = _useIntl.formatMessage;
  var dispatch = (0, _reactRedux.useDispatch)();
  var msg = (0, _reactRedux.useSelector)(_globalErrorMessages.firstDialogErrorMessageSelector);
  if (msg === null) {
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
  }
  var closeCallback = function closeCallback() {
    dispatch((0, _globalErrorMessages2.popGlobalErrorMessage)());
  };
  var actions = [{
    label: _sharedMessages.default.close,
    isPrimary: true,
    handler: closeCallback
  }];
  var content = /*#__PURE__*/_react.default.createElement(_Grid.default, {
    container: true,
    spacing: 2,
    className: classes.grid
  }, /*#__PURE__*/_react.default.createElement(_Grid.default, {
    container: true,
    item: true,
    spacing: 0
  }, msg.description && /*#__PURE__*/_react.default.createElement(_Grid.default, {
    item: true,
    xs: 12
  }, msg.description), ((_msg$messages = msg.messages) == null ? void 0 : _msg$messages.length) > 0 && /*#__PURE__*/_react.default.createElement(_Grid.default, {
    item: true,
    xs: 12
  }, /*#__PURE__*/_react.default.createElement(_List.default, {
    className: classes.root
  }, msg.messages.map(function (msg, index) {
    var hasLookup = msg.lookupModule && msg.lookupName && msg.lookupKey;
    return /*#__PURE__*/_react.default.createElement(_ListItem.default, {
      key: index
    }, /*#__PURE__*/_react.default.createElement(_ListItemIcon.default, null, "\u25CF"), /*#__PURE__*/_react.default.createElement(_ListItemText.default, null, hasLookup && /*#__PURE__*/_react.default.createElement(_LookupDisplayValue.default, {
      moduleName: msg.lookupModule,
      lookupName: msg.lookupName,
      lookupKey: msg.lookupKey,
      lookupReplacementValues: msg.lookupReplacementValues,
      labelComponent: GlobalErrorMessageLabel
    }), !hasLookup && /*#__PURE__*/_react.default.createElement(GlobalErrorMessageLabel, null, msg.message)));
  })))));
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children, /*#__PURE__*/_react.default.createElement(_ActionModal.default, {
    title: msg.title || formatMessage(_sharedMessages.default.error),
    message: content,
    open: true,
    actions: actions
  }));
};
__signature__(GlobalErrorMessagesModal, "useStyles{classes}\nuseIntl{{ formatMessage }}\nuseDispatch{dispatch}\nuseSelector{msg}", function () {
  return [useStyles, _reactIntl.useIntl, _reactRedux.useDispatch, _reactRedux.useSelector];
});
__signature__(GlobalErrorMessagesModal, "useStyles{classes}\nuseIntl{{ formatMessage }}\nuseDispatch{dispatch}\nuseSelector{msg}", function () {
  return [useStyles, _reactIntl.useIntl, _reactRedux.useDispatch, _reactRedux.useSelector];
});
var _default = GlobalErrorMessagesModal;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
  reactHotLoader.register(useMessageStyles, "useMessageStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
  reactHotLoader.register(GlobalErrorMessageLabel, "GlobalErrorMessageLabel", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
  reactHotLoader.register(GlobalErrorMessagesModal, "GlobalErrorMessagesModal", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
  reactHotLoader.register(useMessageStyles, "useMessageStyles", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
  reactHotLoader.register(GlobalErrorMessageLabel, "GlobalErrorMessageLabel", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
  reactHotLoader.register(GlobalErrorMessagesModal, "GlobalErrorMessagesModal", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();