/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import{b as u}from"./R65RAOHV.js";import{H as r,h as n,i as a}from"./5CQPQ7AE.js";import"./3QPJ2JCA.js";var c=n`:host{display:block;margin-block-start:var(--padding)}[role=group],li{display:grid;grid-template-columns:1fr auto}[role=group]{align-items:end;gap:var(--padding);calcite-label{--calcite-label-margin-bottom: 0}calcite-button{height:32px}}ol,li{list-style:none;padding:0;margin:0}ol{border:var(--border-style);margin-block-start:var(--padding)}li{align-items:center;padding-inline-start:var(--padding);&:not(:last-child){border-bottom:var(--border-style)}span{color:inherit;font-size:inherit;font-weight:var(--calcite-font-weight-normal)}calcite-button{--calcite-icon-color: var(--calcite-color-text-3);width:var(--close-button-size);height:var(--close-button-size)}}`;function l(i){return a`<li class="buffer-distance-value"><span>${i.value}</span><calcite-button kind=neutral appearance=transparent scale=s @click=${i.onRemoveClick} .label=${i.removeValueLabel}><calcite-icon icon=x scale=s></calcite-icon></calcite-button></li>`}var s=class extends r{constructor(){super(...arguments),this.#e=3,this._uniqueDistanceValues=new Set}static{this.properties={_uniqueDistanceValues:16,distanceValuesSorted:32,bufferInputStep:11,bufferDistance:11,bufferMinDistance:11,bufferMaxDistance:11,inputNumberLabel:1,addButtonLabel:1,removeValueLabel:1}}static{this.styles=c}#e;#t;#i;#a;#s;get distanceValuesSorted(){return[...this._uniqueDistanceValues].sort((e,t)=>e-t)}get bufferInputStep(){return this.#s}set bufferInputStep(e){this._validateBufferNumber(e,"bufferInputStep"),this.#s=e}get bufferDistance(){return this.#t}set bufferDistance(e){if(this._validateBufferNumber(e,"bufferDistance"),e<this.bufferMinDistance)throw new Error("bufferDistance must be greater than bufferMinDistance");if(e>this.bufferMaxDistance)throw new Error("bufferDistance must be less than bufferMaxDistance");this.#t=e}get bufferMinDistance(){return this.#i}set bufferMinDistance(e){if(this._validateBufferNumber(e,"bufferMinDistance"),e>this.bufferMaxDistance)throw new Error("bufferMinDistance must be less than bufferMaxDistance");this.#i=e}get bufferMaxDistance(){return this.#a}set bufferMaxDistance(e){if(this._validateBufferNumber(e,"bufferMaxDistance"),e<this.bufferMinDistance)throw new Error("bufferMaxDistance must be greater than bufferMinDistance");this.#a=e}_validateBufferNumber(e,t){if(typeof e!="number"||Number.isNaN(e))throw new Error(`${t} must be a valid number`);if(e<=0)throw new Error(`${t} must be > 0`)}_maybeAddDistanceValue(){this._uniqueDistanceValues.size<this.#e&&(this._uniqueDistanceValues=new Set([...this._uniqueDistanceValues,this.bufferDistance]))}_removeDistanceValue(e){this._uniqueDistanceValues.size&&(this._uniqueDistanceValues.delete(e),this._uniqueDistanceValues=new Set(this._uniqueDistanceValues))}_getRemoveValueLabel(e){return this.removeValueLabel.replace("{number}",`${e}`)}_onBufferDistanceInputInput(e){let t=Number(e.target.value);t>=this.bufferMinDistance&&t<=this.bufferMaxDistance&&(this.bufferDistance=t)}_renderDistanceValuesList(){return this._uniqueDistanceValues.size?a`<ol role=list>${this.distanceValuesSorted.map(e=>l({value:e,removeValueLabel:this._getRemoveValueLabel(e),onRemoveClick:()=>this._removeDistanceValue(e)}))}</ol>`:null}render(){return a`<div><div role=group><calcite-label><span>${this.inputNumberLabel}</span><calcite-input-number .value=${`${this.bufferDistance}`} .step=${this.bufferInputStep} .min=${this.bufferMinDistance} .max=${this.bufferMaxDistance} @calciteInputNumberInput=${this._onBufferDistanceInputInput}></calcite-input-number></calcite-label><calcite-button icon-start=plus @click=${this._maybeAddDistanceValue} appearance=outline>${this.addButtonLabel}</calcite-button></div>${this._renderDistanceValuesList()}</div>`}};u("instant-apps-buffer-distance-manager",s);export{s as InstantAppsBufferDistanceManager};
