import {
  __esm,
  __export,
  __toCommonJS
} from "./chunk-NFEGQTCC.mjs";

// __generated__/SendMessageMutation.graphql.ts
var SendMessageMutation_graphql_exports = {};
__export(SendMessageMutation_graphql_exports, {
  default: () => SendMessageMutation_graphql_default
});
var node, SendMessageMutation_graphql_default;
var init_SendMessageMutation_graphql = __esm({
  "__generated__/SendMessageMutation.graphql.ts"() {
    "use strict";
    node = /* @__PURE__ */ function() {
      var v0 = {
        "defaultValue": null,
        "kind": "LocalArgument",
        "name": "connections"
      }, v1 = {
        "defaultValue": null,
        "kind": "LocalArgument",
        "name": "input"
      }, v2 = [
        {
          "kind": "Variable",
          "name": "input",
          "variableName": "input"
        }
      ], v3 = {
        "alias": null,
        "args": null,
        "kind": "ScalarField",
        "name": "id",
        "storageKey": null
      }, v4 = {
        "alias": null,
        "args": null,
        "kind": "ScalarField",
        "name": "messageType",
        "storageKey": null
      }, v5 = {
        "alias": null,
        "args": null,
        "concreteType": "ErrorType",
        "kind": "LinkedField",
        "name": "errors",
        "plural": true,
        "selections": [
          {
            "alias": null,
            "args": null,
            "kind": "ScalarField",
            "name": "field",
            "storageKey": null
          },
          {
            "alias": null,
            "args": null,
            "kind": "ScalarField",
            "name": "messages",
            "storageKey": null
          }
        ],
        "storageKey": null
      }, v6 = [
        v3
      ];
      return {
        "fragment": {
          "argumentDefinitions": [
            v0,
            v1
          ],
          "kind": "Fragment",
          "metadata": null,
          "name": "SendMessageMutation",
          "selections": [
            {
              "alias": null,
              "args": v2,
              "concreteType": "ChatRoomSendMessagePayload",
              "kind": "LinkedField",
              "name": "chatRoomSendMessage",
              "plural": false,
              "selections": [
                {
                  "alias": null,
                  "args": null,
                  "concreteType": "MessageEdge",
                  "kind": "LinkedField",
                  "name": "message",
                  "plural": false,
                  "selections": [
                    {
                      "alias": null,
                      "args": null,
                      "concreteType": "Message",
                      "kind": "LinkedField",
                      "name": "node",
                      "plural": false,
                      "selections": [
                        v3,
                        v4,
                        {
                          "args": null,
                          "kind": "FragmentSpread",
                          "name": "MessageItemFragment"
                        }
                      ],
                      "storageKey": null
                    }
                  ],
                  "storageKey": null
                },
                v5
              ],
              "storageKey": null
            }
          ],
          "type": "Mutation",
          "abstractKey": null
        },
        "kind": "Request",
        "operation": {
          "argumentDefinitions": [
            v1,
            v0
          ],
          "kind": "Operation",
          "name": "SendMessageMutation",
          "selections": [
            {
              "alias": null,
              "args": v2,
              "concreteType": "ChatRoomSendMessagePayload",
              "kind": "LinkedField",
              "name": "chatRoomSendMessage",
              "plural": false,
              "selections": [
                {
                  "alias": null,
                  "args": null,
                  "concreteType": "MessageEdge",
                  "kind": "LinkedField",
                  "name": "message",
                  "plural": false,
                  "selections": [
                    {
                      "alias": null,
                      "args": null,
                      "concreteType": "Message",
                      "kind": "LinkedField",
                      "name": "node",
                      "plural": false,
                      "selections": [
                        v3,
                        v4,
                        {
                          "alias": null,
                          "args": null,
                          "kind": "ScalarField",
                          "name": "content",
                          "storageKey": null
                        },
                        {
                          "alias": null,
                          "args": null,
                          "kind": "ScalarField",
                          "name": "created",
                          "storageKey": null
                        },
                        {
                          "alias": null,
                          "args": null,
                          "kind": "ScalarField",
                          "name": "deleted",
                          "storageKey": null
                        },
                        {
                          "alias": null,
                          "args": null,
                          "kind": "ScalarField",
                          "name": "extraData",
                          "storageKey": null
                        },
                        {
                          "alias": null,
                          "args": null,
                          "concreteType": "Message",
                          "kind": "LinkedField",
                          "name": "inReplyTo",
                          "plural": false,
                          "selections": v6,
                          "storageKey": null
                        },
                        {
                          "alias": null,
                          "args": null,
                          "kind": "ScalarField",
                          "name": "isRead",
                          "storageKey": null
                        },
                        {
                          "alias": null,
                          "args": null,
                          "kind": "ScalarField",
                          "name": "pk",
                          "storageKey": null
                        },
                        {
                          "alias": null,
                          "args": null,
                          "concreteType": "Profile",
                          "kind": "LinkedField",
                          "name": "profile",
                          "plural": false,
                          "selections": v6,
                          "storageKey": null
                        },
                        {
                          "alias": null,
                          "args": null,
                          "kind": "ScalarField",
                          "name": "verb",
                          "storageKey": null
                        }
                      ],
                      "storageKey": null
                    }
                  ],
                  "storageKey": null
                },
                {
                  "alias": null,
                  "args": null,
                  "filters": null,
                  "handle": "prependEdge",
                  "key": "",
                  "kind": "LinkedHandle",
                  "name": "message",
                  "handleArgs": [
                    {
                      "kind": "Variable",
                      "name": "connections",
                      "variableName": "connections"
                    }
                  ]
                },
                v5
              ],
              "storageKey": null
            }
          ]
        },
        "params": {
          "cacheID": "f1f83794e980cf67bbad0227c12a8467",
          "id": null,
          "metadata": {},
          "name": "SendMessageMutation",
          "operationKind": "mutation",
          "text": "mutation SendMessageMutation(\n  $input: ChatRoomSendMessageInput!\n) {\n  chatRoomSendMessage(input: $input) {\n    message {\n      node {\n        id\n        messageType\n        ...MessageItemFragment\n      }\n    }\n    errors {\n      field\n      messages\n    }\n  }\n}\n\nfragment MessageItemFragment on Message {\n  id\n  content\n  created\n  deleted\n  extraData\n  inReplyTo {\n    id\n  }\n  isRead\n  pk\n  profile {\n    id\n  }\n  verb\n}\n"
        }
      };
    }();
    node.hash = "5bf2d0d2799770d10ed709dfc512b261";
    SendMessageMutation_graphql_default = node;
  }
});

