/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import{substitute as t}from"../../intl.js";import{property as s,subclass as o}from"../../core/accessorSupport/decorators.js";import{popupFromView as i}from"../../views/popupAdapter.js";import r from"../Widget.js";import{css as l}from"./searchResultRendererCSS.js";import n from"./SearchViewModel.js";import{loadCalciteComponents as c}from"../support/componentsUtils.js";import{globalCss as p}from"../support/globalCss.js";import{messageBundle as u,tsx as m}from"../support/widget.js";let a=class extends r{constructor(e,t){super(e,t),this.messages=null,this.showMoreResultsOpen=!1,this.viewModel=null}loadDependencies(){return c({block:()=>import("@esri/calcite-components/dist/components/calcite-block"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),"list-item-group":()=>import("@esri/calcite-components/dist/components/calcite-list-item-group")})}destroy(){this.viewModel=null}render(){return m("div",{class:this.classes(l.base,p.widget)},this.viewModel?.selectedResult?.name??"",this._renderMoreResults())}_renderMoreResults(){if(!this.viewModel)return null;const{resultCount:e,results:s}=this.viewModel;return!e||e<2||!s?null:m("calcite-block",{class:l.moreResults,collapsible:!0,expanded:this.showMoreResultsOpen,heading:t(this.messages.showMoreResults,{count:e-1}),onCalciteBlockClose:()=>this._toggleShowMoreResults(!1),onCalciteBlockOpen:()=>this._toggleShowMoreResults(!0)},s.map(e=>this._renderMoreResultsList(e,s?.length>1)))}_renderListItem(e){return m("calcite-list-item",{key:`result-${e.sourceIndex}-${e.key}`,label:e.name,onCalciteListItemSelect:()=>this._selectResult(e)})}_renderMoreResultsList(e,t){const{results:s}=e;if(!(s?.length??0)||!s)return null;const o=this.viewModel?.selectedResult,i=this._getSourceName(e.source,e.sourceIndex),r=s.filter(e=>e!==o).map(e=>this._renderListItem(e));return m("calcite-list",{label:i},t?m("calcite-list-item-group",{heading:i,key:`group-${e.sourceIndex}`},r):r)}_selectResult(e){this.showMoreResultsOpen=!1,this.viewModel?.select(e)}_toggleShowMoreResults(e){this.showMoreResultsOpen=e;const t=i(this.viewModel?.view);t&&"reposition"in t&&"function"==typeof t.reposition&&t.reposition()}_getSourceName(e,t){return t===n.ALL_INDEX?this.messages.all:e.name}};e([s(),u("esri/widgets/Search/t9n/Search")],a.prototype,"messages",void 0),e([s()],a.prototype,"showMoreResultsOpen",void 0),e([s({type:n})],a.prototype,"viewModel",void 0),a=e([o("esri.widgets.Search.SearchResultRenderer")],a);const d=a;export{d as default};
