"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Frame = void 0;
var _react = _interopRequireWildcard(require("react"));
var _useLinkClicked = require("../../../state/analytics/useLinkClicked");
var _styled = require("./styled");
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); }
var Frame = exports.Frame = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var isSelected = props.isSelected,
    children = props.children,
    onClick = props.onClick,
    onAuxClick = props.onAuxClick,
    onContextMenu = props.onContextMenu,
    link = props.link,
    viewType = props.viewType,
    withoutBackground = props.withoutBackground,
    testId = props.testId,
    className = props.className,
    isHovered = props.isHovered,
    truncateInline = props.truncateInline;
  var handleClick = (0, _react.useCallback)(function (event) {
    if (onClick) {
      event.preventDefault();
      event.stopPropagation();
      onClick(event);
    }
  }, [onClick]);
  var handleKeyPress = (0, _react.useCallback)(function (event) {
    if (event.key !== ' ' && event.key !== 'Enter') {
      return;
    }
    if (onClick) {
      event.preventDefault();
      event.stopPropagation();
      onClick(event);
    }
  }, [onClick]);
  var handleMouseDown = (0, _useLinkClicked.useMouseDownEvent)();
  var isInteractive = Boolean(onClick);
  var isAnchor = Boolean(link || onClick);

  // Depending on whenever Frame was given onClick or link itself we display span or anchor elements
  var Wrapper = isAnchor ? _styled.WrapperAnchor : _styled.WrapperSpan;
  return /*#__PURE__*/_react.default.createElement(Wrapper, {
    href: link,
    withoutBackground: withoutBackground,
    isSelected: isSelected,
    isInteractive: isInteractive,
    tabIndex: isInteractive && !link ? 0 : undefined,
    role: isInteractive && !link ? 'button' : undefined,
    onClick: handleClick,
    onAuxClick: onAuxClick,
    onContextMenu: onContextMenu,
    onMouseDown: handleMouseDown,
    onKeyPress: handleKeyPress,
    "data-testid": testId
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
    ,
    className: className,
    ref: ref,
    isHovered: isHovered,
    truncateInline: truncateInline,
    viewType: viewType
  }, children);
});