"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@emotion/react");
var _types = require("@atlaskit/analytics-listeners/types");
var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
var _analytics = require("../../analytics");
var _keymaps = require("../../keymaps");
var _styles = _interopRequireDefault(require("./styles"));
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); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // If you make any change here, copy it to above file as well
// and notify about the change in #team-fc-editor-ai-dev channel.
/**
 * @jsxRuntime classic
 * @jsx jsx
 */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
var buttonWrapper = (0, _react2.css)({
  display: 'flex',
  height: '100%'
});
var ToolbarButton = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
  var buttonId = props.buttonId,
    testId = props.testId,
    _props$className = props.className,
    className = _props$className === void 0 ? '' : _props$className,
    href = props.href,
    iconAfter = props.iconAfter,
    iconBefore = props.iconBefore,
    disabled = props.disabled,
    selected = props.selected,
    spacing = props.spacing,
    target = props.target,
    children = props.children,
    hideTooltip = props.hideTooltip,
    title = props.title,
    keymap = props.keymap,
    _props$titlePosition = props.titlePosition,
    titlePosition = _props$titlePosition === void 0 ? 'top' : _props$titlePosition,
    item = props.item,
    rel = props.rel,
    ariaLabel = props['aria-label'],
    ariaHasPopup = props['aria-haspopup'],
    ariaExpanded = props['aria-expanded'],
    ariaPressed = props['aria-pressed'],
    ariaKeyShortcuts = props['aria-keyshortcuts'],
    ariaControls = props['aria-controls'],
    dataDsLevel = props['data-ds--level'],
    onClick = props.onClick,
    onKeyDown = props.onKeyDown,
    onItemClick = props.onItemClick,
    onFocus = props.onFocus,
    onBlur = props.onBlur,
    onMouseEnter = props.onMouseEnter,
    onMouseLeave = props.onMouseLeave;
  var handleClick = (0, _react.useCallback)(function (event, analyticsEvent) {
    if (disabled) {
      return;
    }
    if (buttonId) {
      analyticsEvent.update(function (payload) {
        return _objectSpread(_objectSpread({}, payload), {}, {
          action: _analytics.ACTION.CLICKED,
          actionSubject: _analytics.ACTION_SUBJECT.TOOLBAR_BUTTON,
          actionSubjectId: buttonId,
          eventType: _analytics.EVENT_TYPE.UI
        });
      }).fire(_types.FabricChannel.editor);
    }
    if (onClick) {
      onClick(event);
    }
    if (item && onItemClick) {
      onItemClick(item);
    }
  }, [disabled, onClick, onItemClick, item, buttonId]);
  var button = (0, _react2.jsx)(_styles.default, {
    ref: ref,
    appearance: "subtle",
    testId: testId
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
    ,
    className: className,
    href: href,
    iconAfter: iconAfter,
    iconBefore: iconBefore,
    isDisabled: disabled,
    isSelected: selected,
    onClick: handleClick,
    spacing: spacing || 'default',
    target: target,
    shouldFitContainer: true,
    "aria-expanded": ariaExpanded,
    "aria-controls": ariaControls,
    "aria-haspopup": ariaHasPopup,
    "aria-label": ariaLabel,
    "aria-pressed": ariaPressed,
    "aria-keyshortcuts": ariaKeyShortcuts,
    onKeyDown: onKeyDown,
    onFocus: onFocus,
    onBlur: onBlur,
    onMouseEnter: onMouseEnter,
    onMouseLeave: onMouseLeave,
    "data-ds--level": dataDsLevel,
    rel: rel
  }, children);
  if (!title) {
    return button;
  }
  var tooltipContent = hideTooltip ? null : (0, _react2.jsx)(_keymaps.ToolTipContent, {
    description: title,
    keymap: keymap
  });
  return (0, _react2.jsx)(_tooltip.default, {
    content: tooltipContent,
    hideTooltipOnClick: true,
    position: titlePosition
  }, (0, _react2.jsx)("div", {
    css: buttonWrapper
  }, button));
});
var _default = exports.default = ToolbarButton;