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