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{m as l}from"./useMutation-DvG2_Fq3.js";import{n as u}from"./trpc-client-QrVjRqP1.js";import{l as d}from"./index-BXnbw4dQ.js";import{r as f,t as p}from"./cart-query-hooks-BCr0eax3.js";import{t as m}from"./prominent-api-hooks-DipwWw0H.js";var h=n(t()),g=e();function _(){let e=c(),t=l(),{isAuthenticated:n}=d(),{data:_}=f(`regular`),{data:v}=m(),[y,b]=(0,h.useState)(!1),x=v?.products||[],S={};x.forEach(e=>{S[e.id]=e});let{data:C}=u.user.address.getUserAddresses.useQuery(void 0,{enabled:n}),[w,T]=(0,h.useState)(null),E=(_?.items||[]).filter(e=>S[e.productId]),D=0;E.forEach(e=>{let t=S[e.productId];t&&(D+=t.price*e.quantity)});let O=u.user.order.placeOrder.useMutation({onSuccess:n=>{let r=n.data?.[0];p(`regular`),t.invalidateQueries({queryKey:[`local-cart-regular`]}),e({to:`/home/order-success`,search:{orderId:r?.id,totalAmount:D}})},onSettled:()=>b(!1)});return(0,g.jsxs)(o,{children:[(0,g.jsx)(s,{weight:`bold`,className:`mb-4 text-xl`,children:`Checkout`}),(0,g.jsxs)(`div`,{className:`mb-6`,children:[(0,g.jsx)(s,{weight:`semibold`,className:`mb-2`,children:`Delivery Address`}),C?.data?.map(e=>(0,g.jsxs)(a,{onClick:()=>T(e.id),className:`mb-2 rounded-xl border p-3 ${w===e.id?`border-brand-500 bg-brand-50`:`border-gray-200`}`,children:[(0,g.jsx)(s,{weight:`semibold`,children:e.name}),(0,g.jsxs)(s,{className:`text-sm text-gray-600`,children:[e.addressLine1,`, `,e.city]}),(0,g.jsx)(s,{className:`text-sm text-gray-500`,children:e.phone})]},e.id))]}),(0,g.jsxs)(`div`,{className:`mb-6`,children:[(0,g.jsx)(s,{weight:`semibold`,className:`mb-2`,children:`Order Summary`}),E.map(e=>{let t=S[e.productId];return t?(0,g.jsxs)(`div`,{className:`flex items-center justify-between py-2`,children:[(0,g.jsxs)(s,{className:`text-sm`,numberOfLines:1,children:[t.name,` x`,e.quantity]}),(0,g.jsxs)(s,{className:`text-sm font-bold`,children:[`₹`,t.price*e.quantity]})]},e.productId):null}),(0,g.jsx)(`div`,{className:`mt-2 border-t border-gray-200 pt-2`,children:(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsx)(s,{weight:`bold`,children:`Total`}),(0,g.jsxs)(s,{weight:`bold`,className:`text-brand-600`,children:[`₹`,D]})]})})]}),(0,g.jsx)(r,{fullWidth:!0,textContent:`Place Order (COD)`,onClick:()=>{w&&(b(!0),O.mutate({selectedItems:E.map(e=>({productId:e.productId,quantity:e.quantity,slotId:null})),addressId:w,paymentMethod:`cod`,isFlashDelivery:!1}))},disabled:!w||O.isPending,className:`bg-brand-500 text-white`}),(0,g.jsx)(i,{open:y,message:`Placing your order...`})]})}export{_ as component};