import e from"@babel/runtime/helpers/defineProperty";import o from"@babel/runtime/helpers/slicedToArray";import n from"prop-types";import{useState as r,useRef as t,useEffect as i}from"react";import{TextField as s,InputAdornment as a}from"@material-ui/core";import l from"classnames";import{noop as u}from"lodash";import m from"./PostInput.css.js";import p from"../FilePreview/index.js";import c from"../FailedFileUploading.js";import d from"../UserMention/index.js";import f from"../FileUploadIconButton.js";import g from"../EmojiIconButton.js";import{jsxs as h,jsx as v}from"react/jsx-runtime";var w=function(n){var u=n.className,w=n.userCompanyId,y=n.onChange,P=n.onKeyDown,b=n.initialValue,C=n.filePreviewWrapperClass,j=n.smallerView,F=n.suggestionsPortalHost,I=n.allowSuggestionsAboveCursor,A=r(b.body),N=o(A,2),S=N[0],T=N[1],x=r(b.attachment),D=o(x,2),U=D[0],V=D[1],H=r(null),K=o(H,2),E=K[0],W=K[1],B=t(null);return i((function(){B.current&&(B.current.selectionStart=B.current.value.length)}),[]),i((function(){y({body:S,attachment:U})}),[S,U]),h("div",{className:l(m.input,u),children:[v(s,{"data-testid":"".concat("PostInput","_input"),className:l(m.inputTextField,e({},m.inputTextFieldSmaller,j)),placeholder:"Add Comment...",FormHelperTextProps:{component:"div",margin:"dense"},inputRef:B,InputProps:{inputComponent:d,inputProps:{onChange:T,value:S,withLightTheme:!1,companyId:w,autoFocus:!0,className:m.inputInput,placeholder:"Type here...",suggestionsPortalHost:F,allowSuggestionsAboveCursor:I},endAdornment:h(a,{position:"end",className:l(m.inputAdornment,e({},m.inputAdornmentSmaller,j)),children:[!U&&v("div",{children:v(f,{openPreviewDialogOnUpload:!1,onFinish:function(e,o,n){V({url:e,name:o,size:n})},onError:W})}),v("div",{children:v(g,{"data-testid":"".concat("PostInput","_emoji"),handleSelectEmoji:function(e){return T((function(o){return"".concat(o).concat(e.native)}))}})})]}),disableUnderline:!0,classes:{}},onKeyDown:P}),U&&v(p,{fileName:U.name,fileUrl:U.url,handleFileDelete:function(){return V(null)},classes:{wrapper:C}}),E&&v(c,{errorMessage:E})]})};w.propTypes={userCompanyId:n.oneOfType([n.string,n.number]).isRequired,className:n.string,onKeyDown:n.func,onChange:n.func,initialValue:n.shape({body:n.string,attachment:n.shape({})}),filePreviewWrapperClass:n.string,suggestionsPortalHost:n.node,allowSuggestionsAboveCursor:n.bool,smallerView:n.bool},w.defaultProps={className:null,initialValue:{body:"",attachment:null},filePreviewWrapperClass:null,onKeyDown:u,onChange:u,smallerView:!1,suggestionsPortalHost:void 0,allowSuggestionsAboveCursor:!1};export{w as default};
