"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = __importStar(require("react"));
const classnames_1 = __importDefault(require("classnames"));
const emoji_1 = __importDefault(require("../../utils/emoji"));
class Reaction extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
        this.onClick = this.onClick.bind(this);
    }
    render() {
        const messageReactionClasses = classnames_1.default('message-reaction', {
            'message-reaction--active': this.props.isClicked
        });
        return (React.createElement("div", { className: messageReactionClasses, onClick: this.onClick },
            React.createElement("span", { className: "message-reaction__emoji", dangerouslySetInnerHTML: { __html: emoji_1.default.toImage(this.props.emoji) } }),
            React.createElement("span", { className: "message-reaction__count" }, this.props.count)));
    }
    onClick() {
        this.props.onClick(this.props.emoji);
    }
}
class Reactions extends React.Component {
    constructor(props) {
        super(props);
        this.mapReactionsToiew = this.mapReactionsToiew.bind(this);
        this.onReactionClick = this.onReactionClick.bind(this);
        this.state = {};
    }
    render() {
        return React.createElement("div", { className: "message-reactions" }, this.props.reactions.map(this.mapReactionsToiew));
    }
    mapReactionsToiew(reaction, idx) {
        let { emoji, count } = reaction;
        let isClicked = false;
        if (this.state[emoji]) {
            count = parseInt(count, 10) + 1;
            isClicked = true;
        }
        return (React.createElement(Reaction, { key: reaction.emoji, onClick: this.onReactionClick, emoji: emoji, count: count, isClicked: isClicked }));
    }
    onReactionClick(emoji) {
        if (!this.state[emoji])
            this.setState({ [emoji]: 1 });
        delete this.state[emoji];
        this.setState(Object.assign({}, this.state));
    }
}
exports.default = Reactions;
//# sourceMappingURL=Reactions.js.map