/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{deprecateWidget as t}from"../core/deprecate.js";import r from"../core/Logger.js";import{watch as i}from"../core/reactiveUtils.js";import{createScreenPoint as s}from"../core/screenUtils.js";import{property as o,subclass as l}from"../core/accessorSupport/decorators.js";import{formatNumber as a}from"../intl/number.js";import{defaultUnitPropertyMetadata as n}from"../properties/defaultUnit.js";import d from"./Widget.js";import{css as c}from"./ScaleBar/css.js";import p from"./ScaleBar/ScaleBarViewModel.js";import{globalCss as u}from"./support/globalCss.js";import{messageBundle as m,tsx as h}from"./support/widget.js";function v(e,t){return a(e,{style:"unit",unit:t,unitDisplay:"short"})}let f=class extends d{constructor(e,i){super(e,i),this.messages=null,this.style="line",this.viewModel=new p,t(r.getLogger(this),"Scale Bar","arcgis-scale-bar",{version:"4.32"})}initialize(){this.addHandles(i(()=>{const{view:e}=this;return[e?.stationary,e?.center,e?.scale,e?.zoom]},([e])=>{e&&this.scheduleRender()}))}get icon(){return"actual-size"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get unit(){return this._defaultUnit}set unit(e){this._overrideIfSome("unit",e)}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}render(){const e="disabled"===this.viewModel.state,t={[u.disabled]:e};let r,i;if(!e){const{unit:e,style:t}=this,s="metric"===e||"dual"===e,o=100,l="dual"===e?"line":t;if("imperial"===e||"dual"===e){const e=this.viewModel.getScaleBarProperties(o,"imperial");e&&(i="ruler"===l?this._renderRuler(e):this._renderLine(e,"bottom"))}if(s){const e=this.viewModel.getScaleBarProperties(o,"metric");e&&(r="ruler"===l?this._renderRuler(e):this._renderLine(e,"top"))}}return h("div",{afterCreate:this._handleRootCreateOrUpdate,afterUpdate:this._handleRootCreateOrUpdate,bind:this,class:this.classes(c.base,u.widget,t)},r,i)}_renderRuler(e){const{length:t,unit:r,value:i}=e,s=Math.round(t),o=v(i,r);return h("div",{class:this.classes(c.barContainer,c.rulerBarContainer),key:c.rulerBarContainer},h("div",{class:c.ruler,styles:{width:`${s}px`}},h("div",{class:c.rulerBlock}),h("div",{class:c.rulerBlock}),h("div",{class:c.rulerBlock}),h("div",{class:c.rulerBlock})),h("div",{class:this.classes(c.labelContainer,c.rulerLabelContainer)},h("div",{class:c.label},"0"),h("div",{class:c.label},o)))}_renderLine(e,t){const{length:r,unit:i,value:s}=e,o=Math.round(r),l=v(s,i),a={[c.topLabelContainer]:"top"===t,[c.bottomLabelContainer]:"bottom"===t},n=h("div",{class:this.classes(c.labelContainer,c.lineLabelContainer,a),key:c.labelContainer},h("div",{class:c.label},l)),d={[c.topLine]:"top"===t,[c.bottomLine]:"bottom"===t},p=h("div",{class:this.classes(c.line,d),key:c.line,styles:{width:`${o}px`}});return h("div",{class:this.classes(c.barContainer,c.lineBarContainer),key:c.lineBarContainer},[p,n])}_handleRootCreateOrUpdate(e){if(!this.viewModel)return;const{scaleComputedFrom:t}=this.viewModel,r=e.getBoundingClientRect(),i=r.left+window.pageXOffset,o=r.top+window.pageYOffset,l=s(i,o);(l.x!==t.x||l.y!==t.y)&&(this.viewModel.scaleComputedFrom=l)}};e([o(n)],f.prototype,"_defaultUnit",void 0),e([o()],f.prototype,"icon",null),e([o()],f.prototype,"label",null),e([o(),m("esri/widgets/ScaleBar/t9n/ScaleBar")],f.prototype,"messages",void 0),e([o({type:["ruler","line"]})],f.prototype,"style",void 0),e([o({type:["metric","imperial","dual"]})],f.prototype,"unit",null),e([o()],f.prototype,"view",null),e([o({type:p})],f.prototype,"viewModel",void 0),f=e([l("esri.widgets.ScaleBar")],f);const b=f;export{b as default};
