/* index.tsx generated by @compiled/babel-plugin v0.38.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toLinkProps = exports.default = void 0;
require("./index.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
var _constants = require("../../../../../../constants");
var _useLinkClicked = require("../../../../../../state/analytics/useLinkClicked");
var _experiments = require("../../../../../../utils/experiments");
var _utils = require("../../../utils");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
/* eslint-disable @compiled/shorthand-property-sorting */
/* eslint-disable @atlaskit/design-system/use-tokens-typography */
var DEFAULT_MAX_LINES = 2;
var MAXIMUM_MAX_LINES = 2;
var MINIMUM_MAX_LINES = 1;
var containerStyles = null;
var getMaxLines = function getMaxLines(maxLines) {
  if (maxLines > MAXIMUM_MAX_LINES) {
    return DEFAULT_MAX_LINES;
  }
  if (maxLines < MINIMUM_MAX_LINES) {
    return MINIMUM_MAX_LINES;
  }
  return maxLines;
};
var withTooltip = function withTooltip(trigger, content, testId) {
  return /*#__PURE__*/_react.default.createElement(_tooltip.default, {
    content: content,
    testId: "".concat(testId, "-tooltip"),
    tag: "span"
  }, trigger);
};
var linkStyleSizeMap = {
  xlarge: "_11c8lodh _k48pi7a9 _vwz41k8s",
  large: "_11c82smr _k48pi7a9 _vwz41j6v",
  medium: "_11c82smr _k48pi7a9 _vwz41j6v",
  small: "_11c8dcr7 _k48pi7a9 _vwz41j6v"
};
var baseAnchorStyle = null;
var workBreakStyleMap = {
  true: "_1nmz1hna",
  false: "_1nmz9jpi"
};
var anchorConstantsStyles = null;
var anchorLineClampMap = {
  1: "_1yyjkb7n",
  2: "_1yyjcs5v"
};
var anchorLinkLineHeight1Map = {
  xlarge: "_102k1k8s",
  large: "_102k1j6v",
  medium: "_102k1j6v",
  small: "_102k1j6v"
};
var anchorLinkLineHeight2Map = {
  xlarge: "_102k1wto",
  large: "_102kviql",
  medium: "_102kviql",
  small: "_102kviql"
};
var themeStyleMap = {
  grey: "_fjv61r31 _93u91r31 _g2lk1r31 _pnzf1r31 _hlwq8stv _1e2m8stv _1l4b8stv _ue8d8stv _yni7nqa1 _1bianqa1 _93jhnqa1 _64n6nqa1 _1ray131l _dlb7131l _rnxt131l _1h4d131l _10uedcr7 _ye10131l",
  black: "_syaz1gjq _1nrm1r31 _1a3b1r31 _9oik1r31 _1ydc1r31 _c2wa8stv _4fpr8stv _1bnx8stv _1x288stv _1iohnqa1 _5goinqa1 _jf4cnqa1 _1726nqa1 _9h8h1gjq _f8pj1gjq _30l31gjq _10531gjq",
  link: "_syaz14q2 _9oik1r31 _1bnx8stv _jf4cnqa1 _30l314q2 _9h8h16c2"
};
/**
 * A base element that represent an anchor.
 * @internal
 * @param {BaseLinkElementProps} BaseLinkElementProps - The props necessary for the Link element.
 * @see LinkIcon
 */
var BaseLinkElement = function BaseLinkElement(_ref) {
  var hideTooltip = _ref.hideTooltip,
    _ref$maxLines = _ref.maxLines,
    maxLines = _ref$maxLines === void 0 ? DEFAULT_MAX_LINES : _ref$maxLines,
    name = _ref.name,
    className = _ref.className,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? _constants.SmartLinkSize.Medium : _ref$size,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-element-link' : _ref$testId,
    text = _ref.text,
    _ref$theme = _ref.theme,
    theme = _ref$theme === void 0 ? _constants.SmartLinkTheme.Link : _ref$theme,
    url = _ref.url,
    onClick = _ref.onClick,
    _ref$target = _ref.target,
    target = _ref$target === void 0 ? '_blank' : _ref$target,
    anchorRef = _ref.anchorRef;
  var onMouseDown = (0, _useLinkClicked.useMouseDownEvent)();
  var hasSpace = (0, _react.useMemo)(function () {
    return text ? (0, _utils.hasWhiteSpace)(text) : false;
  }, [text]);
  var anchor = /*#__PURE__*/_react.default.createElement("a", (0, _extends2.default)({
    "data-smart-element": name,
    "data-smart-element-link": true,
    "data-testid": testId,
    onClick: onClick,
    onMouseDown: onMouseDown,
    href: url
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    ,
    className: (0, _runtime.ax)(["_16jlkb7n _1o9zkb7n _i0dl1wug", linkStyleSizeMap[size], anchorLineClampMap[getMaxLines(maxLines)], "_1reo15vq _18m915vq _1e0ccj1k _1bto1l2s _sudp1e54", workBreakStyleMap[hasSpace ? 'true' : 'false'], getMaxLines(maxLines) === 1 && anchorLinkLineHeight1Map[size], getMaxLines(maxLines) === 2 && anchorLinkLineHeight2Map[size], themeStyleMap[theme], className])
    // We do not want set the target if it is the default value of '_self'. This prevents link
    // click issues in Confluence and Trello which rely on it not being set unless necessary.
  }, target !== '_self' && {
    target: target
  }, {
    ref: anchorRef
  }), text);
  return /*#__PURE__*/_react.default.createElement("span", {
    className: (0, _runtime.ax)(["_16jlkb7n _1o9zkb7n _i0dl1wug"])
  }, hideTooltip || text === undefined ? anchor : withTooltip(anchor, url !== null && url !== void 0 && url.includes(text) && (0, _experiments.isNewBlockcardUnauthorizedRefreshExperimentEnabled)() ? url : text, testId));
};
var _default = exports.default = BaseLinkElement;
var toLinkProps = exports.toLinkProps = function toLinkProps(text, url) {
  return text ? {
    text: text,
    url: url
  } : undefined;
};