import{a as V}from"./B7jNADEc.js";import{_ as M}from"./CAQNniay.js";import{i as U}from"./vY_KiDi_.js";import{u as j}from"./CSqzEET8.js";import{d as z,Y as q,j as P}from"./Cfh3kXIQ.js";import{l as G,a1 as H,k,b as J,E as m,P as w,J as I,Z as y,R as Y,F as R,D as Z,U as K,L as Q,N as X,u as d,O as x}from"./DEIzhR9A.js";const ee=(s,a={columns:2,page:1,perPage:24})=>{const{columns:l,page:r,perPage:p}=a,f=s+(r-1)*p;return Math.floor(f/l)},te=(s,a)=>a.reduce((l,r,p)=>(r.insert_in_row===s.toString()&&l.push(r),l),[]),$=(s,a)=>s%a===0,se=(s,a)=>a.includes(s.toString()),oe=24,ue=G({__name:"ProductList",props:{products:{type:Array,default:()=>[]},loading:{type:Boolean,default:!1},refreshing:{type:Boolean,default:!1},isInWishlist:{type:Function,default:()=>{}},showAddToCart:{type:Boolean,default:!1},columns:{type:Number,default:2},perPage:{type:Number,default:oe},disruptors:{type:Array,default:()=>[]}},emits:["intersect:row","click:toggle-product-wishlist","click:product","click:add-to-basket"],setup(s,{emit:a}){const l=s,r=a,{getProductDetailRoute:p}=j(),{disruptors:f,products:b,columns:u}=H(l),B=k(()=>f.value.map(e=>e.insert_in_row)),F=z(),A=k(()=>parseInt(F.query.page)||1),h=e=>ee(e,{columns:l.columns,page:A.value,perPage:l.perPage}),v=J([]),D=(e,i)=>{const g=h(i);if($(i,u.value)&&v.value.findIndex(t=>t.row===g)===-1){const t=b.value.slice(i,i+u.value).map((o,n)=>({...o,index:i+n}));r("intersect:row",{row:g,items:t}),v.value.push({row:g,items:t})}},O=e=>{var i;return e?!!((i=P(e.attributes,"editedOnlineExclusive"))!=null&&i.label):!1},S=e=>e?U(e):!1,L=e=>{var i;return!!((i=P(e.attributes,"editedPremium"))!=null&&i.label)},_=e=>u.value===e,E=e=>se(h(e),B.value),W=e=>$(e,u.value),T=e=>te(h(e),f.value),N=k(()=>{const e=[];return _(1)?e.push("grid-cols-1"):e.push("grid-cols-2"),e.push(`md:grid-cols-${l.columns}`),e});return(e,i)=>{const g=V,C=M;return m(),w("div",{class:x(["mt-4 grid w-auto gap-1",d(N)])},[(m(!0),w(I,null,y(d(b),(t,o)=>Y(e.$slots,"product",{product:t,loading:s.loading,refreshing:s.refreshing},()=>[E(o)&&W(o)?(m(!0),w(I,{key:0},y(T(o),n=>(m(),R(Z(n.component),{key:n._uid,index:o,blok:n,"onClick:toggleProductWishlist":c=>r("click:toggle-product-wishlist",t),"onClick:product":c=>r("click:product",t,o)},null,40,["index","blok","onClick:toggleProductWishlist","onClick:product"]))),128)):K("",!0),Q(C,{important:o<d(u)*2,"placeholder-ratio":"2/3"},{default:X(()=>{var n;return[(m(),R(g,{id:t.id,key:`product-${t.id}`,columns:d(u),"badge-label":e.$helpers.product.getBadgeLabel({isSoldOut:t.isSoldOut,isOnlineOnly:O(t),isSustainable:S(t),isPremium:L(t)}),colors:d(q)(t),link:d(p)(t),"is-in-wishlist":s.isInWishlist({productId:t.id}),image:e.$helpers.image.getFirstModelImage(t.images,o),"hover-images":e.$helpers.image.getModelImages(t.images),"show-add-to-cart":s.showAddToCart,loading:!s.loading&&s.refreshing,price:e.$helpers.product.getLowestPrice(t.variants),"lowest-prior-price":e.$helpers.product.getVariantWithLowestPrice(t.variants).lowestPriorPrice,variants:t.variants,title:((n=e.$helpers.attribute.getFirstAttributeValue(t.attributes,"name"))==null?void 0:n.label)||"","onClick:addToBasket":c=>r("click:add-to-basket",{variant:c,product:t,index:o}),"onClick:toggleWishlist":c=>r("click:toggle-product-wishlist",t,o),"onIntersect:product":c=>D(c,o),"onClick:product":c=>r("click:product",t,o)},null,8,["id","columns","badge-label","colors","link","is-in-wishlist","image","hover-images","show-add-to-cart","loading","price","lowest-prior-price","variants","title","onClick:addToBasket","onClick:toggleWishlist","onIntersect:product","onClick:product"]))]}),_:2},1032,["important"])])),256))],2)}}});export{oe as D,ue as _};