"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = PatternFlyTooltip;
var _react = _interopRequireDefault(require("react"));
var _Tooltip = require("@patternfly/react-core/dist/esm/components/Tooltip");
var _model = require("../model");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
 * Copyright 2021 The Kubernetes Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const Markdown = _react.default.lazy(() => Promise.resolve().then(() => require('../../../Content/Markdown')));
function isMarkdownContent(str) {
  return !/^\w+$/.test(str);
}
function PatternFlyTooltip(props) {
  const isMarkdown = (0, _model.isMarkdownProps)(props);
  const isReference = (0, _model.isReferenceProps)(props);
  if (!isReference && (isMarkdown && !props.markdown || !isMarkdown && !props.content)) {
    // no content to display!
    return _react.default.createElement(_react.default.Fragment, null, props.children);
  }
  return _react.default.createElement(_Tooltip.Tooltip, {
    className: "kui--tooltip",
    enableFlip: props.enableFlip,
    maxWidth: props.maxWidth,
    isContentLeftAligned: isMarkdown,
    position: props.position || 'auto',
    distance: 10,
    entryDelay: props.entryDelay || 200,
    "data-is-markdown": isMarkdown || undefined,
    reference: isReference && props.reference,
    content: isReference ? props.children : isMarkdown ? !isMarkdownContent(props.markdown) ? props.markdown : _react.default.createElement(_react.default.Suspense, {
      fallback: _react.default.createElement("div", null)
    }, _react.default.createElement(Markdown, {
      nested: true,
      executableCodeBlocks: false,
      source: props.markdown
    })) : props.content
  }, !isReference && _react.default.createElement(_react.default.Fragment, null, props.children));
}