/*
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/screenUtils","../core/accessorSupport/decorators/aliasOf","../core/arrayUtils","../core/has","../core/accessorSupport/decorators/cast","../core/accessorSupport/decorators/property","../core/accessorSupport/decorators/subclass","./Widget","./ScaleBar/ScaleBarViewModel","./support/widgetUtils","./support/decorators/messageBundle","./support/jsxFactory"],(function(e,t,r,s,a,l,i,o,n,c,d,u,b,p,_){"use strict";const h={base:"esri-scale-bar esri-widget",labelContainer:"esri-scale-bar__label-container",rulerLabelContainer:"esri-scale-bar__label-container--ruler",lineLabelContainer:"esri-scale-bar__label-container--line",topLabelContainer:"esri-scale-bar__label-container--top",bottomLabelContainer:"esri-scale-bar__label-container--bottom",label:"esri-scale-bar__label",line:"esri-scale-bar__line",topLine:"esri-scale-bar__line--top",bottomLine:"esri-scale-bar__line--bottom",ruler:"esri-scale-bar__ruler",rulerBlock:"esri-scale-bar__ruler-block",barContainer:"esri-scale-bar__bar-container",rulerBarContainer:"esri-scale-bar__bar-container--ruler",lineBarContainer:"esri-scale-bar__bar-container--line",disabled:"esri-disabled"};function v(e){return 2*e}let y=function(t){function a(e,r){var s;return(s=t.call(this,e,r)||this).label=void 0,s.messages=null,s.unit="non-metric",s.view=null,s.viewModel=new u,s}e._inheritsLoose(a,t);var l=a.prototype;return l.initialize=function(){this.own([r.watch((()=>{const{view:e}=this;return[null==e?void 0:e.stationary,null==e?void 0:e.center,null==e?void 0:e.scale,null==e?void 0:e.zoom]}),(([e])=>{e&&this.scheduleRender()}))])},l.castStyle=function(e){return"line"===e?e:"ruler"},l.castUnit=function(e){return"metric"===e||"dual"===e?e:"non-metric"},l.render=function(){const e="disabled"===this.get("viewModel.state"),t={[h.disabled]:e};let r,s;if(!e){const{unit:e,style:t}=this,a="metric"===e||"dual"===e,l=50;if("non-metric"===e||"dual"===e){const e=this.viewModel.getScaleBarProperties(l,"non-metric");e&&(s="ruler"===t?this._renderRuler(e):this._renderLine(e,"bottom"))}if(a){const e=this.viewModel.getScaleBarProperties(l,"metric");e&&(r="ruler"===t?this._renderRuler(e):this._renderLine(e,"top"))}}return _.tsx("div",{afterCreate:this._handleRootCreateOrUpdate,afterUpdate:this._handleRootCreateOrUpdate,bind:this,class:this.classes(h.base,t)},r,s)},l._renderRuler=function(e){const t=v(Math.round(e.length)),{messages:r}=this,s=r[e.unit]||r.unknownUnit,a=`${v(e.value)} ${s}`;return _.tsx("div",{class:this.classes(h.barContainer,h.rulerBarContainer),key:"esri-scale-bar__ruler"},_.tsx("div",{class:h.ruler,styles:{width:`${t}px`}},_.tsx("div",{class:h.rulerBlock}),_.tsx("div",{class:h.rulerBlock}),_.tsx("div",{class:h.rulerBlock}),_.tsx("div",{class:h.rulerBlock})),_.tsx("div",{class:this.classes(h.labelContainer,h.rulerLabelContainer)},_.tsx("div",{class:h.label},"0"),_.tsx("div",{class:h.label},a)))},l._renderLine=function(e,t){const{messages:r}=this,s=r[e.unit]||r.unknownUnit,a=`${v(e.value)} ${s}`,l={[h.topLabelContainer]:"top"===t,[h.bottomLabelContainer]:"bottom"===t},i=_.tsx("div",{class:this.classes(h.labelContainer,h.lineLabelContainer,l),key:"esri-scale-bar__label"},_.tsx("div",{class:h.label},a)),o={[h.topLine]:"top"===t,[h.bottomLine]:"bottom"===t},n=v(Math.round(e.length)),c=_.tsx("div",{class:this.classes(h.line,o),key:"esri-scale-bar__line",styles:{width:`${n}px`}});return _.tsx("div",{class:this.classes(h.barContainer,h.lineBarContainer),key:"esri-scale-bar__line-container"},[c,i])},l._handleRootCreateOrUpdate=function(e){const t=this.viewModel;if(!t)return;const r=e.getBoundingClientRect(),a=r.left+window.pageXOffset,l=r.top+window.pageYOffset,i=s.createScreenPoint(a,l);(i.x!==t.scaleComputedFrom.x||i.y!==t.scaleComputedFrom.y)&&(t.scaleComputedFrom=i)},e._createClass(a,[{key:"style",set:function(e){const t="dual"===this.unit?"line":e;this._set("style",t)}}]),a}(d);t.__decorate([n.property({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],y.prototype,"label",void 0),t.__decorate([n.property(),p.messageBundle("esri/widgets/ScaleBar/t9n/ScaleBar")],y.prototype,"messages",void 0),t.__decorate([n.property()],y.prototype,"style",null),t.__decorate([o.cast("style")],y.prototype,"castStyle",null),t.__decorate([n.property()],y.prototype,"unit",void 0),t.__decorate([o.cast("unit")],y.prototype,"castUnit",null),t.__decorate([a.aliasOf("viewModel.view")],y.prototype,"view",void 0),t.__decorate([n.property()],y.prototype,"viewModel",void 0),y=t.__decorate([c.subclass("esri.widgets.ScaleBar")],y);return y}));
