"use strict";

exports.__esModule = true;
exports.extractMessages = extractMessages;
exports.TestWrapper = exports.generateClassName = exports.createMuiTheme = exports.ignoreConsoleError = exports.PropStruct = exports.firstItemComparator = exports.getStyledClassSelector = exports.getClassSelector = exports.getClassName = exports.getElmClasses = exports.spyOnConsole = void 0;

var _react = _interopRequireDefault(require("react"));

var _styledComponents = require("styled-components");

var _unexpectedReaction = require("unexpected-reaction");

var _muiThemes = _interopRequireDefault(require("./../components/MaterialUI/muiThemes"));

var _reactRouterDom = require("react-router-dom");

var _core = require("@material-ui/core");

var _styles = require("@material-ui/core/styles");

var _reactIntl = require("react-intl");

var _reactRedux = require("react-redux");

var _NotificationContext = require("./../components/MaterialUI/Feedback/NotificationContext");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(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 _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 sinon = require("sinon");
/* istanbul ignore next */


var spyOnConsole = function spyOnConsole(spyNames) {
  if (spyNames === void 0) {
    spyNames = ["log", "warn", "error"];
  }

  var spiedFuncs;
  beforeEach(function () {
    spiedFuncs = spyNames.map(function (funcName) {
      var func = sinon.spy().named("console." + funcName);
      var oldFunc = console[funcName];
      console[funcName] = func;
      return oldFunc;
    });
  });
  afterEach(function () {
    spiedFuncs.forEach(function (func, index) {
      var name = spyNames[index];
      console[name] = func;
    });
  });
};

exports.spyOnConsole = spyOnConsole;

var getElmClasses = function getElmClasses(reactElm, container) {
  var domElm = (0, _unexpectedReaction.mount)(reactElm, container ? {
    container: container
  } : undefined);
  var classes = domElm.getAttribute("class");

  if (!classes) {
    throw new Error("Class name not found in <" + (reactElm.type.name || reactElm.type) + " />");
  }

  return classes.split(" ");
};

exports.getElmClasses = getElmClasses;

var getClassName = function getClassName(reactElm, index, container) {
  if (index === void 0) {
    index = 0;
  }

  var classes = getElmClasses(reactElm, container);
  return classes[index] || "";
};

exports.getClassName = getClassName;

var getClassSelector = function getClassSelector(elm, index, container) {
  if (index < 0) {
    return "." + getElmClasses(elm, container).join(".");
  } else {
    var className = getClassName(elm, index, container) || "";
    return className && "." + className;
  }
};

exports.getClassSelector = getClassSelector;

var getStyledClassSelector = function getStyledClassSelector(elm) {
  var component = elm.type || elm;

  if (!(0, _styledComponents.isStyledComponent)(component)) {
    throw new Error("<" + (component.name || component) + " /> is not a styled component");
  } // Styled component toString() function returns a stable class name


  return component.toString();
};

exports.getStyledClassSelector = getStyledClassSelector;

var firstItemComparator = function firstItemComparator(a, b) {
  return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0;
};

exports.firstItemComparator = firstItemComparator;

var PropStruct = _react.default.forwardRef(function (props, ref) {
  return (
    /*#__PURE__*/
    // TODO: Handle refs sensibly instead of ignoring?
    _react.default.createElement("dl", {
      id: props.id
    }, Object.entries(props).sort(firstItemComparator).map(function (_ref) {
      var _ref2 = _slicedToArray(_ref, 2),
          key = _ref2[0],
          value = _ref2[1];

      return value === undefined || value === null ? null : value === "__ignore" ? [/*#__PURE__*/_react.default.createElement(_unexpectedReaction.Ignore, {
        key: "dt-" + key
      }), /*#__PURE__*/_react.default.createElement(_unexpectedReaction.Ignore, {
        key: "dd-" + key
      })] : [/*#__PURE__*/_react.default.createElement("dt", {
        key: "dt-" + key
      }, "".concat(key, ":")), /*#__PURE__*/_react.default.createElement("dd", {
        key: "dd-" + key
      }, key === "children" ? value : typeof value === "object" ? value["$$typeof"] && value["$$typeof"] === Symbol.for("react.element") ? "React <" + (value.type.name || value.type) + ">" : /*#__PURE__*/_react.default.createElement(PropStruct, value) : typeof value === "function" ? "Function" : typeof value === "string" ? "string \"".concat(value, "\"") : typeof value === "symbol" ? "symbol ".concat(value.toString()) : typeof value + " " + value)];
    }))
  );
});

exports.PropStruct = PropStruct;

var ignoreConsoleError = function ignoreConsoleError(func) {
  jest.spyOn(console, "error");
  console.error.mockImplementation(function () {});
  func();
  console.error.mockRestore();
};

exports.ignoreConsoleError = ignoreConsoleError;

var createMuiTheme = function createMuiTheme() {
  var applicationTheme = {
    primary: {
      main: "#1F5B7F"
    }
  };
  var themeDefinition = {
    palette: {
      primary: {
        lighter: "#f5f5f5",
        light: "#CCC",
        main: "#232323",
        dark: "#000",
        contrastText: "#fff"
      }
    }
  };
  var themes = (0, _muiThemes.default)(applicationTheme, themeDefinition);
  var muiTheme = themes.muiTheme;
  return muiTheme;
};

exports.createMuiTheme = createMuiTheme;

var generateClassName = function generateClassName(rule, styleSheet) {
  return "".concat(styleSheet.options.classNamePrefix, "-").concat(rule.key);
};

exports.generateClassName = generateClassName;

function extractMessages() {
  var extractedMessages = {};

  for (var i = 0; i < arguments.length; i++) {
    var messages = arguments[i];

    for (var property in messages) {
      var message = messages[property];
      extractedMessages[message.id] = message.defaultMessage;
    }
  }

  return extractedMessages;
}

var TestWrapper = function TestWrapper(_ref3) {
  var provider = _ref3.provider,
      intlProvider = _ref3.intlProvider,
      router = _ref3.router,
      memoryRouter = _ref3.memoryRouter,
      stylesProvider = _ref3.stylesProvider,
      muiThemeProvider = _ref3.muiThemeProvider,
      children = _ref3.children;

  var ProviderWrapper = function ProviderWrapper(_ref4) {
    var children = _ref4.children;
    if (provider == null) return children;
    return /*#__PURE__*/_react.default.createElement(_reactRedux.Provider, {
      store: provider.store
    }, children);
  };

  var IntlProvderWrapper = function IntlProvderWrapper(_ref5) {
    var children = _ref5.children;
    if (intlProvider == null) return children;
    return /*#__PURE__*/_react.default.createElement(_reactIntl.IntlProvider, {
      locale: "en-US",
      timeZone: "UTC",
      messages: intlProvider.messages
    }, children);
  };

  var StylesProviderWrapper = function StylesProviderWrapper(_ref6) {
    var children = _ref6.children;
    if (stylesProvider == null) return children;
    return /*#__PURE__*/_react.default.createElement(_styles.StylesProvider, {
      generateClassName: generateClassName
    }, children);
  };

  var MuiThemeProviderWrapper = function MuiThemeProviderWrapper(_ref7) {
    var children = _ref7.children;
    if (muiThemeProvider == null) return children;
    return /*#__PURE__*/_react.default.createElement(_core.MuiThemeProvider, {
      theme: muiThemeProvider.theme
    }, children);
  };

  var MemoryRouterWrapper = function MemoryRouterWrapper(_ref8) {
    var children = _ref8.children;
    if (memoryRouter == null) return children;
    return /*#__PURE__*/_react.default.createElement(_reactRouterDom.MemoryRouter, {
      initialEntries: memoryRouter.initialEntries
    }, children);
  };

  var RouterWrapper = function RouterWrapper(_ref9) {
    var children = _ref9.children;
    if (router == null) return children;
    return /*#__PURE__*/_react.default.createElement(_reactRouterDom.Router, {
      history: router.history
    }, children);
  };

  return /*#__PURE__*/_react.default.createElement(ProviderWrapper, null, /*#__PURE__*/_react.default.createElement(RouterWrapper, null, /*#__PURE__*/_react.default.createElement(MemoryRouterWrapper, null, /*#__PURE__*/_react.default.createElement(IntlProvderWrapper, null, /*#__PURE__*/_react.default.createElement(StylesProviderWrapper, null, /*#__PURE__*/_react.default.createElement(MuiThemeProviderWrapper, null, /*#__PURE__*/_react.default.createElement(_NotificationContext.NotificationContextProvider, null, children)))))));
};

exports.TestWrapper = TestWrapper;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(spyOnConsole, "spyOnConsole", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(getElmClasses, "getElmClasses", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(getClassName, "getClassName", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(getClassSelector, "getClassSelector", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(getStyledClassSelector, "getStyledClassSelector", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(firstItemComparator, "firstItemComparator", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(PropStruct, "PropStruct", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(ignoreConsoleError, "ignoreConsoleError", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(createMuiTheme, "createMuiTheme", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(generateClassName, "generateClassName", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(extractMessages, "extractMessages", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(TestWrapper, "TestWrapper", "/home/vsts/work/1/s/src/utils/testUtils.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(spyOnConsole, "spyOnConsole", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(getElmClasses, "getElmClasses", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(getClassName, "getClassName", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(getClassSelector, "getClassSelector", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(getStyledClassSelector, "getStyledClassSelector", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(firstItemComparator, "firstItemComparator", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(PropStruct, "PropStruct", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(ignoreConsoleError, "ignoreConsoleError", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(createMuiTheme, "createMuiTheme", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(generateClassName, "generateClassName", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(extractMessages, "extractMessages", "/home/vsts/work/1/s/src/utils/testUtils.js");
  reactHotLoader.register(TestWrapper, "TestWrapper", "/home/vsts/work/1/s/src/utils/testUtils.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();