"use strict";Object.defineProperty(exports, "__esModule", {value: true});



var _chunk4CV4JOE5js = require('./chunk-4CV4JOE5.js');

// __generated__/ReactionButton_target.graphql.ts
var ReactionButton_target_graphql_exports = {};
_chunk4CV4JOE5js.__export.call(void 0, ReactionButton_target_graphql_exports, {
  default: () => ReactionButton_target_graphql_default
});
var node, ReactionButton_target_graphql_default;
var init_ReactionButton_target_graphql = _chunk4CV4JOE5js.__esm.call(void 0, {
  "__generated__/ReactionButton_target.graphql.ts"() {
    "use strict";
    node = /* @__PURE__ */ function() {
      var v0 = {
        "alias": null,
        "args": null,
        "kind": "ScalarField",
        "name": "id",
        "storageKey": null
      };
      return {
        "argumentDefinitions": [],
        "kind": "Fragment",
        "metadata": null,
        "name": "ReactionButton_target",
        "selections": [
          v0,
          {
            "alias": null,
            "args": null,
            "concreteType": "ReactionsCount",
            "kind": "LinkedField",
            "name": "reactionsCount",
            "plural": false,
            "selections": [
              {
                "alias": null,
                "args": null,
                "kind": "ScalarField",
                "name": "total",
                "storageKey": null
              }
            ],
            "storageKey": null
          },
          {
            "alias": null,
            "args": null,
            "concreteType": "Reaction",
            "kind": "LinkedField",
            "name": "myReaction",
            "plural": false,
            "selections": [
              v0,
              {
                "alias": null,
                "args": null,
                "kind": "ScalarField",
                "name": "reactionType",
                "storageKey": null
              }
            ],
            "storageKey": null
          }
        ],
        "type": "ReactionsInterface",
        "abstractKey": "__isReactionsInterface"
      };
    }();
    node.hash = "c3861c327bdc15c2a59dfbfe2ce2ed12";
    ReactionButton_target_graphql_default = node;
  }
});

// __generated__/ReactionButtonMutation.graphql.ts
var ReactionButtonMutation_graphql_exports = {};
_chunk4CV4JOE5js.__export.call(void 0, ReactionButtonMutation_graphql_exports, {
  default: () => ReactionButtonMutation_graphql_default
});
var node2, ReactionButtonMutation_graphql_default;
var init_ReactionButtonMutation_graphql = _chunk4CV4JOE5js.__esm.call(void 0, {
  "__generated__/ReactionButtonMutation.graphql.ts"() {
    "use strict";
    node2 = /* @__PURE__ */ function() {
      var v0 = [
        {
          "defaultValue": null,
          "kind": "LocalArgument",
          "name": "input"
        }
      ], v1 = [
        {
          "kind": "Variable",
          "name": "input",
          "variableName": "input"
        }
      ], v2 = {
        "alias": null,
        "args": null,
        "kind": "ScalarField",
        "name": "id",
        "storageKey": null
      }, v3 = [
        v2,
        {
          "alias": null,
          "args": null,
          "kind": "ScalarField",
          "name": "reactionType",
          "storageKey": null
        }
      ], v4 = {
        "alias": null,
        "args": null,
        "concreteType": "ReactionEdge",
        "kind": "LinkedField",
        "name": "reaction",
        "plural": false,
        "selections": [
          {
            "alias": null,
            "args": null,
            "concreteType": "Reaction",
            "kind": "LinkedField",
            "name": "node",
            "plural": false,
            "selections": v3,
            "storageKey": null
          }
        ],
        "storageKey": null
      }, v5 = {
        "alias": null,
        "args": null,
        "kind": "ScalarField",
        "name": "reactionDeletedId",
        "storageKey": null
      };
      return {
        "fragment": {
          "argumentDefinitions": v0,
          "kind": "Fragment",
          "metadata": null,
          "name": "ReactionButtonMutation",
          "selections": [
            {
              "alias": null,
              "args": v1,
              "concreteType": "ReactionTogglePayload",
              "kind": "LinkedField",
              "name": "reactionToggle",
              "plural": false,
              "selections": [
                v4,
                v5,
                {
                  "alias": null,
                  "args": null,
                  "concreteType": null,
                  "kind": "LinkedField",
                  "name": "target",
                  "plural": false,
                  "selections": [
                    v2,
                    {
                      "args": null,
                      "kind": "FragmentSpread",
                      "name": "ReactionButton_target"
                    }
                  ],
                  "storageKey": null
                }
              ],
              "storageKey": null
            }
          ],
          "type": "Mutation",
          "abstractKey": null
        },
        "kind": "Request",
        "operation": {
          "argumentDefinitions": v0,
          "kind": "Operation",
          "name": "ReactionButtonMutation",
          "selections": [
            {
              "alias": null,
              "args": v1,
              "concreteType": "ReactionTogglePayload",
              "kind": "LinkedField",
              "name": "reactionToggle",
              "plural": false,
              "selections": [
                v4,
                v5,
                {
                  "alias": null,
                  "args": null,
                  "filters": null,
                  "handle": "deleteRecord",
                  "key": "",
                  "kind": "ScalarHandle",
                  "name": "reactionDeletedId"
                },
                {
                  "alias": null,
                  "args": null,
                  "concreteType": null,
                  "kind": "LinkedField",
                  "name": "target",
                  "plural": false,
                  "selections": [
                    {
                      "alias": null,
                      "args": null,
                      "kind": "ScalarField",
                      "name": "__typename",
                      "storageKey": null
                    },
                    v2,
                    {
                      "kind": "TypeDiscriminator",
                      "abstractKey": "__isReactionsInterface"
                    },
                    {
                      "alias": null,
                      "args": null,
                      "concreteType": "ReactionsCount",
                      "kind": "LinkedField",
                      "name": "reactionsCount",
                      "plural": false,
                      "selections": [
                        {
                          "alias": null,
                          "args": null,
                          "kind": "ScalarField",
                          "name": "total",
                          "storageKey": null
                        }
                      ],
                      "storageKey": null
                    },
                    {
                      "alias": null,
                      "args": null,
                      "concreteType": "Reaction",
                      "kind": "LinkedField",
                      "name": "myReaction",
                      "plural": false,
                      "selections": v3,
                      "storageKey": null
                    }
                  ],
                  "storageKey": null
                }
              ],
              "storageKey": null
            }
          ]
        },
        "params": {
          "cacheID": "10b1f38991c6795cddbb1a4cf30f2286",
          "id": null,
          "metadata": {},
          "name": "ReactionButtonMutation",
          "operationKind": "mutation",
          "text": "mutation ReactionButtonMutation(\n  $input: ReactionToggleInput!\n) {\n  reactionToggle(input: $input) {\n    reaction {\n      node {\n        id\n        reactionType\n      }\n    }\n    reactionDeletedId\n    target {\n      __typename\n      id\n      ...ReactionButton_target\n    }\n  }\n}\n\nfragment ReactionButton_target on ReactionsInterface {\n  __isReactionsInterface: __typename\n  id\n  reactionsCount {\n    total\n  }\n  myReaction {\n    id\n    reactionType\n  }\n}\n"
        }
      };
    }();
    node2.hash = "5b17c14ee951ae101017eb3ee7e12e5c";
    ReactionButtonMutation_graphql_default = node2;
  }
});

