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,f0?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:""}}),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:""}}),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:""}}),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,""):"",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:"",type:2,needsAccentColor:!0},r.HasAttachments&&(h.secondaryIcon={content:"",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():"",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:"",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=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