"use strict";var e=require("@babel/runtime/helpers/asyncToGenerator"),t=require("@babel/runtime/helpers/defineProperty"),r=require("@babel/runtime/regenerator"),a=require("react"),i=require("prop-types"),s=require("classnames"),n=require("lodash"),o=require("@material-ui/core/styles"),u=require("@material-ui/core/withWidth"),c=require("@material-ui/core/Paper"),d=require("@material-ui/core/Typography"),l=require("@material-ui/icons/Comment"),m=require("@material-ui/icons/Close"),p=require("../../../../clients/jsonApi/index.js"),f=require("./style.css.js"),h=require("../../../UserCardPopover.js"),v=require("../../../Avatar/index.js"),q=require("../../../UserMention/utils/index.js"),x=require("../../../../utils/mobileDetect.js"),b=require("react/jsx-runtime");function y(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var j=y(e),g=y(t),N=y(r),A=y(s),R=y(u),U=y(c),_=y(d),C=y(l),L=y(m),T="lastAnnotation",w=function(e){var t=e.user,r=e.currentUser,a=e.isNative,i=e.className,s=e.size,n=b.jsx(v.AvatarComponent,{displayName:"".concat(t.first_name," ").concat(t.last_name),imgSrc:t.profile_photo,size:s,className:i});return a?n:b.jsx(h,{user:t,currentUser:r,children:n})},I=function(e){var t=e.commentsCount,r=e.commentUsers,a=e.isSmallScreen,i=e.isNative,s=e.currentUser,n=e.classes;return t?b.jsxs("div",{className:f.cTopAnnotationAdditionalReactions,children:[b.jsx(C.default,{className:n.commentIcon}),!a&&b.jsxs(_.default,{variant:"body2","data-testid":"".concat(T,"_comments"),noWrap:!0,className:n.commentText,component:"div",children:["Comments ",t]}),b.jsx("div",{className:f.cTopAnnotationAdditionalReactionsList,children:r.map((function(e,t){var r=e.attributes;return b.jsx(w,{user:r,currentUser:s,isNative:i,className:A.default(n.avatar,g.default({},n.avatarInList,0!==t)),size:25},r.id)}))})]}):null},S=function(e){var t,r=e.isNative,i=e.appId,s=e.annotation,n=e.openAnnotationsList,o=e.currentUser,c=e.updateCurrentDashboardAppLastAnnotation,d=e.width,l=e.classes,m=s.data,h=s.included,v=h.find((function(e){var t=e.id,r=e.type;return t===m.relationships.user.data.id&&"user"===r})),x=a.useMemo((function(){return m.relationships.mentioned_users.data.map((function(e){var t=e.id;return h.find((function(e){return e.id===t}))}))}),[m.relationships.mentioned_users.data,h]),y=a.useMemo((function(){return m.relationships.comment_users.data.map((function(e){var t=e.id;return h.find((function(e){return e.id===t}))}))}),[m.relationships.comment_users.data,h]),g=!u.isWidthUp("sm",d),A=(t=j.default(N.default.mark((function e(t){var r;return N.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.stopPropagation(),e.prev=1,e.next=4,p.closeLastAnnotation(m.id);case 4:r=e.sent,c(m.id,i,r),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 t.apply(this,arguments)});return b.jsxs(U.default,{"data-testid":"".concat(T,"_lastAnnotation"),className:l.container,onClick:n,children:[b.jsxs("div",{className:f.cTopAnnotationMain,children:[b.jsx(w,{user:v.attributes,currentUser:o,isNative:r,className:l.avatar,size:38}),b.jsx(_.default,{variant:"body2","data-testid":"".concat(T,"_message"),noWrap:!0,className:l.body,children:q.formatMentionText(m.attributes.body,x,r,null,o)})]}),b.jsxs("div",{className:f.cTopAnnotationAdditional,children:[b.jsx(I,{commentsCount:m.attributes.comments_count,commentUsers:y,classes:l,isSmallScreen:g,currentUser:o}),b.jsx(L.default,{"data-testid":"".concat(T,"_closeButton"),fontSize:"small",className:l.closeButton,onClick:A})]})]})};S.propTypes={appId:i.number.isRequired,annotation:i.shape({included:i.arrayOf(i.shape({})).isRequired,data:i.shape({relationships:i.shape({user:i.shape({data:i.shape({id:i.string.isRequired}).isRequired}).isRequired,mentioned_users:i.shape({data:i.arrayOf(i.shape()).isRequired}).isRequired}).isRequired,attributes:i.shape({body:i.string.isRequired,created_at:i.string.isRequired})}).isRequired}).isRequired,classes:i.shape({}).isRequired,isNative:i.bool,width:i.string.isRequired,openAnnotationsList:i.func.isRequired,updateCurrentDashboardAppLastAnnotation:i.func,currentUser:i.shape({})},S.defaultProps={isNative:x.isNativeDetected,updateCurrentDashboardAppLastAnnotation:function(){},currentUser:{}};var z=n.flowRight([o.withStyles((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}}})),R.default()])(a.memo(S));module.exports=z;
