"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const prop_types_1 = __importDefault(require("prop-types"));
const react_1 = __importDefault(require("react"));
const react_native_1 = require("react-native");
const GiftedAvatar_1 = __importDefault(require("./GiftedAvatar"));
const utils_1 = require("./utils");
const styles = {
    left: react_native_1.StyleSheet.create({
        container: {
            marginRight: 8,
        },
        onTop: {
            alignSelf: 'flex-start',
        },
        onBottom: {},
        image: {
            height: 36,
            width: 36,
            borderRadius: 18,
        },
    }),
    right: react_native_1.StyleSheet.create({
        container: {
            marginLeft: 8,
        },
        onTop: {
            alignSelf: 'flex-start',
        },
        onBottom: {},
        image: {
            height: 36,
            width: 36,
            borderRadius: 18,
        },
    }),
};
class Avatar extends react_1.default.Component {
    renderAvatar() {
        if (this.props.renderAvatar) {
            const _a = this.props, { renderAvatar } = _a, avatarProps = __rest(_a, ["renderAvatar"]);
            return this.props.renderAvatar(avatarProps);
        }
        if (this.props.currentMessage) {
            return (react_1.default.createElement(GiftedAvatar_1.default, { avatarStyle: [
                    styles[this.props.position].image,
                    this.props.imageStyle
                        && this.props.imageStyle[this.props.position],
                ], textStyle: this.props.textStyle ? this.props.textStyle : {}, user: this.props.currentMessage.user, onPress: () => this.props.onPressAvatar
                    && this.props.onPressAvatar(this.props.currentMessage.user), onLongPress: () => this.props.onLongPressAvatar
                    && this.props.onLongPressAvatar(this.props.currentMessage.user) }));
        }
        return null;
    }
    render() {
        const { renderAvatarOnTop, showAvatarForEveryMessage, containerStyle, position, currentMessage, renderAvatar, previousMessage, nextMessage, imageStyle, } = this.props;
        const messageToCompare = renderAvatarOnTop ? previousMessage : nextMessage;
        const computedStyle = renderAvatarOnTop ? 'onTop' : 'onBottom';
        if (renderAvatar === null) {
            return null;
        }
        if (!showAvatarForEveryMessage
            && currentMessage
            && messageToCompare
            && utils_1.isSameUser(currentMessage, messageToCompare)
            && utils_1.isSameDay(currentMessage, messageToCompare)) {
            return (react_1.default.createElement(react_native_1.View, { style: [
                    styles[position].container,
                    containerStyle && containerStyle[position],
                ] },
                react_1.default.createElement(GiftedAvatar_1.default, { avatarStyle: [
                        styles[position].image,
                        imageStyle && imageStyle[position],
                    ] })));
        }
        return (react_1.default.createElement(react_native_1.View, { style: [
                styles[position].container,
                styles[position][computedStyle],
                containerStyle && containerStyle[position],
            ] }, this.renderAvatar()));
    }
}
exports.default = Avatar;
Avatar.defaultProps = {
    renderAvatarOnTop: false,
    showAvatarForEveryMessage: false,
    position: 'left',
    currentMessage: {
        user: null,
    },
    previousMessage: {},
    nextMessage: {},
    containerStyle: {},
    imageStyle: {},
    onPressAvatar: () => { },
    onLongPressAvatar: () => { },
};
Avatar.propTypes = {
    renderAvatarOnTop: prop_types_1.default.bool,
    showAvatarForEveryMessage: prop_types_1.default.bool,
    position: prop_types_1.default.oneOf(['left', 'right']),
    currentMessage: prop_types_1.default.object,
    previousMessage: prop_types_1.default.object,
    nextMessage: prop_types_1.default.object,
    onPressAvatar: prop_types_1.default.func,
    onLongPressAvatar: prop_types_1.default.func,
    renderAvatar: prop_types_1.default.func,
    containerStyle: prop_types_1.default.shape({
        left: utils_1.StylePropType,
        right: utils_1.StylePropType,
    }),
    imageStyle: prop_types_1.default.shape({
        left: utils_1.StylePropType,
        right: utils_1.StylePropType,
    }),
};
//# sourceMappingURL=Avatar.js.map