/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{b as c}from"./HVT2WBVC.js";import{E as r,F as u,G as l,h as n,i}from"./FFF5HUPM.js";import"./EXBEKVP5.js";var o=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;margin-block:var(--add-btn-margin, 0)}}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 f(a){return i`<li class="buffer-distance-value"><span>${a.value}</span><calcite-button kind=neutral appearance=transparent scale=s @click=${a.onRemoveClick} .label=${a.removeValueLabel}><calcite-icon icon=x scale=s></calcite-icon></calcite-button></li>`}var s=class extends l{constructor(){super(...arguments),this.#e=r(),this.#t=3,this.inputNumberInvalid=!1,this._uniqueDistanceValues=new Set,this.showMissingDistanceValueErrorMessage=!1}static{this.properties={inputNumberInvalid:16,_uniqueDistanceValues:16,distanceValuesSorted:32,bufferInputStep:11,bufferDistance:11,bufferMinDistance:11,bufferMaxDistance:11,labels:0,showMissingDistanceValueErrorMessage:5}}static{this.styles=o}#e;#t;#i;#a;#s;#n;get distanceValuesSorted(){return[...this._uniqueDistanceValues].sort((e,t)=>e-t)}get bufferInputStep(){return this.#n}set bufferInputStep(e){this._validateBufferNumber(e,"bufferInputStep"),this.#n=e}get bufferDistance(){return this.#i}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.#i=e}get bufferMinDistance(){return this.#a}set bufferMinDistance(e){if(this._validateBufferNumber(e,"bufferMinDistance"),e>this.bufferMaxDistance)throw new Error("bufferMinDistance must be less than bufferMaxDistance");this.#a=e}get bufferMaxDistance(){return this.#s}set bufferMaxDistance(e){if(this._validateBufferNumber(e,"bufferMaxDistance"),e<this.bufferMinDistance)throw new Error("bufferMaxDistance must be greater than bufferMinDistance");this.#s=e}clearDistanceValues(){this._uniqueDistanceValues.size&&(this._uniqueDistanceValues=new Set([]))}maybeAddDistanceValue(){this.bufferDistance&&this._uniqueDistanceValues.size<this.#t&&(this.showMissingDistanceValueErrorMessage=!1,this._uniqueDistanceValues=new Set([...this._uniqueDistanceValues,this.bufferDistance]))}_handleNumberInputValidity(){let e=this.#e.value,t=Number(e?.value);Number.isNaN(t)||!t?this.inputNumberInvalid=!0:this.inputNumberInvalid=!1}_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`)}_removeDistanceValue(e){this._uniqueDistanceValues.size&&(this._uniqueDistanceValues.delete(e),this._uniqueDistanceValues=new Set(this._uniqueDistanceValues))}_getRemoveValueLabel(e){return this.labels.removeDistanceValue.replace("{number}",`${e}`)}_onBufferDistanceInputInput(e){let t=Number(e.target.value);t>=this.bufferMinDistance&&t<=this.bufferMaxDistance&&(this.bufferDistance=t)}_renderMissingDistanceValueErrorMessage(){return this.showMissingDistanceValueErrorMessage?i`<calcite-input-message icon=exclamation-mark-triangle status=invalid style="margin-top: 1rem;">${this.labels.missingDistanceValue}</calcite-input-message>`:null}_renderDistanceValuesList(){return this._uniqueDistanceValues.size?i`<ol role=list>${this.distanceValuesSorted.map(e=>f({value:e,removeValueLabel:this._getRemoveValueLabel(e),onRemoveClick:()=>this._removeDistanceValue(e)}))}</ol>`:null}render(){let e=this.inputNumberInvalid?"auto":0;return i`<div style=${`--add-btn-margin: ${e}`}><div role=group><calcite-label><span>${this.labels.distance}</span><calcite-input-number .value=${this.bufferDistance.toString()} .step=${this.bufferInputStep} .min=${this.bufferMinDistance} .max=${this.bufferMaxDistance} @calciteInputNumberInput=${this._onBufferDistanceInputInput} @blur=${this._handleNumberInputValidity} .validationMessage=${this.labels.distanceValueValidation} validation-icon=exclamation-mark-triangle .status=${this.inputNumberInvalid?"invalid":"idle"} ${u(this.#e)}></calcite-input-number></calcite-label><calcite-button icon-start=plus @click=${this.maybeAddDistanceValue} appearance=outline>${this.labels.add}</calcite-button></div>${this._renderMissingDistanceValueErrorMessage()}${this._renderDistanceValuesList()}</div>`}};c("instant-apps-buffer-distance-manager",s);export{s as InstantAppsBufferDistanceManager};
