import{a as s,r as o,j as f,F as q}from"./index.9be5fb1a.js";import{Link as M}from"./ecb79917.js";import{f as A}from"./92add5bc.js";import"./a36cb30c.js";import"./d060b8a3.js";import{u as J}from"./4a28fcdf.js";import"./097174ad.js";import"./f84d33f8.js";import"./1cfd448b.js";import"./a5033887.js";import"./119338b3.js";import{c as K}from"./2e4f433f.js";import"./3245d962.js";import{g as x}from"./3037522c.js";import{ProductCard as P}from"./8bc5270c.js";import"./c215153d.js";import"./0ddb42b7.js";/* empty css */import"./ac04e32d.js";import"./3fd5546a.js";import"./30205710.js";import"./133c3a40.js";import"./88f224b7.js";import"./31dfd9ab.js";import"./391fa51f.js";import"./66d5f687.js";import"./fc0e79f7.js";import"./c05ec191.js";function R({as:d="button",className:r="",variant:a="",width:p="",...c}){const m=c!=null&&c.to?M:d,i={primary:"btn-prim",secondary:"btn-sec",inline:"border-b border-primary/10 leading-none pb-1"},h={auto:"w-auto",full:"w-full"},u=K(B(r,"bg-")&&i[a],B(r,"w-")&&h[p],r);return s(m,{className:u,...c})}function B(d,r){if(!d)return!0;const a=new RegExp(` ?${r}`,"g");return d.match(a)===null}function Ne({url:d,collection:r}){var y,E,L,k;const a=o.exports.useRef(null),p=((y=r==null?void 0:r.products)==null?void 0:y.nodes)||[],{hasNextPage:c,endCursor:m}=(L=(E=r==null?void 0:r.products)==null?void 0:E.pageInfo)!=null?L:{},[i,h]=o.exports.useState(p),[u,T]=o.exports.useState(m!=null?m:""),[b,O]=o.exports.useState(c),[l,v]=o.exports.useState(!1),U=p.length>0,g=o.exports.useCallback(async()=>{var I,j,F,S;v(!0);const t=new URL(window.location.origin+d);t.searchParams.set("cursor",u);const n=await fetch(t,{method:"POST"}),{data:e}=await n.json(),D=A(((I=e==null?void 0:e.collection)==null?void 0:I.products)||(e==null?void 0:e.products)||[]),{endCursor:G,hasNextPage:H}=((F=(j=e==null?void 0:e.collection)==null?void 0:j.products)==null?void 0:F.pageInfo)||((S=e==null?void 0:e.products)==null?void 0:S.pageInfo)||{endCursor:"",hasNextPage:!1};h([...i,...D]),T(G),O(H),v(!1)},[u,d,i]),N=o.exports.useCallback(t=>{t.forEach(n=>{n.isIntersecting&&g()})},[g]);o.exports.useEffect(()=>{const t=new IntersectionObserver(N,{rootMargin:"100%"}),n=a.current;return n&&t.observe(n),()=>{n&&t.unobserve(n)}},[a,u,N]);const{pathname:w}=J(),C=w==="/products";`${r==null?void 0:r.handle}`;function $(t){return t.filter(e=>(e==null?void 0:e.productType)==="EDP 50ML"||(e==null?void 0:e.productType)==="COL 100ML"||(e==null?void 0:e.productType)==="EHP 10ML")}const z=C?$(i):i;if(U){if(C)return f("div",{className:"mx-auto px-0 md:px-12",children:[s("div",{className:"product-card-grid",children:z.map((t,n)=>s("div",{className:"product-card bg-[#F3ECEE]",children:s(P,{product:t,loading:x(n)})},t.id))}),b&&s("div",{className:"flex items-center justify-center mt-6",ref:a,children:s(R,{variant:"secondary",disabled:l,onClick:g,width:"full",children:l?"Loading...":"Load more products"})})]})}else return f("div",{className:"page-container",children:[s("p",{children:"No products found on this collection"}),s(M,{to:"/products",children:s("p",{className:"underline",children:"Browse catalog"})})]});return f(q,{children:[s("div",{className:"md:page-container",children:r!=null&&r.image?f("div",{className:"collection-page-grid",children:[s("div",{className:"collection-card large",children:s("div",{className:"",style:{backgroundImage:`url(${(k=r==null?void 0:r.image)==null?void 0:k.url})`,backgroundPosition:"center",backgroundSize:"cover",backgroundRepeat:"no-repeat",height:"100%",width:"100%"}})}),i.map((t,n)=>s("div",{className:"product-card bg-[#F3ECEE]",id:t==null?void 0:t.title,children:s(P,{product:t,loading:x(n)})},t.id))]}):s("div",{className:"product-card-grid",children:i.map((t,n)=>s("div",{className:"product-card bg-[#F3ECEE]",children:s(P,{product:t,loading:x(n)})},t.id))})}),b&&s("div",{className:"flex items-center justify-center mt-6",ref:a,children:s(R,{variant:"secondary",disabled:l,onClick:g,width:"full",children:l?"Loading...":"Load more products"})})]})}export{Ne as ProductGrid}; //# sourceMappingURL=20e75ddb.js.map