/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
/* 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 ImageIcon from '../../../../../common/image-icon';
import AtlaskitIcon from '../../../common/atlaskit-icon';
import { getIconWidth } from '../../../utils';
const styles = {
  container: "_1ul91ns9",
  iconWrapperStyle: "_1e0c1txw _4cvr1h6o _1bah1h6o"
};
const positionStyleMap = {
  center: "_1wpz1h6o",
  top: "_19pkidpf _2hwxidpf _otyridpf _18u0idpf _1wpz1y6m"
};
const 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"
};
const renderAtlaskitIcon = (icon, testId, size = SmartLinkSize.Medium, label, isTiledIcon) => {
  if (icon) {
    return /*#__PURE__*/React.createElement(AtlaskitIcon, _extends({
      icon: icon,
      testId: `${testId}-icon`
    }, fg('platform_navx_smart_link_icon_label_a11y') ? {
      label
    } : {
      'aria-hidden': true,
      label: ''
    }, {
      size: size,
      isTiledIcon: isTiledIcon
    }));
  }
};
const renderDefaultIcon = (label, testId) => /*#__PURE__*/React.createElement(LinkIcon, {
  label: label,
  testId: `${testId}-default`,
  color: "currentColor"
});
const widthFromSize = (size, isTiledIcon) => {
  switch (size) {
    case SmartLinkSize.XLarge:
      return "var(--ds-space-300, 24px)";
    case SmartLinkSize.Large:
      return "var(--ds-space-300, 24px)";
    case SmartLinkSize.Medium:
      return isTiledIcon ? "var(--ds-space-250, 20px)" : "var(--ds-space-200, 16px)";
    case SmartLinkSize.Small:
      return "var(--ds-space-200, 16px)";
    default:
      return "var(--ds-space-200, 16px)";
  }
};
const renderImageIcon = (defaultIcon, url, testId, size = SmartLinkSize.Medium, appearance, hideLoadingSkeleton, label) => {
  const 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
    } : {}, {
      defaultIcon: defaultIcon,
      testId: testId,
      url: url,
      width: width,
      height: width,
      appearance: appearance,
      hideLoadingSkeleton: hideLoadingSkeleton
    }));
  }
};
const renderImageIconNew = (defaultIcon, url, testId, size = SmartLinkSize.Medium, appearance, hideLoadingSkeleton, label, isTiledIcon = false) => {
  const width = widthFromSize(size, isTiledIcon);
  if (url) {
    return /*#__PURE__*/React.createElement(ImageIcon, _extends({}, fg('platform_navx_smart_link_icon_label_a11y') ? {
      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
 */
const IconElement = ({
  icon,
  overrideIcon,
  label: labelProp,
  name,
  position = SmartLinkPosition.Top,
  className,
  render,
  size = SmartLinkSize.Medium,
  testId = 'smart-element-icon',
  url,
  appearance = 'square',
  hideLoadingSkeleton,
  isTiledIcon
}) => {
  const label = fg('platform_navx_smart_link_icon_label_a11y') ? labelProp !== null && labelProp !== void 0 ? labelProp : '' : labelProp !== null && labelProp !== void 0 ? labelProp : 'Link';
  const element = useMemo(() => {
    const defaultIcon = renderDefaultIcon(label, testId);
    return overrideIcon || (render === null || render === void 0 ? void 0 : render()) || (fg('platform_sl_3p_preauth_better_hovercard_killswitch') ? renderImageIconNew(defaultIcon, url, testId, size, appearance, hideLoadingSkeleton, fg('platform_navx_smart_link_icon_label_a11y') ? label : undefined, isTiledIcon) : 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, isTiledIcon) || defaultIcon;
  }, [label, testId, overrideIcon, render, url, size, appearance, hideLoadingSkeleton, icon, isTiledIcon]);
  const 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 ? /*#__PURE__*/React.createElement(Tile, {
    size: size,
    hasBorder: true,
    backgroundColor: "white",
    label: label,
    testId: `${testId}-tile`
  }, element) : /*#__PURE__*/React.createElement(Box, {
    xcss: styles.iconWrapperStyle,
    testId: `${testId}-box`,
    style: {
      width,
      height: width
    }
  }, element));
};
export default IconElement;
export const toLinkIconProps = (data, type) => {
  const isDataLinkIcon = _data => {
    return typeof _data === 'object' && _data !== null && ('icon' in _data || 'url' in _data);
  };
  if (!isDataLinkIcon(data)) {
    return typeof data === 'object' ? data : undefined;
  }
  const isImageRound = isProfileType(type);
  return {
    ...data,
    appearance: isImageRound ? 'round' : 'square'
  };
};