1import{a4 as U,u as q,k as z,r as s,j as n,a as G}from"./vendor-CspWRbDh.js";import{M as J}from"./MainTemplate-D3lpptSi.js";import{P as K}from"./ProductCard-B_BhuHjs.js";import{P as Q}from"./PageHeader-D-ZjVpga.js";import{u as V}from"./index-KgDEeEkX.js";import"./Footer-CSPeaO4E.js";const re=()=>{const{code:u}=U(),x=q(),B=z(),{isDarkMode:f}=V(),[c,I]=s.useState(!1),[P,b]=s.useState(null),[m,M]=s.useState([]),[H,O]=s.useState(0),[W,v]=s.useState(1),[N]=s.useState(20),[p,k]=s.useState(!1),[w,j]=s.useState(!0),S=s.useRef(null),g=s.useRef(!1),$=s.useRef(1),C=async({pageToLoad:e,isLoadMore:r=!1})=>{var a,l;if(u&&!g.current){g.current=!0,r?k(!0):I(!0),b(null);try{const i=`https://product-api.loomfashion.co.in/product/admin/prod/get_product_couponcode/${encodeURIComponent(u)}?page=${e}&limit=${N}`,o=await G.get(i),t=o==null?void 0:o.data;if(t!=null&&t.success){const y=((a=t==null?void 0:t.data)==null?void 0:a.products)||[],h=((l=t==null?void 0:t.data)==null?void 0:l.total)??0;h>0&&O(h),M(D=>{var E;const L=[...e===1?[]:D,...y],_=new Set,T=[];for(const d of L){const F=`${d._id}_${((E=d==null?void 0:d.variantThumbnail)==null?void 0:E.variantId)||""}`;_.has(F)||(_.add(F),T.push(d))}return T});const A=(e===1?0:m.length)+y.length;h>0?j(A<h):j(y.length===N),r?($.current=e,v(e)):($.current=1,v(1))}else b((t==null?void 0:t.message)||"Failed to fetch products")}catch(i){b((i==null?void 0:i.message)||"Failed to fetch products")}finally{r?k(!1):I(!1),g.current=!1}}};s.useEffect(()=>{M([]),v(1),j(!0),C({pageToLoad:1,isLoadMore:!1})},[u]);const R=s.useCallback(e=>{if(!e[0].isIntersecting||c||p||g.current||!w)return;const a=($.current||1)+1;C({pageToLoad:a,isLoadMore:!0})},[c,p,w]);return s.useEffect(()=>{const e=S.current;if(!e)return;const r=new IntersectionObserver(R,{root:null,rootMargin:"300px",threshold:0});return r.observe(e),()=>{r.disconnect()}},[R]),n.jsxs(J,{children:[n.jsx(Q,{isH1:!0,title:`${u} (${H} Products)`,onBack:()=>x(-1)}),n.jsx("div",{className:`py-4 sm:py-8 md:py-5 md:px-5 transition-colors duration-300 ${f?"bg-black":"bg-gray-50"}`,children:n.jsxs("div",{className:"max-w-8xl mx-auto sm:px-4 md:px-6",children:[n.jsx("div",{className:"flex items-center justify-center mb-4"}),c&&n.jsx("div",{className:"flex justify-center items-center py-12",children:n.jsx("div",{className:`w-12 h-12 border-4 border-t-transparent rounded-full animate-spin transition-colors duration-300 ${f?"border-white":"border-black"}`})}),!c&&P&&m.length===0&&n.jsx("div",{className:"text-center py-16 font-medium",children:n.jsx("p",{className:`transition-colors duration-300 ${f?"text-gray-400":"text-gray-500"}`,children:"No products found for this coupon."})}),!c&&!P&&m.length>0&&n.jsx("div",{className:"grid grid-cols-2 md:grid-cols-2 lg:grid-cols-3 gap-2 md:gap-2 lg:gap-8",children:m.map(e=>{var r,a;return n.jsx(K,{product:e,variantId:(r=e==null?void 0:e.variantThumbnail)==null?void 0:r.variantId,onClick:()=>{var o,t;const l=e.title.replace(/\s+/g,"-").toLowerCase();/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?x(`/product/${l}/${e._id}?variantId=${(o=e==null?void 0:e.variantThumbnail)==null?void 0:o.variantId}`,{state:{from:B.pathname}}):x(`/product/${l}/${e._id}?variantId=${(t=e==null?void 0:e.variantThumbnail)==null?void 0:t.variantId}`)}},`${e._id}_${((a=e==null?void 0:e.variantThumbnail)==null?void 0:a.variantId)||""}`)})}),n.jsx("div",{ref:S,className:"h-10"}),p&&n.jsx("div",{className:"flex justify-center items-center py-6",children:n.jsx("div",{className:`w-8 h-8 border-4 border-t-transparent rounded-full animate-spin transition-colors duration-300 ${f?"border-white":"border-black"}`})})]})})]})};export{re as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.