function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { Component } from "react";
import { View } from "react-native";
import { getReactions, getUserPreview } from "../helper";
import { Reaction } from "./Reaction";
class Reactions extends Component {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "state", {
      reactions: getReactions()
    });
  }
  getReaction(key) {
    if (!this.props.entity) {
      return {};
    }
    if (!this.props.entity.Reactions) {
      this.props.entity.Reactions = {};
    }
    return this.props.entity.Reactions[key] || {};
  }
  onLike(key) {
    if (!this.props.entity.Reactions) {
      this.props.entity.Reactions = {};
    }
    if (!this.props.entity.Reactions[key]) {
      this.props.entity.Reactions[key] = {};
    }
    this.props.entity.Reactions[key][this.props.user.uid] = getUserPreview(this.props.user);
    this.props.onUpdateReactions();
  }
  onUnlike(key) {
    if (!this.props.entity.Reactions) {
      return;
    }
    if (!this.props.entity.Reactions[key]) {
      return;
    }
    delete this.props.entity.Reactions[key][this.props.user.uid];
    this.props.onUpdateReactions();
  }
  render() {
    return /*#__PURE__*/React.createElement(View, {
      style: [styles.container, this.props.style]
    }, this.state.reactions.map((r, i) => {
      return /*#__PURE__*/React.createElement(Reaction, {
        key: i,
        reaction: r,
        entityType: this.props.entityType,
        entityId: this.props.entityId,
        reactions: this.getReaction(r.key),
        anyHighlighted: this.props.anyHighlighted,
        userId: this.props.user.uid,
        onLike: this.onLike.bind(this, r.key),
        onUnlike: this.onUnlike.bind(this, r.key),
        site: this.props.site
      });
    }));
  }
}
const styles = {
  container: {
    flexDirection: "row",
    justifyContent: "center",
    width: "100%"
  }
};
export { Reactions };
//# sourceMappingURL=Reactions.js.map