import t from"@babel/runtime/helpers/slicedToArray";import{useState as e}from"react";import n from"moment";import{string as i,shape as o,func as a,bool as l,number as r}from"prop-types";import{withStyles as c}from"@material-ui/core/styles";import{Paper as s,Input as m,Tooltip as d,FormControl as p,InputLabel as u,MenuItem as f,Typography as h,IconButton as g}from"@material-ui/core";import v from"@material-ui/icons/Send";import b from"@material-ui/core/colors/grey";import{ANNOTATION_ACTIVE_PERIODS as y}from"../../../../constants.js";import A from"./StyledSelect.js";import N from"./style.css.js";import j from"../../../../../UserMention/index.js";import C from"../../../../../EmojiIconButton.js";import I from"../../../../../FileUploadIconButton.js";import U from"../../../../../FailedFileUploading.js";import S from"../../../../../FilePreview/index.js";import{isSuggestionsListOpened as E}from"../../../../../UserMention/utils/index.js";import _ from"../../../../../../effects/useEscPress.js";import{jsxs as x,jsx as P}from"react/jsx-runtime";var k="AppAnnotationsPo",B=Object.keys(y),F=function(i){var o=i.initialText,a=i.initialPeriod,l=i.onSend,r=i.onClose,c=i.closeOnEsc,F=i.classes,T=i.initialAttachment,w=i.assetCompanyId,R=i.currentUser,L=e(o),D=t(L,2),O=D[0],z=D[1],H=e((function(){return T?{attachmentName:T.file_name,attachmentUrl:T.signed_url||T.s3_link}:null})),M=t(H,2),W=M[0],q=M[1],K=e(null),G=t(K,2),J=G[0],Q=G[1],V=e(!1),X=t(V,2),Y=X[0],Z=X[1],$=e(B[0]),tt=t($,2),et=tt[0],nt=tt[1];_((function(){c&&r()}));var it=function(){if(O){var t=function(t,e){if("forever"===t)return null;var i=y[t];return n(e).add(i.time.amount,i.time.key).format()}(et,a);l(O,t,W)}};return x("div",{className:N.cAnnotationInput,children:[x(s,{className:N.cAnnotationInputContent,children:[P(m,{"data-testid":"".concat(k,"_annotationsInput"),inputComponent:j,inputProps:{withLightTheme:!1,onChange:function(t){return z(t)},onKeyDown:function(t){"Shift"===t.key&&Z(!0),"Enter"!==t.key||Y||E()||(t.preventDefault(),it())},onKeyUp:function(t){"Shift"===t.key&&Z(!1)},companyId:w,currentUser:R},placeholder:"Type annotation here",fullWidth:!0,disableUnderline:!0,multiline:!0,rows:"3",className:F.inputRoot,value:O}),x("div",{className:N.cAnnotationInputContentActions,children:[P(d,{title:"Attach File",placement:"bottom",children:P("div",{className:N.cAnnotationInputContentActionsButton,children:P(I,{"data-testid":"".concat(k,"_attachFileButton"),openPreviewDialogOnUpload:!1,disableRipple:!0,onFinish:function(t,e,n){q({attachmentUrl:t,attachmentName:e,attachmentSize:n}),Q(null)},onError:function(t){q(null),Q(t)},htmlColor:"action"})})}),P(d,{title:"Add Emoji",placement:"bottom",children:P("div",{className:N.cAnnotationInputContentActionsButton,children:P(C,{"data-testid":"".concat(k,"_emojiButton"),htmlColor:b[400],handleSelectEmoji:function(t){return z("".concat(O).concat(t.native))}})})})]})]}),J&&P(U,{className:F.uploadingError,errorMessage:J}),W&&W.attachmentUrl&&P(S,{fileName:W.attachmentName,fileUrl:W.attachmentUrl,handleFileDelete:function(){q(null),Q(null)}}),x("div",{className:N.cAnnotationInputActions,children:[x(p,{className:F.formControl,children:[P(u,{shrink:!0,id:"periods-label-label",className:F.selectLabel,children:"Active"}),P(A,{"data-testid":"".concat(k,"_periodDropdown"),labelId:"periods-label-label",id:"periods-label",value:et,disableUnderline:!0,onChange:function(t){return nt(t.target.value)},children:B.map((function(t){return P(f,{"data-testid":"".concat(k,"_period_").concat(y[t].label,"MenuItem"),value:t,children:y[t].label},t)}))})]}),x("div",{className:N.cAnnotationInputActionsSend,children:[x(h,{variant:"caption",className:F.sendLabel,children:["Press ",P(h,{variant:"caption",color:"primary",component:"span",className:F.labelHighlighter,children:"Enter "}),"to send "]}),P(d,{title:"Send",placement:"bottom",children:P("div",{children:P(g,{"data-testid":"".concat(k,"_sendButton"),className:F.sendButton,onClick:it,disabled:!O,children:P(v,{color:"primary"})})})})]})]})]})};F.propTypes={initialText:i,initialPeriod:i,initialAttachment:o({file_name:i,s3_link:i}),onSend:a,onClose:a,closeOnEsc:l,assetCompanyId:r.isRequired,currentUser:o().isRequired,classes:o().isRequired},F.defaultProps={initialText:"",initialPeriod:void 0,initialAttachment:null,onSend:function(){},onClose:function(){},closeOnEsc:!1};var T=c((function(t){return{inputLabel:{color:t.palette.grey[700],fontWeight:200,width:"100%"},inputRoot:{lineHeight:15},sendLabel:{display:"flex",alignItems:"center",fontWeight:200,color:t.palette.grey[700],marginRight:22,fontSize:10},sendButton:{padding:5},labelHighlighter:{fontWeight:200,fontSize:10},selectLabel:{fontSize:10,lineHeight:"14px",color:t.palette.grey[500]},uploadingError:{paddingTop:"10px"}}}))(F);export{T as default};
//# sourceMappingURL=index.js.map
