import{d as e,f as t,h as n,l as r,o as i,s as a,t as o,u as s}from"./src-C0xjWfnx.js";import{t as c}from"./useNavigate-VRicZWJI.js";import{n as l}from"./trpc-client-QrVjRqP1.js";import{t as u}from"./arrow-left-9Wn53Zfu.js";import{i as d}from"./index-BXnbw4dQ.js";var f=n(t()),p=e();function m(){let{id:e}=d.useParams(),t=c(),n=Number(e),[m,h]=(0,f.useState)(!1),{data:g}=l.user.order.getOrderById.useQuery({orderId:n}),_=l.user.order.cancelOrder.useMutation(),v=g?.data;return v?(0,p.jsxs)(o,{children:[(0,p.jsxs)(a,{onClick:()=>t({to:`/me/orders`}),className:`mb-4 flex items-center gap-2`,children:[(0,p.jsx)(u,{className:`h-5 w-5`}),(0,p.jsx)(s,{children:`Back to Orders`})]}),(0,p.jsxs)(`div`,{className:`mb-4`,children:[(0,p.jsxs)(s,{weight:`bold`,className:`text-xl`,children:[`Order #`,v.id]}),(0,p.jsx)(`span`,{className:`mt-1 inline-block rounded-full px-3 py-1 text-xs font-medium ${v.status===`delivered`?`bg-green-100 text-green-700`:v.status===`cancelled`?`bg-red-100 text-red-700`:`bg-yellow-100 text-yellow-700`}`,children:v.status})]}),(0,p.jsxs)(`div`,{className:`mb-6`,children:[(0,p.jsx)(s,{weight:`semibold`,className:`mb-2`,children:`Items`}),(v.items||[]).map((e,t)=>(0,p.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-100 py-2`,children:[(0,p.jsxs)(s,{className:`text-sm`,children:[e.product?.name||`Product #${e.productId}`,` x`,e.quantity]}),(0,p.jsxs)(s,{className:`text-sm font-bold`,children:[`₹`,e.price||0]})]},t)),(0,p.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[(0,p.jsx)(s,{weight:`bold`,children:`Total`}),(0,p.jsxs)(s,{weight:`bold`,className:`text-brand-600`,children:[`₹`,v.totalAmount||0]})]})]}),v.address&&(0,p.jsxs)(`div`,{className:`mb-6`,children:[(0,p.jsx)(s,{weight:`semibold`,className:`mb-2`,children:`Delivery Address`}),(0,p.jsxs)(`div`,{className:`rounded-xl border border-gray-100 bg-gray-50 p-3`,children:[(0,p.jsx)(s,{weight:`semibold`,children:v.address.name}),(0,p.jsxs)(s,{className:`text-sm text-gray-600`,children:[v.address.addressLine1,`, `,v.address.city]}),(0,p.jsx)(s,{className:`text-sm text-gray-500`,children:v.address.phone})]})]}),v.status!==`cancelled`&&v.status!==`delivered`&&(0,p.jsx)(r,{variant:`red`,fullWidth:!0,textContent:_.isPending?`Cancelling...`:`Cancel Order`,onClick:()=>h(!0),disabled:_.isPending}),m&&(0,p.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50`,children:(0,p.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-xl bg-white p-6`,children:[(0,p.jsx)(s,{weight:`bold`,className:`mb-2 text-lg`,children:`Cancel Order?`}),(0,p.jsx)(s,{className:`mb-6 text-sm text-gray-600`,children:`Are you sure you want to cancel this order?`}),(0,p.jsxs)(`div`,{className:`flex gap-3`,children:[(0,p.jsx)(r,{textContent:`No, Keep It`,onClick:()=>h(!1),className:`flex-1 bg-gray-100 text-gray-700`}),(0,p.jsx)(r,{variant:`red`,textContent:`Yes, Cancel`,onClick:()=>{_.mutate({orderId:n},{onSuccess:()=>h(!1)})},className:`flex-1`,disabled:_.isPending})]})]})}),(0,p.jsx)(i,{open:_.isPending,message:`Cancelling order...`})]}):(0,p.jsx)(o,{children:(0,p.jsx)(s,{children:`Loading...`})})}export{m as component};