"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Coin", {
    enumerable: true,
    get: function() {
        return Coin;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _css = require("../utils/css");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const Coin = (props)=>{
    const [url, setUrl] = _react.default.useState();
    (0, _react.useEffect)(()=>{
        const img = new Image();
        img.onload = function() {
            setUrl(img.src);
        };
        img.onerror = function() {};
        // crypto logos
        // https://cryptologos.cc/logos/
        // img.src = `https://cryptologos.cc/logos/${props.name.toLowerCase()}-${props.size}.png?v=010`;
        img.src = `https://oss.orderly.network/static/symbol_logo/${props.name.toUpperCase()}.png`;
    }, []);
    const icon = (0, _react.useMemo)(()=>{
        if (!url) {
            return null;
        }
        return /*#__PURE__*/ (0, _jsxruntime.jsx)("img", {
            src: url,
            alt: props.name
        });
    }, [
        url
    ]);
    const size = (0, _react.useMemo)(()=>{
        if (typeof props.size === "undefined") return "24px";
        if (props.size === "small") return "16px";
        if (props.size === "medium") return "24px";
        if (props.size === "large") return "32px";
        return `${props.size}px`;
    }, [
        props.size
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
        className: (0, _css.cn)("orderly-inline-block", props.className),
        style: {
            width: size,
            height: size,
            backgroundColor: props.backgroundColor
        },
        children: icon
    });
};

//# sourceMappingURL=coin.js.map