import{__decorate as t}from"tslib";import{s}from"./nile-slider.css.esm.js";import{N as i}from"../internal/nile-element.esm.js";import{classMap as e}from"lit/directives/class-map.js";import{html as h}from"lit";import{property as a,customElement as l}from"lit/decorators.js";import{l as n,r,s as o}from"./nile-slider.template.esm.js";import{h as c,a as m,b as p,v as d,r as u,c as v,d as b,g as y}from"./utils/nile-slider.utils.esm.js";import"../internal/accessibility/a11y.state.enum.esm.js";import"../internal/accessibility/a11y.property.enum.esm.js";import"../internal/accessibility/role.enum.esm.js";let g=class extends i{constructor(){super(...arguments),this.minValue=0,this.value=this.minValue,this.maxValue=100,this.rangeOneValue=this.minValue,this.rangeTwoValue=this.maxValue,this.showLabel=!1,this.labelStart="",this.labelEnd="",this.rangeSlider=!1,this.labelPosition="top",this.tooltipPosition="top",this.activeThumb=null,this.onMouseMove=t=>{const s=this.range.getBoundingClientRect();if(this.rangeSlider){"one"===this.activeThumb?m(t,s,this):"two"===this.activeThumb&&p(t,s,this);const i=d(this.rangeOneValue,this),e=d(this.rangeTwoValue,this),h=Math.min(i,e),a=Math.abs(e-i);this.rangeTwoValue>=this.rangeOneValue&&(this.completed.style.left=`${h}%`,this.completed.style.width=`${a}%`)}else c(t,s,this)},this.onMouseUp=()=>{this.rangeSlider?(this.emit("nile-button-first-change-end",{value:this.rangeOneValue}),this.emit("nile-button-last-change-end",{value:this.rangeTwoValue})):this.emit("nile-change-end",{value:this.value}),this.activeThumb=null,u(this)},this.onMouseDown=t=>{const s=this.range.getBoundingClientRect(),i=(t.clientX-s.left)/s.width*100,e=this.minValue+i/100*(this.maxValue-this.minValue);if(this.rangeSlider){b(e,this);const t=Math.abs(e-this.rangeOneValue),s=Math.abs(e-this.rangeTwoValue);this.activeThumb=t<=s?"one":"two",v(this)}else c(t,s,this),this.activeThumb="one",v(this)}}static get styles(){return[s]}connectedCallback(){super.connectedCallback(),this.emit("nile-init"),this.rangeSlider&&this.checkRangeValidity()}firstUpdated(t){if(y(this),!this.rangeSlider&&t.has("value")){this.value=this.checkValueValidity(this.value,this.minValue,this.maxValue);const t=d(this.value,this);this.buttonOne.style.left=`${t}%`,this.completed.style.width=`${t}%`}else if(this.rangeSlider){const t=d(this.rangeOneValue,this),s=d(this.rangeTwoValue,this);this.buttonOne&&(this.buttonOne.style.left=`${t}%`),this.buttonTwo&&(this.buttonTwo.style.left=`${s}%`);const i=Math.min(t,s),e=Math.abs(s-t);this.completed.style.left=`${i}%`,this.completed.style.width=`${e}%`}}checkValueValidity(t,s,i){return i-s<=1?Math.max(s,Math.min(t,i)):Math.floor(Math.max(s,Math.min(t,i)))}checkRangeValidity(){this.rangeTwoValue>this.maxValue?this.rangeTwoValue=this.maxValue:this.rangeTwoValue<this.rangeOneValue&&(this.rangeTwoValue=this.rangeOneValue),this.rangeOneValue<this.minValue?this.rangeOneValue=this.minValue:this.rangeOneValue>this.rangeTwoValue&&(this.rangeOneValue=this.rangeTwoValue)}render(){const t=this.showLabel,s=t?"label-start label-end":void 0;return h`
      <div
        part="base"
        class=${e({container:!0,"align-item-center":!t})}
      >
        <slot class="span" name="prefix"></slot>
  
        <div
          part="range-container"
          class=${e({"range-container":!0,"column-reverse":"bottom"===this.labelPosition})}
        >
          ${t?n(this):h``}
  
          <div
            class="range"
            part="range"
            role="group"
            aria-labelledby=${s}
          >
            <span class="range-completed" part="range-completed"></span>
            ${this.rangeSlider?r(this):o(this)}
          </div>
        </div>
  
        <slot class="span" name="suffix"></slot>
      </div>
    `}disconnectedCallback(){super.disconnectedCallback(),this.emit("nile-destroy")}};t([a({type:Number})],g.prototype,"minValue",void 0),t([a({type:Number})],g.prototype,"value",void 0),t([a({type:Number})],g.prototype,"maxValue",void 0),t([a({type:Number})],g.prototype,"rangeOneValue",void 0),t([a({type:Number})],g.prototype,"rangeTwoValue",void 0),t([a({type:Boolean})],g.prototype,"showLabel",void 0),t([a({type:String})],g.prototype,"labelStart",void 0),t([a({type:String})],g.prototype,"labelEnd",void 0),t([a({type:Boolean})],g.prototype,"rangeSlider",void 0),t([a({type:String})],g.prototype,"labelPosition",void 0),t([a({type:String})],g.prototype,"tooltipPosition",void 0),g=t([l("nile-slider")],g);export{g as N};
