"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Avatar = void 0;
const tslib_1 = require("tslib");
const components_1 = require("@bluebase/components");
const Avatar_1 = tslib_1.__importDefault(require("@material-ui/core/Avatar"));
const react_1 = tslib_1.__importDefault(require("react"));
const lodash_get_1 = tslib_1.__importDefault(require("lodash.get"));
const core_1 = require("@material-ui/core");
const core_2 = require("@bluebase/core");
const useStyles = core_1.makeStyles({
    root: (props) => {
        const { textStyle, style } = props;
        const size = lodash_get_1.default(props, 'size', 56);
        return Object.assign(Object.assign(Object.assign({}, style), textStyle), { fontSize: size * 0.6, height: size, width: size });
    },
    colorDefault: ({ color }) => ({
        color,
    }),
});
exports.Avatar = (props) => {
    const _a = props, { type, icon, size, image, text } = _a, rest = tslib_1.__rest(_a, ["type", "icon", "size", "image", "text"]);
    const { theme } = core_2.useTheme();
    const classes = useStyles(props);
    const style = props.style;
    const variant = props.variant === 'circle' ? 'circular' : props.variant;
    const color = props.color || theme.palette.background.default;
    if (type === 'icon') {
        return (react_1.default.createElement(Avatar_1.default, Object.assign({ classes: classes }, rest, { variant: variant, style: style }),
            react_1.default.createElement(components_1.Icon, { name: icon, color: color, size: size && size * 0.6 })));
    }
    if (type === 'image') {
        return (react_1.default.createElement(Avatar_1.default, Object.assign({ classes: classes }, rest, { variant: variant, style: style }),
            react_1.default.createElement(components_1.BlueBaseImage, { source: image, style: [{ height: size, width: size }, style] })));
    }
    return (react_1.default.createElement(Avatar_1.default, Object.assign({ classes: classes }, rest, { variant: variant, style: Object.assign(Object.assign({}, style), { color }) }), text));
};
exports.Avatar.defaultProps = components_1.AvatarDefaultProps;
