"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var CryptoIcon_exports = {};
__export(CryptoIcon_exports, {
  default: () => CryptoIcon_default,
  iconNames: () => iconNames
});
module.exports = __toCommonJS(CryptoIcon_exports);
var icons = __toESM(require("@ledgerhq/crypto-icons-ui/react"));
var import_react = __toESM(require("react"));
var import_styles = require("../../../styles");
var import_styled_components = __toESM(require("styled-components"));
var import_Text = __toESM(require("../Text/index"));
var import_Flex = __toESM(require("../../layout/Flex"));
const iconNames = Array.from(
  Object.keys(icons).reduce((set, rawKey) => {
    const key = rawKey;
    if (!set.has(key))
      set.add(key);
    return set;
  }, /* @__PURE__ */ new Set())
);
const Container = (0, import_styled_components.default)(import_Flex.default).attrs((p) => ({
  heigth: p.size,
  width: p.size,
  alignItems: "center",
  justifyContent: "center",
  position: "relative"
}))``;
const Circle = (0, import_styled_components.default)(import_Flex.default).attrs((p) => ({
  heigth: p.size,
  width: p.size,
  alignItems: "center",
  justifyContent: "center",
  position: "relative",
  borderRadius: "50%",
  backgroundColor: p.backgroundColor
}))``;
const TokenContainer = (0, import_styled_components.default)(import_Flex.default).attrs(
  (p) => ({
    position: "absolute",
    bottom: "-2px",
    right: "-5px",
    alignItems: "center",
    justifyContent: "center",
    heigth: p.size,
    width: p.size,
    borderRadius: "50%",
    border: `2px solid ${p.borderColor}`,
    backgroundColor: p.backgroundColor,
    zIndex: 0
  })
)``;
function Fallback({ name }) {
  return /* @__PURE__ */ import_react.default.createElement(import_Text.default, { uppercase: true, color: "neutral.c70" }, name.slice(0, 1));
}
const IconBox = ({
  children,
  color,
  backgroundColor,
  disabled,
  size = 16,
  tokenIcon = ""
}) => {
  const { colors } = (0, import_styled_components.useTheme)();
  if (tokenIcon in icons) {
    const Component = icons[tokenIcon];
    const defaultColor = Component.DefaultColor;
    const iconColor = disabled ? colors.neutral.c70 : color || defaultColor;
    const contrastedColor = (0, import_styles.ensureContrast)(iconColor, backgroundColor || colors.background.main);
    return /* @__PURE__ */ import_react.default.createElement(Container, { size }, children, tokenIcon && /* @__PURE__ */ import_react.default.createElement(
      TokenContainer,
      {
        size: size / 3,
        borderColor: colors.background.main,
        backgroundColor: contrastedColor
      },
      /* @__PURE__ */ import_react.default.createElement(Component, { size, color: colors.background.main })
    ));
  }
  return children;
};
const CryptoIcon = ({
  name,
  size = 16,
  color,
  backgroundColor,
  circleIcon,
  disabled,
  tokenIcon,
  fallbackIcon
}) => {
  const { colors } = (0, import_styled_components.useTheme)();
  const maybeIconName = `${name}`;
  if (maybeIconName in icons) {
    const Component = icons[maybeIconName];
    const defaultColor = Component.DefaultColor;
    const iconColor = disabled ? colors.neutral.c70 : color || defaultColor;
    const contrastedColor = (0, import_styles.ensureContrast)(iconColor, backgroundColor || colors.background.main);
    return /* @__PURE__ */ import_react.default.createElement(IconBox, { size, tokenIcon, color, disabled, name }, tokenIcon || circleIcon ? /* @__PURE__ */ import_react.default.createElement(Circle, { backgroundColor: contrastedColor, size }, /* @__PURE__ */ import_react.default.createElement(Component, { size, color: colors.background.main })) : /* @__PURE__ */ import_react.default.createElement(Component, { size, color: contrastedColor }));
  }
  if (fallbackIcon) {
    return fallbackIcon;
  }
  return /* @__PURE__ */ import_react.default.createElement(Fallback, { name });
};
var CryptoIcon_default = CryptoIcon;
//# sourceMappingURL=CryptoIcon.js.map
