import{d as e,f as t,h as n,l as r,r as i,t as a,u as o}from"./src-C0xjWfnx.js";import{t as s}from"./useNavigate-VRicZWJI.js";import{n as c}from"./trpc-client-QrVjRqP1.js";import{t as l}from"./createLucideIcon-7nArgiy8.js";import{t as u}from"./shopping-cart-BBNoSjWE.js";import{r as d}from"./index-BXnbw4dQ.js";import{n as f}from"./cart-query-hooks-BCr0eax3.js";import{t as p}from"./central-product-store-DGoerB5U.js";var m=l(`Star`,[[`polygon`,{points:`12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2`,key:`8f66p6`}]]),h=n(t()),g=e();function _(){let{id:e}=d.useParams(),t=Number(e),n=s(),[l,_]=(0,h.useState)(1),v=p(e=>e.productsById)[t],y=f(`regular`),{data:b}=c.user.product.getProductReviews.useQuery({productId:t},{enabled:!!t}),x=()=>{v&&y.mutate({productId:v.id,quantity:l,storeId:v.storeId},{onSuccess:()=>n({to:`/cart`})})};if(!v)return(0,g.jsx)(a,{children:(0,g.jsx)(o,{children:`Product not found`})});let S=v.discountedPrice??v.price,C=v.images?.[0];return(0,g.jsxs)(a,{children:[C&&(0,g.jsx)(`div`,{className:`mb-4 aspect-square w-full overflow-hidden rounded-xl bg-gray-100`,children:(0,g.jsx)(`img`,{src:C,alt:v.name,className:`h-full w-full object-cover`})}),(0,g.jsx)(o,{weight:`bold`,className:`mb-1 text-xl`,children:v.name}),(0,g.jsxs)(o,{className:`mb-2 text-sm text-gray-500`,children:[v.unitValue,v.unit]}),(0,g.jsxs)(`div`,{className:`mb-4 flex items-baseline gap-2`,children:[(0,g.jsxs)(o,{weight:`bold`,className:`text-2xl text-brand-600`,children:[`₹`,S]}),v.discountedPrice&&(0,g.jsxs)(o,{className:`text-sm text-gray-400 line-through`,children:[`₹`,v.price]})]}),v.description&&(0,g.jsx)(o,{className:`mb-4 text-gray-600`,children:v.description}),(0,g.jsx)(`div`,{className:`mb-6`,children:(0,g.jsx)(i,{value:l,setValue:_,max:10})}),(0,g.jsxs)(r,{fullWidth:!0,onClick:x,disabled:y.isPending,className:`flex items-center justify-center gap-2 bg-brand-500 text-white`,children:[(0,g.jsx)(u,{className:`h-4 w-4`}),y.isPending?`Adding...`:`Add to Cart`]}),b?.data&&b.data.length>0&&(0,g.jsxs)(`div`,{className:`mt-8`,children:[(0,g.jsx)(o,{weight:`bold`,className:`mb-3 text-lg`,children:`Reviews`}),b.data.map((e,t)=>(0,g.jsxs)(`div`,{className:`mb-3 rounded-lg border border-gray-100 p-3`,children:[(0,g.jsx)(`div`,{className:`mb-1 flex items-center gap-1`,children:Array.from({length:e.rating||5}).map((e,t)=>(0,g.jsx)(m,{className:`h-3 w-3 fill-yellow-400 text-yellow-400`},t))}),(0,g.jsx)(o,{className:`text-sm text-gray-600`,children:e.comment})]},t))]})]})}export{_ as component};