import{o as e,r as t,t as n}from"./jsx-runtime-BbTa8W_M-1776590214964.js";import{s as r}from"./app-CXDQ5oEH-1776590214964.js";import{t as i}from"./useTranslation-D1etqd9u-1776590214964.js";import{t as a}from"./ProductCard-cuRTv_LB-1776590214964.js";var o=e(t(),1),s=n(),c=()=>(0,s.jsxs)(`div`,{className:`flex flex-col h-full bg-card rounded-2xl border border-border/50 overflow-hidden shadow-sm animate-pulse`,children:[(0,s.jsx)(`div`,{className:`w-full aspect-square bg-muted`}),(0,s.jsxs)(`div`,{className:`p-4 sm:p-5 flex flex-col flex-1`,children:[(0,s.jsx)(`div`,{className:`h-4 bg-muted rounded-md w-full mb-2`}),(0,s.jsx)(`div`,{className:`h-4 bg-muted rounded-md w-2/3 mb-4`}),(0,s.jsxs)(`div`,{className:`mt-auto space-y-3`,children:[(0,s.jsx)(`div`,{children:(0,s.jsx)(`div`,{className:`h-7 bg-muted rounded-md w-1/2 mb-1`})}),(0,s.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border/50 pt-3`,children:[(0,s.jsx)(`div`,{className:`h-5 bg-muted rounded-md w-1/3`}),(0,s.jsx)(`div`,{className:`h-4 bg-muted rounded-md w-1/4`})]})]})]})]});function l({dbProducts:e}){let{t}=i(),[n,l]=(0,o.useState)(e?.data||[]),[u,d]=(0,o.useState)(e?.next_page_url||null),[f,p]=(0,o.useState)(!1),m=(0,o.useRef)(),h=(0,o.useCallback)(e=>{f||(m.current&&m.current.disconnect(),m.current=new IntersectionObserver(e=>{e[0].isIntersecting&&u&&g()},{rootMargin:`400px`}),e&&m.current.observe(e))},[f,u]);(0,o.useEffect)(()=>{e&&(l(e.data),d(e.next_page_url))},[e]);let g=async()=>{if(u){p(!0);try{let e=await r.get(u,{headers:{Accept:`application/json`}});l(t=>{let n=e.data.data.filter(e=>!t.some(t=>t.id===e.id));return[...t,...n]}),d(e.data.next_page_url)}catch(e){console.error(`Pagination Error:`,e)}finally{p(!1)}}};return!n||n.length===0?null:(0,s.jsxs)(`div`,{className:`mb-12`,children:[(0,s.jsx)(`h3`,{className:`text-xl md:text-2xl font-bold mb-6`,children:t(`Just For You`)}),(0,s.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4`,children:[n.map((e,t)=>n.length===t+1?(0,s.jsx)(`div`,{ref:h,className:`h-full`,children:(0,s.jsx)(a,{product:e})},e.id):(0,s.jsx)(a,{product:e},e.id)),f&&Array.from({length:6}).map((e,t)=>(0,s.jsx)(c,{},`skeleton-${t}`))]})]})}export{l as default};