/* app-logo.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.AppLogo = void 0;
require("./app-logo.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@compiled/react");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _compiled = require("@atlaskit/primitives/compiled");
var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
var _hasCustomThemeContext = require("../themed/has-custom-theme-context");
var _logoRenderer = require("./logo-renderer");
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 anchorStyles = {
  root: "_2rko19bv _1e0c1txw _4cvr1h6o _4t3izwfg _1o9zidpf _ahbq1b66 _1toh1r31 _5jyqglyw _mrqmnqa1 _1w901kw7",
  interactionStates: "_irr31dpa _1di69yc7",
  interactionStatesCustomTheming: "_irr31rps _1di6yhlj",
  fullHeightSidebar: "_1reo15vq _18m915vq _1o9zkb7n"
};
var logoWrapperStyles = {
  root: "_18zr1b66",
  fullHeightSidebar: "_p12f1osq"
};
var iconContainerStyles = {
  root: "_1reo15vq _18m915vq _1e0c1txw _p12f1tcg",
  fullHeightSidebar: "_1o9zidpf"
};
var logoTextStyles = {
  root: "_1bsb1ris _p12fnklw _uiztglyw _y4tiv77o _1e0cglyw _10y418uv"
};
function isTextClamped(element) {
  // Checking for vertical height rather than horizontal height.
  // When text is "clamped", it's technically being clamped vertically! 🤯
  return element.scrollHeight > element.clientHeight;
}

/**
 * __App logo__
 *
 * The app logo for the top navigation.
 *
 * To provide a responsive experience, label text will render next to an icon at larger viewports.
 */
var AppLogo = exports.AppLogo = function AppLogo(_ref) {
  var name = _ref.name,
    label = _ref.label,
    href = _ref.href,
    icon = _ref.icon,
    onClick = _ref.onClick;
  var ref = (0, _react.useRef)(null);
  var nameRef = (0, _react.useRef)(null);
  var hasCustomTheme = (0, _hasCustomThemeContext.useHasCustomTheme)();

  /**
   * Show the tooltip if the name is truncated
   */
  var canTooltipAppear = (0, _react.useCallback)(function () {
    var text = nameRef.current;
    return Boolean(text && isTextClamped(text));
  }, []);
  return /*#__PURE__*/_react.default.createElement(_compiled.Anchor, {
    ref: ref,
    "aria-label": label,
    href: href
    // @ts-expect-error - non-standard values for `borderRadius` and the custom theming interaction states
    // eslint-disable-next-line @compiled/no-suppress-xcss
    ,
    xcss: (0, _react2.cx)(anchorStyles.root, hasCustomTheme ? anchorStyles.interactionStatesCustomTheming : anchorStyles.interactionStates, (0, _platformFeatureFlags.fg)('navx-full-height-sidebar') && anchorStyles.fullHeightSidebar),
    onClick: onClick
  }, /*#__PURE__*/_react.default.createElement(_compiled.Inline, {
    space: "space.075",
    alignBlock: "center",
    xcss: (0, _react2.cx)(logoWrapperStyles.root, (0, _platformFeatureFlags.fg)('navx-full-height-sidebar') && logoWrapperStyles.fullHeightSidebar)
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _runtime.ax)([iconContainerStyles.root, (0, _platformFeatureFlags.fg)('navx-full-height-sidebar') && iconContainerStyles.fullHeightSidebar])
  }, /*#__PURE__*/_react.default.createElement(_logoRenderer.LogoRenderer
  // Top nav always uses the new logo design
  , {
    shouldUseNewLogoDesign: true,
    logoOrIcon: icon
  })), /*#__PURE__*/_react.default.createElement("span", {
    className: (0, _runtime.ax)([logoTextStyles.root])
  }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
    content: name,
    position: "bottom",
    ignoreTooltipPointerEvents: true,
    hideTooltipOnMouseDown: true
    // We don't need a duplicate hidden element containing tooltip content
    // as the content of the tooltip matches what is rendered in the nav item.
    ,
    isScreenReaderAnnouncementDisabled: true,
    canAppear: canTooltipAppear
  }, function (tooltipProps) {
    return /*#__PURE__*/_react.default.createElement("span", tooltipProps, /*#__PURE__*/_react.default.createElement(_compiled.Text, {
      "aria-hidden": true,
      color: "inherit",
      weight: "semibold",
      maxLines: 1,
      ref: nameRef
    }, name));
  }))));
};