define(["require","exports","tslib","react","classnames","spectrum/tertiary_link","spectrum/tooltip","comments2/components/comment","comments2/components/thread/third_party_reply_cta","comments2/components/thread/thread_editor","comments2/components/thread/thread_source_message","prop-types","comments2/components/comment_editor/draft_utils","comments2/components/comment_utils","comments2/l10n"],(function(e,t,o,n,r,s,i,a,d,c,l,m,u,h,p){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),n=o.__importStar(n),r=o.__importDefault(r),m=o.__importStar(m);var f=function(){},v=function(e,t){var o=t.localization.intl,r=e.count;o.formatMessage({id:"61xw1",defaultMessage:"{count, plural, one {# comment} other {# comments}}"},{count:r});var s=o.formatMessage({id:"DbGm_",defaultMessage:"{count} comments"},{count:r});return n.createElement("div",{className:"sc-thread-comment-number"},s)};function g(e,t){return{onDeleted:function(){return t.onCommentDeleted(e.id)},onEdited:function(o){return t.onCommentEdited(e.id,o)},onMentionsQueryUpdated:t.onMentionsQueryUpdated,onClickTimeCode:t.onClickTimeCode,onClickOlderInfo:t.onClickOlderInfo}}v.contextTypes={localization:m.object};var E={type:"no_details"},M=(function(e){function t(){var t=e.apply(this,arguments)||this;return t.state={isEditorEmpty:!0,isEditorFocused:!1,shouldFocusThreadEditor:!1},t.ref=null,t.onFocusEditor=function(){return t.setState({isEditorFocused:!0})},t.onBlurEditor=function(){return t.setState({isEditorFocused:!1})},t.onClick=function(){var e=t.props;(0,e.onThreadInteractedWith)(e.thread)},t.handleKeyDown=function(e){13===e.which&&t.onClick()},t.onEditorStateChange=function(e){u.hasFocus(e)&&t.props.actions.onEditorFocused(),t.props.actions.onEditorStateChange(e),t.setState({isEditorEmpty:u.contentIsEmpty(e)})},t.setRef=function(e){t.ref=e},t.renderMarkedAsResolved=function(e){var o,r,s=t.intl,a="with_details"===e.type&&e;return a?(o=s.formatMessage({id:"dzqht",defaultMessage:"Marked as resolved by {name}"},{name:a.resolver.name.display}),r=p.getActingTime(s,a.resolvedTimestamp)):(o=s.formatMessage({id:"1Xu7U",defaultMessage:"Marked as resolved"}),r=s.formatMessage({id:"1Xu7U",defaultMessage:"Marked as resolved"})),n.createElement(i.Tooltip,{positioning:"above",tooltipContent:r},n.createElement("div",{className:"sc-thread-controls-resolved-note"},o))},t.getResolvedInfo=function(e){var t=e.resolvedInfo,o=e.resolved;return t||(o?E:void 0)},t}return o.__extends(t,e),Object.defineProperty(t.prototype,"intl",{get:function(){return this.context.localization.intl},enumerable:!0,configurable:!0}),t.prototype.componentDidMount=function(){var e=this;this.props.active&&this.scrollToThread(!1).then((function(){e.ref&&e.ref.focus()}))},t.prototype.componentDidUpdate=function(e){if(this.props.active&&!e.active){var t=this.props.streamSettings.canComment;this.scrollToThread(t)}else!this.props.active&&e.active&&this.setState({isEditorFocused:!1,shouldFocusThreadEditor:!1})},t.prototype.scrollToThread=function(e){var t=this,o=this.props.scrollToElem,n=this.ref;return n&&o?o(n).then((function(){t.ref&&t.setState({shouldFocusThreadEditor:e})})):Promise.resolve()},Object.defineProperty(t.prototype,"innerRef",{get:function(){return this.ref},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"activeOrEditorHasText",{get:function(){return this.props.active||!this.state.isEditorEmpty},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"className",{get:function(){var e=this.props,t=e.className,o=void 0===t?"":t,n=e.thread,s=e.isMobile,i=e.focused,a=n.resolved||n.resolvedInfo;return r.default(o,{"sc-thread":!0,"sc-thread-active":this.activeOrEditorHasText,"sc-thread-inactive":!this.activeOrEditorHasText,"sc-thread-read":n.read,"sc-thread-unread":!n.read,"sc-thread-resolved":a,"sc-thread-unresolved":!a,"sc-thread-mobile":s,"sc-thread-focused":i,"sc-thread-editor-is-focused":this.state.isEditorFocused})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filteredReplies",{get:function(){return this.props.thread.comments.slice(1).filter((function(e){return!e.deleted}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"includeEditor",{get:function(){var e=this.props,t=e.streamSettings.canShowEditor,o=e.isMobile,n=e.thread.isThirdParty;return t&&!o&&!n},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDisabled",{get:function(){return!!this.props.thread.pending},enumerable:!0,configurable:!0}),t.prototype.renderComment=function(e,t,o,r){void 0===o&&(o=a.Comment);var s=this.props,i=s.actions,d=s.editedComment,c=s.mentionsMatches,l=s.onStartEdit,m=s.onEndEdit,u=s.isMobile,p=s.showRevisionInfo,f=!!d&&e.id===d.id;return t||(e=h.truncateComment(e)),n.createElement(o,{actions:g(e,i),active:t,annotation:r,comment:e,key:e.id,isEditing:f,onStartEdit:l,onEndEdit:m,mentionsMatches:c,isMobile:u,showRevisionInfo:p})},t.prototype.renderReadToggle=function(){var e=this.intl,t=this.props,o=t.actions,r=t.thread,a=r.read?o.onMarkAsUnread:o.onMarkAsRead,d=r.read?e.formatMessage({id:"3RQUH",defaultMessage:"Mark as unread"}):e.formatMessage({id:"1g51C",defaultMessage:"Mark as read"});return n.createElement(i.Tooltip,{positioning:"above",tooltipContent:d},n.createElement(s.TertiaryLink,{className:"sc-thread-toggle",onClick:a,disabled:this.isDisabled},d))},t.prototype.renderToplineControls=function(){var e=this.intl,t=this.props,o=t.streamSettings,r=t.isMobile,a=t.actions,d=t.thread,c=this.activeOrEditorHasText;if(r)return null;var l=c&&o.canModifyThreads&&!d.isThirdParty,m=this.getResolvedInfo(d);return m?n.createElement("div",{className:"sc-thread-controls"},this.renderMarkedAsResolved(m),l&&n.createElement(i.Tooltip,{positioning:"above",tooltipContent:e.formatMessage({id:"SvXtJ",defaultMessage:"Restore"})},n.createElement(s.TertiaryLink,{className:"sc-thread-toggle",disabled:this.isDisabled,onClick:a.onUnresolve},e.formatMessage({id:"SvXtJ",defaultMessage:"Restore"})))):l?n.createElement("div",{className:"sc-thread-controls"},this.renderReadToggle(),n.createElement(i.Tooltip,{positioning:"above",tooltipContent:e.formatMessage({id:"1hWLR",defaultMessage:"Resolve"})},n.createElement(s.TertiaryLink,{className:"sc-thread-toggle",onClick:a.onResolve,disabled:this.isDisabled},e.formatMessage({id:"1hWLR",defaultMessage:"Resolve"})))):null},t.prototype.renderActive=function(){var e=this,t=this.intl,o=this.props,r=o.actions,s=r.onMentionsQueryUpdated,i=r.onMouseEnter,l=r.onMouseLeave,m=r.onReply,u=o.commentComponent,h=o.mentionsMatches,p=o.stickerPacks,f=o.onCancel,v=o.openWith,g=o.thirdPartySource,E=o.thread,M=o.user,y=this.filteredReplies;return n.createElement("li",{onMouseEnter:i,onMouseLeave:l,className:this.className,tabIndex:0,role:"button","aria-expanded":!0,"aria-label":E.read?t.formatMessage({id:"2diM1",defaultMessage:"Comment thread"}):t.formatMessage({id:"sHIhB",defaultMessage:"Unread comment thread"}),ref:this.setRef,onClick:this.onClick},this.renderToplineControls(),n.createElement("ul",{className:"sc-thread-comments"},this.renderComment(E.comments[0],this.activeOrEditorHasText,u,E.annotation),y.map((function(t){return e.renderComment(t,!0,a.Comment)}))),this.includeEditor&&n.createElement(c.ThreadEditor,{author:M,disabled:this.isDisabled,shouldFocus:this.state.shouldFocusThreadEditor,mentionsMatches:h,onCancel:f,onEditorStateChange:this.onEditorStateChange,onMentionsQueryUpdated:s,onPost:m,onFocus:this.onFocusEditor,onBlur:this.onBlurEditor,stickerPacks:p}),n.createElement(d.ThirdPartyReplyCTA,{intl:t,thirdPartySource:E.isThirdParty?g:void 0,openWith:v}))},t.prototype.renderInactive=function(){var e=this.intl,t=this.props,o=t.actions,r=o.onMouseEnter,s=o.onMouseLeave,i=o.onFocus,d=o.onBlur,c=t.active,m=t.commentComponent,u=void 0===m?a.Comment:m,p=t.mentionsMatches,g=t.thread,E=t.isMobile,M=t.showRevisionInfo,y=t.thirdPartySource,b=this.filteredReplies;return n.createElement("li",{className:this.className,tabIndex:0,"aria-label":g.read?e.formatMessage({id:"2diM1",defaultMessage:"Comment thread"}):e.formatMessage({id:"sHIhB",defaultMessage:"Unread comment thread"}),role:"button","aria-expanded":!1,onClick:this.onClick,onKeyDown:this.handleKeyDown,onMouseEnter:r,onMouseLeave:s,onFocus:i,onBlur:d,ref:this.setRef},this.renderToplineControls(),n.createElement("ul",{className:"sc-thread-comments"},this.renderComment(g.comments[0],c,u,g.annotation),b.length>1&&n.createElement(v,{count:b.length-1}),b.length>0&&n.createElement(a.Comment,{active:!1,comment:h.truncateComment(b[b.length-1]),actions:{onClickTimeCode:f,onDeleted:f,onEdited:f,onMentionsQueryUpdated:f,onClickOlderInfo:f},mentionsMatches:p,onEndEdit:f,onStartEdit:f,isEditing:!1,isMobile:E,showRevisionInfo:M})),this.includeEditor&&n.createElement("div",{className:"sc-thread-reply-hint"},e.formatMessage({id:"2Wm7z",defaultMessage:"Reply…"})),n.createElement(l.ThreadSourceMessage,{thirdPartySource:g.isThirdParty?y:void 0,intl:e}))},t.prototype.render=function(){return this.props.thread.comments.every((function(e){return!!e.deleted}))?null:this.activeOrEditorHasText?this.renderActive():this.renderInactive()},t})(n.PureComponent);t.Thread=M,M.contextTypes={localization:m.object}})); //# sourceMappingURL=thread.min.js-vflPQUj7O.map