import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/regenerator";import{memo as i,useMemo as a}from"react";import{number as n,shape as s,arrayOf as o,string as c,bool as m,func as u}from"prop-types";import d from"classnames";import{flowRight as l}from"lodash";import{withStyles as p}from"@material-ui/core/styles";import f,{isWidthUp as h}from"@material-ui/core/withWidth";import v from"@material-ui/core/Paper";import b from"@material-ui/core/Typography";import y from"@material-ui/icons/Comment";import N from"@material-ui/icons/Close";import{closeLastAnnotation as A}from"../../../../clients/jsonApi/index.js";import R from"./style.css.js";import g from"../../../UserCardPopover.js";import{AvatarComponent as x}from"../../../Avatar/index.js";import{formatMentionText as q}from"../../../UserMention/utils/index.js";import{isNativeDetected as _}from"../../../../utils/mobileDetect.js";import{jsxs as U,jsx as C}from"react/jsx-runtime";var j="lastAnnotation",L=function(e){var t=e.user,r=e.currentUser,i=e.isNative,a=e.className,n=e.size,s=C(x,{displayName:"".concat(t.first_name," ").concat(t.last_name),imgSrc:t.profile_photo,size:n,className:a});return i?s:C(g,{user:t,currentUser:r,children:s})},T=function(e){var r=e.commentsCount,i=e.commentUsers,a=e.isSmallScreen,n=e.isNative,s=e.currentUser,o=e.classes;return r?U("div",{className:R.cTopAnnotationAdditionalReactions,children:[C(y,{className:o.commentIcon}),!a&&U(b,{variant:"body2","data-testid":"".concat(j,"_comments"),noWrap:!0,className:o.commentText,component:"div",children:["Comments ",r]}),C("div",{className:R.cTopAnnotationAdditionalReactionsList,children:i.map((function(e,r){var i=e.attributes;return C(L,{user:i,currentUser:s,isNative:n,className:d(o.avatar,t({},o.avatarInList,0!==r)),size:25},i.id)}))})]}):null},w=function(t){var i,n=t.isNative,s=t.appId,o=t.annotation,c=t.openAnnotationsList,m=t.currentUser,u=t.updateCurrentDashboardAppLastAnnotation,d=t.width,l=t.classes,p=o.data,f=o.included,y=f.find((function(e){var t=e.id,r=e.type;return t===p.relationships.user.data.id&&"user"===r})),g=a((function(){return p.relationships.mentioned_users.data.map((function(e){var t=e.id;return f.find((function(e){return e.id===t}))}))}),[p.relationships.mentioned_users.data,f]),x=a((function(){return p.relationships.comment_users.data.map((function(e){var t=e.id;return f.find((function(e){return e.id===t}))}))}),[p.relationships.comment_users.data,f]),_=!h("sm",d),w=(i=e(r.mark((function e(t){var i;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.stopPropagation(),e.prev=1,e.next=4,A(p.id);case 4:i=e.sent,u(p.id,s,i),e.next=11;break;case 8:e.prev=8,e.t0=e.catch(1),console.error(e.t0);case 11:case"end":return e.stop()}}),e,null,[[1,8]])}))),function(e){return i.apply(this,arguments)});return U(v,{"data-testid":"".concat(j,"_lastAnnotation"),className:l.container,onClick:c,children:[U("div",{className:R.cTopAnnotationMain,children:[C(L,{user:y.attributes,currentUser:m,isNative:n,className:l.avatar,size:38}),C(b,{variant:"body2","data-testid":"".concat(j,"_message"),noWrap:!0,className:l.body,children:q(p.attributes.body,g,n,null,m)})]}),U("div",{className:R.cTopAnnotationAdditional,children:[C(T,{commentsCount:p.attributes.comments_count,commentUsers:x,classes:l,isSmallScreen:_,currentUser:m}),C(N,{"data-testid":"".concat(j,"_closeButton"),fontSize:"small",className:l.closeButton,onClick:w})]})]})};w.propTypes={appId:n.isRequired,annotation:s({included:o(s({})).isRequired,data:s({relationships:s({user:s({data:s({id:c.isRequired}).isRequired}).isRequired,mentioned_users:s({data:o(s()).isRequired}).isRequired}).isRequired,attributes:s({body:c.isRequired,created_at:c.isRequired})}).isRequired}).isRequired,classes:s({}).isRequired,isNative:m,width:c.isRequired,openAnnotationsList:u.isRequired,updateCurrentDashboardAppLastAnnotation:u,currentUser:s({})},w.defaultProps={isNative:_,updateCurrentDashboardAppLastAnnotation:function(){},currentUser:{}};var I=l([p((function(e){return{container:{height:56,margin:"10px 0",padding:"0 20px",display:"flex",alignItems:"center",justifyContent:"space-between",flex:"auto 1",width:"100%",cursor:"pointer"},body:{margin:"0 16px ",minWidth:100},avatar:{border:"1px solid #909090"},commentIcon:{marginRight:16,color:e.palette.grey[500]},commentText:{marginRight:16,color:e.palette.grey[500]},closeButton:{color:e.palette.grey[500]},avatarInList:{marginLeft:-4}}})),f()])(i(w));export{I as default};
//# sourceMappingURL=index.js.map