// tmp-babel/messages/common/graphql/mutations/SendMessage.js
import { useNotification } from "@baseapp-frontend/utils";
import { graphql, useMutation } from "react-relay";
function _typeof(o) {
  "@babel/helpers - typeof";
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
    return typeof o2;
  } : function(o2) {
    return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
  }, _typeof(o);
}
var _SendMessageMutation;
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : 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);
}
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 SendMessageMutationQuery = _SendMessageMutation !== void 0 ? _SendMessageMutation : (_SendMessageMutation = (init_SendMessageMutation_graphql(), __toCommonJS(SendMessageMutation_graphql_exports)), _SendMessageMutation.hash && _SendMessageMutation.hash !== "5bf2d0d2799770d10ed709dfc512b261" && console.error("The definition of 'SendMessageMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _SendMessageMutation);
var useSendMessageMutation = function useSendMessageMutation2() {
  var _useNotification = useNotification(), sendToast = _useNotification.sendToast;
  var _useMutation = useMutation(SendMessageMutationQuery), _useMutation2 = _slicedToArray(_useMutation, 2), commitMutation = _useMutation2[0], isMutationInFlight = _useMutation2[1];
  var commit = function commit2(config) {
    return commitMutation(_objectSpread(_objectSpread({}, config), {}, {
      onCompleted: function onCompleted(response, errors) {
        var _config$onCompleted;
        errors === null || errors === void 0 || errors.forEach(function(error) {
          sendToast(error.message, {
            type: "error"
          });
        });
        config === null || config === void 0 || (_config$onCompleted = config.onCompleted) === null || _config$onCompleted === void 0 || _config$onCompleted.call(config, response, errors);
      },
      onError: function onError(error) {
        var _config$onError;
        sendToast(error.message, {
          type: "error"
        });
        config === null || config === void 0 || (_config$onError = config.onError) === null || _config$onError === void 0 || _config$onError.call(config, error);
      }
    }));
  };
  return [commit, isMutationInFlight];
};

export {
  SendMessageMutationQuery,
  useSendMessageMutation
};
//# sourceMappingURL=chunk-Y4R2HTN5.mjs.map