/*
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/reactiveUtils","../core/accessorSupport/decorators/aliasOf","../core/arrayUtils","../core/has","../core/accessorSupport/ensureType","../core/accessorSupport/decorators/property","../core/accessorSupport/decorators/subclass","./Widget","./Attribution/AttributionViewModel","./support/decorators/accessibleHandler","./support/decorators/messageBundle","./support/jsxFactory","./support/widgetUtils"],(function(e,t,r,i,o,s,n,c,a,d,p,l,u,_,h){"use strict";const v={base:"esri-attribution esri-widget",poweredBy:"esri-attribution__powered-by",sources:"esri-attribution__sources",open:"esri-attribution--open",sourcesOpen:"esri-attribution__sources--open",link:"esri-attribution__link",widgetIcon:"esri-icon-description",interactive:"esri-interactive"};let b=function(t){function i(e,r){var i;return(i=t.call(this,e,r)||this)._isOpen=!1,i._attributionTextOverflowed=!1,i._prevSourceNodeHeight=0,i._resizeObserver=new ResizeObserver((e=>e.forEach((({target:e})=>i._checkSourceTextOverflow(e))))),i.iconClass=v.widgetIcon,i.itemDelimiter=" | ",i.label=void 0,i.messages=null,i.view=null,i.viewModel=new p,i}e._inheritsLoose(i,t);var o=i.prototype;return o.initialize=function(){this.own(r.on((()=>{var e;return null==(e=this.viewModel)?void 0:e.items}),"change",(()=>this.scheduleRender())))},o.destroy=function(){var e;null==(e=this._resizeObserver)||e.disconnect()},o.render=function(){const e={[v.open]:this._isOpen};return _.tsx("div",{bind:this,class:this.classes(v.base,e),dir:"ltr",onclick:this._toggleState,onkeydown:this._toggleState},this.renderSourcesNode(),this.renderPoweredBy())},o.renderPoweredBy=function(){return _.tsx("div",{class:v.poweredBy},"Powered by"," ",_.tsx("a",{class:v.link,href:"http://www.esri.com/",target:"_blank",rel:"noreferrer"},"Esri"))},o.renderSourcesNode=function(){const e=this._isOpen,t=this._isInteractive,r=t?"0":"",{attributionText:i}=this,o={[v.sourcesOpen]:e,[v.interactive]:t};return _.tsx("div",{afterCreate:this._afterSourcesNodeCreate,bind:this,class:this.classes(v.sources,o),innerHTML:i,tabindex:r})},o._afterSourcesNodeCreate=function(e){this._prevSourceNodeHeight=e.clientWidth,this._resizeObserver.observe(e)},o._checkSourceTextOverflow=function(e){let t=!1;const{clientHeight:r,clientWidth:i,scrollWidth:o}=e,s=o>i,n=this._attributionTextOverflowed!==s;if(this._attributionTextOverflowed=s,n&&(t=!0),this._isOpen){const e=r<this._prevSourceNodeHeight;this._prevSourceNodeHeight=r,e&&(this._isOpen=!1,t=!0)}t&&this.scheduleRender()},o._toggleState=function(){this._isInteractive&&(this._isOpen=!this._isOpen)},e._createClass(i,[{key:"_isInteractive",get:function(){return this._isOpen||this._attributionTextOverflowed}},{key:"attributionText",get:function(){return this.viewModel.items.reduce(((e,t)=>(e.includes(t.text)||e.push(t.text),e)),[]).join(this.itemDelimiter)}}]),i}(d);t.__decorate([c.property()],b.prototype,"_isOpen",void 0),t.__decorate([c.property()],b.prototype,"_isInteractive",null),t.__decorate([c.property()],b.prototype,"_attributionTextOverflowed",void 0),t.__decorate([c.property()],b.prototype,"_prevSourceNodeHeight",void 0),t.__decorate([c.property({readOnly:!0,dependsOn:["viewModel.items.length","itemDelimiter"]})],b.prototype,"attributionText",null),t.__decorate([c.property()],b.prototype,"iconClass",void 0),t.__decorate([c.property()],b.prototype,"itemDelimiter",void 0),t.__decorate([c.property({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],b.prototype,"label",void 0),t.__decorate([c.property(),u.messageBundle("esri/widgets/Attribution/t9n/Attribution")],b.prototype,"messages",void 0),t.__decorate([i.aliasOf("viewModel.view")],b.prototype,"view",void 0),t.__decorate([c.property({type:p})],b.prototype,"viewModel",void 0),t.__decorate([l.accessibleHandler()],b.prototype,"_toggleState",null),b=t.__decorate([a.subclass("esri.widgets.Attribution")],b);return b}));
