import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import fetchMock from 'fetch-mock/cjs/client';
import { fieldValuesEmptyResponse, fieldValuesErrorResponse, fieldValuesResponseForAssignees, fieldValuesResponseForProjects, fieldValuesResponseForProjectsMoreData, fieldValuesResponseForStatuses, fieldValuesResponseForTypes, hydrateJqlStandardResponseForVRTesting, successfuluserHydrationResponse, successfulUserQueryResponse } from './mocks';
export var mockBasicFilterAGGFetchRequests = function mockBasicFilterAGGFetchRequests() {
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
    withJiraFilterHydration: true
  };
  fetchMock.post(new RegExp("/graphql"), /*#__PURE__*/function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_url, details) {
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", new Promise(function (resolve) {
              var _mockBasicFilterData$;
              var requestBody = JSON.parse(details.body);

              // CLOL basic filter - edited/created by
              if (requestBody.operationName === 'userQuery') {
                return resolve(successfulUserQueryResponse);
              }
              if (requestBody.operationName === 'userHydration') {
                return resolve(successfuluserHydrationResponse);
              }

              // JLOL basic filter hydration for VR testing
              if (requestBody.operationName === 'hydrate' && opts.withJiraFilterHydration) {
                return resolve(hydrateJqlStandardResponseForVRTesting);
              }
              var filterType = requestBody.variables.jqlTerm;
              var searchString = requestBody.variables.searchString;
              var pageCursor = requestBody.variables.after;
              var mockBasicFilterData = {
                project: fieldValuesResponseForProjects,
                assignee: fieldValuesResponseForAssignees,
                type: fieldValuesResponseForTypes,
                status: fieldValuesResponseForStatuses
              };
              var resolveData = {
                data: ((_mockBasicFilterData$ = mockBasicFilterData[filterType]) === null || _mockBasicFilterData$ === void 0 ? void 0 : _mockBasicFilterData$.data) || []
              };

              // playwright test specifically requesting more projects data
              if (pageCursor) {
                resolve(fieldValuesResponseForProjectsMoreData);
              }

              // slowing down specifically for vr testing
              if (searchString === 'loading-message') {
                setTimeout(function () {
                  resolve(resolveData);
                }, 5000);
              } // returning empty response for vr testing
              else if (searchString === 'empty-message') {
                resolve(fieldValuesEmptyResponse);
              } // returning error response for vr testing
              else if (searchString === 'error-message') {
                resolve(fieldValuesErrorResponse);
              } else {
                resolve(resolveData);
              }
            }));
          case 1:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function (_x, _x2) {
      return _ref.apply(this, arguments);
    };
  }());
};