/* index.tsx generated by @compiled/babel-plugin v0.38.1 */
/* eslint-disable @compiled/shorthand-property-sorting */
/* eslint-disable @atlaskit/design-system/use-tokens-typography */
/* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useMemo } from 'react';
import LinkIcon from '@atlaskit/icon/core/link';
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';
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) => {
  if (icon) {
    return /*#__PURE__*/React.createElement(AtlaskitIcon, {
      icon: icon,
      testId: `${testId}-icon`,
      "aria-hidden": "true",
      label: "" // Since we already set aria-hidden="true", the label should be given an empty string
      ,
      size: size
    });
  }
};
const renderDefaultIcon = (label, testId) => /*#__PURE__*/React.createElement(LinkIcon, {
  label: label,
  testId: `${testId}-default`,
  color: "currentColor"
});
const renderImageIcon = (defaultIcon, url, testId, size = SmartLinkSize.Medium, appearance, hideLoadingSkeleton) => {
  const width = size === SmartLinkSize.Large ? "var(--ds-space-300, 24px)" : "var(--ds-space-200, 16px)";
  if (url) {
    return /*#__PURE__*/React.createElement(ImageIcon, {
      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 = 'Link',
  name,
  position = SmartLinkPosition.Top,
  className,
  render,
  size = SmartLinkSize.Medium,
  testId = 'smart-element-icon',
  url,
  appearance = 'square',
  hideLoadingSkeleton,
  isTiledIcon
}) => {
  const element = useMemo(() => {
    const defaultIcon = renderDefaultIcon(label, testId);
    return overrideIcon || (render === null || render === void 0 ? void 0 : render()) || renderImageIcon(defaultIcon, url, testId, size, appearance, hideLoadingSkeleton) || renderAtlaskitIcon(icon, testId, size) || defaultIcon;
  }, [label, testId, overrideIcon, render, url, size, appearance, hideLoadingSkeleton, icon]);
  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 && isNewBlockcardUnauthorizedRefreshExperimentEnabled() ? /*#__PURE__*/React.createElement(Tile, {
    size: size,
    label: label
  }, element) : /*#__PURE__*/React.createElement(Box, {
    xcss: styles.iconWrapperStyle,
    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'
  };
};