class LiquidDynamicRangeBehavior extends LiquidBehavior{static behaviorName="liquidDynamicRange";elTextAnimations=[];lastValue=0;lastSeparatedText=0;options(){return{range:{},el:null,placeholderEl:null,separator:null,appendSeparatedTo:null,hideElsIfNan:null,showElsIfNan:null,duration:1,useLocaleString:!1,changeExtra:[]}}initialize(){const i=this.view.model.get("topParentContainer");if(!i||!this.getOption("el"))return;const a=i.get("childrenCollection");a?.length&&(this.el=this.view.el.querySelector(this.getOption("el")),this.placeholderEl=this.view.el.querySelector(this.getOption("placeholderEl")),this.el&&(this.range=this.getOption("range"),this.separator=this.getOption("separator"),this.appendSeparatedTo=this.view.el.querySelector(this.getOption("appendSeparatedTo")),this.hideElsIfNan=this.view.el.querySelectorAll(this.getOption("hideElsIfNan")),this.showElsIfNan=this.view.el.querySelectorAll(this.getOption("showElsIfNan")),this.changeExtra=this.getOption("changeExtra"),a.on("change:currentRangeKey",this.onParentChildrenRangeChange.bind(this)),this.view.model.trigger("init:dynamicRange",this)))}onParentChildrenRangeChange(i,a){let t=this.range[a],l;if(!t)return;if(this.separator){const e=t.split(this.separator);e.length>1&&(t=e[0],l=e[1])}const n={value:this.lastValue};if(this.killAnimations(),this.elTextAnimations=[],this.placeholderEl&&(this.placeholderEl.innerText=t),isNaN(parseFloat(t.replace(/,/g,""))))return this.hideElsIfNan?.length&&this.hideElsIfNan.forEach(e=>e.style.display="none"),this.showElsIfNan?.length&&this.showElsIfNan.forEach(e=>e.style.display="block"),this.el.innerText=t,this.lastValue=0;this.hideElsIfNan?.length&&this.hideElsIfNan.forEach(e=>e.style.display=""),this.showElsIfNan?.length&&this.showElsIfNan.forEach(e=>e.style.display="");const h=gsap.to(n,{value:parseFloat(t.replace(/,/g,"")),duration:this.getOption("duration"),ease:"power2.inOut",snap:{value:t.indexOf(".")===-1?1:this.getDecimal(t)},onUpdate:()=>{const e=this.getString(n.value);this.el.innerText=e}});if(this.lastValue=this.range[a],this.elTextAnimations.push(h),this.changeExtra.filter(e=>e.key===a).forEach(e=>{this.view.el.querySelectorAll(e.el).forEach(s=>s.innerText=e.value)}),l&&this.appendSeparatedTo){const e={value:this.lastSeparatedText};if(isNaN(parseFloat(l.replace(/,/g,""))))return this.appendSeparatedTo.innerText=l;const o=gsap.to(e,{value:l,duration:this.getOption("duration"),ease:"power2.inOut",snap:{value:l.indexOf(".")===-1?1:this.getDecimal(l)},onUpdate:()=>{const s=this.getString(e.value);this.appendSeparatedTo.innerText=s}});this.lastSeparatedText=l,this.elTextAnimations.push(o)}}getDecimal(i){i=i.toString();const a=i.split(".")[1];let t;switch(console.log(a),a.length){case 1:t=.1;break;case 2:t=.01;break;case 3:t=.001;break;default:t=1e-4}return t}getString(i){return!this.getOption("useLocaleString")||isNaN(parseFloat(i))?i:parseFloat(i).toLocaleString()}killAnimations(){this.elTextAnimations.forEach(i=>i.kill())}destroy(){this.killAnimations(),super.destroy()}}typeof window<"u"&&(window.liquid?.app?window.liquid?.app?.model?.set("loadedBehaviors",[...window.liquid.app.model.get("loadedBehaviors"),LiquidDynamicRangeBehavior]):window.liquid?.loadedBehaviors?.push(LiquidDynamicRangeBehavior));
