"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styles = require("@material-ui/core/styles");
var _reactRouterDom = require("react-router-dom");
var _reactIntl = require("react-intl");
var _Icon = _interopRequireDefault(require("../MaterialUI/DataDisplay/Icon"));
var _excluded = ["staticContext", "dispatch", "component"],
  _excluded2 = ["open", "label", "icon", "alert", "isHidden", "href", "menuToggle", "active"];
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 _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); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
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 getToastColor = function getToastColor(theme, alertType) {
  var toastBorderColors = {
    error: theme.palette.error.main,
    warn: theme.palette.warning.main,
    confirm: theme.palette.success.main
  };
  return toastBorderColors[alertType] || "red";
};
var useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    block: function block(props) {
      return {
        display: "block",
        position: "relative",
        padding: "0 10px",
        marginBottom: "35px",
        textDecoration: "none",
        cursor: "pointer",
        color: props.active ? theme.palette.primary.light : theme.palette.text.hint,
        "&:hover": {
          color: props.menuToggle ? undefined : theme.palette.primary.light
        }
      };
    },
    alert: function alert(props) {
      var toastColor = getToastColor(theme, props.alertType);
      return {
        borderRadius: "50%",
        border: "4px solid ".concat(toastColor),
        position: "absolute",
        top: 0,
        left: "27px",
        visibility: "hidden",
        "&.show": {
          visibility: "visible"
        }
      };
    },
    alertMessage: function alertMessage(props) {
      var toastColor = getToastColor(theme, props.alertType);
      return {
        position: "absolute",
        zIndex: 10000,
        top: "calc(-10px - 0.7em)",
        left: "22px",
        width: "max-content",
        borderRadius: "5px",
        padding: "10px 15px",
        boxShadow: "0 2px 4px 0 rgba(0, 0, 0, 0.5)",
        color: theme.palette.grey.light,
        backgroundColor: toastColor,
        fontSize: "11px",
        fontWeight: "bold",
        lineHeight: 1.2,
        transition: "transform 200ms cubic-bezier(0.68, -0.55, 0.27, 1.55), opacity 100ms 50ms ease-out",
        opacity: 0.01,
        transform: "translateX(-50%) scaleX(0)",
        "&::before": {
          content: "",
          position: "absolute",
          top: "calc(10px + 0.2em)",
          left: "-0.9em",
          border: "solid transparent",
          borderWidth: "0.4em 0.9em 0.4em 0",
          borderRightColor: toastColor
        },
        "&.show": {
          opacity: 1,
          transform: "translateX(0) scaleX(1)"
        }
      };
    },
    menuIcon: function menuIcon(props) {
      return {
        fontSize: "24px",
        verticalAlign: "middle",
        color: props.active ? theme.palette.primary.light : theme.palette.text.hint
      };
    },
    label: function label(props) {
      return {
        fontFamily: theme.typography.button.fontFamily,
        fontSize: "13px",
        verticalAlign: "middle",
        textTransform: "uppercase",
        paddingLeft: "10px",
        transition: "opacity 0.3s ease-out",
        opacity: props.showLabel ? 1 : 0
      };
    }
  };
});
var FilteredLink = function FilteredLink(_ref) {
  var staticContext = _ref.staticContext,
    dispatch = _ref.dispatch,
    component = _ref.component,
    props = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, props);
};
var MenuItem = function MenuItem(_ref2) {
  var _ref2$open = _ref2.open,
    open = _ref2$open === void 0 ? false : _ref2$open,
    _ref2$label = _ref2.label,
    label = _ref2$label === void 0 ? "" : _ref2$label,
    icon = _ref2.icon,
    alert = _ref2.alert,
    _ref2$isHidden = _ref2.isHidden,
    isHidden = _ref2$isHidden === void 0 ? false : _ref2$isHidden,
    href = _ref2.href,
    menuToggle = _ref2.menuToggle,
    active = _ref2.active,
    props = _objectWithoutProperties(_ref2, _excluded2);
  var classes = useStyles({
    active: active,
    menuToggle: menuToggle,
    alertType: alert == null ? void 0 : alert.type,
    showLabel: open
  });
  var alertMessage = (0, _react.useRef)("");
  var showAlert = !!alert;
  var showAlertMessage = !!(alert != null && alert.message);
  if (showAlert && showAlertMessage) {
    alertMessage.current = alert.message;
  }
  if (isHidden) {
    return false;
  }
  var ItemWrapper = menuToggle ? "a" : FilteredLink;
  return /*#__PURE__*/_react.default.createElement(ItemWrapper, _extends({
    to: href,
    className: classes.block
  }, props), /*#__PURE__*/_react.default.createElement(_Icon.default, {
    id: icon,
    className: classes.menuIcon
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(classes.alert, " ").concat(showAlert ? "show" : undefined)
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(classes.alertMessage, " ").concat(showAlertMessage ? "show" : undefined)
  }, alertMessage.current)), /*#__PURE__*/_react.default.createElement("span", {
    className: classes.label
  }, typeof label === "string" ? label : /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, label)));
};
__signature__(MenuItem, "useStyles{classes}\nuseRef{alertMessage}", function () {
  return [useStyles];
});
__signature__(MenuItem, "useStyles{classes}\nuseRef{alertMessage}", function () {
  return [useStyles];
});
var _default = MenuItem;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(getToastColor, "getToastColor", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
  reactHotLoader.register(FilteredLink, "FilteredLink", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
  reactHotLoader.register(MenuItem, "MenuItem", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.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(getToastColor, "getToastColor", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
  reactHotLoader.register(FilteredLink, "FilteredLink", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
  reactHotLoader.register(MenuItem, "MenuItem", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/AppFrame/MenuItem.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();