/* eslint-disable @atlaskit/ui-styling-standard/use-compiled -- Pre-existing lint debt surfaced by this mechanical type-import-only PR. */
/**
 * @jsxRuntime classic
 * @jsx jsx
 */
import React, { forwardRef, Fragment, useCallback } from 'react';
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
import { css, jsx } from '@emotion/react';

// AFP-2532 TODO: Fix automatic suppressions below
// eslint-disable-next-line @atlassian/tangerine/import/entry-points

import { injectIntl } from 'react-intl';
import { relativeFontSizeToBase16 } from '@atlaskit/editor-shared-styles';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { getCorrectAltByIconUrl } from './listItemAlts';
import { transformTimeStamp } from './transformTimeStamp';
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
export const container = css({
  backgroundColor: 'transparent',
  padding: `${"var(--ds-space-100, 8px)"} ${"var(--ds-space-150, 12px)"}`,
  cursor: 'pointer',
  display: 'flex',
  marginTop: 0
});

// eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles, @atlaskit/volt-strict-mode/no-multiple-exports -- Ignored via go/DSP-18766
export const containerSelected = css({
  backgroundColor: "var(--ds-background-neutral-subtle-hovered, #0515240F)"
});
const nameWrapper = css({
  overflow: 'hidden'
});

// eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles, @atlaskit/volt-strict-mode/no-multiple-exports -- Ignored via go/DSP-18766
export const nameStyle = css({
  color: "var(--ds-text, #292A2E)",
  overflow: 'hidden',
  textOverflow: 'ellipsis',
  whiteSpace: 'nowrap',
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
  lineHeight: '20px'
});

// eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles, @atlaskit/volt-strict-mode/no-multiple-exports -- Ignored via go/DSP-18766
export const containerName = css({
  color: "var(--ds-text-subtlest, #6B6E76)",
  // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
  lineHeight: '14px',
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
  fontSize: relativeFontSizeToBase16(11)
});
const iconStyle = css({
  minWidth: '16px',
  marginTop: "var(--ds-space-050, 4px)",
  marginRight: "var(--ds-space-150, 12px)",
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
  img: {
    maxWidth: '16px'
  }
});
const LinkSearchListItem = (props, ref) => {
  const {
    id,
    item,
    onBlur,
    onFocus,
    onKeyDown,
    onMouseEnter,
    onMouseLeave,
    onMouseMove,
    onSelect,
    selected,
    intl
  } = props;
  const handleSelect = useCallback(e => {
    e.preventDefault(); // don't let editor lose focus
    onSelect(item.url, item.name);
  }, [onSelect, item.url, item.name]);
  const handleKeyDown = useCallback(event => {
    if (event.key === 'Enter') {
      onSelect(item.url, item.name);
    }
    onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
  }, [onSelect, onKeyDown, item.url, item.name]);
  const handleMouseMove = useCallback(() => {
    onMouseMove === null || onMouseMove === void 0 ? void 0 : onMouseMove(item.objectId);
  }, [onMouseMove, item.objectId]);
  const handleMouseEnter = useCallback(() => {
    onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(item.objectId);
  }, [onMouseEnter, item.objectId]);
  const handleMouseLeave = useCallback(() => {
    onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(item.objectId);
  }, [onMouseLeave, item.objectId]);
  const renderIcon = () => {
    if (item.icon) {
      return jsx("span", {
        css: iconStyle
      }, item.icon);
    }
    if (item.iconUrl) {
      return jsx("span", {
        css: iconStyle
      }, jsx("img", {
        src: item.iconUrl,
        alt: getCorrectAltByIconUrl(item.iconUrl, intl)
      }));
    }
    return null;
  };
  const renderTimeStamp = () => {
    const date = transformTimeStamp(intl, item.lastViewedDate, item.lastUpdatedDate);
    return date && jsx(Fragment, null, "\xA0 \u2022", jsx("span", {
      // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
      className: "link-search-timestamp",
      "data-testid": "link-search-timestamp"
    }, "\xA0 ", date.pageAction, " ", date.dateString, " ", date.timeSince || ''));
  };
  return jsx("div", {
    ref: ref,
    css: [container, selected && containerSelected],
    role: 'option',
    tabIndex: 0,
    id: id,
    "aria-selected": selected,
    "data-testid": "link-search-list-item",
    onBlur: expValEquals('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? onBlur : undefined,
    onFocus: onFocus,
    onKeyDown: handleKeyDown,
    onMouseMove: handleMouseMove,
    onMouseEnter: handleMouseEnter,
    onMouseLeave: handleMouseLeave,
    onClick: handleSelect
  }, renderIcon(), jsx("span", {
    css: nameWrapper
  }, jsx("div", {
    css: nameStyle
  }, item.name), jsx("div", {
    "data-testid": "link-search-list-item-container",
    css: containerName
  }, item.container, renderTimeStamp())));
};
const ForwardedLinkSearchListItem = /*#__PURE__*/forwardRef(LinkSearchListItem);

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export const ForwardedLinkSearchListItemWithIntl = injectIntl(ForwardedLinkSearchListItem, {
  forwardRef: true
});

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export default ForwardedLinkSearchListItemWithIntl;