// tmp-babel/__shared__/web/ReactionButton/index.js
var _authentication = require('@baseapp-frontend/authentication');
var _reactrelay = require('react-relay');
var _ReactionButton_target;
var _ReactionButtonMutation;
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e, n, i, u, a = [], f = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var fragmentQuery = _ReactionButton_target !== void 0 ? _ReactionButton_target : (_ReactionButton_target = (init_ReactionButton_target_graphql(), _chunk4CV4JOE5js.__toCommonJS.call(void 0, ReactionButton_target_graphql_exports)), _ReactionButton_target.hash && _ReactionButton_target.hash !== "c3861c327bdc15c2a59dfbfe2ce2ed12" && console.error("The definition of 'ReactionButton_target' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _ReactionButton_target);
var mutationQuery = _ReactionButtonMutation !== void 0 ? _ReactionButtonMutation : (_ReactionButtonMutation = (init_ReactionButtonMutation_graphql(), _chunk4CV4JOE5js.__toCommonJS.call(void 0, ReactionButtonMutation_graphql_exports)), _ReactionButtonMutation.hash && _ReactionButtonMutation.hash !== "5b17c14ee951ae101017eb3ee7e12e5c" && console.error("The definition of 'ReactionButtonMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _ReactionButtonMutation);
var ReactionButton = function ReactionButton2(_ref) {
  var targetRef = _ref.target, reactionType = _ref.reactionType, children = _ref.children, handleSuccess = _ref.handleSuccess, handleError = _ref.handleError;
  var target = _reactrelay.useFragment.call(void 0, fragmentQuery, targetRef);
  var _useMutation = _reactrelay.useMutation.call(void 0, mutationQuery), _useMutation2 = _slicedToArray(_useMutation, 2), commitMutation = _useMutation2[0], isMutationInFlight = _useMutation2[1];
  var _useCurrentProfile = _authentication.useCurrentProfile.call(void 0, ), currentProfile = _useCurrentProfile.currentProfile;
  var handleReaction = function handleReaction2() {
    var _target$reactionsCoun, _target$reactionsCoun2, _target$myReaction, _target$myReaction2, _target$myReaction3;
    if (isMutationInFlight) {
      return;
    }
    var currentReactionsCount = (_target$reactionsCoun = (_target$reactionsCoun2 = target.reactionsCount) === null || _target$reactionsCoun2 === void 0 ? void 0 : _target$reactionsCoun2.total) !== null && _target$reactionsCoun !== void 0 ? _target$reactionsCoun : 0;
    commitMutation({
      variables: {
        input: {
          targetObjectId: target.id,
          reactionType,
          profileObjectId: currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id
        }
      },
      optimisticResponse: {
        reactionToggle: {
          reaction: {
            node: {
              id: "client:newReaction:".concat(Date.now()),
              reactionType
            }
          },
          reactionDeletedId: (_target$myReaction = target.myReaction) === null || _target$myReaction === void 0 ? void 0 : _target$myReaction.id,
          target: {
            id: target.id,
            __typename: "Comment",
            __isReactionsInterface: "Comment",
            myReaction: !((_target$myReaction2 = target.myReaction) !== null && _target$myReaction2 !== void 0 && _target$myReaction2.id) ? {
              id: "client:myReaction:".concat(Date.now()),
              reactionType
            } : null,
            reactionsCount: {
              total: (_target$myReaction3 = target.myReaction) !== null && _target$myReaction3 !== void 0 && _target$myReaction3.id ? currentReactionsCount - 1 : currentReactionsCount + 1
            }
          }
        }
      },
      onCompleted: function onCompleted() {
        handleSuccess === null || handleSuccess === void 0 || handleSuccess();
      },
      onError: function onError() {
        handleError === null || handleError === void 0 || handleError();
      }
    });
  };
  return children({
    handleReaction,
    isLoading: isMutationInFlight,
    target
  });
};
var ReactionButton_default = ReactionButton;



exports.ReactionButton_default = ReactionButton_default;
//# sourceMappingURL=chunk-VSCZBFV4.js.map