/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _typeof from "@babel/runtime/helpers/typeof";
import _extends from "@babel/runtime/helpers/extends";
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
/* eslint-disable @compiled/shorthand-property-sorting */
/* eslint-disable @atlaskit/design-system/use-tokens-typography */
/* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */

import { useMemo } from 'react';
import LinkIcon from '@atlaskit/icon/core/link';
import { fg } from '@atlaskit/platform-feature-flags';
import { Box } from '@atlaskit/primitives/compiled';
import Tile from '@atlaskit/tile';
import { SmartLinkPosition, SmartLinkSize } from '../../../../../../constants';
import { isProfileType } from '../../../../../../utils';
import { isNewBlockcardUnauthorizedRefreshExperimentEnabled } from '../../../../../../utils/experiments';
import AtlaskitIcon from '../../../common/atlaskit-icon';
import ImageIcon from '../../../common/image-icon';
import { getIconWidth } from '../../../utils';
var styles = {
  container: "_1ul91ns9",
  iconWrapperStyle: "_1e0c1txw _4cvr1h6o _1bah1h6o"
};
var positionStyleMap = {
  center: "_1wpz1h6o",
  top: "_19pkidpf _2hwxidpf _otyridpf _18u0idpf _1wpz1y6m"
};
var customRenderStyleMap = {
  xlarge: "_1reo15vq _18m915vq _11c810sd _1e0ccj1k _1nmz1hna _1yyjkb7n _y3gn1h6o _1btozryt _sudpn7od _1ipkidpf _1kdcidpf _3glyidpf _1w2uidpf _1oh2idpf _99ztidpf _1m2uidpf _9n9oidpf _e4km1q9y _1xjx1osq _e2oo1osq _102kz42d",
  large: "_1reo15vq _18m915vq _11c810sd _1e0ccj1k _1nmz1hna _1yyjkb7n _y3gn1h6o _1btozryt _sudpn7od _1ipkidpf _1kdcidpf _3glyidpf _1w2uidpf _1oh2idpf _99ztidpf _1m2uidpf _9n9oidpf _e4km1q9y _1xjx1osq _e2oo1osq _102kz42d",
  medium: "_1reo15vq _18m915vq _11c81e3o _1e0ccj1k _1nmz1hna _1yyjkb7n _y3gn1h6o _1btozryt _sudpn7od _1ipkidpf _1kdcidpf _3glyidpf _1w2uidpf _1oh2idpf _99ztidpf _1m2uidpf _9n9oidpf _e4km1q9y _1xjx1osq _e2oo1osq _102kptym",
  small: "_1reo15vq _18m915vq _11c81e3o _1e0ccj1k _1nmz1hna _1yyjkb7n _y3gn1h6o _1btozryt _sudpn7od _1ipkidpf _1kdcidpf _3glyidpf _1w2uidpf _1oh2idpf _99ztidpf _1m2uidpf _9n9oidpf _e4km1q9y _1xjx1osq _e2oo1osq _102kptym"
};
var renderAtlaskitIcon = function renderAtlaskitIcon(icon, testId) {
  var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : SmartLinkSize.Medium;
  var label = arguments.length > 3 ? arguments[3] : undefined;
  if (icon) {
    return /*#__PURE__*/React.createElement(AtlaskitIcon, _extends({
      icon: icon,
      testId: "".concat(testId, "-icon")
    }, fg('platform_navx_smart_link_icon_label_a11y') ? {
      label: label
    } : {
      'aria-hidden': true,
      label: ''
    }, {
      size: size
    }));
  }
};
var renderDefaultIcon = function renderDefaultIcon(label, testId) {
  return /*#__PURE__*/React.createElement(LinkIcon, {
    label: label,
    testId: "".concat(testId, "-default"),
    color: "currentColor"
  });
};
var renderImageIcon = function renderImageIcon(defaultIcon, url, testId) {
  var size = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : SmartLinkSize.Medium;
  var appearance = arguments.length > 4 ? arguments[4] : undefined;
  var hideLoadingSkeleton = arguments.length > 5 ? arguments[5] : undefined;
  var label = arguments.length > 6 ? arguments[6] : undefined;
  var width = size === SmartLinkSize.Large ? "var(--ds-space-300, 24px)" : "var(--ds-space-200, 16px)";
  if (url) {
    return /*#__PURE__*/React.createElement(ImageIcon, _extends({}, fg('platform_navx_smart_link_icon_label_a11y') ? {
      label: label
    } : {}, {
      defaultIcon: defaultIcon,
      testId: testId,
      url: url,
      width: width,
      height: width,
      appearance: appearance,
      hideLoadingSkeleton: hideLoadingSkeleton
    }));
  }
};

/**
 * A base element that displays an Icon or favicon.
 * @internal
 * @param props - The props necessary for the Icon element.
 * @see LinkIcon
 */
var IconElement = function IconElement(_ref) {
  var icon = _ref.icon,
    overrideIcon = _ref.overrideIcon,
    labelProp = _ref.label,
    name = _ref.name,
    _ref$position = _ref.position,
    position = _ref$position === void 0 ? SmartLinkPosition.Top : _ref$position,
    className = _ref.className,
    render = _ref.render,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? SmartLinkSize.Medium : _ref$size,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-element-icon' : _ref$testId,
    url = _ref.url,
    _ref$appearance = _ref.appearance,
    appearance = _ref$appearance === void 0 ? 'square' : _ref$appearance,
    hideLoadingSkeleton = _ref.hideLoadingSkeleton,
    isTiledIcon = _ref.isTiledIcon;
  var label = fg('platform_navx_smart_link_icon_label_a11y') ? labelProp !== null && labelProp !== void 0 ? labelProp : '' : labelProp !== null && labelProp !== void 0 ? labelProp : 'Link';
  var element = useMemo(function () {
    var defaultIcon = renderDefaultIcon(label, testId);
    return overrideIcon || (render === null || render === void 0 ? void 0 : render()) || renderImageIcon(defaultIcon, url, testId, size, appearance, hideLoadingSkeleton, fg('platform_navx_smart_link_icon_label_a11y') ? label : undefined) || renderAtlaskitIcon(icon, testId, size, fg('platform_navx_smart_link_icon_label_a11y') ? label : undefined) || defaultIcon;
  }, [label, testId, overrideIcon, render, url, size, appearance, hideLoadingSkeleton, icon]);
  var width = getIconWidth(size);
  return /*#__PURE__*/React.createElement("div", {
    "data-smart-element": name,
    "data-smart-element-icon": true,
    "data-testid": testId
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    ,
    className: ax([styles.container, positionStyleMap[position], render && customRenderStyleMap[size], className])
  }, isTiledIcon && isNewBlockcardUnauthorizedRefreshExperimentEnabled() ? /*#__PURE__*/React.createElement(Tile, {
    size: size,
    label: label
  }, element) : /*#__PURE__*/React.createElement(Box, {
    xcss: styles.iconWrapperStyle,
    style: {
      width: width,
      height: width
    }
  }, element));
};
export default IconElement;
export var toLinkIconProps = function toLinkIconProps(data, type) {
  var isDataLinkIcon = function isDataLinkIcon(_data) {
    return _typeof(_data) === 'object' && _data !== null && ('icon' in _data || 'url' in _data);
  };
  if (!isDataLinkIcon(data)) {
    return _typeof(data) === 'object' ? data : undefined;
  }
  var isImageRound = isProfileType(type);
  return _objectSpread(_objectSpread({}, data), {}, {
    appearance: isImageRound ? 'round' : 'square'
  });
};