/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */!function(e){var t={};function r(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=e,r.c=t,r.d=function(e,t,a){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(a,n,function(t){return e[t]}.bind(null,n));return a},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=16)}([function(e,t){e.exports=__kbnSharedDeps__.EmotionReact},function(e,t){e.exports=__kbnSharedDeps__.ElasticEui},function(e,t){e.exports=__kbnSharedDeps__.React},function(e,t){e.exports=__kbnSharedDeps__.KbnI18n},function(e,t){e.exports=__kbnSharedDeps__.KbnI18nReact},function(e,t){e.exports=__kbnSharedDeps__.KbnAnalytics},function(e,t,r){e.exports=r(27)(1465)},function(e,t){e.exports=__kbnSharedDeps__.TsLib},function(e,t){e.exports=__kbnSharedDeps__.ReactDom},function(e,t,r){"use strict";var a,n=function(){var e={};return function(t){if(void 0===e[t]){var r=document.querySelector(t);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}e[t]=r}return e[t]}}(),o=[];function s(e){for(var t=-1,r=0;r=0,E=new FocusEvent("focusout",{bubbles:!0}),v=(e,t)=>e.scoret.score?-1:0,S=(e,t)=>{const r=e.title.toUpperCase(),a=t.title.toUpperCase();return ra?1:0};var x=r(3);const y=({children:e})=>Object(c.jsx)("ul",{className:"kbnSearchOption__tagsList","aria-label":x.i18n.translate("xpack.globalSearchBar.searchBar.optionTagListAriaLabel",{defaultMessage:"Tags"})},e),T=({color:e,name:t,id:r})=>Object(c.jsx)("li",{className:"kbnSearchOption__tagsListItem",key:r},Object(c.jsx)(l.EuiBadge,{color:e},t)),j=({tags:e,searchTagIds:t})=>{if(!(e.length>3))return Object(c.jsx)(y,null,e.map(T));e.sort((e=>t.find((t=>t===e.id))?-1:1));const r=e.splice(3),a=x.i18n.translate("xpack.globalSearchBar.searchbar.overflowTagsAriaLabel",{defaultMessage:"{n} more {n, plural, one {tag} other {tags}}: {tags}",values:{n:r.length,tags:r.map((({name:e})=>e))}});return Object(c.jsx)(y,null,e.map(T),Object(c.jsx)("li",{className:"kbnSearchOption__tagsListItem","aria-label":a},Object(c.jsx)(l.EuiBadge,{title:a},"+",r.length)))},O=e=>{const{key:t,label:r,description:a,icon:n,suggestedSearch:o}=e;return{key:t,label:r,type:"__suggestion__",icon:{type:n},suggestion:o,meta:[{text:a}],"data-test-subj":"nav-search-option"}},C=["tag","type"],k={tag:["tags"],type:["types"]},R=e=>e.map((e=>String(e))),A={placeholderText:x.i18n.translate("xpack.globalSearchBar.searchBar.placeholder",{defaultMessage:"Find apps, content, and more."}),popoverButton:x.i18n.translate("xpack.globalSearchBar.searchBar.mobileSearchButtonAriaLabel",{defaultMessage:"Site-wide search"}),showSearchAriaText:x.i18n.translate("xpack.globalSearchBar.searchBar.showSearchAriaText",{defaultMessage:"Show search bar"}),closeSearchAriaText:x.i18n.translate("xpack.globalSearchBar.searchBar.closeSearchAriaText",{defaultMessage:"Close search bar"}),keyboardShortcutTooltip:{prefix:x.i18n.translate("xpack.globalSearchBar.searchBar.shortcutTooltip.description",{defaultMessage:"Keyboard shortcut"}),onMac:x.i18n.translate("xpack.globalSearchBar.searchBar.shortcutTooltip.macCommandDescription",{defaultMessage:"Command + /"}),onNotMac:x.i18n.translate("xpack.globalSearchBar.searchBar.shortcutTooltip.windowsCommandDescription",{defaultMessage:"Control + /"})}},L=(e,t)=>e.toLowerCase()===t.toLowerCase(),M=e=>/\s/g.test(e)?`"${e}"`:e,w=({isMac:e})=>Object(c.jsx)(l.EuiFlexGroup,{alignItems:"center",justifyContent:"spaceBetween",gutterSize:"s",responsive:!1,wrap:!0},Object(c.jsx)(l.EuiFlexItem,null,Object(c.jsx)(l.EuiText,{color:"subdued",size:"xs"},Object(c.jsx)("p",null,Object(c.jsx)(a.FormattedMessage,{id:"xpack.globalSearchBar.searchBar.helpText.helpTextPrefix",defaultMessage:"Filter by"})," ",Object(c.jsx)(l.EuiCode,null,"type:")," ",Object(c.jsx)(a.FormattedMessage,{id:"xpack.globalSearchBar.searchBar.helpText.helpTextConjunction",defaultMessage:"or"})," ",Object(c.jsx)(l.EuiCode,null,"tag:")))),Object(c.jsx)(l.EuiFlexItem,{grow:!1},Object(c.jsx)(l.EuiText,{color:"subdued",size:"xs"},Object(c.jsx)("p",null,Object(c.jsx)(a.FormattedMessage,{id:"xpack.globalSearchBar.searchBar.shortcutDescription.shortcutDetail",defaultMessage:"{shortcutDescription} {commandDescription}",values:{shortcutDescription:Object(c.jsx)(a.FormattedMessage,{id:"xpack.globalSearchBar.searchBar.shortcutDescription.shortcutInstructionDescription",defaultMessage:"Shortcut"}),commandDescription:Object(c.jsx)(l.EuiCode,null,e?Object(c.jsx)(a.FormattedMessage,{id:"xpack.globalSearchBar.searchBar.shortcutDescription.macCommandDescription",defaultMessage:"Command + /"}):Object(c.jsx)(a.FormattedMessage,{id:"xpack.globalSearchBar.searchBar.shortcutDescription.windowsCommandDescription",defaultMessage:"Control + /"}))}}))))),B=({basePath:e,darkMode:t})=>Object(c.jsx)(l.EuiFlexGroup,{style:{minHeight:300},"data-test-subj":"nav-search-no-results",direction:"column",gutterSize:"xs",alignItems:"center",justifyContent:"center"},Object(c.jsx)(l.EuiFlexItem,{grow:!1},Object(c.jsx)(l.EuiImage,{alt:x.i18n.translate("xpack.globalSearchBar.searchBar.noResultsImageAlt",{defaultMessage:"Illustration of black hole"}),size:"fullWidth",url:`${e}illustration_product_no_search_results_${t?"dark":"light"}.svg`}),Object(c.jsx)(l.EuiText,{size:"m"},Object(c.jsx)("p",null,Object(c.jsx)(a.FormattedMessage,{id:"xpack.globalSearchBar.searchBar.noResultsHeading",defaultMessage:"No results found"}))),Object(c.jsx)("p",null,Object(c.jsx)(a.FormattedMessage,{id:"xpack.globalSearchBar.searchBar.noResults",defaultMessage:"Try searching for applications, dashboards, visualizations, and more."}))));r(18);const I=e=>Object(c.jsx)(B,{darkMode:e.darkMode,basePath:e.basePathUrl}),D=()=>Object(c.jsx)(l.EuiFlexGroup,{direction:"column",justifyContent:"center",style:{minHeight:"300px"}},Object(c.jsx)(l.EuiFlexItem,{grow:!1},Object(c.jsx)(l.EuiLoadingSpinner,{size:"xl"})));var P={name:"nvzj33",styles:"max-block-size:75vh"};const N=e=>{const{globalSearch:t,taggingApi:r,navigateToUrl:a,reportEvent:n,chromeStyle$:s,...i}=e,u=b()(),{euiTheme:d}=Object(l.useEuiTheme)(),f=_()(s),[g,y]=Object(o.useState)(!1),T=Object(o.useRef)(null),[B,N]=Object(o.useState)(!1),[U,F]=Object(o.useState)(""),[V,$]=Object(o.useState)(""),[K,H]=Object(o.useState)(null),[G,J]=Object(o.useState)(null),z=Object(o.useRef)(null),[Y,q]=Object(o.useState)([]),[Q,W]=Object(o.useState)([]),[X,Z]=Object(o.useState)(!0),ee="__unknown__";Object(o.useEffect)((()=>{B&&(async()=>{const e=await t.getSearchableTypes();W(e)})()}),[t,B]);const te=Object(o.useCallback)((e=>(({searchTerm:e,searchableTypes:t,tagCache:r})=>{const a=[],n=e.trim(),o=((e,t)=>{for(const r of e)if(L(r,t))return r})(t,n);if(o){const e=M(o);a.push({key:"__type__suggestion__",label:`type: ${o}`,icon:"filter",description:x.i18n.translate("xpack.globalSearchBar.suggestions.filterByTypeLabel",{defaultMessage:"Filter by type"}),suggestedSearch:`type:${e}`})}if(r&&e){const e=r.getState().find((e=>L(e.name,n)));if(e){const t=M(e.name);a.push({key:"__tag__suggestion__",label:`tag: ${e.name}`,icon:"tag",description:x.i18n.translate("xpack.globalSearchBar.suggestions.filterByTagLabel",{defaultMessage:"Filter by tag name"}),suggestedSearch:`tag:${t}`})}}return a})({searchTerm:e,searchableTypes:Q,tagCache:null==r?void 0:r.cache})),[r,Q]),re=Object(o.useCallback)(((e,t,a=[])=>{u()&&q([...t.map(O),...e.map((e=>{var t;return((e,t,r)=>{var a;const{id:n,title:o,url:s,icon:i,type:l,meta:u={}}=e,{tagIds:p=[],categoryLabel:d=""}=u,h="application"===l||"integration"===l||"enterprise search"===l.toLowerCase()||"search"===l.toLowerCase(),f={key:n,label:o,url:s,type:l,icon:{type:h&&i?i:"empty"},"data-test-subj":"nav-search-option"};var b;if(f.meta="application"===l?[{text:d}]:[{text:(b=null!==(a=u.displayName)&&void 0!==a?a:l,(b.charAt(0).toUpperCase()+b.slice(1)).replace(/-/g," "))}],r&&p.length){const a=p.map(r).filter(((t,r)=>!!t||(console.warn(`SearchBar: Tag with id "${p[r]}" not found. Tag "${p[r]}" is referenced by the search result "${e.type}:${e.id}". Skipping displaying the missing tag.`),!1)));a.length&&(f.append=Object(c.jsx)(j,{tags:a,searchTagIds:t}))}return f})(e,null!==(t=null==a?void 0:a.filter((e=>e!==ee)))&&void 0!==t?t:[],null==r?void 0:r.ui.getTag)}))])}),[u,q,r]);p()((()=>{if(B){var e;z.current&&(z.current.unsubscribe(),z.current=null);const a=te(U);let o=[];0!==U.length&&n.searchRequest();const s=(e=>{let t;try{t=l.Query.parse(e)}catch(t){return{term:e,filters:{unknowns:{}}}}const r=(e=>{var t;let r;return e.ast.getTermClauses().length&&(r=e.ast.getTermClauses().map((e=>e.value)).join(" ").replace(/\s{2,}/g," ").trim()),null!==(t=r)&&void 0!==t&&t.length?r:void 0})(t),a=((e,t)=>{const r={};Object.entries(t).forEach((([e,t])=>{t.forEach((t=>{r[t]=e}))}));const a=new Map;return e.forEach(((e,t)=>{var n,o;const s=null!==(n=r[t])&&void 0!==n?n:t;a.set(s,[...null!==(o=a.get(s))&&void 0!==o?o:[],...e])})),a})((e=>{const t=new Map;return e.ast.clauses.forEach((e=>{if("field"===e.type){var r;const{field:a,value:n}=e;t.set(a,[...null!==(r=t.get(a))&&void 0!==r?r:[],...Array.isArray(n)?n:[n]])}})),t})(t),k),n=[...a.entries()].filter((([e])=>!C.includes(e))).reduce(((e,[t,r])=>({...e,[t]:r})),{}),o=a.get("tag"),s=a.get("type");return{term:r,filters:{tags:o?R(o):void 0,types:s?R(s):void 0,unknowns:n}}})(U),i=r&&s.filters.tags?s.filters.tags.map((e=>{var t;return null!==(t=r.ui.getTagIdFromName(e))&&void 0!==t?t:ee})):void 0,c={term:s.term,types:s.filters.types,tags:i};$(null!==(e=s.term)&&void 0!==e?e:""),z.current=t.find(c,{}).subscribe({next:({results:e})=>{if(U.length>0)return o=[...e,...o].sort(v),void re(o,a,c.tags);e=e.filter((({type:e})=>"application"===e)),o=[...e,...o].sort(S),re(o,a,c.tags)},error:e=>{n.error({message:e,searchValue:U})},complete:()=>{}})}}),350,[U,te,Q,B]);const ae=Object(o.useCallback)((e=>{var t;"/"===e.key&&(m?e.metaKey:e.ctrlKey)&&(e.preventDefault(),n.shortcutUsed(),"project"!==f||g?K?K.focus():G&&G.children[0].click():null===(t=T.current)||void 0===t||t.click())}),[f,g,G,K,n]),ne=Object(o.useCallback)((e=>{var t;let r=null;const o=e.find((({checked:e},t)=>{const a="on"===e;return a&&(r=t+1),a}));if(!o)return;const s=null!==(t=o.label)&&void 0!==t?t:null,{url:i,type:c,suggestion:l}=o;if("__suggestion__"!==c){try{if("application"===c){var u;const e=`${(null!==(u=o.key)&&void 0!==u?u:"unknown").toLowerCase().replaceAll(" ","_")}`;n.navigateToApplication({application:e,searchValue:U,selectedLabel:s,selectedRank:r})}else n.navigateToSavedObject({type:c,searchValue:U,selectedLabel:s,selectedRank:r})}catch(e){n.error({message:e,searchValue:U}),console.log("Error trying to track searchbar metrics",e)}a(i),document.activeElement.blur(),K&&(oe(),K.dispatchEvent(E))}else F(l)}),[n,a,K,U]),oe=()=>F(""),se=`${A.keyboardShortcutTooltip.prefix}: ${m?A.keyboardShortcutTooltip.onMac:A.keyboardShortcutTooltip.onNotMac}`;return h()("keydown",ae),"project"!==f||g?Object(c.jsx)(l.EuiSelectableTemplateSitewide,{isPreFiltered:!0,onChange:ne,options:Y,className:"kbnSearchBar",popoverButtonBreakpoints:["xs","s"],singleSelection:!0,renderOption:e=>Object(l.euiSelectableTemplateSitewideRenderOptions)(e,V),listProps:{className:"eui-yScroll",css:P},searchProps:{autoFocus:"project"===f,value:U,onInput:e=>F(e.currentTarget.value),"data-test-subj":"nav-search-input",inputRef:H,compressed:!0,"aria-label":A.placeholderText,placeholder:A.placeholderText,onFocus:()=>{n.searchFocus(),N(!0),Z(!1)},onBlur:()=>{n.searchBlur(),Z(!U.length)},fullWidth:!0,append:"project"===f?Object(c.jsx)(l.EuiButtonIcon,{"aria-label":A.closeSearchAriaText,color:"text","data-test-subj":"nav-search-conceal",iconType:"cross",onClick:()=>{n.searchBlur(),y(!1)}}):X?Object(c.jsx)(l.EuiFormLabel,{title:se,css:Object(c.css)({fontFamily:d.font.familyCode},"","")},m?"⌘/":"^/"):void 0},emptyMessage:Object(c.jsx)(D,null),noMatchesMessage:Object(c.jsx)(I,i),popoverProps:{"data-test-subj":"nav-search-popover",panelClassName:"navSearch__panel",repositionOnScroll:!0,buttonRef:J,panelStyle:{marginTop:"6px"}},popoverButton:Object(c.jsx)(l.EuiHeaderSectionItemButton,{"aria-label":A.popoverButton},Object(c.jsx)(l.EuiIcon,{type:"search",size:"m"})),popoverFooter:Object(c.jsx)(w,{isMac:m})}):Object(c.jsx)(l.EuiButtonIcon,{"aria-label":A.showSearchAriaText,buttonRef:T,color:"text","data-test-subj":"nav-search-reveal",iconType:"search",onClick:()=>{y(!0)}})};var U=r(6),F=r.n(U),V=r(5);let $,K,H,G;!function(e){e.UNHANDLED_ERROR="unhandled_error",e.SHORTCUT_USED="shortcut_used",e.SEARCH_FOCUS="search_focus",e.SEARCH_REQUEST="search_request"}($||($={})),function(e){e.USER_NAVIGATED_TO_APPLICATION="user_navigated_to_application",e.USER_NAVIGATED_TO_SAVED_OBJECT="user_navigated_to_saved_object"}(K||(K={})),function(e){e.CLICK_APPLICATION="global_search_bar_click_application",e.CLICK_SAVED_OBJECT="global_search_bar_click_saved_object",e.SEARCH_BLUR="global_search_bar_blur",e.ERROR="global_search_bar_error"}(H||(H={})),function(e){e.APPLICATION="application",e.SAVED_OBJECT_TYPE="saved_object_type",e.FOCUS_TIME="focus_time_ms",e.SELECTED_LABEL="selected_label",e.SELECTED_RANK="selected_rank",e.ERROR_MESSAGE="error_message",e.TERMS="terms"}(G||(G={}));class event_reporter_EventReporter{constructor({analytics:e,usageCollection:t}){F()(this,"reportEvent",void 0),F()(this,"trackUiMetric",void 0),F()(this,"focusStart",1/0),this.reportEvent=e.reportEvent,this.trackUiMetric=t?(e,r,a)=>{let n;switch(r){case K.USER_NAVIGATED_TO_APPLICATION:case K.USER_NAVIGATED_TO_SAVED_OBJECT:n=[e,[r,`${r}_${a}`]];break;default:n=[e,r]}t.reportUiCounter("global_search_bar",...n)}:()=>{}}searchFocus(){this.trackUiMetric(V.METRIC_TYPE.COUNT,$.SEARCH_FOCUS),this.focusStart=Date.now()}searchBlur(){const e=Date.now()-this.focusStart;e>0&&this.reportEvent(H.SEARCH_BLUR,{[G.FOCUS_TIME]:e}),this.focusStart=1/0}searchRequest(){this.trackUiMetric(V.METRIC_TYPE.COUNT,$.SEARCH_REQUEST)}shortcutUsed(){this.trackUiMetric(V.METRIC_TYPE.COUNT,$.SHORTCUT_USED)}navigateToApplication(e){var t,r;const a=null!==(t=null==e?void 0:e.application)&&void 0!==t?t:"unknown";this.trackUiMetric(V.METRIC_TYPE.CLICK,K.USER_NAVIGATED_TO_APPLICATION,a);const n=null!==(r=null==e?void 0:e.searchValue)&&void 0!==r?r:"";this.reportEvent(H.CLICK_APPLICATION,{[G.TERMS]:n,[G.APPLICATION]:a,[G.SELECTED_RANK]:e.selectedRank,[G.SELECTED_LABEL]:e.selectedLabel})}navigateToSavedObject(e){var t,r;const a=null!==(t=null==e?void 0:e.type)&&void 0!==t?t:"unknown";this.trackUiMetric(V.METRIC_TYPE.CLICK,K.USER_NAVIGATED_TO_SAVED_OBJECT,a);const n=null!==(r=null==e?void 0:e.searchValue)&&void 0!==r?r:"";this.reportEvent(H.CLICK_SAVED_OBJECT,{[G.TERMS]:n,[G.SAVED_OBJECT_TYPE]:a,[G.SELECTED_RANK]:e.selectedRank,[G.SELECTED_LABEL]:e.selectedLabel})}error(e){var t,r;this.trackUiMetric(V.METRIC_TYPE.COUNT,$.UNHANDLED_ERROR);const a=null!==(t=null==e?void 0:e.message.toString())&&void 0!==t?t:"unknown",n=null!==(r=null==e?void 0:e.searchValue)&&void 0!==r?r:"";this.reportEvent(H.ERROR,{[G.TERMS]:n,[G.ERROR_MESSAGE]:a})}}const J={[G.APPLICATION]:{[G.APPLICATION]:{type:"keyword",_meta:{description:"The name of the application selected in the global search bar results."}}},[G.SAVED_OBJECT_TYPE]:{[G.SAVED_OBJECT_TYPE]:{type:"keyword",_meta:{description:"The type of the saved object selected in the global search bar results."}}},[G.FOCUS_TIME]:{[G.FOCUS_TIME]:{type:"long",_meta:{description:"The length in milliseconds the global search bar had the cursor focused."}}},[G.SELECTED_RANK]:{[G.SELECTED_RANK]:{type:"short",_meta:{description:"The ranking of placement of the selected option in the results list."}}},[G.SELECTED_LABEL]:{[G.SELECTED_LABEL]:{type:"keyword",_meta:{description:"The text of the selected option in the results list."}}},[G.ERROR_MESSAGE]:{[G.ERROR_MESSAGE]:{type:"keyword",_meta:{description:"A message from an error that was caught."}}},[G.TERMS]:{[G.TERMS]:{type:"keyword",_meta:{description:"The search terms entered by the user."}}}},z=[{eventType:H.CLICK_APPLICATION,schema:{...J[G.APPLICATION],...J[G.TERMS],...J[G.SELECTED_RANK],...J[G.SELECTED_LABEL]}},{eventType:H.CLICK_SAVED_OBJECT,schema:{...J[G.SAVED_OBJECT_TYPE],...J[G.TERMS],...J[G.SELECTED_RANK],...J[G.SELECTED_LABEL]}},{eventType:H.SEARCH_BLUR,schema:{...J[G.FOCUS_TIME]}},{eventType:H.ERROR,schema:{...J[G.ERROR_MESSAGE],...J[G.TERMS]}}];class plugin_GlobalSearchBarPlugin{setup({analytics:e}){return z.forEach((t=>{e.registerEventType(t)})),{}}start(e,t){return e.chrome.navControls.registerCenter(this.getNavControl({core:e,...t})),{}}getNavControl(e){const{core:t,globalSearch:r,savedObjectsTagging:o,usageCollection:s}=e,{application:l,http:u,theme:p,uiSettings:d}=t,h=new event_reporter_EventReporter({analytics:t.analytics,usageCollection:s});return{order:1e3,mount:e=>(i.a.render(Object(c.jsx)(n.KibanaThemeProvider,{theme$:p.theme$},Object(c.jsx)(a.I18nProvider,null,Object(c.jsx)(N,{globalSearch:r,navigateToUrl:l.navigateToUrl,taggingApi:o,basePathUrl:u.basePath.prepend("/plugins/globalSearchBar/assets/"),darkMode:d.get("theme:darkMode"),chromeStyle$:t.chrome.getChromeStyle$(),reportEvent:h}))),e),()=>i.a.unmountComponentAtNode(e))}}}const Y=()=>new plugin_GlobalSearchBarPlugin}]);