"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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

(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(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

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
    },
    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";

    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 = _default2;
exports.default = _default3;
;

(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);
})();