/* index.tsx generated by @compiled/babel-plugin v0.38.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof3 = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toLinkIconProps = exports.default = void 0;
require("./index.compiled.css");
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _runtime = require("@compiled/react/runtime");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _link = _interopRequireDefault(require("@atlaskit/icon/core/link"));
var _compiled = require("@atlaskit/primitives/compiled");
var _tile = _interopRequireDefault(require("@atlaskit/tile"));
var _constants = require("../../../../../../constants");
var _utils = require("../../../../../../utils");
var _experiments = require("../../../../../../utils/experiments");
var _atlaskitIcon = _interopRequireDefault(require("../../../common/atlaskit-icon"));
var _imageIcon = _interopRequireDefault(require("../../../common/image-icon"));
var _utils2 = require("../../../utils");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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) { (0, _defineProperty2.default)(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 */
var styles = {
  container: "_1ul91ns9",
  iconWrapperStyle: "_1e0c1txw _4cvr1h6o _1bah1h6o"
};
var positionStyleMap = {
  center: "_1wpz1h6o",
  top: "_19pkidpf _2hwxidpf _otyridpf _18u0idpf _1wpz1y6m"
};
var customRenderStyleMap = {
  xlarge: "_1reo15vq _18m915vq _11c8nf1z _1e0ccj1k _1nmz1hna _1yyjkb7n _y3gn1h6o _1btozryt _sudpn7od _1ipkidpf _1kdcidpf _3glyidpf _1w2uidpf _1oh2idpf _99ztidpf _1m2uidpf _9n9oidpf _e4km1q9y _1xjx1osq _e2oo1osq _102kz42d",
  large: "_1reo15vq _18m915vq _11c8nf1z _1e0ccj1k _1nmz1hna _1yyjkb7n _y3gn1h6o _1btozryt _sudpn7od _1ipkidpf _1kdcidpf _3glyidpf _1w2uidpf _1oh2idpf _99ztidpf _1m2uidpf _9n9oidpf _e4km1q9y _1xjx1osq _e2oo1osq _102kz42d",
  medium: "_1reo15vq _18m915vq _11c8nbxd _1e0ccj1k _1nmz1hna _1yyjkb7n _y3gn1h6o _1btozryt _sudpn7od _1ipkidpf _1kdcidpf _3glyidpf _1w2uidpf _1oh2idpf _99ztidpf _1m2uidpf _9n9oidpf _e4km1q9y _1xjx1osq _e2oo1osq _102kptym",
  small: "_1reo15vq _18m915vq _11c8nbxd _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] : _constants.SmartLinkSize.Medium;
  if (icon) {
    return /*#__PURE__*/React.createElement(_atlaskitIcon.default, {
      icon: icon,
      testId: "".concat(testId, "-icon"),
      "aria-hidden": "true",
      label: "" // Since we already set aria-hidden="true", the label should be given an empty string
      ,
      size: size
    });
  }
};
var renderDefaultIcon = function renderDefaultIcon(label, testId) {
  return /*#__PURE__*/React.createElement(_link.default, {
    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] : _constants.SmartLinkSize.Medium;
  var appearance = arguments.length > 4 ? arguments[4] : undefined;
  var hideLoadingSkeleton = arguments.length > 5 ? arguments[5] : undefined;
  var width = size === _constants.SmartLinkSize.Large ? "var(--ds-space-300, 24px)" : "var(--ds-space-200, 16px)";
  if (url) {
    return /*#__PURE__*/React.createElement(_imageIcon.default, {
      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,
    _ref$label = _ref.label,
    label = _ref$label === void 0 ? 'Link' : _ref$label,
    name = _ref.name,
    _ref$position = _ref.position,
    position = _ref$position === void 0 ? _constants.SmartLinkPosition.Top : _ref$position,
    className = _ref.className,
    render = _ref.render,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? _constants.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 element = (0, _react.useMemo)(function () {
    var 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]);
  var width = (0, _utils2.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: (0, _runtime.ax)([styles.container, positionStyleMap[position], render && customRenderStyleMap[size], className])
  }, isTiledIcon && (0, _experiments.isNewBlockcardUnauthorizedRefreshExperimentEnabled)() ? /*#__PURE__*/React.createElement(_tile.default, {
    size: size,
    label: label
  }, element) : /*#__PURE__*/React.createElement(_compiled.Box, {
    xcss: styles.iconWrapperStyle,
    style: {
      width: width,
      height: width
    }
  }, element));
};
var _default = exports.default = IconElement;
var toLinkIconProps = exports.toLinkIconProps = function toLinkIconProps(data, type) {
  var isDataLinkIcon = function isDataLinkIcon(_data) {
    return (0, _typeof2.default)(_data) === 'object' && _data !== null && ('icon' in _data || 'url' in _data);
  };
  if (!isDataLinkIcon(data)) {
    return (0, _typeof2.default)(data) === 'object' ? data : undefined;
  }
  var isImageRound = (0, _utils.isProfileType)(type);
  return _objectSpread(_objectSpread({}, data), {}, {
    appearance: isImageRound ? 'round' : 'square'
  });
};