import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
import { fg } from '@atlaskit/platform-feature-flags';
import { ElementName } from '../../../../../constants';
import { useFlexibleUiContext } from '../../../../../state/flexible-ui-context';
import { BaseIconElement, toLinkIconProps } from '../common';
import { resourceTypeToLabel } from './resourceTypeToLabel';
var LinkIconElement = function LinkIconElement(props) {
  var context = useFlexibleUiContext();
  if (!context) {
    return null;
  }
  if (fg('platform_navx_smart_link_icon_label_a11y')) {
    var _ref, _resourceTypeToLabel, _context$meta, _linkIconProps$label;
    var linkIconProps = toLinkIconProps(context === null || context === void 0 ? void 0 : context.linkIcon, context.type);
    if (!linkIconProps) {
      return null;
    }
    var label = (_ref = (_resourceTypeToLabel = resourceTypeToLabel((_context$meta = context.meta) === null || _context$meta === void 0 ? void 0 : _context$meta.resourceType)) !== null && _resourceTypeToLabel !== void 0 ? _resourceTypeToLabel : (_linkIconProps$label = linkIconProps.label) === null || _linkIconProps$label === void 0 ? void 0 : _linkIconProps$label.trim()) !== null && _ref !== void 0 ? _ref : props.label;
    return /*#__PURE__*/React.createElement(BaseIconElement, _extends({}, linkIconProps, props, {
      label: label,
      name: ElementName.LinkIcon
    }));
  }
  var data = toLinkIconProps(context === null || context === void 0 ? void 0 : context.linkIcon, context.type);
  return data ? /*#__PURE__*/React.createElement(BaseIconElement, _extends({}, data, props, {
    name: ElementName.LinkIcon
  })) : null;
};
export default LinkIconElement;