"use strict";

exports.__esModule = true;
exports.default = exports.RemoteRouteReceiver = void 0;

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

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

var _hooks = require("subfirelib/hooks");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (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; }

// eslint-disable-line
const convertSubFire2Route2Subfire3 = s => {
  return s;
};

const RemoteRouteReceiver = props => {
  const {
    acknowledgePLComment,
    remotePLComment
  } = (0, _hooks.useRemoteReceiver)();
  const history = (0, _reactRouter.useHistory)();
  (0, _react.useEffect)(() => {
    const c = remotePLComment;

    if (c && c !== 'pending' && c !== 'disabled') {
      if (c.startsWith('route')) {
        let r = c.substring(6);
        console.log('got', r);
        r = convertSubFire2Route2Subfire3(r);
        const method = history.location.pathname === '/player' ? 'replace' : 'push';
        console.log('go', r, method);
        history[method](r); // console.log(history[method]);

        acknowledgePLComment();
      } // leave it for other components

    }
  }, [remotePLComment]); // eslint-disable-line

  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
};

exports.RemoteRouteReceiver = RemoteRouteReceiver;
var _default = RemoteRouteReceiver;
exports.default = _default;