import{b as P}from"./chunk-V2H4OEKG.mjs";import{b as O}from"./chunk-A5QFDUFT.mjs";import{a as I}from"./chunk-X2VVDCO6.mjs";import{a as g,c as _}from"./chunk-256IQ3QR.mjs";import{forwardRef as G}from"react";import{useCurrentProfile as K}from"@baseapp-frontend/authentication";import{setFormRelayErrors as z,useNotification as W}from"@baseapp-frontend/utils";import{zodResolver as q}from"@hookform/resolvers/zod";import{useForm as B}from"react-hook-form";import{ConnectionHandler as J}from"react-relay";import{jsx as Q}from"react/jsx-runtime";function c(e){"@babel/helpers - typeof";return c=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(e)}function h(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,o)}return r}function x(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?h(Object(r),!0).forEach(function(o){F(e,o,r[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):h(Object(r)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(r,o))})}return e}function F(e,t,r){return(t=N(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(e){var t=U(e,"string");return c(t)=="symbol"?t:t+""}function U(e,t){if(c(e)!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var o=r.call(e,t||"default");if(c(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Y(e,t){return V(e)||H(e,t)||k(e,t)||$()}function $(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function k(e,t){if(e){if(typeof e=="string")return j(e,t);var r={}.toString.call(e).slice(8,-1);return r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set"?Array.from(e):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?j(e,t):void 0}}function j(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,o=Array(t);r<t;r++)o[r]=e[r];return o}function H(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var o,i,a,u,l=[],n=!0,f=!1;try{if(a=(r=r.call(e)).next,t===0){if(Object(r)!==r)return;n=!1}else for(;!(n=(o=a.call(r)).done)&&(l.push(o.value),l.length!==t);n=!0);}catch(s){f=!0,i=s}finally{try{if(!n&&r.return!=null&&(u=r.return(),Object(u)!==u))return}finally{if(f)throw i}}return l}}function V(e){if(Array.isArray(e))return e}var M=0,X=G(function(e,t){var r=e.roomId,o=e.SocialInput,i=o===void 0?I:o,a=e.SocialInputProps,u=a===void 0?{}:a,l=K(),n=l.currentProfile,f=W(),s=f.sendToast,m=B({defaultValues:g,resolver:q(_)}),A=P(),d=Y(A,2),E=d[0],b=d[1],w=function(T){if(!(b||!n)){M+=1;var R=M.toString(),D=J.getConnectionID(r,"chatRoom_allMessages"),v=T.body;E({variables:{input:{content:v,profileId:n?.id,roomId:r,clientMutationId:R},connections:[D]},optimisticResponse:{chatRoomSendMessage:{message:{node:{id:"client:new_message:".concat(Date.now()),content:v,created:new Date(Date.now()).toISOString(),deleted:!1,extraData:null,messageType:O.user,inReplyTo:null,isRead:!0,pk:0,profile:{id:n.id},verb:"SENT_MESSAGE"}},errors:[]}},onCompleted:function(p,L){var y;L&&s("Your last message could not be sent. Please try again.",{type:"error"});var S=p==null||(y=p.chatRoomSendMessage)===null||y===void 0?void 0:y.errors;S&&(z(m,S),s("Your last message could not be sent. Please try again.",{type:"error"}))},onError:function(){s("Your last message could not be sent. Please try again.",{type:"error"})}}),m.reset()}};return Q(i,x({ref:t,form:m,submit:w,isLoading:b},u))}),ce=X;export{ce as a};
//# sourceMappingURL=chunk-YLQRDOJ6.mjs.map