import{_ as S,o as r,b as o,v as l,q as y,F as m,e as T,n as h,p,u as w,I as Q,T as R,L as D,aJ as U,k as x,E as B,r as f,N as O,O as P,Z as _,l as v,a as q,w as C}from"./main-BDtKGhFI.js";import{_ as k}from"./sellingUnitMixin-BqI7WVPQ.js";const A={methods:{allowQuantityPartials(t){return t==null?void 0:t.partPackagingAllowed}}},E={name:"PriceRowsSavingsFi",mixins:[k],props:{savings:{type:Array,default:()=>[]},mobile:{type:Boolean,default:!1}},emits:["clicked"],computed:{currency(){return this.savings.currency}},methods:{prefix(t){return t!=null&&t.code?this.getSellingUnit(t.code):this.getSellingUnit("ST")},isSaving(t){var e;return(e=t.savingsInformation)==null?void 0:e.savingsInPercent},rowClicked(t){this.$emit("clicked",t)}}},K={key:0,class:"price-rows-savings-fi__label"},M=["onClick"],H={class:"price-rows-savings-fi__qtd"},L={class:"price-rows-savings-fi__price"},z={"data-test":"price-rows-price"},Z={class:"price-rows-savings-fi__price-prefix"},$={class:"price-rows-savings-fi__saving"},W={key:0,"data-test":"price-rows-saving",class:"price-rows-savings-fi__saving__saving badge-fi"};function j(t,e,i,u,a,n){return r(),o("div",{class:h({"price-rows-savings-fi":!0,"price-rows-savings-fi--mobile":i.mobile})},[i.mobile?(r(),o("div",K,l(t.$dict.get("online-Shop.Product.Price-Rows-Savings")),1)):y("",!0),(r(!0),o(m,null,T(i.savings,(s,d)=>(r(),o("div",{key:d,class:h({"price-rows-savings-fi__row":!0,"price-rows-savings-fi__row--active":s.active}),onClick:V=>i.mobile?null:n.rowClicked(s)},[p("div",H,[d===0?(r(),o(m,{key:0},[w(l(s.minQty)+" "+l(n.prefix(s.unit)),1)],64)):(r(),o(m,{key:1},[w(l(t.$dict.get("online-Shop.Product.Price-Rows-Quantity-Label",[`${s.minQty} ${n.prefix(s.unit)}`])),1)],64))]),p("div",L,[p("strong",z,l(s.valueFormatted),1),p("span",Z,"/ "+l(s.priceQty!==1?s.priceQty:null)+" "+l(n.prefix(s.unit)),1)]),p("div",$,[n.isSaving(s)?(r(),o("span",W,l(t.$dict.get("online-Shop.Product.Price-Rows-Saving-Label",[s.savingsInformation.savingsInPercent])),1)):y("",!0)])],10,M))),128))],2)}const G=S(E,[["render",j],["__scopeId","data-v-dbb8ef36"]]),J={methods:{getRawValue(t){return String(t).replace(/\D/g,"")},getFormattedValue(t){const e=this.getRawValue(t);return new Intl.NumberFormat(this.$fischer.siteLanguage()).format(e)}}},g=99e4,I=(t,e)=>{if(Number.isNaN(t))return!1;const i=e.rangeFrom!==null?t>=e.rangeFrom:!0,u=e.rangeTo!==null?e.rangeTo:g,a=t<=u;return i&&a},X=(t,e)=>Number.isNaN(t)?!1:t<=e.rangeTo,b=(t,e)=>t%e.rangeValue===0,Y=(t,e)=>{if(e.rangeValue===null&&e.rangeFrom===null&&e.rangeTo===null)return null;let i=t;const u=e.rangeTo||g,a=e.rangeFrom||0;if(i<=a)return;const n=i%e.rangeValue;n?i-=n:i-=e.rangeValue;let s=Math.max(i,a);if(s>u&&(s=u),s!==0)return s},tt=(t,e)=>{if(e.rangeValue===null&&e.rangeFrom===null&&e.rangeTo===null)return null;const i=e.rangeTo||g,u=e.rangeFrom||0;if(t>=i)return;let a=t-t%e.rangeValue+e.rangeValue;return a<u&&(a=u),Math.min(a,i)},et={name:"QuantitySteps",components:{IconFi:Q,TextInputFi:R,LinkFi:D,PriceRowsSavingsFi:G},directives:{clickOutside:U.directive},mixins:[k,x,J,A],props:{item:{type:Object,default:null},template:{default:"article",type:String},requestedQuantity:{type:Number,default:null},noBtnMargins:{type:Boolean},isLoading:Boolean,disabled:{default:!1,type:Boolean},disabledText:{default:"",type:String},productId:{type:[String,Number],default:null},light:Boolean,small:{default:!1,type:Boolean},large:{default:!1,type:Boolean},priceRowsSavings:{type:Array,default:null},selectInputOnFocus:{type:Boolean,default:!1},arrowKeyControlEnabled:{type:Boolean,default:!1},triggerRemoveEventOnZero:{type:Boolean,default:!1},autoWidth:{type:Boolean,default:!1}},emits:["arrow-key-pressed","blur","focus","keyup-enter","quantity-input","quantity-stepper-remove-item","scrollToElement","text-input","update-quantity","user-input","value-rounded"],data(){return{quantityInputValue:"1",maxInputValue:g,isClicked:void 0,timeOut:null,stepDownHover:!1,stepUpHover:!1,showSavings:!1}},computed:{allowPartials(){return this.allowQuantityPartials(this.item)},myTemplate(){const t=[];return this.template&&t.push(`quantity-steps--${this.template}`),this.light&&t.push("quantity-steps--light"),this.small&&!this.large&&t.push("quantity-steps--small"),this.large&&t.push("quantity-steps--large"),t},stepRanges(){var t;return((t=this.item)==null?void 0:t.quantityStepRanges)||[{}]},prefix(){var t,e;return(e=(t=this.item)==null?void 0:t.unit)!=null&&e.code?this.getSellingUnit(this.item.unit.code):this.getSellingUnit("ST")},inputDisabled(){if(this.disabled||this.stepRanges===null||this.stepRanges.length===0)return!0;if(this.stepRanges.length===1){const t=this.stepRanges[0];if(t.rangeFrom===null&&t.rangeTo===null&&t.rangeValue===null)return!0}return!1},theme(){return this.template==="article"?"theme--blocky":"theme--blocky-dark"},buttonClass(){return[this.theme,"ma-0","quantity-steps__buttons"]},inputValue(){return parseInt(this.getRawValue(this.quantityInputValue),10)},stepUp(){let t;return this.stepRanges.forEach(e=>{const i=tt(this.inputValue,e);Number.isNaN(i)||i>t||(t=i)}),t===void 0&&(t=null),t},stepDown(){let t;return this.stepRanges.forEach(e=>{const i=Y(this.inputValue,e);Number.isNaN(i)||i<t||(t=i)}),t===void 0&&(t=null),t}},watch:{requestedQuantity(t){this.quantityInputValue=this.getFormattedValue(t)},item:{deep:!0,handler(t,e){if(!t||e&&e.articleNo===t.aricleNo)return;const i=this.requestedQuantity||t&&(t.quantity||t.requestedQuantity||t.initialQuantity)||1;this.quantityInputValue=this.getFormattedValue(i)},immediate:!0}},methods:{focus(){this.$refs.input&&this.$refs.input.focus()},updateQuantityInputValue(t){this.debounceInput||(this.debounceInput=B(600,()=>{const e=this.getRawValue(this.quantityInputValue);e>0&&(this.allowPartials||this.stepRanges.some(i=>b(e,i)&&I(e,i)))&&this.$emit("user-input",e)})),this.quantityInputValue=this.getFormattedValue(t),this.$emit("user-input"),this.debounceInput()},onKeyUpEnter(t){this.quantityStepInputField(t,!1),this.$emit("keyup-enter")},onBlur(t,e){this.quantityStepInputField(t,!0),this.$emit("blur",t,e)},getInputValue(){return this.inputValue},quantityStepPlus(){this.isAppView&&(this.stepUpHover=!1),this.$emit("quantity-input"),this.timeOut&&clearTimeout(this.timeOut),this.stepUp!==null&&(this.quantityInputValue=this.getFormattedValue(this.stepUp),this.setTimeOut())},quantityStepMinus(){this.isAppView&&(this.stepDownHover=!1),this.$emit("quantity-input"),this.timeOut&&clearTimeout(this.timeOut),this.stepDown!==null&&(this.quantityInputValue=this.getFormattedValue(this.stepDown),this.setTimeOut())},triggerInput(){this.quantityStepInputField(this.quantityInputValue,!0)},quantityStepInputField(t,e){if(this.triggerRemoveEventOnZero&&parseInt(t,10)===0){this.$emit("quantity-stepper-remove-item",this.item.articleNo);return}let i;t.target?i=this.getRawValue(t.target.value):i=this.getRawValue(t),i>g&&(i=this.getFormattedValue(g)),this.quantityInputValue=String(i),this.quantityInputValue.length||(this.quantityInputValue="0");const u=parseInt(this.quantityInputValue,10);let a,n;if(u>0){if(this.allowPartials)a=!0;else for(let s=0;s<this.stepRanges.length;s+=1){const d=this.stepRanges[s];if(b(u,d)&&I(u,d)){a=!0,this.quantityInputValue=this.getFormattedValue(this.quantityInputValue);break}else if(this.item.articleStatus==="REMAINING_STOCK"&&!X(u,d)){n=!0,this.quantityInputValue=this.getFormattedValue(d.rangeTo);break}}if(a){const s=this.getRawValue(this.quantityInputValue);if(e&&(s===this.item.quantity||s===String(this.item.requestedQuantity)))return;this.sendNewQuantityToParent()}else n?(this.$emit("update-quantity",this.quantityInputValue,this.productId),this.$emit("value-rounded",this.$dict.get("online-Shop.Product.Out-Of-Remaining-Stock"))):this.roundValue()}else this.roundValue();this.quantityInputValue=this.getFormattedValue(this.quantityInputValue)},changeQuantity(t){this.closeSavings(),this.quantityInputValue=t,this.sendNewQuantityToParent(),this.quantityInputValue=this.getFormattedValue(t)},setTimeOut(){this.timeOut=setTimeout(()=>{this.sendNewQuantityToParent(),this.timeOut=null},1e3)},sendNewQuantityToParent(){const t=this.getRawValue(this.quantityInputValue),e=typeof t=="string"?parseInt(t,10):t;this.$emit("update-quantity",e,this.productId)},roundValue(){var t;if((t=this.stepRanges)!=null&&t.length){const e=this.stepRanges[0].rangeValue,i=Math.ceil(this.getRawValue(this.quantityInputValue)/e);let u=e*i;u<e&&(u=e),this.quantityInputValue=String(u),this.$emit("update-quantity",this.quantityInputValue,this.productId),this.$emit("value-rounded",this.$dict.get("online-Shop.Product.Quantity-Rounded-Up",[e]),"rounded-up")}},quantityFocused(){this.isMD&&this.openSavings(),this.$emit("focus")},openSavings(){this.isMD?this.showSavings=!0:this.$emit("scrollToElement")},closeSavings(){this.showSavings=!1},onArrowKeyUp(){this.arrowKeyControlEnabled&&(this.quantityInputValue=this.getFormattedValue(this.stepUp),this.$emit("arrow-key-pressed"))},onArrowKeyDown(){this.arrowKeyControlEnabled&&(this.quantityInputValue=this.getFormattedValue(this.stepDown),this.$emit("arrow-key-pressed"))}}},it={class:"quantity-steps__inner"},nt=["disabled"],st={key:0,class:"quantity-steps__inner__disabled-text"},at=["disabled"],ut={key:0,class:"quantity-steps__savings"},rt={class:"quantity-steps__savings__btn"};function lt(t,e,i,u,a,n){const s=f("icon-fi"),d=f("text-input-fi"),V=f("link-fi"),F=f("price-rows-savings-fi"),N=O("click-outside");return P((r(),o("div",{class:h(["quantity-steps",n.myTemplate])},[p("div",it,[p("button",{class:h({"quantity-steps__button":!0,"quantity-steps__button--hover":a.stepDownHover,"app-view":t.isAppView}),disabled:i.disabled||n.stepDown===null||isNaN(n.stepDown)||i.isLoading===!0,"data-test":"quantity-steps-minus",onClick:e[0]||(e[0]=_(c=>n.quantityStepMinus(),["stop","prevent"])),onMouseover:e[1]||(e[1]=c=>a.stepDownHover=!0),onMouseout:e[2]||(e[2]=c=>a.stepDownHover=!1)},[v(s,{class:"quantity-steps__button__icon",icon:"minus",size:i.large?"1":"0_8"},null,8,["size"])],42,nt),i.disabled&&i.disabledText?(r(),o("div",st,[p("span",null,l(i.disabledText),1)])):(r(),q(d,{key:1,id:"stk-prefix",ref:"input","data-test":"stk-prefix","model-value":a.quantityInputValue,class:h({"quantity-steps__input":!0,"text-input-fi--light text-input-fi--focus-dark":i.template==="addArticle","text-input-fi--light":i.light,"quantity-steps__input--auto-width":i.autoWidth}),small:i.small&&!i.large,large:i.large,disabled:n.inputDisabled,prefix:n.prefix,"select-input-on-focus":i.selectInputOnFocus,"arrow-key-control-enabled":"","onUpdate:modelValue":n.updateQuantityInputValue,onKeyupEnter:n.onKeyUpEnter,onKeydownArrowUp:n.onArrowKeyUp,onKeydownArrowDown:n.onArrowKeyDown,onFocus:n.quantityFocused,onBlur:n.onBlur},null,8,["model-value","class","small","large","disabled","prefix","select-input-on-focus","onUpdate:modelValue","onKeyupEnter","onKeydownArrowUp","onKeydownArrowDown","onFocus","onBlur"])),p("button",{class:h({"quantity-steps__button":!0,"quantity-steps__button--hover":a.stepUpHover,"app-view":t.isAppView}),disabled:i.disabled||n.stepUp===null||isNaN(n.stepUp)||i.isLoading===!0,"data-test":"quantity-steps-plus",onClick:e[3]||(e[3]=_(c=>n.quantityStepPlus(),["stop","prevent"])),onMouseover:e[4]||(e[4]=c=>a.stepUpHover=!0),onMouseout:e[5]||(e[5]=c=>a.stepUpHover=!1)},[v(s,{class:"quantity-steps__button__icon",icon:"plus",size:i.large?"1":"0_8"},null,8,["size"])],42,at)]),i.priceRowsSavings?(r(),o("div",ut,[p("div",rt,[v(V,{href:"#",size:t.isMD?18:16,primary:"",onClick:_(n.openSavings,["prevent"])},{default:C(()=>[w(l(t.$dict.get("online-Shop.Product.Show-Price-Rows-Savings")),1)]),_:1},8,["size","onClick"])]),a.showSavings&&t.isMD?(r(),q(F,{key:0,savings:i.priceRowsSavings,class:"quantity-steps__price-rows-savings",onClicked:e[6]||(e[6]=c=>n.changeQuantity(c.minQty))},null,8,["savings"])):y("",!0)])):y("",!0)],2)),[[N,n.closeSavings]])}const dt=S(et,[["render",lt]]);export{G as P,dt as Q,A as _};