function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
import { Avatar, theme } from "antd";
import classNames from "clsx";
import React from "react";
import { isEmoji } from "./isEmoji";
/**
 * @module Avatar
 * @description 头像组件，用于显示用户头像信息
 * @exports Avatar
 * @component
 *
 * @param {string} [avatar] - 头像图片的URL或base64数据
 * @param {string} [background] - 头像的背景颜色
 * @param {'circle' | 'square'} [shape='circle'] - 头像的形状，默认为圆形
 * @param {number} [size=40] - 头像的尺寸（像素）
 * @param {string} [title] - 如果未提供头像，则显示的标题文本
 * @param {string} [className] - 自定义的CSS类名
 * @param {Function} [onClick] - 点击头像时触发的回调函数
 * @param {Object} [style] - 自定义的行内样式
 * @param {Object} [props] - 其他传递给AntAvatar组件的属性
 *
 */ export var BubbleAvatar = function BubbleAvatar(_0) {
    var className = _0.className, avatar = _0.avatar, title = _0.title, _0_size = _0.size, size = _0_size === void 0 ? 24 : _0_size, _0_shape = _0.shape, shape = _0_shape === void 0 ? 'circle' : _0_shape, onClick = _0.onClick, prefixCls = _0.prefixCls, style = _0.style, props = _object_without_properties(_0, [
        "className",
        "avatar",
        "title",
        "size",
        "shape",
        "onClick",
        "prefixCls",
        "style"
    ]);
    var hashId = theme.useToken().hashId;
    var isImage = Boolean(avatar && [
        '/',
        'http',
        'data:'
    ].some(function(index) {
        return avatar.startsWith(index);
    }));
    var isBase64 = Boolean(avatar === null || avatar === void 0 ? void 0 : avatar.startsWith('data'));
    if (typeof avatar === 'string' && isEmoji(String(avatar))) {
        return /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-emoji"), hashId)
        }, avatar);
    }
    var text = String(isImage ? title : avatar);
    var avatarProps = {
        className: classNames(className, "".concat(prefixCls), hashId),
        shape: shape,
        size: size,
        style: onClick ? style : _object_spread({
            cursor: 'default'
        }, style)
    };
    return isImage ? /*#__PURE__*/ React.createElement(Avatar, _object_spread_props(_object_spread({
        src: isBase64 ? avatar : /*#__PURE__*/ React.createElement("img", {
            src: avatar,
            alt: "avatar"
        })
    }, avatarProps, props), {
        onClick: onClick,
        "data-testid": "bubble-avatar"
    })) : /*#__PURE__*/ React.createElement(Avatar, _object_spread_props(_object_spread({}, avatarProps, props), {
        onClick: onClick,
        "data-testid": "bubble-avatar"
    }), text === null || text === void 0 ? void 0 : text.toUpperCase().slice(0, 2));
};
