"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
var _reactMagneticDi = require("react-magnetic-di");
var _analyticsNext = require("@atlaskit/analytics-next");
var _LinkAnalyticsContext = require("../../utils/analytics/LinkAnalyticsContext");
var _Hyperlink = _interopRequireDefault(require("./Hyperlink"));
var _HyperlinkResolver = require("./HyperlinkResolver");
var _LinkWarningModal = _interopRequireDefault(require("./LinkWarningModal"));
var _useLinkWarningModal2 = require("./LinkWarningModal/hooks/use-link-warning-modal");
var _excluded = ["href", "children", "checkSafety", "onClick", "testId", "isLinkComponent", "enableResolve"],
  _excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
var PACKAGE_DATA = {
  packageName: "@atlaskit/smart-card",
  packageVersion: "44.23.0",
  componentName: 'linkUrl'
};
var LinkUrl = function LinkUrl(_ref) {
  var href = _ref.href,
    children = _ref.children,
    _ref$checkSafety = _ref.checkSafety,
    checkSafety = _ref$checkSafety === void 0 ? true : _ref$checkSafety,
    _onClick = _ref.onClick,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'link-with-safety' : _ref$testId,
    _ref$isLinkComponent = _ref.isLinkComponent,
    isLinkComponent = _ref$isLinkComponent === void 0 ? false : _ref$isLinkComponent,
    _ref$enableResolve = _ref.enableResolve,
    enableResolve = _ref$enableResolve === void 0 ? false : _ref$enableResolve,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var _useLinkWarningModal = (0, _useLinkWarningModal2.useLinkWarningModal)(),
    isLinkSafe = _useLinkWarningModal.isLinkSafe,
    showSafetyWarningModal = _useLinkWarningModal.showSafetyWarningModal,
    linkWarningModalProps = (0, _objectWithoutProperties2.default)(_useLinkWarningModal, _excluded2);
  var Link = enableResolve ? _HyperlinkResolver.HyperlinkWithSmartLinkResolver : _Hyperlink.default;
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_LinkAnalyticsContext.LinkAnalyticsContext, {
    url: href,
    display: "url"
  }, /*#__PURE__*/_react.default.createElement(Link, (0, _extends2.default)({
    href: href,
    testId: testId,
    isLinkComponent: isLinkComponent,
    onClick: function onClick(e) {
      if (!checkSafety) {
        _onClick && _onClick(e);
        return;
      }

      // Only call the onClick if the link is safe
      if (isLinkSafe(e, href)) {
        _onClick && _onClick(e);
      } else {
        showSafetyWarningModal(e, href);
      }
    }
  }, props), children)), checkSafety && /*#__PURE__*/_react.default.createElement(_LinkWarningModal.default, linkWarningModalProps));
};
var _default_1 = (0, _analyticsNext.withAnalyticsContext)(PACKAGE_DATA)(LinkUrl);
var _default = exports.default = _default_1;