import{r as e,t}from"./jsx-runtime-DGeXAQPT.js";import{H as n,t as r}from"./link-BEigRx5R.js";import{t as i}from"./badge-check-Br8mxJM-.js";import{d as a,n as o,r as s,t as c}from"./Modals-BkPPnKoF.js";import{S as l,a as u,b as d,i as f,o as p,r as m,u as h,y as g}from"./index-BFZg1haX.js";var _=e(n()),v=t();function y(){let{name:e}=m.useLoaderData(),{addToCart:t,vendorProducts:n,getAllProducts:y,vendors:b}=l(),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(`pop`),k=u(e).map(e=>e.toLowerCase()),A=e===`Other categories`?y():[...d,...n].filter(e=>k.includes((e.category??``).toLowerCase()));return e===`Official Store`&&A.length===0&&(A=d.slice(0,8)),D===`low`&&(A=[...A].sort((e,t)=>e.price-t.price)),D===`high`&&(A=[...A].sort((e,t)=>t.price-e.price)),(0,v.jsxs)(`div`,{className:`min-h-screen`,style:{backgroundColor:`#f0f2f5`},children:[(0,v.jsx)(s,{open:x,onOpenChange:S}),(0,v.jsx)(c,{open:C,onOpenChange:w,onCheckout:()=>{w(!1),E(!0)}}),(0,v.jsx)(o,{open:T,onOpenChange:E}),(0,v.jsx)(a,{onOpenCart:()=>w(!0),onOpenSignIn:()=>S(!0)}),(0,v.jsxs)(`main`,{className:`max-w-[1200px] mx-auto px-4 py-4 space-y-4`,children:[(0,v.jsxs)(`nav`,{className:`text-xs text-neutral-500`,children:[(0,v.jsx)(r,{to:`/`,className:`hover:text-orange-600`,children:`Home`}),(0,v.jsx)(`span`,{className:`mx-1.5`,children:`/`}),(0,v.jsx)(`span`,{className:`text-neutral-800`,children:e})]}),(0,v.jsxs)(`div`,{className:`flex flex-col lg:grid lg:grid-cols-12 gap-3`,children:[(0,v.jsxs)(`aside`,{className:`hidden lg:block lg:col-span-3 bg-white rounded-md py-2 text-sm h-fit`,children:[(0,v.jsx)(`div`,{className:`px-4 py-1.5 text-xs uppercase tracking-wide text-neutral-500 font-semibold`,children:`Categories`}),f.map(t=>(0,v.jsx)(r,{to:`/category/$slug`,params:{slug:p(t)},className:`block px-4 py-1.5 hover:bg-orange-50 hover:text-orange-600 ${t===e?`bg-orange-50 text-orange-600 font-medium`:``}`,children:t},t))]}),(0,v.jsxs)(`div`,{className:`lg:col-span-9 space-y-3`,children:[(0,v.jsxs)(`div`,{className:`bg-white rounded-md px-4 py-3 flex items-center justify-between`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h1`,{className:`text-lg font-bold text-neutral-800`,children:e}),(0,v.jsxs)(`div`,{className:`text-xs text-neutral-500`,children:[A.length,` products`]})]}),(0,v.jsxs)(`label`,{className:`text-xs text-neutral-600 flex items-center gap-2`,children:[`Sort by`,(0,v.jsxs)(`select`,{value:D,onChange:e=>O(e.target.value),className:`border rounded px-2 py-1 text-xs`,children:[(0,v.jsx)(`option`,{value:`pop`,children:`Popularity`}),(0,v.jsx)(`option`,{value:`low`,children:`Price: low to high`}),(0,v.jsx)(`option`,{value:`high`,children:`Price: high to low`})]})]})]}),A.length===0?(0,v.jsxs)(`div`,{className:`bg-white rounded-md p-10 text-center text-neutral-500`,children:[(0,v.jsxs)(`p`,{className:`mb-2`,children:[`No products in `,e,` yet.`]}),(0,v.jsx)(r,{to:`/`,className:`text-orange-600 underline text-sm`,children:`Explore other deals`})]}):(0,v.jsx)(`div`,{className:`bg-white rounded-md grid grid-cols-3 sm:grid-cols-4 lg:grid-cols-4`,children:A.map(e=>{let n=b.find(t=>t.contactEmail===e.vendorEmail)?.is_verified;return(0,v.jsxs)(`div`,{className:`border-r border-b last:border-r-0 p-3 bg-white hover:shadow-md transition`,children:[(0,v.jsxs)(r,{to:`/product/$id`,params:{id:e.id},className:`block`,children:[(0,v.jsx)(`img`,{src:e.images?.[0]||`https://picsum.photos/seed/${e.seed}/240/240`,alt:e.name,className:`w-full aspect-square object-cover rounded`}),(0,v.jsxs)(`div`,{className:`mt-2 space-y-0.5`,children:[(0,v.jsxs)(`div`,{className:`text-xs text-neutral-700 line-clamp-2 flex items-center gap-1`,children:[e.name,n&&(0,v.jsx)(`span`,{className:`inline-flex`,children:(0,v.jsx)(i,{className:`w-3.5 h-3.5 text-sky-500 shrink-0`})})]}),(0,v.jsxs)(`div`,{className:`text-sm font-bold text-neutral-900`,children:[`₦ `,g(e.price)]}),e.old&&(0,v.jsxs)(`div`,{className:`text-[11px] text-neutral-400 line-through`,children:[`₦ `,g(e.old)]})]})]}),(0,v.jsx)(h,{onClick:()=>t(e),size:`sm`,className:`w-full mt-2 h-8 bg-orange-500 hover:bg-orange-600 text-white text-xs`,children:`Add to cart`})]},e.id)})})]})]})]})]})}export{y as component};