import{a as e,d as t,f as n,h as r,i,p as a,r as o,s,u as c}from"./src-C0xjWfnx.js";import{t as l}from"./useNavigate-VRicZWJI.js";import{t as u}from"./createLucideIcon-7nArgiy8.js";import{t as d}from"./shopping-cart-BBNoSjWE.js";import{t as f}from"./truck-DbJZ8T2i.js";import{t as p}from"./zap-CufcM84a.js";import{a as m,i as h,n as g,r as _}from"./cart-query-hooks-BCr0eax3.js";import{a as v,n as y,r as b,t as x}from"./prominent-api-hooks-DipwWw0H.js";import{t as S}from"./react-BnURElzN.js";var C=u(`X`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),w=a(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self).dayjs=r()})(e,(function(){var e=1e3,t=6e4,n=36e5,r=`millisecond`,i=`second`,a=`minute`,o=`hour`,s=`day`,c=`week`,l=`month`,u=`quarter`,d=`year`,f=`date`,p=`Invalid Date`,m=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,h=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,g={name:`en`,weekdays:`Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday`.split(`_`),months:`January_February_March_April_May_June_July_August_September_October_November_December`.split(`_`),ordinal:function(e){var t=[`th`,`st`,`nd`,`rd`],n=e%100;return`[`+e+(t[(n-20)%10]||t[n]||t[0])+`]`}},_=function(e,t,n){var r=String(e);return!r||r.length>=t?e:``+Array(t+1-r.length).join(n)+e},v={s:_,z:function(e){var t=-e.utcOffset(),n=Math.abs(t),r=Math.floor(n/60),i=n%60;return(t<=0?`+`:`-`)+_(r,2,`0`)+`:`+_(i,2,`0`)},m:function e(t,n){if(t.date()1)return e(o[0])}else{var s=t.name;b[s]=t,i=s}return!r&&i&&(y=i),i||!r&&y},w=function(e,t){if(S(e))return e.clone();var n=typeof t==`object`?t:{};return n.date=e,n.args=arguments,new E(n)},T=v;T.l=C,T.i=S,T.w=function(e,t){return w(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var E=function(){function g(e){this.$L=C(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[x]=!0}var _=g.prototype;return _.parse=function(e){this.$d=function(e){var t=e.date,n=e.utc;if(t===null)return new Date(NaN);if(T.u(t))return new Date;if(t instanceof Date)return new Date(t);if(typeof t==`string`&&!/Z$/i.test(t)){var r=t.match(m);if(r){var i=r[2]-1||0,a=(r[7]||`0`).substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,a)}}return new Date(t)}(e),this.init()},_.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},_.$utils=function(){return T},_.isValid=function(){return this.$d.toString()!==p},_.isSame=function(e,t){var n=w(e);return this.startOf(t)<=n&&n<=this.endOf(t)},_.isAfter=function(e,t){return w(e)({addedToCartProduct:null,setAddedToCartProduct:t=>e({addedToCartProduct:t}),clearAddedToCartProduct:()=>e({addedToCartProduct:null})})),O=t(),k=e=>{let t=(0,E.default)(e),n=t.add(1,`hour`),r=t.format(`A`),i=n.format(`A`);return r===i?`${t.format(`h`)}-${n.format(`h`)} ${r}`:`${t.format(`h:mm`)} ${r} - ${n.format(`h:mm`)} ${i}`};function A(){let t=l(),{addedToCartProduct:n,clearAddedToCartProduct:r}=D(),[i,a]=(0,T.useState)(1),[u,v]=(0,T.useState)(null),[y,x]=(0,T.useState)(!1),{data:S}=b(),{data:w}=_(),A=g(`regular`),j=m(`regular`),M=h(`regular`),N=!!n,P=n?.product;(0,T.useEffect)(()=>{if(N&&P){let e=w?.items?.find(e=>e.productId===P.id),t=e?.quantity||0;a(t===0?1:t),v(e?.slotId||null)}},[N,w,P]);let{slotMap:F,productSlotIdsMap:I}=(0,T.useMemo)(()=>{let e={},t={};return S?.slots&&S.slots.forEach(n=>{e[n.id]=n,n.products?.forEach(e=>{t[e.id]||(t[e.id]=[]),t[e.id].push(n.id)})}),{slotMap:e,productSlotIdsMap:t}},[S]),L=I[P?.id]||[],R=L.map(e=>F[e]).filter(Boolean).filter(e=>(0,E.default)(e.deliveryTime).isAfter((0,E.default)())),z=w?.items?.find(e=>e.productId===P?.id),B=(z?.quantity||0)>=1,V=S?.productAvailability?.find(e=>e.id===P?.id)?.isFlashAvailable===!0&&!0;return!N||!n?null:(0,O.jsx)(e,{open:N,onClose:r,children:(0,O.jsxs)(`div`,{className:`px-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,O.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-blue-50`,children:(0,O.jsx)(f,{className:`h-5 w-5 text-blue-500`})}),(0,O.jsxs)(`div`,{className:`flex-1`,children:[(0,O.jsx)(c,{weight:`bold`,className:`text-lg`,children:`Select Delivery Slot`}),P?.name&&(0,O.jsxs)(c,{className:`text-sm text-gray-500`,children:[P.name,` (`,P.productQuantity,P.unitNotation?` ${P.unitNotation}`:``,`)`]})]}),(0,O.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-600`,children:(0,O.jsx)(C,{className:`h-5 w-5`})})]}),(0,O.jsx)(`div`,{className:`max-h-[40vh] space-y-3 overflow-y-auto mb-4`,children:R.map(e=>(0,O.jsxs)(s,{onClick:()=>{v(e.id),x(!1)},className:`flex items-start gap-3 rounded-xl border bg-gray-50 p-4 ${u===e.id?`border-brand-500`:`border-gray-100`}`,children:[(0,O.jsx)(f,{className:`mt-0.5 h-5 w-5 shrink-0 text-blue-500`}),(0,O.jsxs)(c,{weight:`bold`,className:`flex-1 text-sm`,children:[(0,E.default)(e.deliveryTime).format(`ddd, DD MMM • `),k(e.deliveryTime)]}),u===e.id?(0,O.jsx)(`svg`,{className:`h-6 w-6 shrink-0 text-brand-500`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z`})}):(0,O.jsx)(`svg`,{className:`h-6 w-6 shrink-0 text-gray-300`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{d:`M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z`})})]},e.id))}),V&&(0,O.jsxs)(s,{onClick:()=>{x(!0),v(null)},className:`flex items-center gap-3 rounded-xl border p-4 mb-4 ${y?`border-pink-500 bg-pink-50`:`border-pink-200 bg-pink-50`}`,children:[(0,O.jsx)(p,{className:`h-5 w-5 shrink-0 text-pink-500`}),(0,O.jsx)(c,{weight:`bold`,className:`flex-1 text-sm`,children:`1 hr Delivery`}),y?(0,O.jsx)(`svg`,{className:`h-6 w-6 shrink-0 text-pink-500`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z`})}):(0,O.jsx)(`svg`,{className:`h-6 w-6 shrink-0 text-pink-300`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{d:`M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z`})})]}),(0,O.jsxs)(`div`,{className:`mb-4`,children:[(0,O.jsx)(c,{weight:`bold`,className:`mb-2 text-sm`,children:`Quantity`}),(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsx)(o,{value:i,setValue:a,step:1,unit:P?.unitNotation}),B&&(0,O.jsx)(s,{onClick:()=>{z?M.mutate(P.id,{onSuccess:()=>r()}):r()},className:`rounded-lg border border-red-200 bg-red-50 p-2`,children:(0,O.jsx)(`svg`,{className:`h-5 w-5 text-red-500`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})})]})]}),(0,O.jsxs)(`div`,{className:`flex gap-3 pb-4`,children:[(0,O.jsxs)(`button`,{onClick:()=>{if(y){t({to:`/flash`}),r();return}if(B&&z)j.mutate({productId:P.id,quantity:i,slotId:u,deliveryDate:u?F[u]?.deliveryTime:null},{onSuccess:()=>r()});else{let e=u??L[0]??0;A.mutate({productId:P.id,quantity:i,storeId:P.storeId||1,slotId:e,deliveryDate:F[e]?.deliveryTime||null},{onSuccess:()=>r()})}},disabled:!u&&!y||A.isPending||j.isPending,className:`flex flex-1 items-center justify-center gap-2 rounded-xl py-3 font-bold text-white transition-colors ${!u&&!y||A.isPending||j.isPending?`bg-brand-500/50`:`bg-brand-500 hover:bg-brand-600`}`,children:[(0,O.jsx)(d,{className:`h-4 w-4`}),A.isPending||j.isPending?B?`Updating...`:`Adding...`:B?`Update Item`:`Add to Cart`]}),(0,O.jsx)(`button`,{onClick:r,className:`flex-1 rounded-xl bg-gray-100 py-3 font-bold text-gray-700 hover:bg-gray-200 transition-colors`,children:`Cancel`})]})]})})}function j(){let e=l(),{data:t}=x(),{data:n}=v(),{data:r}=y(),{setAddedToCartProduct:a}=D(),o=n?.stores||[],s=r?.banners||[],u=t?.products||[],d=e=>{a({productId:e.id,product:e})};return(0,O.jsxs)(`div`,{className:`mx-auto min-h-screen max-w-7xl bg-white`,children:[(0,O.jsx)(`div`,{className:`sticky top-0 z-10 bg-white/95 backdrop-blur-sm px-4 md:px-6 lg:px-8 pt-4 pb-3 border-b border-gray-100`,children:(0,O.jsx)(i,{placeholder:`Search products here...`,onSearch:t=>e({to:`/home/search`,search:{q:t}})})}),(0,O.jsxs)(`div`,{className:`px-4 md:px-6 lg:px-8`,children:[s.length>0&&(0,O.jsx)(`div`,{className:`mt-4 mb-8 overflow-hidden rounded-xl`,children:(0,O.jsx)(M,{banners:s})}),(0,O.jsxs)(`div`,{className:`mb-8`,children:[(0,O.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,O.jsx)(c,{weight:`bold`,className:`text-lg md:text-xl`,children:`Our Stores`})}),(0,O.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3 md:gap-4`,children:o.map(t=>(0,O.jsx)(N,{store:t,onClick:()=>e({to:`/stores/$storeId`,params:{storeId:String(t.id)}})},t.id))})]}),(0,O.jsxs)(`div`,{className:`mb-24`,children:[(0,O.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,O.jsx)(c,{weight:`bold`,className:`text-lg md:text-xl`,children:`All Products`})}),(0,O.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3 md:gap-4`,children:u.slice(0,30).map(t=>(0,O.jsx)(P,{product:t,onClick:()=>e({to:`/home/product/$id`,params:{id:String(t.id)}}),onAddToCart:()=>d(t)},t.id))})]})]}),(0,O.jsx)(F,{onClick:()=>e({to:`/cart`})}),(0,O.jsx)(A,{})]})}function M({banners:e}){let[t,n]=(0,T.useState)(0),r=e.map(e=>e.imageUrl).filter(Boolean);return(0,T.useEffect)(()=>{if(r.length<=1)return;let e=setInterval(()=>{n(e=>(e+1)%r.length)},4e3);return()=>clearInterval(e)},[r.length]),r.length===0?null:(0,O.jsxs)(`div`,{className:`relative group`,children:[(0,O.jsx)(`img`,{src:r[t],alt:`Banner`,className:`h-36 sm:h-44 md:h-52 lg:h-64 w-full rounded-xl object-cover transition-all duration-500`}),r.length>1&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`button`,{onClick:()=>n(e=>(e-1+r.length)%r.length),className:`absolute left-2 top-1/2 -translate-y-1/2 bg-black/30 hover:bg-black/50 text-white rounded-full p-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,O.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,O.jsx)(`button`,{onClick:()=>n(e=>(e+1)%r.length),className:`absolute right-2 top-1/2 -translate-y-1/2 bg-black/30 hover:bg-black/50 text-white rounded-full p-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,O.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M9 5l7 7-7 7`})})}),(0,O.jsx)(`div`,{className:`absolute bottom-3 left-1/2 flex -translate-x-1/2 gap-1.5`,children:r.map((e,r)=>(0,O.jsx)(`button`,{onClick:()=>n(r),className:`h-2 rounded-full transition-all ${r===t?`w-6 bg-white`:`w-2 bg-white/50`}`},r))})]})]})}function N({store:e,onClick:t}){return(0,O.jsxs)(s,{onClick:t,className:`rounded-xl border border-gray-100 bg-white p-3 shadow-sm hover:shadow-md transition-shadow`,children:[(0,O.jsx)(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded-lg bg-gray-100`,children:e.signedImageUrl?(0,O.jsx)(`img`,{src:e.signedImageUrl,alt:e.name,className:`h-full w-full object-cover`}):(0,O.jsx)(`div`,{className:`flex h-full items-center justify-center text-gray-400`,children:(0,O.jsx)(`svg`,{className:`w-8 h-8`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.5,d:`M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4`})})})}),(0,O.jsx)(c,{weight:`semibold`,className:`text-sm truncate`,children:e.name}),(0,O.jsxs)(c,{className:`text-xs text-gray-500`,children:[e.productCount||0,` products`]})]})}function P({product:e,onClick:t,onAddToCart:n}){let r=e.images?.[0],i=e.marketPrice!=null&&e.marketPrice>e.price;return(0,O.jsxs)(`div`,{className:`rounded-xl border border-gray-100 bg-white p-3 shadow-sm hover:shadow-md transition-shadow`,children:[(0,O.jsxs)(s,{onClick:t,children:[(0,O.jsx)(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded-lg bg-gray-100`,children:r?(0,O.jsx)(`img`,{src:r,alt:e.name,className:`h-full w-full object-cover`}):(0,O.jsx)(`div`,{className:`flex h-full items-center justify-center text-gray-300`,children:(0,O.jsx)(`svg`,{className:`w-10 h-10`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.5,d:`M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z`})})})}),(0,O.jsx)(c,{weight:`semibold`,className:`text-sm leading-tight line-clamp-2 mb-1`,children:e.name}),(0,O.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,O.jsxs)(c,{weight:`bold`,className:`text-brand-600 text-sm md:text-base`,children:[`₹`,e.price]}),i&&(0,O.jsxs)(c,{className:`text-xs text-gray-400 line-through`,children:[`₹`,e.marketPrice]})]}),(0,O.jsxs)(c,{className:`text-[11px] text-gray-400 mb-2`,children:[`/`,e.unit]}),e.nextDeliveryDate&&(0,O.jsxs)(`div`,{className:`mb-3 flex items-center gap-1 self-start rounded-lg bg-brand-50 px-2 py-1 border border-brand-100`,children:[(0,O.jsx)(f,{className:`h-3 w-3 text-brand-600`}),(0,O.jsx)(c,{className:`text-[10px] font-bold text-brand-700`,children:(0,E.default)(e.nextDeliveryDate).format(`ddd, DD MMM • h:mm A`)})]})]}),n&&(0,O.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`flex w-full items-center justify-center gap-2 rounded-lg bg-brand-500 py-2 text-sm font-bold text-white hover:bg-brand-600 transition-colors`,children:[(0,O.jsx)(d,{className:`h-4 w-4`}),`Add to Cart`]})]})}function F({onClick:e}){let{data:t}=_(`regular`),{data:n}=x(),r=n?.products||[],i={};r.forEach(e=>{i[e.id]=e});let a=t?.items||[],o=a.length,s=a.reduce((e,t)=>e+(i[t.productId]?.price??0)*t.quantity,0),l=Math.max(0,149-s);return(0,O.jsx)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 bg-brand-600 px-4 py-2 md:px-6 md:py-3 shadow-lg`,children:(0,O.jsxs)(`div`,{className:`mx-auto flex max-w-7xl items-center justify-between`,children:[(0,O.jsxs)(`div`,{className:`flex-1`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsxs)(c,{weight:`bold`,className:`text-sm text-white`,children:[`₹`,s]}),(0,O.jsx)(c,{className:`text-xs text-white/80`,children:o===0?`No items in cart`:`• ${o} ${o===1?`item`:`items`}`})]}),l>0?(0,O.jsxs)(c,{className:`text-[10px] font-bold text-white/70`,children:[`₹`,l,` more for FREE Delivery`]}):o>0?(0,O.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(`svg`,{className:`h-3 w-3 text-emerald-300`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,O.jsx)(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z`})}),(0,O.jsx)(c,{className:`text-[10px] font-bold text-emerald-300`,children:`Free Delivery Unlocked`})]}):(0,O.jsxs)(c,{className:`text-[10px] text-white/50`,children:[`Shop for ₹`,149,`+ for free shipping`]})]}),(0,O.jsx)(`button`,{onClick:e,className:`rounded-full bg-white px-4 py-2 text-sm font-bold text-brand-600 shadow-md hover:bg-gray-100 transition-colors`,children:`Go to Cart`})]})})}export{j as component};