class LiquidPinBehavior extends LiquidBehavior{static behaviorName="liquidPin";static viewModelEvents={"change:computedStyles":"initialize","change:isPinned":"onChangePinned"};get bindToThis(){return["onEnter","onLeave","onEnterBack","onLeaveBack"]}mm=gsap.matchMedia();options(){return{start:"top top",end:"bottom top",trigger:"self",endTrigger:"self",pin:"self",animation:null,horizontal:!1,pinnedContainer:null,pinReparent:null,pinSpacer:null,pinSpacing:!0,pinType:"fixed",onEnter:null,onLeave:null,onEnterBack:null,onLeaveBack:null,onBeforeInit:null,onAfterDestroy:null,breakpoints:{all:{},tablet:{},mobile:{}}}}initialize(){gsap.registerPlugin(ScrollTrigger);const i=this.getOption("breakpoints"),r=this.getOption("onBeforeInit"),e=this.getOption("onAfterDestroy"),t=this.view.model.get("isContainer"),a={..._.uniq(Object.keys({...i})).sort((n,s)=>this.liquidApp.breakpointsOrder.indexOf(n)-this.liquidApp.breakpointsOrder.indexOf(s)).reduce((n,s)=>{const o=window.liquid.breakpoints[s];return n[s]={direction:o.direction,value:o.value,mq:o?`(${o.direction}-width: ${o.value}px)`:"all"},n},{})};let d=Object.keys(a);this.view.el.dataset[DATA_ATTRS.STICKY_EL.JS_DATASET]="false",this.view.el.dataset[t?DATA_ATTRS.STICKY_CONTAINER.JS_DATASET:DATA_ATTRS.STICKY_WIDGET.JS_DATASET]="false",d.forEach((n,s)=>{const o=a[n],p=a[d[s+1]],h=a[d[s-1]];p?.direction==="max"&&o.direction==="max"?a[n].mq=`(min-width: ${p.value+1}px) and (max-width: ${o.value}px)`:h?.direction==="min"&&o.direction==="min"&&(a[n].mq=`(min-width: ${o.value}px) and (max-width: ${h.value-1}px)`)}),this.mm.add(_.mapObject(a,n=>n.mq),n=>{r&&r.apply(this,[this]);const{conditions:s}=n,o=Object.keys(s).find(p=>s[p]);return ScrollTrigger.create(this.buildConfig(o)),()=>{e&&e.apply(this,[this])}}),this.isInitialized=!0}buildConfig(i){i==="desktop"&&(i="all");const e=this.getOption("breakpoints")[i];let t={trigger:this.getTriggerEl(this.getOption("trigger"),this.view.el),endTrigger:this.getTriggerEl(this.getOption("endTrigger")),pin:this.getPinEl(this.getOption("pin")),start:this.getOption("start"),end:this.getOption("end"),animation:this.getOption("animation"),horizontal:this.getOption("horizontal"),pinnedContainer:this.getOption("pinnedContainer"),pinReparent:this.getOption("pinReparent"),pinSpacer:this.getOption("pinSpacer"),pinSpacing:this.getOption("pinSpacing"),pinType:this.getOption("pinType"),onEnter:this.onEnter,onLeave:this.onLeave,onEnterBack:this.onEnterBack,onLeaveBack:this.onLeaveBack};return e&&(e.trigger&&(e.trigger=this.getTriggerEl(e.trigger,this.view.el)),e.endTrigger&&(e.endTrigger=this.getTriggerEl(e.endTrigger)),e.pin&&(e.pin=this.getPinEl(e.pin)),t={...t,...e}),typeof t.start=="function"&&(t.start=t.start.bind(this)),typeof t.end=="function"&&(t.end=t.end.bind(this)),t}getPinEl(i){return typeof i=="string"?i==="self"?this.view.el:this.view.el.querySelector(i):!1}getTriggerEl(i,r=null){if(i==="closestParentContainer"){const e=this.view.model.get("parentsCollection");return e?.length?e.at(0).view.el:this.view.el}else if(i==="topParentContainer"){const e=this.view.model.get("topParentContainer");if(e)return e.view.el;if(this.view.model.get("isTopLevelContainer"))return this.view.el}else if(i==="pageContent"){if(this.liquidApp.layoutRegions?.liquidPageContent?.el)return this.liquidApp.layoutRegions?.liquidPageContent?.el}else if(i==="pageFooter"){if(this.liquidApp.layoutRegions?.liquidPageFooter?.el)return this.liquidApp.layoutRegions?.liquidPageFooter?.el}else return i==="self"?this.view.el:typeof i=="string"?document.querySelector(i):r}onEnter(){this.view.model.set("isPinned",!0),this.getOption("onEnter")?.apply(this,[this])}onLeave(){this.view.model.set("isPinned",!1),this.getOption("onLeave")?.apply(this,[this])}onEnterBack(){this.view.model.set("isPinned",!0),this.getOption("onEnterBack")?.apply(this,[this])}onLeaveBack(){this.view.model.set("isPinned",!1),this.getOption("onLeaveBack")?.apply(this,[this])}onChangePinned(){const i=this.view.model.get("isContainer"),r=this.view.model.get("isPinned"),e=getComputedStyle(this.view.el).transitionProperty;if(this.view.el.dataset[DATA_ATTRS.STICKY_EL.JS_DATASET]=r?"true":"false",this.view.el.dataset[i?DATA_ATTRS.STICKY_CONTAINER.JS_DATASET:DATA_ATTRS.STICKY_WIDGET.JS_DATASET]=r?"true":"false",e.includes("transform")){const t=e.split(",").map(l=>l.trim());this.view.el.style.transitionProperty=t.filter(l=>l!=="transform").join(", ")}}killMM(){this.mm?.kill(!0)}destroy(){this.killMM(),super.destroy()}}typeof window<"u"&&(window.liquid?.app?window.liquid?.app?.model?.set("loadedBehaviors",[...window.liquid.app.model.get("loadedBehaviors"),LiquidPinBehavior]):window.liquid?.loadedBehaviors?.push(LiquidPinBehavior));