"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useReactRouter = useReactRouter;
exports.useRouter = void 0;

var _link = _interopRequireDefault(require("next/link"));

var _router = require("next/router");

var _react = require("react");

var _reactRouter = require("react-router");

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

var _isNextApp = require("../utils/isNextApp");

function useReactRouter() {
  var router_context = (0, _react.useContext)(_reactRouter.__RouterContext);

  if (router_context === undefined) {
    // will use light theme by default
    return null;
  }

  return router_context;
}

var useRouter = function useRouter() {
  // const location = useLocation();
  // const history = useHistory();
  var reactRouter = useReactRouter();
  var router = (0, _router.useRouter)(); // next

  if ((0, _isNextApp.isNextApp)()) {
    return {
      id: 'next',
      pathname: router === null || router === void 0 ? void 0 : router.pathname,
      search: router === null || router === void 0 ? void 0 : router.query,
      router: router,
      Link: _link["default"]
    };
  } // react-router


  if (reactRouter) {
    var _reactRouter$location, _reactRouter$location2;

    return {
      id: 'react-router',
      pathname: reactRouter === null || reactRouter === void 0 ? void 0 : (_reactRouter$location = reactRouter.location) === null || _reactRouter$location === void 0 ? void 0 : _reactRouter$location.pathname,
      search: reactRouter === null || reactRouter === void 0 ? void 0 : (_reactRouter$location2 = reactRouter.location) === null || _reactRouter$location2 === void 0 ? void 0 : _reactRouter$location2.search,
      router: reactRouter === null || reactRouter === void 0 ? void 0 : reactRouter.history,
      Link: _reactRouterDom.NavLink
    };
  }

  return {
    id: null,
    pathname: null,
    search: null,
    router: null,
    Link: null
  };
};

exports.useRouter = useRouter;
//# sourceMappingURL=router.js.map