/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../Widget","./SearchViewModel","../support/decorators/accessibleHandler","../support/decorators/messageBundle","../support/jsxFactory","../support/widgetUtils"],(function(e,s,r,t,o,l,u,n,i,c,a,d,h){"use strict";const _={base:"esri-search-result-renderer esri-widget",anchor:"esri-widget__anchor",showMoreResults:"esri-search-result-renderer__more-results--show-more-results",moreResults:"esri-search-result-renderer__more-results",moreResultsList:"esri-search-result-renderer__more-results-list",moreResultsHeader:"esri-search-result-renderer__more-results-header",moreResultsItem:"esri-search-result-renderer__more-results-item",moreResultsListHeader:"esri-search-result-renderer__more-results-list-header"};let p=function(s){function r(e,r){var t;return(t=s.call(this,e,r)||this).messages=null,t.showMoreResultsOpen=!1,t.viewModel=null,t}e._inheritsLoose(r,s);var t=r.prototype;return t.render=function(){const e={[_.showMoreResults]:this.showMoreResultsOpen};return d.tsx("div",{class:_.base},d.tsx("div",{key:"esri-search-renderer__container",class:this.classes(_.moreResults,e)},this.renderSearchResultName(),this.renderMoreResults()))},t.renderMoreResults=function(){return d.tsx("div",{key:"esri-search-renderer__more-results"},this.renderMoreResultsButton(),this.renderMoreResultsLists())},t.renderSearchResultName=function(){var e;const s=null==(e=this.viewModel)?void 0:e.selectedResult,r=s&&s.name||"";return d.tsx("div",{key:"esri-search-renderer__result-name",class:_.moreResultsItem},r)},t.renderMoreResultsLists=function(){var e;const s=null==(e=this.viewModel)?void 0:e.results,{resultCount:r}=this.viewModel;if(r<2)return null;const t=s.map((e=>this.renderMoreResultsList(e)));return d.tsx("div",{key:"esri-search-renderer__more-results-container",class:_.moreResultsList},t)},t.renderMoreResultsButton=function(){const{messages:e}=this,{resultCount:s}=this.viewModel;return s<2?null:d.tsx("div",{key:"esri-search-renderer__more-results-button",class:_.moreResultsItem},d.tsx("a",{class:_.anchor,href:"#",bind:this,onclick:this._showMoreResultsClick,onkeydown:this._showMoreResultsClick},this.showMoreResultsOpen?e.hideMoreResults:e.showMoreResults))},t.renderMoreResultsHeader=function(e,s){return d.tsx("div",{key:`esri-search-result-renderer__header-${s}`,class:_.moreResultsListHeader},e)},t.renderMoreResultsList=function(e){var s,r;const{results:t}=e,o=t.length,l=!!o,u=null==(s=this.viewModel)?void 0:s.selectedResult,n=1===o&&t[0]===u,i=this._getSourceName(e.source,e.sourceIndex),c=(null==(r=this.viewModel)?void 0:r.results.length)>1&&!n?this.renderMoreResultsHeader(i,e.sourceIndex):null,a=l&&t.map(((e,s)=>this.renderMoreResultsListItem(e,s))),h=l&&!n?d.tsx("ul",{key:`esri-search-result-renderer__list-${e.sourceIndex}`},a):null;return l?d.tsx("div",{key:`esri-search-result-renderer__results-${e.sourceIndex}`},c,h):null},t.renderMoreResultsListItem=function(e,s){return e!==this.get("viewModel.selectedResult")?d.tsx("li",{key:`esri-search-result-renderer__list-item-${s}`},d.tsx("a",{class:_.anchor,href:"#",tabindex:"0",bind:this,"data-result":e,onclick:this._selectResultClick,onkeydown:this._selectResultClick},e.name)):null},t._showMoreResultsClick=function(e){e.preventDefault(),this.showMoreResultsOpen=!this.showMoreResultsOpen;const s=this.get("viewModel.view.popup");s&&s.reposition()},t._selectResultClick=function(e){e.preventDefault();const s=e.currentTarget["data-result"];this.viewModel&&this.viewModel.select(s)},t._getSourceName=function(e,s){return s===i.ALL_INDEX?this.messages.all:e.name},r}(n);s.__decorate([r.property(),a.messageBundle("esri/widgets/Search/t9n/Search")],p.prototype,"messages",void 0),s.__decorate([r.property()],p.prototype,"showMoreResultsOpen",void 0),s.__decorate([r.property()],p.prototype,"viewModel",void 0),s.__decorate([c.accessibleHandler()],p.prototype,"_showMoreResultsClick",null),s.__decorate([c.accessibleHandler()],p.prototype,"_selectResultClick",null),p=s.__decorate([u.subclass("esri.widgets.Search.SearchResultRenderer")],p);return p}));
