"use strict";

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

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

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

var _codeEditor = require("@looker/code-editor");

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

var _extensionUtils = require("@looker/extension-utils");

var _state = require("../../state");

var _utils = require("./utils");

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

var DocMarkdown = _ref => {
  var {
    source,
    specKey
  } = _ref;
  var searchPattern = (0, _reactRedux.useSelector)(_state.selectSearchPattern);
  var history = (0, _reactRouterDom.useHistory)();

  var linkClickHandler = (pathname, url) => {
    if (pathname.startsWith("/".concat(specKey))) {
      history.push(pathname);
    } else if (url.startsWith("/".concat(specKey))) {
      history.push(url);
    } else if (url.startsWith('https://')) {
      var adaptor = (0, _extensionUtils.getEnvAdaptor)();
      adaptor.openBrowserWindow(url);
    }
  };

  return _react.default.createElement(_codeEditor.Markdown, {
    source: source,
    pattern: searchPattern,
    linkClickHandler: linkClickHandler,
    transformLinkUri: _utils.transformURL.bind(null, specKey)
  });
};

exports.DocMarkdown = DocMarkdown;
//# sourceMappingURL=DocMarkdown.js.map