"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styles = require("@material-ui/core/styles");
var _Snackbar = _interopRequireDefault(require("@material-ui/core/Snackbar"));
var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
var _Icon = _interopRequireDefault(require("./Icon"));
var _NotificationProps = _interopRequireDefault(require("./NotificationProps"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(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 () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : 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); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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 {
    close: {
      padding: theme.spacing(0.5),
      color: theme.palette.primary.contrastText,
      border: "none",
      margin: theme.spacing(-0.7),
      fontSize: theme.spacing(1.5),
      width: theme.spacing(2.5),
      height: theme.spacing(2.5)
    },
    closeIcon: {
      color: theme.palette.primary.contrastText
    },
    notification: {
      padding: theme.spacing(1),
      borderRadius: theme.spacing(0.5),
      width: theme.spacing(35),
      display: "flex"
    },
    icon: {
      color: theme.palette.primary.contrastText,
      padding: theme.spacing(1),
      fontSize: theme.spacing(3)
    },
    success: {
      backgroundColor: theme.palette.success.main,
      color: theme.palette.success.contrastText
    },
    error: {
      backgroundColor: theme.palette.error.main,
      color: theme.palette.error.contrastText
    },
    info: {
      backgroundColor: theme.palette.warning.main,
      color: theme.palette.success.contrastText
    },
    message: {
      flex: 1,
      padding: theme.spacing(0.5),
      fontSize: theme.typography.fieldLabelSize
    }
  };
});
var defaultAnchorOrigin = {
  vertical: "top",
  horizontal: "right"
};
var getIconIdByType = function getIconIdByType(type) {
  switch (type) {
    case "success":
      return "checkmark-filled";
    case "error":
      return "error-cross-filled";
    case "info":
      return "info";
    default:
      return "";
  }
};
var useNotificationState = function useNotificationState(snackPack, setSnackPack, lastOnly) {
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    open = _useState2[0],
    setOpen = _useState2[1];
  var _useState3 = (0, _react.useState)(undefined),
    _useState4 = _slicedToArray(_useState3, 2),
    messageInfo = _useState4[0],
    setMessageInfo = _useState4[1];
  (0, _react.useEffect)(function () {
    if (snackPack.length && !messageInfo) {
      // Set a new snack when we don't have an active one
      setMessageInfo(_objectSpread({}, snackPack[0]));
      setSnackPack(function (prev) {
        prev.splice(0, 1);
        return prev;
      });
      setOpen(true);
    } else if (lastOnly && snackPack.length && messageInfo && open) {
      // Close an active snack when a new one is added
      setOpen(false);
    }
  }, [snackPack, messageInfo, open, lastOnly, setSnackPack]);
  var handleClose = function handleClose(event, reason) {
    if (reason === "clickaway") {
      return;
    }
    setOpen(false);
  };
  var handleExited = function handleExited() {
    setMessageInfo(undefined);
  };
  return {
    open: open,
    messageInfo: messageInfo,
    handleClose: handleClose,
    handleExited: handleExited
  };
};
__signature__(useNotificationState, "useState{[open, setOpen](false)}\nuseState{[messageInfo, setMessageInfo](undefined)}\nuseEffect{}");
__signature__(useNotificationState, "useState{[open, setOpen](false)}\nuseState{[messageInfo, setMessageInfo](undefined)}\nuseEffect{}");
var Notification = function Notification(_ref) {
  var _notificationProps$ge;
  var notificationProps = _ref.notificationProps,
    snackPack = _ref.snackPack,
    setSnackPack = _ref.setSnackPack;
  var classes = useStyles();
  var autoHideDuration = (notificationProps == null ? void 0 : notificationProps.get(_NotificationProps.default.propNames.autoHideDuration)) || 5000;
  var anchorOrigin = (notificationProps == null ? void 0 : notificationProps.get(_NotificationProps.default.propNames.anchorOrigin)) || defaultAnchorOrigin;
  var lastOnly = (_notificationProps$ge = notificationProps == null ? void 0 : notificationProps.get(_NotificationProps.default.propNames.lastOnly)) != null ? _notificationProps$ge : true;
  var _useNotificationState = useNotificationState(snackPack, setSnackPack, lastOnly),
    open = _useNotificationState.open,
    messageInfo = _useNotificationState.messageInfo,
    handleClose = _useNotificationState.handleClose,
    handleExited = _useNotificationState.handleExited;
  return messageInfo ? /*#__PURE__*/_react.default.createElement(_Snackbar.default, {
    key: messageInfo.key,
    anchorOrigin: anchorOrigin,
    open: open,
    autoHideDuration: autoHideDuration,
    onClose: handleClose,
    TransitionProps: {
      onExited: handleExited
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    key: messageInfo.key,
    className: "".concat(classes.notification, " ").concat(classes[messageInfo.type])
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
    id: getIconIdByType(messageInfo.type),
    className: classes.icon
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: classes.message
  }, messageInfo.message), /*#__PURE__*/_react.default.createElement(_IconButton.default, {
    "aria-label": "close",
    color: "inherit",
    className: classes.close,
    onClick: handleClose
  }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
    id: "close2",
    className: classes.closeIcon
  })))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
};
__signature__(Notification, "useStyles{classes}\nuseNotificationState{{ open, messageInfo, handleClose, handleExited }}", function () {
  return [useStyles, useNotificationState];
});
__signature__(Notification, "useStyles{classes}\nuseNotificationState{{ open, messageInfo, handleClose, handleExited }}", function () {
  return [useStyles, useNotificationState];
});
var _default = _react.default.memo(Notification);
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/Notification.js");
  reactHotLoader.register(defaultAnchorOrigin, "defaultAnchorOrigin", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
  reactHotLoader.register(getIconIdByType, "getIconIdByType", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
  reactHotLoader.register(useNotificationState, "useNotificationState", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
  reactHotLoader.register(Notification, "Notification", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.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/Notification.js");
  reactHotLoader.register(defaultAnchorOrigin, "defaultAnchorOrigin", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
  reactHotLoader.register(getIconIdByType, "getIconIdByType", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
  reactHotLoader.register(useNotificationState, "useNotificationState", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
  reactHotLoader.register(Notification, "Notification", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/DataDisplay/Notification.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();