var __extends=this&&this.__extends||function(){var n=function(t,i){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,t){n.__proto__=t}||function(n,t){for(var i in t)t.hasOwnProperty(i)&&(n[i]=t[i])},n(t,i)};return function(t,i){function r(){this.constructor=t}n(t,i);t.prototype=i===null?Object.create(i):(r.prototype=i.prototype,new r)}}(),AutoSuggest;(function(n){var t;(function(t){var r="NT",b="NF",i="https://substrate.office.com{0}/api/v1/",k=i+"events",h=i+"init",d=i+"suggestions?query=",g=i+"query",nt=i+"recommendations",c="SubstrateSearchService",tt="https://outlook.office365.com/autodiscover/autodiscover.json/v1.0/{0}?Protocol={1}",u="AutoDiscoveryKey",l="3sflights",it="3sdebug",e="gwsflt.",rt="textdecorations",a="scenario",ut="setflight",ft="debug",v="entitytypes",et="1",ot="scopes",st="people.directorysearch",ht="Authorization",o="Content-Type",ct="X-AnchorMailbox",lt="X-Client-Language",at="X-Client-LocalTime",y="Client-Request-Id",p="User-Agent",vt="X-Debug-ExternalExp",yt="X-Client-Flights",s="application/json",pt=6e4,f,w=!1,wt=function(i){function wt(r,o,s,c,a,v){var y=i.call(this,wt.getDataSource(c,a))||this,k,p,d,g,b;return y._host=r,y._accessTokenManager=o,y._instrumentationHelper=s,y._authType=c,y._providerType=a,y._storage=v,y._autoDiscoveryData={stem:"/search",timestamp:-1},w||(w=!0,p=t.config.enable3SPeopleGroups?["WSBGroups"]:[],d=function(n){return n.split(",").filter(function(n){return n.toLocaleLowerCase().startsWith(e)}).map(function(n){return n.substr(e.length)})},t.config.th&&p.push.apply(p,d(ClientTestHooks.getUrlValue(l,""))),f=p.join(","),ThresholdUtilities.getCortanaHeaders(function(n){var t,i;n&&(t=n["X-BM-ClientFeatures"],t&&(i=d(t),i.length>0&&(p.push.apply(p,i),f=p.join(","))))})),t.config.th&&ClientTestHooks.isTesthookParamSet("clearAutoDCache")&&y._storage.removeItem(u),g=y._storage.getItem(u),g&&(b=n.safeExecute(function(){return JSON.parse(g)},"parseAutoDiscovery",null),b&&!b.errorState?y._autoDiscoveryData=b:y._storage.removeItem(u)),y._host.bindAccessTokenAvailable(function(t){var r,f,i;if(t==y._authType){if(y._providerType==0){if(r=n.getCurrentTime(),k&&(f=r-k,f<pt))return;k=r;y.fetchUrl(h,null,"",function(){},null,function(){return!0})}i=n.getCurrentDate();i.setDate(i.getDate()-1);y._autoDiscoveryData.timestamp<i.getTime()&&y.getStem()(t,function(t){t.timestamp=n.getCurrentTime();y._autoDiscoveryData=t;t.errorState||y._storage.setItem(u,JSON.stringify(t))})}}),y}return __extends(wt,i),wt.prototype.getName=function(){return"SubstrateDataProvider "+this._dataSource},wt.prototype.createUrl=function(r){if(this._providerType==1)return r.queryToFetch?this.getBaseUrl():nt;if(r.scope==t.Scope.Documents){var u=t.getEffectiveQuery(r);if(u!=r.queryToFetch)return this.getBaseUrl()+n.encodeQueryParameter(u.toLocaleLowerCase())}return i.prototype.createUrl.call(this,r)},wt.prototype.getBaseUrl=function(){return this._providerType==1?g:d},wt.getDataSource=function(n,t){return t==0?n==1?"SSUE":"SSUC":n==1?"SSEE":"SSEC"},wt.prototype.getPostBody=function(n){var i,u,f,r;if(this._providerType==1){if(i=void 0,u=t.getEffectiveScope(n),u==t.Scope.All&&t.RuntimeConfig.QfMode!=5)throw new Error("Unsupported scope "+n.scope);switch(u){case t.Scope.PeopleEmail:case t.Scope.Emails:f=[{Score:{SortDirection:"Desc",Count:t.config.maxNumberOfEmailsInTopResult}},{Time:{SortDirection:"Desc"}}];i=this.buildPostBodyForQueryEndpoint(n,"Message",["Exchange"],f);break;case t.Scope.Documents:case t.Scope.AllFiles:case t.Scope.FilesFolders:case t.Scope.All:if(r=void 0,n.queryToFetch){switch(t.config.queryProvenances){case 0:r=["SharePoint"];break;case 1:r=["OneDriveBusiness"];break;case 2:r=["SharePoint","OneDriveBusiness"];break;default:throw new Error("Unexpected query provenances: "+t.config.queryProvenances);}i=this.buildPostBodyForQueryEndpoint(n,"Documents",r,[{Score:"Desc"}])}else i=this.buildPostBody("Document","OpenFile");break;default:throw new Error("Unsupported scope "+n.scope);}return JSON.stringify(i)}return""},wt.prototype.buildPostBodyForQueryEndpoint=function(n,t,i,r){return this.buildPostBody(t,"WindowsSearchBoxL2",n.queryToFetch,i,r,"ProvenanceOptimized","Forward")},wt.prototype.buildPostBody=function(n,t,i,r,u,f,e){return{EntityRequests:[{Query:i?{QueryString:i}:undefined,EntityType:n,Provenances:r,Sort:u,PropertySet:f}],Cvid:this._host.getConversationId(),TextDecorations:e,Scenario:{Name:t}}},wt.prototype.getStem=function(){var u=this;return t.Promise.safeChainWithGlobalCaching("getStem",function(f){return ThresholdUtilities.createPromise(function(e){u._accessTokenManager.getAccount(f,t.getSubstrateResourceOrScope(f),!1,!0,function(t){var h,f,l;t&&t.UserName?(h=n.formatString(tt,[t.UserName,c]),f={},f[o]=s,f[y]=u._host.getConversationId(),f[p]=navigator.userAgent,l=function(t,i,r){var u,f,o;if(r){e({stem:"",errorState:r});return}if(u=i,!u){e({stem:""});return}if(!u.Url){e({stem:"",errorState:"NAU"});return}if(u.Protocol!=c){e({stem:"",errorState:"NAP"});return}if(f=n.tryParseUrl(u.Url,!0),o=f?f.path:null,!o){e({stem:"",errorState:"NAS"});return}e({stem:o})},i.prototype.fetchUrl.call(u,h,f,"",l,null,function(){return!0})):e({stem:"",errorState:r})})})},function(){return"autoDiscovery"})},wt.prototype.getAllAccountTokens=function(n,i){if(n||t.RuntimeConfig.QfMode!=5)this._accessTokenManager.getAccount(this._authType,t.getSubstrateResourceOrScope(this._authType),!1,!0,function(n){n&&n.Token?i([n]):i(null,r)});else{var u=SearchAppWrapper.CortanaApp.fileExplorerSuggestionPage.currentSyncRootAccount;u?this._accessTokenManager.getAccountByUserName(!0,1,u,!1,!0,function(n){n&&n.Token?i([n]):i(null,r)}):t.isFileExplorerCurrentPathThisPcOrQuickAccess?this._accessTokenManager.getAllSyncingAccounts(!0,1,!1,!0,function(n){n.length>0?i(n):i(null,r)}):(SharedLogHelper.LogError("fetchUrl",null,new Error("Substrate provider called without currentSyncRootAccount")),i(null,b))}},wt.prototype.fetchUrl=function(r,u,f,e,o,s){var l=this,v,c,a;if(!this._autoDiscoveryData.stem){e(this._dataSource,null,this._autoDiscoveryData.errorState,null,!0);return}v=r==h;r=n.formatString(r,[this._autoDiscoveryData.stem]);u||(u={});c={numOfPendingResponses:0};a=function(n){var h=Object.assign({},u);h[ht]="Bearer "+n.Token;l._authType==1&&!t.SubstrateTenantName&&n.TenantName&&(t.SubstrateTenantName=n.TenantName);h[ct]=n.RoutingHint;i.prototype.fetchUrl.call(l,r,h,f,function(n,t,i,r,u){--c.numOfPendingResponses;e(n,t,i,r,u,c.numOfPendingResponses!=0)},o,s)};this.getAllAccountTokens(v,function(n,t){t?e(l._dataSource,null,t,null,null,!1):n?(c.numOfPendingResponses=n.length,n.forEach(function(n){return a(n)})):(c.numOfPendingResponses=1,a(null))})},wt.prototype.fetch=function(r,u,e,h,c,l){var w=this,a,b,k;if(n.isDataSourceEnabled(this._dataSource,r)){if(a={},a[lt]=t.uiLanguageCache,a[at]=n.getDateWithTimezone(),a[p]=navigator.userAgent,typeof _CachedFlights!="undefined"&&_CachedFlights.sort&&(a[vt]=_CachedFlights.sort().join(",")),a[y]=this._instrumentationHelper.getImpressionGuid(e),b=this.buildParams(l,r.scope,!r.queryToFetch),this._providerType==0){if(!b[v])return}else a[o]=s;f&&(a[yt]=f);k=function(i,r,f,e,o,s){var h=parseInt(f);(h==403||h==401)&&n.safeSetTimeout(function(){return w._accessTokenManager.getAccount(w._authType,t.getSubstrateResourceOrScope(w._authType),!0,!0,function(){})},0,"SubstrateDataProvider onResponseReceived");u(i,r,f,e,o,s)};i.prototype.fetch.call(this,r,k,e,h,c,b,a)}},wt.prototype.buildParams=function(i,r,u){var f={},o;return this._providerType==0&&(f[n.Service.QueryParams.ConversationId]=i[n.Service.QueryParams.ConversationId],f[rt]=et,this._authType!=1||u||r!=t.Scope.People?r!=t.Scope.All&&(f[a]=ot):f[a]=st,f[v]=this.getEntityTypes(r)),t.config.th&&(o=ClientTestHooks.getUrlValue(l,"").split(",").filter(function(n){return!n.toLocaleLowerCase().startsWith(e)}).join(","),o&&(f[ut]=o),ClientTestHooks.isTesthookParamSet(it)&&(f[ft]="1")),f},wt.prototype.getEntityTypes=function(n){var i,r;switch(n){case t.Scope.Documents:case t.Scope.AllFiles:case t.Scope.FilesFolders:i="Documents";break;case t.Scope.PeopleEmail:case t.Scope.People:i="People";break;case t.Scope.All:r=[];this._authType==1&&r.push("Documents");t.RuntimeConfig.QfMode==5||t.config.ssPeopleOff||r.push("People");i=r.join(",");break;default:throw new Error("Unsupported scope "+n);}return i},wt.prototype.instrumentClick=function(t,i){if(t&&i){var u=[{Key:t,Value:[{Name:"entityclicked",Attributes:[{Key:"id",Value:i},{Key:"localtime",Value:n.getDateWithTimezone()}]}]}],r={};r[o]=s;this.fetchUrl(k,r,JSON.stringify(u),function(){},null,function(){return!0})}},wt}(t.CortanaJsonDataProvider);t.SubstrateDataProvider=wt})(t=n.WSB||(n.WSB={}))})(AutoSuggest||(AutoSuggest={})),function(n){var t;(function(t){function l(n,i,r){var u=t.OfficeTypeExtensionConfigs[n];u?t.LocalDataProvider.getApps(u.appIds,function(n){var f=!t.Map.isEmpty(n);f?i(u.uri):r()}):r()}function a(n,t,i){l(t,function(t){return i.launchUri(t+n)},function(){return i.launchUri(n+"?web=1")})}function v(n,i,r,u,f){t.setExtraVerbs(n,function(){var i=[];return i.push({verb:t.JumplistActionItemType[t.JumplistActionItemType.S_OpenInBrowser],displayName:f.getLocString("OpenInBrowser"),executeSync:function(){return f.launchUri(r)},icon:{type:1,content:"&#xE774"}}),n.locationUrl&&i.push({verb:t.JumplistActionItemType[t.JumplistActionItemType.S_OpenFileLocationInBrowser],displayName:f.getLocString("OpenFileLocationIn",u),executeSync:function(){return f.launchUri(n.locationUrl)},icon:{type:2,content:"&#xE838"}}),n.url&&SearchAppWrapper.CortanaApp.copyToClipboard&&i.push({verb:t.JumplistActionItemType[t.JumplistActionItemType.S_CopyFullPath],displayName:f.getLocString("CopyFullPath"),executeSync:function(){return SearchAppWrapper.CortanaApp.copyToClipboard(n.url,"")},icon:{type:1,content:"&#xE8C8"}}),i},!1)}function y(n,t,i,r){var f,e=t.toLocaleLowerCase(),s=decodeURI(i).toLocaleLowerCase().indexOf(e),u,o;s!=-1&&(f=i.substr(0,s-1),e.endsWith(".one")&&(f=f.substr(0,f.lastIndexOf("/"))));u=decodeURI(i).split("/");r?(o="OneDrive for Business:\\",u.length>5&&u[3].toLocaleLowerCase()=="personal"&&u[5].toLocaleLowerCase()=="documents"&&(u=u.slice(6))):(u=u.slice(3),o="SharePoint:\\");e.endsWith(".one")&&u.splice(u.length-2,1);n.path=o+u.join("\\");n.url=i;f&&(n.locationUrl=f)}function h(i,r,u,f,e,o,s,h,c,l,p,w,b,k,d,g,nt,tt,it){var et=t.ScopeConfig[t.Scope.Documents].icon,ot=r+"?web=1",ut,rt,ft;return f=HitHighlightingParser.removeMarkers(f),e&&(e=e.toLocaleLowerCase()),ut="FL",rt=t.createSuggestion(i,u,t.getIconForTypeAsync(et,"."+e),et,ut,f,n.InstrumentedItem.createInstrumentedItem(b,ut),8,b,!0),rt.instrumentPingBack=w,rt.click=function(){return a(r,e,g)},rt.extensionLC="."+e,rt.lastModifiedDate=t.toDate(s),rt.lastModifiedBy=h,rt.author=c,rt.matchedOnlyOnAuthor=l,rt.matchedOnlyOnContent=p,rt.textContentIfMatched=nt,ft=o?3:4,y(rt,f,r,o),o||(rt.siteTitle=it),l?rt.match=t.createMatch(t.MatchType.Author,c):u.includes(HitHighlightingParser.startMarker)||(rt.match=t.tryGetLocationMatch(rt.path,k)||tt),rt.sourceForGroup=ft,t.setFileTemplate(i,k,d,rt,g),v(rt,e,ot,t.getGroupSourceDisplayName(ft,g),g),rt}var u={Word:{appIds:["Microsoft.Office.WINWORD.EXE.15","Microsoft.Office.WINWORD.EXE.16","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office15\\WINWORD.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office15\\WINWORD.EXE","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office16\\WINWORD.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office16\\WINWORD.EXE","Microsoft.Office.Word_8wekyb3d8bbwe!microsoft.word"],uri:"ms-word:ofe|u|"},Excel:{appIds:["Microsoft.Office.EXCEL.EXE.15","Microsoft.Office.EXCEL.EXE.16","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office15\\EXCEL.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office15\\EXCEL.EXE","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office16\\EXCEL.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office16\\EXCEL.EXE","Microsoft.Office.Excel_8wekyb3d8bbwe!microsoft.excel"],uri:"ms-excel:ofe|u|"},PowerPoint:{appIds:["Microsoft.Office.POWERPNT.EXE.15","Microsoft.Office.POWERPNT.EXE.16","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office15\\POWERPNT.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office15\\POWERPNT.EXE","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office16\\POWERPNT.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office16\\POWERPNT.EXE","Microsoft.Office.PowerPoint_8wekyb3d8bbwe!microsoft.pptim"],uri:"ms-powerpoint:ofe|u|"},Visio:{appIds:["{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office15\\VISIO.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office14\\VISIO.EXE","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office16\\VISIO.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office16\\VISIO.EXE","Microsoft.Office.VISIO.EXE.15"],uri:"ms-visio:ofe|u|"},OneNote:{appIds:["Microsoft.Office.ONENOTE.EXE.15","Microsoft.Office.ONENOTE.EXE.16","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office15\\ONENOTE.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office15\\ONENOTE.EXE","{6D809377-6AF0-444B-8957-A3773F02200E}\\Microsoft Office\\Office16\\ONENOTE.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\\Microsoft Office\\Office16\\ONENOTE.EXE","Microsoft.Office.OneNote_8wekyb3d8bbwe!microsoft.onenoteim"],uri:"onenote:"}},e="sip:",c=["Microsoft.Office.lync.exe.15","{6D809377-6AF0-444B-8957-A3773F02200E}Microsoft OfficeOffice15lync.exe","{6D809377-6AF0-444B-8957-A3773F02200E}Microsoft OfficeOffice16lync.exe","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}Microsoft OfficeOffice15lync.exe","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}Microsoft OfficeOffice16lync.exe","{6D809377-6AF0-444B-8957-A3773F02200E}MSOfficeOffice15lync.exe","{6D809377-6AF0-444B-8957-A3773F02200E}MSOfficeOffice16lync.exe","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}MSOfficeOffice15lync.exe","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}MSOfficeOffice16lync.exe","Microsoft.Office.Desktop_8wekyb3d8bbwe!Lync","com.squirrel.Teams.Teams",],i=u.Word,r=u.Excel,f=u.PowerPoint,o=u.Visio,s;t.OfficeTypeExtensionConfigs={doc:i,dot:i,dotx:i,docx:i,docm:i,docb:i,xls:r,xlm:r,xlsx:r,xlsm:r,xlsb:r,xltx:r,ppt:f,pps:f,pptx:f,pptm:f,vsd:o,vsdx:o,one:u.OneNote};s=function(){function i(n,t,i,r,u,f,e){this._host=n;this._substrateSuggestionsDataProvider=t;this._instrumentationHelper=i;this._accessTokenManager=r;this._substrateProfilePictureProvider=u;this._sequenceNumberReader=f;this._authType=e;this._mailboxLocations={}}return i.prototype.parse=function(i,r,u,f,e,o){var l=this,s;if(n.isDataSourceEnabled(u,i)){if(s=[],!f||!f.Groups){o(u,s,null);return}var a=u=="SSUE"?t.config.aadPeopleCardHandoffEnabled&&!t.config.ssPeopleOff:t.config.msaPeopleCardHandoffEnabled,p=t.getEffectiveQuery(i),v=t.isL2(i),y=function(c){for(var y,it,rt,b,nt,ut,ft,d,tt,k,w=0,g=f.Groups;w<g.length;w++)if(y=g[w],y.Suggestions&&y.Suggestions.length)switch(y.Type){case"Documents":for(it=y.Suggestions,rt=function(u){var e=n.safeExecute(function(){return h(i,u.Url,u.Text,u.FileName,u.FileExtension,u.FileSourceType=="OneDriveForBusiness",u.DateModified,null,u.CreatedBy||HitHighlightingParser.removeMarkers(u.Author),u.PropertyHits&&u.PropertyHits[0]=="Author",!1,function(){return l._substrateSuggestionsDataProvider.instrumentClick(f.Instrumentation.TraceId,u.ReferenceId)},r,p,v,l._host,"",null,u.SourceTitle||"")},"buildSubstrateDocumentSuggestion");e&&t.isValidSuggestion(e,"SubstrateDocumentsSuggestionsParser")&&s.push(e)},b=0,nt=it;b<nt.length;b++)k=nt[b],rt(k);t.decorateSuggestionsWithParentFolder(s,l._host);break;case"People":for(ut=y.Suggestions,ft=function(e){var o=n.safeExecute(function(){return l.buildPersonSuggestion(a,e,r,f.Instrumentation.TraceId,v,u,i,c)},"buildPersonSuggestion");o&&t.isValidSuggestion(o,"SubstratePeopleSuggestionsParser")&&s.push(o)},d=0,tt=ut;d<tt.length;d++)k=tt[d],ft(k);a&&n.safeExecute(function(){return l.prefetchPeopleCards(s.filter(function(n){return n.type=="PPL"}),r,e)},"prefetchPeopleCards");t.isL2(i)||l.decorateContactsWithSameDisplayName(s,i);break;default:SharedLogHelper.LogError("parseSubstrateResponse",y.Type,new Error("Unexpected group type"))}o(u,s,null)};u=="SSUE"?t.LocalDataProvider.getApps(c,function(n){return y(!t.Map.isEmpty(n))}):y(!1)}},i.prototype.prefetchPeopleCards=function(n,i,r){var u=this;n.length&&this.getPeopleCardTokenAndMailboxLocation(function(f){var s,e,o,h;f&&f.token&&f.location&&i==u._sequenceNumberReader.getSequenceNumber()&&r()&&(s=f.location+"api/v1/personacards/preparePersona",e=SearchAppWrapper.CortanaApp.createStringMap(),e.Authorization="Bearer "+f.token,e["X-ClientCorrelationId"]=u._instrumentationHelper.getImpressionGuid(i),e["X-ClientType"]="6",o=SearchAppWrapper.CortanaApp.createStringMap(),o["Content-Type"]="application/json",h=JSON.stringify(n.map(function(n){return{Smtp:n.email,PersonaType:"User"}})),t.Promise.safeChain("prefetchPeopleCards",function(){return SearchAppWrapper.CortanaApp.makeHttpRequestAsync(1,s,e,h,o)},function(n){if(n.statusCode!=200&&n.statusCode!=204){var t=new Error("Prefetch request failed with status code: "+n.statusCode);SharedLogHelper.LogError("prefetchPeopleCards",null,t)}}))})},i.prototype.buildPersonSuggestion=function(i,r,u,f,o,s,h,c){var y=this,g,a,nt,b,et;if(!r.EmailAddresses||!r.EmailAddresses[0])return null;var ot=r.PeopleType=="Group",tt=r.EmailAddresses[0],v=HitHighlightingParser.removeMarkers(tt),w,it;ot?w={content:"&#xE716",type:2}:(w=this._substrateProfilePictureProvider.getPersonDefaultIcon(r.DisplayName),it=this._substrateProfilePictureProvider.getProfilePictureIcon(this._authType,v,w));var rt=s=="SSUE",ut="PPL",l=t.createSuggestion(h,r.Text,it,w,ut,r.DisplayName,n.InstrumentedItem.createInstrumentedItem(u,ut),rt?8:12,u,!0),k=r.Id,d;rt&&(g=r.Id.split("@"),k=g[0],d=g[1]);l.email=v;l.emailHH=tt;l.uniqueName=v;a=r.ImAddress;a&&!a.startsWith(e)&&(a=a.includes(":")?undefined:e+a);a&&(l.imAddress=a,nt=a.substr(e.length),nt!=v&&(l.alternativeEmail=nt));b=k&&d&&!i;l.tooltip=this.getPersonTooltip(r.DisplayName,r.Department,r.JobTitle,r.OfficeLocation,r.CompanyName,v,l.alternativeEmail);l.instrumentPingBack=function(){return y._substrateSuggestionsDataProvider.instrumentClick(f,r.ReferenceId)};l.click=function(n){return y.onPersonSuggestionClick(i,b,v,l.query,u,n,k,d)};var ft=this._host.getLocString("Email"),st=function(){return y._host.launchUri("mailto:"+v)},p={};return p[ft]=[{text:v,click:st}],l.alternativeEmail&&(et=function(){return y._host.launchUri("mailto:"+l.alternativeEmail)},p[ft].push({text:l.alternativeEmail,click:et})),r.OfficeLocation&&(p[this._host.getLocString("Location")]=[{text:r.OfficeLocation}]),r.CompanyName&&(p[this._host.getLocString("Company")]=[{text:r.CompanyName}]),l.previewMetadata=p,l.department=r.Department,this.setPersonTemplate(l,o,r.JobTitle,h),this.setPersonContextMenuItems(l,i||b,c),!t.RuntimeConfig.AlwaysWide&&(i||b)&&(l.calculateChildSuggestions=function(){return y.getPersonChildSuggestions(h,l,u,s,c)}),l},i.prototype.getPersonChildSuggestions=function(n,t,i,r,u){var f=[];f.push(this.getChildSuggestion(n,t,"CortanaAnnotation_Email","&#xE715","mailto:"+t.email,"PPLE",i));t.imAddress&&u&&f.push(this.getChildSuggestion(n,t,"SendInstantMessage","&#xE8BD",t.imAddress,"PPLM",i));t.childSuggestions=f;t.calculateChildSuggestions=null;this._instrumentationHelper.instrumentDataSource(i,r,t.childSuggestions,null)},i.prototype.getChildSuggestion=function(i,r,u,f,e,o,s){var l=this,c=this._host.getLocString(u),h=t.createSuggestion(i,c,null,{type:2,content:f},o,c,n.InstrumentedItem.createInstrumentedItem(s,o),r.handoffType,s,!1,null,null,!0);return h.parent=r,h.groupType=t.GroupType.Contact,h.click=function(){return l._host.launchUri(e)},h.instrumentPingBack=r.instrumentPingBack,h},i.prototype.getPeopleCardTokenAndMailboxLocation=function(i){var r=this;this._accessTokenManager.getAccount(this._authType,this._authType==1?"394866fc-eedb-4f01-8536-3ff84b16be2a":"LiveProfileCard.Access",!1,!0,function(u){var f,o,s,e;if(!u||!u.Token){i(null);return}if(f=u.Token,o=r._mailboxLocations[u.RoutingHint],o){i({token:f,location:o});return}s=SearchAppWrapper.CortanaApp.createStringMap();e=SearchAppWrapper.CortanaApp.createStringMap();e.Authorization="Bearer "+f;e["X-ClientType"]="6";t.Promise.safeChain("lokiConfiguration",function(){return SearchAppWrapper.CortanaApp.makeHttpRequestAsync(0,t.config.peopleCardLokiHost+"api/v1/configuration/cortana",e,"",s)},function(e){if(e.statusCode!==200){i(null);return}t.Promise.safeChain("lokiConfigurationResponse",function(){return e.readAsStringAsync()},function(t){if(!t){i(null);return}var e=n.safeExecute(function(){return JSON.parse(t)},"parseLokiConfiguration");if(!e||!e.LokiUrl){i(null);return}r._mailboxLocations[u.RoutingHint]=e.LokiUrl;i({token:f,location:e.LokiUrl})},function(){return i(null)})},function(){return i(null)})})},i.prototype.getSharePointHost=function(n){for(var f,i,e,t,s,l,a,v=new DOMParser,u=0,h=n.value;u<h.length;u++)if(f=h[u],f.serviceElements)for(i=0,e=f.serviceElements;i<e.length;i++){var y=e[i],p=v.parseFromString(y,"text/xml"),r=p.getElementsByTagName("ServiceParameter"),o=void 0,c=!1;for(t=0;t<r.length;t++)if(s=r[t].getElementsByTagName("Name"),s[0].childNodes[0].nodeValue=="IsDefaultDataLocation"?(l=r[t].getElementsByTagName("Value"),l[0].childNodes[0].nodeValue=="True"&&(c=!0)):s[0].childNodes[0].nodeValue=="SPO_MySiteHost_AboutMeUrl"&&(a=r[t].getElementsByTagName("Value"),o=a[0].childNodes[0].nodeValue),c&&o)return o}return null},i.prototype.onPersonSuggestionClick=function(i,r,u,f,e,o,s,h){var c=this,l=function(){return c._host.launchUri("mailto:"+u)},a=function(){var i=function(){return c._host.launchUri(c._sharePointSiteHostUrl+"?aadObjectId="+s)};c._sharePointSiteHostUrl?i():c._accessTokenManager.getAccount(1,"https://graph.windows.net/",!1,!0,function(r){if(!r||!r.Token){l();return}var f=SearchAppWrapper.CortanaApp.createStringMap(),u=SearchAppWrapper.CortanaApp.createStringMap();u.Authorization="Bearer "+r.Token;t.Promise.safeChain("getSharePointUrl",function(){return SearchAppWrapper.CortanaApp.makeHttpRequestAsync(0,"https://graph.windows.net/"+h+"/tenantDetails/"+h+"/serviceInfo?api-version=1.6-internal",u,"",f)},function(r){if(r.statusCode!==200){l();return}t.Promise.safeChain("readSharePointUrlResponse",function(){return r.readAsStringAsync()},function(t){var r=t?n.safeExecute(function(){return JSON.parse(t)},"parseSharePointUrlResponse"):null;if(!r){l();return}c._sharePointSiteHostUrl=c.getSharePointHost(r);c._sharePointSiteHostUrl?i():l()},l)},l)})};i?this.getPeopleCardTokenAndMailboxLocation(function(n){if(e==c._sequenceNumberReader.getSequenceNumber())if(n&&n.token&&n.location){var i=n.location+"api/v1/personacard?clientType=Cortana&userSmtp="+u+"&ClientCorrelationId="+c._instrumentationHelper.getImpressionGuid(e)+"&cts="+o+"&CultureInfoName="+t.uiLanguageCache;c._host.launchWebContent(i,f,n.token)}else r?a():l()}):r?a():l()},i.prototype.setPersonContextMenuItems=function(n,i,r){var u=this;t.setExtraVerbs(n,function(){var f=[],e=n.childSuggestions&&n.childSuggestions.some(function(n){return n.displayed});return e||(f.push({verb:t.JumplistActionItemType[t.JumplistActionItemType.S_SendEmail],displayName:u._host.getLocString("CortanaAnnotation_Email"),executeSync:function(){return u._host.launchUri("mailto:"+n.email)},isDefault:!i,icon:{content:"&#xE715",type:2}}),n.imAddress&&r&&f.push({verb:t.JumplistActionItemType[t.JumplistActionItemType.S_SendInstantMessage],displayName:u._host.getLocString("SendInstantMessage"),executeSync:function(){return u._host.launchUri(n.imAddress)},icon:{content:"&#xE8BD",type:2}})),SearchAppWrapper.CortanaApp.copyToClipboard&&f.push({verb:t.JumplistActionItemType[t.JumplistActionItemType.S_CopyPersonDetails],displayName:u._host.getLocString("CopyDetails"),executeSync:function(){return SearchAppWrapper.CortanaApp.copyToClipboard(n.tooltip.replace(/\n/g,"\r\n"),"")},icon:{type:1,content:"&#xE8C8"}}),f},!0)},i.prototype.setPersonTemplate=function(n,i,r,u){var e=t.getEffectiveQuery(u),f;r?(n.jobTitle=r,n.primaryMetadata=r):n.text!=n.emailHH&&(n.primaryMetadata=n.emailHH);e&&(n.text.includes(HitHighlightingParser.startMarker)||(n.emailHH.includes(HitHighlightingParser.startMarker)?(n.template=1,n.primaryMetadata=n.emailHH):n.alternativeEmail&&(f=HitHighlightingParser.addMarkers(n.alternativeEmail,e),f.includes(HitHighlightingParser.startMarker)&&(n.template=1,n.primaryMetadata=f))));n.narratorText=t.getNarratorText(n);i?(n.template=u.isSearchHomeZI?0:1,u.isSearchHomeZI||n.classNames.push("people","topResultTemplateInGroups")):n.template==1&&n.classNames.push("forceNoWrapOutsideTopResult")},i.prototype.getPersonTooltip=function(n,t,i,r,u,f,e){var h="",c=[n,i,t,r,u],o,l,s;for(n!=f&&c.push(f),e&&n!=e&&c.push(e),o=0,l=c;o<l.length;o++)s=l[o],s&&(h+=h?"\n"+s:s);return h},i.prototype.decorateContactsWithSameDisplayName=function(n,i){for(var r,e,u,f=0;f<n.length-1;++f)if(r=n[f],r.type=="PPL")for(e=f+1;e<n.length;++e)if(u=n[e],u.type=="PPL"&&r.text.toLocaleLowerCase()==u.text.toLocaleLowerCase()){t.isL2(i)||(r.template!=1&&r.classNames.push("forceNoWrapOutsideTopResult"),u.template!=1&&u.classNames.push("forceNoWrapOutsideTopResult"));r.template=u.template=1;r.primaryMetadata=r.emailHH;u.primaryMetadata=u.emailHH;break}},i}();t.SubstrateSuggestionsParser=s;t.buildSubstrateDocumentSuggestion=h})(t=n.WSB||(n.WSB={}))}(AutoSuggest||(AutoSuggest={})),function(n){var t;(function(t){function u(n,t){return function(){return n(t)}}var f=["Microsoft.Office.OUTLOOK.EXE.15","Microsoft.Office.OUTLOOK.EXE.16","{6D809377-6AF0-444B-8957-A3773F02200E}Microsoft OfficeOffice15OUTLOOK.EXE","{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}Microsoft OfficeOffice15OUTLOOK.EXE"],i="OutlookLaunchPref",r=[0,1],e=function(){function e(n,t,i,r,u){this._host=n;this._substrateSuggestionsDataProvider=t;this._lightweightStorage=i;this._accessTokenManager=r;this._authType=u;this._outlookLaunchPreference={}}return e.prototype.parse=function(i,r,u,f,e,o){var w=this,s,a,h,c,v,y,b,k,l,p,d;if(n.isDataSourceEnabled(u,i)){if(s=[],!f||!f.EntitySets){o(u,s,null);return}for(a=t.getEffectiveQuery(i),h=t.getEffectiveScope(i),c=0,v=f.EntitySets;c<v.length;c++)if(y=v[c],y.ResultSets)for(b=function(e){var p,o,v,b,l,y,c;if(e.Results)if(h==t.Scope.All&&t.RuntimeConfig.QfMode!=5)SharedLogHelper.LogError("parseSubstrateSearchResponse",h.toString(),new Error("Unexpected scope"));else switch(h){case t.Scope.PeopleEmail:case t.Scope.Emails:for(p=function(e){var o=n.safeExecute(function(){return w.buildMessageSuggestion(i,e.Source,r,u,f.Instrumentation?f.Instrumentation.TraceId:null,e.ReferenceId,a)},"buildMessageSuggestion");o&&t.isValidSuggestion(o,"parseSubstrateSearchResponse_emails",!1)&&s.push(o)},o=0,v=e.Results;o<v.length;o++)c=v[o],p(c);break;case t.Scope.Documents:case t.Scope.AllFiles:case t.Scope.FilesFolders:case t.Scope.All:for(b=function(u){var o=n.safeExecute(function(){return w.buildDocumentSuggestion(u.Source,r,f.Instrumentation?f.Instrumentation.TraceId:null,u.ReferenceId,(u.Provenance||e.Provenance)=="OneDriveBusiness",a,i)},"buildDocumentSuggestion");o&&t.isValidSuggestion(o,"parseSubstrateSearchResponse_documents")&&s.push(o)},l=0,y=e.Results;l<y.length;l++)c=y[l],b(c);t.decorateSuggestionsWithParentFolder(s,k._host);break;default:SharedLogHelper.LogError("parseSubstrateSearchResponse",h.toString(),new Error("Unexpected scope"))}},k=this,l=0,p=y.ResultSets;l<p.length;l++)d=p[l],b(d);o(u,s,null)}},e.prototype.buildDocumentSuggestion=function(n,i,r,u,f,e,o){var w=this,a=e?HitHighlightingParser.addMarkers(n.FileName,e):n.FileName,s=a.includes(HitHighlightingParser.startMarker);if(e&&!s&&(!t.config.minLengthForContentMatch||o.queryToFetch.length<t.config.minLengthForContentMatch))return null;var v=n.Author==null?null:n.Author.DisplayName,c=t.matchesOnPropertyHH(v,e),b=n.Description?t.decodeHtml(n.Description).replace(/<\/?[^>]+(>|$)/g,""):"",y=t.tryGetTextContentMatch(b,e),k=y[0],p=y[1],l=n.LastModifiedBy==null?null:n.LastModifiedBy.DisplayName,h;return s||c||(t.matchesOnPropertyHH(l,e)&&(h=t.createMatch(t.MatchType.LastModifiedBy,l)),h=h||p),t.buildSubstrateDocumentSuggestion(o,n.Url,a,n.FileName,n.FileExtension,f,n.LastModifiedDateTime,l,v,!s&&c,!s&&!c&&!!p,function(){return w._substrateSuggestionsDataProvider.instrumentClick(r,u)},i,e,t.isL2(o),this._host,k,h,n.SiteTitle||"")},e.prototype.buildMessageSuggestion=function(i,r,u,f,e,o,s){var w=this,y,a,l,p;if(r.IsDraft)return null;if(!r.WebLink)return SharedLogHelper.LogError("buildMessageSuggestion",null,new Error("Missing web link")),null;if(y=r.From&&r.From.EmailAddress?r.From.EmailAddress.Name||r.From.EmailAddress.Address:null,a=r.Sender&&r.Sender.EmailAddress?r.Sender.EmailAddress.Name||r.Sender.EmailAddress.Address:null,!y&&!a)return SharedLogHelper.LogError("buildMessageSuggestion",null,new Error("No valid from or sender fields present")),null;var v=y||a,c=r.Subject,b=f=="SSEE",k=null;t.config.enableRichEmailPreview&&a&&(k=this.getProfilePictureIcon(r.Sender.EmailAddress.Address,this.getPersonIcon(r.Sender.EmailAddress.Name)));var d="OLE",h=t.createSuggestion(i,HitHighlightingParser.addMarkers(v,s),k,null,d,c||v,n.InstrumentedItem.createInstrumentedItem(u,d),b?8:12,u,!0),g=b?1:2;return this.setEmailContextMenuItems(h,r.ItemHexId,r.WebLink,g),h.click=function(){return w.launchEmail(r.ItemHexId,r.WebLink,g)},h.template=1,h.classNames.push("email","forceNoWrapOutsideTopResult","topResultTemplateInGroups"),h.primaryMetadata=HitHighlightingParser.addMarkers(c,s),h.secondaryMetadata=HitHighlightingParser.addMarkers(r.Preview,s),h.tooltip=v+(c?"\n"+c:""),h.hc=r.SortOrderSource=="Relevance",h.previewIcon={content:"&#xE715",type:2,needsAccentColor:!0},r.HasAttachments&&(h.secondaryIcon={content:"&#xE723",type:2}),r.IsRead||h.classNames.push("accentColor"),r.DateTimeReceived&&(l=t.toDate(r.DateTimeReceived),p=t.getTodayTimeString(l),h.dateShort=p?p:l.toLocaleDateString(),h.dateLong=l.toLocaleString(navigator.language,{year:"numeric",month:"numeric",day:"numeric"}),h.dateAndTime=l.toLocaleString(navigator.language,{weekday:"long",month:"long",day:"numeric",year:"numeric",hour:"numeric",minute:"numeric"})),h.internetMessageId=r.InternetMessageId,h.instrumentPingBack=function(){return w._substrateSuggestionsDataProvider.instrumentClick(e,o)},h.narratorText=t.getNarratorText(h),h.subject=HitHighlightingParser.addMarkers(c,s),h.from=v,h.to=r.DisplayTo,h.preview=r.Preview,h.hasAttachment=r.HasAttachments,h.importance=r.Importance!="Normal"?this._host.getLocString("EmailImportance",r.Importance):"",h},e.prototype.getPersonIcon=function(n){var f=/[0-9a-zA-Z]/,t,i=n.trim().replace(/\s+/g," ").split(" ",2),r,u;return i.length>0&&(r=i[0][0],f.test(r)&&(t=r),i.length==2&&(u=i[1][0],t&&f.test(u)?t+=u:t="")),{type:t?5:2,content:t?t.toUpperCase():"&#xE77B",className:"peopleIcon"}},e.prototype.getProfilePictureToken=function(n){this._accessTokenManager.getAccount(this._authType,this._authType==1?"https://outlook.office.com/":"https://outlook.office.com/User.ReadWrite",!1,!0,function(t){return n(t?t.Token:null)})},e.prototype.getProfilePictureIcon=function(n,i){var r=this;return t.Promise.safeChainWithGlobalCaching("getProfilePictureIcon",function(){return ThresholdUtilities.createPromise(function(i){return r.getProfilePictureToken(function(u){var f,e,o;if(!u){i(null);return}f=SearchAppWrapper.CortanaApp.createStringMap();e=SearchAppWrapper.CortanaApp.createStringMap();f.Authorization="Bearer "+u;r._authType==0&&(f["X-AnchorMailbox"]=n);o=r._authType==1?"https://substrate.office.com/api/v2.0/Users('"+n+"')/photo/$value":"https://substrate.office.com/profile/v0/users/"+n+"/image/$value";t.Promise.safeChain("getProfilePictureIcon",function(){return SearchAppWrapper.CortanaApp.makeHttpRequestAsync(0,o,f,"",e)},function(n){if(n.statusCode!==200){i(null);return}t.Promise.safeChain("getProfilePictureIcon",function(){return n.readAsStreamAsync()},i,function(){return i(null)})},function(){return i(null)})})})},function(){return n+"_icon"},function(n){var r=t.toIcon(n,"getProfilePictureIcon",i);return r.className="peopleIcon",r},i)},e.prototype.setEmailContextMenuItems=function(n,i,r,u){var e=this;i&&t.setExtraVerbsAsync(n,function(){var n=[];return ThresholdUtilities.createPromise(function(o){t.LocalDataProvider.getApps(f,function(f){var a=!t.Map.isEmpty(f);if(a){var h=e.getOutlookLaunchPreference(u),c="Outlook",l,s=Object.keys(f);s.length==1&&(c=f[s[0]].deviceItem.displayName,l=f[s[0]].getIcon);n.push({verb:"OpenInOutlookWeb",displayName:e._host.getLocString("OpenIn","Outlook Web"),executeSync:function(){return e.launchOutlookWeb(r,u)},isDefault:h==0,icon:{content:"&#xE774",type:1}});n.push({verb:"LaunchOutlookNative",displayName:e._host.getLocString("OpenIn",c),executeSync:function(){return e.launchOutlokNative(i,u)},isDefault:h==1,getIcon:l})}o(n)})})},!0)},e.prototype.launchOutlookWeb=function(n,t,i){var r=this;this._host.launchUri(n,!1,function(){return r.setOutlookLaunchPreference(0,t)},i)},e.prototype.launchOutlokNative=function(n,t,i){var r=this;this._host.launchOutlook(n,function(){return r.setOutlookLaunchPreference(1,t)},i)},e.prototype.launchEmail=function(t,i,f){for(var c,e,s,l=this,v=this.getOutlookLaunchPreference(f),o=[v],h=0,a=r;h<a.length;h++)c=a[h],n.contains(o,c)||o.push(c);for(s=o.length-1;s>=0;s--)switch(o[s]){case 1:e=u(function(n){return l.launchOutlokNative(t,f,n)},e);break;case 0:e=u(function(n){return l.launchOutlookWeb(i,f,n)},e)}e()},e.prototype.getOutlookLaunchPreference=function(n){if(!this._outlookLaunchPreference[n]){var t=parseInt(this._lightweightStorage.getItem(i+n));this._outlookLaunchPreference[n]=isNaN(t)?r[0]:t}return this._outlookLaunchPreference[n]},e.prototype.setOutlookLaunchPreference=function(n,t){this._outlookLaunchPreference[t]=n;this._lightweightStorage.setItem(i+t,n.toString())},e}();t.SubstrateSearchParser=e})(t=n.WSB||(n.WSB={}))}(AutoSuggest||(AutoSuggest={}));1