/** @jsx jsx */
import { useCallback } from 'react';
import { css, jsx } from '@emotion/react';
import classnames from 'classnames';
import { N0, N30, N300, N500 } from '@atlaskit/theme/colors';
const labelStyles = css({
  opacity: 0,
  display: 'inline-flex',
  width: 'max-content',
  justifyContent: 'left',
  position: 'absolute',
  // Unfortunately, these need to be these exact numbers - otherwise there will be a noticeable gap/overlap
  // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
  top: '-19px',
  '&.inline': {
    // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
    top: '-17px',
    marginLeft: "var(--ds-space-150, 12px)"
  },
  '&.show-label': {
    cursor: 'pointer',
    background: `var(--ds-background-accent-gray-subtle-pressed, ${N300})`,
    color: `var(--ds-text-subtle, ${N500})`,
    opacity: 1
  },
  borderRadius: `${"var(--ds-border-radius, 3px)"} ${"var(--ds-border-radius, 3px)"} 0 0`,
  lineHeight: 1,
  '&.nested': {
    // Need to add indent if the node is nested since we removed previous indentation styles to make it fit properly
    // in the nested component
    marginLeft: "var(--ds-space-150, 12px)"
  },
  '&.bodied-background': {
    background: `var(--ds-surface, ${N0})`
  },
  '&.bodied-border': {
    border: `1px solid ${`var(--ds-border, ${N30})`}`
  },
  // to account for bodied having borders now - adding this to help with less conditional styling
  border: '1px solid transparent',
  borderBottom: 'none'
});
const textStyles = css({
  fontSize: '14px',
  fontWeight: 'normal',
  padding: `${"var(--ds-space-025, 2px)"} ${"var(--ds-space-050, 4px)"}`
});
export const ExtensionLabel = ({
  text,
  extensionName,
  isNodeHovered,
  customContainerStyles,
  isNodeNested,
  setIsNodeHovered,
  isBodiedMacro
}) => {
  const classNames = classnames('extension-title', 'extension-label', {
    nested: isNodeNested,
    inline: extensionName === 'inlineExtension',
    bodied: isBodiedMacro,
    'bodied-border': isBodiedMacro && !isNodeHovered,
    'bodied-background': isBodiedMacro && !isNodeHovered,
    'show-label': isNodeHovered || isBodiedMacro
  });
  const handleMouseEnter = useCallback(() => {
    // If current node is hovered and the label is hovered,
    // consider the node as hovered so we can display the label for users to click on
    if (isNodeHovered) {
      setIsNodeHovered === null || setIsNodeHovered === void 0 ? void 0 : setIsNodeHovered(true);
    }
  }, [isNodeHovered, setIsNodeHovered]);
  const handleMouseLeave = useCallback(() => {
    setIsNodeHovered === null || setIsNodeHovered === void 0 ? void 0 : setIsNodeHovered(false);
  }, [setIsNodeHovered]);
  return jsx("div", {
    style: customContainerStyles,
    onMouseEnter: handleMouseEnter,
    onMouseLeave: handleMouseLeave
  }, jsx("span", {
    "data-testid": "new-lozenge",
    css: labelStyles,
    className: classNames
  }, jsx("span", {
    css: textStyles
  }, text)));
};