(window.unifiedSearch_bundle_jsonpfunction=window.unifiedSearch_bundle_jsonpfunction||[]).push([[17],{40:function(e,t,r){"use strict";r.r(t),r.d(t,"DataViewsList",(function(){return b}));var i=r(7),o=r.n(i),n=r(0),a=r.n(n),s=r(11),c=r(5),d=r(1),l=r(3),g=r.n(l),u=r(8);const p="unified_search_sorting",S="alphabetically";class sorting_service_SortingService{constructor(e,t=new u.Storage(window.localStorage)){g()(this,"sortingStrategyType",void 0),g()(this,"direction",void 0),this.sortingStrategies=e,this.storage=t;const{sortingStrategyType:r,direction:i}=this.getSorting();this.sortingStrategyType=r,this.direction=i}getSorting(){var e,t;let r;try{r=this.storage.get(p)}catch(e){r=void 0}return{sortingStrategyType:(null===(e=r)||void 0===e?void 0:e.sortingStrategyType)||S,direction:(null===(t=r)||void 0===t?void 0:t.direction)||s.SortDirection.ASC}}setDirection(e){this.direction=e,this.storage.set(p,{direction:e,sortingStrategyType:this.sortingStrategyType})}setSortingStrategyType(e){this.sortingStrategyType=e,this.storage.set(p,{sortingStrategyType:e,direction:this.direction})}getOrderDirections(){return[s.SortDirection.ASC,s.SortDirection.DESC]}getSortingStrategyTypes(){return[S]}sortData(e){return[...e].sort(((e,t)=>{const r=this.sortingStrategies[this.sortingStrategyType],i=r(e),o=r(t);return this.compare(i,o)}))}compare(e,t){return this.direction===s.SortDirection.ASC?e.localeCompare(t):t.localeCompare(e)}}const h={sortOrder:{asc:{getSortOrderLabel:()=>c.i18n.translate("unifiedSearch.optionsList.popover.sortOrder.asc",{defaultMessage:"Ascending"})},desc:{getSortOrderLabel:()=>c.i18n.translate("unifiedSearch.optionsList.popover.sortOrder.desc",{defaultMessage:"Descending"})}},editorAndPopover:{getSortDirectionLegend:()=>c.i18n.translate("unifiedSearch.optionsList.popover.sortDirections",{defaultMessage:"Sort directions"}),adhoc:{getTemporaryDataviewLabel:()=>c.i18n.translate("unifiedSearch.query.queryBar.indexPattern.temporaryDataviewLabel",{defaultMessage:"Temporary"})},search:{getSearchPlaceholder:()=>c.i18n.translate("unifiedSearch.query.queryBar.indexPattern.findDataView",{defaultMessage:"Find a data view"})}}};var y={name:"18g08sj",styles:"padding-bottom:0"};function b({dataViewsList:e,onChangeDataView:t,isTextBasedLangSelected:r,currentDataViewId:i,selectableProps:c,searchListInputId:l}){const g=Object(n.useMemo)((()=>new sorting_service_SortingService({alphabetically:e=>{var t;return null!==(t=e.name)&&void 0!==t?t:e.title}})),[]),[u,p]=Object(n.useState)(g.sortData(e)),S=Object(n.useMemo)((()=>g.getOrderDirections().map((e=>({id:e,iconType:`sort${Object(s.toSentenceCase)(e)}ending`,label:h.sortOrder[e].getSortOrderLabel()})))),[g]),b=Object(n.useCallback)((e=>{g.setDirection(e),p((e=>g.sortData(e)))}),[g]);return Object(d.jsx)(s.EuiSelectable,o()({},c,{"data-test-subj":"indexPattern-switcher",searchable:!0,singleSelection:"always",options:null==u?void 0:u.map((({title:e,id:t,name:o,isAdhoc:n})=>({key:t,label:o||e,value:t,checked:t!==i||Boolean(r)?void 0:"on",append:n?Object(d.jsx)(s.EuiBadge,{color:"hollow","data-test-subj":`dataViewItemTempBadge-${o}`},h.editorAndPopover.adhoc.getTemporaryDataviewLabel()):null}))),onChange:e=>{const r=e.find((({checked:e})=>e));t(r.value)},searchProps:{id:l,compressed:!0,placeholder:h.editorAndPopover.search.getSearchPlaceholder(),"data-test-subj":"indexPattern-switcher--input",...c?c.searchProps:void 0}}),((e,t)=>Object(d.jsx)(a.a.Fragment,null,Object(d.jsx)(s.EuiPanel,{css:y,color:"transparent",paddingSize:"s"},Object(d.jsx)(s.EuiFlexGroup,{gutterSize:"xs",direction:"row",justifyContent:"spaceBetween",alignItems:"center",responsive:!1},Object(d.jsx)(s.EuiFlexItem,null,t),Object(d.jsx)(s.EuiFlexItem,{grow:!1},Object(d.jsx)(s.EuiButtonGroup,{isIconOnly:!0,buttonSize:"compressed",options:S,legend:h.editorAndPopover.getSortDirectionLegend(),idSelected:g.direction,onChange:b})))),e)))}t.default=b}}]);