import{d as V,a as j,r as n,Z as G,bk as J,b as Q,e as y,c3 as Z,s as A,b1 as Y,f as M,h as r,aG as h,i as m,C as S,D as H,bL as q,g as t,z as c,v as ee,A as E,o as g,t as te,aW as ae,aH as ue,bI as d,J as oe,_ as se}from"./BxiWQxwE.js";const ne={class:"product__quantity--controls"},le=["aria-label","disabled"],ie=["min","max","value","disabled","aria-label"],re=["aria-label","disabled"],ce={class:"product__quantity--add-wrapper"},de=["aria-label"],ve=["disabled"],pe=3e3,fe=V({__name:"quantity-original",props:{product:{type:Object,required:!0},weightSelectorOpen:{type:Boolean,required:!1,default:!1},showLargeButton:{type:Boolean,required:!1,default:!1}},emits:["add-quantity","remove-quantity","no-quantity-selected","update"],setup(k,{emit:F}){const v=k,{$messages:p}=j(),s=n(!0),e=n(0),{basketData:L}=G(),l=n(!1),u=n(!1),o=n(!1),{isDesktop:C,isMobile:R}=J(),{showWeightSelector:x}=Q(),P=n(null),O=n(),D=y(()=>e.value===d.MIN),w=y(()=>e.value===d.MAX),b=F,N=a=>{const i=Number(a.target.value);e.value=Math.min(Math.max(i,d.MIN),d.MAX)},B=()=>{if(!w.value){if(v.product.isWeightProduct&&!x.value){x.value=v.product.productId,o.value=!0,u.value=!0;return}u.value=!0,o.value=!0,e.value++}},U=()=>{D.value||e.value--},W=()=>{e.value!==f.value&&(s.value=!0,e.value>0&&f.value===0?b("add-quantity",e.value):_.value&&e.value<1&&f.value>0?b("remove-quantity"):_.value&&e.value>0&&b("update",{product:_.value,quantity:e.value}),K())},X=()=>{C||setTimeout(()=>{e.value>0&&(u.value=!1,l.value=!0,o.value=!1)},0)},$=()=>{e.value>0&&(u.value=!0,o.value=!0)},z=()=>{e.value>0&&(O.value=setTimeout(()=>{u.value=!1,l.value=!0,o.value=!1},pe))},K=()=>{C||(clearTimeout(O.value),z())},_=y(()=>{var a;return(a=L.value)==null?void 0:a.productLines.find(i=>i.productId===v.product.productId)}),f=y(()=>{var a;return((a=_.value)==null?void 0:a.quantity)??0});Z(()=>{e.value=f.value,setTimeout(()=>{s.value=!1},1e3)}),A(f,a=>{a!==e.value&&(e.value=a),s.value&&(s.value=!1)}),Y(e,()=>{W()},{debounce:1300}),A(()=>v.weightSelectorOpen,()=>{v.weightSelectorOpen||T()}),A(()=>e.value,a=>{if(R){l.value=!0,u.value=!1,o.value=!1;return}if(a>0){l.value=!0,u.value=!0,o.value=!0;return}T()});const T=()=>{l.value=!1,u.value=!1,o.value=!1,b("no-quantity-selected")};return(a,i)=>{const I=oe;return g(),M("div",{class:E(["product__quantity",{"weight-selector-open":k.weightSelectorOpen}]),onClick:c(()=>{},["stop"])},[r("div",ne,[m(H,{name:"slide-minus"},{default:S(()=>[h(r("button",{type:"button",class:E(["product__quantity--button button--remove",{"button--delete":t(e)===1}]),"aria-label":t(p)("aria.quantity.remove"),disabled:t(D)||t(s),onClick:c(U,["stop"])},[(g(),te(ae(`svgo-${t(e)===1?"delete":"minus"}`)))],10,le),[[q,t(o)]])]),_:1}),m(H,{name:"slide-input"},{default:S(()=>[h(r("input",{ref_key:"inputEl",ref:P,class:"product__quantity--input",type:"number",pattern:"[0-9]{1,3}",min:t(d).MIN,max:t(d).MAX,value:t(e),disabled:t(s),maxlength:"3","aria-label":t(p)("aria.quantity.input"),enterkeyhint:"done",onBlur:X,onKeyup:ue(N,["enter"]),onFocus:$,onChange:N,onClick:i[0]||(i[0]=c(me=>u.value=!0,["stop"]))},null,40,ie),[[q,t(l)||t(u)]])]),_:1}),h(r("button",{class:"product__quantity--button button--add",type:"button","aria-label":t(p)("aria.quantity.add"),disabled:t(w)||t(s),onClick:c(B,["stop"])},[m(I)],8,re),[[q,t(o)]])]),h(r("div",ce,[k.showLargeButton?(g(),M("button",{key:0,type:"button",class:"product__quantity--button button--large","aria-label":t(p)("aria.plusOne"),onClick:c(B,["stop"])},[r("span",null,ee(t(p)("common.addProduct")),1),m(I)],8,de)):(g(),M("button",{key:1,class:"product__quantity--button button--add",type:"button","aria-label":"toevoegen",disabled:t(w)||t(s),onClick:c(B,["stop"])},[m(I)],8,ve))],512),[[q,t(e)===0]])],2)}}}),_e=se(fe,[["__scopeId","data-v-455553e7"]]);export{_e as default};
