/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["require","../chunks/_rollupPluginBabelHelpers","../chunks/tslib.es6","../assets","../core/Handles","../core/reactiveUtils","../core/accessorSupport/decorators/aliasOf","../core/arrayUtils","../core/has","../core/accessorSupport/ensureType","../core/accessorSupport/decorators/property","../core/accessorSupport/decorators/subclass","./Widget","./BasemapGallery/BasemapGalleryViewModel","./support/Heading","./support/decorators/accessibleHandler","./support/decorators/messageBundle","./support/jsxFactory","./support/widgetUtils"],(function(e,s,a,t,i,r,l,o,d,n,c,p,m,u,g,h,_,y,b){"use strict";const v={base:"esri-basemap-gallery esri-widget esri-widget--panel-height-only",sourceLoading:"esri-basemap-gallery--source-loading",loader:"esri-basemap-gallery__loader",item:"esri-basemap-gallery__item",itemContainer:"esri-basemap-gallery__item-container",itemTitle:"esri-basemap-gallery__item-title",itemThumbnail:"esri-basemap-gallery__item-thumbnail",selectedItem:"esri-basemap-gallery__item--selected",itemError:"esri-basemap-gallery__item--error",emptyMessage:"esri-widget__content--empty",widgetIcon:"esri-icon-basemap",disabled:"esri-disabled",loaderAnimation:"esri-widget__loader-animation"};let w=function(a){function l(e,s){var t;return(t=a.call(this,e,s)||this)._handles=new i,t.activeBasemap=null,t.disabled=!1,t.headingLevel=2,t.iconClass=v.widgetIcon,t.label=void 0,t.messages=null,t.source=null,t.view=null,t.viewModel=new u,t}s._inheritsLoose(l,a);var o=l.prototype;return o.initialize=function(){const e=this._handles;this.own([r.on((()=>this.viewModel.items),"change",(s=>{const a="basemap-gallery-item-changes",{added:t,moved:i}=s;e.remove(a),e.add([...t,...i].map((e=>r.watch((()=>e.state),(()=>this.scheduleRender())))),a),this.scheduleRender()})),e,r.when((()=>this.source),(()=>this.viewModel.load()),{initial:!0,once:!0})])},o.destroy=function(){this._handles.destroy()},o.loadDependencies=function(){return new Promise(((s,a)=>e(["../chunks/calcite-scrim"],s,a)))},o.render=function(){const e="loading"===this.get("source.state"),s=this.disabled||"disabled"===this.get("viewModel.state"),a=this.get("viewModel.items").toArray().map(this._renderBasemapGalleryItem,this),t={[v.sourceLoading]:e,[v.disabled]:s},i=e?y.tsx("div",{class:v.loader,key:"esri-basemap-gallery__loader"}):null,r=e?null:a.length>0?y.tsx("ul",{class:v.itemContainer,key:"esri-basemap-gallery__item-container",role:"menu"},a):y.tsx("div",{class:v.emptyMessage,key:"esri-basemap-gallery__empty-message"},y.tsx(g.Heading,{level:this.headingLevel},this.messages.noBasemaps));return y.tsx("div",{class:this.classes(v.base,t)},i,r)},o._handleClick=function(e){const s=e.currentTarget["data-item"];"ready"===s.state&&(this.viewModel.activeBasemap=s.basemap)},o._renderBasemapGalleryItem=function(e){const s=e.get("basemap.thumbnailUrl")||t.getAssetUrl("esri/themes/base/images/basemap-toggle-64.svg"),a=e.get("basemap.title"),i=e.get("basemap.portalItem.snippet"),r=e.get("error.message")||i||a,{viewModel:l}=this,o=!this.disabled&&"disabled"!==l.state&&"ready"===e.state?0:-1,d=l.basemapEquals(e.basemap,this.activeBasemap),n="loading"===l.state,c={[v.selectedItem]:d,[v.itemError]:"error"===e.state};return y.tsx("li",{"aria-selected":d.toString(),bind:this,class:this.classes(v.item,c),"data-item":e,onkeydown:this._handleClick,onclick:this._handleClick,role:"menuitem",tabIndex:o,title:r},y.tsx("img",{alt:"",class:v.itemThumbnail,src:s}),y.tsx("div",{class:v.itemTitle},a),"loading"===e.state||d&&n?y.tsx("calcite-scrim",null,y.tsx("span",{"aria-hidden":"true",role:"presentation",class:v.loaderAnimation})):null)},l}(m);a.__decorate([l.aliasOf("viewModel.activeBasemap")],w.prototype,"activeBasemap",void 0),a.__decorate([c.property()],w.prototype,"disabled",void 0),a.__decorate([c.property()],w.prototype,"headingLevel",void 0),a.__decorate([c.property()],w.prototype,"iconClass",void 0),a.__decorate([c.property({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],w.prototype,"label",void 0),a.__decorate([c.property(),_.messageBundle("esri/widgets/BasemapGallery/t9n/BasemapGallery")],w.prototype,"messages",void 0),a.__decorate([l.aliasOf("viewModel.source")],w.prototype,"source",void 0),a.__decorate([l.aliasOf("viewModel.view")],w.prototype,"view",void 0),a.__decorate([c.property()],w.prototype,"viewModel",void 0),a.__decorate([h.accessibleHandler()],w.prototype,"_handleClick",null),w=a.__decorate([p.subclass("esri.widgets.BasemapGallery")],w);return w}));
