(()=>{"use strict";var e,t,r,n={5994:(e,t,r)=>{var n=r(5338),s=r(4976),i=r(2691),a=r(7665),l=r(5793),o=r(4519),d=r(7767);const c=(0,r(6544).A)({palette:{primary:{main:"#FF6B6B",light:"#FF8E8E",dark:"#FF4848",contrastText:"#fff"},secondary:{main:"#4ECDC4",light:"#71D7D0",dark:"#2BC4B8",contrastText:"#fff"},background:{default:"#F7F7F7",paper:"#FFFFFF"},custom:{gradientPrimary:"linear-gradient(108.73deg, #F9881F 23.73%, #FF774C 79.34%)"}},typography:{fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif',h1:{fontWeight:700},h2:{fontWeight:600},h3:{fontWeight:600},h4:{fontWeight:600},h5:{fontWeight:500},h6:{fontWeight:500}},components:{MuiButton:{styleOverrides:{root:{borderRadius:8,textTransform:"none",fontWeight:500}}},MuiCard:{styleOverrides:{root:{borderRadius:12,boxShadow:"0 4px 6px rgba(0,0,0,0.1)"}}}}});var x=r(6540),u=r(9270),m=r(4073),h=r(7834),A=r(9067),j=r(6990),p=r(2471),g=r(5239),y=r(3357),v=r(3959),b=r(4745),f=r(8737),I=r(6908);let S="https://indimitra.com/graphql";const C=window.location.href?.includes("http://localhost");C&&(S="http://127.0.0.1:8000/graphql");const w=new I.l4(S,{headers:{"Content-Type":"application/json"}}),P=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return w.request(e,t)},D="\n  mutation UpdateOrderStatus($input: UpdateOrderStatusInput!) {\n    updateOrderStatus(input: $input) {\n      id\n      status\n      deliveryDate\n      deliveryInstructions\n    }\n  }\n",F="\n  query GetUserProfile($userId: String!) {\n    getUserProfile(userId: $userId) {\n      active\n      createdAt\n      email\n      id\n      mobile\n      referralId\n      secondaryPhone\n      type\n      updatedAt\n      stores {\n        edges {\n          node {\n            id\n            name\n            taxPercentage\n          }\n        }\n      }\n    }\n  }\n",k="\n  query GetOrdersByStore($storeId: Int!) {\n    getOrdersByStore(storeId: $storeId) {\n      id\n      addressId\n      cancelledAt\n      cancelledByUserId\n      createdByUserId\n      deliveryDate\n      deliveryInstructions\n      id\n      paymentId\n      status\n      storeId\n      totalAmount\n      orderTotalAmount\n      deliveryFee\n      tipAmount\n      taxAmount\n      address {\n        address\n      }\n      creator {\n        mobile\n        email\n      }\n      delivery {\n        driverId\n      }\n      orderItems {\n        edges {\n          node {\n            id\n            inventoryId\n            orderAmount\n            orderId\n            productId\n            quantity\n            updatedOrderitemsId\n            product {\n              id\n              name\n              description\n              inventoryItems {\n                edges {\n                  node {\n                    price\n                    measurement\n                    unit\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n",E="\n  query GetStoreDrivers($storeId: Int!) {\n    getStoreDrivers(storeId: $storeId) {\n      id\n      storeId\n      userId\n      driver {\n        active\n        email\n        mobile\n        referralId\n        referredBy\n        type\n      }\n    }\n  }\n",$="\n  mutation CancelOrder($orderId: Int!, $cancelMessage: String!, $cancelledByUserId: Int!) {\n    cancelOrderById(\n      orderId: $orderId, \n      cancelMessage: $cancelMessage, \n      cancelledByUserId: $cancelledByUserId\n    ) {\n      id\n      status\n    }\n  }\n",W="\n  query GetStores {\n    stores {\n      id\n      name\n      address\n      description\n      disabled\n      email\n      isActive\n      managerUserId\n      mobile\n      pincodes\n      radius\n      tnc\n      storeDeliveryFee\n      taxPercentage\n      drivers {\n        edges {\n          node {\n            driver {\n              active\n              id\n              email\n              mobile\n              referredBy\n              type\n            }\n          }\n        }\n      }\n    }\n  }\n",L="\n  query GetProducts {\n    products {\n      id\n      name\n      description\n      categoryId\n      image\n      inventoryItems {\n        edges {\n          node {\n            id\n          }\n        }\n      }\n    }\n  }\n";var q=r(1511),R=r(8496);const T="admin",z="user",U="delivery_agent",B="store_manager",O="orders",N="userStatus",M=e=>(0,R.ms)((t=>{e=e?.toLowerCase().trim(),e===T&&(t("view",T),t("view",N)),e===z&&(t("view",z),t("view",O),t("view","cart")),e===U&&t("view",U),e===B&&(t("view",B),t("manage","inventory"))})),_=(0,q.v)(((e,t)=>({cart:{},selectedStore:null,availableStores:[],setAvailableStores:t=>e({availableStores:t}),setSelectedStore:t=>e({selectedStore:t}),getSelectedStore:()=>t().selectedStore,addToCart:t=>e((e=>({cart:{...e.cart,[t.id]:{...e.cart[t.id]||t,quantity:(e.cart[t.id]?.quantity||0)+1}}}))),removeFromCart:t=>e((e=>{if(!e.cart[t])return e;const r={...e.cart};return r[t].quantity>1?r[t].quantity-=1:delete r[t],{cart:r}})),cartCount:()=>Object.values(t().cart).reduce(((e,t)=>e+(t.quantity||0)),0),cartTotal:()=>Object.values(t().cart).reduce(((e,t)=>e+(t?.price||0)*(t?.quantity||0)),0),clearCart:()=>e({cart:{}}),getCartTotals:()=>{const e=t(),r=e.cart,n=e.selectedStore,s=Object.values(r).reduce(((e,t)=>e+(t.price*t.quantity||0)),0),i=n?.storeDeliveryFee||0,a=n?.taxPercentage||0,l=s*a/100,o=e.tipAmount||0;return{subtotal:s,deliveryFee:i,taxAmount:l,taxPercentage:a,tipAmount:o,total:s+i+l+o}},setTipAmount:t=>e({tipAmount:t})}))),V=(0,q.v)(((e,t)=>({user:null,userProfile:null,ability:null,isProfileLoading:!1,profileError:null,modalOpen:!1,currentForm:"login",setAbility:t=>{e({ability:t})},setUser:t=>{e({user:t})},setUserProfile:t=>{if(!t)return;const r=JSON.parse(JSON.stringify(t));e((e=>({...e,userProfile:r})))},setModalOpen:t=>{e({modalOpen:t})},getUserProfile:()=>t().userProfile,setCurrentForm:t=>{e({currentForm:t})},setAbility:t=>e({ability:t}),logout:()=>{e({user:null,userProfile:null,ability:M(null)})},fetchUserProfile:async t=>{if(t){e({isProfileLoading:!0});try{const r=await P(F,{userId:t});if(r.errors)return void e({isProfileLoading:!1});const n=r.getUserProfile||r.data?.getUserProfile;if(!n)return void e({isProfileLoading:!1});e({userProfile:n,isProfileLoading:!1,ability:M(n.role)})}catch(t){e({isProfileLoading:!1})}}},isProfileLoaded:()=>!!t().userProfile}))),Y=(0,q.v)(((e,t)=>({addresses:[],isLoading:!1,error:null,selectedAddressId:null,setSelectedAddressId:t=>e({selectedAddressId:t}),fetchAddresses:async r=>{if(!r)return[];e({isLoading:!0,error:null});try{const n="string"==typeof r?parseInt(r,10):r,s=await P("\n  query GetAddressesByUser($userId: Int!) {\n    getAddressesByUser(userId: $userId) {\n      id\n      address\n      isPrimary\n    }\n  }\n",{userId:n}),i=s?.getAddressesByUser||[];return e({addresses:i,isLoading:!1,selectedAddressId:i.length>0&&!t().selectedAddressId?i[0].id:t().selectedAddressId}),i}catch(t){return e({error:t.message||"Failed to fetch addresses",isLoading:!1}),[]}},createAddress:async function(t,r){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!r||!t)return null;e({isLoading:!0,error:null});try{const s="string"==typeof r?parseInt(r,10):r,i=await P("\n  mutation CreateAddress($address: String!, $userId: Int!, $isPrimary: Boolean) {\n    createAddress(address: $address, userId: $userId, isPrimary: $isPrimary) {\n      id\n      address\n      isPrimary\n    }\n  }\n",{address:t,userId:s,isPrimary:n});if(i?.createAddress)return e((e=>({addresses:[...e.addresses,i.createAddress],isLoading:!1}))),i.createAddress;throw new Error("Failed to create address")}catch(t){return e({error:t.message||"Failed to create address",isLoading:!1}),null}},updateAddress:async(t,r,n)=>{if(!t)return null;e({isLoading:!0,error:null});try{const s=await P("\n  mutation UpdateAddress($addressId: Int!, $address: String, $isPrimary: Boolean) {\n    updateAddress(addressId: $addressId, address: $address, isPrimary: $isPrimary) {\n      id\n      address\n      isPrimary\n    }\n  }\n",{addressId:t,address:r,isPrimary:n});if(s?.updateAddress)return e((e=>({addresses:e.addresses.map((e=>e.id===t?s.updateAddress:e)),isLoading:!1}))),s.updateAddress;throw new Error("Failed to update address")}catch(t){return e({error:t.message||"Failed to update address",isLoading:!1}),null}},deleteAddress:async t=>{if(!t)return!1;e({isLoading:!0,error:null});try{const r=await P("\n  mutation DeleteAddress($addressId: Int!) {\n    deleteAddress(addressId: $addressId)\n  }\n",{addressId:t});if(r?.deleteAddress)return e((e=>({addresses:e.addresses.filter((e=>e.id!==t)),isLoading:!1,selectedAddressId:e.selectedAddressId===t?null:e.selectedAddressId}))),!0;throw new Error("Failed to delete address")}catch(t){return e({error:t.message||"Failed to delete address",isLoading:!1}),!1}},getSelectedAddress:()=>{const{addresses:e,selectedAddressId:r}=t();return e.find((e=>e.id===r))||null}}))),G=_;var K=r(4848);const H=e=>(0,K.jsx)(A.A,{...e}),Q=e=>(0,K.jsx)(j.A,{...e}),J=e=>(0,K.jsx)(p.A,{...e}),Z=e=>(0,K.jsx)(m.A,{...e});var X=r(9502);const ee=e=>(0,K.jsx)(X.A,{...e});var te=r(538);const re=e=>(0,K.jsx)(te.A,{...e}),ne=e=>{let{size:t=40,thickness:r=3.6,sx:n={}}=e;return(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",...n},children:(0,K.jsx)(y.A,{size:t,thickness:r})})};var se=r(790),ie=r(9898);const ae=e=>{let{fields:t,onSubmit:r,buttonLabel:n,loading:s,error:i,success:a}=e;const l=e=>{switch(e){case"email":return(0,K.jsx)(se.A,{sx:{color:"#FF6B6B"}});case"password":return(0,K.jsx)(ie.A,{sx:{color:"#FF6B6B"}});default:return null}};return(0,K.jsxs)("form",{onSubmit:r,children:[t.map(((e,t)=>(0,K.jsx)(J,{label:e.label,type:e.type,fullWidth:!0,margin:"normal",value:e.value,onChange:t=>e.onChange(t.target.value),required:!0,InputProps:{startAdornment:e.type&&(0,K.jsx)(g.A,{position:"start",children:l(e.type)})}},t))),i&&(0,K.jsx)(ee,{severity:"error",sx:{mt:2},children:i}),a&&(0,K.jsx)(ee,{severity:"success",sx:{mt:2},children:a}),(0,K.jsx)(Q,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:s,sx:{mt:2},children:s?(0,K.jsx)(ne,{size:24,sx:{color:"#fff"}}):n})]})};var le=r(1641);const oe=e=>(0,K.jsx)(le.A,{...e});var de=r(3896);const ce=e=>(0,K.jsx)(de.A,{...e});var xe=r(8239),ue=r(4977),me=r(7393),he=r(7636),Ae=r(6826),je=r(7839),pe=r(1649),ge=r(9682),ye=r(1235);const ve={"grains & rice":["https://images.unsplash.com/photo-1586201375761-83865001e31c?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1586201375761-83865001e31c?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1586201375761-83865001e31c?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],"pulses & lentils":["https://images.unsplash.com/photo-1600857544200-b2f666a9a2ec?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1600857544200-b2f666a9a2ec?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1600857544200-b2f666a9a2ec?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],"spices & masalas":["https://images.unsplash.com/photo-1596040033229-a9821ebd058d?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1596040033229-a9821ebd058d?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1596040033229-a9821ebd058d?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],flours:["https://images.unsplash.com/photo-1576045057995-568f588f82fb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1576045057995-568f588f82fb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1576045057995-568f588f82fb?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],"oils & ghee":["https://images.unsplash.com/photo-1474979266404-7eaacbcd87c5?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1474979266404-7eaacbcd87c5?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1474979266404-7eaacbcd87c5?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],"snacks & namkeen":["https://images.unsplash.com/photo-1601050690597-df0568f70950?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1601050690597-df0568f70950?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1601050690597-df0568f70950?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],beverages:["https://images.unsplash.com/photo-1564890369478-c89ca6d9cde9?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1564890369478-c89ca6d9cde9?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1564890369478-c89ca6d9cde9?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],"dairy & paneer":["https://images.unsplash.com/photo-1628088062854-d1870b4553da?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1628088062854-d1870b4553da?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1628088062854-d1870b4553da?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],"pickles & chutneys":["https://images.unsplash.com/photo-1600857544200-b2f666a9a2ec?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1600857544200-b2f666a9a2ec?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1600857544200-b2f666a9a2ec?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],"sweets & desserts":["https://images.unsplash.com/photo-1587314168485-3236d6710814?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1587314168485-3236d6710814?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80","https://images.unsplash.com/photo-1587314168485-3236d6710814?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"],default:"https://images.unsplash.com/photo-1542838132-92c53300491e?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=80"};var be=r(4675),fe=r(2022);const Ie=e=>{let{categoryName:t}=e;return t?(0,K.jsx)(fe.A,{label:t,size:"small",sx:{position:"absolute",top:12,right:12,zIndex:1,backgroundColor:"rgba(255, 255, 255, 0.9)",fontWeight:600,fontSize:"0.7rem",borderRadius:"12px",boxShadow:"0 2px 5px rgba(0,0,0,0.1)"}}):null},Se="grey",Ce=e=>{let{product:t}=e;(0,be.A)();const{cart:r,addToCart:n,removeFromCart:s}=G(),{id:i,name:a,price:l,description:o,image:d,categoryName:c,isAvailable:x}=t,u=r[i]?.quantity||0,h=d||(c?(e=>{if(e&&ve[e.toLowerCase()]){const t=ve[e.toLowerCase()];return t[Math.floor(Math.random()*t.length)]}return ve.default})(c):"https://picsum.photos/200");return(0,K.jsxs)(ue.A,{sx:{height:"100%",display:"flex",flexDirection:"column",borderRadius:"16px",overflow:"hidden",transition:"transform 0.3s, box-shadow 0.3s",position:"relative",border:"1px solid",borderColor:"divider",...!x&&{opacity:.5,pointerEvents:"none"}},children:[(0,K.jsx)(Ie,{categoryName:c}),(0,K.jsx)(me.A,{component:"img",height:"140",image:h,alt:a,sx:{padding:"10px 0 0 0",objectFit:"contain",transition:"transform 0.5s","&:hover":{transform:"scale(1.05)"}}}),!x&&(0,K.jsx)(A.A,{sx:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",bgcolor:"rgba(0, 0, 0, 0.6)",color:"white",px:2,py:1,borderRadius:"4px",zIndex:1},children:(0,K.jsx)(m.A,{variant:"body1",children:"Sold out"})}),(0,K.jsxs)(he.A,{sx:{flexGrow:1,p:2.5,pb:0,display:"flex",flexDirection:"column"},children:[(0,K.jsx)(m.A,{gutterBottom:!0,variant:"h6",sx:{fontWeight:600,fontSize:"1.1rem",mb:1,lineHeight:1.3},children:a}),o&&(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1.5,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:"0.85rem",lineHeight:1.4},children:o}),(0,K.jsx)(A.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:"auto",mb:2},children:(0,K.jsxs)(m.A,{variant:"h6",sx:{fontWeight:700,color:"primary.main",fontSize:"1.2rem"},children:["$",l.toFixed(2)]})})]}),(0,K.jsx)(Ae.A,{sx:{justifyContent:"center",pb:2.5,px:2.5},children:u>0?(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"48px",borderRadius:"8px",background:"rgba(255, 107, 107, 0.15)",border:"2px solid #FF6B6B",boxShadow:"0 2px 8px rgba(255, 107, 107, 0.15)",transition:"all 0.2s ease","&:hover":{background:"rgba(255, 107, 107, 0.15)",boxShadow:"0 4px 12px rgba(255, 107, 107, 0.2)"}},children:[(0,K.jsx)(je.A,{title:"Remove from cart",children:(0,K.jsx)(le.A,{onClick:()=>s(i),sx:{color:"#FF6B6B",p:1,"&:hover":{backgroundColor:"rgba(255, 107, 107, 0.2)",transform:"scale(1.1)"},transition:"all 0.2s ease"},children:(0,K.jsx)(pe.A,{fontSize:"small"})})}),(0,K.jsx)(m.A,{variant:"body1",sx:{color:"#FF6B6B",fontWeight:700,mx:2,minWidth:"24px",textAlign:"center",fontSize:"1.1rem"},children:u}),(0,K.jsx)(je.A,{title:"Add to cart",children:(0,K.jsx)(le.A,{onClick:()=>n(t),sx:{color:"#FF6B6B",p:1,"&:hover":{backgroundColor:"rgba(255, 107, 107, 0.2)",transform:"scale(1.1)"},transition:"all 0.2s ease"},children:(0,K.jsx)(ge.A,{fontSize:"small"})})})]}):(0,K.jsx)(j.A,{size:"medium",sx:{width:"100%",height:"48px",background:"transparent",color:x?"#FF6B6B":Se,borderRadius:"8px",fontWeight:600,fontSize:"0.95rem",textTransform:"none",position:"relative",overflow:"hidden",border:`2px solid ${x?"#FF6B6B":Se}`,transition:"all 0.2s ease","&:hover":{background:"transparent","& .MuiButton-startIcon":{transform:"translateX(2px)"}},"& .MuiButton-startIcon":{transition:"transform 0.2s ease",marginRight:"8px"}},startIcon:(0,K.jsx)(ye.A,{sx:{fontSize:"1.1rem"}}),onClick:()=>n(t),disabled:!x,children:x?"Add to Cart":"Unavailable"})})]})},we=e=>{let{products:t,title:r}=e;return 0===t.length?(0,K.jsx)(A.A,{sx:{py:8,textAlign:"center"},children:(0,K.jsx)(m.A,{variant:"h6",color:"text.secondary",children:"No products available."})}):(0,K.jsxs)(h.A,{maxWidth:"xl",children:[r&&(0,K.jsx)(m.A,{variant:"h5",sx:{mb:4,fontWeight:600,position:"relative",display:"inline-block","&:after":{content:'""',position:"absolute",bottom:-8,left:0,width:"40%",height:"3px",background:"linear-gradient(45deg, #FF6B6B, #FFA07A)",borderRadius:"3px"}},children:r}),(0,K.jsx)(xe.Ay,{container:!0,spacing:3,children:t.map((e=>(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,K.jsx)(Ce,{product:e})},e.id)))})]})};var Pe=r(8031),De=r(6831),Fe=r(2477);const ke=e=>{let{open:t,onClose:r,children:n,title:s,...i}=e;const a=(0,be.A)();return(0,K.jsxs)(Pe.A,{open:t,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.1)"}},...i,children:[s&&(0,K.jsx)(De.A,{sx:{textAlign:"center",background:a.palette.custom.gradientPrimary,color:"white",py:2.5,mb:2},children:s}),(0,K.jsx)(Fe.A,{children:n})]})};var Ee=r(8532);const $e=e=>(0,K.jsx)(Ee.A,{...e,sx:{minHeight:{xs:"64px",sm:"70px"},px:{xs:2,sm:4},...e.sx}}),We=e=>(0,K.jsx)(je.A,{...e,sx:{"& .MuiTooltip-tooltip":{backgroundColor:"rgba(42, 47, 79, 0.9)",fontSize:"0.875rem",borderRadius:"8px",padding:"8px 16px"},...e.sx}});var Le=r(781);const qe=e=>(0,K.jsx)(Le.A,{...e,sx:{"& .MuiBadge-badge":{backgroundColor:"#E53935",color:"white",minWidth:"20px",height:"20px",padding:"0 6px",fontSize:"0.75rem",fontWeight:600,...e.sx?.["& .MuiBadge-badge"]},...e.sx}});var Re=r(7190);const Te=e=>(0,K.jsx)(Re.A,{...e,sx:{"& .MuiPaper-root":{mt:2,minWidth:"200px",borderRadius:"12px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.1)",border:"1px solid rgba(145, 127, 179, 0.1)",overflow:"hidden"},"& .MuiList-root":{padding:"8px 0"},"& .MuiMenuItem-root":{padding:"12px 24px","&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},...e.sx}}),ze={1:{2:r.p+"9eb9fe16cf24f64648f4.jpg",3:r.p+"97d88e9949ad49749160.jpg",4:r.p+"1b6333e925b3879a2984.jpg",5:r.p+"d35b1aa413caca3d6aa2.png",6:r.p+"5c2c140bb8e65ee1aa94.png",7:r.p+"0a359809026b5022f2d5.jpg"}};const Ue=e=>{let{setStoreModalOpen:t}=e;const[r,n]=(0,x.useState)(""),[s,i]=(0,x.useState)(0),[a,l]=(0,x.useState)(12),{selectedStore:o,availableStores:d}=G(),c=function(e,t){const[r,n]=(0,x.useState)(e);return(0,x.useEffect)((()=>{const r=setTimeout((()=>{n(e)}),t);return()=>{clearTimeout(r)}}),[e,t]),r}(r,300),{data:I,isLoading:S,error:C}=(0,u.I)({queryKey:["storeInventory",o?.id],queryFn:async()=>await P("\n  query GetStoreProducts($storeId: Int!, $isListed: Boolean) {\n    getInventoryByStore(storeId: $storeId, isListed: $isListed) {\n      id\n      isAvailable\n      isListed\n      measurement\n      price\n      productId\n      quantity\n      storeId\n      unit\n      updatedAt\n      product {\n        id\n        name\n        image\n        description\n        category {\n          id\n          name\n        }\n      }\n    }\n  }\n",{storeId:o.id,isListed:!0}),enabled:!!o?.id}),w=(0,x.useMemo)((()=>I?.getInventoryByStore?.map((e=>{const t=o?.id,r=e.productId,n=ze[t]||{};return{id:e.productId,name:e.product.name,image:e.product.image||n[r]||"https://picsum.photos/200",price:e.price,description:e.product.description,categoryId:e.product.category.id,categoryName:e.product.category.name,inventoryId:e.id,quantity:e.quantity,measurement:e.measurement,unit:e.unit,isAvailable:e.isAvailable,isListed:e.isListed}}))||[]),[I,o?.id]),D=(0,x.useMemo)((()=>w.filter((e=>e.name.toLowerCase().includes(c.toLowerCase())))),[w,c]),F=(0,x.useMemo)((()=>D.slice(s*a,s*a+a)),[D,s,a]);return C?(0,K.jsxs)(m.A,{children:["Error fetching products: ",C.message]}):(0,K.jsxs)(K.Fragment,{children:[o&&(0,K.jsx)(h.A,{children:(0,K.jsxs)(A.A,{sx:{alignItems:"center",mb:3,mt:2,p:2,backgroundColor:"rgba(0, 0, 0, 0.03)",borderRadius:2},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",width:"100%"},children:[(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:o.name}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:o.address})]}),(0,K.jsx)(j.A,{variant:"outlined",startIcon:(0,K.jsx)(f.A,{}),onClick:()=>t(!0),children:"Change Store"})]}),(0,K.jsxs)(A.A,{sx:{mt:1,display:"flex",justifyContent:"space-between"},children:[(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:o.description}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:o.tnc})]})]})}),(0,K.jsxs)(h.A,{children:[(0,K.jsx)(p.A,{label:"Search Products",variant:"outlined",fullWidth:!0,sx:{mb:3},value:r,onChange:e=>n(e.target.value),placeholder:"Search by product name or category...",InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(b.A,{})})}}),S?(0,K.jsx)(A.A,{display:"flex",justifyContent:"center",my:4,children:(0,K.jsx)(y.A,{})}):0===w.length?(0,K.jsx)(m.A,{variant:"h6",align:"center",sx:{mt:4},children:"No products available in this store."}):(0,K.jsx)(we,{products:F}),(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,K.jsx)(v.A,{rowsPerPageOptions:[8,12,24],component:"div",count:D.length,rowsPerPage:a,page:s,onPageChange:(e,t)=>{i(t)},onRowsPerPageChange:e=>{l(parseInt(e.target.value,10)),i(0)}})})]})]})};var Be=r(548),Oe=r(7980),Ne=r(4201),Me=r(5327);const _e="/login",Ve="/forgot-password",Ye="/admin",Ge="/user",Ke="/delivery_agent",He="/store_manager",Qe="/store_manager/orders",Je="/orders",Ze="/profile",Xe="/signup",et="/cart";var tt=r(8939),rt=r(9781),nt=r(8393),st=r(437),it=r(8438),at=r(2594);const lt=e=>{let{email:t,onComplete:r,onSuccess:n}=e;const s=(0,d.Zp)(),[i,a]=(0,x.useState)(""),[l,o]=(0,x.useState)(!1),[c,u]=(0,x.useState)(""),[h,A]=(0,x.useState)("");return(0,K.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),o(!0),u(""),A("");try{await(0,at.z)({username:t,confirmationCode:i}),A("Account verified successfully! Redirecting to login..."),setTimeout((()=>{s("/")}),2e3),n&&n(),r&&r()}catch(e){u(e.message||"OTP verification failed. Please try again.")}finally{o(!1)}},children:[(0,K.jsx)(m.A,{variant:"h4",component:"h1",gutterBottom:!0,children:"Verify OTP"}),(0,K.jsx)(p.A,{label:"Enter OTP",variant:"outlined",fullWidth:!0,margin:"normal",value:i,onChange:e=>a(e.target.value),required:!0}),c&&(0,K.jsx)(X.A,{severity:"error",sx:{mt:2},children:c}),h&&(0,K.jsx)(X.A,{severity:"success",sx:{mt:2},children:h}),(0,K.jsx)(j.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:l,sx:{mt:2,py:1.2,borderRadius:"8px",textTransform:"none",fontSize:"1rem"},children:l?(0,K.jsx)(y.A,{size:24,sx:{color:"#fff"}}):"Verify OTP"})]})};var ot=r(5673),dt=r(6768);const ct=e=>{let{onSuccess:t,onError:r}=e;const n=(0,d.Zp)(),{setUser:s,setAbility:i,setModalOpen:a}=V(),[l,o]=(0,x.useState)(""),[c,u]=(0,x.useState)(""),[m,h]=(0,x.useState)(!1),[v,b]=(0,x.useState)(""),[f,I]=(0,x.useState)(!1),[S,C]=(0,x.useState)(!1);return(0,K.jsx)(A.A,{children:f?(0,K.jsx)(lt,{email:l,onSuccess:()=>n("/"),onComplete:()=>I(!1)}):(0,K.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),h(!0),b("");try{const e=await(0,nt.J)({username:l,password:c});if("CONFIRM_SIGN_UP"===e.nextStep?.signInStep)return await(0,st.h)({username:l}),void I(!0);const r=await(0,it.T)(),o=r["custom:role"].toLowerCase();s({email:r.email,role:o});const d=M(o);i(d),t&&t(),a(!1),n(`/${o}`)}catch(e){if(e.message.includes("User is not confirmed"))try{await(0,st.h)({username:l}),I(!0)}catch(e){b(e.message||"Error resending OTP.")}else b(e.message||"Login failed. Please try again.")}finally{h(!1)}},children:[(0,K.jsx)(p.A,{label:"Email",variant:"outlined",fullWidth:!0,value:l,onChange:e=>o(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(se.A,{sx:{color:"#FF6B6B"}})})}}),(0,K.jsx)(p.A,{label:"Password",variant:"outlined",type:S?"text":"password",fullWidth:!0,value:c,onChange:e=>u(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(ie.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,K.jsx)(g.A,{position:"end",children:(0,K.jsx)(le.A,{onClick:()=>C((e=>!e)),edge:"end",children:S?(0,K.jsx)(dt.A,{}):(0,K.jsx)(ot.A,{})})})}}),v&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:2},children:v}),(0,K.jsx)(j.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:m,sx:{py:1.2,borderRadius:"8px",textTransform:"none",fontSize:"1rem"},children:m?(0,K.jsx)(y.A,{size:24,sx:{color:"#fff"}}):"Login"})]})})};var xt=r(3728),ut=r(1432),mt=r(9873);const ht=e=>{let{referredBy:t="",onSuccess:r}=e;const[n,s]=(0,x.useState)(""),[i,a]=(0,x.useState)(""),[l,o]=(0,x.useState)(""),[d,c]=(0,x.useState)(""),[u,m]=(0,x.useState)(""),[h,y]=(0,x.useState)(t),[v,b]=(0,x.useState)(!1),[f,I]=(0,x.useState)(""),[S,C]=(0,x.useState)(""),[w,P]=(0,x.useState)(!1);return(0,K.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),b(!0),I(""),C("");try{await(0,xt.H)({username:n,password:d,options:{userAttributes:{"custom:given_name":i,"custom:family_name":l,"custom:phone_number":u,"custom:referredBy":h}}}),C("Signup successful! Enter the OTP sent to your email."),r&&r(n)}catch(e){if(e.message.includes("User already exists"))try{await(0,st.h)({username:n}),C("OTP resent. Please check your email."),r&&r(n)}catch(e){I(e.message||"Error resending OTP.")}else I(e.message||"Signup failed. Please try again.")}finally{b(!1)}},children:[(0,K.jsx)(p.A,{label:"First Name",variant:"outlined",fullWidth:!0,value:i,onChange:e=>a(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(ut.A,{sx:{color:"#FF6B6B"}})})}}),(0,K.jsx)(p.A,{label:"Last Name",variant:"outlined",fullWidth:!0,value:l,onChange:e=>o(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(ut.A,{sx:{color:"#FF6B6B"}})})}}),(0,K.jsx)(p.A,{label:"Email",variant:"outlined",fullWidth:!0,value:n,onChange:e=>s(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(se.A,{sx:{color:"#FF6B6B"}})})}}),(0,K.jsx)(p.A,{label:"Password",variant:"outlined",type:w?"text":"password",fullWidth:!0,value:d,onChange:e=>c(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(ie.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,K.jsx)(g.A,{position:"end",children:(0,K.jsx)(le.A,{onClick:()=>P((e=>!e)),edge:"end",children:w?(0,K.jsx)(dt.A,{}):(0,K.jsx)(ot.A,{})})})}}),(0,K.jsxs)(A.A,{sx:{display:"flex",gap:1,mb:2},children:[(0,K.jsx)(p.A,{label:"Country Code",variant:"outlined",value:"+1",disabled:!0,sx:{width:"120px"},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(mt.A,{sx:{color:"#FF6B6B"}})})}}),(0,K.jsx)(p.A,{label:"Phone Number",variant:"outlined",fullWidth:!0,value:u,onChange:e=>m(e.target.value),required:!0,InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(mt.A,{sx:{color:"#FF6B6B"}})})}})]}),(0,K.jsx)(p.A,{label:"Referral Code",variant:"outlined",fullWidth:!0,value:h,onChange:e=>y(e.target.value),disabled:!!t,sx:{mb:2},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(se.A,{sx:{color:"#FF6B6B"}})})}}),f&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:2},children:f}),S&&(0,K.jsx)(X.A,{severity:"success",sx:{mb:2},children:S}),(0,K.jsx)(j.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:v,sx:{mt:1,mb:2},children:v?"Processing...":"Sign Up"})]})};var At=r(7442),jt=r(7888);const pt=()=>{const[e,t]=(0,x.useState)(""),[r,n]=(0,x.useState)(""),[s,i]=(0,x.useState)(""),[a,l]=(0,x.useState)(!1),[o,c]=(0,x.useState)(""),[u,m]=(0,x.useState)(""),[h,A]=(0,x.useState)(1),j=(0,d.Zp)();return(0,K.jsx)(H,{sx:{display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"background.default",position:"relative",overflow:"hidden","&::before":{content:'""',position:"absolute",top:0,left:0,right:0,bottom:0,background:"linear-gradient(135deg, rgba(255,107,107,0.1) 0%, rgba(255,107,107,0.05) 100%)",zIndex:0}},children:(0,K.jsxs)(re,{elevation:0,sx:{width:"100%",maxWidth:560,borderRadius:4,p:{xs:3,sm:4,md:6},bgcolor:"background.paper",boxShadow:"0 8px 32px rgba(0,0,0,0.08)",position:"relative",zIndex:1,backdropFilter:"blur(10px)",border:"1px solid rgba(255,255,255,0.2)"},children:[(0,K.jsxs)(H,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,K.jsx)(Z,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:1===h?"Forgot Password":"Reset Password"}),(0,K.jsx)(Z,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:1===h?"Enter your email address to receive a reset code":"Enter the OTP sent to your email and your new password"})]}),1===h?(0,K.jsx)(ae,{fields:[{label:"Email",type:"email",value:e,onChange:t}],onSubmit:async t=>{t.preventDefault(),l(!0),c(""),m("");try{await(0,At.x)({username:e}),A(2),m("OTP sent successfully! Check your email.")}catch(e){c(e.message||"Failed to send OTP. Try again.")}finally{l(!1)}},buttonLabel:"Send OTP",loading:a,error:o,success:u}):(0,K.jsx)(ae,{fields:[{label:"OTP",type:"text",value:r,onChange:n},{label:"New Password",type:"password",value:s,onChange:i}],onSubmit:async t=>{t.preventDefault(),l(!0),c(""),m("");try{await(0,jt.P)({username:e,confirmationCode:r,newPassword:s}),m("Password reset successfully! Redirecting to login..."),setTimeout((()=>j("/")),2e3)}catch(e){c(e.message||"Failed to reset password. Try again.")}finally{l(!1)}},buttonLabel:"Reset Password",loading:a,error:o,success:u})]})})},gt=e=>{let{open:t,onClose:r,initialForm:n="login"}=e;const[s,i]=(0,x.useState)(n),[a,l]=(0,x.useState)(""),[o,d]=(0,x.useState)(!1),c=(0,be.A)(),u=e=>{i(e),d(!1)};return(0,K.jsx)(tt.A,{open:t,onClose:r,"aria-labelledby":"modal-modal-title","aria-describedby":"modal-modal-description",sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:(0,K.jsxs)(A.A,{sx:{width:"100%",maxWidth:560,borderRadius:4,p:{xs:3,sm:4,md:5},bgcolor:"background.paper",boxShadow:"0 8px 32px rgba(0,0,0,0.08)",position:"relative",zIndex:1,backdropFilter:"blur(10px)",border:"1px solid rgba(255,255,255,0.2)"},children:[(0,K.jsx)(j.A,{onClick:r,sx:{position:"absolute",top:8,right:8,minWidth:0,p:.5},children:(0,K.jsx)(rt.A,{})}),(0,K.jsxs)(A.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:3},children:[(0,K.jsx)(m.A,{variant:"h5",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.5rem",sm:"1.75rem"}},children:"login"===s?"Welcome Back":"signup"===s?"Create Account":"otp"===s?"Verify Email":""}),(0,K.jsx)(m.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"login"===s?"Sign in to continue your journey with us":"signup"===s?"Join us and start your adventure":"otp"===s?"Enter the OTP sent to your email":""})]}),o&&"login"===s&&(0,K.jsx)(X.A,{severity:"success",sx:{mb:2},children:"Email verified successfully! Please login to continue."}),"login"===s?(0,K.jsx)(ct,{}):"signup"===s?(0,K.jsx)(ht,{onSuccess:e=>{l(e),i("otp")}}):"otp"===s?(0,K.jsx)(lt,{email:a,onSuccess:()=>{d(!0),i("login")}}):(0,K.jsx)(pt,{}),(0,K.jsxs)(A.A,{sx:{mt:3,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:["login"===s&&(0,K.jsx)(j.A,{onClick:()=>u("forgotPassword"),sx:{color:c.palette.primary.main,textTransform:"none"},children:"Forgot Password?"}),"otp"!==s&&(0,K.jsxs)(m.A,{variant:"body2",sx:{color:"text.secondary"},children:["login"===s?"Don't have an account?":"signup"===s?"Already have an account?":"Remember your password?",(0,K.jsx)(j.A,{color:"primary",onClick:()=>u("login"===s?"signup":"login"),sx:{textTransform:"none"},children:"login"===s?"Sign Up":"Login"})]})]})]})})},yt=e=>{let{navigate:t,userRole:r}=e;const{setUser:n}=V();return(0,K.jsx)(Z,{onClick:async()=>{let e=r;if(!e)try{const t=await(0,Be.$)();t?.tokens?.idToken&&(e=t.tokens.idToken.payload["custom:role"]?.toLowerCase(),n({role:e}))}catch(e){}t(e?`/${e}`:"/")},sx:{cursor:"pointer",fontWeight:800,fontSize:{xs:"1.5rem",sm:"1.75rem"},background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",letterSpacing:"0.5px"},children:"Indimitra"})},vt=()=>{const e=(0,d.Zp)(),[t,r]=(0,x.useState)(null),n=(0,Me.A)("(max-width: 600px)"),s=G((e=>e.cartCount())),{user:i,ability:a,logout:l}=V(),[o,c]=x.useState(null),{modalOpen:u,setModalOpen:m,currentForm:h,setCurrentForm:A}=V(),[j,p]=(0,x.useState)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Be.$)(),t=await(0,it.T)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;p(t)}const n=t["custom:role"]?.toLowerCase();r(n)}catch(e){}})()}),[]);const g=()=>c(null),y=M(i?.role||"user");return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(H,{sx:{position:"fixed",top:0,left:0,right:0,zIndex:1100,backgroundColor:"#ffffff",boxShadow:"0 2px 20px rgba(0,0,0,0.08)"},children:(0,K.jsxs)($e,{sx:{minHeight:{xs:"64px",sm:"70px"},px:{xs:2,sm:4}},children:[(0,K.jsx)(yt,{navigate:e,userRole:i?.role}),(0,K.jsx)(H,{sx:{flexGrow:1}}),(0,K.jsxs)(H,{sx:{display:"flex",alignItems:"center",gap:{xs:1,sm:2}},children:[!j&&(0,K.jsx)(Q,{onClick:()=>{m(!0),A("login")},sx:{color:"#2A2F4F",textTransform:"none",fontSize:"1rem",fontWeight:500,px:2,"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:"Sign In"}),(0,K.jsx)(gt,{open:u,onClose:()=>m(!1),currentForm:h,setCurrentForm:A}),!n&&j&&y&&y.can("view","orders")&&(0,K.jsx)(Q,{onClick:()=>e(Je),sx:{color:"#2A2F4F",textTransform:"none",fontSize:"1rem",fontWeight:500,px:2,"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:"Orders"}),i?y?.can("view","cart")&&(0,K.jsx)(We,{title:"Cart",children:(0,K.jsx)(oe,{onClick:()=>e(et),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white","&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,K.jsx)(qe,{badgeContent:s,children:(0,K.jsx)(ye.A,{})})})}):(0,K.jsx)(We,{title:"Cart",children:(0,K.jsx)(oe,{onClick:()=>e(et),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white","&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,K.jsx)(qe,{badgeContent:s,children:(0,K.jsx)(ye.A,{})})})}),j&&(0,K.jsx)(We,{title:"Profile",children:(0,K.jsx)(oe,{onClick:e=>c(e.currentTarget),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white","&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,K.jsx)(Oe.A,{})})})]})]})}),(0,K.jsxs)(Te,{anchorEl:o,open:Boolean(o),onClose:g,PaperProps:{elevation:3,sx:{mt:2,minWidth:"200px",borderRadius:"12px",overflow:"hidden"}},children:[n&&y?.can("view","orders")&&(0,K.jsx)(ce,{onClick:()=>{e(Je),g()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,K.jsx)(Z,{variant:"body1",children:"Orders"})}),(0,K.jsx)(ce,{onClick:()=>{e(Ze),g()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,K.jsx)(Z,{variant:"body1",children:"Profile"})}),(0,K.jsx)(ce,{onClick:()=>{(async()=>{try{await(0,Ne.C)(),l(),p(null),r(null),e("/")}catch(e){}})(),g()},sx:{py:1.5,px:3,color:"#FF5757","&:hover":{backgroundColor:"rgba(255, 87, 87, 0.1)"}},children:(0,K.jsx)(Z,{variant:"body1",children:"Logout"})})]}),(0,K.jsx)(H,{sx:{height:{xs:"64px",sm:"70px"}}})]})};var bt=r(7992),ft=r(1451);const It=()=>(0,K.jsx)(bt.A,{color:"success","aria-label":"WhatsApp",onClick:()=>{const e=`https://wa.me/+15627872535?text=${encodeURIComponent("Hello! I have a question about your services.")}`;window.open(e,"_blank")},sx:{position:"fixed",bottom:20,right:20,zIndex:1e3,backgroundColor:"#25D366","&:hover":{backgroundColor:"#128C7E"}},children:(0,K.jsx)(ft.A,{sx:{fontSize:32}})}),St=e=>{let{children:t}=e;return(0,K.jsxs)(H,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[(0,K.jsx)(vt,{}),t,(0,K.jsx)(It,{})]})},Ct=e=>{let{children:t,role:r}=e;const{user:n,setUser:s,ability:i,setAbility:a}=V(),[l,o]=(0,x.useState)(!0),[c,u]=(0,x.useState)(!1),[m,h]=(0,x.useState)(null),A=(0,d.zy)();if((0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Be.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload["custom:role"]?.toLowerCase();n||s({role:t});const r=M(t);a(r),h(r),u(!0)}else u(!1)}catch(e){u(!1)}finally{o(!1)}})()}),[n,s,a]),l)return(0,K.jsx)(ne,{});if(!c)return(0,K.jsx)(d.C5,{to:"/",replace:!0});if(A.pathname===Ze)return(0,K.jsx)(St,{children:t});const j=(Array.isArray(r)?r:[r]).map((e=>e.toLowerCase()));return m&&j.some((e=>m.can("view",e)))?(0,K.jsx)(St,{children:t}):(0,K.jsx)(d.C5,{to:"/not-authorized",replace:!0})},wt=()=>{const[e,t]=(0,x.useState)(!1),[r,n]=(0,x.useState)(""),[i]=(0,s.ok)(),a=i.get("referredby")||"";return(0,K.jsx)(A.A,{sx:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"background.default",position:"relative",overflow:"hidden","&::before":{content:'""',position:"absolute",top:0,left:0,right:0,bottom:0,background:"linear-gradient(135deg, rgba(255,107,107,0.1) 0%, rgba(255,107,107,0.05) 100%)",zIndex:0}},children:(0,K.jsxs)(te.A,{elevation:0,sx:{width:"100%",maxWidth:560,borderRadius:4,p:{xs:3,sm:4,md:6},bgcolor:"background.paper",boxShadow:"0 8px 32px rgba(0,0,0,0.08)",position:"relative",zIndex:1,backdropFilter:"blur(10px)",border:"1px solid rgba(255,255,255,0.2)"},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,K.jsx)(m.A,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:e?"Verify OTP":"Create Account"}),(0,K.jsx)(m.A,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:e?"Enter the OTP sent to your email to verify your account":"Join us and start your journey today"})]}),(0,K.jsx)(A.A,{sx:{minHeight:300},children:e?(0,K.jsx)(lt,{email:r,onComplete:()=>t(!1)}):(0,K.jsx)(ht,{referredBy:a,onOtpStep:e=>{n(e),t(!0)}})})]})})};var Pt=r(1543),Dt=r(9799),Ft=r(4090),kt=r(7873),Et=r(2241),$t=r(8620),Wt=r(1117),Lt=r(9603),qt=r(9377),Rt=r(5685),Tt=r(9634),zt=r(215),Ut=r(5764),Bt=r(2935),Ot=r(4654),Nt=r(7451),Mt=r(3198),_t=r(4137),Vt=r(6627),Yt=r(6798),Gt=r(4774),Kt=r(3884),Ht=r(7532),Qt=r(423),Jt=r(779),Zt=r(4433),Xt=r(5460),er=r(8763),tr=r(5557),rr=r(2297),nr=r(9388),sr=r(8125),ir=r(7097);const ar=()=>{const e=(0,be.A)(),t=(0,Me.A)(e.breakpoints.down("sm")),[r,n]=(0,x.useState)(0),[s,i]=(0,x.useState)(""),[a,l]=(0,x.useState)(0),[o,d]=(0,x.useState)(10),[c,h]=(0,x.useState)(!1),[b,f]=(0,x.useState)(""),[I,S]=(0,x.useState)(null),[C,w]=(0,x.useState)(!1),[D,F]=(0,x.useState)(""),[k,E]=(0,x.useState)({open:!1,message:"",severity:"success"}),[$,L]=(0,x.useState)(null),[q,R]=(0,x.useState)(!1),[T,z]=(0,x.useState)(""),[U,B]=(0,x.useState)([]),{data:O,isLoading:N,error:M,refetch:_}=(0,u.I)({queryKey:["users"],queryFn:async()=>{const e=await P("query getAllUsers {\n  getAllUsers {\n    id\n    email\n    type\n    cognitoId\n  }\n}");return e?.getAllUsers||[]},enabled:!0}),{data:V,isLoading:Y,error:G,refetch:H}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{const e=await P(W);return e?.stores||[]},enabled:!0}),Q=(0,ir.n)({mutationFn:e=>P("\n  mutation UpdateUserType($requesterId: String!, $targetUserId: String!, $newType: String!) {\n    updateUserType(requesterId: $requesterId, targetUserId: $targetUserId, newType: $newType) {\n      user {\n        id\n        email\n        type\n      }\n      error {\n        message\n      }\n    }\n  }\n",e),onSuccess:e=>{const t=e?.updateUserType;t?.error?E({open:!0,message:t.error.message||"Failed to update user role",severity:"error"}):t?.user&&(E({open:!0,message:`Successfully updated user role to ${t.user.type}`,severity:"success"}),_()),w(!1)},onError:e=>{E({open:!0,message:"Error updating user role: "+e.message,severity:"error"})}}),J=(0,ir.n)({mutationFn:e=>P("\n  mutation AssignDriverToStore($storeId: Int!, $userId: Int!) {\n    assignDriverToStore(storeId: $storeId, userId: $userId) {\n      id\n      userId\n      store {\n        name\n        drivers {\n          edges {\n            node {\n              driver {\n                email\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n",e),onSuccess:e=>{const t=e?.assignDriverToStore;t&&(E({open:!0,message:`Successfully assigned driver to ${t.store.name}`,severity:"success"}),H()),R(!1)},onError:e=>{E({open:!0,message:"Error assigning driver to store: "+e.message,severity:"error"})}});(0,x.useEffect)((()=>{O&&(async()=>{try{if(O){const e=O.find((e=>"ADMIN"===e.type));e&&L(e.cognitoId)}}catch(e){}})()}),[O]),(0,x.useEffect)((()=>{V&&B(V)}),[V]);const Z=e=>{S(e),F(e.type),w(!0)},ee=e=>{S(e),z(""),R(!0)},re=()=>{E({...k,open:!1})},ne=()=>{if(!O)return[];let e=O;return 1===r?e=O.filter((e=>"USER"===e.type)):2===r?e=O.filter((e=>"DELIVERY"===e.type)):3===r&&(e=O.filter((e=>"STORE_MANAGER"===e.type))),s&&(e=e.filter((e=>e.email.toLowerCase().includes(s.toLowerCase())||e.mobile&&e.mobile.includes(s)||e.referralId&&e.referralId.toLowerCase().includes(s.toLowerCase())))),e};return(0,K.jsxs)(A.A,{sx:{p:t?2:3},children:[(0,K.jsxs)(te.A,{sx:{p:3,mb:3},children:[(0,K.jsx)(m.A,{variant:"h5",gutterBottom:!0,children:"User Management"}),(0,K.jsxs)(Ht.A,{value:r,onChange:(e,t)=>{n(t),l(0)},sx:{mb:3},variant:t?"fullWidth":"standard",children:[(0,K.jsx)(Qt.A,{label:"All"}),(0,K.jsx)(Qt.A,{label:"Users"}),(0,K.jsx)(Qt.A,{label:"Delivery Partners"}),(0,K.jsx)(Qt.A,{label:"Store Managers"})]}),(0,K.jsx)(A.A,{sx:{mb:3,display:"flex",gap:2,flexWrap:"wrap"},children:(0,K.jsx)(p.A,{size:"small",placeholder:"Search...",value:s,onChange:e=>{i(e.target.value),l(0)},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(sr.A,{})})},sx:{flexGrow:1,minWidth:200}})}),M&&(0,K.jsxs)(X.A,{severity:"error",sx:{mb:3},children:["Error loading users: ",M.message]}),N?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,K.jsx)(y.A,{})}):(0,K.jsxs)(K.Fragment,{children:[0===r&&(0,K.jsx)(Mt.A,{children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"ID"}),(0,K.jsx)(Gt.A,{children:"Email"}),(0,K.jsx)(Gt.A,{children:"Mobile"}),(0,K.jsx)(Gt.A,{children:"Type"}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{children:"Referral ID"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:ne().slice(a*o,a*o+o).map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e.id}),(0,K.jsx)(Gt.A,{children:e.email}),(0,K.jsx)(Gt.A,{children:e.mobile||"N/A"}),(0,K.jsx)(Gt.A,{children:e.type}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,K.jsx)(Gt.A,{children:e.referralId||"N/A"}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(le.A,{size:"small",color:"primary",onClick:()=>Z(e),children:(0,K.jsx)(rr.A,{})}),"DELIVERY"===e.type&&(0,K.jsx)(le.A,{size:"small",color:"secondary",onClick:()=>ee(e),title:"Assign to Store",children:(0,K.jsx)(nr.A,{})})]})]},e.id)))})]})}),1===r&&(0,K.jsx)(Mt.A,{children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"ID"}),(0,K.jsx)(Gt.A,{children:"Email"}),(0,K.jsx)(Gt.A,{children:"Mobile"}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{children:"Referral ID"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:ne().slice(a*o,a*o+o).map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e.id}),(0,K.jsx)(Gt.A,{children:e.email}),(0,K.jsx)(Gt.A,{children:e.mobile||"N/A"}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,K.jsx)(Gt.A,{children:e.referralId||"N/A"}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(le.A,{size:"small",color:"primary",onClick:()=>Z(e),children:(0,K.jsx)(rr.A,{})})})]},e.id)))})]})}),2===r&&(0,K.jsx)(Mt.A,{children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"ID"}),(0,K.jsx)(Gt.A,{children:"Email"}),(0,K.jsx)(Gt.A,{children:"Mobile"}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{children:"Referral ID"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:ne().slice(a*o,a*o+o).map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e.id}),(0,K.jsx)(Gt.A,{children:e.email}),(0,K.jsx)(Gt.A,{children:e.mobile||"N/A"}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,K.jsx)(Gt.A,{children:e.referralId||"N/A"}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(le.A,{size:"small",color:"primary",onClick:()=>Z(e),children:(0,K.jsx)(rr.A,{})}),(0,K.jsx)(le.A,{size:"small",color:"secondary",onClick:()=>ee(e),title:"Assign to Store",children:(0,K.jsx)(nr.A,{})})]})]},e.id)))})]})}),3===r&&(0,K.jsx)(Mt.A,{children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"ID"}),(0,K.jsx)(Gt.A,{children:"Email"}),(0,K.jsx)(Gt.A,{children:"Mobile"}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{children:"Referral ID"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:ne().slice(a*o,a*o+o).map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e.id}),(0,K.jsx)(Gt.A,{children:e.email}),(0,K.jsx)(Gt.A,{children:e.mobile||"N/A"}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,K.jsx)(Gt.A,{children:e.referralId||"N/A"}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(le.A,{size:"small",color:"primary",onClick:()=>Z(e),children:(0,K.jsx)(rr.A,{})})})]},e.id)))})]})}),(0,K.jsx)(v.A,{component:"div",count:ne().length,page:a,onPageChange:(e,t)=>{l(t)},rowsPerPage:o,onRowsPerPageChange:e=>{d(parseInt(e.target.value,10)),l(0)},sx:{mt:2}})]})]}),(0,K.jsxs)(Pe.A,{open:C,onClose:()=>w(!1),fullWidth:!0,maxWidth:"sm",PaperProps:{sx:{width:"100%",maxWidth:"600px",m:{xs:2,sm:3,md:4},p:{xs:2,sm:3}}},children:[(0,K.jsx)(De.A,{sx:{pb:1},children:"Update User Role"}),(0,K.jsx)(Fe.A,{children:I&&(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsxs)(m.A,{variant:"subtitle1",gutterBottom:!0,children:["User: ",I.email]}),(0,K.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",I.id]}),(0,K.jsxs)(Jt.A,{fullWidth:!0,sx:{mt:2},children:[(0,K.jsx)(Zt.A,{children:"Role"}),(0,K.jsxs)(Xt.A,{value:D,onChange:e=>{F(e.target.value)},label:"Role",sx:{mb:2},children:[(0,K.jsx)(de.A,{value:"USER",children:"User"}),(0,K.jsx)(de.A,{value:"ADMIN",children:"Admin"}),(0,K.jsx)(de.A,{value:"DELIVERY",children:"Delivery Partner"}),(0,K.jsx)(de.A,{value:"STORE_MANAGER",children:"Store Manager"})]})]})]})}),(0,K.jsxs)(er.A,{sx:{px:3,py:2},children:[(0,K.jsx)(j.A,{onClick:()=>w(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:()=>{if(!$)return void E({open:!0,message:"Admin ID not available. Please try again.",severity:"error"});Q.mutate({requesterId:$,targetUserId:I.cognitoId,newType:{USER:"USER",ADMIN:"ADMIN",DELIVERY:"DELIVERY_AGENT",STORE_MANAGER:"STORE_MANAGER"}[D]||D})},variant:"contained",color:"primary",disabled:Q.isPending,children:Q.isPending?"Updating...":"Update Role"})]})]}),(0,K.jsxs)(Pe.A,{open:q,onClose:()=>R(!1),fullWidth:!0,maxWidth:"sm",PaperProps:{sx:{width:"100%",maxWidth:"600px",m:{xs:2,sm:3,md:4},p:{xs:2,sm:3}}},children:[(0,K.jsx)(De.A,{sx:{pb:1},children:"Assign Driver to Store"}),(0,K.jsx)(Fe.A,{children:I&&(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsxs)(m.A,{variant:"subtitle1",gutterBottom:!0,children:["Driver: ",I.email]}),(0,K.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",I.id]}),(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,sx:{mt:2},children:"Select Store"}),Y?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,K.jsx)(y.A,{size:24})}):G?(0,K.jsxs)(X.A,{severity:"error",sx:{mb:2},children:["Error loading stores: ",G.message]}):0===U.length?(0,K.jsx)(X.A,{severity:"info",sx:{mb:2},children:"No stores available"}):(0,K.jsxs)(Jt.A,{fullWidth:!0,sx:{mt:1},children:[(0,K.jsx)(Zt.A,{children:"Store"}),(0,K.jsx)(Xt.A,{value:T,onChange:e=>{z(e.target.value)},label:"Store",sx:{mb:2},children:U.map((e=>(0,K.jsxs)(de.A,{value:e.id,children:[e.name," - ",e.address]},e.id)))})]}),T&&(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,children:"Current Drivers"}),U.find((e=>e.id===parseInt(T)))?.drivers?.edges?.length>0?(0,K.jsx)(A.A,{sx:{mt:1},children:U.find((e=>e.id===parseInt(T)))?.drivers?.edges?.map(((e,t)=>(0,K.jsx)(fe.A,{label:e.node.driver.email,size:"small",sx:{mr:1,mb:1}},t)))}):(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"No drivers assigned to this store yet"})]})]})}),(0,K.jsxs)(er.A,{sx:{px:3,py:2},children:[(0,K.jsx)(j.A,{onClick:()=>R(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:()=>{T&&I?J.mutate({storeId:parseInt(T),userId:parseInt(I.id)}):E({open:!0,message:"Please select a store",severity:"error"})},variant:"contained",color:"primary",disabled:!T||J.isPending,children:J.isPending?"Assigning...":"Assign to Store"})]})]}),(0,K.jsx)(tr.A,{open:k.open,autoHideDuration:6e3,onClose:re,message:k.message,children:(0,K.jsx)(X.A,{onClose:re,severity:k.severity,children:k.message})})]})};var lr=r(9738),or=r(2997),dr=r(7363),cr=r(250),xr=r(7027),ur=r(765),mr=r(4337),hr=r(2306),Ar=r(9432);const jr=["Store Information","Inventory","Drivers","Store Managers","Review"],pr=()=>{const[e,t]=(0,x.useState)(0),[r,n]=(0,x.useState)(""),[s,i]=(0,x.useState)(!1),[a,l]=(0,x.useState)(null),[o,d]=(0,x.useState)(!1),[c,h]=(0,x.useState)({}),v=(0,be.A)(),[b,f]=((0,Me.A)(v.breakpoints.down("sm")),(0,x.useState)(0)),[I,S]=(0,x.useState)({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",inventory:[],drivers:[],storeManagers:[],pincodes:""}),[C,w]=(0,x.useState)(null),[D,F]=(0,x.useState)({open:!1,message:"",severity:"success"}),{data:k,isLoading:E,refetch:$}=(0,u.I)({queryKey:["stores"],queryFn:()=>P(W),enabled:s}),L=(0,ir.n)({mutationFn:e=>P("\n  mutation CreateStore(\n    $name: String!\n    $address: String!\n    $managerUserId: Int!\n    $radius: Float!\n    $email: String!\n    $mobile: String!\n    $description: String\n    $storeDeliveryFee: Float\n    $taxPercentage: Float\n    $tnc: String\n    $pincodes: [String!]\n  ) {\n    createStore(\n      name: $name\n      address: $address\n      managerUserId: $managerUserId\n      radius: $radius\n      email: $email\n      mobile: $mobile\n      description: $description\n      storeDeliveryFee: $storeDeliveryFee\n      taxPercentage: $taxPercentage\n      tnc: $tnc\n      pincodes: $pincodes\n    ) {\n      id\n      name\n      address\n        email\n        mobile\n      managerUserId\n      radius\n      description\n      storeDeliveryFee\n      taxPercentage\n      tnc\n      pincodes\n    }\n  }\n",{name:e.name,address:e.address,managerUserId:parseInt(e.managerUserId,10),radius:parseFloat(e.radius),email:e.email,mobile:e.mobile,description:e.description||null,storeDeliveryFee:e.storeDeliveryFee?parseFloat(e.storeDeliveryFee):null,taxPercentage:e.taxPercentage?parseFloat(e.taxPercentage):null,tnc:e.tnc||null,pincodes:e.pincodes||null}),onSuccess:()=>{d(!0),l(null),S({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",inventory:[],drivers:[],storeManagers:[],pincodes:""}),f(0),$()},onError:e=>{l(e.message||"Failed to create store"),d(!1)}}),q=(0,ir.n)({mutationFn:e=>P("\n  mutation UpdateStore(\n    $storeId: Int!\n    $name: String\n    $address: String\n    $email: String\n    $mobile: String\n    $managerUserId: Int\n    $radius: Float\n    $isActive: Boolean\n    $disabled: Boolean\n    $description: String\n    $pincodes: [String!]\n    $tnc: String\n    $storeDeliveryFee: Float\n    $taxPercentage: Float\n  ) {\n    updateStore(\n      storeId: $storeId\n      name: $name\n      address: $address\n      email: $email\n      mobile: $mobile\n      managerUserId: $managerUserId\n      radius: $radius\n      isActive: $isActive\n      disabled: $disabled\n      description: $description\n      pincodes: $pincodes\n      tnc: $tnc\n      storeDeliveryFee: $storeDeliveryFee\n      taxPercentage: $taxPercentage\n    ) {\n      id\n      name\n      address\n      email\n      mobile\n      managerUserId\n      radius\n      isActive\n      disabled\n      description\n      pincodes\n      tnc\n      storeDeliveryFee\n      taxPercentage\n    }\n  }\n",e),onSuccess:()=>{F({open:!0,message:"Store updated successfully",severity:"success"}),w(null),$()},onError:e=>{F({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),R=e=>{const{name:t,value:r}=e.target;S((e=>({...e,[t]:r}))),c[t]&&h((e=>({...e,[t]:null}))),a&&l(null)},T=()=>{const e={};return I.name.trim()||(e.name="Store name is required"),I.address.trim()||(e.address="Address is required"),I.managerUserId||(e.managerUserId="Manager User ID is required"),h(e),0===Object.keys(e).length},z=()=>{w(null)},U=k?.stores?.filter((e=>e.name.toLowerCase().includes(r.toLowerCase())||e.address.toLowerCase().includes(r.toLowerCase())))||[];return(0,K.jsxs)(A.A,{children:[(0,K.jsxs)(te.A,{sx:{p:3,mb:3},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,K.jsx)(Lt.A,{sx:{mr:1}}),(0,K.jsx)(m.A,{variant:"h5",children:"Store Management"})]}),(0,K.jsxs)(Ht.A,{value:e,onChange:(e,r)=>{t(r)},sx:{mb:3},children:[(0,K.jsx)(Qt.A,{label:"Store List"}),(0,K.jsx)(Qt.A,{label:"Add New Store"})]}),a&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:3},children:a}),o&&(0,K.jsx)(X.A,{severity:"success",sx:{mb:3},children:"Store created successfully!"}),0===e?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(A.A,{sx:{mb:3},children:(0,K.jsx)(p.A,{fullWidth:!0,variant:"outlined",placeholder:"Search stores...",value:r,onChange:e=>n(e.target.value),InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(sr.A,{})})}})}),s?E?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,K.jsx)(y.A,{})}):0===U.length?(0,K.jsx)(X.A,{severity:"info",sx:{mb:3},children:"No stores found matching your criteria"}):(0,K.jsx)(xe.Ay,{container:!0,spacing:3,children:U.map((e=>(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(te.A,{sx:{transition:"all 0.3s ease-in-out",position:"relative",overflow:"hidden","&:hover":{boxShadow:e=>`0 8px 24px ${e.palette.primary.main}20`,"& .store-header":{background:e=>`linear-gradient(45deg, ${e.palette.primary.main}, ${e.palette.primary.dark})`,"& .store-name":{color:"white"},"& .store-id":{color:"rgba(255, 255, 255, 0.8)"}},"& .action-buttons":{opacity:1}}},children:[(0,K.jsx)(A.A,{className:"store-header",sx:{p:2,background:e=>`linear-gradient(45deg, ${e.palette.primary.light}, ${e.palette.primary.main})`,transition:"all 0.3s ease-in-out"},children:(0,K.jsxs)(xe.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(Lt.A,{sx:{mr:2,color:"white",fontSize:"2rem"}}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{className:"store-name",variant:"h6",sx:{color:"white",fontWeight:600,transition:"color 0.3s ease-in-out"},children:e.name}),(0,K.jsxs)(m.A,{className:"store-id",variant:"body2",sx:{color:"rgba(255, 255, 255, 0.8)",transition:"color 0.3s ease-in-out"},children:["ID: ",e.id]})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",md:"flex-end"},gap:2},children:[(0,K.jsx)(fe.A,{label:e.isActive?"Active":"Inactive",color:e.isActive?"success":"error",sx:{fontWeight:600,boxShadow:2,"& .MuiChip-label":{px:1}}}),(0,K.jsx)(A.A,{className:"action-buttons",sx:{display:"flex",gap:1,opacity:.9},children:(0,K.jsx)(j.A,{size:"small",startIcon:(0,K.jsx)(rr.A,{}),sx:{fontWeight:600,textTransform:"none",color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},onClick:()=>(e=>{w(e)})(e),children:"Edit"})})]})})]})}),(0,K.jsx)(A.A,{sx:{p:3},children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle2",sx:{mb:2,fontWeight:600,color:"primary.main",display:"flex",alignItems:"center","&::before":{content:'""',display:"inline-block",width:4,height:16,backgroundColor:"primary.main",marginRight:1,borderRadius:1}},children:"Contact Information"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,K.jsx)(xr.A,{sx:{mr:1.5,color:"primary.main",mt:.3,flexShrink:0,fontSize:"1.2rem"}}),(0,K.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.address})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,K.jsx)(ur.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,K.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.mobile||"No contact info"})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(mr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,K.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.email||"No email info"})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle2",sx:{mb:2,fontWeight:600,color:"primary.main",display:"flex",alignItems:"center","&::before":{content:'""',display:"inline-block",width:4,height:16,backgroundColor:"primary.main",marginRight:1,borderRadius:1}},children:"Delivery Information"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,K.jsx)(nr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,K.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Radius: ",e.radius," mi"]})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,K.jsx)(hr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,K.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Delivery Fee: $",e.storeDeliveryFee?.toFixed(2)||"0.00"]})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,K.jsx)(Ar.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,K.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Tax Rate: ",e.taxPercentage?.toFixed(1)||"0.0","%"]})]}),e.pincodes&&e.pincodes.length>0&&(0,K.jsx)(A.A,{sx:{display:"flex",flexWrap:"wrap",gap:.8},children:e.pincodes.map((e=>(0,K.jsx)(fe.A,{label:e,size:"small",sx:{backgroundColor:"primary.light",color:"primary.contrastText",fontWeight:600,transition:"all 0.2s ease-in-out","&:hover":{backgroundColor:"primary.main",transform:"scale(1.05)"}}},e)))})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsxs)(A.A,{children:[e.description&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",sx:{mb:2,fontWeight:600,color:"primary.main",display:"flex",alignItems:"center","&::before":{content:'""',display:"inline-block",width:4,height:16,backgroundColor:"primary.main",marginRight:1,borderRadius:1}},children:"Description"}),(0,K.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.description})]}),e.tnc&&(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle2",sx:{mb:2,fontWeight:600,color:"primary.main",display:"flex",alignItems:"center","&::before":{content:'""',display:"inline-block",width:4,height:16,backgroundColor:"primary.main",marginRight:1,borderRadius:1}},children:"Terms & Conditions"}),(0,K.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.tnc})]})]})})]})})]})},e.id)))}):(0,K.jsxs)(ue.A,{sx:{mb:3},children:[(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Stores" to load store data'}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]}),(0,K.jsx)(Ae.A,{sx:{justifyContent:"center"},children:(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(cr.A,{}),onClick:()=>{i(!0),$()},children:"Fetch Stores"})})]})]}):(0,K.jsxs)(A.A,{sx:{maxWidth:800,mx:"auto"},children:[(0,K.jsx)(lr.A,{activeStep:b,sx:{mb:4},children:jr.map((e=>(0,K.jsx)(or.A,{children:(0,K.jsx)(dr.A,{children:e})},e)))}),(e=>{switch(e){case 0:return(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Basic Store Information"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Store Name",name:"name",value:I.name,onChange:R,error:!!c.name,helperText:c.name})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Address",name:"address",value:I.address,onChange:R,error:!!c.address,helperText:c.address})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Manager Email",name:"email",type:"email",value:I.email,onChange:R,error:!!c.email,helperText:c.email})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Manager Mobile",name:"mobile",value:I.mobile,onChange:R,error:!!c.mobile,helperText:c.mobile})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Manager User ID",name:"managerUserId",type:"number",value:I.managerUserId,onChange:R,error:!!c.managerUserId,helperText:c.managerUserId||"Enter the ID of the user who will manage this store"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Delivery Radius (mi)",name:"radius",type:"number",value:I.radius,onChange:R,inputProps:{step:"0.1"}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Delivery Fee ($)",name:"storeDeliveryFee",type:"number",value:I.storeDeliveryFee,onChange:R,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:"$"})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Tax Rate (%)",name:"taxPercentage",type:"number",value:I.taxPercentage,onChange:R,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,K.jsx)(g.A,{position:"end",children:"%"})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Description",name:"description",value:I.description,onChange:R,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Terms & Conditions",name:"tnc",value:I.tnc,onChange:R,multiline:!0,rows:3})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Delivery Pincodes",name:"pincodes",value:I.pincodes,onChange:R,helperText:"Enter pincodes separated by commas"})})]});case 1:return(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Inventory Management"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",paragraph:!0,children:"This is a placeholder for inventory management. In a real implementation, you would be able to add products to the store."})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsxs)(te.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Inventory Items"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,K.jsx)(ue.A,{variant:"outlined",children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:"Product 1"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Grocery"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $9.99"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 50"})]})})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,K.jsx)(ue.A,{variant:"outlined",children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:"Product 2"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Electronics"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $49.99"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 25"})]})})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,K.jsx)(ue.A,{variant:"outlined",children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:"Product 3"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Clothing"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $19.99"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 100"})]})})})]})]}),(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,K.jsx)(j.A,{variant:"outlined",startIcon:(0,K.jsx)(ge.A,{}),children:"Add Inventory Item"})})]})]});case 2:return(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Driver Management"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",paragraph:!0,children:"This is a placeholder for driver management. In a real implementation, you would be able to assign drivers to the store."})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsxs)(te.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Drivers"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,K.jsx)(ue.A,{variant:"outlined",children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:"John Doe"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: john.doe@example.com"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 123-4567"}),(0,K.jsx)(fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,K.jsx)(ue.A,{variant:"outlined",children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:"Jane Smith"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: jane.smith@example.com"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 987-6543"}),(0,K.jsx)(fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,K.jsx)(ue.A,{variant:"outlined",children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:"Mike Johnson"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: mike.johnson@example.com"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 456-7890"}),(0,K.jsx)(fe.A,{label:"Inactive",color:"error",size:"small",sx:{mt:1}})]})})})]})]}),(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,K.jsx)(j.A,{variant:"outlined",startIcon:(0,K.jsx)(ge.A,{}),children:"Add Driver"})})]})]});case 3:return(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Store Manager Management"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",paragraph:!0,children:"This is a placeholder for store manager management. In a real implementation, you would be able to assign managers to the store."})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsxs)(te.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Store Managers"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,children:(0,K.jsx)(ue.A,{variant:"outlined",children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:"Sarah Williams"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: sarah.williams@example.com"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 234-5678"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Role: Store Manager"}),(0,K.jsx)(fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,children:(0,K.jsx)(ue.A,{variant:"outlined",children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",children:"Robert Brown"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: robert.brown@example.com"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 876-5432"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Role: Assistant Manager"}),(0,K.jsx)(fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})})]})]}),(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,K.jsx)(j.A,{variant:"outlined",startIcon:(0,K.jsx)(ge.A,{}),children:"Add Store Manager"})})]})]});case 4:return(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Review Store Information"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(te.A,{variant:"outlined",sx:{p:2},children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Details"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"body2",children:[(0,K.jsx)("strong",{children:"Name:"})," ",I.name]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"body2",children:[(0,K.jsx)("strong",{children:"Address:"})," ",I.address]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"body2",children:[(0,K.jsx)("strong",{children:"Manager User ID:"})," ",I.managerUserId]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"body2",children:[(0,K.jsx)("strong",{children:"Delivery Radius:"})," ",I.radius," km"]})})]}),(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Additional Information (Placeholder)"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"body2",children:[(0,K.jsx)("strong",{children:"Inventory Items:"})," 3 sample items"]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"body2",children:[(0,K.jsx)("strong",{children:"Drivers:"})," 3 sample drivers"]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"body2",children:[(0,K.jsx)("strong",{children:"Store Managers:"})," 2 sample managers"]})})]})]})})]});default:return null}})(b),(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",mt:4},children:[(0,K.jsx)(j.A,{disabled:0===b,onClick:()=>{f((e=>e-1))},children:"Back"}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",onClick:b===jr.length-1?()=>{if(!T())return void l("Please fill in all required fields");const e=I.pincodes,t=e?e.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],r={name:I.name,address:I.address,managerUserId:parseInt(I.managerUserId,10),radius:parseFloat(I.radius),email:I.email,mobile:I.mobile,description:I.description||null,storeDeliveryFee:I.storeDeliveryFee?parseFloat(I.storeDeliveryFee):null,taxPercentage:I.taxPercentage?parseFloat(I.taxPercentage):null,tnc:I.tnc||null,pincodes:t,is_active:!0,disabled:!1};L.mutate(r)}:()=>{0!==b||T()?f((e=>e+1)):l("Please fill in all required fields")},disabled:L.isLoading,children:L.isLoading?(0,K.jsx)(y.A,{size:24}):b===jr.length-1?"Submit":"Next"})]})]})]}),(0,K.jsxs)(Pe.A,{open:!!C,onClose:z,maxWidth:"md",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(Lt.A,{}),(0,K.jsx)(m.A,{variant:"h6",children:"Edit Store"})]})}),(0,K.jsxs)("form",{onSubmit:e=>{e.preventDefault();const t=new FormData(e.target),r=t.get("pincodes"),n=r?r.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],s={storeId:C.id,name:t.get("name"),address:t.get("address"),email:t.get("email"),mobile:t.get("mobile")||null,managerUserId:parseInt(t.get("managerUserId")),radius:parseFloat(t.get("radius")),isActive:"true"===t.get("isActive"),disabled:"true"===t.get("disabled"),description:t.get("description")||null,pincodes:n,tnc:t.get("tnc")||null,storeDeliveryFee:parseFloat(t.get("storeDeliveryFee"))||null,taxPercentage:parseFloat(t.get("taxPercentage"))||null};q.mutate(s)},children:[(0,K.jsx)(Fe.A,{children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"name",label:"Store Name",defaultValue:C?.name,required:!0,fullWidth:!0})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"email",label:"Email",type:"email",defaultValue:C?.email,required:!0,fullWidth:!0})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"mobile",label:"Mobile Number",defaultValue:C?.mobile,fullWidth:!0})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"managerUserId",label:"Manager User ID",type:"number",defaultValue:C?.managerUserId,required:!0,fullWidth:!0})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{name:"address",label:"Address",defaultValue:C?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:C?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:C?.storeDeliveryFee,fullWidth:!0,inputProps:{step:.01,min:0},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:"$"})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:C?.taxPercentage,fullWidth:!0,inputProps:{step:.1,min:0},InputProps:{endAdornment:(0,K.jsx)(g.A,{position:"end",children:"%"})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:C?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{name:"description",label:"Description",defaultValue:C?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{name:"tnc",label:"Terms & Conditions",defaultValue:C?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,children:[(0,K.jsx)(Zt.A,{children:"Store Status"}),(0,K.jsxs)(Xt.A,{name:"isActive",label:"Store Status",defaultValue:C?.isActive,children:[(0,K.jsx)(de.A,{value:!0,children:"Active"}),(0,K.jsx)(de.A,{value:!1,children:"Inactive"})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,children:[(0,K.jsx)(Zt.A,{children:"Disabled Status"}),(0,K.jsxs)(Xt.A,{name:"disabled",label:"Disabled Status",defaultValue:C?.disabled,children:[(0,K.jsx)(de.A,{value:!0,children:"Disabled"}),(0,K.jsx)(de.A,{value:!1,children:"Enabled"})]})]})})]})}),(0,K.jsxs)(er.A,{sx:{p:3,pt:0},children:[(0,K.jsx)(j.A,{onClick:z,children:"Cancel"}),(0,K.jsx)(j.A,{type:"submit",variant:"contained",disabled:q.isPending,startIcon:q.isPending?(0,K.jsx)(y.A,{size:20}):null,children:q.isPending?"Updating...":"Update Store"})]})]})]}),(0,K.jsx)(tr.A,{open:D.open,autoHideDuration:6e3,onClose:()=>F({...D,open:!1}),children:(0,K.jsx)(X.A,{onClose:()=>F({...D,open:!1}),severity:D.severity,sx:{width:"100%"},children:D.message})})]})};var gr=r(7110),yr=r(5068);const vr=()=>{const[e,t]=(0,x.useState)(""),[r,n]=(0,x.useState)(!1),[s,i]=(0,x.useState)(null),[a,l]=(0,x.useState)({name:"",description:"",categoryId:"",image:""}),[o,d]=(0,x.useState)(!1),[c,h]=(0,x.useState)(!1),[g,b]=(0,x.useState)(null),[f,I]=(0,x.useState)(!1),[S,C]=(0,x.useState)(""),[w,D]=(0,x.useState)(""),[F,k]=(0,x.useState)(0),[E,$]=(0,x.useState)(10),[W,q]=(0,x.useState)([]),[R,T]=(0,x.useState)(""),[z,U]=(0,x.useState)(!1),[B,O]=(0,x.useState)({open:!1,message:"",severity:"info"}),N=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",{data:M,refetch:_}=(0,u.I)({queryKey:["products",e],queryFn:()=>P(L),enabled:!1}),{data:V,refetch:Y}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await P("\n  query GetCategories {\n    categories {\n      id\n      name\n    }\n  }\n")).categories||[]}),G=(0,ir.n)({mutationFn:e=>P("\n  mutation CreateProduct($name: String!, $description: String!, $categoryId: Int!, $image: String) {\n    createProduct(name: $name, description: $description, categoryId: $categoryId, image: $image) {\n      id\n      name\n      description\n      categoryId\n      image\n    }\n  }\n",{name:e.name,description:e.description,categoryId:e.categoryId,image:e.image}),onSuccess:()=>{_(),re()}}),H=(0,ir.n)({mutationFn:e=>{let{id:t,data:r}=e;return P("\n  mutation UpdateProduct($id: ID!, $input: UpdateProductInput!) {\n    updateProduct(id: $id, input: $input) {\n      id\n      name\n      description\n      categoryId\n      image\n    }\n  }\n",{id:t,input:r})},onSuccess:()=>{_(),re()}}),Q=(0,ir.n)({mutationFn:e=>P("\n  mutation DeleteProduct($productId: Int!) {\n    deleteProduct(productId: $productId)\n  }\n",{productId:e}),onSuccess:()=>{_()}}),J=(0,ir.n)({mutationFn:e=>P("\n  mutation CreateCategory($name: String!) {\n    createCategory(name: $name) {\n      category {\n        id\n        name\n      }\n    }\n  }\n",{name:e}),onSuccess:()=>{I(!1),C(""),D(""),Y()},onError:e=>{D(e.message||"Failed to create category")}}),Z=(0,x.useMemo)((()=>V?V.reduce(((e,t)=>(e[t.id]=t.name,e)),{}):{}),[V]),ee=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(i(e),l({name:e.name,description:e.description,categoryId:e.categoryId,image:e.image})):(i(null),l({name:"",description:"",categoryId:"",image:""})),n(!0)},re=()=>{n(!1),i(null),l({name:"",description:"",categoryId:"",image:""})},ne=e=>{const{name:t,value:r}=e.target;"categoryId"!==t||"new"!==r?l((e=>({...e,[t]:r}))):I(!0)},se=()=>{S.trim()?J.mutate(S.trim()):D("Category name is required")},ie=(0,x.useMemo)((()=>e?W.filter((t=>t.categoryId===parseInt(e))):W),[W,e]),ae=(0,x.useMemo)((()=>{const e=F*E;return ie.slice(e,e+E)}),[ie,F,E]),oe=()=>{O((e=>({...e,open:!1})))};return(0,K.jsxs)(A.A,{children:[(0,K.jsxs)(te.A,{sx:{p:3,mb:3},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,K.jsx)(ge.A,{sx:{mr:1}}),(0,K.jsx)(m.A,{variant:"h5",children:"Product Management"})]}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,children:[(0,K.jsx)(Zt.A,{children:"Category"}),(0,K.jsxs)(Xt.A,{value:e,onChange:e=>t(e.target.value),label:"Category",children:[(0,K.jsx)(de.A,{value:"",children:"All Categories"}),Object.entries(Z).map((e=>{let[t,r]=e;return(0,K.jsx)(de.A,{value:t,children:r},t)}))]})]})}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,md:8,sx:{display:"flex",alignItems:"center",gap:2},children:[(0,K.jsx)(j.A,{variant:"contained",startIcon:(0,K.jsx)(cr.A,{}),onClick:()=>{h(!0),b(null),_().then((e=>{e.data?.products&&q(e.data.products),d(!0),h(!1)})).catch((e=>{b("Failed to load products. Please try again."),h(!1)}))},disabled:c,sx:{minWidth:150},children:c?(0,K.jsx)(y.A,{size:24}):"Fetch Products"}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(ge.A,{}),onClick:()=>ee(),children:"Add Product"})]})]}),g&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:3},children:g}),o?c?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,K.jsx)(y.A,{})}):(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)(Mt.A,{component:te.A,children:[(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"Image"}),(0,K.jsx)(Gt.A,{children:"Name"}),(0,K.jsx)(Gt.A,{children:"Category"}),(0,K.jsx)(Gt.A,{children:"Description"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:ae.map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:(0,K.jsx)("img",{src:e.image,alt:e.name,style:{width:"50px",height:"50px",objectFit:"cover"}})}),(0,K.jsx)(Gt.A,{children:e.name}),(0,K.jsx)(Gt.A,{children:Z[e.categoryId]||"Unknown"}),(0,K.jsx)(Gt.A,{children:e.description}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(le.A,{size:"small",onClick:()=>ee(e),children:(0,K.jsx)(rr.A,{})}),(0,K.jsx)(le.A,{size:"small",onClick:()=>(e=>{const t=W.find((t=>t.id===e));if(t?.inventoryItems?.edges?.length>0){if(!window.confirm("This product has inventory items. Deleting it will also remove all associated inventory items. Are you sure you want to proceed?"))return}else if(!window.confirm("Are you sure you want to delete this product?"))return;Q.mutate(parseInt(e,10))})(e.id),children:(0,K.jsx)(gr.A,{})})]})]},e.id)))})]}),(0,K.jsx)(v.A,{component:"div",count:ie.length,page:F,onPageChange:(e,t)=>{k(t)},rowsPerPage:E,onRowsPerPageChange:e=>{$(parseInt(e.target.value,10)),k(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,K.jsxs)(A.A,{sx:{textAlign:"center",py:4},children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Products" to load product information'}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,K.jsxs)(Pe.A,{open:r,onClose:re,maxWidth:"md",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:s?"Edit Product":"Add New Product"}),(0,K.jsx)(Fe.A,{children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Product Name",name:"name",value:a.name,onChange:ne})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,required:!0,children:[(0,K.jsx)(Zt.A,{children:"Category"}),(0,K.jsxs)(Xt.A,{name:"categoryId",value:a.categoryId,onChange:ne,label:"Category",children:[(0,K.jsx)(de.A,{value:"",children:(0,K.jsx)("em",{children:"Select a category"})}),Object.entries(Z).map((e=>{let[t,r]=e;return(0,K.jsx)(de.A,{value:t,children:r},t)})),(0,K.jsx)(de.A,{value:"new",sx:{borderTop:"1px solid #e0e0e0",mt:1},children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",color:"primary.main"},children:[(0,K.jsx)(ge.A,{sx:{mr:1}}),"Add New Category"]})})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,multiline:!0,rows:3,label:"Description",name:"description",value:a.description,onChange:ne})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(A.A,{sx:{display:"flex",flexDirection:"column",gap:1},children:[(0,K.jsx)(p.A,{fullWidth:!0,label:"Image URL",name:"image",value:a.image,onChange:ne,placeholder:"https://example.com/image.jpg",disabled:z,error:!!R,helperText:R}),(0,K.jsxs)(j.A,{variant:"outlined",component:"label",startIcon:(0,K.jsx)(yr.A,{}),disabled:z||!a.name||!a.categoryId,children:[z?"Uploading...":"Upload Image",(0,K.jsx)("input",{type:"file",hidden:!0,accept:"image/*",onChange:async e=>{const t=e.target.files[0];if(!t)return;if(["image/jpeg","image/png","image/gif","image/webp"].includes(t.type))if(t.size>5242880)T("Image size should be less than 5MB");else try{U(!0),T("");const e=Z[a.categoryId]||"uncategorized",r=await fetch(`${N}/s3/generate-product-upload-url?product_name=${encodeURIComponent(a.name)}&category_name=${encodeURIComponent(e)}&file_name=${encodeURIComponent(t.name)}`);if(!r.ok)throw new Error("Failed to get upload URL");const{upload_url:n,content_type:s,key:i}=await r.json();if(!(await fetch(n,{method:"PUT",headers:{"Content-Type":s},body:t})).ok)throw new Error("Failed to upload image");const o=`https://indimitra-dev-order-files.s3.amazonaws.com/${i}`;l((e=>({...e,image:o}))),O({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){T("Failed to upload image. Please try again."),O({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{U(!1)}else T("Please upload a valid image file (JPEG, PNG, GIF, or WebP)")},disabled:z})]}),a.image&&(0,K.jsx)(A.A,{sx:{mt:1},children:(0,K.jsx)("img",{src:a.image,alt:"Product preview",style:{maxWidth:"200px",maxHeight:"200px",objectFit:"contain"}})})]})})]})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:re,children:"Cancel"}),(0,K.jsx)(j.A,{variant:"contained",onClick:()=>{if(s)H.mutate({id:s.id,data:a});else{const e={name:a.name,description:a.description,categoryId:parseInt(a.categoryId,10),image:a.image||null};G.mutate(e)}},disabled:G.isLoading||H.isLoading,children:G.isLoading||H.isLoading?(0,K.jsx)(y.A,{size:24}):s?"Update":"Add"})]})]}),(0,K.jsxs)(Pe.A,{open:f,onClose:()=>I(!1),children:[(0,K.jsx)(De.A,{children:"Add New Category"}),(0,K.jsx)(Fe.A,{children:(0,K.jsx)(p.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:S,onChange:e=>C(e.target.value),error:!!w,helperText:w,onKeyPress:e=>{"Enter"===e.key&&se()}})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>I(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:se,variant:"contained",disabled:J.isLoading,children:J.isLoading?"Creating...":"Create"})]})]}),(0,K.jsx)(tr.A,{open:B.open,autoHideDuration:6e3,onClose:oe,anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,K.jsx)(X.A,{onClose:oe,severity:B.severity,sx:{width:"100%"},children:B.message})})]})};var br=r(5813),fr=r(8047),Ir=r(9966),Sr=r(4415),Cr=r(2653);const wr=[{value:"PENDING",label:"Pending",color:"warning"},{value:"ORDER_PLACED",label:"Order Placed",color:"info"},{value:"ACCEPTED",label:"Accepted",color:"primary"},{value:"READY_FOR_DELIVERY",label:"Ready for Delivery",color:"success"},{value:"SCHEDULED",label:"Scheduled",color:"info"},{value:"PICKED_UP",label:"Picked Up",color:"info"},{value:"DELIVERED",label:"Delivered",color:"success"},{value:"CANCELLED",label:"Cancelled",color:"error"}],Pr=()=>{const[e,t]=(0,x.useState)(""),[r,n]=(0,x.useState)(""),[s,i]=(0,x.useState)(!1),[a,l]=(0,x.useState)(null),[o,d]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null),[v,b]=(0,x.useState)(!1),[f,I]=(0,x.useState)(""),[S,C]=(0,x.useState)(""),[w,F]=(0,x.useState)(""),[k,$]=(0,x.useState)(""),{data:W,isLoading:L,refetch:q}=(0,u.I)({queryKey:["orders",r,e],queryFn:()=>P("\nquery GetAllOrders {\n  getAllOrders {\n    id\n    creator {\n      email\n      mobile\n    }\n    address { \n      id\n      address\n      isPrimary\n    }\n    status\n    storeId\n    totalAmount\n    deliveryDate\n    deliveryInstructions\n    orderItems {\n      edges {\n        node {\n          id\n          product {\n            id\n            name\n            description\n          }\n          quantity\n          orderAmount\n        }\n      }\n    }\n  }\n}\n"),enabled:o}),{data:R}=(0,u.I)({queryKey:["storeDrivers",a?.storeId],queryFn:async()=>a?.storeId?await P(E,{storeId:a.storeId}):null,enabled:!!a?.storeId}),T=(0,ir.n)({mutationFn:async e=>await P(D,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onSuccess:()=>{q(),b(!1),l(null),I(""),C(""),F(""),$("")},onError:e=>{h(e.message)}}),z=()=>{d(!0),q()},U=()=>{i(!1),l(null)},B=e=>{const{name:r,value:s}=e.target;"searchTerm"===r?t(s):"statusFilter"===r&&n(s)},O=e=>{switch(e){case"READY_FOR_DELIVERY":return"success";case"CANCELLED":return"error";case"PENDING":return"warning";default:return"default"}},N=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,K.jsx)(br.A,{});case"CANCELLED":return(0,K.jsx)(fr.A,{});case"PENDING":return(0,K.jsx)(Ir.A,{});default:return null}},M=e=>{if(!e)return"Not scheduled";return new Date(e).toLocaleString()},_=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e),V=W?.getAllOrders?.filter((t=>{const n=""===e||t.address?.address.toLowerCase().includes(e.toLowerCase())||t.id.toString().includes(e),s=""===r||t.status===r;return n&&s}));return(0,K.jsxs)(A.A,{children:[(0,K.jsxs)(te.A,{sx:{p:3,mb:3},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,K.jsx)(Sr.A,{sx:{mr:1}}),(0,K.jsx)(m.A,{variant:"h5",children:"Orders Management"})]}),c&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:3},children:c}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsx)(p.A,{fullWidth:!0,placeholder:"Search by address or order ID",name:"searchTerm",value:e,onChange:B,InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(sr.A,{})})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,children:[(0,K.jsx)(Zt.A,{children:"Status"}),(0,K.jsxs)(Xt.A,{name:"statusFilter",value:r,onChange:B,label:"Status",children:[(0,K.jsx)(de.A,{value:"",children:"All Status"}),(0,K.jsx)(de.A,{value:"PENDING",children:"Pending"}),(0,K.jsx)(de.A,{value:"ACCEPTED",children:"Accepted"}),(0,K.jsx)(de.A,{value:"READY_FOR_DELIVERY",children:"Ready for Delivery"}),(0,K.jsx)(de.A,{value:"PICKED_UP",children:"Picked Up"}),(0,K.jsx)(de.A,{value:"DELIVERED",children:"Delivered"}),(0,K.jsx)(de.A,{value:"CANCELLED",children:"Cancelled"})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(cr.A,{}),onClick:z,fullWidth:!0,sx:{height:"56px"},children:"Fetch Orders"})})]}),o?L?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,K.jsx)(y.A,{})}):0===V?.length?(0,K.jsx)(X.A,{severity:"info",sx:{mb:3},children:"No orders found matching your criteria"}):(0,K.jsx)(Mt.A,{children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"Order ID"}),(0,K.jsx)(Gt.A,{children:"Address"}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{children:"Total Amount"}),(0,K.jsx)(Gt.A,{children:"Delivery Date"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:V.map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsxs)(Gt.A,{children:["#",e.id]}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(m.A,{variant:"body2",children:e.address?.address||"N/A"})}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{icon:N(e.status),label:e.status.replace(/_/g," "),color:O(e.status),size:"small"})}),(0,K.jsx)(Gt.A,{children:_(e.totalAmount)}),(0,K.jsx)(Gt.A,{children:M(e.deliveryDate)}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(le.A,{size:"small",onClick:()=>(e=>{l(e),i(!0)})(e),children:(0,K.jsx)(Cr.A,{})}),(0,K.jsx)(le.A,{size:"small",onClick:()=>(e=>{l(e),I(e.status),C(e.deliveryInstructions||""),b(!0)})(e),disabled:"CANCELLED"===e.status||"DELIVERED"===e.status,children:(0,K.jsx)(rr.A,{})})]})]},e.id)))})]})}):(0,K.jsxs)(ue.A,{sx:{mb:3},children:[(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Orders" to load order data'}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]}),(0,K.jsx)(Ae.A,{sx:{justifyContent:"center"},children:(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(cr.A,{}),onClick:z,children:"Fetch Orders"})})]})]}),(0,K.jsxs)(Pe.A,{open:s,onClose:U,maxWidth:"md",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:"Order Details"}),(0,K.jsx)(Fe.A,{children:a&&(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsxs)(m.A,{variant:"h6",gutterBottom:!0,children:["Order #",a.id]}),(0,K.jsx)(fe.A,{icon:N(a.status),label:a.status.replace(/_/g," "),color:O(a.status),sx:{mb:2}})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Information"}),(0,K.jsxs)(m.A,{variant:"body2",children:["Address: ",a.address?.address||"N/A"]}),(0,K.jsxs)(m.A,{variant:"body2",children:["Total Amount: ",_(a.totalAmount)]}),(0,K.jsxs)(m.A,{variant:"body2",children:["Delivery Date: ",M(a.deliveryDate)]}),a.deliveryInstructions&&(0,K.jsxs)(m.A,{variant:"body2",children:["Delivery Instructions: ",a.deliveryInstructions]})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Items"}),(0,K.jsx)(Mt.A,{children:(0,K.jsxs)(_t.A,{size:"small",children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"Product"}),(0,K.jsx)(Gt.A,{children:"Quantity"}),(0,K.jsx)(Gt.A,{children:"Amount"})]})}),(0,K.jsx)(Kt.A,{children:a.orderItems?.edges?.map((e=>{let{node:t}=e;return(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:t.product?.name||"N/A"}),(0,K.jsx)(Gt.A,{children:t.quantity}),(0,K.jsx)(Gt.A,{children:_(t.orderAmount)})]},t.id)}))})]})})]})]})}),(0,K.jsx)(er.A,{children:(0,K.jsx)(j.A,{onClick:U,children:"Close"})})]}),(0,K.jsxs)(Pe.A,{open:v,onClose:()=>b(!1),maxWidth:"sm",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:"Update Order Status"}),(0,K.jsx)(Fe.A,{children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{select:!0,fullWidth:!0,label:"Status",value:f,onChange:e=>I(e.target.value),children:wr.map((e=>(0,K.jsx)(de.A,{value:e.value,children:e.label},e.value)))})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Delivery Instructions",value:S,onChange:e=>C(e.target.value),multiline:!0,rows:3})}),("READY"===f||"READY_FOR_DELIVERY"===f)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,required:!0,children:[(0,K.jsx)(Zt.A,{children:"Delivery Agent"}),(0,K.jsx)(Xt.A,{value:w,onChange:e=>F(e.target.value),label:"Delivery Agent",children:R?.getStoreDrivers?.map((e=>(0,K.jsxs)(de.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId)))})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Schedule Time",value:k,onChange:e=>$(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>b(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:async()=>{try{const e={orderId:a.id,status:f,deliveryInstructions:S};if("READY"===f||"READY_FOR_DELIVERY"===f){if(!w)return void h("Driver ID is required for this status");if(!k)return void h("Schedule time is required for this status");e.driverId=parseInt(w),e.scheduleTime=k}await T.mutateAsync(e)}catch(e){h(e.message)}},variant:"contained",color:"primary",disabled:T.isLoading,children:T.isLoading?"Updating...":"Update"})]})]})]})},Dr=["Store Selection","Payment Method","Account Details","Documents","Review"],Fr=()=>{const[e,t]=(0,x.useState)(""),[r,n]=(0,x.useState)(""),[s,i]=(0,x.useState)(!1),[a,l]=(0,x.useState)(null),[o,d]=(0,x.useState)(0),[c,h]=(0,x.useState)({storeId:"",paymentMethod:"",accountDetails:{accountName:"",accountNumber:"",bankName:"",ifscCode:"",routingNumber:"",swiftCode:""},documents:[]}),[v,b]=(0,x.useState)(null),[f,I]=(0,x.useState)(!1),{data:S,isLoading:C,refetch:w,error:D}=(0,u.I)({queryKey:["paymentOnboarding",r,e],queryFn:()=>P("\n  query GetPaymentOnboarding($status: String, $searchTerm: String) {\n    paymentOnboarding(status: $status, searchTerm: $searchTerm) {\n      id\n      store {\n        id\n        name\n      }\n      status\n      paymentMethod\n      accountDetails\n      documents\n      createdAt\n      updatedAt\n    }\n  }\n",{status:r||null,searchTerm:e||null})}),{data:F}=(0,u.I)({queryKey:["stores"],queryFn:()=>P("\n  query GetStores {\n    stores {\n      id\n      name\n    }\n  }\n")}),k=(0,ir.n)({mutationFn:e=>P("\n  mutation CreatePaymentOnboarding($input: CreatePaymentOnboardingInput!) {\n    createPaymentOnboarding(input: $input) {\n      id\n      store {\n        id\n        name\n      }\n      status\n      paymentMethod\n      accountDetails\n      documents\n    }\n  }\n",{input:e}),onSuccess:()=>{w(),L(),I(!0),setTimeout((()=>I(!1)),3e3)},onError:e=>{b(e.message||"Failed to create payment onboarding"),setTimeout((()=>b(null)),3e3)}}),E=(0,ir.n)({mutationFn:e=>{let{id:t,data:r}=e;return P("\n  mutation UpdatePaymentOnboarding($id: ID!, $input: UpdatePaymentOnboardingInput!) {\n    updatePaymentOnboarding(id: $id, input: $input) {\n      id\n      store {\n        id\n        name\n      }\n      status\n      paymentMethod\n      accountDetails\n      documents\n    }\n  }\n",{id:t,input:r})},onSuccess:()=>{w(),L(),I(!0),setTimeout((()=>I(!1)),3e3)},onError:e=>{b(e.message||"Failed to update payment onboarding"),setTimeout((()=>b(null)),3e3)}}),$=(0,ir.n)({mutationFn:e=>P("\n  mutation DeletePaymentOnboarding($id: ID!) {\n    deletePaymentOnboarding(id: $id)\n  }\n",{id:e}),onSuccess:()=>{w(),I(!0),setTimeout((()=>I(!1)),3e3)},onError:e=>{b(e.message||"Failed to delete payment onboarding"),setTimeout((()=>b(null)),3e3)}}),W=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(l(e),h({storeId:e.store.id,paymentMethod:e.paymentMethod,accountDetails:e.accountDetails||{accountName:"",accountNumber:"",bankName:"",ifscCode:"",routingNumber:"",swiftCode:""},documents:e.documents||[]})):(l(null),h({storeId:"",paymentMethod:"",accountDetails:{accountName:"",accountNumber:"",bankName:"",ifscCode:"",routingNumber:"",swiftCode:""},documents:[]})),d(0),i(!0)},L=()=>{i(!1),l(null),d(0),h({storeId:"",paymentMethod:"",accountDetails:{accountName:"",accountNumber:"",bankName:"",ifscCode:"",routingNumber:"",swiftCode:""},documents:[]})},q=e=>{const{name:t,value:r}=e.target;if(t.startsWith("accountDetails.")){const e=t.split(".")[1];h((t=>({...t,accountDetails:{...t.accountDetails,[e]:r}})))}else h((e=>({...e,[t]:r})))},R=e=>{switch(e){case"APPROVED":return"success";case"REJECTED":return"error";case"PENDING":return"warning";default:return"default"}},T=e=>{switch(e){case"APPROVED":return(0,K.jsx)(CheckCircleIcon,{});case"REJECTED":return(0,K.jsx)(ErrorIcon,{});case"PENDING":return(0,K.jsx)(PendingIcon,{});default:return null}},z=e=>new Date(e).toLocaleString();return(0,K.jsxs)(A.A,{children:[(0,K.jsxs)(te.A,{sx:{p:3,mb:3},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,K.jsx)(zt.A,{sx:{mr:1}}),(0,K.jsx)(m.A,{variant:"h5",children:"Payment Onboarding"})]}),v&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:3},children:v}),f&&(0,K.jsx)(X.A,{severity:"success",sx:{mb:3},children:a?"Payment onboarding updated successfully!":"Payment onboarding created successfully!"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,placeholder:"Search by store name",value:e,onChange:e=>t(e.target.value),InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(sr.A,{})})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,children:[(0,K.jsx)(Zt.A,{children:"Status"}),(0,K.jsxs)(Xt.A,{value:r,onChange:e=>n(e.target.value),label:"Status",children:[(0,K.jsx)(de.A,{value:"",children:"All Status"}),(0,K.jsx)(de.A,{value:"APPROVED",children:"Approved"}),(0,K.jsx)(de.A,{value:"PENDING",children:"Pending"}),(0,K.jsx)(de.A,{value:"REJECTED",children:"Rejected"})]})]})})]}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(ge.A,{}),onClick:()=>W(),sx:{mb:3},disabled:!0,children:"Add Payment Onboarding"}),(0,K.jsx)(Mt.A,{children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"Store"}),(0,K.jsx)(Gt.A,{children:"Payment Method"}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{children:"Created At"}),(0,K.jsx)(Gt.A,{children:"Updated At"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:D?(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:6,align:"center",children:(0,K.jsx)(m.A,{color:"error",children:"Error fetching payment onboarding"})})}):C?(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:6,align:"center",children:(0,K.jsx)(y.A,{})})}):0===S?.paymentOnboarding.length?(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:6,align:"center",children:"No payment onboarding found"})}):S?.paymentOnboarding.map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e.store.name}),(0,K.jsx)(Gt.A,{children:e.paymentMethod}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{icon:T(e.status),label:e.status,color:R(e.status),size:"small"})}),(0,K.jsx)(Gt.A,{children:z(e.createdAt)}),(0,K.jsx)(Gt.A,{children:z(e.updatedAt)}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(le.A,{size:"small",onClick:()=>W(e),children:(0,K.jsx)(rr.A,{})}),(0,K.jsx)(le.A,{size:"small",onClick:()=>{return t=e.id,void(window.confirm("Are you sure you want to delete this payment onboarding?")&&$.mutate(t));var t},children:(0,K.jsx)(DeleteIcon,{})})]})]},e.id)))})]})})]}),(0,K.jsxs)(Pe.A,{open:s,onClose:L,maxWidth:"md",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:a?"Edit Payment Onboarding":"Add New Payment Onboarding"}),(0,K.jsxs)(Fe.A,{children:[(0,K.jsx)(lr.A,{activeStep:o,sx:{my:3},children:Dr.map((e=>(0,K.jsx)(or.A,{children:(0,K.jsx)(dr.A,{children:e})},e)))}),(0,K.jsx)(Pt.A,{sx:{mb:3}}),(e=>{switch(e){case 0:return(0,K.jsx)(xe.Ay,{container:!0,spacing:2,children:(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Select Store"}),(0,K.jsxs)(Jt.A,{fullWidth:!0,required:!0,children:[(0,K.jsx)(Zt.A,{children:"Store"}),(0,K.jsx)(Xt.A,{name:"storeId",value:c.storeId,onChange:q,label:"Store",children:F?.stores.map((e=>(0,K.jsx)(de.A,{value:e.id,children:e.name},e.id)))})]})]})});case 1:return(0,K.jsx)(xe.Ay,{container:!0,spacing:2,children:(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Payment Method"}),(0,K.jsxs)(Jt.A,{fullWidth:!0,required:!0,children:[(0,K.jsx)(Zt.A,{children:"Payment Method"}),(0,K.jsxs)(Xt.A,{name:"paymentMethod",value:c.paymentMethod,onChange:q,label:"Payment Method",children:[(0,K.jsx)(de.A,{value:"BANK_TRANSFER",children:"Bank Transfer"}),(0,K.jsx)(de.A,{value:"UPI",children:"UPI"}),(0,K.jsx)(de.A,{value:"PAYPAL",children:"PayPal"}),(0,K.jsx)(de.A,{value:"STRIPE",children:"Stripe"})]})]})]})});case 2:return(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Account Details"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Account Name",name:"accountDetails.accountName",value:c.accountDetails.accountName,onChange:q})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Account Number",name:"accountDetails.accountNumber",value:c.accountDetails.accountNumber,onChange:q})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{required:!0,fullWidth:!0,label:"Bank Name",name:"accountDetails.bankName",value:c.accountDetails.bankName,onChange:q})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"IFSC Code",name:"accountDetails.ifscCode",value:c.accountDetails.ifscCode,onChange:q})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Routing Number",name:"accountDetails.routingNumber",value:c.accountDetails.routingNumber,onChange:q})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"SWIFT Code",name:"accountDetails.swiftCode",value:c.accountDetails.swiftCode,onChange:q})})]});case 3:return(0,K.jsx)(xe.Ay,{container:!0,spacing:2,children:(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Documents"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",paragraph:!0,children:"Upload relevant documents for payment verification. This step is optional."}),(0,K.jsxs)(j.A,{variant:"outlined",component:"label",children:["Upload Documents",(0,K.jsx)("input",{type:"file",hidden:!0,multiple:!0,onChange:e=>{const t=Array.from(e.target.files).map((e=>e.name));h((e=>({...e,documents:[...e.documents,...t]})))}})]}),c.documents.length>0&&(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)(m.A,{variant:"subtitle2",children:"Uploaded Documents:"}),(0,K.jsx)("ul",{children:c.documents.map(((e,t)=>(0,K.jsx)("li",{children:e},t)))})]})]})});case 4:return(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Review Information"})}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"subtitle1",children:"Store"}),(0,K.jsx)(m.A,{children:F?.stores.find((e=>e.id===c.storeId))?.name})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"subtitle1",children:"Payment Method"}),(0,K.jsx)(m.A,{children:c.paymentMethod})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"subtitle1",children:"Account Details"}),(0,K.jsxs)(m.A,{children:["Account Name: ",c.accountDetails.accountName]}),(0,K.jsxs)(m.A,{children:["Account Number: ",c.accountDetails.accountNumber]}),(0,K.jsxs)(m.A,{children:["Bank Name: ",c.accountDetails.bankName]}),c.accountDetails.ifscCode&&(0,K.jsxs)(m.A,{children:["IFSC Code: ",c.accountDetails.ifscCode]}),c.accountDetails.routingNumber&&(0,K.jsxs)(m.A,{children:["Routing Number: ",c.accountDetails.routingNumber]}),c.accountDetails.swiftCode&&(0,K.jsxs)(m.A,{children:["SWIFT Code: ",c.accountDetails.swiftCode]})]}),c.documents.length>0&&(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"subtitle1",children:"Documents"}),(0,K.jsx)("ul",{children:c.documents.map(((e,t)=>(0,K.jsx)("li",{children:e},t)))})]})]});default:return null}})(o)]}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:L,children:"Cancel"}),(0,K.jsx)(j.A,{disabled:0===o,onClick:()=>{d((e=>e-1))},sx:{mr:1},children:"Back"}),o===Dr.length-1?(0,K.jsx)(j.A,{variant:"contained",onClick:()=>{const e={...c,status:"PENDING"};a?E.mutate({id:a.id,data:e}):k.mutate(e)},disabled:k.isLoading||E.isLoading,children:k.isLoading||E.isLoading?(0,K.jsx)(y.A,{size:24}):a?"Update":"Submit"}):(0,K.jsx)(j.A,{variant:"contained",onClick:()=>{d((e=>e+1))},children:"Next"})]})]})]})},kr=e=>{let{title:t,value:r,icon:n,color:s}=e;const i=(0,be.A)(),a=(0,Me.A)(i.breakpoints.down("sm"));return(0,K.jsx)(ue.A,{sx:{height:"100%"},children:(0,K.jsxs)(he.A,{children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,K.jsx)(A.A,{sx:{backgroundColor:`${s}15`,borderRadius:"50%",p:1,mr:2,display:"flex",alignItems:"center",justifyContent:"center"},children:x.cloneElement(n,{sx:{color:s}})}),(0,K.jsx)(m.A,{variant:"h6",color:"text.secondary",children:t})]}),(0,K.jsx)(m.A,{variant:a?"h5":"h4",component:"div",sx:{fontWeight:"bold"},children:r})]})})},Er=()=>{const e=(0,be.A)(),t=(0,Me.A)(e.breakpoints.down("sm")),r="1,234",n="56",s="89",i="2,345";return(0,K.jsxs)(A.A,{sx:{p:t?2:3},children:[(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,sx:{mb:4},children:"Dashboard Overview"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,K.jsx)(kr,{title:"Total Users",value:r,icon:(0,K.jsx)(Tt.A,{}),color:e.palette.primary.main})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,K.jsx)(kr,{title:"Total Stores",value:n,icon:(0,K.jsx)(Lt.A,{}),color:e.palette.success.main})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,K.jsx)(kr,{title:"Active Drivers",value:s,icon:(0,K.jsx)(nr.A,{}),color:e.palette.info.main})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,K.jsx)(kr,{title:"Total Orders",value:i,icon:(0,K.jsx)(ye.A,{}),color:e.palette.warning.main})})]})]})};var $r=r(7558),Wr=r(1275),Lr=r(8116),qr=r(8708),Rr=r(181);const Tr=()=>{const[e,t]=(0,x.useState)(0),[r,n]=(0,x.useState)(10),[s,i]=(0,x.useState)(""),[a,l]=(0,x.useState)(""),[o,d]=(0,x.useState)(null),[c,h]=(0,x.useState)(!1),[b,f]=(0,x.useState)(!1),[I,S]=(0,x.useState)(!1),[C,w]=(0,x.useState)(""),[D,F]=(0,x.useState)(""),[k,E]=(0,x.useState)(!0),[$,q]=(0,x.useState)(!0),[R,T]=(0,x.useState)({open:!1,message:"",severity:"success"}),[z,U]=(0,x.useState)("table"),[B,O]=(0,x.useState)(null),[N,M]=(0,x.useState)(""),[_,V]=(0,x.useState)(!1),[Y,G]=(0,x.useState)({price:"",quantity:"",measurement:"",unit:""}),H=(0,x.useRef)(null),{data:Q,isLoading:J,error:Z,refetch:ee}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{const e=await P(W);return e?.stores||[]},enabled:!0}),{data:re,isLoading:ne}=(0,u.I)({queryKey:["products"],queryFn:async()=>{const e=await P(L);return e?.products||[]},enabled:I}),{data:se,isLoading:ie,error:ae,refetch:oe}=(0,u.I)({queryKey:["storeInventory",a],queryFn:async()=>{if(!a)return[];const e=await P("\n  query GetInventoryByStore($storeId: Int!) {\n    getInventoryByStore(storeId: $storeId) {\n      id\n      quantity\n      price\n      updatedAt\n      isAvailable\n      isListed\n      product {\n        id\n        name\n        description\n        category {\n          id\n          name\n        }\n        image\n      }\n    }\n  }\n",{storeId:parseInt(a)});return e?.getInventoryByStore||[]},enabled:!!a}),ce=(0,ir.n)({mutationFn:e=>P("\n  mutation UpdateInventoryItem(\n    $inventoryId: Int!\n    $price: Float\n    $quantity: Int\n    $isAvailable: Boolean\n    $isListed: Boolean\n  ) {\n    updateInventoryItem(\n      inventoryId: $inventoryId\n      price: $price\n      quantity: $quantity\n      isAvailable: $isAvailable\n      isListed: $isListed\n    ) {\n      id\n      isAvailable\n      isListed\n      measurement\n      price\n      productId\n      quantity\n      storeId\n      unit\n      updatedAt\n    }\n  }\n",e),onSuccess:()=>{T({open:!0,message:"Inventory item updated successfully",severity:"success"}),oe(),h(!1)},onError:e=>{T({open:!0,message:`Error updating inventory: ${e.message}`,severity:"error"})}}),Ae=(0,ir.n)({mutationFn:e=>P("\n  mutation AddProductToInventory(\n    $productId: Int!\n    $storeId: Int!\n    $price: Float!\n    $quantity: Int!\n    $measurement: Int\n    $unit: String\n  ) {\n    addProductToInventory(\n      productId: $productId\n      storeId: $storeId\n      price: $price\n      quantity: $quantity\n      measurement: $measurement\n      unit: $unit\n    ) {\n      id\n      measurement\n      price\n      productId\n      quantity\n      storeId\n      unit\n    }\n  }\n",e),onSuccess:()=>{T({open:!0,message:"Product added to inventory successfully",severity:"success"}),oe(),S(!1),be()},onError:e=>{T({open:!0,message:`Error adding product to inventory: ${e.message}`,severity:"error"})}}),je=e=>{d(e),w(e.quantity.toString()),F(e.price.toString()),E(e.isAvailable),q(e.isListed),h(!0)},pe=e=>{d(e),f(!0)},ye=()=>{T({...R,open:!1})},ve=()=>{S(!1),be()},be=()=>{O(null),M(""),G({price:"",quantity:"",measurement:"",unit:""})},Ie=e=>{const{name:t,value:r}=e.target;G((e=>({...e,[t]:r})))},Se=()=>se?se.filter((e=>e.product.name.toLowerCase().includes(s.toLowerCase()))):[],Ce=re?.filter((e=>e.name.toLowerCase().includes(N.toLowerCase())))||[];return(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Inventory Management"}),(0,K.jsxs)(te.A,{sx:{p:3,mb:3},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",mb:3,flexWrap:"wrap",gap:2},children:[(0,K.jsxs)(Jt.A,{sx:{minWidth:200},children:[(0,K.jsx)(Zt.A,{children:"Select Store"}),(0,K.jsxs)(Xt.A,{value:a,onChange:e=>{l(e.target.value),t(0)},label:"Select Store",children:[(0,K.jsx)(de.A,{value:"",children:(0,K.jsx)("em",{children:"All Stores"})}),Q?.map((e=>(0,K.jsx)(de.A,{value:e.id,children:e.name},e.id)))]})]}),(0,K.jsx)(p.A,{placeholder:"Search products...",value:s,onChange:e=>{i(e.target.value),t(0)},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(sr.A,{})})},sx:{width:300}}),(0,K.jsx)(j.A,{variant:"outlined",startIcon:"table"===z?(0,K.jsx)(qr.A,{}):(0,K.jsx)(Rr.A,{}),onClick:()=>{U("table"===z?"grid":"table")},children:"table"===z?"Grid View":"Table View"}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(ge.A,{}),onClick:()=>{a?S(!0):T({open:!0,message:"Please select a store first",severity:"warning"})},disabled:!a,children:"Add Product"})]}),Z&&(0,K.jsxs)(X.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",Z.message]}),ae&&(0,K.jsxs)(X.A,{severity:"error",sx:{mb:3},children:["Error loading inventory: ",ae.message]}),J||a&&ie?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,K.jsx)(y.A,{})}):(0,K.jsxs)(K.Fragment,{children:["table"===z?(0,K.jsx)(Mt.A,{children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"Product"}),(0,K.jsx)(Gt.A,{children:"Category"}),(0,K.jsx)(Gt.A,{children:"Available"}),(0,K.jsx)(Gt.A,{children:"Listed"}),(0,K.jsx)(Gt.A,{children:"Price"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:Se().slice(e*r,e*r+r).map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[e.product.image&&(0,K.jsx)(A.A,{component:"img",src:e.product.image,alt:e.product.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"body1",children:e.product.name}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:e.product.description})]})]})}),(0,K.jsx)(Gt.A,{children:e.product.category?.name||"N/A"}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:e.isAvailable?"Available":"Not Available",color:e.isAvailable?"success":"error",size:"small"})}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:e.isListed?"Listed":"Not Listed",color:e.isListed?"success":"error",size:"small"})}),(0,K.jsxs)(Gt.A,{children:["$",e.price.toFixed(2)]}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(le.A,{size:"small",color:"primary",onClick:()=>je(e),children:(0,K.jsx)(rr.A,{})}),(0,K.jsx)(le.A,{size:"small",color:"error",onClick:()=>pe(e),children:(0,K.jsx)(gr.A,{})})]})]},e.id)))})]})}):(0,K.jsx)(xe.Ay,{container:!0,spacing:3,children:Se().slice(e*r,e*r+r).map((e=>(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,K.jsxs)(ue.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,K.jsx)(me.A,{component:"img",height:"140",image:e.product.image||"https://via.placeholder.com/140",alt:e.product.name}),(0,K.jsxs)(he.A,{sx:{flexGrow:1},children:[(0,K.jsx)(m.A,{gutterBottom:!0,variant:"h6",component:"div",noWrap:!0,children:e.product.name}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1},children:e.product.category?.name||"N/A"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1},noWrap:!0,children:e.product.description}),(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:2},children:[(0,K.jsx)(fe.A,{label:`Qty: ${e.quantity}`,color:e.quantity<10?"error":"success",size:"small"}),(0,K.jsxs)(m.A,{variant:"h6",color:"primary",children:["₹",e.price.toFixed(2)]})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",mt:2},children:[(0,K.jsx)(j.A,{size:"small",startIcon:(0,K.jsx)(rr.A,{}),onClick:()=>je(e),children:"Edit"}),(0,K.jsx)(j.A,{size:"small",color:"error",startIcon:(0,K.jsx)(gr.A,{}),onClick:()=>pe(e),children:"Delete"})]})]})]})},e.id)))}),(0,K.jsx)(v.A,{component:"div",count:Se().length,page:e,onPageChange:(e,r)=>{t(r)},rowsPerPage:r,onRowsPerPageChange:e=>{n(parseInt(e.target.value,10)),t(0)},sx:{mt:2}})]})]}),(0,K.jsxs)(Pe.A,{open:c,onClose:()=>h(!1),fullWidth:!0,maxWidth:"sm",children:[(0,K.jsx)(De.A,{children:"Edit Inventory Item"}),(0,K.jsx)(Fe.A,{children:o&&(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[o.product.image&&(0,K.jsx)(A.A,{component:"img",src:o.product.image,alt:o.product.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle1",children:o.product.name}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:o.product.category?.name||"N/A"})]})]}),(0,K.jsx)(p.A,{label:"Quantity",type:"number",fullWidth:!0,value:C,onChange:e=>w(e.target.value),sx:{mb:2}}),(0,K.jsx)(p.A,{label:"Price ($)",type:"number",fullWidth:!0,value:D,onChange:e=>F(e.target.value),sx:{mb:2}}),(0,K.jsxs)(Jt.A,{fullWidth:!0,sx:{mb:2},children:[(0,K.jsx)(Zt.A,{children:"Availability"}),(0,K.jsxs)(Xt.A,{value:k,onChange:e=>E(e.target.value),label:"Availability",children:[(0,K.jsx)(de.A,{value:!0,children:"Available"}),(0,K.jsx)(de.A,{value:!1,children:"Not Available"})]})]}),(0,K.jsxs)(Jt.A,{fullWidth:!0,sx:{mb:2},children:[(0,K.jsx)(Zt.A,{children:"Listing Status"}),(0,K.jsxs)(Xt.A,{value:$,onChange:e=>q(e.target.value),label:"Listing Status",children:[(0,K.jsx)(de.A,{value:!0,children:"Listed"}),(0,K.jsx)(de.A,{value:!1,children:"Not Listed"})]})]})]})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>h(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:()=>{o&&ce.mutate({inventoryId:o.id,price:parseFloat(D),quantity:parseInt(C),isAvailable:k,isListed:$})},variant:"contained",color:"primary",disabled:ce.isPending,children:ce.isPending?"Updating...":"Update"})]})]}),(0,K.jsxs)(Pe.A,{open:b,onClose:()=>f(!1),fullWidth:!0,maxWidth:"sm",children:[(0,K.jsx)(De.A,{children:"Delete Inventory Item"}),(0,K.jsx)(Fe.A,{children:o&&(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[o.product.image&&(0,K.jsx)(A.A,{component:"img",src:o.product.image,alt:o.product.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle1",children:o.product.name}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:o.product.category?.name||"N/A"})]})]}),(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Are you sure you want to delete this inventory item?"}),(0,K.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Quantity: ",o.quantity]}),(0,K.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Price: ₹",o.price.toFixed(2)]})]})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>f(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:()=>{f(!1),T({open:!0,message:"Delete functionality not implemented yet",severity:"info"})},variant:"contained",color:"error",children:"Delete"})]})]}),(0,K.jsxs)(Pe.A,{open:I,onClose:ve,fullWidth:!0,maxWidth:"md",children:[(0,K.jsx)(De.A,{children:"Add Product to Inventory"}),(0,K.jsx)(Fe.A,{children:(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Select a product to add to the store's inventory"}),(0,K.jsxs)(Jt.A,{fullWidth:!0,sx:{mt:2,mb:3},children:[(0,K.jsx)(p.A,{ref:H,label:"Search Product",placeholder:"Start typing to search...",value:N,onChange:e=>{M(e.target.value),V(!0)},onFocus:()=>V(!0),onClick:()=>V(!0),fullWidth:!0,InputProps:{endAdornment:ne?(0,K.jsx)(y.A,{color:"inherit",size:20}):null}}),(0,K.jsx)($r.A,{open:_&&Ce.length>0,anchorEl:H.current,placement:"bottom-start",style:{width:H.current?.offsetWidth,zIndex:1300},children:(0,K.jsx)(Wr.x,{onClickAway:()=>{V(!1)},children:(0,K.jsx)(te.A,{elevation:3,children:(0,K.jsx)(Lr.A,{sx:{maxHeight:300,overflow:"auto"},children:Ce.map((e=>(0,K.jsx)(de.A,{onClick:()=>(e=>{O(e),M(e.name),V(!1)})(e),selected:B?.id===e.id,children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[e.image&&(0,K.jsx)(A.A,{component:"img",src:e.image,alt:e.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"body1",children:e.name}),(0,K.jsx)(m.A,{variant:"caption",color:"textSecondary",children:e.categoryId?`Category ID: ${e.categoryId}`:"No category"})]})]})},e.id)))})})})})]}),B&&(0,K.jsxs)(A.A,{sx:{mb:3,p:2,bgcolor:"background.paper",borderRadius:1},children:[(0,K.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,children:"Selected Product:"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[B.image&&(0,K.jsx)(A.A,{component:"img",src:B.image,alt:B.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"body1",children:B.name}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:B.description})]})]})]}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,children:(0,K.jsx)(p.A,{label:"Price ($)",type:"number",name:"price",fullWidth:!0,value:Y.price,onChange:Ie,required:!0,inputProps:{min:0,step:.01}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,children:(0,K.jsx)(p.A,{label:"Quantity",type:"number",name:"quantity",fullWidth:!0,value:Y.quantity,onChange:Ie,required:!0,inputProps:{min:0}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,children:(0,K.jsx)(p.A,{label:"Measurement (optional)",type:"number",name:"measurement",fullWidth:!0,value:Y.measurement,onChange:Ie,inputProps:{min:0,step:.01}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,children:(0,K.jsx)(p.A,{label:"Unit (optional)",name:"unit",fullWidth:!0,value:Y.unit,onChange:Ie,placeholder:"e.g., kg, g, L, ml"})})]})]})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:ve,children:"Cancel"}),(0,K.jsx)(j.A,{onClick:()=>{B?Y.price&&Y.quantity?Ae.mutate({productId:B.id,storeId:parseInt(a),price:parseFloat(Y.price),quantity:parseInt(Y.quantity),measurement:Y.measurement?parseInt(Y.measurement):null,unit:Y.unit||""}):T({open:!0,message:"Please fill in all required fields",severity:"warning"}):T({open:!0,message:"Please select a product",severity:"warning"})},variant:"contained",color:"primary",disabled:Ae.isPending||!B,children:Ae.isPending?"Adding...":"Add to Inventory"})]})]}),(0,K.jsx)(tr.A,{open:R.open,autoHideDuration:6e3,onClose:ye,message:R.message,children:(0,K.jsx)(X.A,{onClose:ye,severity:R.severity,children:R.message})})]})},zr=()=>{const[e,t]=(0,x.useState)(0),[r,n]=(0,x.useState)(10),[s,i]=(0,x.useState)(!1),[a,l]=(0,x.useState)(null),[o,d]=(0,x.useState)(""),[c,h]=(0,x.useState)(null),[g,b]=(0,x.useState)(!1),[f,I]=(0,x.useState)(!1),[S,C]=(0,x.useState)(null),[w,D]=(0,x.useState)(null),[F,k]=(0,x.useState)(!1),{data:E,refetch:$}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await P("\n  query GetCategories {\n    categories {\n      id\n      name\n      createdAt\n    }\n  }\n")).categories||[],enabled:!1}),W=(0,ir.n)({mutationFn:e=>P("\n  mutation CreateCategory($name: String!) {\n    createCategory(name: $name) {\n      category {\n        id\n        name\n      }\n    }\n  }\n",{name:e}),onSuccess:()=>{T(),$()},onError:e=>{h(e.message||"Failed to create category")}}),L=(0,ir.n)({mutationFn:e=>{let{id:t,name:r}=e;return P("\n  mutation UpdateCategory($id: Int!, $name: String!) {\n    updateCategory(id: $id, name: $name) {\n      category {\n        id\n        name\n      }\n    }\n  }\n",{id:t,name:r})},onSuccess:()=>{T(),$()},onError:e=>{h(e.message||"Failed to update category")}}),q=(0,ir.n)({mutationFn:e=>P("\n  mutation DeleteCategory($categoryId: Int!) {\n    deleteCategory(categoryId: $categoryId) {\n      success\n    }\n  }\n",e),onSuccess:()=>{C("Category deleted successfully"),k(!1),$()},onError:e=>{h(e.message)}}),R=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(l(e),d(e.name)):(l(null),d("")),i(!0)},T=()=>{i(!1),l(null),d(""),h(null)},z=()=>{o.trim()?a?L.mutate({id:a.id,name:o.trim()}):W.mutate(o.trim()):h("Category name is required")},U=E?.slice(e*r,e*r+r);return(0,K.jsxs)(A.A,{children:[(0,K.jsxs)(te.A,{sx:{p:3,mb:3},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,K.jsx)(ge.A,{sx:{mr:1}}),(0,K.jsx)(m.A,{variant:"h5",children:"Category Management"})]}),(0,K.jsx)(xe.Ay,{container:!0,spacing:2,sx:{mb:3},children:(0,K.jsxs)(xe.Ay,{item:!0,xs:12,sx:{display:"flex",gap:2},children:[(0,K.jsx)(j.A,{variant:"contained",startIcon:(0,K.jsx)(cr.A,{}),onClick:()=>{b(!0),h(null),$().then((()=>{I(!0),b(!1)})).catch((e=>{h("Failed to load categories. Please try again."),b(!1)}))},disabled:g,sx:{minWidth:150},children:g?(0,K.jsx)(y.A,{size:24}):"Fetch Categories"}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(ge.A,{}),onClick:()=>R(),children:"Add Category"})]})}),c&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:3},children:c}),f?g?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,K.jsx)(y.A,{})}):(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)(Mt.A,{children:[(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"ID"}),(0,K.jsx)(Gt.A,{children:"Name"}),(0,K.jsx)(Gt.A,{children:"Created At"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:0===U?.length?(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:4,align:"center",children:"No categories found"})}):U?.map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e.id}),(0,K.jsx)(Gt.A,{children:e.name}),(0,K.jsx)(Gt.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(le.A,{size:"small",onClick:()=>R(e),children:(0,K.jsx)(rr.A,{})}),(0,K.jsx)(le.A,{size:"small",onClick:()=>(e=>{D(e),k(!0)})(e),children:(0,K.jsx)(gr.A,{})})]})]},e.id)))})]}),(0,K.jsx)(v.A,{component:"div",count:E?.length||0,page:e,onPageChange:(e,r)=>{t(r)},rowsPerPage:r,onRowsPerPageChange:e=>{n(parseInt(e.target.value,10)),t(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,K.jsxs)(A.A,{sx:{textAlign:"center",py:4},children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Categories" to load category information'}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,K.jsxs)(Pe.A,{open:s,onClose:T,children:[(0,K.jsx)(De.A,{children:a?"Edit Category":"Add New Category"}),(0,K.jsx)(Fe.A,{children:(0,K.jsx)(p.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:o,onChange:e=>d(e.target.value),error:!!c,helperText:c,onKeyPress:e=>{"Enter"===e.key&&z()}})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:T,children:"Cancel"}),(0,K.jsx)(j.A,{onClick:z,variant:"contained",disabled:W.isLoading||L.isLoading,children:W.isLoading||L.isLoading?(0,K.jsx)(y.A,{size:24}):a?"Update":"Create"})]})]}),(0,K.jsxs)(Pe.A,{open:F,onClose:()=>k(!1),children:[(0,K.jsx)(De.A,{children:"Delete Category"}),(0,K.jsx)(Fe.A,{children:(0,K.jsx)(m.A,{children:"Are you sure you want to delete this category?"})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>k(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:()=>{w&&q.mutate({categoryId:w.id})},variant:"contained",color:"error",children:"Delete"})]})]})]})},Ur=240,Br=[{text:"Dashboard",icon:(0,K.jsx)(Wt.A,{}),path:"/admin/dashboard"},{text:"Stores",icon:(0,K.jsx)(Lt.A,{}),path:"/admin/stores"},{text:"Product Management",icon:(0,K.jsx)(qt.A,{}),path:"/admin/products"},{text:"Inventory Management",icon:(0,K.jsx)(Rt.A,{}),path:"/admin/inventory"},{text:"Orders",icon:(0,K.jsx)(ye.A,{}),path:"/admin/orders"},{text:"Users",icon:(0,K.jsx)(Tt.A,{}),path:"/admin/users"},{text:"Payment Onboarding",icon:(0,K.jsx)(zt.A,{}),path:"/admin/payment-onboarding"},{text:"Settings",icon:(0,K.jsx)(Ut.A,{}),path:"/admin/settings"},{text:"Categories",icon:(0,K.jsx)(Rt.A,{}),path:"/admin/categories"}],Or=()=>{const[e,t]=(0,x.useState)(!1),[r,n]=(0,x.useState)(!0),{user:s,ability:i,logout:a}=V(),l=(0,be.A)(),o=(0,Me.A)(l.breakpoints.down("sm")),c=(0,d.Zp)(),u=(0,d.zy)(),h=(0,K.jsxs)(A.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:2,minHeight:64},children:[r&&(0,K.jsx)(A.A,{sx:{display:"flex",alignItems:"center",gap:2},children:(0,K.jsx)(m.A,{variant:"h6",noWrap:!0,component:"div",children:"Admin Panel"})}),(0,K.jsx)(le.A,{onClick:()=>{n(!r)},children:r?(0,K.jsx)(Bt.A,{}):(0,K.jsx)(Ot.A,{})})]}),(0,K.jsx)(Pt.A,{}),(0,K.jsxs)(Dt.A,{children:[Br.map((e=>(0,K.jsxs)(Ft.Ay,{button:!0,onClick:()=>{return r=e.path,c(r),void(o&&t(!1));var r},selected:u.pathname===e.path,sx:{minHeight:48,justifyContent:r?"initial":"center",px:2.5,"&.Mui-selected":{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white","&:hover":{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",opacity:.9},"& .MuiListItemIcon-root":{color:"white"}}},children:[(0,K.jsx)(kt.A,{sx:{minWidth:0,mr:r?3:"auto",justifyContent:"center",color:u.pathname===e.path?"white":"inherit"},children:e.icon}),(0,K.jsx)(Et.A,{primary:e.text,sx:{opacity:r?1:0}})]},e.text))),(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsxs)(Ft.Ay,{button:!0,onClick:()=>{(async()=>{try{await(0,Ne.C)(),a(),c("/")}catch(e){}})()},sx:{minHeight:48,justifyContent:r?"initial":"center",px:2.5},children:[(0,K.jsx)(kt.A,{sx:{minWidth:0,mr:r?3:"auto",justifyContent:"center"},children:(0,K.jsx)(Nt.A,{})}),(0,K.jsx)(Et.A,{primary:"Logout",sx:{opacity:r?1:0}})]})]})]});return(0,K.jsxs)(A.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,K.jsx)(vt,{}),(0,K.jsx)(A.A,{component:"nav",sx:{width:{sm:r?Ur:65},flexShrink:{sm:0},position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,K.jsx)($t.Ay,{variant:o?"temporary":"persistent",open:!0,onClose:()=>{t(!e)},ModalProps:{keepMounted:!0},sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:r?Ur:65,top:{xs:"64px",sm:"70px"},transition:l.transitions.create("width",{easing:l.transitions.easing.sharp,duration:l.transitions.duration.enteringScreen}),overflowX:"hidden"}},children:h})}),(0,K.jsx)(A.A,{component:"main",sx:{flexGrow:1,p:3,width:{sm:`calc(100% - ${r?Ur:65}px)`},ml:{sm:`${r?Ur:65}px`},mt:{xs:"64px",sm:"70px"},transition:l.transitions.create(["width","margin"],{easing:l.transitions.easing.sharp,duration:l.transitions.duration.leavingScreen})},children:(0,K.jsxs)(d.BV,{children:[(0,K.jsx)(d.qh,{path:"/",element:(0,K.jsx)(d.C5,{to:"dashboard",replace:!0})}),(0,K.jsx)(d.qh,{path:"dashboard",element:(0,K.jsx)(Er,{})}),(0,K.jsx)(d.qh,{path:"users/*",element:(0,K.jsx)(ar,{})}),(0,K.jsx)(d.qh,{path:"stores/*",element:(0,K.jsx)(pr,{})}),(0,K.jsx)(d.qh,{path:"products",element:(0,K.jsx)(vr,{})}),(0,K.jsx)(d.qh,{path:"inventory",element:(0,K.jsx)(Tr,{})}),(0,K.jsx)(d.qh,{path:"orders",element:(0,K.jsx)(Pr,{})}),(0,K.jsx)(d.qh,{path:"payment-onboarding",element:(0,K.jsx)(Fr,{})}),(0,K.jsx)(d.qh,{path:"categories",element:(0,K.jsx)(zr,{})})]})})]})};var Nr=r(4389),Mr=r(6030),_r=r(7809);const Vr=()=>{const[,e]=(0,x.useReducer)((e=>e+1),0),[t,r]=(0,x.useState)(null),[n,s]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[l,o]=(0,x.useState)(""),[d,c]=(0,x.useState)(""),[v,b]=(0,x.useState)("ALL"),[f,I]=(0,x.useState)(""),[S,C]=(0,x.useState)(!1),[w,k]=(0,x.useState)(0),[E,W]=(0,x.useState)({}),[L,q]=(0,x.useState)(!1),{userProfile:R,setUserProfile:T}=V();(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Be.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;a(t)}}catch(e){}})()}),[]);const{data:z,isLoading:U,error:B}=(0,u.I)({queryKey:["getUserProfile",i],queryFn:async()=>{const t=await P(F,{userId:i});return t?.getUserProfile&&(T(t.getUserProfile),setTimeout((()=>{e()}),200)),t},enabled:!!i,onError:e=>{}}),O=V.getState().userProfile||R||z?.getUserProfile,{data:N,isLoading:M,error:_,refetch:Y}=(0,u.I)({queryKey:["driverDeliveries",O?.id],queryFn:()=>O?.id?P("\n  query GetDeliveriesByDriver($driverId: Int!) {\n    getDeliveriesByDriver(driverId: $driverId) {\n      id\n      orderId\n      schedule\n      pickedUpTime\n      deliveredTime\n      status\n      comments\n      order {\n        addressId\n        cancelMessage\n        cancelledAt\n        cancelledByUserId\n        createdByUserId\n        deliveryDate\n        deliveryInstructions\n        id\n        paymentId\n        status\n        storeId\n        totalAmount\n        address {\n          address\n        }\n        orderItems {\n          edges {\n            node {\n              id\n              inventoryId\n              orderAmount\n              orderId\n              productId\n              quantity\n              updatedOrderitemsId\n              product {\n                categoryId\n                description\n                id\n                image\n                name\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n",{driverId:O.id}):null,enabled:!!O?.id}),G=(0,ir.n)({mutationFn:e=>P(D,{input:{orderId:e.orderId,status:e.status}}),onSuccess:()=>{Y(),s(!1),I(""),C(!1)},onError:e=>{}}),H=(0,ir.n)({mutationFn:e=>P($,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:O?.id}),onSuccess:()=>{Y(),s(!1),I(""),C(!1)},onError:e=>{}}),Q=e=>!!e?.edges?.length&&e.edges.every((e=>E[e.node.id])),J=x.useMemo((()=>N?.getDeliveriesByDriver?N.getDeliveriesByDriver.filter((e=>{if("ALL"!==v&&e.status!==v)return!1;if(d){const t=d.toLowerCase(),r=e.orderId.toString().includes(t),n=e.address?.toLowerCase().includes(t);return r||n}return!0})):[]),[N?.getDeliveriesByDriver,v,d]);if(U||M&&O?.id)return(0,K.jsx)(y.A,{sx:{display:"block",mx:"auto",mt:4}});if(B)return(0,K.jsx)(m.A,{color:"error",children:"Error fetching user profile!"});if(_&&O?.id)return(0,K.jsx)(m.A,{color:"error",children:"Error fetching deliveries!"});const Z=N?.getDeliveriesByDriver||[],ee=e=>{switch(e){case"READY_FOR_DELIVERY":return"primary";case"PICKED_UP":return"info";case"DELIVERED":return"success";case"CANCELLED":return"error";default:return"default"}},re=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,K.jsx)(Ir.A,{});case"PICKED_UP":return(0,K.jsx)(nr.A,{});case"DELIVERED":return(0,K.jsx)(br.A,{});case"CANCELLED":return(0,K.jsx)(fr.A,{});default:return null}},ne=e=>N?.getDeliveriesByDriver?N.getDeliveriesByDriver.filter((t=>t.status===e)).length:0;return(0,K.jsxs)(h.A,{maxWidth:"lg",sx:{mt:4,mb:6},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:4,flexDirection:{xs:"column",sm:"row"},gap:{xs:2,sm:0}},children:[(0,K.jsx)(m.A,{variant:"h4",fontWeight:"500",sx:{fontSize:{xs:"1.5rem",sm:"2rem"}},children:"Delivery Partner Dashboard"}),(0,K.jsx)(p.A,{size:"small",placeholder:"Search orders...",value:d,onChange:e=>c(e.target.value),InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(sr.A,{fontSize:"small"})})},sx:{width:{xs:"100%",sm:250},"& .MuiOutlinedInput-root":{borderRadius:2}}})]}),(0,K.jsx)(A.A,{sx:{mb:4},children:(0,K.jsxs)(Ht.A,{value:w,onChange:(e,t)=>{k(t),0===t?b("ALL"):1===t?b("READY_FOR_DELIVERY"):2===t?b("PICKED_UP"):3===t&&b("DELIVERED")},variant:"scrollable",scrollButtons:"auto",sx:{borderBottom:1,borderColor:"divider","& .MuiTab-root":{minWidth:120,textTransform:"none",fontSize:"0.875rem"}},children:[(0,K.jsx)(Qt.A,{label:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:["All Orders",(0,K.jsx)(Le.A,{badgeContent:Z.length,color:"primary",sx:{ml:2}})]})}),(0,K.jsx)(Qt.A,{label:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:["Ready",(0,K.jsx)(Le.A,{badgeContent:ne("READY_FOR_DELIVERY"),color:"primary",sx:{ml:2}})]})}),(0,K.jsx)(Qt.A,{label:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:["In Transit",(0,K.jsx)(Le.A,{badgeContent:ne("PICKED_UP"),color:"info",sx:{ml:2}})]})}),(0,K.jsx)(Qt.A,{label:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:["Delivered",(0,K.jsx)(Le.A,{badgeContent:ne("DELIVERED"),color:"success",sx:{ml:2}})]})})]})}),(0,K.jsx)(xe.Ay,{container:!0,spacing:{xs:2,sm:3},children:J.length>0?J.map((e=>(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,K.jsx)(ue.A,{sx:{cursor:"pointer",height:"100%",display:"flex",flexDirection:"column",borderRadius:2,boxShadow:"0 2px 8px rgba(0,0,0,0.05)",transition:"all 0.2s ease-in-out","&:hover":{boxShadow:"0 4px 12px rgba(0,0,0,0.1)",transform:"translateY(-2px)"}},onClick:()=>(e=>{r(e),o(e.orderStatus||e.status),s(!0),C(!1),I("")})(e),children:(0,K.jsxs)(he.A,{sx:{flexGrow:1,p:{xs:2,sm:2.5}},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,K.jsxs)(m.A,{variant:"h6",sx:{fontSize:{xs:"1rem",sm:"1.25rem"},fontWeight:500},children:["Order #",e.orderId]}),(0,K.jsx)(fe.A,{icon:re(e.status),label:e.status.replace(/_/g," "),color:ee(e.status),size:"small",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},height:{xs:24,sm:28},borderRadius:1.5}})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,K.jsx)(Mr.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,K.jsx)(m.A,{variant:"body2",sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:new Date(e.schedule).toLocaleString()})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,K.jsx)(xr.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,K.jsx)(m.A,{variant:"body2",sx:{flexGrow:1,fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:e?.order?.address?.address||"No address provided"})]}),e.pickedUpTime&&(0,K.jsxs)(m.A,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},mb:1},children:["Picked up: ",new Date(e.pickedUpTime).toLocaleString()]}),e.deliveredTime&&(0,K.jsxs)(m.A,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"}},children:["Delivered: ",new Date(e.deliveredTime).toLocaleString()]}),"CANCELLED"===e.status&&e.order?.cancelMessage&&(0,K.jsx)(A.A,{sx:{mt:1},children:(0,K.jsxs)(m.A,{variant:"body2",color:"error",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},fontStyle:"italic",bgcolor:"error.lightest",p:1,borderRadius:1,display:"flex",alignItems:"center"},children:[(0,K.jsx)(fr.A,{fontSize:"small",sx:{mr:.5,flexShrink:0}}),(0,K.jsxs)("span",{style:{lineHeight:1},children:['Cancellation Reason: "',e.order.cancelMessage,'"']})]})}),e.comments&&"CANCELLED"!==e.status&&(0,K.jsx)(A.A,{sx:{mt:1},children:(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},fontStyle:"italic",display:"flex",alignItems:"flex-start"},children:(0,K.jsxs)("span",{children:['"',e.comments,'"']})})})]})})},e.id))):(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(te.A,{sx:{p:{xs:3,sm:4},borderRadius:2,textAlign:"center"},children:[(0,K.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"No Deliveries Found"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:d||"ALL"!==v?"No deliveries match your search criteria.":"You have no deliveries assigned at this time."})]})})}),(0,K.jsx)(tt.A,{open:n,onClose:()=>s(!1),"aria-labelledby":"delivery-details-modal",children:(0,K.jsx)(A.A,{sx:{width:{xs:"95%",sm:"90%",md:500},bgcolor:"background.paper",p:{xs:2,sm:3},mx:"auto",mt:{xs:2,sm:5},borderRadius:2,boxShadow:3,maxHeight:"90vh",overflow:"auto"},children:t&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,K.jsxs)(m.A,{variant:"h5",fontWeight:"500",sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"}},children:["Order #",t.orderId]}),(0,K.jsx)(le.A,{edge:"end","aria-label":"close",onClick:()=>s(!1),size:"small",children:(0,K.jsx)(_r.A,{})})]}),(0,K.jsx)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:(0,K.jsx)(fe.A,{icon:re(t.status),label:t.status.replace(/_/g," "),color:ee(t.status),sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}}})}),(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY ADDRESS"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"flex-start"},children:[(0,K.jsx)(xr.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,K.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.order?.address?.address||t.address||"No address provided"})]})]}),(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"SCHEDULED DELIVERY"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(Mr.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,K.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.schedule).toLocaleString()})]})]}),t.pickedUpTime&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"PICKED UP"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(nr.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,K.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.pickedUpTime).toLocaleString()})]})]}),t.deliveredTime&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERED"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(br.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,K.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.deliveredTime).toLocaleString()})]})]}),"CANCELLED"===t.status&&t.order?.cancelMessage&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"error",gutterBottom:!0,children:"CANCELLATION REASON"}),(0,K.jsxs)(A.A,{sx:{p:2,bgcolor:"error.lightest",borderRadius:1,borderLeft:"3px solid",borderColor:"error.main",display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(fr.A,{color:"error",sx:{flexShrink:0}}),(0,K.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"},color:"error.main",lineHeight:1.2},children:t.order.cancelMessage})]})]}),t.comments&&"CANCELLED"!==t.status&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"COMMENTS"}),(0,K.jsx)(A.A,{sx:{p:2,bgcolor:"rgba(0, 0, 0, 0.03)",borderRadius:1,borderLeft:"3px solid",borderColor:"primary.main"},children:(0,K.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.comments})})]}),t.photo&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY PROOF"}),(0,K.jsx)("img",{src:t.photo,alt:"Delivery Proof",style:{width:"100%",borderRadius:4}})]}),L&&t?.order?.orderItems&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"VERIFY ITEMS TO BE PICKED UP"}),(0,K.jsx)(te.A,{sx:{p:2,maxHeight:300,overflow:"auto"},children:t.order.orderItems.edges.filter((e=>{let{node:t}=e;return null===t.updatedOrderitemsId&&t.quantity>0})).map((e=>{let{node:t}=e;return(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:1,p:1,borderRadius:1,bgcolor:"background.default"},children:[(0,K.jsx)(Nr.A,{checked:!!E[t.id],onChange:()=>{return e=t.id,void W((t=>({...t,[e]:!t[e]})));var e},color:"primary"}),(0,K.jsxs)(A.A,{sx:{ml:2,flex:1},children:[(0,K.jsx)(m.A,{variant:"body2",fontWeight:"500",children:t.product.name}),(0,K.jsxs)(m.A,{variant:"caption",color:"text.secondary",children:["Quantity: ",t.quantity," × $",t.orderAmount.toFixed(2)]})]})]},t.id)}))}),!Q(t.order.orderItems)&&(0,K.jsx)(X.A,{severity:"warning",sx:{mt:1},children:"Please verify all items before updating status"})]}),(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"UPDATE STATUS"}),(0,K.jsx)(Jt.A,{fullWidth:!0,sx:{mb:2},children:(0,K.jsxs)(Xt.A,{value:l,onChange:e=>{const r=e.target.value;o(r),"READY_FOR_DELIVERY"===t?.status&&"READY_FOR_DELIVERY"!==r?(q(!0),W({})):q(!1),C("CANCELLED"===r)},size:"small",children:[(0,K.jsx)(de.A,{value:"PICKED_UP",children:"Picked Up"}),(0,K.jsx)(de.A,{value:"DELIVERED",children:"Delivered"}),(0,K.jsx)(de.A,{value:"CANCELLED",children:"Cancelled"})]})}),S&&(0,K.jsx)(p.A,{fullWidth:!0,label:"Cancellation Reason",multiline:!0,rows:3,value:f,onChange:e=>I(e.target.value),sx:{mb:2},required:!0,size:"small"}),(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"flex-end",mt:3},children:(0,K.jsx)(j.A,{onClick:()=>{t&&l&&("READY_FOR_DELIVERY"!==t.status||"READY_FOR_DELIVERY"===l||Q(t.order.orderItems))&&("CANCELLED"===l?H.mutate({orderId:t.orderId,cancelMessage:f}):G.mutate({orderId:t.orderId,status:l}))},variant:"contained",color:"primary",disabled:("CANCELLED"===l?H.isLoading:G.isLoading)||l===t.orderStatus||"CANCELLED"===l&&!f||L&&!Q(t.order.orderItems),sx:{minWidth:120},children:("CANCELLED"===l?H.isLoading:G.isLoading)?"Updating...":"Update"})})]})})})]})},Yr=[{text:"Dashboard",icon:(0,K.jsx)(Wt.A,{}),path:He},{text:"Orders",icon:(0,K.jsx)(ye.A,{}),path:Qe},{text:"Delivery Partners",icon:(0,K.jsx)(nr.A,{}),path:"/store_manager/delivery-partners"},{text:"Inventory",icon:(0,K.jsx)(qt.A,{}),path:"/store_manager/inventory"},{text:"Settings",icon:(0,K.jsx)(Ut.A,{}),path:"/store_manager/settings"}],Gr=()=>{const e=(0,be.A)(),t=(0,Me.A)(e.breakpoints.down("sm")),r=(0,d.Zp)(),n=(0,d.zy)(),{open:s,setOpen:i}=x.useContext(Kr),a=()=>{i(!s)},l=(0,K.jsxs)(A.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:2,minHeight:64},children:[s&&(0,K.jsx)(m.A,{variant:"h6",noWrap:!0,component:"div",children:"Store Manager"}),(0,K.jsx)(le.A,{onClick:a,children:s?(0,K.jsx)(Bt.A,{}):(0,K.jsx)(Ot.A,{})})]}),(0,K.jsx)(Pt.A,{}),(0,K.jsx)(Dt.A,{children:Yr.map((e=>(0,K.jsxs)(Ft.Ay,{button:!0,onClick:()=>{return n=e.path,r(n),void(t&&i(!1));var n},selected:n.pathname===e.path,sx:{minHeight:48,justifyContent:s?"initial":"center",px:2.5,"&.Mui-selected":{backgroundColor:"primary.light","&:hover":{backgroundColor:"primary.light"}}},children:[(0,K.jsx)(kt.A,{sx:{minWidth:0,mr:s?3:"auto",justifyContent:"center",color:n.pathname===e.path?"primary.main":"inherit"},children:e.icon}),(0,K.jsx)(Et.A,{primary:e.text,sx:{opacity:s?1:0}})]},e.text)))})]});return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(le.A,{color:"inherit","aria-label":"open drawer",edge:"start",onClick:a,sx:{mr:2,display:{sm:"none"}},children:(0,K.jsx)(Ot.A,{})}),(0,K.jsx)(A.A,{component:"nav",sx:{width:{sm:s?240:65},flexShrink:{sm:0},position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,K.jsx)($t.Ay,{variant:t?"temporary":"persistent",open:!0,onClose:a,ModalProps:{keepMounted:!0},sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:s?240:65,top:{xs:"64px",sm:"70px"},transition:e.transitions.create("width",{easing:e.transitions.easing.sharp,duration:e.transitions.duration.enteringScreen}),overflowX:"hidden"}},children:l})})]})},Kr=(0,x.createContext)({open:!0,setOpen:()=>{}}),Hr=e=>{let{children:t}=e;const r=(0,be.A)(),[n,s]=(0,x.useState)(!0);return(0,K.jsx)(Kr.Provider,{value:{open:n,setOpen:s},children:(0,K.jsxs)(A.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,K.jsx)(o.Ay,{}),(0,K.jsx)(vt,{}),(0,K.jsx)(Gr,{}),(0,K.jsx)(A.A,{component:"main",sx:{flexGrow:1,p:3,width:{sm:`calc(100% - ${n?240:65}px)`},ml:{sm:(n?240:65)+"px"},transition:r.transitions.create(["width","margin"],{easing:r.transitions.easing.sharp,duration:r.transitions.duration.leavingScreen}),display:"flex",flexDirection:"column",alignItems:"center",maxWidth:"100%",overflow:"hidden"},children:(0,K.jsx)(A.A,{sx:{width:"100%"},children:t})})]})})},Qr=()=>{const[e,t]=(0,x.useState)(""),{userProfile:r,setUserProfile:n}=V(),[s,i]=(0,x.useState)(null),[a,l]=(0,x.useState)(!1),[o,d]=(0,x.useState)(!1),[c,v]=(0,x.useState)(null),[b,f]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[C,w]=(0,x.useState)(""),[D,k]=(0,x.useState)(""),[E,$]=(0,x.useState)(""),[W,L]=(0,x.useState)(""),[q,R]=(0,x.useState)(""),[T,z]=(0,x.useState)(""),[U,B]=(0,x.useState)(""),[O,N]=(0,x.useState)(!1),[M,_]=(0,x.useState)(10),[Y,G]=(0,x.useState)(""),[H,Q]=(0,x.useState)([]),[J,Z]=(0,x.useState)(!1),[ee,re]=((0,x.useRef)(null),(0,x.useState)(0)),[ne,se]=(0,x.useState)(10),[ie,ae]=(0,x.useState)(!0),[le,oe]=(0,x.useState)(null),[ce,ue]=(0,x.useState)({open:!1,message:"",severity:"success"});(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,it.T)();t(e.sub)}catch(e){}})()}),[]),(0,x.useEffect)((()=>{const e=setTimeout((()=>{ae(!1)}),500);return()=>clearTimeout(e)}),[]);const{data:me,isLoading:he}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const t=await P(F,{userId:e});return t?.getUserProfile&&n(t.getUserProfile),t},enabled:!!e}),{data:Ae,isLoading:je,error:pe,refetch:ge}=(0,u.I)({queryKey:["storeWithInventory",r?.id],queryFn:()=>P("\n  query GetStoreWithInventory($managerId: Int!) {\n    storesByManager(managerUserId: $managerId) {\n      id\n      name\n      address\n      description\n      disabled\n      email\n      isActive\n      mobile\n      pincodes\n      radius\n      tnc\n      storeDeliveryFee\n      taxPercentage\n    }\n  }\n",{managerId:r.id}),enabled:!!r?.id}),ye=Ae?.storesByManager&&Ae.storesByManager[0],ve=ye?.inventory?.edges?.map((e=>e.node))||[],be=Ae?.products||[];(0,x.useEffect)((()=>{if(""===Y.trim())Q(be);else{const e=be.filter((e=>e.name.toLowerCase().includes(Y.toLowerCase())));Q(e)}}),[Y,be]);const fe=(0,ir.n)({mutationFn:e=>P("\n  mutation UpdateStore(\n    $storeId: Int!\n    $name: String\n    $address: String\n    $email: String\n    $mobile: String\n    $radius: Float\n    $isActive: Boolean\n    $description: String\n    $pincodes: [String!]\n    $tnc: String\n    $storeDeliveryFee: Float\n    $taxPercentage: Float\n  ) {\n    updateStore(\n      storeId: $storeId\n      name: $name\n      address: $address\n      email: $email\n      mobile: $mobile\n      radius: $radius\n      isActive: $isActive\n      description: $description\n      pincodes: $pincodes\n      tnc: $tnc\n      storeDeliveryFee: $storeDeliveryFee\n      taxPercentage: $taxPercentage\n    ) {\n      id\n      name\n      address\n      email\n      mobile\n      radius\n      isActive\n      description\n      pincodes\n      tnc\n      storeDeliveryFee\n      taxPercentage\n    }\n  }\n",e),onSuccess:()=>{ue({open:!0,message:"Store updated successfully",severity:"success"}),oe(null),ge()},onError:e=>{ue({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),Ie=()=>{oe(null)};return he||je||ie?(0,K.jsx)(Hr,{children:(0,K.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,K.jsx)(y.A,{})})}):pe?(0,K.jsx)(Hr,{children:(0,K.jsx)(h.A,{sx:{mt:4},children:(0,K.jsxs)(X.A,{severity:"error",children:["Error loading store data: ",pe.message]})})}):ye?(0,K.jsx)(Hr,{children:(0,K.jsxs)(h.A,{sx:{mb:4},children:[(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Manager Dashboard"}),(0,K.jsxs)(te.A,{elevation:3,sx:{p:3,mb:4},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,K.jsx)(m.A,{variant:"h5",children:"Store Information"}),(0,K.jsx)(j.A,{variant:"outlined",startIcon:(0,K.jsx)(rr.A,{}),onClick:()=>{oe(ye)},sx:{textTransform:"none"},children:"Edit Store"})]}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:[(0,K.jsx)("strong",{children:"Name:"})," ",ye.name]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:[(0,K.jsx)("strong",{children:"Address:"})," ",ye.address]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:[(0,K.jsx)("strong",{children:"Delivery Radius:"})," ",ye.radius||"Not set"," ",ye.radius?"mi":""]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:[(0,K.jsx)("strong",{children:"Delivery Fee:"})," $",ye.storeDeliveryFee?.toFixed(2)||"0.00"]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:[(0,K.jsx)("strong",{children:"Tax Rate:"})," ",ye.taxPercentage?.toFixed(1)||"0.0","%"]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:[(0,K.jsx)("strong",{children:"Total Products:"})," ",ve.length]})}),ye.description&&(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:[(0,K.jsx)("strong",{children:"Description:"})," ",ye.description]})}),ye.pincodes&&ye.pincodes.length>0&&(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:[(0,K.jsx)("strong",{children:"Delivery Pincodes:"})," ",ye.pincodes.join(", ")]})})]})]}),(0,K.jsxs)(Pe.A,{open:!!le,onClose:Ie,maxWidth:"md",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(Lt.A,{}),(0,K.jsx)(m.A,{variant:"h6",children:"Edit Store"})]})}),(0,K.jsxs)("form",{onSubmit:e=>{e.preventDefault();const t=new FormData(e.target),r=t.get("pincodes"),n=r?r.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],s={storeId:le.id,name:t.get("name"),address:t.get("address"),email:t.get("email"),mobile:t.get("mobile")||null,radius:parseFloat(t.get("radius")),isActive:"true"===t.get("isActive"),description:t.get("description")||null,pincodes:n,tnc:t.get("tnc")||null,storeDeliveryFee:parseFloat(t.get("storeDeliveryFee"))||null,taxPercentage:parseFloat(t.get("taxPercentage"))||null};fe.mutate(s)},children:[(0,K.jsx)(Fe.A,{children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"name",label:"Store Name",defaultValue:le?.name,required:!0,fullWidth:!0})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"email",label:"Email",type:"email",defaultValue:le?.email,required:!0,fullWidth:!0})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"mobile",label:"Mobile Number",defaultValue:le?.mobile,fullWidth:!0})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{name:"address",label:"Address",defaultValue:le?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:le?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:le?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:"$"})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:le?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,K.jsx)(g.A,{position:"end",children:"%"})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:le?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{name:"description",label:"Description",defaultValue:le?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{name:"tnc",label:"Terms & Conditions",defaultValue:le?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,children:[(0,K.jsx)(Zt.A,{children:"Store Status"}),(0,K.jsxs)(Xt.A,{name:"isActive",label:"Store Status",defaultValue:le?.isActive,children:[(0,K.jsx)(de.A,{value:!0,children:"Active"}),(0,K.jsx)(de.A,{value:!1,children:"Inactive"})]})]})})]})}),(0,K.jsxs)(er.A,{sx:{p:3,pt:0},children:[(0,K.jsx)(j.A,{onClick:Ie,children:"Cancel"}),(0,K.jsx)(j.A,{type:"submit",variant:"contained",disabled:fe.isPending,startIcon:fe.isPending?(0,K.jsx)(y.A,{size:20}):null,children:fe.isPending?"Updating...":"Update Store"})]})]})]}),(0,K.jsx)(tr.A,{open:ce.open,autoHideDuration:6e3,onClose:()=>ue({...ce,open:!1}),children:(0,K.jsx)(X.A,{onClose:()=>ue({...ce,open:!1}),severity:ce.severity,sx:{width:"100%"},children:ce.message})})]})}):(0,K.jsx)(Hr,{children:(0,K.jsx)(h.A,{sx:{mt:4},children:(0,K.jsx)(X.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})};var Jr=r(2848),Zr=r(7867),Xr=r(9381),en=r(7301),tn=r(2183),rn=r(9149),nn=r(1365);const sn=()=>{const[,e]=(0,x.useReducer)((e=>e+1),0),[t,r]=(0,x.useState)(null),[n,s]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[l,o]=(0,x.useState)(null),[d,c]=(0,x.useState)(""),[g,v]=(0,x.useState)(!1),[b,f]=(0,x.useState)(null),[I,S]=(0,x.useState)(null),[C,w]=(0,x.useState)({open:!1,title:"",message:"",onConfirm:null}),D=(0,be.A)(),k=(0,Me.A)(D.breakpoints.down("sm")),{userProfile:E,setUserProfile:W}=V();(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Be.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;r(t)}}catch(e){}})()}),[]);const{data:L,isLoading:q,error:R}=(0,u.I)({queryKey:["getUserProfile",t],queryFn:async()=>{const r=await P(F,{userId:t});return r?.getUserProfile&&(W(r.getUserProfile),setTimeout((()=>{e()}),200)),r},enabled:!!t,onError:e=>{}}),T=V.getState().userProfile||E||L?.getUserProfile,{data:z,isLoading:U,error:B,refetch:O}=(0,u.I)({queryKey:["userOrders",T?.id],queryFn:()=>P("\n  query GetUserOrders($userId: Int!) {\n    getOrdersByUser(userId: $userId) {\n      addressId\n      billUrl\n      deliveryDate\n      deliveryFee\n      deliveryInstructions\n      id\n      cancelMessage\n      cancelledAt\n      cancelledByUserId\n      createdByUserId\n      orderTotalAmount\n      paymentId\n      status\n      storeId\n      taxAmount\n      tipAmount\n      totalAmount\n      address { \n        id\n        address\n        isPrimary\n      }\n      orderItems {\n        edges {\n          node {\n            id\n            orderAmount\n            quantity\n            updatedOrderitemsId\n            product {\n              id\n              name\n              description\n              category {\n                id\n                name\n              }\n              inventoryItems {\n                edges {\n                  node {\n                    id\n                    price\n                    quantity\n                    measurement\n                    unit\n                    storeId\n                    productId\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n",{userId:T.id}),enabled:!!T?.id}),N=(0,ir.n)({mutationFn:e=>P($,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:T.id}),onSuccess:()=>{O(),_(),c("")}}),M=(0,ir.n)({mutationFn:e=>P("\n  mutation UpdateOrderItems(\n    $orderId: Int!\n    $orderItemUpdates: [OrderItemUpdateInput!]!\n    $totalAmount: Float!\n    $orderTotalAmount: Float!\n    $taxAmount: Float\n  ) {\n    updateOrderItems(\n      orderId: $orderId\n      orderItemUpdates: $orderItemUpdates\n      totalAmount: $totalAmount\n      orderTotalAmount: $orderTotalAmount\n      taxAmount: $taxAmount\n    ) {\n      id\n      totalAmount\n      orderTotalAmount\n      taxAmount\n      orderItems {\n        edges {\n          node {\n            id\n            quantity\n            orderAmount\n            product {\n              id\n              name\n              category {\n                name\n              }\n              inventoryItems {\n                edges {\n                  node {\n                    price\n                    measurement\n                    unit\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n",{orderId:e.orderId,orderItemUpdates:e.orderItemUpdates,totalAmount:e.totalAmount,orderTotalAmount:e.orderTotalAmount,taxAmount:e.taxAmount}),onSuccess:()=>{O()}}),_=()=>{s(!1),a(null)},Y=e=>{o(l===e?null:e)},G=(e,t,r)=>{if(!t||!t.id)return;const n=r-t.quantity,s=(t.product.inventoryItems?.edges[0]?.node?.price||0)*n,i=e.totalAmount+s,a=0===i?0:.1*i,l=0===i?0:i+a+(e.deliveryFee||0)+(e.tipAmount||0),o={orderId:parseInt(e.id,10),orderItemUpdates:[{orderItemId:parseInt(t.id,10),quantityChange:n}],totalAmount:i,orderTotalAmount:l,taxAmount:a};M.mutate(o)},H=e=>{if(!e?.edges?.length)return null;const t=new Map;e.edges.forEach((e=>{let{node:r}=e;t.set(r.id,r)}));return e.edges.map((e=>{let{node:t}=e;return t})).filter((e=>null===e.updatedOrderitemsId))},Q=()=>{f(null),S(null)},J=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e);if(q||U&&T?.id)return(0,K.jsx)(y.A,{sx:{display:"block",mx:"auto",mt:4}});if(R)return(0,K.jsx)(m.A,{color:"error",children:"Error fetching user profile!"});if(B&&T?.id)return(0,K.jsx)(m.A,{color:"error",children:"Error fetching orders!"});const Z=z?.getOrdersByUser||[];return(0,K.jsxs)(h.A,{maxWidth:"xl",sx:{mt:4,px:{xs:1,sm:2,md:3}},children:[(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,sx:{fontSize:{xs:"1.5rem",sm:"2rem",md:"2.125rem"},mb:{xs:2,sm:3}},children:"My Orders"}),0===Z.length?(0,K.jsx)(m.A,{children:"No orders found!"}):(0,K.jsx)(Mt.A,{component:te.A,sx:{mt:2,overflowX:"auto","& .MuiTableCell-root":{px:{xs:1,sm:2},py:{xs:1.5,sm:2},whiteSpace:"nowrap"}},children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{sx:{display:{xs:"none",md:"table-cell"}},children:"Order ID"}),(0,K.jsx)(Gt.A,{children:"Address"}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Total"}),(0,K.jsx)(Gt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Delivery Date"}),(0,K.jsx)(Gt.A,{children:"Bill"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:Z.map((e=>(0,K.jsxs)(x.Fragment,{children:[(0,K.jsxs)(Yt.A,{onClick:()=>Y(e.id),sx:{cursor:"pointer"},children:[(0,K.jsx)(Gt.A,{sx:{display:{xs:"none",md:"table-cell"}},children:e.id}),(0,K.jsx)(Gt.A,{sx:{maxWidth:{xs:"120px",sm:"200px",md:"300px"},overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.address.address}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:e.status,size:k?"small":"medium",color:"COMPLETE"===e.status?"success":"PENDING"===e.status||"ORDER_PLACED"===e.status?"warning":"error"})}),(0,K.jsxs)(Gt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:["$",e.totalAmount.toFixed(2)]}),(0,K.jsx)(Gt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:e.deliveryDate?new Date(e.deliveryDate).toLocaleDateString():"N/A"}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(A.A,{sx:{display:"flex",gap:1},children:(0,K.jsx)(je.A,{title:"Download Bill",children:(0,K.jsx)(le.A,{size:"small",onClick:t=>{t.stopPropagation(),(async e=>{if(!g)try{v(!0);const t=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",r=await fetch(`${t}/s3/generate-view-url?order_id=${e}&file_name=order_${e}.jpeg`);if(200===r.status){const e=await r.json();if(e?.view_url){const t=document.createElement("a");return t.href=e.view_url,t.download=e.file_name,t.target="_blank",document.body.appendChild(t),t.click(),void document.body.removeChild(t)}}alert("No bill available for this order")}catch(e){alert("Error downloading the bill. Please try again.")}finally{v(!1)}})(e.id)},children:(0,K.jsx)(Xr.A,{})})})})}),(0,K.jsx)(Gt.A,{children:(0,K.jsxs)(A.A,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,K.jsx)(j.A,{variant:"contained",color:"error",size:k?"small":"medium",onClick:t=>{var r;t.stopPropagation(),r=e.id,a(r),s(!0)},disabled:!J(e.status),children:"Cancel"}),(0,K.jsx)(le.A,{onClick:t=>{t.stopPropagation(),Y(e.id)},size:"small",children:l===e.id?(0,K.jsx)(en.A,{}):(0,K.jsx)(tn.A,{})})]})})]}),(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{style:{paddingBottom:0,paddingTop:0},colSpan:7,children:(0,K.jsx)(Jr.A,{in:l===e.id,timeout:"auto",unmountOnExit:!0,children:(0,K.jsx)(A.A,{sx:{margin:{xs:1,sm:2}},children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsxs)(m.A,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1,color:"primary.main",fontWeight:600,fontSize:{xs:"1rem",sm:"1.25rem"}},children:[(0,K.jsx)(Sr.A,{})," Order Items"]}),(0,K.jsx)(te.A,{sx:{p:{xs:1.5,sm:2}},children:e.orderItems?.edges?.length>0?(0,K.jsx)(xe.Ay,{container:!0,spacing:{xs:1,sm:2},children:H(e.orderItems).map((t=>{const r=t.product.inventoryItems?.edges[0]?.node,n=((e,t)=>{const r=new Map;t.forEach((e=>{let{node:t}=e;r.set(t.id,t)}));const n=[e];let s=e.id;for(;;){const e=Array.from(r.values()).find((e=>e.updatedOrderitemsId===s));if(!e)break;n.push(e),s=e.id}return n.reverse()})(t,e.orderItems.edges);return(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(ue.A,{variant:"outlined",sx:{p:{xs:1.5,sm:2},"&:hover":{bgcolor:"grey.50"}},children:[(0,K.jsxs)(xe.Ay,{container:!0,spacing:{xs:1,sm:2},alignItems:"center",children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,sm:4,children:[(0,K.jsx)(m.A,{variant:"subtitle1",fontWeight:600,sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.product.name}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:500,children:t.product.category.name}),n.length>1&&(0,K.jsxs)(m.A,{variant:"caption",color:"primary",sx:{display:"block",mt:.5},children:[n.length-1," previous version",n.length>2?"s":""]})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:6,sm:2,children:[(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Unit Price"}),(0,K.jsxs)(m.A,{variant:"body1",fontWeight:500,children:["$",r?.price.toFixed(2)]}),r&&(0,K.jsxs)(m.A,{variant:"caption",color:"text.secondary",fontWeight:500,children:[r.measurement," ",r.unit]})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:6,sm:2,children:[(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Quantity"}),b===t.id?(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(p.A,{type:"number",size:"small",value:I,onChange:e=>S(parseInt(e.target.value)||0),inputProps:{min:0},sx:{width:"80px"}}),(0,K.jsxs)(A.A,{sx:{display:"flex",gap:.5},children:[(0,K.jsx)(le.A,{size:"small",color:"primary",onClick:()=>((e,t)=>{0===I?w({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{G(e,t,0),f(null),S(null),w({open:!1,title:"",message:"",onConfirm:null})}}):I>0&&(G(e,t,I),f(null),S(null))})(e,t),disabled:null===I||I<0,children:(0,K.jsx)(rn.A,{fontSize:"small"})}),(0,K.jsx)(le.A,{size:"small",color:"error",onClick:Q,children:(0,K.jsx)(_r.A,{fontSize:"small"})})]})]}):(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(m.A,{variant:"body1",fontWeight:500,children:t.quantity}),J(e.status)&&(0,K.jsx)(le.A,{size:"small",onClick:()=>{return f((e=t).id),void S(e.quantity);var e},children:(0,K.jsx)(rr.A,{fontSize:"small"})})]})]}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:4,children:(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",sm:"flex-end"},alignItems:"center",gap:1,mt:{xs:1,sm:0}},children:[(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Total:"}),(0,K.jsxs)(m.A,{variant:"h6",color:"primary",fontWeight:700,sx:{fontSize:{xs:"1rem",sm:"1.25rem"}},children:["$",(t.quantity*(t.product.inventoryItems?.edges[0]?.node?.price||0)).toFixed(2)]}),J(e.status)&&(0,K.jsx)(le.A,{size:"small",color:"error",onClick:r=>{r.stopPropagation(),((e,t)=>{w({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{G(e,t,0),w({open:!1,title:"",message:"",onConfirm:null})}})})(e,t)},children:(0,K.jsx)(gr.A,{fontSize:"small"})})]})})]}),n.length>1&&(0,K.jsxs)(A.A,{sx:{mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[(0,K.jsxs)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(nn.A,{fontSize:"small"}),"Order Change History (",n.length-1," ","changes)"]}),(0,K.jsx)(A.A,{sx:{pl:2},children:n.slice(0,-1).map(((e,t)=>(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1.5,borderRadius:1,mb:1},children:[(0,K.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"120px",fontWeight:500},children:["Change ",t+1]}),(0,K.jsxs)(A.A,{sx:{display:"flex",gap:3},children:[(0,K.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,K.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount: $",e.orderAmount.toFixed(2)]})]})]},e.id)))})]})]})},t.id)}))}):(0,K.jsx)(A.A,{sx:{textAlign:"center",py:3,color:"text.secondary"},children:(0,K.jsx)(m.A,{fontWeight:500,children:"No items found for this order."})})})]}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(te.A,{sx:{p:{xs:1.5,sm:2},mb:3},children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,md:6,children:[(0,K.jsxs)(m.A,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1,color:"primary.main",fontWeight:600,mb:1,fontSize:{xs:"1rem",sm:"1.25rem"}},children:[(0,K.jsx)(Xr.A,{})," Order Details"]}),(0,K.jsxs)(A.A,{sx:{pl:1},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Subtotal"}),(0,K.jsxs)(m.A,{fontWeight:500,children:["$",e.totalAmount.toFixed(2)]})]}),e.deliveryFee&&(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Fee"}),(0,K.jsxs)(m.A,{fontWeight:500,children:["$",e.deliveryFee.toFixed(2)]})]}),e.taxAmount&&(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tax"}),(0,K.jsxs)(m.A,{fontWeight:500,children:["$",e.taxAmount.toFixed(2)]})]}),e.tipAmount&&(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tip"}),(0,K.jsxs)(m.A,{fontWeight:500,children:["$",e.tipAmount.toFixed(2)]})]}),(0,K.jsx)(Pt.A,{sx:{my:1}}),(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Total Amount"}),(0,K.jsxs)(m.A,{variant:"subtitle1",color:"primary",fontWeight:700,children:["$",e.orderTotalAmount.toFixed(2)]})]})]})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,md:6,children:[(0,K.jsxs)(m.A,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1,color:"primary.main",fontWeight:600,mb:1,fontSize:{xs:"1rem",sm:"1.25rem"}},children:[(0,K.jsx)(nr.A,{})," Delivery Information"]}),(0,K.jsxs)(A.A,{sx:{pl:1},children:[(0,K.jsxs)(A.A,{sx:{mb:1},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Address"}),(0,K.jsx)(m.A,{variant:"body2",fontWeight:500,children:e.address.address})]}),e.deliveryInstructions&&(0,K.jsxs)(A.A,{sx:{mb:1},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Instructions"}),(0,K.jsx)(m.A,{variant:"body2",fontWeight:500,children:e.deliveryInstructions})]}),e.deliveryDate&&(0,K.jsxs)(A.A,{sx:{mb:1},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,children:"Expected Delivery Date"}),(0,K.jsx)(m.A,{variant:"body2",fontWeight:500,children:new Date(e.deliveryDate).toLocaleDateString()})]}),e.cancelMessage&&(0,K.jsxs)(A.A,{sx:{mb:1},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"error",fontWeight:700,children:"Cancellation Reason"}),(0,K.jsx)(m.A,{variant:"body2",color:"error",fontWeight:500,children:e.cancelMessage})]})]})]})]})})})]})})})})})]},e.id)))})]})}),(0,K.jsxs)(Pe.A,{open:n,onClose:_,fullWidth:!0,maxWidth:"sm",children:[(0,K.jsx)(De.A,{children:"Cancel Order"}),(0,K.jsxs)(Fe.A,{children:[(0,K.jsx)(Zr.A,{gutterBottom:!0,children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,K.jsx)(p.A,{autoFocus:!0,margin:"dense",id:"cancelMessage",label:"Reason for Cancellation",type:"text",fullWidth:!0,variant:"outlined",value:d,onChange:e=>c(e.target.value),error:n&&!d.trim(),sx:{mt:2}})]}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:_,color:"primary",children:"No, Keep Order"}),(0,K.jsx)(j.A,{onClick:()=>{i&&d.trim()&&N.mutate({orderId:i,cancelMessage:d.trim()})},color:"error",variant:"contained",disabled:!d.trim(),children:"Yes, Cancel Order"})]})]}),(0,K.jsxs)(Pe.A,{open:C.open,onClose:()=>w({open:!1,title:"",message:"",onConfirm:null}),children:[(0,K.jsx)(De.A,{children:C.title}),(0,K.jsx)(Fe.A,{children:(0,K.jsx)(Zr.A,{children:C.message})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>w({open:!1,title:"",message:"",onConfirm:null}),color:"primary",children:"Cancel"}),(0,K.jsx)(j.A,{onClick:C.onConfirm,color:"error",variant:"contained",children:"Remove"})]})]})]})};var an=r(1385),ln=r(995),on=r(8864),dn=r(7211),cn=r(5629),xn=r(5402);const un=()=>{const{userProfile:e,setUserProfile:t,fetchUserProfile:r,isProfileLoading:n,profileError:s}=V(),i=(0,d.Zp)(),[a,l]=(0,x.useState)(0),[o,c]=(0,x.useState)(null),[u,g]=(0,x.useState)(null),[v,b]=(0,x.useState)(!1),f=window.location.origin,{addresses:I,selectedAddressId:S,setSelectedAddressId:C,fetchAddresses:w,isLoading:P,createAddress:D,updateAddress:F,deleteAddress:k}=Y(),[E,$]=(0,x.useState)(!1),[W,L]=(0,x.useState)(null),[q,R]=(0,x.useState)(""),[T,z]=(0,x.useState)(!1),[U,B]=(0,x.useState)(!1);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Be.$)();e?.tokens?.idToken&&g(e.tokens.idToken.payload.sub)}catch(e){}})()}),[]),(0,x.useEffect)((()=>{e||r()}),[e,r]);const O=e||o;(0,x.useEffect)((()=>{O?.id&&w(O.id)}),[O?.id,w]);const N=async()=>{try{await(0,Ne.C)(),i("/")}catch(e){}},M=`${f}/signup?referredby=${e?.referralId}`,_=async()=>{try{await navigator.clipboard.writeText(M),b(!0),setTimeout((()=>b(!1)),2e3)}catch(e){}};if(n)return(0,K.jsx)(h.A,{children:(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:[(0,K.jsx)(y.A,{}),(0,K.jsx)(m.A,{sx:{ml:2},children:"Loading profile..."})]})});if(s)return(0,K.jsxs)(h.A,{children:[(0,K.jsxs)(X.A,{severity:"error",sx:{mt:4},children:["Error loading profile: ",s]}),(0,K.jsx)(j.A,{variant:"contained",onClick:()=>r(),sx:{mt:2},children:"Retry"})]});if(!e)return(0,K.jsxs)(h.A,{children:[(0,K.jsx)(X.A,{severity:"warning",sx:{mt:4},children:"No profile data available. Please try again."}),(0,K.jsx)(j.A,{variant:"contained",onClick:()=>r(),sx:{mt:2},children:"Load Profile"})]});return(0,K.jsxs)(h.A,{maxWidth:"xl",sx:{py:4},children:[(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:3,children:(0,K.jsxs)(te.A,{elevation:0,sx:{borderRadius:2,overflow:"hidden"},children:[(0,K.jsx)(A.A,{sx:{p:2,bgcolor:"primary.main",color:"white"},children:(0,K.jsx)(m.A,{variant:"h6",children:"My Account"})}),(0,K.jsxs)(Dt.A,{component:"nav",sx:{pt:0},children:[(0,K.jsxs)(dn.A,{selected:0===a,onClick:()=>l(0),sx:{borderRadius:"0 0 0 0","&.Mui-selected":{bgcolor:"rgba(25, 118, 210, 0.08)",borderLeft:"4px solid",borderColor:"primary.main"}},children:[(0,K.jsx)(kt.A,{children:(0,K.jsx)(Oe.A,{color:0===a?"primary":"inherit"})}),(0,K.jsx)(Et.A,{primary:"Profile"})]}),(0,K.jsxs)(dn.A,{selected:1===a,onClick:()=>l(1),sx:{"&.Mui-selected":{bgcolor:"rgba(25, 118, 210, 0.08)",borderLeft:"4px solid",borderColor:"primary.main"}},children:[(0,K.jsx)(kt.A,{children:(0,K.jsx)(xr.A,{color:1===a?"primary":"inherit"})}),(0,K.jsx)(Et.A,{primary:"Addresses"})]}),(0,K.jsxs)(dn.A,{selected:2===a,onClick:()=>l(2),sx:{"&.Mui-selected":{bgcolor:"rgba(25, 118, 210, 0.08)",borderLeft:"4px solid",borderColor:"primary.main"}},children:[(0,K.jsx)(kt.A,{children:(0,K.jsx)(Ut.A,{color:2===a?"primary":"inherit"})}),(0,K.jsx)(Et.A,{primary:"Settings"})]})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:9,children:(0,K.jsxs)(A.A,{sx:{height:"100%"},children:[0===a&&(0,K.jsx)(ue.A,{sx:{height:"100%"},children:(0,K.jsxs)(he.A,{children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,K.jsx)(an.A,{sx:{width:100,height:100,bgcolor:"primary.main",fontSize:"2.5rem",mr:3},children:e?.firstName?.[0]}),(0,K.jsxs)(A.A,{children:[(0,K.jsxs)(m.A,{variant:"h5",gutterBottom:!0,children:[e?.firstName," ",e?.lastName]}),(0,K.jsxs)(ln.A,{direction:"row",spacing:2,alignItems:"center",children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(mr.A,{sx:{mr:1,color:"text.secondary"}}),(0,K.jsx)(m.A,{color:"text.secondary",children:e?.email})]}),e?.mobile&&(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(ur.A,{sx:{mr:1,color:"text.secondary"}}),(0,K.jsx)(m.A,{color:"text.secondary",children:e.mobile})]})]})]})]}),(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Referral Program"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:2},children:[(0,K.jsx)(p.A,{fullWidth:!0,value:M,InputProps:{readOnly:!0,endAdornment:(0,K.jsx)(je.A,{title:v?"Copied!":"Copy referral link",children:(0,K.jsx)(le.A,{onClick:_,children:(0,K.jsx)(cn.A,{})})})}}),(0,K.jsx)(j.A,{variant:"contained",startIcon:(0,K.jsx)(xn.A,{}),onClick:_,children:"Share"})]})]})}),1===a&&(0,K.jsx)(ue.A,{sx:{height:"100%"},children:(0,K.jsxs)(he.A,{children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,K.jsx)(m.A,{variant:"h6",children:"My Addresses"}),(0,K.jsx)(j.A,{variant:"contained",startIcon:(0,K.jsx)(ge.A,{}),onClick:()=>$(!0),children:"Add Address"})]}),P?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",p:4},children:(0,K.jsx)(y.A,{})}):I.length>0?(0,K.jsx)(xe.Ay,{container:!0,spacing:2,children:I.map((e=>(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:6,children:(0,K.jsxs)(te.A,{elevation:2,sx:{p:2,position:"relative",border:e.isPrimary?"2px solid":"1px solid",borderColor:e.isPrimary?"primary.main":"divider"},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[(0,K.jsx)(m.A,{variant:"subtitle2",color:"primary",children:e.isPrimary?"Primary Address":"Secondary Address"}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(le.A,{size:"small",onClick:()=>(e=>{L(e),R(e.address),z(e.isPrimary),$(!0)})(e),children:(0,K.jsx)(rr.A,{fontSize:"small"})}),(0,K.jsx)(le.A,{size:"small",onClick:()=>(async e=>{if(window.confirm("Are you sure you want to delete this address?"))try{await k(e)}catch(e){alert("Failed to delete address. Please try again.")}})(e.id),children:(0,K.jsx)(gr.A,{fontSize:"small"})})]})]}),(0,K.jsx)(m.A,{variant:"body2",children:e.address})]})},e.id)))}):(0,K.jsx)(X.A,{severity:"info",sx:{mt:2},children:"You don't have any addresses yet. Add one to get started!"})]})}),2===a&&(0,K.jsx)(ue.A,{sx:{height:"100%"},children:(0,K.jsxs)(he.A,{children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Account Settings"}),(0,K.jsxs)(ln.A,{spacing:3,children:[(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Notification Preferences"}),(0,K.jsx)(on.A,{control:(0,K.jsx)(Nr.A,{defaultChecked:!0}),label:"Email notifications for orders"}),(0,K.jsx)(on.A,{control:(0,K.jsx)(Nr.A,{defaultChecked:!0}),label:"SMS notifications for delivery updates"})]}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Privacy Settings"}),(0,K.jsx)(on.A,{control:(0,K.jsx)(Nr.A,{defaultChecked:!0}),label:"Share order history with delivery partners"})]}),(0,K.jsx)(A.A,{children:(0,K.jsx)(j.A,{variant:"outlined",color:"error",startIcon:(0,K.jsx)(Nt.A,{}),onClick:N,sx:{mt:2},children:"Logout"})})]})]})})]})})]}),(0,K.jsxs)(Pe.A,{open:E,onClose:()=>$(!1),fullWidth:!0,children:[(0,K.jsx)(De.A,{children:W?"Edit Address":"Add Address"}),(0,K.jsx)(Fe.A,{children:(0,K.jsxs)(ln.A,{spacing:2,mt:1,children:[(0,K.jsx)(p.A,{label:"Address",fullWidth:!0,multiline:!0,rows:3,value:q,onChange:e=>R(e.target.value)}),(0,K.jsx)(on.A,{control:(0,K.jsx)(Nr.A,{checked:T,onChange:e=>z(e.target.checked)}),label:"Set as Primary Address"})]})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>$(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:async()=>{if(O?.id){B(!0);try{W?await F(W.id,q,T):await D(q,O.id,T),$(!1),L(null),R(""),z(!1)}catch(e){alert("Failed to save address. Please try again.")}finally{B(!1)}}else alert("Could not save address: user information not available")},variant:"contained",disabled:!q||U,children:U?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(y.A,{size:20,sx:{mr:1}})," Saving..."]}):"Save"})]})]})]})},mn=()=>{const e=(0,d.Zp)();return(0,K.jsx)(h.A,{maxWidth:"md",children:(0,K.jsx)(A.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,K.jsxs)(te.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,K.jsx)(m.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,K.jsx)(m.A,{variant:"body1",color:"text.secondary",paragraph:!0,children:"The page you are looking for does not exist or is not available."}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(He),children:"Go to Dashboard"})]})})})},hn=()=>{const e=(0,d.Zp)();return(0,K.jsx)(Hr,{children:(0,K.jsx)(h.A,{maxWidth:"md",children:(0,K.jsx)(A.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,K.jsxs)(te.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,K.jsx)(m.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,K.jsx)(m.A,{variant:"body1",color:"text.secondary",paragraph:!0,children:"The page you are looking for does not exist or is not available in the Store Manager section."}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(He),children:"Go to Dashboard"})]})})})})},An=()=>{const e=(0,d.Zp)(),{user:t,setUser:r}=V(),[n,i]=(0,x.useState)(!0),a=(0,be.A)();return(0,x.useEffect)((()=>{(async()=>{try{const t=await(0,Be.$)();if(t?.tokens?.idToken){const n=t.tokens.idToken.payload.sub,s=t.tokens.idToken.payload["custom:role"]?.toLowerCase();r({id:n,role:s}),e(`/${s}`)}}catch(e){}finally{i(!1)}})()}),[r,e]),n?(0,K.jsx)(ne,{}):(0,K.jsx)(A.A,{sx:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"background.default",position:"relative",overflow:"hidden","&::before":{content:'""',position:"absolute",top:0,left:0,right:0,bottom:0,background:"linear-gradient(135deg, rgba(255,107,107,0.1) 0%, rgba(255,107,107,0.05) 100%)",zIndex:0}},children:(0,K.jsxs)(te.A,{elevation:0,sx:{width:"100%",maxWidth:560,borderRadius:4,p:{xs:3,sm:4,md:6},bgcolor:"background.paper",boxShadow:"0 8px 32px rgba(0,0,0,0.08)",position:"relative",zIndex:1,backdropFilter:"blur(10px)",border:"1px solid rgba(255,255,255,0.2)"},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,K.jsx)(m.A,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:"Welcome Back"}),(0,K.jsx)(m.A,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"Sign in to continue your journey with us"})]}),(0,K.jsx)(ct,{}),(0,K.jsxs)(A.A,{sx:{mt:4,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:[(0,K.jsx)(s.N_,{to:"/forgot-password",style:{textDecoration:"none",color:a.palette.primary.main,fontWeight:500,transition:"all 0.2s ease","&:hover":{textDecoration:"underline",opacity:.8}},children:"Forgot Password?"}),(0,K.jsxs)(m.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:["Don't have an account?"," ",(0,K.jsx)(s.N_,{to:"/signup",style:{textDecoration:"none",color:a.palette.primary.main,fontWeight:500,transition:"all 0.2s ease","&:hover":{textDecoration:"underline",opacity:.8}},children:"Sign Up"})]})]})]})})};var jn=r(420),pn=r(2223),gn=r(364),yn=r(2882),vn=r(5873);const bn=e=>{let{store:t,isSelected:r,onSelect:n}=e;const s=t.isActive;return(0,K.jsx)(te.A,{elevation:0,sx:{mb:2,borderRadius:2,overflow:"hidden",transition:"all 0.2s ease",border:"1px solid",borderColor:r?"primary.main":s?"rgba(0, 0, 0, 0.08)":"rgba(211, 47, 47, 0.3)",backgroundColor:s?"transparent":"rgba(0, 0, 0, 0.01)","&:hover":{transform:s?"translateY(-2px)":"none",boxShadow:s?2:0}},children:(0,K.jsx)(Ft.Ay,{disablePadding:!0,children:(0,K.jsx)(dn.A,{onClick:()=>s&&n(t),selected:r,disabled:!s,sx:{p:0,cursor:s?"pointer":"not-allowed"},children:(0,K.jsx)(A.A,{sx:{width:"100%"},children:(0,K.jsxs)(A.A,{sx:{p:2,backgroundColor:r?"rgba(0, 0, 0, 0.02)":"transparent"},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"flex-start",mb:1},children:[(0,K.jsx)(an.A,{sx:{bgcolor:s?r?"primary.main":"grey.300":"rgba(211, 47, 47, 0.1)",mr:2,color:s?"inherit":"error.main"},children:s?(0,K.jsx)(jn.A,{}):(0,K.jsx)(vn.A,{})}),(0,K.jsxs)(A.A,{sx:{flex:1},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[(0,K.jsx)(m.A,{fontWeight:600,fontSize:"1.1rem",color:"text.primary",children:t.name}),!s&&(0,K.jsx)(fe.A,{label:"Offline",size:"small",sx:{height:20,fontSize:"0.75rem",backgroundColor:"rgba(211, 47, 47, 0.1)",color:"error.main",fontWeight:500}})]}),(!s||t.description)&&(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"flex-start",mb:1,backgroundColor:s?"transparent":"rgba(0, 0, 0, 0.02)",p:s?0:1,borderRadius:1},children:[(0,K.jsx)(yn.A,{sx:{fontSize:"0.9rem",color:s?"text.secondary":"error.main",mr:.5,mt:.2}}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{fontStyle:s?"normal":"italic",fontWeight:s?400:500},children:t.description||"Store timings not available"})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(pn.A,{sx:{fontSize:"0.9rem",color:"text.secondary",mr:.5}}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:t.address})]})]})]}),(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:1},children:[t.radius&&(0,K.jsx)(fe.A,{icon:(0,K.jsx)(gn.A,{fontSize:"small"}),label:`${t.radius} mi radius`,size:"small",variant:"outlined",color:r?"primary":"default",sx:{opacity:s?1:.7}}),!s&&(0,K.jsx)(m.A,{variant:"caption",sx:{ml:"auto",color:"error.main",fontStyle:"italic"},children:"Store is currently offline"})]})]})})})})})},fn=e=>{let{availableStores:t,selectedStore:r,handleStoreSelect:n}=e;return(0,K.jsx)(Dt.A,{sx:{mt:1},children:t.map((e=>(0,K.jsx)(bn,{store:e,isSelected:r?.id===e.id,onSelect:n},e.id)))})},In=()=>(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:1},children:[(0,K.jsx)(Lt.A,{}),(0,K.jsx)(m.A,{variant:"h5",fontWeight:600,children:"Select a Store"})]}),Sn=()=>(0,K.jsx)(te.A,{elevation:0,sx:{p:3,textAlign:"center",backgroundColor:"rgba(33, 150, 243, 0.1)",borderRadius:2},children:(0,K.jsx)(m.A,{sx:{fontWeight:500,color:"info.main"},children:"No stores available at the moment."})}),Cn=e=>{let{open:t,onClose:r}=e;const{selectedStore:n,setSelectedStore:s,availableStores:i,clearCart:a}=G();return(0,K.jsx)(ke,{open:t,onClose:r,title:(0,K.jsx)(In,{}),children:0===i.length?(0,K.jsx)(Sn,{}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(m.A,{paragraph:!0,sx:{textAlign:"center",fontWeight:500,color:"text.secondary",mb:3},children:"Please select a store to browse products from"}),(0,K.jsx)(fn,{availableStores:i,selectedStore:n,handleStoreSelect:e=>{localStorage.setItem("selectedStore",JSON.stringify(e)),s(e),a(),r()}})]})})},wn=()=>{const[e,t]=(0,x.useState)(!1),{selectedStore:r,setAvailableStores:n,setSelectedStore:s}=G(),{data:i,isLoading:a,error:l}=(0,u.I)({queryKey:["stores"],queryFn:async()=>await P("\n  query GetAllStores {\n    stores(disabled: false) {\n      id\n      name\n      address\n      description\n      disabled\n      email\n      isActive\n      managerUserId\n      mobile\n      pincodes\n      radius\n      tnc\n      storeDeliveryFee\n      taxPercentage\n    }\n  }\n")});return(0,x.useEffect)((()=>{if(i?.stores&&i.stores.length>0){n(i.stores);const e=localStorage.getItem("selectedStore");if(e){const t=JSON.parse(e);r&&r.id===t.id||s(t)}r||e||t(!0)}}),[i,r,n]),a?(0,K.jsx)(H,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:(0,K.jsx)(ne,{})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Cn,{open:e,onClose:()=>t(!1)}),r&&(0,K.jsx)(Ue,{setStoreModalOpen:()=>t(!0)})]})};var Pn=r(7483),Dn=r(8211),Fn=r(5916),kn=r(9311);const En=e=>{let{value:t,onChange:r,onValidAddress:n}=e;const s=(0,x.useRef)(null),i=(0,x.useRef)(null),[a,l]=(0,x.useState)(!1);return(0,x.useEffect)((()=>{if(window.google&&window.google.maps&&i.current){const e=new window.google.maps.places.Autocomplete(i.current);s.current=e,e.addListener("place_changed",(()=>{const t=e.getPlace();t&&t.formatted_address?(r(t.formatted_address),l(!0),n(!0)):(l(!1),n(!1))}))}}),[t,n]),(0,x.useEffect)((()=>{""===t&&(l(!1),n(!1))}),[t,n]),(0,K.jsx)(p.A,{inputRef:i,label:"Address",fullWidth:!0,multiline:!0,rows:3,value:t,error:!a,helperText:a?"":"Please select a valid address from the suggestions.",onChange:e=>{r(e.target.value),l(!1),n(!1)}})},$n=e=>{let{size:t=24,sx:r}=e;return(0,K.jsx)(y.A,{size:t,sx:{color:"inherit",...r}})},Wn=e=>{let{userProfile:t,onPhoneUpdate:r}=e;const[n,s]=(0,x.useState)(!1),[i,a]=(0,x.useState)(""),[l,o]=(0,x.useState)(""),{mutate:d,isPending:c}=(0,ir.n)({mutationFn:e=>P("\n  mutation UpdateSecondaryPhone($userId: Int!, $secondaryPhone: String) {\n    updateSecondaryPhone(userId: $userId, secondaryPhone: $secondaryPhone) {\n      active\n    }\n  }\n",e),onSuccess:()=>{r(),s(!1),a(""),o("")},onError:e=>{o("Failed to update phone number. Please try again.")}});return t?(0,K.jsx)(A.A,{sx:{mb:3},children:n?(0,K.jsxs)(te.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(ur.A,{color:"primary"}),(0,K.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:t.secondaryPhone?"Update Number":"Add Number"})]}),(0,K.jsx)(p.A,{size:"small",value:i,onChange:e=>{const t=e.target.value.replace(/\D/g,"").slice(0,10);a(t),o("")},placeholder:"Enter 10-digit number",error:!!l,helperText:l,InputProps:{startAdornment:(0,K.jsx)(m.A,{sx:{mr:1},children:"+1"})}}),(0,K.jsxs)(A.A,{sx:{display:"flex",gap:1},children:[(0,K.jsx)(j.A,{variant:"contained",size:"small",onClick:()=>{10===i.length?d({userId:t.id,secondaryPhone:i}):o("Please enter a valid 10-digit phone number")},disabled:c||10!==i.length,startIcon:c?(0,K.jsx)($n,{size:20}):(0,K.jsx)(ur.A,{}),children:c?"Saving...":"Save"}),(0,K.jsx)(j.A,{variant:"outlined",size:"small",onClick:()=>{s(!1),a(""),o("")},children:"Cancel"})]})]}):(0,K.jsxs)(te.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(ur.A,{color:"primary"}),(0,K.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Secondary Contact"}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"(Update if you want to change)"})]}),t.secondaryPhone?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(m.A,{variant:"body1",children:["+1 ",t.secondaryPhone]}),(0,K.jsx)(j.A,{variant:"outlined",size:"small",onClick:()=>s(!0),startIcon:(0,K.jsx)(ur.A,{}),sx:{alignSelf:"flex-start"},children:"Change Number"})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"No secondary number added"}),(0,K.jsx)(j.A,{variant:"outlined",size:"small",onClick:()=>s(!0),startIcon:(0,K.jsx)(ur.A,{}),sx:{alignSelf:"flex-start"},children:"Add Number"})]})]})}):null},Ln=()=>{const{cart:e,removeFromCart:t,addToCart:r,cartTotal:n,clearCart:i,selectedStore:l,getCartTotals:o,setTipAmount:c}=G(),[u,h]=(0,x.useState)(""),[g,y]=(0,x.useState)(!1),[v,b]=(0,x.useState)(""),{userProfile:f,fetchUserProfile:I,isProfileLoading:S,setModalOpen:C,setCurrentForm:w}=V(),D=(0,d.Zp)(),F=(0,a.jE)(),[k,E]=(0,x.useState)(0),[$,W]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{const e=await(0,Be.$)(),t=e?.tokens?.idToken?.payload?.sub;t&&await I(t)})()}),[I]);const{addresses:L,selectedAddressId:q,setSelectedAddressId:R,fetchAddresses:T,isLoading:z,createAddress:U}=Y(),[B,O]=(0,x.useState)(!1),[N,M]=(0,x.useState)(""),[_,H]=(0,x.useState)(!1),[Q,J]=(0,x.useState)(!1),[Z,ee]=(0,x.useState)(!1),{subtotal:re,deliveryFee:ne,taxAmount:se,taxPercentage:ie,tipAmount:ae,total:oe}=(Object.values(e).reduce(((e,t)=>e+(t.quantity||0)),0),o());(0,x.useEffect)((()=>{f?.id&&T(f.id)}),[f?.id,T]),(0,x.useEffect)((()=>{}),[L,q]);const{mutate:ce,isPending:me}=(0,ir.n)({mutationKey:["createOrder"],mutationFn:async e=>{const t=G.getState().selectedStore;return P("\n  mutation CreateOrder(\n    $userId: Int!\n    $addressId: Int!\n    $storeId: Int!\n    $productItems: [OrderItemInput!]!\n    $totalAmount: Float!\n    $orderTotalAmount: Float!\n    $deliveryFee: Float\n    $tipAmount: Float\n    $taxAmount: Float\n    $deliveryInstructions: String\n  ) {\n    createOrder(\n      userId: $userId\n      addressId: $addressId\n      storeId: $storeId\n      productItems: $productItems\n      totalAmount: $totalAmount\n      orderTotalAmount: $orderTotalAmount\n      deliveryFee: $deliveryFee\n      tipAmount: $tipAmount\n      taxAmount: $taxAmount\n      deliveryInstructions: $deliveryInstructions\n    ) {\n      id\n      status\n      totalAmount\n      orderTotalAmount\n      deliveryFee\n      tipAmount\n      taxAmount\n      deliveryInstructions\n      deliveryDate\n      address {\n        id\n        address\n      }\n      orderItems {\n        edges {\n          node {\n            id\n            quantity\n            orderAmount\n            product {\n              id\n              name\n            }\n          }\n        }\n      }\n    }\n  }\n",{...e,storeId:t.id})},onSuccess:e=>{e.errors?b("Failed to place order. Please try again."):(i(),y(!0),setTimeout((()=>{y(!1),D("/")}),2e3),F.invalidateQueries(["userAddresses",f.id]))},onError:e=>{b("Failed to place order. Please try again.")}});return(0,K.jsxs)(A.A,{sx:{padding:3},children:[(0,K.jsxs)(m.A,{variant:"h4",component:"h1",gutterBottom:!0,sx:{fontWeight:600,color:"primary.main",mb:4,display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(Sr.A,{})," Your Shopping Cart"]}),g?(0,K.jsx)(X.A,{severity:"success",sx:{mb:3},children:"Order placed successfully!"}):(0,K.jsxs)(xe.Ay,{container:!0,spacing:3,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:8,children:(0,K.jsxs)(te.A,{elevation:2,sx:{p:3,mb:3},children:[v&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:2},children:v}),Object.values(e).length>0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(m.A,{variant:"h6",sx:{mb:2,fontWeight:500},children:"Cart Items"}),Object.values(e).map((e=>(0,K.jsx)(ue.A,{sx:{mb:2,position:"relative"},children:(0,K.jsx)(he.A,{children:(0,K.jsxs)(xe.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:4,children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:2},children:[(0,K.jsx)("img",{src:e.image,alt:e.name,style:{width:60,height:60,objectFit:"cover",borderRadius:8}}),(0,K.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:e.name})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:3,children:(0,K.jsxs)(m.A,{color:"text.secondary",children:["$",e.price.toFixed(2)," each"]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:3,children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(le.A,{size:"small",onClick:()=>t(e.id),sx:{border:"1px solid",borderColor:"divider"},children:(0,K.jsx)(pe.A,{fontSize:"small"})}),(0,K.jsx)(m.A,{sx:{minWidth:40,textAlign:"center"},children:e.quantity}),(0,K.jsx)(le.A,{size:"small",onClick:()=>r(e),sx:{border:"1px solid",borderColor:"divider"},children:(0,K.jsx)(ge.A,{fontSize:"small"})})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:2,children:(0,K.jsxs)(m.A,{variant:"subtitle1",sx:{fontWeight:600,textAlign:"right"},children:["$",(e.price*e.quantity).toFixed(2)]})})]})})},e.id)))]}):(0,K.jsxs)(A.A,{sx:{textAlign:"center",py:4},children:[(0,K.jsx)(Sr.A,{sx:{fontSize:60,color:"text.secondary",mb:2}}),(0,K.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"Your cart is empty"}),(0,K.jsx)(j.A,{variant:"contained",component:s.N_,to:"/",startIcon:(0,K.jsx)(Sr.A,{}),children:"Continue Shopping"})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsxs)(te.A,{elevation:2,sx:{p:3,position:"sticky",top:24},children:[(0,K.jsx)(m.A,{variant:"h6",sx:{mb:3,fontWeight:500},children:"Order Summary"}),f&&(0,K.jsx)(A.A,{sx:{mb:3},children:(0,K.jsx)(Wn,{userProfile:f,onPhoneUpdate:()=>{(async()=>{const e=await(0,Be.$)(),t=e?.tokens?.idToken?.payload?.sub;t&&await I(t)})()}})}),(0,K.jsxs)(A.A,{sx:{mt:3},children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Order Summary"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,K.jsx)(m.A,{children:"Subtotal"}),(0,K.jsxs)(m.A,{children:["$",re.toFixed(2)]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,K.jsx)(m.A,{children:"Delivery Fee"}),(0,K.jsxs)(m.A,{children:["$",ne.toFixed(2)]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Tax Rate"}),(0,K.jsxs)(m.A,{children:[ie.toFixed(1),"%"]})]}),(0,K.jsxs)(A.A,{sx:{textAlign:"right"},children:[(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Tax Amount"}),(0,K.jsxs)(m.A,{children:["$",se.toFixed(2)]})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(A.A,{sx:{mb:2},children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Add Tip"}),(0,K.jsxs)(Pn.A,{value:k,exclusive:!0,onChange:(e,t)=>{if(null!==t){E(t),W("");c(re*t/100)}},"aria-label":"tip percentage",size:"small",fullWidth:!0,sx:{mb:1},children:[(0,K.jsx)(Dn.A,{value:0,"aria-label":"no tip",children:"No Tip"}),(0,K.jsx)(Dn.A,{value:10,"aria-label":"10%",children:"10%"}),(0,K.jsx)(Dn.A,{value:15,"aria-label":"15%",children:"15%"}),(0,K.jsx)(Dn.A,{value:20,"aria-label":"20%",children:"20%"})]}),(0,K.jsx)(p.A,{fullWidth:!0,size:"small",label:"Custom Tip Amount",type:"number",value:$,onChange:e=>{const t=e.target.value;W(t),E(0);const r=parseFloat(t)||0;c(r)},InputProps:{startAdornment:(0,K.jsx)(m.A,{sx:{mr:1},children:"$"})},placeholder:"Enter custom amount",sx:{mt:1}})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,K.jsx)(m.A,{children:"Tip Amount"}),(0,K.jsxs)(m.A,{children:["$",ae.toFixed(2)]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(Pt.A,{})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,K.jsx)(m.A,{variant:"h6",children:"Total"}),(0,K.jsxs)(m.A,{variant:"h6",children:["$",oe.toFixed(2)]})]})})]})]}),f&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,K.jsx)(nr.A,{})," Delivery Address"]}),S?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,K.jsx)($n,{size:24})}):(0,K.jsxs)(A.A,{children:[(0,K.jsxs)(Jt.A,{fullWidth:!0,sx:{mb:2},children:[(0,K.jsx)(Zt.A,{children:"Select Address"}),z?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,K.jsx)($n,{size:24})}):(0,K.jsx)(Xt.A,{value:q||"",onChange:e=>R(e.target.value),children:L&&L.length>0?L.map((e=>(0,K.jsxs)(de.A,{value:e.id,children:[e.address," ",e.isPrimary?"(Primary)":""]},e.id))):(0,K.jsx)(de.A,{disabled:!0,children:"No addresses available"})})]}),(0,K.jsx)(j.A,{fullWidth:!0,variant:"outlined",startIcon:B?(0,K.jsx)(Fn.A,{}):(0,K.jsx)(kn.A,{}),onClick:()=>O(!B),sx:{mb:2},children:B?"Cancel":"Add New Address"}),(0,K.jsx)(Jr.A,{in:B,children:(0,K.jsx)(A.A,{sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:1},children:(0,K.jsxs)(ln.A,{spacing:2,children:[(0,K.jsx)(En,{value:N,onChange:M,onValidAddress:ee}),(0,K.jsx)(on.A,{control:(0,K.jsx)(Nr.A,{checked:_,onChange:e=>H(e.target.checked)}),label:"Set as Primary Address"}),(0,K.jsx)(j.A,{variant:"contained",onClick:async()=>{if(N.trim()){J(!0);try{await U(N,f.id,_),O(!1),M(""),H(!1),F.invalidateQueries(["userAddresses",f.id])}catch(e){b("Failed to add address. Please try again.")}finally{J(!1)}}else b("Please enter a valid address")},disabled:!N.trim()||Q||!Z,startIcon:Q?(0,K.jsx)($n,{size:20}):(0,K.jsx)(xr.A,{}),children:Q?"Adding...":"Add Address"})]})})})]})]}),f&&(0,K.jsxs)(A.A,{sx:{mb:3},children:[(0,K.jsx)(m.A,{variant:"subtitle1",sx:{mb:2},children:"Delivery Instructions"}),(0,K.jsx)(p.A,{fullWidth:!0,multiline:!0,rows:2,value:u,onChange:e=>h(e.target.value),placeholder:"Add any special instructions for delivery..."})]}),f?(0,K.jsx)(j.A,{fullWidth:!0,variant:"contained",size:"large",onClick:async()=>{if(b(""),!q)return void b("Please select a delivery address");const t=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity}))),{subtotal:r,deliveryFee:n,taxAmount:s,tipAmount:i,total:a}=o();ce({userId:f.id,addressId:q,storeId:l.id,productItems:t,totalAmount:r,orderTotalAmount:a,deliveryFee:n,tipAmount:i,taxAmount:s,deliveryInstructions:u})},disabled:0===Object.values(e).length||me||!q||S,startIcon:me?(0,K.jsx)($n,{size:20}):(0,K.jsx)(zt.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:me?"Processing...":"Place Order"}):(0,K.jsx)(j.A,{fullWidth:!0,variant:"contained",size:"large",onClick:()=>{C(!0),w("login")},startIcon:(0,K.jsx)(Sr.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"Login to Continue"})]})})]})]})};var qn=r(6099),Rn=r(1309);const Tn=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(e);(0,r(5737).D)();const zn=[{value:"PENDING",label:"Pending",color:"warning"},{value:"ORDER_PLACED",label:"Order Placed",color:"info"},{value:"ACCEPTED",label:"Accepted",color:"primary"},{value:"READY_FOR_DELIVERY",label:"Ready for Delivery",color:"success"},{value:"SCHEDULED",label:"Scheduled",color:"info"},{value:"PICKED_UP",label:"Picked Up",color:"info"},{value:"DELIVERED",label:"Delivered",color:"success"},{value:"CANCELLED",label:"Cancelled",color:"error"}],Un="\n  mutation UpdateOrderItems($orderId: Int!, $orderItemUpdates: [OrderItemUpdateInput!]!, $totalAmount: Float!, $orderTotalAmount: Float!, $taxAmount: Float!) {\n    updateOrderItems(\n      orderId: $orderId,\n      orderItemUpdates: $orderItemUpdates,\n      totalAmount: $totalAmount,\n      orderTotalAmount: $orderTotalAmount,\n      taxAmount: $taxAmount\n    ) {\n      id\n      orderItems {\n        edges {\n          node {\n            id\n            quantity\n            orderAmount\n            productId\n            updatedOrderitemsId\n          }\n        }\n      }\n      totalAmount\n      orderTotalAmount\n      taxAmount\n    }\n  }\n",Bn=()=>{const{userProfile:e}=V(),[t,r]=(0,x.useState)(""),[n,s]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),[l,o]=(0,x.useState)(!1),[d,c]=(0,x.useState)(null),[h,b]=(0,x.useState)(""),[f,I]=(0,x.useState)(""),[S,C]=(0,x.useState)(""),[w,W]=(0,x.useState)("ALL"),[L,q]=(0,x.useState)("createdAt"),[R,T]=(0,x.useState)("desc"),[z,U]=(0,x.useState)(0),[B,O]=(0,x.useState)(10),[N,M]=(0,x.useState)(""),[_,Y]=(0,x.useState)(""),[G,H]=(0,x.useState)(""),[Q,J]=(0,x.useState)(""),[Z,ee]=(0,x.useState)({open:!1,message:"",severity:"info"}),[re,ne]=(0,x.useState)(!1),[se,ie]=(0,x.useState)(null),[ae,oe]=(0,x.useState)(1);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,it.T)();r(e.sub)}catch(e){}})()}),[]);const{data:ce,isLoading:me}=(0,u.I)({queryKey:["getUserProfile",t],queryFn:async()=>await P(F,{userId:t}),enabled:!!t}),Ae=ce?.getUserProfile?.stores?.edges?.[0]?.node?.id,pe=ce?.getUserProfile?.id,{data:ge,isLoading:ye,error:ve,refetch:be}=(0,u.I)({queryKey:["storeDrivers",Ae],queryFn:async()=>await P(E,{storeId:Ae}),enabled:!!Ae}),{data:Ie,isLoading:Se,error:Ce,refetch:we}=(0,u.I)({queryKey:["storeOrders",Ae],queryFn:async()=>(await P(k,{storeId:Ae})).getOrdersByStore||[],enabled:!!Ae}),ke=(0,ir.n)({mutationFn:async e=>await P(D,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onSuccess:()=>{we(),a(!1),c(null),b(""),Y(""),H(""),J("")},onError:e=>{I(e.message)}}),Ee=(0,ir.n)({mutationFn:async e=>{const{orderId:t,itemId:r,quantity:n,price:s}=e,i=Ie.find((e=>e.id===t));if(!i)throw new Error("Order not found");const a=ce?.getUserProfile?.stores?.edges?.[0]?.node?.taxPercentage||0,l=new Map;i.orderItems.edges.forEach((e=>{let{node:t}=e;const r=t.productId;(!l.has(r)||t.id>l.get(r).id)&&l.set(r,t)}));if(!Array.from(l.values()).some((e=>e.id===parseInt(r)?n>0:e.quantity>0)))return await P(Un,{orderId:parseInt(t),orderItemUpdates:[{orderItemId:parseInt(r),quantityChange:n-se.quantity}],totalAmount:0,orderTotalAmount:0,taxAmount:0});let o=0;l.forEach((e=>{if(e.id===parseInt(r))o+=n*s;else{const t=e.product?.inventoryItems?.edges[0]?.node?.price||0;o+=e.quantity*t}}));const d=o*a/100,c=o+d+(i.deliveryFee||0)+(i.tipAmount||0),x=n-se.quantity;return await P(Un,{orderId:parseInt(t),orderItemUpdates:[{orderItemId:parseInt(r),quantityChange:x}],totalAmount:o,orderTotalAmount:c,taxAmount:d})},onSuccess:()=>{we(),ne(!1),ie(null),oe(1)},onError:e=>{I(e.message)}}),$e=e=>{L===e?T("asc"===R?"desc":"asc"):(q(e),T("asc"))},We=x.useMemo((()=>{if(!Ie)return[];let e=[...Ie];return S&&(e=e.filter((e=>e.id.toString().includes(S)||(e.deliveryInstructions||"").toLowerCase().includes(S.toLowerCase())))),"ALL"!==w&&(e=e.filter((e=>e.status===w))),e.sort(((e,t)=>{let r=0;return r="totalAmount"===L?e[L]-t[L]:String(e[L]||"").localeCompare(String(t[L]||"")),"asc"===R?r:-r})),e}),[Ie,S,w,L,R]),Le=x.useMemo((()=>{const e=z*B;return We.slice(e,e+B)}),[We,z,B]),qe=e=>{if(!e?.edges?.length)return null;const t=new Map;e.edges.forEach((e=>{let{node:r}=e;const n=r.productId;(!t.has(n)||r.id>t.get(n).id)&&t.set(n,r)}));return Array.from(t.values())},Re=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e);return me||Se||ye?(0,K.jsx)(Hr,{children:(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,K.jsx)(y.A,{})})}):Ce||ve?(0,K.jsx)(Hr,{children:(0,K.jsx)(X.A,{severity:"error",sx:{mb:2},children:Ce?.message||ve?.message||"An error occurred"})}):(0,K.jsx)(Hr,{children:(0,K.jsxs)(A.A,{sx:{p:3},children:[(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Orders"}),f&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:2},children:f}),(0,K.jsx)(ue.A,{sx:{mb:3},children:(0,K.jsx)(he.A,{children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsx)(p.A,{fullWidth:!0,placeholder:"Search orders...",value:S,onChange:e=>C(e.target.value),InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(sr.A,{})})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Filter by Status",value:w,onChange:e=>W(e.target.value),InputProps:{startAdornment:(0,K.jsx)(g.A,{position:"start",children:(0,K.jsx)(qn.A,{})})},children:[(0,K.jsx)(de.A,{value:"ALL",children:"All Statuses"}),zn.map((e=>(0,K.jsx)(de.A,{value:e.value,children:e.label},e.value)))]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsxs)(m.A,{variant:"body2",color:"textSecondary",children:["Total Orders: ",We.length]})})]})})}),0===We.length?(0,K.jsx)(X.A,{severity:"info",sx:{mb:2},children:"No orders found."}):(0,K.jsxs)(Mt.A,{component:te.A,children:[(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>$e("id"),children:["Order ID",(0,K.jsx)(Rn.A,{sx:{ml:1,transform:"id"===L&&"desc"===R?"rotate(180deg)":"none"}})]})}),(0,K.jsx)(Gt.A,{children:"Delivery Instructions"}),(0,K.jsx)(Gt.A,{children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>$e("totalAmount"),children:["Total",(0,K.jsx)(Rn.A,{sx:{ml:1,transform:"totalAmount"===L&&"desc"===R?"rotate(180deg)":"none"}})]})}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{children:"Actions"}),(0,K.jsx)(Gt.A,{})]})}),(0,K.jsx)(Kt.A,{children:Le.map((e=>{return(0,K.jsxs)(x.Fragment,{children:[(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e.id}),(0,K.jsx)(Gt.A,{children:e.deliveryInstructions||"N/A"}),(0,K.jsxs)(Gt.A,{children:["$",e.orderTotalAmount]}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:zn.find((t=>t.value===e.status))?.label||e.status,color:(t=e.status,zn.find((e=>e.value===t))?.color||"default"),size:"small"})}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(je.A,{title:"Edit Order",children:(0,K.jsx)(le.A,{size:"small",onClick:()=>(e=>{c(e),b(e.status),Y(e.deliveryInstructions||""),a(!0)})(e),disabled:!Re(e.status),children:(0,K.jsx)(rr.A,{})})}),(0,K.jsx)(je.A,{title:"Cancel Order",children:(0,K.jsx)(le.A,{size:"small",onClick:()=>(e=>{c(e),o(!0)})(e),disabled:!Re(e.status),children:(0,K.jsx)(fr.A,{})})}),(0,K.jsx)(je.A,{title:"Upload File",children:(0,K.jsx)(le.A,{size:"small",onClick:()=>(async e=>{const t=document.createElement("input");t.type="file",t.accept="*/*",t.onchange=async()=>{try{const r=t.files[0];if(!r)return;const n=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",s=await fetch(`${n}/s3/generate-upload-url?file_name=${encodeURIComponent(r.name)}&order_id=${e.id}`);if(!s.ok)throw new Error("Failed to get upload URL");const{upload_url:i,content_type:a,file_name:l,key:o}=await s.json(),d=await fetch(i,{method:"PUT",headers:{"Content-Type":a},body:r});if(!d.ok)throw await d.text(),new Error("Failed to upload file");if(!(await fetch(`${n}/orders/${e.id}/set-bill-url?file_name=${encodeURIComponent(l)}`,{method:"POST"})).ok)throw new Error("Failed to update bill URL");(await fetch(`${n}/s3/generate-view-url?bill_key=${encodeURIComponent(o)}`)).ok?ee({open:!0,message:"File uploaded and verified successfully!",severity:"success"}):ee({open:!0,message:"File uploaded but verification failed. Please try viewing the file.",severity:"warning"})}catch(e){ee({open:!0,message:"Failed to upload file. Please try again.",severity:"error"})}},t.click()})(e),disabled:!Re(e.status),children:(0,K.jsx)(yr.A,{})})}),(0,K.jsx)(je.A,{title:"View File",children:(0,K.jsx)(le.A,{size:"small",onClick:()=>(async e=>{try{const t=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com";let r=null,n=null;if(e.bill_url){const s=await fetch(`${t}/s3/generate-view-url?bill_key=${encodeURIComponent(e.bill_url)}`);if(s.ok){const e=await s.json();r=e.view_url,n=e.file_name}}if(!r){const s=[".pdf",".jpg",".jpeg",".png",".docx"];for(const i of s){const s=await fetch(`${t}/s3/generate-view-url?order_id=${e.id}&file_name=receipt${i}`);if(s.ok){const e=await s.json();r=e.view_url,n=e.file_name;break}}}if(!r)return void ee({open:!0,message:"No file found for this order.",severity:"warning"});const s=document.createElement("a");s.href=r,s.target="_blank",s.rel="noopener noreferrer",document.body.appendChild(s),s.click(),document.body.removeChild(s)}catch(e){ee({open:!0,message:"Failed to view file. Please try again.",severity:"error"})}})(e),children:(0,K.jsx)(Cr.A,{})})})]}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(le.A,{size:"small",onClick:()=>s(n===e.id?null:e.id),children:n===e.id?(0,K.jsx)(Fn.A,{}):(0,K.jsx)(kn.A,{})})})]}),n===e.id&&(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:6,children:(0,K.jsx)(A.A,{sx:{p:2},children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Customer Information"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{children:["Email: ",e?.creator?.email||"N/A"]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(m.A,{children:["Phone: ",e?.creator?.mobile||"N/A"]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(m.A,{children:["Delivery Address: ",e?.address?.address||"N/A"]})})]})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Items"}),(0,K.jsxs)(_t.A,{size:"small",children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"Product"}),(0,K.jsx)(Gt.A,{children:"Quantity"}),(0,K.jsx)(Gt.A,{children:"Price"}),(0,K.jsx)(Gt.A,{children:"Total"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:e.orderItems?.edges?.length>0?qe(e.orderItems)?.map((t=>{const r=(n=t,s=e.orderItems.edges,n&&s?s.map((e=>{let{node:t}=e;return t})).filter((e=>e.productId===n.productId)).sort(((e,t)=>e.id-t.id)):[n]);var n,s;const i=t.product?.inventoryItems?.edges[0]?.node?.price||0;return(0,K.jsxs)(x.Fragment,{children:[(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:t.product?.name||"N/A"}),(0,K.jsx)(Gt.A,{children:t.quantity}),(0,K.jsx)(Gt.A,{children:Tn(i)}),(0,K.jsx)(Gt.A,{children:Tn(t.quantity*i)}),(0,K.jsx)(Gt.A,{children:Re(e.status)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(le.A,{size:"small",onClick:()=>{return r=t,n=e.id,ie({...r,orderId:n}),oe(r.quantity),void ne(!0);var r,n},sx:{mr:1},children:(0,K.jsx)(rr.A,{fontSize:"small"})}),(0,K.jsx)(le.A,{size:"small",onClick:()=>{return r=t,n=e.id,ie({...r,orderId:n}),oe(0),void ne(!0);var r,n},color:"error",children:(0,K.jsx)(gr.A,{fontSize:"small"})})]})})]}),r.length>1&&(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:5,children:(0,K.jsxs)(A.A,{sx:{pl:2,py:1},children:[(0,K.jsxs)(m.A,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1},children:["Order Change History (",r.length-1," ","changes)"]}),r.slice(0,-1).map(((e,t)=>(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1,borderRadius:1,mb:1},children:[(0,K.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"100px"},children:["Change ",t+1]}),(0,K.jsxs)(A.A,{sx:{display:"flex",gap:3},children:[(0,K.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,K.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount:"," ",Tn(e.orderAmount)]})]})]},e.id)))]})})})]},t.id)})):(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:5,align:"center",children:"No items found for this order"})})})]})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Summary"}),(0,K.jsx)(A.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:1,children:[(0,K.jsx)(xe.Ay,{item:!0,xs:6,children:(0,K.jsx)(m.A,{children:"Subtotal:"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,K.jsx)(m.A,{children:Tn(e.totalAmount)})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,children:(0,K.jsx)(m.A,{children:"Delivery Fee:"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,K.jsx)(m.A,{children:Tn(e.deliveryFee)})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,children:(0,K.jsx)(m.A,{children:"Tax:"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,K.jsx)(m.A,{children:Tn(e.taxAmount)})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,children:(0,K.jsx)(m.A,{children:"Tip:"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,K.jsx)(m.A,{children:Tn(e.tipAmount)})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(Pt.A,{sx:{my:1}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,children:(0,K.jsx)(m.A,{sx:{fontWeight:"bold"},children:"Total Amount:"})}),(0,K.jsx)(xe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,K.jsx)(m.A,{sx:{fontWeight:"bold"},children:Tn(e.orderTotalAmount)})})]})})]}),e.deliveryInstructions&&(0,K.jsxs)(xe.Ay,{item:!0,xs:12,children:[(0,K.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Delivery Instructions"}),(0,K.jsx)(m.A,{children:e.deliveryInstructions})]})]})})})})]},e.id);var t}))})]}),(0,K.jsx)(v.A,{component:"div",count:We.length,page:z,onPageChange:(e,t)=>{U(t)},rowsPerPage:B,onRowsPerPageChange:e=>{O(parseInt(e.target.value,10)),U(0)},rowsPerPageOptions:[5,10,25,50]})]}),(0,K.jsxs)(Pe.A,{open:i,onClose:()=>a(!1),maxWidth:"sm",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:"Update Order Status"}),(0,K.jsx)(Fe.A,{children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{select:!0,fullWidth:!0,label:"Status",value:h,onChange:e=>b(e.target.value),children:zn.map((e=>(0,K.jsx)(de.A,{value:e.value,children:e.label},e.value)))})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Delivery Instructions",value:_,onChange:e=>Y(e.target.value),multiline:!0,rows:3})}),"READY_FOR_DELIVERY"===h&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,required:!0,children:[(0,K.jsx)(Zt.A,{children:"Delivery Agent"}),(0,K.jsx)(Xt.A,{value:G,onChange:e=>H(e.target.value),label:"Delivery Agent",children:ge?.getStoreDrivers?.map((e=>(0,K.jsxs)(de.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId)))})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:6,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Schedule Time",value:Q,onChange:e=>J(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>a(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:async()=>{try{const e={orderId:d.id,status:h,deliveryInstructions:_};if("READY"===h||"READY_FOR_DELIVERY"===h){if(!G)return void I("Driver ID is required for this status");if(!Q)return void I("Schedule time is required for this status");e.driverId=parseInt(G),e.scheduleTime=Q}await ke.mutateAsync(e)}catch(e){I(e.message)}},variant:"contained",color:"primary",disabled:ke.isLoading,children:ke.isLoading?"Updating...":"Update"})]})]}),(0,K.jsxs)(Pe.A,{open:l,onClose:()=>o(!1),children:[(0,K.jsx)(De.A,{children:"Cancel Order"}),(0,K.jsxs)(Fe.A,{children:[(0,K.jsx)(m.A,{children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,K.jsx)(p.A,{fullWidth:!0,label:"Cancellation Reason",value:N,onChange:e=>M(e.target.value),multiline:!0,rows:3,sx:{mt:2},required:!0})]}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>o(!1),children:"No"}),(0,K.jsx)(j.A,{onClick:async()=>{try{if(!pe)return void I("User profile not found. Please try again.");await P($,{orderId:d.id,cancelMessage:N,cancelledByUserId:pe}),o(!1),M(""),we(),c(null)}catch(e){I(e.message)}},variant:"contained",color:"error",disabled:!N.trim(),children:"Yes, Cancel Order"})]})]}),(0,K.jsxs)(Pe.A,{open:re,onClose:()=>ne(!1),maxWidth:"sm",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:0===ae?"Delete Order Item":"Edit Order Item"}),(0,K.jsx)(Fe.A,{children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsxs)(m.A,{variant:"subtitle1",children:["Product: ",se?.product?.name||"N/A"]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(p.A,{fullWidth:!0,label:"Quantity",type:"number",value:ae,onChange:e=>oe(parseInt(e.target.value)||0),inputProps:{min:0}})})]})}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>ne(!1),children:"Cancel"}),(0,K.jsx)(j.A,{onClick:async()=>{try{await Ee.mutateAsync({orderId:se.orderId,itemId:se.id,quantity:ae,price:se.product?.inventoryItems?.edges[0]?.node?.price||0})}catch(e){I(e.message)}},variant:"contained",color:0===ae?"error":"primary",disabled:Ee.isLoading,children:Ee.isLoading?"Updating...":0===ae?"Delete":"Update"})]})]}),(0,K.jsx)(tr.A,{open:Z.open,autoHideDuration:6e3,onClose:()=>ee({...Z,open:!1}),children:(0,K.jsx)(X.A,{onClose:()=>ee({...Z,open:!1}),severity:Z.severity,sx:{width:"100%"},children:Z.message})})]})})},On=[{value:"PENDING",label:"Pending"},{value:"PROCESSING",label:"Processing"},{value:"READY_FOR_DELIVERY",label:"Ready for Delivery"},{value:"OUT_FOR_DELIVERY",label:"Out for Delivery"},{value:"DELIVERED",label:"Delivered"},{value:"CANCELLED",label:"Cancelled"}],Nn=[{value:"ACTIVE",label:"Active"},{value:"INACTIVE",label:"Inactive"}],Mn=()=>{const{userProfile:e}=V(),[t,r]=(0,x.useState)(null),[n,s]=(0,x.useState)(null),[i,a]=(0,x.useState)({driverStatus:"",orderStatus:"",dateRange:"all"}),[l,o]=(0,x.useState)(!1),[d,c]=(0,x.useState)(null);(0,x.useEffect)((()=>{(async()=>{if(e?.id)try{const t=await P("\n            query GetStoreInfo($managerId: Int!) {\n              storesByManager(managerUserId: $managerId) {\n                id\n                name\n              }\n            }\n          ",{managerId:e.id});t?.storesByManager&&t.storesByManager.length>0?r(t.storesByManager[0].id):c("No store found for this manager")}catch(e){c("Failed to fetch store information")}})()}),[e]);const{data:h,isLoading:g,error:v,refetch:b}=(0,u.I)({queryKey:["driversByStore",t],queryFn:()=>P("\n  query GetStoreDrivers($storeId: Int!) {\n    getStoreDrivers(storeId: $storeId) {\n      id\n      userId\n      driver {\n      id\n      email\n      mobile\n      active\n      referralId\n      referredBy\n    }\n    }\n  }\n",{storeId:t}),enabled:!!t&&l}),{data:f,isLoading:I,error:S,refetch:C}=(0,u.I)({queryKey:["storeOrders",t],queryFn:async()=>(await P(k,{storeId:t})).getOrdersByStore||[],enabled:!!t}),w=(e,t)=>{a((r=>({...r,[e]:t})))},D=e=>({PENDING:"warning",PROCESSING:"info",READY_FOR_DELIVERY:"primary",OUT_FOR_DELIVERY:"secondary",DELIVERED:"success",CANCELLED:"error",ACTIVE:"success",INACTIVE:"error",BUSY:"warning"}[e]||"default"),F=(e,t)=>{if(!e)return[];let r=e.filter((e=>e?.delivery?.driverId===t));if(i.orderStatus&&(r=r.filter((e=>e.status===i.orderStatus))),"all"!==i.dateRange){const e=new Date,t=new Date(e.getFullYear(),e.getMonth(),e.getDate());r=r.filter((e=>{const r=new Date(e.createdAt);switch(i.dateRange){case"today":return r>=t;case"week":const e=new Date(t);return e.setDate(e.getDate()-7),r>=e;case"month":const n=new Date(t);return n.setMonth(n.getMonth()-1),r>=n;default:return!0}}))}return r},E=e=>e?i.driverStatus?e.filter((e=>e.status===i.driverStatus)):e:[],$=g||I,W=v||S||d;return(0,K.jsx)(Hr,{children:(0,K.jsxs)(A.A,{sx:{p:3},children:[(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Delivery Partners"}),d&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:2},children:d}),(0,K.jsxs)(te.A,{sx:{p:3,mb:3},children:[(0,K.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Filters"}),(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:4,children:(0,K.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Driver Status",value:i.driverStatus,onChange:e=>w("driverStatus",e.target.value),children:[(0,K.jsx)(de.A,{value:"",children:"All Statuses"}),Nn.map((e=>(0,K.jsx)(de.A,{value:e.value,children:e.label},e.value)))]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:4,children:(0,K.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Order Status",value:i.orderStatus,onChange:e=>w("orderStatus",e.target.value),children:[(0,K.jsx)(de.A,{value:"",children:"All Statuses"}),On.map((e=>(0,K.jsx)(de.A,{value:e.value,children:e.label},e.value)))]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,sm:4,children:(0,K.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Date Range",value:i.dateRange,onChange:e=>w("dateRange",e.target.value),children:[(0,K.jsx)(de.A,{value:"all",children:"All Time"}),(0,K.jsx)(de.A,{value:"today",children:"Today"}),(0,K.jsx)(de.A,{value:"week",children:"Last 7 Days"}),(0,K.jsx)(de.A,{value:"month",children:"Last 30 Days"})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,children:(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(sr.A,{}),onClick:()=>{o(!0),b(),C()},disabled:!t,children:"Get Data"})})]})]}),$?(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",p:3},children:(0,K.jsx)(y.A,{})}):W?(0,K.jsx)(X.A,{severity:"error",children:v?.message||S?.message||"An error occurred while fetching data"}):l?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(m.A,{variant:"h6",gutterBottom:!0,children:["Delivery Partners (",E(h?.getStoreDrivers||[]).length,")"]}),(0,K.jsx)(Mt.A,{component:te.A,children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"Driver ID"}),(0,K.jsx)(Gt.A,{children:"Name"}),(0,K.jsx)(Gt.A,{children:"Email"}),(0,K.jsx)(Gt.A,{children:"Phone"}),(0,K.jsx)(Gt.A,{children:"Status"}),(0,K.jsx)(Gt.A,{children:"Orders"}),(0,K.jsx)(Gt.A,{})]})}),(0,K.jsxs)(Kt.A,{children:[E(h?.getStoreDrivers||[]).map((e=>(0,K.jsxs)(x.Fragment,{children:[(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e?.userId}),(0,K.jsx)(Gt.A,{children:e.name}),(0,K.jsx)(Gt.A,{children:e?.driver?.email}),(0,K.jsx)(Gt.A,{children:e?.driver?.mobile}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:e?.driver?.active?"Active":"Inactive",color:D(e?.driver?.active),size:"small"})}),(0,K.jsx)(Gt.A,{children:F(f||[],e?.userId).length}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(le.A,{size:"small",onClick:()=>s(n===e?.userId?null:e?.userId),children:n===e?.userId?(0,K.jsx)(en.A,{}):(0,K.jsx)(tn.A,{})})})]}),n===e?.userId&&(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:7,children:(0,K.jsxs)(A.A,{sx:{p:2},children:[(0,K.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:["Orders for ",e.name,":"]}),(0,K.jsxs)(_t.A,{size:"small",children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:"Order ID"}),(0,K.jsx)(Gt.A,{children:"Date"}),(0,K.jsx)(Gt.A,{children:"Customer"}),(0,K.jsx)(Gt.A,{children:"Total"}),(0,K.jsx)(Gt.A,{children:"Status"})]})}),(0,K.jsx)(Kt.A,{children:F(f||[],e?.userId).length>0?F(f||[],e?.userId).map((e=>(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{children:e.id}),(0,K.jsx)(Gt.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,K.jsx)(Gt.A,{children:e.user?.name}),(0,K.jsxs)(Gt.A,{children:["₹",e.totalAmount]}),(0,K.jsx)(Gt.A,{children:(0,K.jsx)(fe.A,{label:On.find((t=>t.value===e.status))?.label||e.status,color:D(e.status),size:"small"})})]},e.id))):(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:5,align:"center",children:"No orders found for this driver with the current filters."})})})]})]})})})]},e?.userId))),0===E(h?.getStoreDrivers||[]).length&&(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{colSpan:7,align:"center",children:"No delivery partners found with the current filters."})})]})]})})]}):(0,K.jsx)(X.A,{severity:"info",children:'Click the "Get Data" button to fetch delivery partners and their orders.'})]})})};var _n=r(9279);const Vn=x.memo((e=>{let{open:t,onClose:r,selectedItem:n,onUpdate:s,isLoading:i}=e;const[a,l]=x.useState(""),[o,d]=x.useState(""),[c,u]=x.useState("");x.useEffect((()=>{n&&(l(n.price?n.price.toString():""),d(n.quantity?n.quantity.toString():""))}),[n]);const h={width:"100%",padding:"8.5px 14px",fontSize:"1rem",borderRadius:"4px",border:"1px solid rgba(0, 0, 0, 0.23)",marginBottom:"16px",outline:"none","&:focus":{borderColor:"#1976d2",borderWidth:"2px"}},p={fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)",marginBottom:"4px",display:"block"};return(0,K.jsxs)(Pe.A,{open:t,onClose:()=>{u(""),r()},maxWidth:"sm",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:"Edit Inventory Item"}),(0,K.jsxs)(Fe.A,{children:[n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[n.product?.image&&(0,K.jsx)(me.A,{component:"img",sx:{width:80,height:80,objectFit:"contain",mr:2},image:n.product.image,alt:n.product.name}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle1",children:(0,K.jsx)("strong",{children:n.product?.name})}),(0,K.jsx)(m.A,{variant:"body2",color:"text.secondary",children:n.product?.category?.name||"Uncategorized"})]})]}),(0,K.jsx)(Pt.A,{sx:{my:2}}),(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)("label",{htmlFor:"edit-price-input",style:p,children:"Price ($)"}),(0,K.jsx)("input",{id:"edit-price-input",type:"number",value:a,onChange:e=>l(e.target.value),min:"0",step:"0.01",style:h}),(0,K.jsx)("label",{htmlFor:"edit-quantity-input",style:p,children:"Quantity"}),(0,K.jsx)("input",{id:"edit-quantity-input",type:"number",value:o,onChange:e=>d(e.target.value),min:"0",style:h})]})]}),c&&(0,K.jsx)(X.A,{severity:"error",sx:{mt:2},children:c})]}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>{u(""),r()},children:"Cancel"}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",onClick:()=>{!a||isNaN(parseFloat(a))||parseFloat(a)<=0?u("Please enter a valid price greater than zero."):!o||isNaN(parseInt(o,10))||parseInt(o,10)<0?u("Please enter a valid quantity (0 or greater)."):(u(""),s({inventoryId:n.id,price:a,quantity:o}))},disabled:i,children:i?(0,K.jsx)(y.A,{size:24}):"Update"})]})]})})),Yn=x.memo((e=>{let{open:t,onClose:r,storeId:n,availableProducts:s,onAdd:i,isLoading:a,errorMessage:l}=e;const[o,d]=(0,x.useState)(null),[c,u]=(0,x.useState)({price:"",quantity:"",size:"",unit:"",searchInput:""}),[m,h]=(0,x.useState)(!1),p=(0,x.useRef)(null),g=e=>{const{name:t,value:r}=e.target;u((e=>({...e,[t]:r})))},v=x.useMemo((()=>s.filter((e=>e.name.toLowerCase().includes(c.searchInput.toLowerCase())))),[s,c.searchInput]),b=()=>{d(null),u({price:"",quantity:"",size:"",unit:"",searchInput:""})};x.useEffect((()=>{t||b()}),[t]);const f={width:"100%",padding:"8.5px 14px",fontSize:"1rem",borderRadius:"4px",border:"1px solid rgba(0, 0, 0, 0.23)",marginBottom:"16px",outline:"none"},I={fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)",marginBottom:"4px",display:"block"};return(0,K.jsxs)(Pe.A,{open:t,onClose:()=>{r(),b()},maxWidth:"sm",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:"Add Product to Inventory"}),(0,K.jsxs)(Fe.A,{children:[(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)("label",{htmlFor:"searchInput",style:I,children:"Search Product"}),(0,K.jsxs)("div",{style:{position:"relative"},children:[(0,K.jsx)("input",{id:"searchInput",name:"searchInput",type:"text",placeholder:"Start typing to search...",value:c.searchInput,onChange:e=>{g(e),h(!0)},onFocus:()=>h(!0),style:f,ref:p}),a&&(0,K.jsx)(y.A,{size:20,style:{position:"absolute",right:"10px",top:"50%",transform:"translateY(-50%)"}})]}),m&&v.length>0&&(0,K.jsx)("div",{style:{position:"absolute",width:p.current?.offsetWidth,zIndex:1300,backgroundColor:"#fff",border:"1px solid rgba(0, 0, 0, 0.23)",borderRadius:"4px",maxHeight:"300px",overflow:"auto"},children:v.map((e=>(0,K.jsxs)("div",{onClick:()=>(e=>{d(e),u((t=>({...t,searchInput:e.name}))),h(!1)})(e),style:{padding:"8px 16px",cursor:"pointer",backgroundColor:o?.id===e.id?"rgba(0, 0, 0, 0.04)":"transparent","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.08)"}},children:[(0,K.jsx)("div",{children:e.name}),(0,K.jsx)("div",{style:{fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)"},children:e.category.name})]},e.id)))})]}),(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)("label",{htmlFor:"price",style:I,children:"Price ($)"}),(0,K.jsx)("input",{id:"price",name:"price",type:"number",value:c.price,onChange:g,min:"0",step:"0.01",style:f})]}),(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)("label",{htmlFor:"quantity",style:I,children:"Quantity"}),(0,K.jsx)("input",{id:"quantity",name:"quantity",type:"number",value:c.quantity,onChange:g,min:"0",style:f})]}),(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)("label",{htmlFor:"size",style:I,children:"Measurement"}),(0,K.jsx)("input",{id:"size",name:"size",type:"number",value:c.size,onChange:g,min:"0",style:f})]}),(0,K.jsxs)(A.A,{sx:{mt:2},children:[(0,K.jsx)("label",{htmlFor:"unit",style:I,children:"Unit"}),(0,K.jsxs)("select",{id:"unit",name:"unit",value:c.unit,onChange:g,style:{...f,backgroundColor:"transparent",appearance:"auto",height:"40px"},children:[(0,K.jsx)("option",{value:"",children:"None"}),(0,K.jsx)("option",{value:"1",children:"Grams (g)"}),(0,K.jsx)("option",{value:"2",children:"Kilograms (kg)"}),(0,K.jsx)("option",{value:"3",children:"Milliliters (ml)"}),(0,K.jsx)("option",{value:"4",children:"Liters (L)"}),(0,K.jsx)("option",{value:"5",children:"Pieces (pcs)"})]})]}),l&&(0,K.jsx)(X.A,{severity:"error",sx:{mt:2},children:l})]}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>{r(),b()},children:"Cancel"}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",onClick:()=>{o&&i({storeId:n,productId:o.id,price:c.price,quantity:c.quantity,size:c.size||null,measurementUnit:c.unit||null})},disabled:a||!o||!c.price||!c.quantity,children:a?(0,K.jsx)(y.A,{size:24}):"Add Product"})]})]})})),Gn=()=>{const[e,t]=(0,x.useState)(""),{userProfile:r,setUserProfile:n}=V(),[s,i]=(0,x.useState)(null),[a,l]=(0,x.useState)(!1),[o,d]=(0,x.useState)(!1),[c,g]=(0,x.useState)(null),[v,b]=(0,x.useState)(""),[f,I]=(0,x.useState)(""),[S,C]=(0,x.useState)(""),[w,D]=(0,x.useState)(!1),[F,k]=(0,x.useState)(10),[E,$]=(0,x.useState)(1),[W]=(0,x.useState)(10),[L,q]=(0,x.useState)("all"),[R,T]=(0,x.useState)([]),[z,U]=(0,x.useState)(!1);(0,x.useRef)(null),(0,x.useRef)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,it.T)();t(e.sub)}catch(e){}})()}),[]);const{data:B,isLoading:O}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const t=await P("\n  query GetUserProfile($userId: String!) {\n    getUserProfile(userId: $userId) {\n      id\n      email\n      mobile\n      active\n      type\n      referralId\n    }\n  }\n",{userId:e});return t?.getUserProfile&&n(t.getUserProfile),t},enabled:!!e}),{data:N,isLoading:M,error:_,refetch:Y}=(0,u.I)({queryKey:["storeWithInventory",r?.id],queryFn:()=>P("\n  query GetStoreWithInventory($managerId: Int!) {\n    storesByManager(managerUserId: $managerId) {\n      id\n      name\n      address\n      radius\n      inventory {\n        edges {\n          node {\n            id\n            quantity\n            price\n            measurement\n            isAvailable\n            isListed\n            updatedAt\n            product {\n              id\n              name\n              description\n              category {\n                id\n                name\n              }\n              image\n            }\n          }\n        }\n      }\n    }\n    products {\n      id\n      name\n      description\n      category {\n        id\n        name\n      }\n    }\n  }\n",{managerId:r?.id}),enabled:!!r?.id});(0,x.useEffect)((()=>{}),[N]);const G=N?.storesByManager&&N.storesByManager[0],H=G?.inventory?.edges?.map((e=>e.node))||[],Q=N?.products||[],J=x.useMemo((()=>H.filter((e=>{const t=""===S||e.product?.name?.toLowerCase().includes(S.toLowerCase())||e.product?.description?.toLowerCase().includes(S.toLowerCase()),r=!w||e.quantity<=F,n="all"===L||e.product?.category?.name===L;return t&&r&&n}))),[H,S,w,F,L]),Z=x.useMemo((()=>J.slice((E-1)*W,E*W)),[J,E,W]);(0,x.useEffect)((()=>{const e=[...new Set(H.map((e=>e.product?.category?.name||"Uncategorized")).filter(Boolean))].sort();JSON.stringify(e)!==JSON.stringify(R)&&T(e)}),[H]);const ee=(0,ir.n)({mutationFn:e=>{let{inventoryId:t,price:r,quantity:n}=e;return P("\n  mutation UpdateInventoryItem($inventoryId: ID!, $price: Float!, $quantity: Int!) {\n    updateInventoryItem(inventoryId: $inventoryId, price: $price, quantity: $quantity) {\n      id\n      price\n      quantity\n      updatedAt\n    }\n  }\n",{inventoryId:t,price:parseFloat(r),quantity:parseInt(n,10)})},onSuccess:()=>{Y(),l(!1),i(null),I("Inventory item updated successfully"),setTimeout((()=>I("")),3e3)},onError:e=>{b(`Error updating inventory: ${e.message}`)}}),re=(0,ir.n)({mutationFn:e=>{let{inventoryId:t}=e;return P("\n  mutation DeleteInventoryItem($inventoryId: ID!) {\n    deleteInventoryItem(inventoryId: $inventoryId) {\n      id\n    }\n  }\n",{inventoryId:t})},onSuccess:()=>{Y(),d(!1),i(null),I("Inventory item deleted successfully"),setTimeout((()=>I("")),3e3)},onError:e=>{b(`Error deleting inventory: ${e.message}`)}}),ne=(0,ir.n)({mutationFn:e=>{let{storeId:t,productId:r,price:n,quantity:s,size:i,measurementUnit:a}=e;return P("\n  mutation AddProductToInventory($storeId: ID!, $productId: ID!, $price: Float!, $quantity: Int!, $size: Float, $measurement_unit: Int) {\n    addProductToInventory(\n      storeId: $storeId\n      productId: $productId\n      price: $price\n      quantity: $quantity\n      size: $size\n      measurement_unit: $measurement_unit\n    ) {\n      id\n      price\n      quantity\n      measurement\n      updatedAt\n      product {\n        id\n        name\n        description\n        category {\n          id\n          name\n        }\n        image\n      }\n    }\n  }\n",{storeId:t,productId:parseInt(r,10),price:parseFloat(n),quantity:parseInt(s,10),size:i?parseFloat(i):null,measurement_unit:a?parseInt(a,10):null})},onSuccess:()=>{Y(),U(!1),I("Product added to inventory successfully"),setTimeout((()=>I("")),3e3)},onError:e=>{b(`Error adding product: ${e.message}`)}}),se=e=>{switch(e){case"ml":return"ml";case"grams":return"g";case"kg":return"kg";case"L":return"L";case"pcs":return"pcs";default:return e||""}},ie=x.memo((e=>{let{searchTerm:t,setSearchTerm:r,filterCategory:n,setFilterCategory:s,lowStockOnly:i,setLowStockOnly:a,lowStockThreshold:l,setLowStockThreshold:o,categories:d}=e;return(0,K.jsx)(te.A,{elevation:3,sx:{p:3,mb:4},children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:4,children:(0,K.jsx)(p.A,{label:"Search Products",variant:"outlined",size:"small",value:t,onChange:e=>r(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,K.jsx)(sr.A,{sx:{mr:1,color:"text.secondary"}})}})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:3,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,size:"small",children:[(0,K.jsx)(Zt.A,{id:"category-select-label",children:"Category"}),(0,K.jsxs)(Xt.A,{labelId:"category-select-label",id:"category-select",value:n,label:"Category",onChange:e=>s(e.target.value),children:[(0,K.jsx)(de.A,{value:"all",children:"All Categories"}),d.map((e=>(0,K.jsx)(de.A,{value:e,children:e},e)))]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:3,children:(0,K.jsxs)(Jt.A,{fullWidth:!0,size:"small",children:[(0,K.jsx)(Zt.A,{id:"stock-filter-label",children:"Stock Filter"}),(0,K.jsxs)(Xt.A,{labelId:"stock-filter-label",id:"stock-filter-select",value:i?"true":"false",label:"Stock Filter",onChange:e=>a("true"===e.target.value),children:[(0,K.jsx)(de.A,{value:"false",children:"All Items"}),(0,K.jsx)(de.A,{value:"true",children:"Low Stock Only"})]})]})}),(0,K.jsx)(xe.Ay,{item:!0,xs:12,md:2,children:(0,K.jsx)(p.A,{label:"Low Stock Threshold",type:"number",size:"small",value:l,onChange:e=>o(parseInt(e.target.value,10)||0),disabled:!i,fullWidth:!0})})]})})}));return O||M?(0,K.jsx)(Hr,{children:(0,K.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,K.jsx)(y.A,{})})}):_?(0,K.jsx)(Hr,{children:(0,K.jsx)(h.A,{sx:{mt:4},children:(0,K.jsxs)(X.A,{severity:"error",children:["Error loading inventory data: ",_.message]})})}):(0,K.jsx)(Hr,{children:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Inventory Management"}),(0,K.jsx)(ie,{searchTerm:S,setSearchTerm:C,filterCategory:L,setFilterCategory:q,lowStockOnly:w,setLowStockOnly:D,lowStockThreshold:F,setLowStockThreshold:k,categories:R}),f&&(0,K.jsx)(X.A,{severity:"success",sx:{mb:2},children:f}),v&&(0,K.jsx)(X.A,{severity:"error",sx:{mb:2},children:v}),(0,K.jsxs)(te.A,{elevation:3,sx:{p:3,mb:4},children:[(0,K.jsxs)(A.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,K.jsx)(m.A,{variant:"h5",children:"Inventory Items"}),(0,K.jsx)(j.A,{variant:"contained",color:"primary",startIcon:(0,K.jsx)(ge.A,{}),onClick:()=>U(!0),children:"Add Product"})]}),0===J.length?(0,K.jsx)(X.A,{severity:"info",sx:{my:2},children:"No inventory items match your filters."}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Mt.A,{component:te.A,variant:"outlined",children:(0,K.jsxs)(_t.A,{children:[(0,K.jsx)(Vt.A,{children:(0,K.jsxs)(Yt.A,{children:[(0,K.jsx)(Gt.A,{}),(0,K.jsx)(Gt.A,{children:"Product"}),(0,K.jsx)(Gt.A,{children:"Category"}),(0,K.jsx)(Gt.A,{children:"Price"}),(0,K.jsx)(Gt.A,{children:"Quantity"}),(0,K.jsx)(Gt.A,{children:"Available"}),(0,K.jsx)(Gt.A,{children:"Listed"}),(0,K.jsx)(Gt.A,{children:"Actions"})]})}),(0,K.jsx)(Kt.A,{children:Z.map((e=>(0,K.jsxs)(x.Fragment,{children:[(0,K.jsxs)(Yt.A,{sx:{backgroundColor:e?.isAvailable?"inherit":"rgba(255, 0, 0, 0.1)"},children:[(0,K.jsx)(Gt.A,{children:(0,K.jsx)(le.A,{size:"small",onClick:()=>{return t=e.id,void g(c===t?null:t);var t},children:c===e.id?(0,K.jsx)(en.A,{}):(0,K.jsx)(tn.A,{})})}),(0,K.jsx)(Gt.A,{children:(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center"},children:[e.product?.image&&(0,K.jsx)(me.A,{component:"img",sx:{width:50,height:50,objectFit:"contain",mr:2},image:e.product.image,alt:e.product.name}),(0,K.jsx)(m.A,{children:e.product?.name})]})}),(0,K.jsx)(Gt.A,{children:e.product?.category?.name||"Uncategorized"}),(0,K.jsxs)(Gt.A,{children:["$",e.price.toFixed(2)]}),(0,K.jsxs)(Gt.A,{children:[e.quantity," ",e.measurement?se(e.measurement):""]}),(0,K.jsx)(Gt.A,{children:e?.isAvailable?(0,K.jsx)(fe.A,{label:"In Stock",color:"success",size:"small"}):(0,K.jsx)(fe.A,{label:"Low Stock",color:"error",size:"small"})}),(0,K.jsx)(Gt.A,{children:e?.isListed?(0,K.jsx)(fe.A,{label:"Listed",color:"success",size:"small"}):(0,K.jsx)(fe.A,{label:"Not Listed",color:"error",size:"small"})}),(0,K.jsxs)(Gt.A,{children:[(0,K.jsx)(le.A,{onClick:()=>(e=>{e&&(i(e),l(!0))})(e),size:"small",color:"primary",children:(0,K.jsx)(rr.A,{})}),(0,K.jsx)(le.A,{onClick:()=>(e=>{i(e),d(!0)})(e),size:"small",color:"error",children:(0,K.jsx)(gr.A,{})})]})]}),(0,K.jsx)(Yt.A,{children:(0,K.jsx)(Gt.A,{sx:{p:0},colSpan:7,children:(0,K.jsx)(Jr.A,{in:c===e.id,timeout:"auto",unmountOnExit:!0,children:(0,K.jsx)(A.A,{sx:{p:3,backgroundColor:"rgba(0, 0, 0, 0.03)"},children:(0,K.jsxs)(xe.Ay,{container:!0,spacing:2,children:[(0,K.jsxs)(xe.Ay,{item:!0,xs:12,md:6,children:[(0,K.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,K.jsx)("strong",{children:"Description:"})," ",e.product?.description||"No description available"]}),(0,K.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,K.jsx)("strong",{children:"Product ID:"})," ",e.product?.id]})]}),(0,K.jsxs)(xe.Ay,{item:!0,xs:12,md:6,children:[(0,K.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,K.jsx)("strong",{children:"Last Updated:"})," ",e.updatedAt?new Date(e.updatedAt).toLocaleString():"N/A"]}),(0,K.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,K.jsx)("strong",{children:"Measurement:"})," ",e.measurement?`${e.measurement} ${se(e.measurement)}`:"N/A"]})]})]})})})})})]},e.id)))})]})}),(0,K.jsx)(A.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,K.jsx)(_n.A,{count:Math.ceil(J.length/W),page:E,onChange:(e,t)=>$(t),color:"primary"})})]})]}),(0,K.jsx)(Vn,{open:a,onClose:()=>{l(!1),b("")},selectedItem:s,onUpdate:e=>ee.mutate(e),isLoading:ee.isLoading}),(0,K.jsxs)(Pe.A,{open:o,onClose:()=>{d(!1),b("")},maxWidth:"sm",fullWidth:!0,children:[(0,K.jsx)(De.A,{children:"Delete Inventory Item"}),(0,K.jsxs)(Fe.A,{children:[s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(m.A,{variant:"body1",gutterBottom:!0,children:"Are you sure you want to delete this inventory item?"}),(0,K.jsxs)(A.A,{sx:{display:"flex",alignItems:"center",mt:2},children:[s.product?.image&&(0,K.jsx)(me.A,{component:"img",sx:{width:80,height:80,objectFit:"contain",mr:2},image:s.product.image,alt:s.product.name}),(0,K.jsxs)(A.A,{children:[(0,K.jsx)(m.A,{variant:"subtitle1",children:(0,K.jsx)("strong",{children:s.product?.name})}),(0,K.jsxs)(m.A,{variant:"body2",color:"text.secondary",children:["Quantity: ",s.quantity]}),(0,K.jsxs)(m.A,{variant:"body2",color:"text.secondary",children:["Price: $",s.price.toFixed(2)]})]})]})]}),v&&(0,K.jsx)(X.A,{severity:"error",sx:{mt:2},children:v})]}),(0,K.jsxs)(er.A,{children:[(0,K.jsx)(j.A,{onClick:()=>{d(!1),b("")},children:"Cancel"}),(0,K.jsx)(j.A,{variant:"contained",color:"error",onClick:()=>re.mutate({inventoryId:s.id}),disabled:re.isLoading,children:re.isLoading?(0,K.jsx)(y.A,{size:24}):"Delete"})]})]}),(0,K.jsx)(Yn,{open:z,onClose:()=>U(!1),storeId:G?.id,availableProducts:Q,onAdd:ne.mutate,isLoading:ne.isLoading,errorMessage:v})]})})},Kn=()=>{const{user:e}=V();return(0,K.jsxs)(l.A,{theme:c,children:[(0,K.jsx)(o.Ay,{}),(0,K.jsxs)(d.BV,{children:[(0,K.jsx)(d.qh,{path:_e,element:(0,K.jsx)(An,{})}),(0,K.jsx)(d.qh,{path:Xe,element:(0,K.jsx)(wt,{})}),(0,K.jsx)(d.qh,{path:Ve,element:(0,K.jsx)(pt,{})}),(0,K.jsx)(d.qh,{path:"/",element:(0,K.jsx)(K.Fragment,{children:(0,K.jsx)(St,{children:(0,K.jsx)(wn,{})})})}),(0,K.jsx)(d.qh,{path:et,element:(0,K.jsx)(St,{children:(0,K.jsx)(Ln,{})})}),(0,K.jsx)(d.qh,{path:`${Ye}/*`,element:(0,K.jsx)(Ct,{role:"admin",children:(0,K.jsx)(Or,{})})}),(0,K.jsx)(d.qh,{path:Ge,element:(0,K.jsx)(Ct,{role:"user",children:(0,K.jsx)(wn,{})})}),(0,K.jsx)(d.qh,{path:Ke,element:(0,K.jsx)(Ct,{role:"delivery_agent",children:(0,K.jsx)(Vr,{})})}),(0,K.jsx)(d.qh,{path:Je,element:(0,K.jsx)(Ct,{role:"user",children:(0,K.jsx)(sn,{})})}),(0,K.jsx)(d.qh,{path:Ze,element:(0,K.jsx)(Ct,{children:(0,K.jsx)(un,{})})}),(0,K.jsx)(d.qh,{path:He,element:(0,K.jsx)(Ct,{role:"store_manager",children:(0,K.jsx)(Qr,{})})}),(0,K.jsx)(d.qh,{path:`${He}/orders`,element:(0,K.jsx)(Ct,{role:"store_manager",children:(0,K.jsx)(Bn,{})})}),(0,K.jsx)(d.qh,{path:"/store_manager/delivery-partners",element:(0,K.jsx)(Ct,{role:"store_manager",children:(0,K.jsx)(Mn,{})})}),(0,K.jsx)(d.qh,{path:"/store_manager/inventory",element:(0,K.jsx)(Ct,{role:"store_manager",children:(0,K.jsx)(Gn,{})})}),(0,K.jsx)(d.qh,{path:`${He}/*`,element:(0,K.jsx)(Ct,{role:"store_manager",children:(0,K.jsx)(hn,{})})}),(0,K.jsx)(d.qh,{path:"*",element:(0,K.jsx)(mn,{})})]})]})};var Hn=r(5072),Qn=r.n(Hn),Jn=r(7825),Zn=r.n(Jn),Xn=r(7659),es=r.n(Xn),ts=r(5056),rs=r.n(ts),ns=r(540),ss=r.n(ns),is=r(1113),as=r.n(is),ls=r(4767),os={};os.styleTagTransform=as(),os.setAttributes=rs(),os.insert=es().bind(null,"head"),os.domAPI=Zn(),os.insertStyleElement=ss();Qn()(ls.A,os);ls.A&&ls.A.locals&&ls.A.locals;const ds=window.location.href?.includes("http://localhost");let cs="us-east-1_6NtAulnkj",xs="1361ghg1fpt2grmchv7ttf8bbj";ds&&(cs="us-east-1_ehhI7OmUk",xs="1okaltgd288h6sjgc5cedlth45");const us={Auth:{Cognito:{region:"us-east-1",userPoolId:cs,userPoolClientId:xs,loginWith:{email:!0},signUpVerificationMethod:"code",userAttributes:{email:{required:!0}},allowGuestAccess:!0,passwordFormat:{minLength:8,requireLowercase:!0,requireUppercase:!0,requireNumbers:!0,requireSpecialCharacters:!0}}}};r(9023).E.configure(us);const ms=new i.E({defaultOptions:{queries:{retry:3,refetchOnWindowFocus:!1},mutations:{retry:0}}});(0,n.createRoot)(document.getElementById("root")).render((0,K.jsx)(a.Ht,{client:ms,children:(0,K.jsx)(s.Kd,{children:(0,K.jsx)(Kn,{})})}))},4767:(e,t,r)=>{r.d(t,{A:()=>l});var n=r(1354),s=r.n(n),i=r(6314),a=r.n(i)()(s());a.push([e.id,"// extracted by mini-css-extract-plugin\nexport {};","",{version:3,sources:["webpack://./src/styles/index.css"],names:[],mappings:"AAAA;QACQ,CAAA",sourcesContent:["// extracted by mini-css-extract-plugin\nexport {};"],sourceRoot:""}]);const l=a}},s={};function i(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[e]={id:e,exports:{}};return n[e](r,r.exports,i),r.exports}i.m=n,e=[],i.O=(t,r,n,s)=>{if(!r){var a=1/0;for(c=0;c<e.length;c++){for(var[r,n,s]=e[c],l=!0,o=0;o<r.length;o++)(!1&s||a>=s)&&Object.keys(i.O).every((e=>i.O[e](r[o])))?r.splice(o--,1):(l=!1,s<a&&(a=s));if(l){e.splice(c--,1);var d=n();void 0!==d&&(t=d)}}return t}s=s||0;for(var c=e.length;c>0&&e[c-1][2]>s;c--)e[c]=e[c-1];e[c]=[r,n,s]},i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(e,n){if(1&n&&(e=this(e)),8&n)return e;if("object"==typeof e&&e){if(4&n&&e.__esModule)return e;if(16&n&&"function"==typeof e.then)return e}var s=Object.create(null);i.r(s);var a={};t=t||[null,r({}),r([]),r(r)];for(var l=2&n&&e;"object"==typeof l&&!~t.indexOf(l);l=r(l))Object.getOwnPropertyNames(l).forEach((t=>a[t]=()=>e[t]));return a.default=()=>e,i.d(s,a),s},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.p="/",(()=>{var e={792:0};i.O.j=t=>0===e[t];var t=(t,r)=>{var n,s,[a,l,o]=r,d=0;if(a.some((t=>0!==e[t]))){for(n in l)i.o(l,n)&&(i.m[n]=l[n]);if(o)var c=o(i)}for(t&&t(r);d<a.length;d++)s=a[d],i.o(e,s)&&e[s]&&e[s][0](),e[s]=0;return i.O(c)},r=self.webpackChunkindimitra_web=self.webpackChunkindimitra_web||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})(),i.nc=void 0;var a=i.O(void 0,[16],(()=>i(5994)));a=i.O(a)})();
//# sourceMappingURL=bundle.21e1841f7b112f305084.js.map