define(["require","exports","tslib","classnames","react","prop-types","external/lodash","deep-integrations/data/user_settings","modules/clean/file_store/utils","modules/clean/loggers/pass_facepile_logger","modules/clean/integrations/data/store","modules/clean/react/css","modules/clean/react/file_viewer/share_helpers","modules/clean/react/pass/avatars","modules/clean/react/pass/constants","modules/clean/react/pass/event_emitter","modules/clean/react/pass/empty_seen_state_facepile","modules/clean/react/pass/utils","modules/clean/react/pass/types","modules/clean/react/size_class/constants","modules/clean/sharing/constants","modules/clean/viewer","modules/core/i18n","modules/core/user_i18n","comments2/components/rich_facepile","spectrum/facepile"],(function(e,t,s,n,r,i,o,a,p,u,l,c,d,h,f,m,_,g,S,v,y,I,w,C,E,L){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),n=s.__importDefault(n),r=s.__importDefault(r),i=s.__importStar(i),o=s.__importStar(o),d=s.__importStar(d),C=s.__importStar(C);var P=(function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={newPresentUserIds:[]},t.hasPassShownBeenLogged=!1,t.onAvatarHover=function(){return t.logPassEvent(f.EventTypes.PASS_HOVER)},t.openShareModal=function(){d.share(t.props.file,I.Viewer.get_viewer().get_user_by_id(t.props.user.id),t.props.url||null,y.SHARE_ACTION_ORIGIN_TYPE.PREVIEW_PAGE_FACEPILE)},t.onAvatarClick=function(e){t.logPassEvent(f.EventTypes.PASS_CLICK);var s=t.context.getIntegrationStore(),n=t.getPromptsToDismiss(s);n.length>0&&l.wrapDispatch(s.dispatch)(a.dismissPrompts(n)),e===E.OVERFLOW&&t.openShareModal()},t.onTooltipChange=function(e,s){e.activeMode;var n=e.displayInfo,r=(s.activeMode,s.displayInfo);null!==r&&n!==r&&t.onAvatarHover()},t.localization={nOthers:function(e,t){return w.ungettext("%(display_num)s other","%(display_num)s others",e).format({display_num:t})},ninetyNinePlus:w._("99+")},t}return s.__extends(t,e),t.prototype.componentWillMount=function(){this.resetLogging(),u.passFacepileLogger.listenTo(m.passEventEmitter)},t.prototype.componentDidMount=function(){this.logFacepileShownEvents()},t.prototype.componentWillReceiveProps=function(e){if(p.areFilesEqual(this.props.file,e.file)){if(null==e.presence||null==this.props.presence)return;var t=o.difference(e.presence,this.props.presence),s=o.difference(this.props.presence,e.presence);this.updateNewPresentUserIds(t,s)}else this.setState({newPresentUserIds:[]}),this.resetLogging()},t.prototype.componentDidUpdate=function(e){this.logFacepileShownEvents()},t.prototype.componentWillUnmount=function(){u.passFacepileLogger.unlistenTo(m.passEventEmitter)},t.prototype.updateNewPresentUserIds=function(e,t){var s=o.filter(this.state.newPresentUserIds,(function(e){return-1===t.indexOf(e)}));this.setState({newPresentUserIds:e.concat(s)})},t.prototype.computeOverflowBasis=function(e){if(!this.props.uniqueMemberCountInfo.data)return e.length;var t=this.props.uniqueMemberCountInfo.data;return e.forEach((function(e){e.incrementOverflowBasis&&++t})),Math.max(t,e.length)},t.prototype.resetLogging=function(){this.hasPassShownBeenLogged=!1},t.prototype.logFacepileShownEvents=function(){if(!this.hasPassShownBeenLogged&&this.dataSufficientForLoggingHasLoaded()){var e=this.getUserInfoList();this.haveSeenStateDataToShow(e)&&(this.logPassEvent(f.EventTypes.PASS_SHOWN,e),this.hasPassShownBeenLogged=!0)}},t.prototype.logPassEvent=function(e,t){var s=this.props,n=s.anonymousPresenceInfo.length,r=s.file,i=s.passPermissions,o=this.getViewerCountByAccessLevel(),a=o.numViewers,p=o.numInTeamEditors,u=o.numInTeamViewers,l=o.numNonTeamEditors,c=o.numNonTeamViewers,d=this.computeOverflowBasis(t||this.getUserInfoList());return m.passEventEmitter.emit(e,!1,r,{numAccessors:d,numViewers:a,numCurrentViewers:this.getNumCurrentViewers(),canSeeViewerHistory:i&&i.canReadSeenState,numGuests:n,numInTeamEditors:p,numInTeamViewers:u,numNonTeamEditors:l,numNonTeamViewers:c})},t.prototype.getViewerCountByAccessLevel=function(){var e,t,s=this,n=0,r=0,i=0,o=0;if(this.shouldHardcodeCurrentViewer()){t=this.seenStateDataWithViewerFiltered(this.getSeenStates());var a=this.getSeenStates().filter((function(e){return e.seen_state_user.user_id===s.props.user.account_id}));if(a.length>0){e=0;var p=a[0];p.when_last_seen=1,t.push(p)}else e=1,n++}else e=0,t=this.getSeenStates();for(var u=0,l=t;u=0},t.prototype.userIsOnline=function(e){return null!=this.props.presence&&this.props.presence.indexOf(e.user_id)>=0},t.prototype.buildUserInfo=function(e){var t=e.platform_type,s=e.seen_state_user,n=e.seen_state_user,r=n.access_level,i=n.display_name,o=n.email,a=n.photo_circle_url,p=n.sharing_access_type,u=n.user_id,l=e.when_last_seen,c=u||i,d=g.shouldIncrementOverflowBasisForAccessType(p);return new S.UserInfo(c,i,this.userIsOnline(s),!1,d,o,r,l,a,u,t)},t.prototype.seenStateDataWithViewerFiltered=function(e){var t=this;return o.filter(e,(function(e){return e.seen_state_user.user_id!==t.props.user.account_id}))},t.prototype.partitionUserInfoLists=function(e){for(var t=[],s=[],n=[],r=[],i=[],o={},a=0,p=e;a=0},t.prototype.getMergedSeenStateData=function(){var e=this.getSeenStates(),t=e.map((function(e){return e.seen_state_user.user_id}));if(this.props.sharingStorePassInfo.data){for(var s=0,n=this.props.sharingStorePassInfo.data.users;s=0;return e||t},t.prototype.getSeenStates=function(){return this.props.identifiedSeenStateInfo&&this.props.identifiedSeenStateInfo.seen_states?this.props.identifiedSeenStateInfo.seen_states.slice():[]},t.prototype.haveSeenStateDataToShow=function(e){var t=e.length;return t>=2||1===t&&e[0].key!==this.props.user.account_id},t.prototype.dataSufficientForLoggingHasLoaded=function(){return this.sharingAndCountInfoHasLoaded()&&f.fetchingStatusCanLogAsShown(this.props.passFetchingStatus)},t.prototype.dataSufficientForDisplayHasLoaded=function(){return this.sharingAndCountInfoHasLoaded()&&f.fetchingStatusSeenStateIsComplete(this.props.passFetchingStatus)},t.prototype.sharingAndCountInfoHasLoaded=function(){var e=this.props,t=e.sharingStorePassInfo,s=e.uniqueMemberCountInfo;return t.isLoaded&&s.isLoaded},t.prototype.getPromptsToDismiss=function(e){return[{".tag":"tooltip_click_for_more"},{".tag":"tooltip_click_for_more_auto_display"}].filter((function(t){return!l.isPromptDismissed(e.getState(),t[".tag"])}))},t.prototype.render=function(){var e,t=this.props,s=t.isCollapsed,n=t.isPassPermissionsPending,i=t.passFetchingStatus,o=t.passPermissions;if(n||i===f.PassFetchingStatus.ERROR||null==o||!o.canReadPresence&&!o.canReadSeenState)return this.renderEmptyFacepile();if(!this.dataSufficientForDisplayHasLoaded())return r.default.createElement("div",null);var a=this.getUserInfoList();if(this.haveSeenStateDataToShow(a)){if(s)return this.renderCollapsedFacepile(a[0]);var p=this.computeOverflowBasis(a);return r.default.createElement("div",{className:this.facepileClassName()},r.default.createElement(E.RichFacepile,{avatarInfoList:this.computeAvatarInfos(a),becomePassiveOnOverflowAvatarClick:!0,localization:this.localization,onAvatarClick:this.onAvatarClick,onTooltipChange:this.onTooltipChange,overflowBasis:p,sizeClass:this.getConvertedSizeClass(),sizeClassToCircleCountOverrides:(e={},e[E.SizeClass.Small]=0,e[E.SizeClass.Large]=3,e),tooltipComponent:E.UtilTooltip}))}return this.renderEmptyFacepile()},t.prototype.getConvertedSizeClass=function(){switch(this.props.sizeClass){case v.SizeClass.Small:return E.SizeClass.Small;case v.SizeClass.Medium:return E.SizeClass.Medium;case v.SizeClass.Large:return E.SizeClass.Large;case v.SizeClass.ExtraLarge:return E.SizeClass.ExtraLarge}},t.prototype.renderEmptyFacepile=function(){return r.default.createElement(_.EmptySeenStateFacepile,{hasPresence:null!=this.props.presence})},t.prototype.renderCollapsedFacepile=function(e){var t=e.isActive,s=e.displayName,n=e.photoUrl;return r.default.createElement(L.FacepileMembersAvatar,{active:t,avatarColorSeed:s,avatarSize:32,initials:C.getInitials(s),photoUrl:n||null,disabled:!0})},t.prototype.facepileClassName=function(){var e;return n.default(((e={})[f.FACEPILE_CLASSNAME]=!0,e[f.PRESENCE_RECEIVED_CLASSNAME]=null!=this.props.presence,e))},t.prototype.computeAvatarInfos=function(e){if(0===e.length)return[];var t=this.context.getIntegrationStore(),s=this.context.logEvent(),n=this.context.performanceTimer(),i=this.context.reportError(),o=this.props,a=o.file,u=o.file.file_id,l=o.user.id,c=p.getFilename(a);return e.slice(0,E.MAX_FACES).map((function(e){var o=(function(e){var t=e.userId,s=e.displayName;return t&&g.AnonymousViewerUtils.isAnonymousUserId(t)?{colorSeed:t,initials:g.AnonymousViewerUtils.getAnonymousViewerInitials(s)}:{colorSeed:s,initials:C.getInitials(s)}})(e),a=o.colorSeed,p=o.initials,d=e.isActive,f=e.displayName,m=e.key,_=e.userId;return{present:d,displayName:f,avatarColorSeed:a,initials:p,memberKey:m,photoUrl:e.photoUrl||null,userId:_,passiveTooltipContent:r.default.createElement(h.UserAvatarPassiveTooltipContent,{colorSeed:a,integrationStore:t,userInfo:e}),activeTooltipContent:r.default.createElement(h.UserAvatarActiveTooltipContent,{colorSeed:a,integrationStore:t,integrationInfo:{fileId:u,fileName:c,userId:l},logEvent:s,performanceTimer:n,reportError:i,userInfo:e})}}))},t.contextTypes={getIntegrationStore:i.func,logEvent:i.func,performanceTimer:i.func,reportError:i.func},t})(r.default.Component);t.SeenStateFacepileComponentSpectrumized=P,t.SeenStateFacepileSpectrumized=c.requireCssWithComponent(P,["/static/css/seen_state_facepile-vflu8S6gi.css","/static/js/deep-integrations/index.web-vfl7Ht8xl.css","/static/js/comments2/index.web-vfl8qQuOT.css"])})); //# sourceMappingURL=seen_state_facepile_spectrumized.min.js-vfl1jjE4d.map