/* app-logo.tsx generated by @compiled/babel-plugin v0.38.1 */
import "./app-logo.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React, { useCallback, useRef } from 'react';
import { cx } from '@compiled/react';
import { fg } from '@atlaskit/platform-feature-flags';
import { Anchor, Inline, Text } from '@atlaskit/primitives/compiled';
import Tooltip from '@atlaskit/tooltip';
import { useHasCustomTheme } from '../themed/has-custom-theme-context';
import { LogoRenderer } from './logo-renderer';
const anchorStyles = {
  root: "_2rko19bv _1e0c1txw _4cvr1h6o _4t3izwfg _1o9zidpf _ahbq1b66 _1toh1r31 _5jyqglyw _mrqmnqa1 _1w901kw7",
  interactionStates: "_irr3166n _1di61wwy",
  interactionStatesCustomTheming: "_irr31rps _1di6yhlj",
  fullHeightSidebar: "_1reo15vq _18m915vq _1o9zkb7n"
};
const logoWrapperStyles = {
  root: "_18zr1b66",
  fullHeightSidebar: "_p12f1osq"
};
const iconContainerStyles = {
  root: "_1reo15vq _18m915vq _1e0c1txw _p12f1tcg",
  fullHeightSidebar: "_1o9zidpf"
};
const 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.
 */
export const AppLogo = ({
  name,
  label,
  href,
  icon,
  onClick
}) => {
  const ref = useRef(null);
  const nameRef = useRef(null);
  const hasCustomTheme = useHasCustomTheme();

  /**
   * Show the tooltip if the name is truncated
   */
  const canTooltipAppear = useCallback(() => {
    const text = nameRef.current;
    return Boolean(text && isTextClamped(text));
  }, []);
  return /*#__PURE__*/React.createElement(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: cx(anchorStyles.root, hasCustomTheme ? anchorStyles.interactionStatesCustomTheming : anchorStyles.interactionStates, fg('navx-full-height-sidebar') && anchorStyles.fullHeightSidebar),
    onClick: onClick
  }, /*#__PURE__*/React.createElement(Inline, {
    space: "space.075",
    alignBlock: "center",
    xcss: cx(logoWrapperStyles.root, fg('navx-full-height-sidebar') && logoWrapperStyles.fullHeightSidebar)
  }, /*#__PURE__*/React.createElement("div", {
    className: ax([iconContainerStyles.root, fg('navx-full-height-sidebar') && iconContainerStyles.fullHeightSidebar])
  }, /*#__PURE__*/React.createElement(LogoRenderer
  // Top nav always uses the new logo design
  , {
    shouldUseNewLogoDesign: true,
    logoOrIcon: icon
  })), /*#__PURE__*/React.createElement("span", {
    className: ax([logoTextStyles.root])
  }, /*#__PURE__*/React.createElement(Tooltip, {
    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
  }, tooltipProps => /*#__PURE__*/React.createElement("span", tooltipProps, /*#__PURE__*/React.createElement(Text, {
    "aria-hidden": true,
    color: "inherit",
    weight: "semibold",
    maxLines: 1,
    ref: nameRef
  }, name))))));
};