(()=>{"use strict";var e,t,s,n,r,i={98811:(e,t,s)=>{var n=s(5338),r=s(84976),i=s(15072),a=s(97665),o=s(65793),l=s(14519),d=s(47767);const c=(0,s(76544).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=s(96540),u=s(59270),h=s(14073),m=s(97834),A=s(42471),p=s(25239),j=s(69067),g=s(73357),y=s(93959),f=s(64745),v=s(56908);let b="https://indimitra.com/graphql";const I=window.location.href?.includes("http://localhost");I&&(b="http://127.0.0.1:8000/graphql");const C=new v.l4(b,{headers:{"Content-Type":"application/json"}}),S={UNAUTHENTICATED:"Please log in to continue.",FORBIDDEN:"You do not have permission to perform this action.",ORDER_NOT_FOUND:"Order not found.",ORDER_ALREADY_CANCELLED:"This order has already been cancelled.",ORDER_CANNOT_BE_UPDATED:"This order cannot be updated at this time.",INSUFFICIENT_INVENTORY:"Some items are out of stock.",ADDRESS_NOT_FOUND:"Delivery address not found.",PICKUP_ADDRESS_NOT_FOUND:"Pickup address not found.",DELIVERY_PINCODE_NOT_SERVICED:"Delivery is not available for this location.",USER_NOT_FOUND:"User not found.",USER_ALREADY_EXISTS:"User already exists.",INVALID_USER_TYPE:"Invalid user type specified.",STORE_NOT_FOUND:"Store not found.",STORE_NOT_AVAILABLE:"Store is currently unavailable.",PRODUCT_NOT_FOUND:"Product not found.",PRODUCT_NOT_AVAILABLE:"Product is currently unavailable.",NETWORK_ERROR:"Network connection error. Please check your internet connection.",TIMEOUT_ERROR:"Request timed out. Please try again.",INTERNAL_SERVER_ERROR:"An unexpected error occurred. Please try again later.",SERVICE_UNAVAILABLE:"Service is temporarily unavailable. Please try again later.",VALIDATION_ERROR:"Please check your input and try again.",INVALID_INPUT:"The information you provided is invalid.",GENERIC_ERROR:"Something went wrong. Please try again."},w=e=>{if(e.response?.errors){return e.response.errors.map((e=>{if(e.extensions?.code){const t=e.extensions.code;if(S[t])return S[t]}return e.message?.includes("Pickup address ID is required for pickup orders")?"Please select a valid address to deliver.":e.message?.includes("validation")?S.VALIDATION_ERROR:e.message?.includes("not found")?"The requested item was not found.":e.message?.includes("permission")?S.FORBIDDEN:e.message?.includes("already exists")?"This item already exists.":e.message||S.GENERIC_ERROR})).join(". ")}if(e.message?.includes("Network request failed"))return S.NETWORK_ERROR;if(e.message?.includes("timeout"))return S.TIMEOUT_ERROR;if(e.response?.status)switch(e.response.status){case 401:return S.UNAUTHENTICATED;case 403:return S.FORBIDDEN;case 404:return"The requested resource was not found.";case 500:return S.INTERNAL_SERVER_ERROR;case 503:return S.SERVICE_UNAVAILABLE;default:return`Server error (${e.response.status}). Please try again.`}return e.message||S.GENERIC_ERROR},P=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{const s=await C.request(e,t);if(s.errors){const e=w({response:s});throw new Error(e)}return s}catch(e){const t=w(e),s=new Error(t);throw s.originalError=e,s.isGraphQLError=!0,s}},E="\n mutation UpdateOrderStatus($input: UpdateOrderStatusInput!) {\n updateOrderStatus(input: $input) {\n id\n status\n deliveryDate\n deliveryInstructions\n }\n }\n",k="\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",F="\n query GetOrdersByStore($storeId: Int!) {\n getOrdersByStore(storeId: $storeId) {\n id\n addressId\n billUrl\n cancelMessage\n cancelledAt\n cancelledByUserId\n createdByUserId\n customOrder\n deliveryDate\n deliveryFee\n deliveryInstructions\n displayCode\n id\n orderTotalAmount\n paymentId\n pickupId\n status\n storeId\n taxAmount\n tipAmount\n totalAmount\n type\n pickupAddress {\n address\n id\n storeId\n }\n address {\n address\n id\n userId\n }\n creator {\n email\n id\n mobile\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",D="\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",L="\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",$="\n query GetAllStores {\n stores(disabled: false, isActive: true) {\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 displayField\n sectionHeaders\n fees {\n edges {\n node {\n feeCurrency\n feeRate\n id\n limit\n storeId\n type\n }\n }\n }\n pickupAddresses {\n edges {\n node {\n address\n id\n storeId\n }\n }\n }\n }\n }\n",T="\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 displayField\n sectionHeaders\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",R="\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 W=s(71511),q=s(18496);const z="admin",O="user",N="delivery_agent",U="store_manager",B="orders",M="userStatus",_=e=>(0,q.ms)((t=>{e=e?.toLowerCase().trim(),e===z&&(t("view",z),t("view",M)),e===O&&(t("view",O),t("view",B),t("view","cart")),e===N&&t("view",N),e===U&&(t("view",U),t("manage","inventory"))})),V=(0,W.v)(((e,t)=>({cart:{},selectedStore:null,availableStores:[],setAvailableStores:t=>e({availableStores:t}),setSelectedStore:t=>e({selectedStore:t}),getSelectedStore:()=>t().selectedStore,pickupAddress:null,setPickupAddress:t=>e({pickupAddress:t}),deliveryType:"pickup",setDeliveryType:t=>e({deliveryType:t}),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 s={...e.cart};return s[t].quantity>1?s[t].quantity-=1:delete s[t],{cart:s}})),cartCount:()=>{const e=t();return Object.values(e.cart).reduce(((e,t)=>e+(t.quantity||0)),0)+(e.customOrder?1:0)},cartTotal:()=>Object.values(t().cart).reduce(((e,t)=>e+(t?.price||0)*(t?.quantity||0)),0),clearCart:()=>e({cart:{}}),calculateDeliveryFee:(e,t,s)=>{if(!t||!t.fees||!t.fees.edges||0===t.fees.edges.length)return 0;const n=t.fees.edges.map((e=>e.node)).filter((e=>e.type===s.toUpperCase()));if(0===n.length)return 0;const r=n.sort(((e,t)=>e.limit-t.limit));let i=null;for(const t of r)if(e<=t.limit){i=t;break}if(!i&&r.length>0&&(i=r[r.length-1]),!i)return 0;return i.feeRate},getCartTotals:()=>{const e=t(),s=e.cart,n=e.selectedStore,r=e.deliveryType,i=Object.values(s).reduce(((e,t)=>e+(t.price*t.quantity||0)),0),a=t().calculateDeliveryFee(i,n,r),o=n?.taxPercentage||0,l=i*o/100,d=e.tipAmount||0;return{subtotal:i,deliveryFee:a,taxAmount:l,taxPercentage:o,tipAmount:d,total:i+a+l+d}},setTipAmount:t=>e({tipAmount:t}),customOrder:"",setCustomOrder:t=>e({customOrder:t}),listInputAnswers:{},setListInputAnswers:t=>e({listInputAnswers:t})}))),G=(0,W.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 s=JSON.parse(JSON.stringify(t));e((e=>({...e,userProfile:s})))},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:_(null)})},fetchUserProfile:async t=>{if(t){e({isProfileLoading:!0});try{const s=await P(k,{userId:t});if(s.errors)return void e({isProfileLoading:!1});const n=s.getUserProfile||s.data?.getUserProfile;if(!n)return void e({isProfileLoading:!1});e({userProfile:n,isProfileLoading:!1,ability:_(n.role)})}catch(t){e({isProfileLoading:!1})}}},isProfileLoaded:()=>!!t().userProfile}))),H=(0,W.v)(((e,t)=>({addresses:[],isLoading:!1,error:null,selectedAddressId:null,setSelectedAddressId:t=>e({selectedAddressId:t}),fetchAddresses:async s=>{if(!s)return[];e({isLoading:!0,error:null});try{const n="string"==typeof s?parseInt(s,10):s,r=await P("\n query GetAddressesByUser($userId: Int!) {\n getAddressesByUser(userId: $userId) {\n id\n address\n isPrimary\n }\n }\n",{userId:n}),i=r?.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,s){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!s||!t)return null;e({isLoading:!0,error:null});try{const r="string"==typeof s?parseInt(s,10):s,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:r,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,s,n)=>{if(!t)return null;e({isLoading:!0,error:null});try{const r=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:s,isPrimary:n});if(r?.updateAddress)return e((e=>({addresses:e.addresses.map((e=>e.id===t?r.updateAddress:e)),isLoading:!1}))),r.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 s=await P("\n mutation DeleteAddress($addressId: Int!) {\n deleteAddress(addressId: $addressId)\n }\n",{addressId:t});if(s?.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:s}=t();return e.find((e=>e.id===s))||null}}))),K=V;var Y=s(74848);const Q=e=>(0,Y.jsx)(j.A,{...e});var J=s(86990);const Z=e=>(0,Y.jsx)(J.A,{...e}),X=e=>(0,Y.jsx)(A.A,{...e}),ee=e=>(0,Y.jsx)(h.A,{...e});var te=s(89502);const se=e=>(0,Y.jsx)(te.A,{...e});var ne=s(60538);const re=e=>(0,Y.jsx)(ne.A,{...e}),ie=e=>{let{size:t=40,thickness:s=3.6,sx:n={}}=e;return(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",...n},children:(0,Y.jsx)(g.A,{size:t,thickness:s})})};var ae=s(50790),oe=s(29898);const le=e=>{let{fields:t,onSubmit:s,buttonLabel:n,loading:r,error:i,success:a}=e;const o=e=>{switch(e){case"email":return(0,Y.jsx)(ae.A,{sx:{color:"#FF6B6B"}});case"password":return(0,Y.jsx)(oe.A,{sx:{color:"#FF6B6B"}});default:return null}};return(0,Y.jsxs)("form",{onSubmit:s,children:[t.map(((e,t)=>(0,Y.jsx)(X,{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,Y.jsx)(p.A,{position:"start",children:o(e.type)})}},t))),i&&(0,Y.jsx)(se,{severity:"error",sx:{mt:2},children:i}),a&&(0,Y.jsx)(se,{severity:"success",sx:{mt:2},children:a}),(0,Y.jsx)(Z,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:r,sx:{mt:2},children:r?(0,Y.jsx)(ie,{size:24,sx:{color:"#fff"}}):n})]})},de=e=>(0,Y.jsx)(m.A,{...e});var ce=s(11641);const xe=e=>(0,Y.jsx)(ce.A,{...e});var ue=s(73896);const he=e=>(0,Y.jsx)(ue.A,{...e});var me=s(8239),Ae=s(14977),pe=s(87393),je=s(37636),ge=s(56826),ye=s(47839),fe=s(1649),ve=s(99682),be=s(11235);const Ie={"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 Ce=s(44675),Se=s(82022);const we=e=>{let{categoryName:t}=e;return t?(0,Y.jsx)(Se.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},Pe="grey",Ee=e=>{let{product:t}=e;(0,Ce.A)();const{cart:s,addToCart:n,removeFromCart:r}=K(),{id:i,name:a,price:o,description:l,image:d,categoryName:c,isAvailable:x}=t,u=s[i]?.quantity||0,m=d||(c?(e=>{if(e&&Ie[e.toLowerCase()]){const t=Ie[e.toLowerCase()];return t[Math.floor(Math.random()*t.length)]}return Ie.default})(c):"https://picsum.photos/200");return(0,Y.jsxs)(Ae.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,Y.jsx)(we,{categoryName:c}),(0,Y.jsx)(pe.A,{component:"img",height:"140",image:m,alt:a,sx:{padding:"10px 0 0 0",objectFit:"contain",transition:"transform 0.5s","&:hover":{transform:"scale(1.05)"}}}),!x&&(0,Y.jsx)(j.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,Y.jsx)(h.A,{variant:"body1",children:"Sold out"})}),(0,Y.jsxs)(je.A,{sx:{flexGrow:1,p:2.5,pb:0,display:"flex",flexDirection:"column"},children:[(0,Y.jsx)(h.A,{gutterBottom:!0,variant:"h6",sx:{fontWeight:600,fontSize:"1.1rem",mb:1,lineHeight:1.3},children:a}),l&&(0,Y.jsx)(h.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:l}),(0,Y.jsx)(j.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:"auto",mb:2},children:(0,Y.jsxs)(h.A,{variant:"h6",sx:{fontWeight:700,color:"primary.main",fontSize:"1.2rem"},children:["$",o.toFixed(2)]})})]}),(0,Y.jsx)(ge.A,{sx:{justifyContent:"center",pb:2.5,px:2.5},children:u>0?(0,Y.jsxs)(j.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,Y.jsx)(ye.A,{title:"Remove from cart",children:(0,Y.jsx)(ce.A,{onClick:()=>r(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,Y.jsx)(fe.A,{fontSize:"small"})})}),(0,Y.jsx)(h.A,{variant:"body1",sx:{color:"#FF6B6B",fontWeight:700,mx:2,minWidth:"24px",textAlign:"center",fontSize:"1.1rem"},children:u}),(0,Y.jsx)(ye.A,{title:"Add to cart",children:(0,Y.jsx)(ce.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,Y.jsx)(ve.A,{fontSize:"small"})})})]}):(0,Y.jsx)(J.A,{size:"medium",sx:{width:"100%",height:"48px",background:"transparent",color:x?"#FF6B6B":Pe,borderRadius:"8px",fontWeight:600,fontSize:"0.95rem",textTransform:"none",position:"relative",overflow:"hidden",border:`2px solid ${x?"#FF6B6B":Pe}`,transition:"all 0.2s ease","&:hover":{background:"transparent","& .MuiButton-startIcon":{transform:"translateX(2px)"}},"& .MuiButton-startIcon":{transition:"transform 0.2s ease",marginRight:"8px"}},startIcon:(0,Y.jsx)(be.A,{sx:{fontSize:"1.1rem"}}),onClick:()=>n(t),disabled:!x,children:x?"Add to Cart":"Unavailable"})})]})},ke=e=>{let{products:t,title:s}=e;return 0===t.length?(0,Y.jsx)(j.A,{sx:{py:8,textAlign:"center"},children:(0,Y.jsx)(h.A,{variant:"h6",color:"text.secondary",children:"No products available."})}):(0,Y.jsxs)(m.A,{maxWidth:"xl",children:[s&&(0,Y.jsx)(h.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:s}),(0,Y.jsx)(me.Ay,{container:!0,spacing:3,children:t.map((e=>(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,Y.jsx)(Ee,{product:e})},e.id)))})]})};var Fe=s(58031),De=s(46831),Le=s(22477),$e=s(39781);const Te=e=>{let{open:t,onClose:s,children:n,title:r,...i}=e;const a=(0,Ce.A)();return(0,Y.jsxs)(Fe.A,{open:t,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.1)"}},...i,children:[r&&(0,Y.jsxs)(De.A,{sx:{textAlign:"center",background:a.palette.custom.gradientPrimary,color:"white",py:2.5,mb:2,position:"relative"},children:[r,(0,Y.jsx)(ce.A,{"aria-label":"close",onClick:s,sx:{position:"absolute",right:8,top:8,color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},children:(0,Y.jsx)($e.A,{})})]}),(0,Y.jsx)(Le.A,{children:n})]})};var Re=s(8532);const We=e=>(0,Y.jsx)(Re.A,{...e,sx:{minHeight:{xs:"64px",sm:"70px"},px:{xs:2,sm:4},...e.sx}}),qe=e=>(0,Y.jsx)(ye.A,{...e,sx:{"& .MuiTooltip-tooltip":{backgroundColor:"rgba(42, 47, 79, 0.9)",fontSize:"0.875rem",borderRadius:"8px",padding:"8px 16px"},...e.sx}});var ze=s(30781);const Oe=e=>(0,Y.jsx)(ze.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 Ne=s(97190);const Ue=e=>(0,Y.jsx)(Ne.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}});var Be=s(54937);const Me=e=>{let{error:t,title:s="Error",severity:n="error"}=e;return(0,Y.jsx)(j.A,{sx:{p:2},children:(0,Y.jsxs)(te.A,{severity:n,children:[(0,Y.jsx)(Be.A,{sx:{fontWeight:"bold"},children:s}),t]})})},_e={1:{2:s.p+"9eb9fe16cf24f64648f4.jpg",3:s.p+"97d88e9949ad49749160.jpg",4:s.p+"1b6333e925b3879a2984.jpg",5:s.p+"d35b1aa413caca3d6aa2.png",6:s.p+"5c2c140bb8e65ee1aa94.png",7:s.p+"0a359809026b5022f2d5.jpg"}};const Ve=()=>{const[e,t]=(0,x.useState)(""),[s,n]=(0,x.useState)(0),[r,i]=(0,x.useState)(12),{selectedStore:a}=K(),o=function(e,t){const[s,n]=(0,x.useState)(e);return(0,x.useEffect)((()=>{const s=setTimeout((()=>{n(e)}),t);return()=>{clearTimeout(s)}}),[e,t]),s}(e,300),{data:l,isLoading:d,error:c}=(0,u.I)({queryKey:["storeInventory",a?.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:a.id,isListed:!0}),enabled:!!a?.id}),v=(0,x.useMemo)((()=>l?.getInventoryByStore?.map((e=>{const t=a?.id,s=e.productId,n=_e[t]||{};return{id:e.productId,name:e.product.name,image:e.product.image||n[s]||"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}}))||[]),[l,a?.id]),b=(0,x.useMemo)((()=>v.filter((e=>e.name.toLowerCase().includes(o.toLowerCase()))).sort(((e,t)=>e.isAvailable===t.isAvailable?0:e.isAvailable?-1:1))),[v,o]),I=(0,x.useMemo)((()=>b.slice(s*r,s*r+r)),[b,s,r]);return c?(0,Y.jsxs)(h.A,{children:["Error fetching products: ",c.message]}):(0,Y.jsxs)(m.A,{children:[(0,Y.jsx)(A.A,{label:"Search Products",variant:"outlined",fullWidth:!0,sx:{mb:3},value:e,onChange:e=>t(e.target.value),placeholder:"Search by product name or category...",InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(f.A,{})})}}),d?(0,Y.jsx)(j.A,{display:"flex",justifyContent:"center",my:4,children:(0,Y.jsx)(g.A,{})}):0===v.length?(0,Y.jsx)(h.A,{variant:"h6",align:"center",sx:{mt:4},children:"No products available in this store."}):(0,Y.jsx)(ke,{products:I}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,Y.jsx)(y.A,{rowsPerPageOptions:[8,12,24],component:"div",count:b.length,rowsPerPage:r,page:s,onPageChange:(e,t)=>{n(t)},onRowsPerPageChange:e=>{i(parseInt(e.target.value,10)),n(0)}})})]})};var Ge=s(10548),He=s(78325),Ke=s(87980),Ye=s(84201),Qe=s(15327);const Je="/login",Ze="/forgot-password",Xe="/admin",et="/user",tt="/delivery_agent",st="/store_manager",nt="/store_manager/orders",rt="/orders",it="/profile",at="/signup",ot="/cart";var lt=s(28939),dt=s(48393),ct=s(80437),xt=s(58438),ut=s(62594);const ht=e=>{let{email:t,onComplete:s,onSuccess:n}=e;const r=(0,d.Zp)(),[i,a]=(0,x.useState)(""),[o,l]=(0,x.useState)(!1),[c,u]=(0,x.useState)(""),[m,p]=(0,x.useState)("");return(0,Y.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),l(!0),u(""),p("");try{await(0,ut.z)({username:t,confirmationCode:i}),p("Account verified successfully! Redirecting to login..."),setTimeout((()=>{r("/")}),2e3),n&&n(),s&&s()}catch(e){u(e.message||"OTP verification failed. Please try again.")}finally{l(!1)}},children:[(0,Y.jsx)(h.A,{variant:"h4",component:"h1",gutterBottom:!0,children:"Verify OTP"}),(0,Y.jsx)(A.A,{label:"Enter OTP",variant:"outlined",fullWidth:!0,margin:"normal",value:i,onChange:e=>a(e.target.value),required:!0}),c&&(0,Y.jsx)(te.A,{severity:"error",sx:{mt:2},children:c}),m&&(0,Y.jsx)(te.A,{severity:"success",sx:{mt:2},children:m}),(0,Y.jsx)(J.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:o,sx:{mt:2,py:1.2,borderRadius:"8px",textTransform:"none",fontSize:"1rem"},children:o?(0,Y.jsx)(g.A,{size:24,sx:{color:"#fff"}}):"Verify OTP"})]})};var mt=s(5673),At=s(76768);const pt=e=>{let{onSuccess:t,onError:s}=e;const n=(0,d.Zp)(),{setUser:r,setAbility:i,setModalOpen:a}=G(),[o,l]=(0,x.useState)(""),[c,u]=(0,x.useState)(""),[h,m]=(0,x.useState)(!1),[y,f]=(0,x.useState)(""),[v,b]=(0,x.useState)(!1),[I,C]=(0,x.useState)(!1);return(0,Y.jsx)(j.A,{children:v?(0,Y.jsx)(ht,{email:o,onSuccess:()=>n("/"),onComplete:()=>b(!1)}):(0,Y.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),m(!0),f("");try{const e=await(0,dt.J)({username:o,password:c});if("CONFIRM_SIGN_UP"===e.nextStep?.signInStep)return await(0,ct.h)({username:o}),void b(!0);const s=await(0,xt.T)(),l=s["custom:role"].toLowerCase();r({email:s.email,role:l});const d=_(l);i(d),t&&t(),a(!1),n(`/${l}`)}catch(e){if(e.message.includes("User is not confirmed"))try{await(0,ct.h)({username:o}),b(!0)}catch(e){f(e.message||"Error resending OTP.")}else f(e.message||"Login failed. Please try again.")}finally{m(!1)}},children:[(0,Y.jsx)(A.A,{label:"Email",variant:"outlined",fullWidth:!0,value:o,onChange:e=>l(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(ae.A,{sx:{color:"#FF6B6B"}})})}}),(0,Y.jsx)(A.A,{label:"Password",variant:"outlined",type:I?"text":"password",fullWidth:!0,value:c,onChange:e=>u(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(oe.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,Y.jsx)(p.A,{position:"end",children:(0,Y.jsx)(ce.A,{onClick:()=>C((e=>!e)),edge:"end",children:I?(0,Y.jsx)(At.A,{}):(0,Y.jsx)(mt.A,{})})})}}),y&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:y}),(0,Y.jsx)(J.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:h,sx:{py:1.2,borderRadius:"8px",textTransform:"none",fontSize:"1rem"},children:h?(0,Y.jsx)(g.A,{size:24,sx:{color:"#fff"}}):"Login"})]})})};var jt=s(83728),gt=s(71432),yt=s(19873);const ft=e=>{let{referredBy:t="",onSuccess:s}=e;const[n,r]=(0,x.useState)(""),[i,a]=(0,x.useState)(""),[o,l]=(0,x.useState)(""),[d,c]=(0,x.useState)(""),[u,h]=(0,x.useState)(""),[m,g]=(0,x.useState)(t),[y,f]=(0,x.useState)(!1),[v,b]=(0,x.useState)(""),[I,C]=(0,x.useState)(""),[S,w]=(0,x.useState)(!1);return(0,Y.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),f(!0),b(""),C("");try{await(0,jt.H)({username:n,password:d,options:{userAttributes:{"custom:given_name":i,"custom:family_name":o,"custom:phone_number":u,"custom:referredBy":m}}}),C("Signup successful! Enter the OTP sent to your email."),s&&s(n)}catch(e){if(e.message.includes("User already exists"))try{await(0,ct.h)({username:n}),C("OTP resent. Please check your email."),s&&s(n)}catch(e){b(e.message||"Error resending OTP.")}else b(e.message||"Signup failed. Please try again.")}finally{f(!1)}},children:[(0,Y.jsx)(A.A,{label:"First Name",variant:"outlined",fullWidth:!0,value:i,onChange:e=>a(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(gt.A,{sx:{color:"#FF6B6B"}})})}}),(0,Y.jsx)(A.A,{label:"Last Name",variant:"outlined",fullWidth:!0,value:o,onChange:e=>l(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(gt.A,{sx:{color:"#FF6B6B"}})})}}),(0,Y.jsx)(A.A,{label:"Email",variant:"outlined",fullWidth:!0,value:n,onChange:e=>r(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(ae.A,{sx:{color:"#FF6B6B"}})})}}),(0,Y.jsx)(A.A,{label:"Password",variant:"outlined",type:S?"text":"password",fullWidth:!0,value:d,onChange:e=>c(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(oe.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,Y.jsx)(p.A,{position:"end",children:(0,Y.jsx)(ce.A,{onClick:()=>w((e=>!e)),edge:"end",children:S?(0,Y.jsx)(At.A,{}):(0,Y.jsx)(mt.A,{})})})}}),(0,Y.jsxs)(j.A,{sx:{display:"flex",gap:1,mb:2},children:[(0,Y.jsx)(A.A,{label:"Country Code",variant:"outlined",value:"+1",disabled:!0,sx:{width:"120px"},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(yt.A,{sx:{color:"#FF6B6B"}})})}}),(0,Y.jsx)(A.A,{label:"Phone Number",variant:"outlined",fullWidth:!0,value:u,onChange:e=>h(e.target.value),required:!0,InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(yt.A,{sx:{color:"#FF6B6B"}})})}})]}),(0,Y.jsx)(A.A,{label:"Referral Code",variant:"outlined",fullWidth:!0,value:m,onChange:e=>g(e.target.value),disabled:!!t,sx:{mb:2},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(ae.A,{sx:{color:"#FF6B6B"}})})}}),v&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:v}),I&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:I}),(0,Y.jsx)(J.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:y,sx:{mt:1,mb:2},children:y?"Processing...":"Sign Up"})]})};var vt=s(15061),bt=s(7888);const It=()=>{const[e,t]=(0,x.useState)(""),[s,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(!1),[l,c]=(0,x.useState)(""),[u,h]=(0,x.useState)(""),[m,A]=(0,x.useState)(1),p=(0,d.Zp)();return(0,Y.jsx)(Q,{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,Y.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,Y.jsxs)(Q,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,Y.jsx)(ee,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:1===m?"Forgot Password":"Reset Password"}),(0,Y.jsx)(ee,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:1===m?"Enter your email address to receive a reset code":"Enter the OTP sent to your email and your new password"})]}),1===m?(0,Y.jsx)(le,{fields:[{label:"Email",type:"email",value:e,onChange:t}],onSubmit:async t=>{t.preventDefault(),o(!0),c(""),h("");try{await(0,vt.x)({username:e}),A(2),h("OTP sent successfully! Check your email.")}catch(e){c(e.message||"Failed to send OTP. Try again.")}finally{o(!1)}},buttonLabel:"Send OTP",loading:a,error:l,success:u}):(0,Y.jsx)(le,{fields:[{label:"OTP",type:"text",value:s,onChange:n},{label:"New Password",type:"password",value:r,onChange:i}],onSubmit:async t=>{t.preventDefault(),o(!0),c(""),h("");try{await(0,bt.P)({username:e,confirmationCode:s,newPassword:r}),h("Password reset successfully! Redirecting to login..."),setTimeout((()=>p("/")),2e3)}catch(e){c(e.message||"Failed to reset password. Try again.")}finally{o(!1)}},buttonLabel:"Reset Password",loading:a,error:l,success:u})]})})},Ct=e=>{let{open:t,onClose:s,initialForm:n="login"}=e;const[r,i]=(0,x.useState)(n),[a,o]=(0,x.useState)(""),[l,d]=(0,x.useState)(!1),c=(0,Ce.A)(),u=e=>{i(e),d(!1)};return(0,Y.jsx)(lt.A,{open:t,onClose:s,"aria-labelledby":"modal-modal-title","aria-describedby":"modal-modal-description",sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:(0,Y.jsxs)(j.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,Y.jsx)(J.A,{onClick:s,sx:{position:"absolute",top:8,right:8,minWidth:0,p:.5},children:(0,Y.jsx)($e.A,{})}),(0,Y.jsxs)(j.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.5rem",sm:"1.75rem"}},children:"login"===r?"Welcome Back":"signup"===r?"Create Account":"otp"===r?"Verify Email":""}),(0,Y.jsx)(h.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"login"===r?"Sign in to continue your journey with us":"signup"===r?"Join us and start your adventure":"otp"===r?"Enter the OTP sent to your email":""})]}),l&&"login"===r&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:"Email verified successfully! Please login to continue."}),"login"===r?(0,Y.jsx)(pt,{}):"signup"===r?(0,Y.jsx)(ft,{onSuccess:e=>{o(e),i("otp")}}):"otp"===r?(0,Y.jsx)(ht,{email:a,onSuccess:()=>{d(!0),i("login")}}):(0,Y.jsx)(It,{}),(0,Y.jsxs)(j.A,{sx:{mt:3,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:["login"===r&&(0,Y.jsx)(J.A,{onClick:()=>u("forgotPassword"),sx:{color:c.palette.primary.main,textTransform:"none"},children:"Forgot Password?"}),"otp"!==r&&(0,Y.jsxs)(h.A,{variant:"body2",sx:{color:"text.secondary"},children:["login"===r?"Don't have an account?":"signup"===r?"Already have an account?":"Remember your password?",(0,Y.jsx)(J.A,{color:"primary",onClick:()=>u("login"===r?"signup":"login"),sx:{textTransform:"none"},children:"login"===r?"Sign Up":"Login"})]})]})]})})};var St=s(30995),wt=s(29428),Pt=s(68864),Et=s(53215),kt=s(71543),Ft=s(10420),Dt=s(74202),Lt=s(92659),$t=s(37856),Tt=s(49799),Rt=s(44090),Wt=s(37211),qt=s(81385),zt=s(2223),Ot=s(10364),Nt=s(2882),Ut=s(85873);const Bt=e=>{let{store:t,isSelected:s,onSelect:n}=e;const r=t.isActive;return(0,Y.jsx)(ne.A,{elevation:0,sx:{mb:2,borderRadius:2,overflow:"hidden",transition:"all 0.2s ease",border:"1px solid",borderColor:s?"primary.main":r?"rgba(0, 0, 0, 0.08)":"rgba(211, 47, 47, 0.3)",backgroundColor:r?"transparent":"rgba(0, 0, 0, 0.01)","&:hover":{transform:r?"translateY(-2px)":"none",boxShadow:r?2:0}},children:(0,Y.jsx)(Rt.Ay,{disablePadding:!0,children:(0,Y.jsx)(Wt.A,{onClick:()=>r&&n(t),selected:s,disabled:!r,sx:{p:0,cursor:r?"pointer":"not-allowed"},children:(0,Y.jsx)(j.A,{sx:{width:"100%"},children:(0,Y.jsxs)(j.A,{sx:{p:2,backgroundColor:s?"rgba(0, 0, 0, 0.02)":"transparent"},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"flex-start",mb:1},children:[(0,Y.jsx)(qt.A,{sx:{bgcolor:r?s?"primary.main":"grey.300":"rgba(211, 47, 47, 0.1)",mr:2,color:r?"inherit":"error.main"},children:r?(0,Y.jsx)(Ft.A,{}):(0,Y.jsx)(Ut.A,{})}),(0,Y.jsxs)(j.A,{sx:{flex:1},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[(0,Y.jsx)(h.A,{fontWeight:600,fontSize:"1.1rem",color:"text.primary",children:t.name}),!r&&(0,Y.jsx)(Se.A,{label:"Offline",size:"small",sx:{height:20,fontSize:"0.75rem",backgroundColor:"rgba(211, 47, 47, 0.1)",color:"error.main",fontWeight:500}})]}),(!r||t.description)&&(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"flex-start",mb:1,backgroundColor:r?"transparent":"rgba(0, 0, 0, 0.02)",p:r?0:1,borderRadius:1},children:[(0,Y.jsx)(Nt.A,{sx:{fontSize:"0.9rem",color:r?"text.secondary":"error.main",mr:.5,mt:.2}}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",sx:{fontStyle:r?"normal":"italic",fontWeight:r?400:500},children:t.description||"Store timings not available"})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Y.jsx)(zt.A,{sx:{fontSize:"0.9rem",color:"text.secondary",mr:.5}}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:t.address})]})]})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:1},children:[t.radius&&(0,Y.jsx)(Se.A,{icon:(0,Y.jsx)(Ot.A,{fontSize:"small"}),label:`${t.radius} mi radius`,size:"small",variant:"outlined",color:s?"primary":"default",sx:{opacity:r?1:.7}}),!r&&(0,Y.jsx)(h.A,{variant:"caption",sx:{ml:"auto",color:"error.main",fontStyle:"italic"},children:"Store is currently offline"})]})]})})})})})},Mt=e=>{let{availableStores:t,selectedStore:s,handleStoreSelect:n}=e;return(0,Y.jsx)(Tt.A,{sx:{mt:1},children:t.map((e=>(0,Y.jsx)(Bt,{store:e,isSelected:s?.id===e.id,onSelect:n},e.id)))})};var _t=s(1984);const Vt=()=>(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:1},children:[(0,Y.jsx)(_t.A,{}),(0,Y.jsx)(h.A,{variant:"h5",fontWeight:600,children:"Select a Store"})]}),Gt=()=>(0,Y.jsx)(ne.A,{elevation:0,sx:{p:3,textAlign:"center",backgroundColor:"rgba(33, 150, 243, 0.1)",borderRadius:2},children:(0,Y.jsx)(h.A,{sx:{fontWeight:500,color:"info.main"},children:"No stores available at the moment."})}),Ht=e=>{let{value:t,onChange:s,onValidAddress:n}=e;const r=(0,x.useRef)(null),i=(0,x.useRef)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,u]=(0,x.useState)(null);(0,x.useEffect)((()=>{const e=setTimeout((()=>{try{if("undefined"!=typeof window&&window.google&&window.google.maps&&window.google.maps.places&&i.current){d(!0);const e=i.current;if(!e)return void d(!1);const t=new window.google.maps.places.Autocomplete(e,{types:["address"],componentRestrictions:{country:"us"}});r.current=t;const a=document.querySelector(".pac-container");a&&(document.body.appendChild(a),a.style.zIndex="99999"),t.addListener("place_changed",(()=>{const e=t.getPlace();e&&e.formatted_address?(u(e),s(e.formatted_address),o(!0),n(!0)):(u(null),o(!1),n(!1))}))}else d(!1),t&&t.trim().length>10?(o(!0),n(!0)):(o(!1),n(!1))}catch(e){d(!1),t&&t.trim().length>10?(o(!0),n(!0)):(o(!1),n(!1))}}),300);return()=>clearTimeout(e)}),[s,n,t]),(0,x.useEffect)((()=>{""===t?(o(!1),n(!1),u(null)):!l&&t.trim().length>10&&(o(!0),n(!0))}),[t,n,l]);return(0,Y.jsx)(A.A,{inputRef:i,label:"Address",fullWidth:!0,multiline:!0,rows:3,value:t,error:!a&&""!==t,helperText:l?a||""===t?l&&!c?"Start typing to see address suggestions...":"":"Please select a valid address from the suggestions above.":"Enter your complete address (street, city, state, zip code)",onChange:e=>{const t=e.target.value;s(t),l&&c&&t!==c.formatted_address?(o(!1),n(!1),u(null)):l||(t.trim().length>10?(o(!0),n(!0)):(o(!1),n(!1)))},placeholder:l?"Start typing to see address suggestions...":"Enter your complete address (e.g., 123 Main St, City, State 12345)"})},Kt=e=>{let{open:t,onClose:s,forceStep:n,initialStore:r}=e;const{selectedStore:i,setSelectedStore:a,availableStores:o,clearCart:l,setPickupAddress:d,deliveryType:c,setDeliveryType:u}=K(),[m,A]=(0,x.useState)("store"),[p,g]=(0,x.useState)(null),[y,f]=(0,x.useState)(null),[v,b]=(0,x.useState)(""),[I,C]=(0,x.useState)(!1),[S,w]=(0,x.useState)(null),[P,E]=(0,x.useState)("");(0,x.useEffect)((()=>{t&&n&&(A(n),r&&g(r)),t||(A("store"),g(null))}),[t,n,r]);const k=e=>{localStorage.setItem("selectedStoreId",String(e.id)),g(e),l(),A("pickup")},F=()=>{if(!p||!y)return;const e=(p.pickupAddresses?.edges?.map((e=>e.node))||[]).find((e=>String(e.id)===String(y)));a(p),d(e),u("pickup"),A("store"),g(null),f(null),s()},D=e=>{C(e)};(0,x.useEffect)((()=>{if(!I||!v)return w(null),void E("");const e=v.match(/\b(\d{5})(?:-\d{4})?\b/g),t=e?e[e.length-1]:null,s=(p?.pincodes||[]).map((e=>String(e).trim())),n=t?String(t).trim():"";n&&s.includes(n)?(w("success"),E("Store delivers here")):(w("error"),E("Store does not deliver here."))}),[I,v,p]);const L=()=>{"success"===S?(a(p),d(null),u("delivery"),setTimeout((()=>{A("store"),g(null),b(""),C(!1),w(null),E(""),s()}),1200)):(w("error"),E("Store does not deliver here."))},$=()=>{A("store"),g(null),f(null),b(""),C(!1),w(null),E("")},T=e=>{f(e.target.value),u("pickup"),b(""),C(!1)},R=e=>{b(e),e&&""!==e.trim()?(u("delivery"),f(null)):u(y?"pickup":null)};if("store"===m)return(0,Y.jsx)(Te,{open:t,onClose:s,title:(0,Y.jsx)(Vt,{}),children:0===o.length?(0,Y.jsx)(Gt,{}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h.A,{paragraph:!0,sx:{textAlign:"center",fontWeight:500,color:"text.secondary",mb:3},children:"Please select a store to browse products from"}),(0,Y.jsx)(Mt,{availableStores:o,selectedStore:i,handleStoreSelect:k})]})});if("pickup"===m){const e=p?.pickupAddresses?.edges?.map((e=>e.node))||[];return(0,Y.jsxs)(Te,{open:t,onClose:s,title:(0,Y.jsx)(Vt,{}),children:[(0,Y.jsxs)(h.A,{paragraph:!0,sx:{textAlign:"center",fontWeight:500,color:"text.secondary",mb:3},children:["Please select a pickup address or enter your home delivery address for"," ",(0,Y.jsx)("b",{children:p?.name})]}),(0,Y.jsxs)(St.A,{spacing:3,children:[e.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(ne.A,{elevation:"pickup"===c?4:1,sx:{p:2,bgcolor:"pickup"===c?"primary.lighter":"grey.50",opacity:"delivery"===c&&v?.5:1,border:"pickup"===c?"2px solid #1976d2":"1px solid #eee",transition:"all 0.2s"},children:[(0,Y.jsxs)(h.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Ft.A,{fontSize:"small",color:"primary"})," Pickup Address"]}),(0,Y.jsx)(wt.A,{value:y||"",onChange:T,children:e.map((e=>(0,Y.jsx)(Pt.A,{value:String(e.id),control:(0,Y.jsx)(Et.A,{color:"primary"}),label:e.address},e.id)))}),(0,Y.jsx)(J.A,{onClick:F,variant:"contained",color:"primary",fullWidth:!0,startIcon:(0,Y.jsx)($t.A,{}),disabled:"pickup"!==c||!y,sx:{mt:2,fontWeight:600,py:1.2,fontSize:"1rem"},children:"Confirm Pickup"})]}),(0,Y.jsx)(kt.A,{children:"OR"})]}),(0,Y.jsxs)(ne.A,{elevation:"delivery"===c?4:1,sx:{p:2,bgcolor:"delivery"===c?"secondary.lighter":"grey.50",opacity:"pickup"===c&&y?.5:1,border:"delivery"===c?"2px solid #9c27b0":"1px solid #eee",transition:"all 0.2s"},children:[(0,Y.jsxs)(h.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Dt.A,{fontSize:"small",color:"secondary"})," Home Delivery Address"]}),(0,Y.jsx)(Ht,{value:v,onChange:R,onValidAddress:D}),S&&(0,Y.jsx)(te.A,{severity:S,sx:{mt:1},children:P}),(0,Y.jsx)(J.A,{onClick:L,variant:"contained",color:"secondary",fullWidth:!0,startIcon:(0,Y.jsx)(Dt.A,{}),disabled:"delivery"!==c||!I,sx:{mt:2,fontWeight:600,py:1.2,fontSize:"1rem"},children:"Confirm Delivery"})]}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"flex-start",mt:1},children:(0,Y.jsx)(J.A,{onClick:$,variant:"outlined",color:"inherit",size:"small",startIcon:(0,Y.jsx)(Lt.A,{}),sx:{fontWeight:500,borderRadius:2},children:"Back"})})]})]})}return null},Yt=e=>{let{navigate:t,userRole:s}=e;const{setUser:n}=G();return(0,Y.jsx)(ee,{onClick:async()=>{let e=s;if(!e)try{const t=await(0,Ge.$)();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"})},Qt=()=>{const e=(0,d.Zp)(),[t,s]=(0,x.useState)(null),n=(0,Qe.A)("(max-width: 600px)"),r=K((e=>e.cartCount())),{user:i,ability:a,logout:o}=G(),[l,c]=x.useState(null),{modalOpen:u,setModalOpen:h,currentForm:m,setCurrentForm:A}=G(),[p,j]=(0,x.useState)(null),[g,y]=(0,x.useState)(!1);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ge.$)(),t=await(0,xt.T)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;j(t)}const n=t["custom:role"]?.toLowerCase();s(n)}catch(e){}})()}),[]);const f=()=>c(null),v=_(i?.role||"user");return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Q,{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,Y.jsxs)(We,{sx:{minHeight:{xs:"64px",sm:"70px"},px:{xs:2,sm:4}},children:[(0,Y.jsx)(Yt,{navigate:e,userRole:i?.role}),(0,Y.jsx)(Q,{sx:{flexGrow:1}}),(0,Y.jsxs)(Q,{sx:{display:"flex",alignItems:"center",gap:{xs:1,sm:2}},children:[!p&&(0,Y.jsx)(Z,{onClick:()=>{h(!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,Y.jsx)(Ct,{open:u,onClose:()=>h(!1),currentForm:m,setCurrentForm:A}),!n&&p&&v&&v.can("view","orders")&&(0,Y.jsx)(Z,{onClick:()=>e(rt),sx:{color:"#2A2F4F",textTransform:"none",fontSize:"1rem",fontWeight:500,px:2,"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:"Orders"}),(!p||p&&"user"===i?.role)&&(0,Y.jsx)(Z,{variant:"outlined",startIcon:(0,Y.jsx)(He.A,{}),onClick:()=>y(!0),sx:{color:"#2A2F4F",borderColor:"#2A2F4F",textTransform:"none",fontSize:"1rem",fontWeight:500,px:2,mr:1,"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:"Change Store"}),i?v?.can("view","cart")&&(0,Y.jsx)(qe,{title:"Cart",children:(0,Y.jsx)(xe,{onClick:()=>e(ot),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white","&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,Y.jsx)(Oe,{badgeContent:r,color:"error",sx:{"& .MuiBadge-badge":{backgroundColor:"#FF6B6B",color:"white",fontWeight:"bold"}},children:(0,Y.jsx)(be.A,{})})})}):(0,Y.jsx)(qe,{title:"Cart",children:(0,Y.jsx)(xe,{onClick:()=>e(ot),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white","&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,Y.jsx)(Oe,{badgeContent:r,color:"error",sx:{"& .MuiBadge-badge":{backgroundColor:"#FF6B6B",color:"white",fontWeight:"bold"}},children:(0,Y.jsx)(be.A,{})})})}),p&&(0,Y.jsx)(qe,{title:"Profile",children:(0,Y.jsx)(xe,{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,Y.jsx)(Ke.A,{})})})]})]})}),(0,Y.jsxs)(Ue,{anchorEl:l,open:Boolean(l),onClose:f,PaperProps:{elevation:3,sx:{mt:2,minWidth:"200px",borderRadius:"12px",overflow:"hidden"}},children:[n&&v?.can("view","orders")&&(0,Y.jsx)(he,{onClick:()=>{e(rt),f()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,Y.jsx)(ee,{variant:"body1",children:"Orders"})}),(0,Y.jsx)(he,{onClick:()=>{e(it),f()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,Y.jsx)(ee,{variant:"body1",children:"Profile"})}),(0,Y.jsx)(he,{onClick:()=>{(async()=>{try{await(0,Ye.C)(),o(),j(null),s(null),e("/")}catch(e){}})(),f()},sx:{py:1.5,px:3,color:"#FF5757","&:hover":{backgroundColor:"rgba(255, 87, 87, 0.1)"}},children:(0,Y.jsx)(ee,{variant:"body1",children:"Logout"})})]}),(0,Y.jsx)(Kt,{open:g,onClose:()=>y(!1)}),(0,Y.jsx)(Q,{sx:{height:{xs:"64px",sm:"70px"}}})]})};var Jt=s(87992),Zt=s(61451);const Xt=()=>(0,Y.jsx)(Jt.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,Y.jsx)(Zt.A,{sx:{fontSize:32}})}),es=e=>{let{children:t}=e;return(0,Y.jsxs)(Q,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[(0,Y.jsx)(Qt,{}),t,(0,Y.jsx)(Xt,{})]})},ts=e=>{let{children:t,role:s}=e;const{user:n,setUser:r,ability:i,setAbility:a}=G(),[o,l]=(0,x.useState)(!0),[c,u]=(0,x.useState)(!1),[h,m]=(0,x.useState)(null),A=(0,d.zy)();if((0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ge.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload["custom:role"]?.toLowerCase();n||r({role:t});const s=_(t);a(s),m(s),u(!0)}else u(!1)}catch(e){u(!1)}finally{l(!1)}})()}),[n,r,a]),o)return(0,Y.jsx)(ie,{});if(!c)return(0,Y.jsx)(d.C5,{to:"/",replace:!0});if(A.pathname===it)return(0,Y.jsx)(es,{children:t});const p=(Array.isArray(s)?s:[s]).map((e=>e.toLowerCase()));return h&&p.some((e=>h.can("view",e)))?(0,Y.jsx)(es,{children:t}):(0,Y.jsx)(d.C5,{to:"/not-authorized",replace:!0})},ss=()=>{const[e,t]=(0,x.useState)(!1),[s,n]=(0,x.useState)(""),[i]=(0,r.ok)(),a=i.get("referredby")||"";return(0,Y.jsx)(j.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,Y.jsxs)(ne.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,Y.jsxs)(j.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,Y.jsx)(h.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,Y.jsx)(h.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,Y.jsx)(j.A,{sx:{minHeight:300},children:e?(0,Y.jsx)(ht,{email:s,onComplete:()=>t(!1)}):(0,Y.jsx)(ft,{referredBy:a,onOtpStep:e=>{n(e),t(!0)}})})]})})};var ns=s(57873),rs=s(82241),is=s(58620),as=s(31117),os=s(69377),ls=s(85685),ds=s(69634),cs=s(50215),xs=s(55764),us=s(47027),hs=s(89388),ms=s(82935),As=s(94654),ps=s(17451);const js=e=>{let{title:t,value:s,icon:n,color:r}=e;const i=(0,Ce.A)(),a=(0,Qe.A)(i.breakpoints.down("sm"));return(0,Y.jsx)(Ae.A,{sx:{height:"100%"},children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Y.jsx)(j.A,{sx:{backgroundColor:`${r}15`,borderRadius:"50%",p:1,mr:2,display:"flex",alignItems:"center",justifyContent:"center"},children:x.cloneElement(n,{sx:{color:r}})}),(0,Y.jsx)(h.A,{variant:"h6",color:"text.secondary",children:t})]}),(0,Y.jsx)(h.A,{variant:a?"h5":"h4",component:"div",sx:{fontWeight:"bold"},children:s})]})})},gs=()=>{const e=(0,Ce.A)(),t=(0,Qe.A)(e.breakpoints.down("sm")),{data:s,isLoading:n,error:r}=(0,u.I)({queryKey:["dashboardStats"],queryFn:async()=>await P("\n query GetDashboardStats {\n getDashboardStats {\n totalUsers\n activeUsers\n deliveryAgents\n usersByType\n }\n }\n")}),{data:i,isLoading:a,error:o}=(0,u.I)({queryKey:["orderStats"],queryFn:async()=>await P("\n query GetOrderStats {\n getOrderStats {\n totalOrders\n recentOrders\n ordersByStatus\n ordersByType\n }\n }\n")}),{data:l,isLoading:d,error:c}=(0,u.I)({queryKey:["stores"],queryFn:async()=>await P($)}),x=s?.getDashboardStats||{},m=i?.getOrderStats||{},A=l?.stores||[],p=x.totalUsers||0,y=A.length||0,f=x.deliveryAgents||0,v=m.totalOrders||0;if(n||a||d)return(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:(0,Y.jsx)(g.A,{})});if(r||o||c){const e=r?.message||o?.message||c?.message||"Error loading dashboard data. Please try again later.";return(0,Y.jsx)(j.A,{sx:{p:t?2:3},children:(0,Y.jsx)(Me,{error:e,title:"Dashboard Error",severity:"error"})})}return(0,Y.jsxs)(j.A,{sx:{p:t?2:3},children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,sx:{mb:4},children:"Dashboard Overview"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(js,{title:"Total Users",value:p.toLocaleString(),icon:(0,Y.jsx)(ds.A,{}),color:e.palette.primary.main})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(js,{title:"Total Stores",value:y.toLocaleString(),icon:(0,Y.jsx)(_t.A,{}),color:e.palette.success.main})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(js,{title:"Active Drivers",value:f.toLocaleString(),icon:(0,Y.jsx)(hs.A,{}),color:e.palette.info.main})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(js,{title:"Total Orders",value:v.toLocaleString(),icon:(0,Y.jsx)(be.A,{}),color:e.palette.warning.main})})]}),(0,Y.jsxs)(j.A,{sx:{mt:4},children:[(0,Y.jsx)(h.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"Detailed Statistics"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(js,{title:"Active Users",value:(x.activeUsers||0).toLocaleString(),icon:(0,Y.jsx)(ds.A,{}),color:e.palette.success.main})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(js,{title:"Recent Orders (30 days)",value:(m.recentOrders||0).toLocaleString(),icon:(0,Y.jsx)(be.A,{}),color:e.palette.info.main})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(js,{title:"Delivery Orders",value:(m.ordersByType?.DELIVERY||0).toLocaleString(),icon:(0,Y.jsx)(hs.A,{}),color:e.palette.secondary.main})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(js,{title:"Pickup Orders",value:(m.ordersByType?.PICKUP||0).toLocaleString(),icon:(0,Y.jsx)(_t.A,{}),color:e.palette.warning.main})})]})]}),x.usersByType&&Object.keys(x.usersByType).length>0&&(0,Y.jsxs)(j.A,{sx:{mt:4},children:[(0,Y.jsx)(h.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"User Type Breakdown"}),(0,Y.jsx)(me.Ay,{container:!0,spacing:2,children:Object.entries(x.usersByType).map((e=>{let[t,s]=e;return(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Y.jsx)(Ae.A,{sx:{height:"100%"},children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}),(0,Y.jsx)(h.A,{variant:"h4",component:"div",sx:{fontWeight:"bold"},children:s.toLocaleString()})]})})},t)}))})]})]})};var ys=s(33198),fs=s(64137),vs=s(96627),bs=s(86798),Is=s(14774),Cs=s(43884),Ss=s(17532),ws=s(10423),Ps=s(50779),Es=s(54433),ks=s(65460),Fs=s(58763),Ds=s(95557),Ls=s(72297),$s=s(68125),Ts=s(57097);const Rs=()=>{const e=(0,Ce.A)(),t=(0,Qe.A)(e.breakpoints.down("sm")),[s,n]=(0,x.useState)(0),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(0),[l,d]=(0,x.useState)(10),[c,m]=(0,x.useState)(!1),[f,v]=(0,x.useState)(""),[b,I]=(0,x.useState)(null),[C,S]=(0,x.useState)(!1),[w,E]=(0,x.useState)(""),[k,F]=(0,x.useState)({open:!1,message:"",severity:"success"}),[D,L]=(0,x.useState)(null),[$,R]=(0,x.useState)(!1),[W,q]=(0,x.useState)(""),[z,O]=(0,x.useState)([]),{data:N,isLoading:U,error:B,refetch:M}=(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:_,isLoading:V,error:G,refetch:H}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{const e=await P(T);return e?.stores||[]},enabled:!0}),K=(0,Ts.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?F({open:!0,message:t.error.message||"Failed to update user role",severity:"error"}):t?.user&&(F({open:!0,message:`Successfully updated user role to ${t.user.type}`,severity:"success"}),M()),S(!1)},onError:e=>{F({open:!0,message:"Error updating user role: "+e.message,severity:"error"})}}),Q=(0,Ts.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&&(F({open:!0,message:`Successfully assigned driver to ${t.store.name}`,severity:"success"}),H()),R(!1)},onError:e=>{F({open:!0,message:"Error assigning driver to store: "+e.message,severity:"error"})}});(0,x.useEffect)((()=>{N&&(async()=>{try{if(N){const e=N.find((e=>"ADMIN"===e.type));e&&L(e.cognitoId)}}catch(e){}})()}),[N]),(0,x.useEffect)((()=>{_&&O(_)}),[_]);const Z=e=>{I(e),E(e.type),S(!0)},X=e=>{I(e),q(""),R(!0)},ee=()=>{F({...k,open:!1})},se=()=>{if(!N)return[];let e=N;return 1===s?e=N.filter((e=>"USER"===e.type)):2===s?e=N.filter((e=>"DELIVERY"===e.type)):3===s&&(e=N.filter((e=>"STORE_MANAGER"===e.type))),r&&(e=e.filter((e=>e.email.toLowerCase().includes(r.toLowerCase())||e.mobile&&e.mobile.includes(r)||e.referralId&&e.referralId.toLowerCase().includes(r.toLowerCase())))),e};return(0,Y.jsxs)(j.A,{sx:{p:t?2:3},children:[(0,Y.jsxs)(ne.A,{sx:{p:3,mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",gutterBottom:!0,children:"User Management"}),(0,Y.jsxs)(Ss.A,{value:s,onChange:(e,t)=>{n(t),o(0)},sx:{mb:3},variant:t?"fullWidth":"standard",children:[(0,Y.jsx)(ws.A,{label:"All"}),(0,Y.jsx)(ws.A,{label:"Users"}),(0,Y.jsx)(ws.A,{label:"Delivery Partners"}),(0,Y.jsx)(ws.A,{label:"Store Managers"})]}),(0,Y.jsx)(j.A,{sx:{mb:3,display:"flex",gap:2,flexWrap:"wrap"},children:(0,Y.jsx)(A.A,{size:"small",placeholder:"Search...",value:r,onChange:e=>{i(e.target.value),o(0)},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)($s.A,{})})},sx:{flexGrow:1,minWidth:200}})}),B&&(0,Y.jsxs)(te.A,{severity:"error",sx:{mb:3},children:["Error loading users: ",B.message]}),U?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Y.jsx)(g.A,{})}):(0,Y.jsxs)(Y.Fragment,{children:[0===s&&(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"ID"}),(0,Y.jsx)(Is.A,{children:"Email"}),(0,Y.jsx)(Is.A,{children:"Mobile"}),(0,Y.jsx)(Is.A,{children:"Type"}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{children:"Referral ID"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:se().slice(a*l,a*l+l).map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.id}),(0,Y.jsx)(Is.A,{children:e.email}),(0,Y.jsx)(Is.A,{children:e.mobile||"N/A"}),(0,Y.jsx)(Is.A,{children:e.type}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,Y.jsx)(Is.A,{children:e.referralId||"N/A"}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{size:"small",color:"primary",onClick:()=>Z(e),children:(0,Y.jsx)(Ls.A,{})}),"DELIVERY"===e.type&&(0,Y.jsx)(ce.A,{size:"small",color:"secondary",onClick:()=>X(e),title:"Assign to Store",children:(0,Y.jsx)(hs.A,{})})]})]},e.id)))})]})}),1===s&&(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"ID"}),(0,Y.jsx)(Is.A,{children:"Email"}),(0,Y.jsx)(Is.A,{children:"Mobile"}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{children:"Referral ID"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:se().slice(a*l,a*l+l).map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.id}),(0,Y.jsx)(Is.A,{children:e.email}),(0,Y.jsx)(Is.A,{children:e.mobile||"N/A"}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,Y.jsx)(Is.A,{children:e.referralId||"N/A"}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(ce.A,{size:"small",color:"primary",onClick:()=>Z(e),children:(0,Y.jsx)(Ls.A,{})})})]},e.id)))})]})}),2===s&&(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"ID"}),(0,Y.jsx)(Is.A,{children:"Email"}),(0,Y.jsx)(Is.A,{children:"Mobile"}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{children:"Referral ID"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:se().slice(a*l,a*l+l).map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.id}),(0,Y.jsx)(Is.A,{children:e.email}),(0,Y.jsx)(Is.A,{children:e.mobile||"N/A"}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,Y.jsx)(Is.A,{children:e.referralId||"N/A"}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{size:"small",color:"primary",onClick:()=>Z(e),children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{size:"small",color:"secondary",onClick:()=>X(e),title:"Assign to Store",children:(0,Y.jsx)(hs.A,{})})]})]},e.id)))})]})}),3===s&&(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"ID"}),(0,Y.jsx)(Is.A,{children:"Email"}),(0,Y.jsx)(Is.A,{children:"Mobile"}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{children:"Referral ID"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:se().slice(a*l,a*l+l).map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.id}),(0,Y.jsx)(Is.A,{children:e.email}),(0,Y.jsx)(Is.A,{children:e.mobile||"N/A"}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,Y.jsx)(Is.A,{children:e.referralId||"N/A"}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(ce.A,{size:"small",color:"primary",onClick:()=>Z(e),children:(0,Y.jsx)(Ls.A,{})})})]},e.id)))})]})}),(0,Y.jsx)(y.A,{component:"div",count:se().length,page:a,onPageChange:(e,t)=>{o(t)},rowsPerPage:l,onRowsPerPageChange:e=>{d(parseInt(e.target.value,10)),o(0)},sx:{mt:2}})]})]}),(0,Y.jsxs)(Fe.A,{open:C,onClose:()=>S(!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,Y.jsx)(De.A,{sx:{pb:1},children:"Update User Role"}),(0,Y.jsx)(Le.A,{children:b&&(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsxs)(h.A,{variant:"subtitle1",gutterBottom:!0,children:["User: ",b.email]}),(0,Y.jsxs)(h.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",b.id]}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mt:2},children:[(0,Y.jsx)(Es.A,{children:"Role"}),(0,Y.jsxs)(ks.A,{value:w,onChange:e=>{E(e.target.value)},label:"Role",sx:{mb:2},children:[(0,Y.jsx)(ue.A,{value:"USER",children:"User"}),(0,Y.jsx)(ue.A,{value:"ADMIN",children:"Admin"}),(0,Y.jsx)(ue.A,{value:"DELIVERY",children:"Delivery Partner"}),(0,Y.jsx)(ue.A,{value:"STORE_MANAGER",children:"Store Manager"})]})]})]})}),(0,Y.jsxs)(Fs.A,{sx:{px:3,py:2},children:[(0,Y.jsx)(J.A,{onClick:()=>S(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:()=>{if(!D)return void F({open:!0,message:"Admin ID not available. Please try again.",severity:"error"});K.mutate({requesterId:D,targetUserId:b.cognitoId,newType:{USER:"USER",ADMIN:"ADMIN",DELIVERY:"DELIVERY_AGENT",STORE_MANAGER:"STORE_MANAGER"}[w]||w})},variant:"contained",color:"primary",disabled:K.isPending,children:K.isPending?"Updating...":"Update Role"})]})]}),(0,Y.jsxs)(Fe.A,{open:$,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,Y.jsx)(De.A,{sx:{pb:1},children:"Assign Driver to Store"}),(0,Y.jsx)(Le.A,{children:b&&(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsxs)(h.A,{variant:"subtitle1",gutterBottom:!0,children:["Driver: ",b.email]}),(0,Y.jsxs)(h.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",b.id]}),(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsx)(h.A,{variant:"subtitle2",gutterBottom:!0,sx:{mt:2},children:"Select Store"}),V?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,Y.jsx)(g.A,{size:24})}):G?(0,Y.jsxs)(te.A,{severity:"error",sx:{mb:2},children:["Error loading stores: ",G.message]}):0===z.length?(0,Y.jsx)(te.A,{severity:"info",sx:{mb:2},children:"No stores available"}):(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mt:1},children:[(0,Y.jsx)(Es.A,{children:"Store"}),(0,Y.jsx)(ks.A,{value:W,onChange:e=>{q(e.target.value)},label:"Store",sx:{mb:2},children:z.map((e=>(0,Y.jsxs)(ue.A,{value:e.id,children:[e.name," - ",e.address]},e.id)))})]}),W&&(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",gutterBottom:!0,children:"Current Drivers"}),z.find((e=>e.id===parseInt(W)))?.drivers?.edges?.length>0?(0,Y.jsx)(j.A,{sx:{mt:1},children:z.find((e=>e.id===parseInt(W)))?.drivers?.edges?.map(((e,t)=>(0,Y.jsx)(Se.A,{label:e.node.driver.email,size:"small",sx:{mr:1,mb:1}},t)))}):(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"No drivers assigned to this store yet"})]})]})}),(0,Y.jsxs)(Fs.A,{sx:{px:3,py:2},children:[(0,Y.jsx)(J.A,{onClick:()=>R(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:()=>{W&&b?Q.mutate({storeId:parseInt(W),userId:parseInt(b.id)}):F({open:!0,message:"Please select a store",severity:"error"})},variant:"contained",color:"primary",disabled:!W||Q.isPending,children:Q.isPending?"Assigning...":"Assign to Store"})]})]}),(0,Y.jsx)(Ds.A,{open:k.open,autoHideDuration:6e3,onClose:ee,message:k.message,children:(0,Y.jsx)(te.A,{onClose:ee,severity:k.severity,children:k.message})})]})};var Ws=s(39738),qs=s(82997),zs=s(47363),Os=s(67110),Ns=s(40250),Us=s(70765),Bs=s(34337),Ms=s(72306),_s=s(79432);const Vs=["Store Information","Inventory","Drivers","Store Managers","Review"],Gs=()=>{const[e,t]=(0,x.useState)(0),[s,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(!1),[c,m]=(0,x.useState)({}),y=(0,Ce.A)(),[f,v]=((0,Qe.A)(y.breakpoints.down("sm")),(0,x.useState)(0)),[b,I]=(0,x.useState)({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",displayField:"",sectionHeaders:[],inventory:[],drivers:[],storeManagers:[],pincodes:""}),[C,S]=(0,x.useState)(null),[w,E]=(0,x.useState)({open:!1,message:"",severity:"success"}),{data:k,isLoading:F,refetch:D}=(0,u.I)({queryKey:["stores"],queryFn:()=>P(T),enabled:r}),L=(0,Ts.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 $displayField: String!\n $sectionHeaders: [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 displayField: $displayField\n sectionHeaders: $sectionHeaders\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 displayField\n sectionHeaders\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,displayField:e.displayField||null,sectionHeaders:e.sectionHeaders||null,pincodes:e.pincodes||null}),onSuccess:()=>{d(!0),o(null),I({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",displayField:"",sectionHeaders:[],inventory:[],drivers:[],storeManagers:[],pincodes:""}),v(0),D()},onError:e=>{o(e.message||"Failed to create store"),d(!1)}}),$=(0,Ts.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 $displayField: String\n $sectionHeaders: [String!]\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 displayField: $displayField\n sectionHeaders: $sectionHeaders\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 displayField\n sectionHeaders\n }\n }\n",e),onSuccess:()=>{E({open:!0,message:"Store updated successfully",severity:"success"}),S(null),D()},onError:e=>{E({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),R=e=>{const{name:t,value:s}=e.target;I((e=>({...e,[t]:s}))),c[t]&&m((e=>({...e,[t]:null}))),a&&o(null)},W=()=>{I((e=>({...e,sectionHeaders:[...e.sectionHeaders,""]})))},q=()=>{const e={};return b.name.trim()||(e.name="Store name is required"),b.address.trim()||(e.address="Address is required"),b.email.trim()||(e.email="Manager email is required"),b.mobile.trim()?/^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/.test(b.mobile.trim())||(e.mobile="Enter a valid US phone number (e.g., 123-456-7890)"):e.mobile="Manager mobile is required",b.managerUserId||(e.managerUserId="Manager User ID is required"),b.radius&&!isNaN(parseFloat(b.radius))||(e.radius="Delivery radius is required"),b.displayField.trim()||(e.displayField="Display Field is required"),m(e),0===Object.keys(e).length},z=()=>{S(null)},O=k?.stores?.filter((e=>e.name.toLowerCase().includes(s.toLowerCase())||e.address.toLowerCase().includes(s.toLowerCase())))||[];return(0,x.useEffect)((()=>{let e;return l&&(e=setTimeout((()=>{d(!1)}),5e3)),()=>{e&&clearTimeout(e)}}),[l]),(0,Y.jsxs)(j.A,{children:[(0,Y.jsxs)(ne.A,{sx:{p:3,mb:3},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Y.jsx)(_t.A,{sx:{mr:1}}),(0,Y.jsx)(h.A,{variant:"h5",children:"Store Management"})]}),(0,Y.jsxs)(Ss.A,{value:e,onChange:(e,s)=>{t(s)},sx:{mb:3},children:[(0,Y.jsx)(ws.A,{label:"Store List"}),(0,Y.jsx)(ws.A,{label:"Add New Store"})]}),a&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:3},children:a}),l&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:3,animation:"fadeOut 0.5s ease-in-out 4.5s forwards","@keyframes fadeOut":{"0%":{opacity:1},"100%":{opacity:0}}},children:"Store created successfully!"}),0===e?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j.A,{sx:{mb:3},children:(0,Y.jsx)(A.A,{fullWidth:!0,variant:"outlined",placeholder:"Search stores...",value:s,onChange:e=>n(e.target.value),InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)($s.A,{})})}})}),r?F?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,Y.jsx)(g.A,{})}):0===O.length?(0,Y.jsx)(te.A,{severity:"info",sx:{mb:3},children:"No stores found matching your criteria"}):(0,Y.jsx)(me.Ay,{container:!0,spacing:3,children:O.map((e=>(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(ne.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,Y.jsx)(j.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,Y.jsxs)(me.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Y.jsx)(_t.A,{sx:{mr:2,color:"white",fontSize:"2rem"}}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{className:"store-name",variant:"h6",sx:{color:"white",fontWeight:600,transition:"color 0.3s ease-in-out"},children:e.name}),(0,Y.jsxs)(h.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,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",md:"flex-end"},gap:2},children:[(0,Y.jsx)(Se.A,{label:e.isActive?"Active":"Inactive",color:e.isActive?"success":"error",sx:{fontWeight:600,boxShadow:2,"& .MuiChip-label":{px:1}}}),(0,Y.jsx)(j.A,{className:"action-buttons",sx:{display:"flex",gap:1,opacity:.9},children:(0,Y.jsx)(J.A,{size:"small",startIcon:(0,Y.jsx)(Ls.A,{}),sx:{fontWeight:600,textTransform:"none",color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},onClick:()=>(e=>{S(e)})(e),children:"Edit"})})]})})]})}),(0,Y.jsx)(j.A,{sx:{p:3},children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.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,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,Y.jsx)(us.A,{sx:{mr:1.5,color:"primary.main",mt:.3,flexShrink:0,fontSize:"1.2rem"}}),(0,Y.jsx)(h.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.address})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Y.jsx)(Us.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Y.jsx)(h.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.mobile||"No contact info"})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Y.jsx)(Bs.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Y.jsx)(h.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.email||"No email info"})]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.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,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Y.jsx)(hs.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Y.jsxs)(h.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Radius: ",e.radius," mi"]})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Y.jsx)(Ms.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Y.jsxs)(h.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Delivery Fee: $",e.storeDeliveryFee?.toFixed(2)||"0.00"]})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Y.jsx)(_s.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Y.jsxs)(h.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,Y.jsx)(j.A,{sx:{display:"flex",flexWrap:"wrap",gap:.8},children:e.pincodes.map((e=>(0,Y.jsx)(Se.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,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(j.A,{children:[e.description&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.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,Y.jsx)(h.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.description})]}),e.tnc&&(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.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,Y.jsx)(h.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.tnc})]})]})})]})})]})},e.id)))}):(0,Y.jsxs)(Ae.A,{sx:{mb:3},children:[(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Stores" to load store data'}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]}),(0,Y.jsx)(ge.A,{sx:{justifyContent:"center"},children:(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(Ns.A,{}),onClick:()=>{i(!0),D()},children:"Fetch Stores"})})]})]}):(0,Y.jsxs)(j.A,{sx:{maxWidth:800,mx:"auto"},children:[(0,Y.jsx)(Ws.A,{activeStep:f,sx:{mb:4},children:Vs.map((e=>(0,Y.jsx)(qs.A,{children:(0,Y.jsx)(zs.A,{children:e})},e)))}),(e=>{switch(e){case 0:return(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Basic Store Information"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Store Name",name:"name",value:b.name,onChange:R,error:!!c.name,helperText:c.name})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Address",name:"address",value:b.address,onChange:R,error:!!c.address,helperText:c.address})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Manager Email",name:"email",type:"email",value:b.email,onChange:R,error:!!c.email,helperText:c.email})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Manager Mobile",name:"mobile",value:b.mobile,onChange:e=>{let t=e.target.value.replace(/\D/g,"");t=t.slice(0,10);let s=t;t.length>0&&(s="("+t.substring(0,3)),t.length>=4&&(s+=") "+t.substring(3,6)),t.length>=7&&(s+="-"+t.substring(6,10)),s=s.replace(/\(\) /g,""),R({target:{name:"mobile",value:s}})},error:!!c.mobile,helperText:c.mobile,inputProps:{maxLength:14}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Manager User ID",name:"managerUserId",type:"number",value:b.managerUserId,onChange:R,error:!!c.managerUserId,helperText:c.managerUserId||"Enter the ID of the user who will manage this store"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Delivery Radius (mi)",name:"radius",type:"number",value:b.radius,onChange:R,inputProps:{step:"0.1"},error:!!c.radius,helperText:c.radius})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Delivery Fee ($)",name:"storeDeliveryFee",type:"number",value:b.storeDeliveryFee,onChange:R,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:"$"})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Tax Rate (%)",name:"taxPercentage",type:"number",value:b.taxPercentage,onChange:R,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,Y.jsx)(p.A,{position:"end",children:"%"})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Description",name:"description",value:b.description,onChange:R,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Terms & Conditions",name:"tnc",value:b.tnc,onChange:R,multiline:!0,rows:3})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Delivery Pincodes",name:"pincodes",value:b.pincodes,onChange:R,helperText:"Enter pincodes separated by commas"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Display Field",name:"displayField",value:b.displayField,onChange:R,error:!!c.displayField,helperText:c.displayField||"Unique identifier for the store"})}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,Y.jsxs)(j.A,{sx:{mb:2},children:[b.sectionHeaders.map(((e,t)=>(0,Y.jsxs)(j.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,Y.jsx)(A.A,{fullWidth:!0,label:`Question ${t+1}`,value:e,onChange:e=>((e,t)=>{const s=[...b.sectionHeaders];s[e]=t,I((e=>({...e,sectionHeaders:s})))})(t,e.target.value),placeholder:"Enter question text"}),(0,Y.jsx)(ce.A,{color:"error",onClick:()=>(e=>{const t=b.sectionHeaders.filter(((t,s)=>s!==e));I((e=>({...e,sectionHeaders:t})))})(t),sx:{alignSelf:"center"},children:(0,Y.jsx)(Os.A,{})})]},t))),(0,Y.jsx)(J.A,{startIcon:(0,Y.jsx)(ve.A,{}),onClick:W,variant:"outlined",sx:{mt:1},children:"Add Question"})]})]})]});case 1:return(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Inventory Management"}),(0,Y.jsx)(h.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,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsxs)(ne.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Inventory Items"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Y.jsx)(Ae.A,{variant:"outlined",children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",children:"Product 1"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Category: Grocery"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Price: $9.99"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Stock: 50"})]})})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Y.jsx)(Ae.A,{variant:"outlined",children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",children:"Product 2"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Category: Electronics"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Price: $49.99"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Stock: 25"})]})})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Y.jsx)(Ae.A,{variant:"outlined",children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",children:"Product 3"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Category: Clothing"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Price: $19.99"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Stock: 100"})]})})})]})]}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,Y.jsx)(J.A,{variant:"outlined",startIcon:(0,Y.jsx)(ve.A,{}),children:"Add Inventory Item"})})]})]});case 2:return(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Driver Management"}),(0,Y.jsx)(h.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,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsxs)(ne.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Drivers"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Y.jsx)(Ae.A,{variant:"outlined",children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",children:"John Doe"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Email: john.doe@example.com"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 123-4567"}),(0,Y.jsx)(Se.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Y.jsx)(Ae.A,{variant:"outlined",children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",children:"Jane Smith"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Email: jane.smith@example.com"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 987-6543"}),(0,Y.jsx)(Se.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Y.jsx)(Ae.A,{variant:"outlined",children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",children:"Mike Johnson"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Email: mike.johnson@example.com"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 456-7890"}),(0,Y.jsx)(Se.A,{label:"Inactive",color:"error",size:"small",sx:{mt:1}})]})})})]})]}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,Y.jsx)(J.A,{variant:"outlined",startIcon:(0,Y.jsx)(ve.A,{}),children:"Add Driver"})})]})]});case 3:return(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Store Manager Management"}),(0,Y.jsx)(h.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,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsxs)(ne.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Store Managers"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,children:(0,Y.jsx)(Ae.A,{variant:"outlined",children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",children:"Sarah Williams"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Email: sarah.williams@example.com"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 234-5678"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Role: Store Manager"}),(0,Y.jsx)(Se.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,children:(0,Y.jsx)(Ae.A,{variant:"outlined",children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",children:"Robert Brown"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Email: robert.brown@example.com"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 876-5432"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Role: Assistant Manager"}),(0,Y.jsx)(Se.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})})]})]}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,Y.jsx)(J.A,{variant:"outlined",startIcon:(0,Y.jsx)(ve.A,{}),children:"Add Store Manager"})})]})]});case 4:return(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Review Store Information"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(ne.A,{variant:"outlined",sx:{p:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Details"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"body2",children:[(0,Y.jsx)("strong",{children:"Name:"})," ",b.name]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"body2",children:[(0,Y.jsx)("strong",{children:"Address:"})," ",b.address]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"body2",children:[(0,Y.jsx)("strong",{children:"Manager User ID:"})," ",b.managerUserId]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"body2",children:[(0,Y.jsx)("strong",{children:"Delivery Radius:"})," ",b.radius," km"]})})]}),(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Additional Information (Placeholder)"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"body2",children:[(0,Y.jsx)("strong",{children:"Inventory Items:"})," 3 sample items"]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"body2",children:[(0,Y.jsx)("strong",{children:"Drivers:"})," 3 sample drivers"]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"body2",children:[(0,Y.jsx)("strong",{children:"Store Managers:"})," 2 sample managers"]})})]})]})})]});default:return null}})(f),(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",mt:4},children:[(0,Y.jsx)(J.A,{disabled:0===f,onClick:()=>{v((e=>e-1))},children:"Back"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",onClick:f===Vs.length-1?()=>{if(!q())return void o("Please fill in all required fields");const e=b.pincodes,t=e?e.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],s={name:b.name,address:b.address,managerUserId:parseInt(b.managerUserId,10),radius:parseFloat(b.radius),email:b.email,mobile:b.mobile,description:b.description||null,storeDeliveryFee:b.storeDeliveryFee?parseFloat(b.storeDeliveryFee):null,taxPercentage:b.taxPercentage?parseFloat(b.taxPercentage):null,tnc:b.tnc||null,displayField:b.displayField,sectionHeaders:b.sectionHeaders.filter((e=>e.trim().length>0)),pincodes:t,is_active:!0,disabled:!1};L.mutate(s)}:()=>{0!==f||q()?v((e=>e+1)):o("Please fill in all required fields")},disabled:L.isLoading,children:L.isLoading?(0,Y.jsx)(g.A,{size:24}):f===Vs.length-1?"Submit":"Next"})]})]})]}),(0,Y.jsxs)(Fe.A,{open:!!C,onClose:z,maxWidth:"md",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(_t.A,{}),(0,Y.jsx)(h.A,{variant:"h6",children:"Edit Store"})]})}),(0,Y.jsxs)("form",{onSubmit:e=>{e.preventDefault();const t=new FormData(e.target),s=t.get("pincodes"),n=s?s.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],r=t.get("sectionHeaders"),i=r?r.split("\n").map((e=>e.trim())).filter((e=>e.length>0)):[],a={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,displayField:t.get("displayField"),sectionHeaders:i};$.mutate(a)},children:[(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"name",label:"Store Name",defaultValue:C?.name,required:!0,fullWidth:!0})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"email",label:"Email",type:"email",defaultValue:C?.email,required:!0,fullWidth:!0})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"mobile",label:"Mobile Number",defaultValue:C?.mobile,fullWidth:!0,inputProps:{maxLength:14},onInput:e=>{let t=e.target.value.replace(/\D/g,"");t=t.slice(0,10);let s=t;t.length>0&&(s="("+t.substring(0,3)),t.length>=4&&(s+=") "+t.substring(3,6)),t.length>=7&&(s+="-"+t.substring(6,10)),s=s.replace(/\(\) /g,""),e.target.value=s}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"managerUserId",label:"Manager User ID",type:"number",defaultValue:C?.managerUserId,required:!0,fullWidth:!0})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"displayField",label:"Display Field",defaultValue:C?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"sectionHeaders",label:"Section Headers",defaultValue:C?.sectionHeaders?.join("\n"),fullWidth:!0,multiline:!0,rows:3,helperText:"Enter each section header on a new line"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"address",label:"Address",defaultValue:C?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:C?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:C?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:"$"})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:C?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,Y.jsx)(p.A,{position:"end",children:"%"})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:C?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"description",label:"Description",defaultValue:C?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"tnc",label:"Terms & Conditions",defaultValue:C?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,children:[(0,Y.jsx)(Es.A,{children:"Store Status"}),(0,Y.jsxs)(ks.A,{name:"isActive",label:"Store Status",defaultValue:C?.isActive,children:[(0,Y.jsx)(ue.A,{value:!0,children:"Active"}),(0,Y.jsx)(ue.A,{value:!1,children:"Inactive"})]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,children:[(0,Y.jsx)(Es.A,{children:"Disabled Status"}),(0,Y.jsxs)(ks.A,{name:"disabled",label:"Disabled Status",defaultValue:C?.disabled,children:[(0,Y.jsx)(ue.A,{value:!0,children:"Disabled"}),(0,Y.jsx)(ue.A,{value:!1,children:"Enabled"})]})]})})]})}),(0,Y.jsxs)(Fs.A,{sx:{p:3,pt:0},children:[(0,Y.jsx)(J.A,{onClick:z,children:"Cancel"}),(0,Y.jsx)(J.A,{type:"submit",variant:"contained",disabled:$.isPending,startIcon:$.isPending?(0,Y.jsx)(g.A,{size:20}):null,children:$.isPending?"Updating...":"Update Store"})]})]})]}),(0,Y.jsx)(Ds.A,{open:w.open,autoHideDuration:6e3,onClose:()=>E({...w,open:!1}),children:(0,Y.jsx)(te.A,{onClose:()=>E({...w,open:!1}),severity:w.severity,sx:{width:"100%"},children:w.message})})]})};var Hs=s(15068);const Ks=()=>{const[e,t]=(0,x.useState)(""),[s,n]=(0,x.useState)(!1),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)({name:"",description:"",categoryId:"",image:""}),[l,d]=(0,x.useState)(!1),[c,m]=(0,x.useState)(!1),[p,f]=(0,x.useState)(null),[v,b]=(0,x.useState)(!1),[I,C]=(0,x.useState)(""),[S,w]=(0,x.useState)(""),[E,k]=(0,x.useState)(0),[F,D]=(0,x.useState)(10),[L,$]=(0,x.useState)([]),[T,W]=(0,x.useState)(""),[q,z]=(0,x.useState)(!1),[O,N]=(0,x.useState)({open:!1,message:"",severity:"info"}),[U,B]=(0,x.useState)(""),M=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",{data:_,refetch:V}=(0,u.I)({queryKey:["products",e],queryFn:()=>P(R),enabled:!1}),{data:G,refetch:H}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await P("\n query GetCategories {\n categories {\n id\n name\n }\n }\n")).categories||[]}),K=(0,Ts.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:()=>{ie(),se(),N({open:!0,message:"Product added successfully!",severity:"success"})}}),Q=(0,Ts.n)({mutationFn:e=>{let{id:t,data:s}=e;return P("\n mutation UpdateProduct(\n $productId: Int!,\n $name: String!,\n $description: String!,\n $categoryId: Int!,\n $image: String\n ) {\n updateProduct(\n productId: $productId,\n name: $name,\n description: $description,\n categoryId: $categoryId,\n image: $image\n ) {\n id\n name\n description\n categoryId\n image\n }\n }\n",{productId:t,name:s.name,description:s.description,categoryId:parseInt(s.categoryId,10),image:s.image||null})},onSuccess:()=>{ie(),se(),N({open:!0,message:"Product updated successfully!",severity:"success"})},onError:e=>{N({open:!0,message:`Failed to update product: ${e.message}`,severity:"error"})}}),Z=((0,Ts.n)({mutationFn:e=>P("\n mutation DeleteProduct($productId: Int!) {\n deleteProduct(productId: $productId)\n }\n",{productId:e}),onSuccess:()=>{V()}}),(0,Ts.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:()=>{b(!1),C(""),w(""),H()},onError:e=>{w(e.message||"Failed to create category")}})),X=(0,x.useMemo)((()=>G?G.reduce(((e,t)=>(e[t.id]=t.name,e)),{}):{}),[G]),ee=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(i(e),o({name:e.name,description:e.description,categoryId:e.categoryId,image:e.image})):(i(null),o({name:"",description:"",categoryId:"",image:""})),n(!0)},se=()=>{n(!1),i(null),o({name:"",description:"",categoryId:"",image:""})},re=e=>{const{name:t,value:s}=e.target;"categoryId"!==t||"new"!==s?(o((e=>({...e,[t]:s}))),B("")):b(!0)},ie=()=>{m(!0),f(null),V().then((e=>{e.data?.products&&$(e.data.products),d(!0),m(!1)})).catch((e=>{f("Failed to load products. Please try again."),m(!1)}))},ae=()=>{I.trim()?Z.mutate(I.trim()):w("Category name is required")},oe=(0,x.useMemo)((()=>e?L.filter((t=>t.categoryId===parseInt(e))):L),[L,e]),le=(0,x.useMemo)((()=>{const e=E*F;return oe.slice(e,e+F)}),[oe,E,F]),de=()=>{N((e=>({...e,open:!1})))};return(0,Y.jsxs)(j.A,{children:[(0,Y.jsxs)(ne.A,{sx:{p:3,mb:3},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Y.jsx)(ve.A,{sx:{mr:1}}),(0,Y.jsx)(h.A,{variant:"h5",children:"Product Management"})]}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,children:[(0,Y.jsx)(Es.A,{children:"Category"}),(0,Y.jsxs)(ks.A,{value:e,onChange:e=>t(e.target.value),label:"Category",children:[(0,Y.jsx)(ue.A,{value:"",children:"All Categories"}),Object.entries(X).map((e=>{let[t,s]=e;return(0,Y.jsx)(ue.A,{value:t,children:s},t)}))]})]})}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,md:8,sx:{display:"flex",alignItems:"center",gap:2},children:[(0,Y.jsx)(J.A,{variant:"contained",startIcon:(0,Y.jsx)(Ns.A,{}),onClick:ie,disabled:c,sx:{minWidth:150},children:c?(0,Y.jsx)(g.A,{size:24}):"Fetch Products"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>ee(),children:"Add Product"})]})]}),p&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:3},children:p}),l?c?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Y.jsx)(g.A,{})}):(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)(ys.A,{component:ne.A,children:[(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Image"}),(0,Y.jsx)(Is.A,{children:"Name"}),(0,Y.jsx)(Is.A,{children:"Category"}),(0,Y.jsx)(Is.A,{children:"Description"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:le.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:(0,Y.jsx)("img",{src:e.image,alt:e.name,style:{width:"50px",height:"50px",objectFit:"cover"}})}),(0,Y.jsx)(Is.A,{children:e.name}),(0,Y.jsx)(Is.A,{children:X[e.categoryId]||"Unknown"}),(0,Y.jsx)(Is.A,{children:e.description}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(ce.A,{size:"small",onClick:()=>ee(e),children:(0,Y.jsx)(Ls.A,{})})})]},e.id)))})]}),(0,Y.jsx)(y.A,{component:"div",count:oe.length,page:E,onPageChange:(e,t)=>{k(t)},rowsPerPage:F,onRowsPerPageChange:e=>{D(parseInt(e.target.value,10)),k(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,Y.jsxs)(j.A,{sx:{textAlign:"center",py:4},children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Products" to load product information'}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,Y.jsxs)(Fe.A,{open:s,onClose:se,maxWidth:"md",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:r?"Edit Product":"Add New Product"}),(0,Y.jsxs)(Le.A,{children:[U&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:U}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Product Name",name:"name",value:a.name,onChange:re})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,required:!0,children:[(0,Y.jsx)(Es.A,{children:"Category"}),(0,Y.jsxs)(ks.A,{name:"categoryId",value:a.categoryId,onChange:re,label:"Category",children:[(0,Y.jsx)(ue.A,{value:"",children:(0,Y.jsx)("em",{children:"Select a category"})}),Object.entries(X).map((e=>{let[t,s]=e;return(0,Y.jsx)(ue.A,{value:t,children:s},t)})),(0,Y.jsx)(ue.A,{value:"new",sx:{borderTop:"1px solid #e0e0e0",mt:1},children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",color:"primary.main"},children:[(0,Y.jsx)(ve.A,{sx:{mr:1}}),"Add New Category"]})})]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,multiline:!0,rows:3,label:"Description",name:"description",value:a.description,onChange:re})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",flexDirection:"column",gap:1},children:[(0,Y.jsx)(A.A,{fullWidth:!0,label:"Image URL",name:"image",value:a.image,onChange:re,placeholder:"https://example.com/image.jpg",disabled:q,error:!!T,helperText:T}),(0,Y.jsxs)(J.A,{variant:"outlined",component:"label",startIcon:(0,Y.jsx)(Hs.A,{}),disabled:q||!a.name||!a.categoryId,children:[q?"Uploading...":"Upload Image",(0,Y.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)W("Image size should be less than 5MB");else try{z(!0),W("");const e=X[a.categoryId]||"uncategorized",s=await fetch(`${M}/s3/generate-product-upload-url?product_name=${encodeURIComponent(a.name)}&category_name=${encodeURIComponent(e)}&file_name=${encodeURIComponent(t.name)}`);if(!s.ok)throw new Error("Failed to get upload URL");const{upload_url:n,content_type:r,key:i}=await s.json();if(!(await fetch(n,{method:"PUT",headers:{"Content-Type":r},body:t})).ok)throw new Error("Failed to upload image");const l=`https://indimitra-dev-order-files.s3.amazonaws.com/${i}`;o((e=>({...e,image:l}))),N({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){W("Failed to upload image. Please try again."),N({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{z(!1)}else W("Please upload a valid image file (JPEG, PNG, GIF, or WebP)")},disabled:q})]}),a.image&&(0,Y.jsx)(j.A,{sx:{mt:1},children:(0,Y.jsx)("img",{src:a.image,alt:"Product preview",style:{maxWidth:"200px",maxHeight:"200px",objectFit:"contain"}})})]})})]})]}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:se,children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{if(a.name.trim()&&a.description.trim()&&a.categoryId&&a.image)if(B(""),r)Q.mutate({productId:r.id,name:a.name,description:a.description,categoryId:parseInt(a.categoryId,10),image:a.image});else{const e={name:a.name,description:a.description,categoryId:parseInt(a.categoryId,10),image:a.image||null};K.mutate(e)}else B("Please fill in all required fields, including an image.")},disabled:K.isLoading||Q.isLoading,children:K.isLoading||Q.isLoading?(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(g.A,{size:20,color:"inherit"}),r?"Updating...":"Creating..."]}):r?"Update":"Add"})]})]}),(0,Y.jsxs)(Fe.A,{open:v,onClose:()=>b(!1),children:[(0,Y.jsx)(De.A,{children:"Add New Category"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(A.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:I,onChange:e=>C(e.target.value),error:!!S,helperText:S,onKeyPress:e=>{"Enter"===e.key&&ae()}})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>b(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:ae,variant:"contained",disabled:Z.isLoading,children:Z.isLoading?"Creating...":"Create"})]})]}),(0,Y.jsx)(Ds.A,{open:O.open,autoHideDuration:6e3,onClose:de,anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,Y.jsx)(te.A,{onClose:de,severity:O.severity,sx:{width:"100%"},children:O.message})})]})};var Ys=s(75813),Qs=s(8047),Js=s(89966),Zs=s(54415),Xs=s(52653);const en=[{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"}],tn=()=>{const[e,t]=(0,x.useState)(""),[s,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(!1),[c,m]=(0,x.useState)(null),[y,f]=(0,x.useState)(!1),[v,b]=(0,x.useState)(""),[I,C]=(0,x.useState)(""),[S,w]=(0,x.useState)(""),[k,F]=(0,x.useState)(""),{data:L,isLoading:$,refetch:T}=(0,u.I)({queryKey:["orders",s,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:l}),{data:R}=(0,u.I)({queryKey:["storeDrivers",a?.storeId],queryFn:async()=>a?.storeId?await P(D,{storeId:a.storeId}):null,enabled:!!a?.storeId}),W=(0,Ts.n)({mutationFn:async e=>await P(E,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onSuccess:()=>{T(),f(!1),o(null),b(""),C(""),w(""),F("")},onError:e=>{m(e.message)}}),q=()=>{d(!0),T()},z=()=>{i(!1),o(null)},O=e=>{const{name:s,value:r}=e.target;"searchTerm"===s?t(r):"statusFilter"===s&&n(r)},N=e=>{switch(e){case"READY_FOR_DELIVERY":return"success";case"CANCELLED":return"error";case"PENDING":return"warning";default:return"default"}},U=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,Y.jsx)(Ys.A,{});case"CANCELLED":return(0,Y.jsx)(Qs.A,{});case"PENDING":return(0,Y.jsx)(Js.A,{});default:return null}},B=e=>{if(!e)return"Not scheduled";return new Date(e).toLocaleString()},M=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e),_=L?.getAllOrders?.filter((t=>{const n=""===e||t.address?.address.toLowerCase().includes(e.toLowerCase())||t.id.toString().includes(e),r=""===s||t.status===s;return n&&r}));return(0,Y.jsxs)(j.A,{children:[(0,Y.jsxs)(ne.A,{sx:{p:3,mb:3},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Y.jsx)(Zs.A,{sx:{mr:1}}),(0,Y.jsx)(h.A,{variant:"h5",children:"Orders Management"})]}),c&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:3},children:c}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsx)(A.A,{fullWidth:!0,placeholder:"Search by address or order ID",name:"searchTerm",value:e,onChange:O,InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)($s.A,{})})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,children:[(0,Y.jsx)(Es.A,{children:"Status"}),(0,Y.jsxs)(ks.A,{name:"statusFilter",value:s,onChange:O,label:"Status",children:[(0,Y.jsx)(ue.A,{value:"",children:"All Status"}),(0,Y.jsx)(ue.A,{value:"PENDING",children:"Pending"}),(0,Y.jsx)(ue.A,{value:"ACCEPTED",children:"Accepted"}),(0,Y.jsx)(ue.A,{value:"READY_FOR_DELIVERY",children:"Ready for Delivery"}),(0,Y.jsx)(ue.A,{value:"PICKED_UP",children:"Picked Up"}),(0,Y.jsx)(ue.A,{value:"DELIVERED",children:"Delivered"}),(0,Y.jsx)(ue.A,{value:"CANCELLED",children:"Cancelled"})]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(Ns.A,{}),onClick:q,fullWidth:!0,sx:{height:"56px"},children:"Fetch Orders"})})]}),l?$?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,Y.jsx)(g.A,{})}):0===_?.length?(0,Y.jsx)(te.A,{severity:"info",sx:{mb:3},children:"No orders found matching your criteria"}):(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Order ID"}),(0,Y.jsx)(Is.A,{children:"Address"}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{children:"Total Amount"}),(0,Y.jsx)(Is.A,{children:"Delivery Date"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:_.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsxs)(Is.A,{children:["#",e.id]}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(h.A,{variant:"body2",children:e.address?.address||"N/A"})}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{icon:U(e.status),label:e.status.replace(/_/g," "),color:N(e.status),size:"small"})}),(0,Y.jsx)(Is.A,{children:M(e.totalAmount)}),(0,Y.jsx)(Is.A,{children:B(e.deliveryDate)}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{size:"small",onClick:()=>(e=>{o(e),i(!0)})(e),children:(0,Y.jsx)(Xs.A,{})}),(0,Y.jsx)(ce.A,{size:"small",onClick:()=>(e=>{o(e),b(e.status),C(e.deliveryInstructions||""),f(!0)})(e),disabled:"CANCELLED"===e.status||"DELIVERED"===e.status,children:(0,Y.jsx)(Ls.A,{})})]})]},e.id)))})]})}):(0,Y.jsxs)(Ae.A,{sx:{mb:3},children:[(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Orders" to load order data'}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]}),(0,Y.jsx)(ge.A,{sx:{justifyContent:"center"},children:(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(Ns.A,{}),onClick:q,children:"Fetch Orders"})})]})]}),(0,Y.jsxs)(Fe.A,{open:r,onClose:z,maxWidth:"md",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:"Order Details"}),(0,Y.jsx)(Le.A,{children:a&&(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsxs)(h.A,{variant:"h6",gutterBottom:!0,children:["Order #",a.id]}),(0,Y.jsx)(Se.A,{icon:U(a.status),label:a.status.replace(/_/g," "),color:N(a.status),sx:{mb:2}})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Information"}),(0,Y.jsxs)(h.A,{variant:"body2",children:["Address: ",a.address?.address||"N/A"]}),(0,Y.jsxs)(h.A,{variant:"body2",children:["Total Amount: ",M(a.totalAmount)]}),(0,Y.jsxs)(h.A,{variant:"body2",children:["Delivery Date: ",B(a.deliveryDate)]}),a.deliveryInstructions&&(0,Y.jsxs)(h.A,{variant:"body2",children:["Delivery Instructions: ",a.deliveryInstructions]})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Items"}),(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{size:"small",children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Product"}),(0,Y.jsx)(Is.A,{children:"Quantity"}),(0,Y.jsx)(Is.A,{children:"Amount"})]})}),(0,Y.jsx)(Cs.A,{children:a.orderItems?.edges?.map((e=>{let{node:t}=e;return(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:t.product?.name||"N/A"}),(0,Y.jsx)(Is.A,{children:t.quantity}),(0,Y.jsx)(Is.A,{children:M(t.orderAmount)})]},t.id)}))})]})})]})]})}),(0,Y.jsx)(Fs.A,{children:(0,Y.jsx)(J.A,{onClick:z,children:"Close"})})]}),(0,Y.jsxs)(Fe.A,{open:y,onClose:()=>f(!1),maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:"Update Order Status"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{select:!0,fullWidth:!0,label:"Status",value:v,onChange:e=>b(e.target.value),children:en.map((e=>(0,Y.jsx)(ue.A,{value:e.value,children:e.label},e.value)))})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Delivery Instructions",value:I,onChange:e=>C(e.target.value),multiline:!0,rows:3})}),("READY"===v||"READY_FOR_DELIVERY"===v)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,required:!0,children:[(0,Y.jsx)(Es.A,{children:"Delivery Agent"}),(0,Y.jsx)(ks.A,{value:S,onChange:e=>w(e.target.value),label:"Delivery Agent",children:R?.getStoreDrivers?.map((e=>(0,Y.jsxs)(ue.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId)))})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Schedule Time",value:k,onChange:e=>F(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>f(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:async()=>{try{const e={orderId:a.id,status:v,deliveryInstructions:I};if("READY"===v||"READY_FOR_DELIVERY"===v){if(!S)return void m("Driver ID is required for this status");if(!k)return void m("Schedule time is required for this status");e.driverId=parseInt(S),e.scheduleTime=k}await W.mutateAsync(e)}catch(e){m(e.message)}},variant:"contained",color:"primary",disabled:W.isLoading,children:W.isLoading?"Updating...":"Update"})]})]})]})},sn=["Store Selection","Payment Method","Account Details","Documents","Review"],nn=()=>{const[e,t]=(0,x.useState)(""),[s,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(0),[c,m]=(0,x.useState)({storeId:"",paymentMethod:"",accountDetails:{accountName:"",accountNumber:"",bankName:"",ifscCode:"",routingNumber:"",swiftCode:""},documents:[]}),[y,f]=(0,x.useState)(null),[v,b]=(0,x.useState)(!1),{data:I,isLoading:C,refetch:S,error:w}=(0,u.I)({queryKey:["paymentOnboarding",s,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:s||null,searchTerm:e||null})}),{data:E={stores:[]}}=(0,u.I)({queryKey:["stores"],queryFn:()=>P("\n query GetStores {\n stores {\n id\n name\n }\n }\n")}),k=(0,Ts.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:()=>{S(),$(),b(!0),setTimeout((()=>b(!1)),3e3)},onError:e=>{f(e.message||"Failed to create payment onboarding"),setTimeout((()=>f(null)),3e3)}}),F=(0,Ts.n)({mutationFn:e=>{let{id:t,data:s}=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:s})},onSuccess:()=>{S(),$(),b(!0),setTimeout((()=>b(!1)),3e3)},onError:e=>{f(e.message||"Failed to update payment onboarding"),setTimeout((()=>f(null)),3e3)}}),D=(0,Ts.n)({mutationFn:e=>P("\n mutation DeletePaymentOnboarding($id: ID!) {\n deletePaymentOnboarding(id: $id)\n }\n",{id:e}),onSuccess:()=>{S(),b(!0),setTimeout((()=>b(!1)),3e3)},onError:e=>{f(e.message||"Failed to delete payment onboarding"),setTimeout((()=>f(null)),3e3)}}),L=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(o(e),m({storeId:e.store.id,paymentMethod:e.paymentMethod,accountDetails:e.accountDetails||{accountName:"",accountNumber:"",bankName:"",ifscCode:"",routingNumber:"",swiftCode:""},documents:e.documents||[]})):(o(null),m({storeId:"",paymentMethod:"",accountDetails:{accountName:"",accountNumber:"",bankName:"",ifscCode:"",routingNumber:"",swiftCode:""},documents:[]})),d(0),i(!0)},$=()=>{i(!1),o(null),d(0),m({storeId:"",paymentMethod:"",accountDetails:{accountName:"",accountNumber:"",bankName:"",ifscCode:"",routingNumber:"",swiftCode:""},documents:[]})},T=e=>{const{name:t,value:s}=e.target;if(t.startsWith("accountDetails.")){const e=t.split(".")[1];m((t=>({...t,accountDetails:{...t.accountDetails,[e]:s}})))}else m((e=>({...e,[t]:s})))},R=e=>{switch(e){case"APPROVED":return"success";case"REJECTED":return"error";case"PENDING":return"warning";default:return"default"}},W=e=>{switch(e){case"APPROVED":return(0,Y.jsx)(CheckCircleIcon,{});case"REJECTED":return(0,Y.jsx)(ErrorIcon,{});case"PENDING":return(0,Y.jsx)(PendingIcon,{});default:return null}},q=e=>new Date(e).toLocaleString();return(0,Y.jsxs)(j.A,{children:[(0,Y.jsxs)(ne.A,{sx:{p:3,mb:3},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Y.jsx)(cs.A,{sx:{mr:1}}),(0,Y.jsx)(h.A,{variant:"h5",children:"Payment Onboarding"})]}),y&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:3},children:y}),v&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:3},children:a?"Payment onboarding updated successfully!":"Payment onboarding created successfully!"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,placeholder:"Search by store name",value:e,onChange:e=>t(e.target.value),InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)($s.A,{})})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,children:[(0,Y.jsx)(Es.A,{children:"Status"}),(0,Y.jsxs)(ks.A,{value:s,onChange:e=>n(e.target.value),label:"Status",children:[(0,Y.jsx)(ue.A,{value:"",children:"All Status"}),(0,Y.jsx)(ue.A,{value:"APPROVED",children:"Approved"}),(0,Y.jsx)(ue.A,{value:"PENDING",children:"Pending"}),(0,Y.jsx)(ue.A,{value:"REJECTED",children:"Rejected"})]})]})})]}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>L(),sx:{mb:3},disabled:!0,children:"Add Payment Onboarding"}),(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Store"}),(0,Y.jsx)(Is.A,{children:"Payment Method"}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{children:"Created At"}),(0,Y.jsx)(Is.A,{children:"Updated At"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:w?(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:6,align:"center",children:(0,Y.jsx)(h.A,{color:"error",children:"Error fetching payment onboarding"})})}):C?(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:6,align:"center",children:(0,Y.jsx)(g.A,{})})}):0===I?.paymentOnboarding.length?(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:6,align:"center",children:"No payment onboarding found"})}):I?.paymentOnboarding.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.store.name}),(0,Y.jsx)(Is.A,{children:e.paymentMethod}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{icon:W(e.status),label:e.status,color:R(e.status),size:"small"})}),(0,Y.jsx)(Is.A,{children:q(e.createdAt)}),(0,Y.jsx)(Is.A,{children:q(e.updatedAt)}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{size:"small",onClick:()=>L(e),children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{size:"small",onClick:()=>{return t=e.id,void(window.confirm("Are you sure you want to delete this payment onboarding?")&&D.mutate(t));var t},children:(0,Y.jsx)(DeleteIcon,{})})]})]},e.id)))})]})})]}),(0,Y.jsxs)(Fe.A,{open:r,onClose:$,maxWidth:"md",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:a?"Edit Payment Onboarding":"Add New Payment Onboarding"}),(0,Y.jsxs)(Le.A,{children:[(0,Y.jsx)(Ws.A,{activeStep:l,sx:{my:3},children:sn.map((e=>(0,Y.jsx)(qs.A,{children:(0,Y.jsx)(zs.A,{children:e})},e)))}),(0,Y.jsx)(kt.A,{sx:{mb:3}}),(e=>{switch(e){case 0:return(0,Y.jsx)(me.Ay,{container:!0,spacing:2,children:(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Select Store"}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,required:!0,children:[(0,Y.jsx)(Es.A,{children:"Store"}),(0,Y.jsx)(ks.A,{name:"storeId",value:c.storeId,onChange:T,label:"Store",children:E?.stores?.map((e=>(0,Y.jsx)(ue.A,{value:e.id,children:e.name},e.id)))})]})]})});case 1:return(0,Y.jsx)(me.Ay,{container:!0,spacing:2,children:(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Payment Method"}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,required:!0,children:[(0,Y.jsx)(Es.A,{children:"Payment Method"}),(0,Y.jsxs)(ks.A,{name:"paymentMethod",value:c.paymentMethod,onChange:T,label:"Payment Method",children:[(0,Y.jsx)(ue.A,{value:"BANK_TRANSFER",children:"Bank Transfer"}),(0,Y.jsx)(ue.A,{value:"UPI",children:"UPI"}),(0,Y.jsx)(ue.A,{value:"PAYPAL",children:"PayPal"}),(0,Y.jsx)(ue.A,{value:"STRIPE",children:"Stripe"})]})]})]})});case 2:return(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Account Details"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Account Name",name:"accountDetails.accountName",value:c.accountDetails.accountName,onChange:T})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Account Number",name:"accountDetails.accountNumber",value:c.accountDetails.accountNumber,onChange:T})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{required:!0,fullWidth:!0,label:"Bank Name",name:"accountDetails.bankName",value:c.accountDetails.bankName,onChange:T})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"IFSC Code",name:"accountDetails.ifscCode",value:c.accountDetails.ifscCode,onChange:T})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Routing Number",name:"accountDetails.routingNumber",value:c.accountDetails.routingNumber,onChange:T})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"SWIFT Code",name:"accountDetails.swiftCode",value:c.accountDetails.swiftCode,onChange:T})})]});case 3:return(0,Y.jsx)(me.Ay,{container:!0,spacing:2,children:(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Documents"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",paragraph:!0,children:"Upload relevant documents for payment verification. This step is optional."}),(0,Y.jsxs)(J.A,{variant:"outlined",component:"label",children:["Upload Documents",(0,Y.jsx)("input",{type:"file",hidden:!0,multiple:!0,onChange:e=>{const t=Array.from(e.target.files).map((e=>e.name));m((e=>({...e,documents:[...e.documents,...t]})))}})]}),c.documents.length>0&&(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",children:"Uploaded Documents:"}),(0,Y.jsx)("ul",{children:c.documents.map(((e,t)=>(0,Y.jsx)("li",{children:e},t)))})]})]})});case 4:return(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Review Information"})}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",children:"Store"}),(0,Y.jsx)(h.A,{children:E?.stores?.find((e=>e.id===c.storeId))?.name||"No store selected"})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",children:"Payment Method"}),(0,Y.jsx)(h.A,{children:c.paymentMethod})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",children:"Account Details"}),(0,Y.jsxs)(h.A,{children:["Account Name: ",c.accountDetails.accountName]}),(0,Y.jsxs)(h.A,{children:["Account Number: ",c.accountDetails.accountNumber]}),(0,Y.jsxs)(h.A,{children:["Bank Name: ",c.accountDetails.bankName]}),c.accountDetails.ifscCode&&(0,Y.jsxs)(h.A,{children:["IFSC Code: ",c.accountDetails.ifscCode]}),c.accountDetails.routingNumber&&(0,Y.jsxs)(h.A,{children:["Routing Number: ",c.accountDetails.routingNumber]}),c.accountDetails.swiftCode&&(0,Y.jsxs)(h.A,{children:["SWIFT Code: ",c.accountDetails.swiftCode]})]}),c.documents.length>0&&(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",children:"Documents"}),(0,Y.jsx)("ul",{children:c.documents.map(((e,t)=>(0,Y.jsx)("li",{children:e},t)))})]})]});default:return null}})(l)]}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:$,children:"Cancel"}),(0,Y.jsx)(J.A,{disabled:0===l,onClick:()=>{d((e=>e-1))},sx:{mr:1},children:"Back"}),l===sn.length-1?(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{const e={...c,status:"PENDING"};a?F.mutate({id:a.id,data:e}):k.mutate(e)},disabled:k.isLoading||F.isLoading,children:k.isLoading||F.isLoading?(0,Y.jsx)(g.A,{size:24}):a?"Update":"Submit"}):(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{d((e=>e+1))},children:"Next"})]})]})]})};var rn=s(87558),an=s(1275),on=s(88116),ln=s(98708),dn=s(60181);const cn=()=>{const[e,t]=(0,x.useState)(0),[s,n]=(0,x.useState)(10),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(""),[l,d]=(0,x.useState)(null),[c,m]=(0,x.useState)(!1),[f,v]=(0,x.useState)(!1),[b,I]=(0,x.useState)(!1),[C,S]=(0,x.useState)(""),[w,E]=(0,x.useState)(""),[k,F]=(0,x.useState)(!0),[D,L]=(0,x.useState)(!0),[$,W]=(0,x.useState)({open:!1,message:"",severity:"success"}),[q,z]=(0,x.useState)("table"),[O,N]=(0,x.useState)(null),[U,B]=(0,x.useState)(""),[M,_]=(0,x.useState)(!1),[V,G]=(0,x.useState)({price:"",quantity:"",measurement:"",unit:""}),H=(0,x.useRef)(null),{data:K=[],isLoading:Q,error:Z,refetch:X}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{const e=await P(T);return e?.stores||[]},enabled:!0}),{data:ee,isLoading:se}=(0,u.I)({queryKey:["products"],queryFn:async()=>{const e=await P(R);return e?.products||[]},enabled:b}),{data:re,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}),le=(0,Ts.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:()=>{W({open:!0,message:"Inventory item updated successfully",severity:"success"}),oe(),m(!1)},onError:e=>{W({open:!0,message:`Error updating inventory: ${e.message}`,severity:"error"})}}),de=(0,Ts.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:()=>{W({open:!0,message:"Product added to inventory successfully",severity:"success"}),oe(),I(!1),fe()},onError:e=>{W({open:!0,message:`Error adding product to inventory: ${e.message}`,severity:"error"})}}),xe=e=>{d(e),S(e.quantity.toString()),E(e.price.toString()),F(e.isAvailable),L(e.isListed),m(!0)},he=e=>{d(e),v(!0)},ge=()=>{W({...$,open:!1})},ye=()=>{I(!1),fe()},fe=()=>{N(null),B(""),G({price:"",quantity:"",measurement:"",unit:""})},be=e=>{const{name:t,value:s}=e.target;G((e=>({...e,[t]:s})))},Ie=()=>re?re.filter((e=>e.product.name.toLowerCase().includes(r.toLowerCase()))):[],Ce=ee?.filter((e=>e.name.toLowerCase().includes(U.toLowerCase())))||[],we=(0,x.useRef)(null),Pe=(0,x.useCallback)((()=>{if("grid"!==q||!we.current)return;const e=we.current.offsetWidth,t=window.innerHeight-we.current.getBoundingClientRect().top-150,r=Math.max(1,Math.floor(e/270))*Math.max(1,Math.floor(t/260));r!==s&&n(r)}),[q,s]);(0,x.useEffect)((()=>{if("grid"===q)return Pe(),window.addEventListener("resize",Pe),()=>window.removeEventListener("resize",Pe)}),[q,Pe]),(0,x.useEffect)((()=>{"table"===q&&10!==s&&n(10)}),[q,s]);return(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Inventory Management"}),(0,Y.jsxs)(ne.A,{sx:{p:3,mb:3},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",mb:3,flexWrap:"wrap",gap:2},children:[(0,Y.jsxs)(Ps.A,{sx:{minWidth:200},children:[(0,Y.jsx)(Es.A,{children:"Select Store"}),(0,Y.jsx)(ks.A,{value:a,onChange:e=>{o(e.target.value),t(0)},label:"Select Store",children:Array.isArray(K)&&K?.map((e=>(0,Y.jsx)(ue.A,{value:e.id,children:e.name},e.id)))})]}),(0,Y.jsx)(A.A,{placeholder:"Search products...",value:r,onChange:e=>{i(e.target.value),t(0)},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)($s.A,{})})},sx:{width:300}}),(0,Y.jsx)(J.A,{variant:"outlined",startIcon:"table"===q?(0,Y.jsx)(ln.A,{}):(0,Y.jsx)(dn.A,{}),onClick:()=>{z("table"===q?"grid":"table")},children:"table"===q?"Grid View":"Table View"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>{a?I(!0):W({open:!0,message:"Please select a store first",severity:"warning"})},disabled:!a,children:"Add Product"})]}),Z&&(0,Y.jsxs)(te.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",Z.message]}),ae&&(0,Y.jsxs)(te.A,{severity:"error",sx:{mb:3},children:["Error loading inventory: ",ae.message]}),a?ie?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Y.jsx)(g.A,{})}):0===Ie().length?(0,Y.jsx)(te.A,{severity:"info",sx:{my:4},children:"No inventory found for this store."}):(0,Y.jsxs)(Y.Fragment,{children:["table"===q?(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Product"}),(0,Y.jsx)(Is.A,{children:"Category"}),(0,Y.jsx)(Is.A,{children:"Available"}),(0,Y.jsx)(Is.A,{children:"Listed"}),(0,Y.jsx)(Is.A,{children:"Price"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:Ie().slice(e*s,e*s+s).map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[e.product.image&&(0,Y.jsx)(j.A,{component:"img",src:e.product.image,alt:e.product.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"body1",children:e.product.name}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:e.product.description})]})]})}),(0,Y.jsx)(Is.A,{children:e.product.category?.name||"N/A"}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:e.isAvailable?"Available":"Not Available",color:e.isAvailable?"success":"error",size:"small"})}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:e.isListed?"Listed":"Not Listed",color:e.isListed?"success":"error",size:"small"})}),(0,Y.jsxs)(Is.A,{children:["$",e.price.toFixed(2)]}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{size:"small",color:"primary",onClick:()=>xe(e),children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{size:"small",color:"error",onClick:()=>he(e),children:(0,Y.jsx)(Os.A,{})})]})]},e.id)))})]})}):(0,Y.jsx)(me.Ay,{container:!0,spacing:3,ref:we,children:Ie().slice(e*s,e*s+s).map((e=>(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,Y.jsxs)(Ae.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,Y.jsx)(pe.A,{component:"img",height:"140",image:e.product.image||"https://via.placeholder.com/140",alt:e.product.name}),(0,Y.jsxs)(je.A,{sx:{flexGrow:1},children:[(0,Y.jsx)(h.A,{gutterBottom:!0,variant:"h6",component:"div",noWrap:!0,children:e.product.name}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",sx:{mb:1},children:e.product.category?.name||"N/A"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",sx:{mb:1},noWrap:!0,children:e.product.description}),(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:2},children:[(0,Y.jsx)(Se.A,{label:`Qty: ${e.quantity}`,color:e.quantity<10?"error":"success",size:"small"}),(0,Y.jsxs)(h.A,{variant:"h6",color:"primary",children:["$",e.price.toFixed(2)]})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",mt:2},children:[(0,Y.jsx)(J.A,{size:"small",startIcon:(0,Y.jsx)(Ls.A,{}),onClick:()=>xe(e),children:"Edit"}),(0,Y.jsx)(J.A,{size:"small",color:"error",startIcon:(0,Y.jsx)(Os.A,{}),onClick:()=>he(e),children:"Delete"})]})]})]})},e.id)))}),(0,Y.jsx)(y.A,{component:"div",count:Ie().length,page:e,onPageChange:(e,s)=>{t(s)},rowsPerPage:s,onRowsPerPageChange:e=>{n(parseInt(e.target.value,10)),t(0)},rowsPerPageOptions:(()=>{if("grid"===q&&we.current){const e=we.current.offsetWidth,t=window.innerHeight-we.current.getBoundingClientRect().top-150,s=270,n=260,r=Math.max(1,Math.floor(e/s));Math.max(1,Math.floor(t/n));return[...[1*r,2*r,3*r,4*r,5*r].filter((e=>em(!1),fullWidth:!0,maxWidth:"sm",children:[(0,Y.jsx)(De.A,{children:"Edit Inventory Item"}),(0,Y.jsx)(Le.A,{children:l&&(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[l.product.image&&(0,Y.jsx)(j.A,{component:"img",src:l.product.image,alt:l.product.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"subtitle1",children:l.product.name}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:l.product.category?.name||"N/A"})]})]}),(0,Y.jsx)(A.A,{label:"Quantity",type:"number",fullWidth:!0,value:C,onChange:e=>S(e.target.value),sx:{mb:2}}),(0,Y.jsx)(A.A,{label:"Price ($)",type:"number",fullWidth:!0,value:w,onChange:e=>E(e.target.value),sx:{mb:2}}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mb:2},children:[(0,Y.jsx)(Es.A,{children:"Availability"}),(0,Y.jsxs)(ks.A,{value:k,onChange:e=>F(e.target.value),label:"Availability",children:[(0,Y.jsx)(ue.A,{value:!0,children:"Available"}),(0,Y.jsx)(ue.A,{value:!1,children:"Not Available"})]})]}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mb:2},children:[(0,Y.jsx)(Es.A,{children:"Listing Status"}),(0,Y.jsxs)(ks.A,{value:D,onChange:e=>L(e.target.value),label:"Listing Status",children:[(0,Y.jsx)(ue.A,{value:!0,children:"Listed"}),(0,Y.jsx)(ue.A,{value:!1,children:"Not Listed"})]})]})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>m(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:()=>{l&&le.mutate({inventoryId:l.id,price:parseFloat(w),quantity:parseInt(C),isAvailable:k,isListed:D})},variant:"contained",color:"primary",disabled:le.isPending,children:le.isPending?"Updating...":"Update"})]})]}),(0,Y.jsxs)(Fe.A,{open:f,onClose:()=>v(!1),fullWidth:!0,maxWidth:"sm",children:[(0,Y.jsx)(De.A,{children:"Delete Inventory Item"}),(0,Y.jsx)(Le.A,{children:l&&(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[l.product.image&&(0,Y.jsx)(j.A,{component:"img",src:l.product.image,alt:l.product.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"subtitle1",children:l.product.name}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:l.product.category?.name||"N/A"})]})]}),(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Are you sure you want to delete this inventory item?"}),(0,Y.jsxs)(h.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Quantity: ",l.quantity]}),(0,Y.jsxs)(h.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Price: ₹",l.price.toFixed(2)]})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>v(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:()=>{v(!1),W({open:!0,message:"Delete functionality not implemented yet",severity:"info"})},variant:"contained",color:"error",children:"Delete"})]})]}),(0,Y.jsxs)(Fe.A,{open:b,onClose:ye,fullWidth:!0,maxWidth:"md",children:[(0,Y.jsx)(De.A,{children:"Add Product to Inventory"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Select a product to add to the store's inventory"}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mt:2,mb:3},children:[(0,Y.jsx)(A.A,{ref:H,label:"Search Product",placeholder:"Start typing to search...",value:U,onChange:e=>{B(e.target.value),_(!0)},onFocus:()=>_(!0),onClick:()=>_(!0),fullWidth:!0,InputProps:{endAdornment:se?(0,Y.jsx)(g.A,{color:"inherit",size:20}):null}}),(0,Y.jsx)(rn.A,{open:M&&Ce.length>0,anchorEl:H.current,placement:"bottom-start",style:{width:H.current?.offsetWidth,zIndex:1300},children:(0,Y.jsx)(an.x,{onClickAway:()=>{_(!1)},children:(0,Y.jsx)(ne.A,{elevation:3,children:(0,Y.jsx)(on.A,{sx:{maxHeight:300,overflow:"auto"},children:Ce.map((e=>(0,Y.jsx)(ue.A,{onClick:()=>(e=>{N(e),B(e.name),_(!1)})(e),selected:O?.id===e.id,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[e.image&&(0,Y.jsx)(j.A,{component:"img",src:e.image,alt:e.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"body1",children:e.name}),(0,Y.jsx)(h.A,{variant:"caption",color:"textSecondary",children:e.categoryId?`Category ID: ${e.categoryId}`:"No category"})]})]})},e.id)))})})})})]}),O&&(0,Y.jsxs)(j.A,{sx:{mb:3,p:2,bgcolor:"background.paper",borderRadius:1},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",gutterBottom:!0,children:"Selected Product:"}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[O.image&&(0,Y.jsx)(j.A,{component:"img",src:O.image,alt:O.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"body1",children:O.name}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:O.description})]})]})]}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,children:(0,Y.jsx)(A.A,{label:"Price ($)",type:"number",name:"price",fullWidth:!0,value:V.price,onChange:be,required:!0,inputProps:{min:0,step:.01}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,children:(0,Y.jsx)(A.A,{label:"Quantity",type:"number",name:"quantity",fullWidth:!0,value:V.quantity,onChange:be,required:!0,inputProps:{min:0}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,children:(0,Y.jsx)(A.A,{label:"Measurement (optional)",type:"number",name:"measurement",fullWidth:!0,value:V.measurement,onChange:be,inputProps:{min:0,step:.01}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,children:(0,Y.jsx)(A.A,{label:"Unit (optional)",name:"unit",fullWidth:!0,value:V.unit,onChange:be,placeholder:"e.g., kg, g, L, ml"})})]})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:ye,children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:()=>{O?V.price&&V.quantity?de.mutate({productId:O.id,storeId:parseInt(a),price:parseFloat(V.price),quantity:parseInt(V.quantity),measurement:V.measurement?parseInt(V.measurement):null,unit:V.unit||""}):W({open:!0,message:"Please fill in all required fields",severity:"warning"}):W({open:!0,message:"Please select a product",severity:"warning"})},variant:"contained",color:"primary",disabled:de.isPending||!O,children:de.isPending?"Adding...":"Add to Inventory"})]})]}),(0,Y.jsx)(Ds.A,{open:$.open,autoHideDuration:6e3,onClose:ge,message:$.message,children:(0,Y.jsx)(te.A,{onClose:ge,severity:$.severity,children:$.message})})]})},xn=()=>{const[e,t]=(0,x.useState)(0),[s,n]=(0,x.useState)(10),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(""),[c,m]=(0,x.useState)(null),[p,f]=(0,x.useState)(!1),[v,b]=(0,x.useState)(!1),[I,C]=(0,x.useState)(null),[S,w]=(0,x.useState)(null),[E,k]=(0,x.useState)(!1),{data:F,refetch:D}=(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}),L=(0,Ts.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:()=>{W(),D()},onError:e=>{m(e.message||"Failed to create category")}}),$=(0,Ts.n)({mutationFn:e=>{let{id:t,name:s}=e;return P("\n mutation UpdateCategory($categoryId: Int!, $name: String!) {\n updateCategory(categoryId: $categoryId, name: $name) {\n category {\n id\n name\n }\n }\n }\n",{categoryId:t,name:s})},onSuccess:()=>{W(),D()},onError:e=>{m(e.message||"Failed to update category")}}),T=(0,Ts.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),D()},onError:e=>{m(e.message)}}),R=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(o(e),d(e.name)):(o(null),d("")),i(!0)},W=()=>{i(!1),o(null),d(""),m(null)},q=()=>{l.trim()?a?$.mutate({id:a.id,name:l.trim()}):L.mutate(l.trim()):m("Category name is required")},z=F?.slice(e*s,e*s+s);return(0,Y.jsxs)(j.A,{children:[(0,Y.jsxs)(ne.A,{sx:{p:3,mb:3},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Y.jsx)(ve.A,{sx:{mr:1}}),(0,Y.jsx)(h.A,{variant:"h5",children:"Category Management"})]}),(0,Y.jsx)(me.Ay,{container:!0,spacing:2,sx:{mb:3},children:(0,Y.jsxs)(me.Ay,{item:!0,xs:12,sx:{display:"flex",gap:2},children:[(0,Y.jsx)(J.A,{variant:"contained",startIcon:(0,Y.jsx)(Ns.A,{}),onClick:()=>{f(!0),m(null),D().then((()=>{b(!0),f(!1)})).catch((e=>{m("Failed to load categories. Please try again."),f(!1)}))},disabled:p,sx:{minWidth:150},children:p?(0,Y.jsx)(g.A,{size:24}):"Fetch Categories"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>R(),children:"Add Category"})]})}),c&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:3},children:c}),v?p?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Y.jsx)(g.A,{})}):(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)(ys.A,{children:[(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"ID"}),(0,Y.jsx)(Is.A,{children:"Name"}),(0,Y.jsx)(Is.A,{children:"Created At"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:0===z?.length?(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:4,align:"center",children:"No categories found"})}):z?.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.id}),(0,Y.jsx)(Is.A,{children:e.name}),(0,Y.jsx)(Is.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{size:"small",onClick:()=>R(e),children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{size:"small",onClick:()=>(e=>{w(e),k(!0)})(e),children:(0,Y.jsx)(Os.A,{})})]})]},e.id)))})]}),(0,Y.jsx)(y.A,{component:"div",count:F?.length||0,page:e,onPageChange:(e,s)=>{t(s)},rowsPerPage:s,onRowsPerPageChange:e=>{n(parseInt(e.target.value,10)),t(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,Y.jsxs)(j.A,{sx:{textAlign:"center",py:4},children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Categories" to load category information'}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,Y.jsxs)(Fe.A,{open:r,onClose:W,children:[(0,Y.jsx)(De.A,{children:a?"Edit Category":"Add New Category"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(A.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:l,onChange:e=>d(e.target.value),error:!!c,helperText:c,onKeyPress:e=>{"Enter"===e.key&&q()}})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:W,children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:q,variant:"contained",disabled:L.isLoading||$.isLoading,children:L.isLoading||$.isLoading?(0,Y.jsx)(g.A,{size:24}):a?"Update":"Create"})]})]}),(0,Y.jsxs)(Fe.A,{open:E,onClose:()=>k(!1),children:[(0,Y.jsx)(De.A,{children:"Delete Category"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{children:"Are you sure you want to delete this category?"})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>k(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:()=>{S&&T.mutate({categoryId:S.id})},variant:"contained",color:"error",children:"Delete"})]})]})]})},un=e=>{let{open:t,onClose:s,selectedFee:n,onUpdate:r,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,l]=(0,x.useState)(a);(0,x.useEffect)((()=>{n?l({feeCurrency:n.feeCurrency||"",feeRate:n.feeRate?.toString()||"",limit:n.limit?.toString()||"",type:n.type?.toUpperCase()||"DELIVERY"}):t&&l(a)}),[n,t]),(0,x.useEffect)((()=>{t||l(a)}),[t]);const d=e=>{const{name:t,value:s}=e.target;l((e=>({...e,[t]:s})))};return(0,Y.jsxs)(Fe.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:n?"Edit Fee":"Add New Fee"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(j.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Y.jsxs)(Ps.A,{fullWidth:!0,children:[(0,Y.jsx)(Es.A,{children:"Fee Type"}),(0,Y.jsxs)(ks.A,{name:"type",value:o.type,onChange:d,label:"Fee Type",children:[(0,Y.jsx)(ue.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,Y.jsx)(ue.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,Y.jsx)(A.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:d,fullWidth:!0,placeholder:"e.g., USD"}),(0,Y.jsx)(A.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,Y.jsx)(A.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:s,children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{r({id:n?.id,...o,feeRate:parseFloat(o.feeRate),limit:parseFloat(o.limit)}),n||l(a)},disabled:i,startIcon:i?(0,Y.jsx)(g.A,{size:20}):null,children:i?"Saving...":"Save"})]})]})},hn=()=>{const[e,t]=(0,x.useState)(""),[s,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,A]=(0,x.useState)(""),{data:p,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>P("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=p?.stores||[],{data:v,isLoading:b,refetch:I}=(0,u.I)({queryKey:["getFeesByStore",e],queryFn:()=>P("\n query GetFeesByStore($storeId: Int!) {\n getFeesByStore(storeId: $storeId) {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n }\n",{storeId:parseInt(e)}),enabled:!!e}),C=v?.getFeesByStore||[],S=(0,Ts.n)({mutationFn:e=>P("\n mutation UpdateFee($input: UpdateFeeInput!) {\n updateFee(input: $input) {\n fee {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:()=>{I(),i(!1),n(null),A("Fee updated successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error updating fee: ${e.message}`)}}),w=(0,Ts.n)({mutationFn:e=>P("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),n(null),A("Fee deleted successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error deleting fee: ${e.message}`)}}),E=(0,Ts.n)({mutationFn:t=>P("\n mutation CreateFee($input: CreateFeeInput!) {\n createFee(input: $input) {\n fee {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n error {\n message\n }\n }\n }\n",{input:{...t,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),n(null),A("Fee added successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error adding fee: ${e.message}`)}});return y?(0,Y.jsx)(m.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Y.jsx)(g.A,{})}):(0,Y.jsxs)(m.A,{children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Fees Management"}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mb:3},children:[(0,Y.jsx)(Es.A,{children:"Select Store"}),(0,Y.jsx)(ks.A,{value:e,onChange:e=>t(e.target.value),label:"Select Store",children:f.map((e=>(0,Y.jsx)(ue.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:l}),e&&(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",children:"Fees"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>{n(null),i(!0)},children:"Add Fee"})]}),b?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",p:3},children:(0,Y.jsx)(g.A,{})}):(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Type"}),(0,Y.jsx)(Is.A,{children:"Currency"}),(0,Y.jsx)(Is.A,{children:"Rate"}),(0,Y.jsx)(Is.A,{children:"Limit"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:0!==C.length||b?C.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.type}),(0,Y.jsx)(Is.A,{children:e.feeCurrency}),(0,Y.jsx)(Is.A,{children:e.feeRate}),(0,Y.jsx)(Is.A,{children:e.limit}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",children:(0,Y.jsx)(Os.A,{})})]})]},e.id))):(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:5,align:"center",children:(0,Y.jsx)(te.A,{severity:"info",sx:{my:2},children:"No fees found for this store."})})})})]})})]}),(0,Y.jsx)(un,{open:r,onClose:()=>{i(!1),n(null),d("")},selectedFee:s,onUpdate:e=>{s?S.mutate(e):E.mutate(e)},isLoading:S.isLoading||E.isLoading}),(0,Y.jsxs)(Fe.A,{open:a,onClose:()=>{o(!1),n(null),d("")},children:[(0,Y.jsx)(De.A,{children:"Delete Fee"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{o(!1),n(null)},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:s.id}),disabled:w.isLoading,children:w.isLoading?(0,Y.jsx)(g.A,{size:24}):"Delete"})]})]})]})},mn=e=>{let{open:t,onClose:s,selectedLocationCode:n,onUpdate:r,isLoading:i,existingCodes:a}=e;const[o,l]=(0,x.useState)({location:"",code:""}),[d,c]=(0,x.useState)("");(0,x.useEffect)((()=>{l(n?{location:n.location||"",code:n.code||""}:{location:"",code:""}),c("")}),[n,t]);const u=()=>{l({location:"",code:""}),c(""),s()},h=e=>{const{name:t,value:s}=e.target;l((e=>({...e,[t]:s}))),c("")};return(0,Y.jsxs)(Fe.A,{open:t,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:n?"Edit Location Code":"Add New Location Code"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(j.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Y.jsx)(A.A,{name:"location",label:"Location",value:o.location,onChange:h,fullWidth:!0,placeholder:"e.g., Main Branch",error:!!d&&d.includes("Location"),helperText:d&&d.includes("Location")?d:""}),(0,Y.jsx)(A.A,{name:"code",label:"Code",value:o.code,onChange:h,fullWidth:!0,placeholder:"e.g., MB001",error:!!d&&(d.includes("Code")||d.includes("already exists")),helperText:d&&(d.includes("Code")||d.includes("already exists"))?d:""})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:u,children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{(o.location.trim()?o.code.trim()?!a.some((e=>e.code.toLowerCase()===o.code.toLowerCase()&&(!n||e.id!==n.id)))||(c("This code already exists for this store"),0):(c("Code is required"),0):(c("Location is required"),0))&&r({id:n?.id,...o})},disabled:i,startIcon:i?(0,Y.jsx)(g.A,{size:20}):null,children:i?"Saving...":"Save"})]})]})},An=()=>{const[e,t]=(0,x.useState)(""),[s,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,A]=(0,x.useState)(""),{data:p,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>P("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=p?.stores||[],{data:v,isLoading:b,refetch:I}=(0,u.I)({queryKey:["getStoreLocationCodesByStore",e],queryFn:()=>P("\n query GetStoreLocationCodesByStore($storeId: Int!) {\n getStoreLocationCodesByStore(storeId: $storeId) {\n id\n storeId\n location\n code\n }\n }\n",{storeId:parseInt(e)}),enabled:!!e}),C=v?.getStoreLocationCodesByStore||[],S=(0,Ts.n)({mutationFn:e=>P("\n mutation UpdateStoreLocationCode($input: UpdateStoreLocationCodeInput!) {\n updateStoreLocationCode(input: $input) {\n locationCode {\n id\n storeId\n location\n code\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:()=>{I(),i(!1),n(null),A("Location code updated successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error updating location code: ${e.message}`)}}),w=(0,Ts.n)({mutationFn:e=>P("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),n(null),A("Location code deleted successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error deleting location code: ${e.message}`)}}),E=(0,Ts.n)({mutationFn:t=>P("\n mutation CreateStoreLocationCode($input: CreateStoreLocationCodeInput!) {\n createStoreLocationCode(input: $input) {\n locationCode {\n id\n storeId\n location\n code\n }\n error {\n message\n }\n }\n }\n",{input:{...t,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),n(null),A("Location code added successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error adding location code: ${e.message}`)}});return y?(0,Y.jsx)(m.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Y.jsx)(g.A,{})}):(0,Y.jsxs)(m.A,{children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mb:3},children:[(0,Y.jsx)(Es.A,{children:"Select Store"}),(0,Y.jsx)(ks.A,{value:e,onChange:e=>t(e.target.value),label:"Select Store",children:f.map((e=>(0,Y.jsx)(ue.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:l}),e&&(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",children:"Location Codes"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>{n(null),i(!0)},children:"Add Location Code"})]}),b?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",p:3},children:(0,Y.jsx)(g.A,{})}):(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Location"}),(0,Y.jsx)(Is.A,{children:"Code"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:0!==C.length||b?C.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.location}),(0,Y.jsx)(Is.A,{children:e.code}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",children:(0,Y.jsx)(Os.A,{})})]})]},e.id))):(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:3,align:"center",children:(0,Y.jsx)(te.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})})]}),(0,Y.jsx)(mn,{open:r,onClose:()=>{i(!1),n(null),d("")},selectedLocationCode:s,onUpdate:e=>{s?S.mutate(e):E.mutate(e)},isLoading:S.isLoading||E.isLoading,existingCodes:C}),(0,Y.jsxs)(Fe.A,{open:a,onClose:()=>{o(!1),n(null),d("")},children:[(0,Y.jsx)(De.A,{children:"Delete Location Code"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{o(!1),n(null)},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:s.id}),disabled:w.isLoading,children:w.isLoading?(0,Y.jsx)(g.A,{size:24}):"Delete"})]})]})]})},pn=e=>{let{open:t,onClose:s,selectedPickupAddress:n,onUpdate:r,isLoading:i,existingAddresses:a}=e;const[o,l]=(0,x.useState)({address:""}),[d,c]=(0,x.useState)(""),[u,m]=(0,x.useState)(!1);x.useEffect((()=>{n?(l({address:n.address||""}),m(!0)):(l({address:""}),m(!1)),c("")}),[n]);return(0,Y.jsxs)(Fe.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:n?"Edit Pickup Address":"Add New Pickup Address"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(j.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Y.jsx)(Ht,{value:o.address,onChange:e=>{l((t=>({...t,address:e}))),c("")},onValidAddress:m}),d&&(0,Y.jsx)(h.A,{color:"error",variant:"caption",children:d})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:s,children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{(o.address.trim()?u?!a.some((e=>e.address.toLowerCase()===o.address.toLowerCase()&&(!n||e.id!==n.id)))||(c("This address already exists for this store"),0):(c("Please select a valid address from the suggestions"),0):(c("Address is required"),0))&&r({id:n?.id,...o})},disabled:i||!u,startIcon:i?(0,Y.jsx)(g.A,{size:20}):null,children:i?"Saving...":"Save"})]})]})},jn=()=>{const[e,t]=(0,x.useState)(""),[s,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,A]=(0,x.useState)(""),{data:p,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>P("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=p?.stores||[],{data:v,isLoading:b,refetch:I}=(0,u.I)({queryKey:["getPickupAddressesByStore",e],queryFn:()=>P("\n query GetPickupAddressesByStore($storeId: Int!) {\n getPickupAddressesByStore(storeId: $storeId) {\n id\n storeId\n address\n }\n }\n",{storeId:parseInt(e)}),enabled:!!e}),C=v?.getPickupAddressesByStore||[],S=(0,Ts.n)({mutationFn:e=>P("\n mutation UpdatePickupAddress($input: UpdatePickupAddressInput!) {\n updatePickupAddress(input: $input) {\n pickupAddress {\n id\n storeId\n address\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:()=>{I(),i(!1),n(null),A("Pickup address updated successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error updating pickup address: ${e.message}`)}}),w=(0,Ts.n)({mutationFn:e=>P("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),n(null),A("Pickup address deleted successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error deleting pickup address: ${e.message}`)}}),E=(0,Ts.n)({mutationFn:t=>P("\n mutation CreatePickupAddress($input: PickupAddressInput!) {\n createPickupAddress(input: $input) {\n pickupAddress {\n id\n storeId\n address\n }\n error {\n message\n }\n }\n }\n",{input:{...t,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),n(null),A("Pickup address added successfully"),setTimeout((()=>A("")),3e3)},onError:e=>{d(`Error adding pickup address: ${e.message}`)}});return y?(0,Y.jsx)(m.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Y.jsx)(g.A,{})}):(0,Y.jsxs)(m.A,{children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mb:3},children:[(0,Y.jsx)(Es.A,{children:"Select Store"}),(0,Y.jsx)(ks.A,{value:e,onChange:e=>t(e.target.value),label:"Select Store",children:f.map((e=>(0,Y.jsx)(ue.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:l}),e&&(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",children:"Pickup Addresses"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>{n(null),i(!0)},children:"Add Pickup Address"})]}),0===C.length?(0,Y.jsx)(te.A,{severity:"info",sx:{my:2},children:"No pickup addresses found. Add your first pickup address to get started."}):(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Address"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:C.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.address}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",children:(0,Y.jsx)(Os.A,{})})]})]},e.id)))})]})})]}),(0,Y.jsx)(pn,{open:r,onClose:()=>{i(!1),n(null),d("")},selectedPickupAddress:s,onUpdate:e=>{s?S.mutate(e):E.mutate(e)},isLoading:S.isLoading||E.isLoading,existingAddresses:C}),(0,Y.jsxs)(Fe.A,{open:a,onClose:()=>{o(!1),n(null),d("")},children:[(0,Y.jsx)(De.A,{children:"Delete Pickup Address"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{o(!1),n(null)},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:s.id}),disabled:w.isLoading,children:w.isLoading?(0,Y.jsx)(g.A,{size:24}):"Delete"})]})]})]})},gn=240,yn=[{text:"Dashboard",icon:(0,Y.jsx)(as.A,{}),path:"/admin/dashboard"},{text:"Stores",icon:(0,Y.jsx)(_t.A,{}),path:"/admin/stores"},{text:"Product Management",icon:(0,Y.jsx)(os.A,{}),path:"/admin/products"},{text:"Inventory Management",icon:(0,Y.jsx)(ls.A,{}),path:"/admin/inventory"},{text:"Orders",icon:(0,Y.jsx)(be.A,{}),path:"/admin/orders"},{text:"Users",icon:(0,Y.jsx)(ds.A,{}),path:"/admin/users"},{text:"Payment Onboarding",icon:(0,Y.jsx)(cs.A,{}),path:"/admin/payment-onboarding"},{text:"Settings",icon:(0,Y.jsx)(xs.A,{}),path:"/admin/settings"},{text:"Categories",icon:(0,Y.jsx)(ls.A,{}),path:"/admin/categories"},{text:"Fees Management",icon:(0,Y.jsx)(cs.A,{}),path:"/admin/fees"},{text:"Location Codes",icon:(0,Y.jsx)(us.A,{}),path:"/admin/location-codes"},{text:"Pickup Addresses",icon:(0,Y.jsx)(hs.A,{}),path:"/admin/pickup-addresses"}],fn=()=>{const[e,t]=(0,x.useState)(!1),[s,n]=(0,x.useState)(!0),{user:r,ability:i,logout:a}=G(),o=(0,Ce.A)(),l=(0,Qe.A)(o.breakpoints.down("sm")),c=(0,d.Zp)(),u=(0,d.zy)(),m=(0,Y.jsxs)(j.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:2,minHeight:64},children:[s&&(0,Y.jsx)(j.A,{sx:{display:"flex",alignItems:"center",gap:2},children:(0,Y.jsx)(h.A,{variant:"h6",noWrap:!0,component:"div",children:"Admin Panel"})}),(0,Y.jsx)(ce.A,{onClick:()=>{n(!s)},children:s?(0,Y.jsx)(ms.A,{}):(0,Y.jsx)(As.A,{})})]}),(0,Y.jsx)(kt.A,{}),(0,Y.jsxs)(Tt.A,{children:[yn.map((e=>(0,Y.jsxs)(Rt.Ay,{button:!0,onClick:()=>{return s=e.path,c(s),void(l&&t(!1));var s},selected:u.pathname===e.path,sx:{minHeight:48,justifyContent:s?"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,Y.jsx)(ns.A,{sx:{minWidth:0,mr:s?3:"auto",justifyContent:"center",color:u.pathname===e.path?"white":"inherit"},children:e.icon}),(0,Y.jsx)(rs.A,{primary:e.text,sx:{opacity:s?1:0}})]},e.text))),(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsxs)(Rt.Ay,{button:!0,onClick:()=>{(async()=>{try{await(0,Ye.C)(),a(),c("/")}catch(e){}})()},sx:{minHeight:48,justifyContent:s?"initial":"center",px:2.5},children:[(0,Y.jsx)(ns.A,{sx:{minWidth:0,mr:s?3:"auto",justifyContent:"center"},children:(0,Y.jsx)(ps.A,{})}),(0,Y.jsx)(rs.A,{primary:"Logout",sx:{opacity:s?1:0}})]})]})]});return(0,Y.jsxs)(j.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,Y.jsx)(Qt,{}),(0,Y.jsx)(j.A,{component:"nav",sx:{width:{sm:s?gn:65},flexShrink:{sm:0},position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,Y.jsx)(is.Ay,{variant:l?"temporary":"persistent",open:!0,onClose:()=>{t(!e)},ModalProps:{keepMounted:!0},sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:s?gn:65,top:{xs:"64px",sm:"70px"},transition:o.transitions.create("width",{easing:o.transitions.easing.sharp,duration:o.transitions.duration.enteringScreen}),overflowX:"hidden"}},children:m})}),(0,Y.jsx)(j.A,{component:"main",sx:{flexGrow:1,p:3,width:{sm:`calc(100% - ${s?gn:65}px)`},ml:{sm:`${s?gn:65}px`},mt:{xs:"64px",sm:"70px"},transition:o.transitions.create(["width","margin"],{easing:o.transitions.easing.sharp,duration:o.transitions.duration.leavingScreen})},children:(0,Y.jsxs)(d.BV,{children:[(0,Y.jsx)(d.qh,{path:"/",element:(0,Y.jsx)(d.C5,{to:"dashboard",replace:!0})}),(0,Y.jsx)(d.qh,{path:"dashboard",element:(0,Y.jsx)(gs,{})}),(0,Y.jsx)(d.qh,{path:"users/*",element:(0,Y.jsx)(Rs,{})}),(0,Y.jsx)(d.qh,{path:"stores/*",element:(0,Y.jsx)(Gs,{})}),(0,Y.jsx)(d.qh,{path:"products",element:(0,Y.jsx)(Ks,{})}),(0,Y.jsx)(d.qh,{path:"inventory",element:(0,Y.jsx)(cn,{})}),(0,Y.jsx)(d.qh,{path:"orders",element:(0,Y.jsx)(tn,{})}),(0,Y.jsx)(d.qh,{path:"payment-onboarding",element:(0,Y.jsx)(nn,{})}),(0,Y.jsx)(d.qh,{path:"categories",element:(0,Y.jsx)(xn,{})}),(0,Y.jsx)(d.qh,{path:"fees",element:(0,Y.jsx)(hn,{})}),(0,Y.jsx)(d.qh,{path:"location-codes",element:(0,Y.jsx)(An,{})}),(0,Y.jsx)(d.qh,{path:"pickup-addresses",element:(0,Y.jsx)(jn,{})})]})})]})};var vn=s(27558),bn=s(76030),In=s(17809);const Cn=()=>{const[,e]=(0,x.useReducer)((e=>e+1),0),[t,s]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[o,l]=(0,x.useState)(""),[d,c]=(0,x.useState)(""),[y,f]=(0,x.useState)("ALL"),[v,b]=(0,x.useState)(""),[I,C]=(0,x.useState)(!1),[S,w]=(0,x.useState)(0),[F,D]=(0,x.useState)({}),[$,T]=(0,x.useState)(!1),{userProfile:R,setUserProfile:W}=G();(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ge.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;a(t)}}catch(e){}})()}),[]);const{data:q,isLoading:z,error:O}=(0,u.I)({queryKey:["getUserProfile",i],queryFn:async()=>{const t=await P(k,{userId:i});return t?.getUserProfile&&(W(t.getUserProfile),setTimeout((()=>{e()}),200)),t},enabled:!!i,onError:e=>{}}),N=G.getState().userProfile||R||q?.getUserProfile,{data:U,isLoading:B,error:M,refetch:_}=(0,u.I)({queryKey:["driverDeliveries",N?.id],queryFn:()=>N?.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:N.id}):null,enabled:!!N?.id}),V=(0,Ts.n)({mutationFn:e=>P(E,{input:{orderId:e.orderId,status:e.status}}),onSuccess:()=>{_(),r(!1),b(""),C(!1)},onError:e=>{}}),H=(0,Ts.n)({mutationFn:e=>P(L,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:N?.id}),onSuccess:()=>{_(),r(!1),b(""),C(!1)},onError:e=>{}}),K=e=>!!e?.edges?.length&&e.edges.every((e=>F[e.node.id])),Q=x.useMemo((()=>U?.getDeliveriesByDriver?U.getDeliveriesByDriver.filter((e=>{if("ALL"!==y&&e.status!==y)return!1;if(d){const t=d.toLowerCase(),s=e.orderId.toString().includes(t),n=e.address?.toLowerCase().includes(t);return s||n}return!0})):[]),[U?.getDeliveriesByDriver,y,d]);if(z||B&&N?.id)return(0,Y.jsx)(g.A,{sx:{display:"block",mx:"auto",mt:4}});if(O)return(0,Y.jsx)(h.A,{color:"error",children:"Error fetching user profile!"});if(M&&N?.id)return(0,Y.jsx)(h.A,{color:"error",children:"Error fetching deliveries!"});const Z=U?.getDeliveriesByDriver||[],X=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"}},ee=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,Y.jsx)(Js.A,{});case"PICKED_UP":return(0,Y.jsx)(hs.A,{});case"DELIVERED":return(0,Y.jsx)(Ys.A,{});case"CANCELLED":return(0,Y.jsx)(Qs.A,{});default:return null}},se=e=>U?.getDeliveriesByDriver?U.getDeliveriesByDriver.filter((t=>t.status===e)).length:0;return(0,Y.jsxs)(m.A,{maxWidth:"lg",sx:{mt:4,mb:6},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:4,flexDirection:{xs:"column",sm:"row"},gap:{xs:2,sm:0}},children:[(0,Y.jsx)(h.A,{variant:"h4",fontWeight:"500",sx:{fontSize:{xs:"1.5rem",sm:"2rem"}},children:"Delivery Partner Dashboard"}),(0,Y.jsx)(A.A,{size:"small",placeholder:"Search orders...",value:d,onChange:e=>c(e.target.value),InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)($s.A,{fontSize:"small"})})},sx:{width:{xs:"100%",sm:250},"& .MuiOutlinedInput-root":{borderRadius:2}}})]}),(0,Y.jsx)(j.A,{sx:{mb:4},children:(0,Y.jsxs)(Ss.A,{value:S,onChange:(e,t)=>{w(t),0===t?f("ALL"):1===t?f("READY_FOR_DELIVERY"):2===t?f("PICKED_UP"):3===t&&f("DELIVERED")},variant:"scrollable",scrollButtons:"auto",sx:{borderBottom:1,borderColor:"divider","& .MuiTab-root":{minWidth:120,textTransform:"none",fontSize:"0.875rem"}},children:[(0,Y.jsx)(ws.A,{label:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:["All Orders",(0,Y.jsx)(ze.A,{badgeContent:Z.length,color:"primary",sx:{ml:2}})]})}),(0,Y.jsx)(ws.A,{label:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:["Ready",(0,Y.jsx)(ze.A,{badgeContent:se("READY_FOR_DELIVERY"),color:"primary",sx:{ml:2}})]})}),(0,Y.jsx)(ws.A,{label:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:["In Transit",(0,Y.jsx)(ze.A,{badgeContent:se("PICKED_UP"),color:"info",sx:{ml:2}})]})}),(0,Y.jsx)(ws.A,{label:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:["Delivered",(0,Y.jsx)(ze.A,{badgeContent:se("DELIVERED"),color:"success",sx:{ml:2}})]})})]})}),(0,Y.jsx)(me.Ay,{container:!0,spacing:{xs:2,sm:3},children:Q.length>0?Q.map((e=>(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Y.jsx)(Ae.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=>{s(e),l(e.orderStatus||e.status),r(!0),C(!1),b("")})(e),children:(0,Y.jsxs)(je.A,{sx:{flexGrow:1,p:{xs:2,sm:2.5}},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,Y.jsxs)(h.A,{variant:"h6",sx:{fontSize:{xs:"1rem",sm:"1.25rem"},fontWeight:500},children:["Order #",e.orderId]}),(0,Y.jsx)(Se.A,{icon:ee(e.status),label:e.status.replace(/_/g," "),color:X(e.status),size:"small",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},height:{xs:24,sm:28},borderRadius:1.5}})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Y.jsx)(bn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,Y.jsx)(h.A,{variant:"body2",sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:new Date(e.schedule).toLocaleString()})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,Y.jsx)(us.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,Y.jsx)(h.A,{variant:"body2",sx:{flexGrow:1,fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:e?.order?.address?.address||"No address provided"})]}),e.pickedUpTime&&(0,Y.jsxs)(h.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,Y.jsxs)(h.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,Y.jsx)(j.A,{sx:{mt:1},children:(0,Y.jsxs)(h.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,Y.jsx)(Qs.A,{fontSize:"small",sx:{mr:.5,flexShrink:0}}),(0,Y.jsxs)("span",{style:{lineHeight:1},children:['Cancellation Reason: "',e.order.cancelMessage,'"']})]})}),e.comments&&"CANCELLED"!==e.status&&(0,Y.jsx)(j.A,{sx:{mt:1},children:(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},fontStyle:"italic",display:"flex",alignItems:"flex-start"},children:(0,Y.jsxs)("span",{children:['"',e.comments,'"']})})})]})})},e.id))):(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(ne.A,{sx:{p:{xs:3,sm:4},borderRadius:2,textAlign:"center"},children:[(0,Y.jsx)(h.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"No Deliveries Found"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:d||"ALL"!==y?"No deliveries match your search criteria.":"You have no deliveries assigned at this time."})]})})}),(0,Y.jsx)(lt.A,{open:n,onClose:()=>r(!1),"aria-labelledby":"delivery-details-modal",children:(0,Y.jsx)(j.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,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,Y.jsxs)(h.A,{variant:"h5",fontWeight:"500",sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"}},children:["Order #",t.orderId]}),(0,Y.jsx)(ce.A,{edge:"end","aria-label":"close",onClick:()=>r(!1),size:"small",children:(0,Y.jsx)(In.A,{})})]}),(0,Y.jsx)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:(0,Y.jsx)(Se.A,{icon:ee(t.status),label:t.status.replace(/_/g," "),color:X(t.status),sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}}})}),(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY ADDRESS"}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"flex-start"},children:[(0,Y.jsx)(us.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,Y.jsx)(h.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.order?.address?.address||t.address||"No address provided"})]})]}),(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"SCHEDULED DELIVERY"}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Y.jsx)(bn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,Y.jsx)(h.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.schedule).toLocaleString()})]})]}),t.pickedUpTime&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"PICKED UP"}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Y.jsx)(hs.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,Y.jsx)(h.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.pickedUpTime).toLocaleString()})]})]}),t.deliveredTime&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERED"}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Y.jsx)(Ys.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,Y.jsx)(h.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.deliveredTime).toLocaleString()})]})]}),"CANCELLED"===t.status&&t.order?.cancelMessage&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"error",gutterBottom:!0,children:"CANCELLATION REASON"}),(0,Y.jsxs)(j.A,{sx:{p:2,bgcolor:"error.lightest",borderRadius:1,borderLeft:"3px solid",borderColor:"error.main",display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Qs.A,{color:"error",sx:{flexShrink:0}}),(0,Y.jsx)(h.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,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"COMMENTS"}),(0,Y.jsx)(j.A,{sx:{p:2,bgcolor:"rgba(0, 0, 0, 0.03)",borderRadius:1,borderLeft:"3px solid",borderColor:"primary.main"},children:(0,Y.jsx)(h.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.comments})})]}),t.photo&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY PROOF"}),(0,Y.jsx)("img",{src:t.photo,alt:"Delivery Proof",style:{width:"100%",borderRadius:4}})]}),$&&t?.order?.orderItems&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"VERIFY ITEMS TO BE PICKED UP"}),(0,Y.jsx)(ne.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,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:1,p:1,borderRadius:1,bgcolor:"background.default"},children:[(0,Y.jsx)(vn.A,{checked:!!F[t.id],onChange:()=>{return e=t.id,void D((t=>({...t,[e]:!t[e]})));var e},color:"primary"}),(0,Y.jsxs)(j.A,{sx:{ml:2,flex:1},children:[(0,Y.jsx)(h.A,{variant:"body2",fontWeight:"500",children:t.product.name}),(0,Y.jsxs)(h.A,{variant:"caption",color:"text.secondary",children:["Quantity: ",t.quantity," × $",t.orderAmount.toFixed(2)]})]})]},t.id)}))}),!K(t.order.orderItems)&&(0,Y.jsx)(te.A,{severity:"warning",sx:{mt:1},children:"Please verify all items before updating status"})]}),(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"UPDATE STATUS"}),(0,Y.jsx)(Ps.A,{fullWidth:!0,sx:{mb:2},children:(0,Y.jsxs)(ks.A,{value:o,onChange:e=>{const s=e.target.value;l(s),"READY_FOR_DELIVERY"===t?.status&&"READY_FOR_DELIVERY"!==s?(T(!0),D({})):T(!1),C("CANCELLED"===s)},size:"small",children:[(0,Y.jsx)(ue.A,{value:"PICKED_UP",children:"Picked Up"}),(0,Y.jsx)(ue.A,{value:"DELIVERED",children:"Delivered"}),(0,Y.jsx)(ue.A,{value:"CANCELLED",children:"Cancelled"})]})}),I&&(0,Y.jsx)(A.A,{fullWidth:!0,label:"Cancellation Reason",multiline:!0,rows:3,value:v,onChange:e=>b(e.target.value),sx:{mb:2},required:!0,size:"small"}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"flex-end",mt:3},children:(0,Y.jsx)(J.A,{onClick:()=>{t&&o&&("READY_FOR_DELIVERY"!==t.status||"READY_FOR_DELIVERY"===o||K(t.order.orderItems))&&("CANCELLED"===o?H.mutate({orderId:t.orderId,cancelMessage:v}):V.mutate({orderId:t.orderId,status:o}))},variant:"contained",color:"primary",disabled:("CANCELLED"===o?H.isLoading:V.isLoading)||o===t.orderStatus||"CANCELLED"===o&&!v||$&&!K(t.order.orderItems),sx:{minWidth:120},children:("CANCELLED"===o?H.isLoading:V.isLoading)?"Updating...":"Update"})})]})})})]})};var Sn=s(47922);const wn=[{text:"Dashboard",icon:(0,Y.jsx)(as.A,{}),path:st},{text:"Orders",icon:(0,Y.jsx)(be.A,{}),path:nt},{text:"Delivery Partners",icon:(0,Y.jsx)(hs.A,{}),path:"/store_manager/delivery-partners"},{text:"Inventory",icon:(0,Y.jsx)(os.A,{}),path:"/store_manager/inventory"},{text:"Delivery Fees",icon:(0,Y.jsx)(Sn.A,{}),path:"/store_manager/delivery-fees"},{text:"Location Codes",icon:(0,Y.jsx)(us.A,{}),path:"/store_manager/location-codes"},{text:"Pickup Addresses",icon:(0,Y.jsx)(hs.A,{}),path:"/store_manager/pickup-addresses"},{text:"Settings",icon:(0,Y.jsx)(xs.A,{}),path:"/store_manager/settings"}],Pn=()=>{const e=(0,Ce.A)(),t=(0,Qe.A)(e.breakpoints.down("sm")),s=(0,d.Zp)(),n=(0,d.zy)(),{open:r,setOpen:i}=x.useContext(En),a=()=>{i(!r)},o=(0,Y.jsxs)(j.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:2,minHeight:64},children:[r&&(0,Y.jsx)(h.A,{variant:"h6",noWrap:!0,component:"div",children:"Store Manager"}),(0,Y.jsx)(ce.A,{onClick:a,children:r?(0,Y.jsx)(ms.A,{}):(0,Y.jsx)(As.A,{})})]}),(0,Y.jsx)(kt.A,{}),(0,Y.jsx)(Tt.A,{children:wn.map((e=>(0,Y.jsxs)(Rt.Ay,{button:!0,onClick:()=>{return n=e.path,s(n),void(t&&i(!1));var n},selected:n.pathname===e.path,sx:{minHeight:48,justifyContent:r?"initial":"center",px:2.5,"&.Mui-selected":{backgroundColor:"primary.light","&:hover":{backgroundColor:"primary.light"}}},children:[(0,Y.jsx)(ns.A,{sx:{minWidth:0,mr:r?3:"auto",justifyContent:"center",color:n.pathname===e.path?"primary.main":"inherit"},children:e.icon}),(0,Y.jsx)(rs.A,{primary:e.text,sx:{opacity:r?1:0}})]},e.text)))})]});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ce.A,{color:"inherit","aria-label":"open drawer",edge:"start",onClick:a,sx:{mr:2,display:{sm:"none"}},children:(0,Y.jsx)(As.A,{})}),(0,Y.jsx)(j.A,{component:"nav",sx:{width:{sm:r?240:65},flexShrink:{sm:0},position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,Y.jsx)(is.Ay,{variant:t?"temporary":"persistent",open:!0,onClose:a,ModalProps:{keepMounted:!0},sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:r?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:o})})]})},En=(0,x.createContext)({open:!0,setOpen:()=>{}}),kn=e=>{let{children:t}=e;const s=(0,Ce.A)(),[n,r]=(0,x.useState)(!0);return(0,Y.jsx)(En.Provider,{value:{open:n,setOpen:r},children:(0,Y.jsxs)(j.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,Y.jsx)(l.Ay,{}),(0,Y.jsx)(Qt,{}),(0,Y.jsx)(Pn,{}),(0,Y.jsx)(j.A,{component:"main",sx:{flexGrow:1,p:3,width:{sm:`calc(100% - ${n?240:65}px)`},ml:{sm:(n?240:65)+"px"},transition:s.transitions.create(["width","margin"],{easing:s.transitions.easing.sharp,duration:s.transitions.duration.leavingScreen}),display:"flex",flexDirection:"column",alignItems:"center",maxWidth:"100%",overflow:"hidden"},children:(0,Y.jsx)(j.A,{sx:{width:"100%"},children:t})})]})})},Fn=()=>{const[e,t]=(0,x.useState)(""),{userProfile:s,setUserProfile:n}=G(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,y]=(0,x.useState)(null),[f,v]=(0,x.useState)(""),[b,I]=(0,x.useState)(""),[C,S]=(0,x.useState)(""),[w,E]=(0,x.useState)(""),[F,D]=(0,x.useState)(""),[L,$]=(0,x.useState)(""),[T,R]=(0,x.useState)(""),[W,q]=(0,x.useState)(""),[z,O]=(0,x.useState)(""),[N,U]=(0,x.useState)(!1),[B,M]=(0,x.useState)(10),[_,V]=(0,x.useState)(""),[H,K]=(0,x.useState)([]),[Q,Z]=(0,x.useState)(!1),[X,ee]=((0,x.useRef)(null),(0,x.useState)(0)),[se,re]=(0,x.useState)(10),[ie,ae]=(0,x.useState)(!0),[oe,le]=(0,x.useState)(null),[de,xe]=(0,x.useState)({open:!1,message:"",severity:"success"}),[he,Ae]=(0,x.useState)([]),[pe,je]=(0,x.useState)(!0);(0,x.useEffect)((()=>{let e=!0;return(async()=>{try{const s=await(0,xt.T)();e&&t(s.sub)}catch(e){}})(),()=>{e=!1}}),[]),(0,x.useEffect)((()=>{const e=setTimeout((()=>{ae(!1)}),1e3);return()=>clearTimeout(e)}),[]);const{data:ge,isLoading:ye}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{if(!e)return null;return await P(k,{userId:e})},enabled:!!e});(0,x.useEffect)((()=>{ge?.getUserProfile&&!s&&n(ge.getUserProfile)}),[ge,s,n]);const{data:fe,isLoading:be,error:Ie,refetch:Ce}=(0,u.I)({queryKey:["storeWithInventory",s?.id],queryFn:async()=>s?.id?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 displayField\n sectionHeaders\n }\n }\n",{managerId:s.id}):null,enabled:!!s?.id}),Se=fe?.storesByManager?.[0]||null,we=Se?.inventory?.edges?.map((e=>e.node))||[],Pe=fe?.products||[];(0,x.useEffect)((()=>{if(Pe.length)if(""===_.trim())K(Pe);else{const e=Pe.filter((e=>e.name.toLowerCase().includes(_.toLowerCase())));K(e)}}),[_,Pe]);const Ee=(0,Ts.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 $displayField: String\n $sectionHeaders: [String!]\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 displayField: $displayField\n sectionHeaders: $sectionHeaders\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 displayField\n sectionHeaders\n }\n }\n",e),onSuccess:()=>{xe({open:!0,message:"Store updated successfully",severity:"success"}),le(null),Ce()},onError:e=>{xe({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),ke=()=>{le(null),Ae([]),je(!0)};return ye||be||ie||!Se?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Y.jsx)(g.A,{})})}):Ie?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4},children:(0,Y.jsxs)(te.A,{severity:"error",children:["Error loading store data: ",Ie.message]})})}):Se||ie?(0,Y.jsx)(kn,{children:(0,Y.jsxs)(m.A,{sx:{mb:4},children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Store Manager Dashboard"}),(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,Y.jsx)(h.A,{variant:"h5",children:"Store Information"}),(0,Y.jsx)(J.A,{variant:"outlined",startIcon:(0,Y.jsx)(Ls.A,{}),onClick:()=>{Se&&(le(Se),Ae(Se.sectionHeaders||[]),je(Se.isActive))},sx:{textTransform:"none"},children:"Edit Store"})]}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Name:"})," ",Se.name]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Address:"})," ",Se.address]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Delivery Radius:"})," ",Se.radius||"Not set"," ",Se.radius?"mi":""]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Delivery Fee:"})," $",Se.storeDeliveryFee?.toFixed(2)||"0.00"]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Tax Rate:"})," ",Se.taxPercentage?.toFixed(1)||"0.0","%"]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Total Products:"})," ",we.length]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Display Field:"})," ",Se.displayField]})}),Se.description&&(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Description:"})," ",Se.description]})}),Se.pincodes&&Se.pincodes.length>0&&(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:[(0,Y.jsx)("strong",{children:"Delivery Pincodes:"})," ",Se.pincodes.join(", ")]})}),Se.sectionHeaders&&Se.sectionHeaders.length>0&&(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:(0,Y.jsx)("strong",{children:"Section Headers:"})}),(0,Y.jsx)(j.A,{sx:{pl:2},children:Se.sectionHeaders.map(((e,t)=>(0,Y.jsxs)(h.A,{variant:"body2",sx:{mb:1},children:["• ",e]},t)))})]})]})]}),(0,Y.jsxs)(Fe.A,{open:!!oe,onClose:ke,maxWidth:"md",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(_t.A,{}),(0,Y.jsx)(h.A,{variant:"h6",children:"Edit Store"})]})}),(0,Y.jsxs)("form",{onSubmit:e=>{if(e.preventDefault(),!oe)return;const t=new FormData(e.target),s=t.get("pincodes"),n=s?s.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],r={storeId:oe.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,displayField:t.get("displayField"),sectionHeaders:he.filter((e=>e.trim().length>0))};Ee.mutate(r)},children:[(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"name",label:"Store Name",defaultValue:oe?.name,required:!0,fullWidth:!0})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"email",label:"Email",type:"email",defaultValue:oe?.email,required:!0,fullWidth:!0})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"mobile",label:"Mobile Number",defaultValue:oe?.mobile,fullWidth:!0})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"address",label:"Address",defaultValue:oe?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:oe?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:oe?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:"$"})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:oe?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,Y.jsx)(p.A,{position:"end",children:"%"})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:oe?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"description",label:"Description",defaultValue:oe?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"tnc",label:"Terms & Conditions",defaultValue:oe?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{name:"displayField",label:"Display Field",defaultValue:oe?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,Y.jsxs)(j.A,{sx:{mb:2},children:[he.map(((e,t)=>(0,Y.jsxs)(j.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,Y.jsx)(A.A,{fullWidth:!0,label:`Question ${t+1}`,value:e,onChange:e=>((e,t)=>{Ae((s=>{const n=[...s];return n[e]=t,n}))})(t,e.target.value),placeholder:"Enter question text",inputProps:{"aria-label":`Question ${t+1}`}}),(0,Y.jsx)(ce.A,{color:"error",onClick:()=>(e=>{Ae((t=>t.filter(((t,s)=>s!==e))))})(t),sx:{alignSelf:"center"},"aria-label":"Remove question",children:(0,Y.jsx)(Os.A,{})})]},t))),(0,Y.jsx)(J.A,{startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>{Ae((e=>[...e,""]))},variant:"outlined",sx:{mt:1},"aria-label":"Add question",children:"Add Question"})]})]}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(h.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,children:[(0,Y.jsx)(Es.A,{children:"Store Status"}),(0,Y.jsxs)(ks.A,{name:"isActive",label:"Store Status",value:pe,onChange:e=>{je(e.target.value)},children:[(0,Y.jsx)(ue.A,{value:!0,children:"Active"}),(0,Y.jsx)(ue.A,{value:!1,children:"Inactive"})]})]})})]})}),(0,Y.jsxs)(Fs.A,{sx:{p:3,pt:0},children:[(0,Y.jsx)(J.A,{onClick:ke,children:"Cancel"}),(0,Y.jsx)(J.A,{type:"submit",variant:"contained",disabled:Ee.isPending,startIcon:Ee.isPending?(0,Y.jsx)(g.A,{size:20}):null,children:Ee.isPending?"Updating...":"Update Store"})]})]})]}),(0,Y.jsx)(Ds.A,{open:de.open,autoHideDuration:6e3,onClose:()=>xe({...de,open:!1}),children:(0,Y.jsx)(te.A,{onClose:()=>xe({...de,open:!1}),severity:de.severity,sx:{width:"100%"},children:de.message})})]})}):(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4},children:(0,Y.jsx)(te.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})};var Dn=s(52848),Ln=s(77867),$n=s(79381),Tn=s(29682),Rn=s(92183),Wn=s(69149),qn=s(51365);const zn=()=>{const[,e]=(0,x.useReducer)((e=>e+1),0),[t,s]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[o,l]=(0,x.useState)(null),[d,c]=(0,x.useState)(""),[p,y]=(0,x.useState)(!1),[f,v]=(0,x.useState)(null),[b,I]=(0,x.useState)(null),[C,S]=(0,x.useState)({open:!1,title:"",message:"",onConfirm:null}),w=(0,Ce.A)(),E=(0,Qe.A)(w.breakpoints.down("sm")),{userProfile:F,setUserProfile:D}=G();(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ge.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;s(t)}}catch(e){}})()}),[]);const{data:$,isLoading:T,error:R}=(0,u.I)({queryKey:["getUserProfile",t],queryFn:async()=>{const s=await P(k,{userId:t});return s?.getUserProfile&&(D(s.getUserProfile),setTimeout((()=>{e()}),200)),s},enabled:!!t,onError:e=>{}}),W=G.getState().userProfile||F||$?.getUserProfile,{data:q,isLoading:z,error:O,refetch:N}=(0,u.I)({queryKey:["userOrders",W?.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 customOrder\n orderTotalAmount\n paymentId\n status\n storeId\n taxAmount\n tipAmount\n totalAmount\n type\n pickupId\n pickupAddress {\n id\n address\n storeId\n }\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:W.id}),enabled:!!W?.id}),U=(0,Ts.n)({mutationFn:e=>P(L,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:W.id}),onSuccess:()=>{N(),M(),c("")}}),B=(0,Ts.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:()=>{N()}}),M=()=>{r(!1),a(null)},_=e=>{l(o===e?null:e)},V=(e,t,s)=>{if(!t||!t.id)return;const n=s-t.quantity,r=(t.product.inventoryItems?.edges[0]?.node?.price||0)*n,i=e.totalAmount+r,a=0===i?0:.1*i,o=0===i?0:i+a+(e.deliveryFee||0)+(e.tipAmount||0),l={orderId:parseInt(e.id,10),orderItemUpdates:[{orderItemId:parseInt(t.id,10),quantityChange:n}],totalAmount:i,orderTotalAmount:o,taxAmount:a};B.mutate(l)},H=e=>{if(!e?.edges?.length)return null;const t=new Map;e.edges.forEach((e=>{let{node:s}=e;t.set(s.id,s)}));return e.edges.map((e=>{let{node:t}=e;return t})).filter((e=>null===e.updatedOrderitemsId))},K=()=>{v(null),I(null)},Q=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e);if(T||z&&W?.id)return(0,Y.jsx)(g.A,{sx:{display:"block",mx:"auto",mt:4}});if(R)return(0,Y.jsx)(h.A,{color:"error",children:"Error fetching user profile!"});if(O&&W?.id)return(0,Y.jsx)(h.A,{color:"error",children:"Error fetching orders!"});const Z=[...q?.getOrdersByUser||[]].sort(((e,t)=>t.id-e.id));return(0,Y.jsxs)(m.A,{maxWidth:"xl",sx:{mt:4,px:{xs:1,sm:2,md:3}},children:[(0,Y.jsx)(h.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,Y.jsx)(h.A,{children:"No orders found!"}):(0,Y.jsx)(ys.A,{component:ne.A,sx:{mt:2,overflowX:"auto","& .MuiTableCell-root":{px:{xs:1,sm:2},py:{xs:1.5,sm:2},whiteSpace:"nowrap"}},children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{sx:{display:{xs:"none",md:"table-cell"}},children:"Order ID"}),(0,Y.jsx)(Is.A,{children:"Address"}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Total"}),(0,Y.jsx)(Is.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Delivery Date"}),(0,Y.jsx)(Is.A,{children:"Bill"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:Z.map((e=>(0,Y.jsxs)(x.Fragment,{children:[(0,Y.jsxs)(bs.A,{onClick:()=>_(e.id),sx:{cursor:"pointer"},children:[(0,Y.jsx)(Is.A,{sx:{display:{xs:"none",md:"table-cell"}},children:e.id}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"PICKUP"===e.type?(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Zs.A,{fontSize:"small"}),e.pickupAddress?.address||"Pickup location not specified"]}):(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(hs.A,{fontSize:"small"}),e.address?.address||"No address provided"]})})}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:e.status,size:E?"small":"medium",color:"COMPLETE"===e.status?"success":"PENDING"===e.status||"ORDER_PLACED"===e.status?"warning":"error"})}),(0,Y.jsxs)(Is.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:["$",e.totalAmount.toFixed(2)]}),(0,Y.jsx)(Is.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:e.deliveryDate?new Date(e.deliveryDate).toLocaleDateString():"N/A"}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(j.A,{sx:{display:"flex",gap:1},children:(0,Y.jsx)(ye.A,{title:"Download Bill",children:(0,Y.jsx)(ce.A,{size:"small",onClick:t=>{t.stopPropagation(),(async e=>{if(!p)try{y(!0);const t=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",s=await fetch(`${t}/s3/generate-view-url?order_id=${e}&file_name=order_${e}.jpeg`);if(200===s.status){const e=await s.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{y(!1)}})(e.id)},children:(0,Y.jsx)($n.A,{})})})})}),(0,Y.jsx)(Is.A,{children:(0,Y.jsxs)(j.A,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,Y.jsx)(J.A,{variant:"contained",color:"error",size:E?"small":"medium",onClick:t=>{var s;t.stopPropagation(),s=e.id,a(s),r(!0)},disabled:!Q(e.status),children:"Cancel"}),(0,Y.jsx)(ce.A,{onClick:t=>{t.stopPropagation(),_(e.id)},size:"small",children:o===e.id?(0,Y.jsx)(Tn.A,{}):(0,Y.jsx)(Rn.A,{})})]})})]}),(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{style:{paddingBottom:0,paddingTop:0},colSpan:7,children:(0,Y.jsx)(Dn.A,{in:o===e.id,timeout:"auto",unmountOnExit:!0,children:(0,Y.jsx)(j.A,{sx:{margin:{xs:1,sm:2}},children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsxs)(h.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,Y.jsx)(Zs.A,{})," Order Items"]}),(0,Y.jsx)(ne.A,{sx:{p:{xs:1.5,sm:2}},children:e.orderItems?.edges?.length>0?(0,Y.jsx)(me.Ay,{container:!0,spacing:{xs:1,sm:2},children:H(e.orderItems).map((t=>{const s=t.product.inventoryItems?.edges[0]?.node,n=((e,t)=>{const s=new Map;t.forEach((e=>{let{node:t}=e;s.set(t.id,t)}));const n=[e];let r=e.id;for(;;){const e=Array.from(s.values()).find((e=>e.updatedOrderitemsId===r));if(!e)break;n.push(e),r=e.id}return n.reverse()})(t,e.orderItems.edges);return(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(Ae.A,{variant:"outlined",sx:{p:{xs:1.5,sm:2},"&:hover":{bgcolor:"grey.50"}},children:[(0,Y.jsxs)(me.Ay,{container:!0,spacing:{xs:1,sm:2},alignItems:"center",children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,sm:4,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",fontWeight:600,sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.product.name}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",fontWeight:500,children:t.product.category.name}),n.length>1&&(0,Y.jsxs)(h.A,{variant:"caption",color:"primary",sx:{display:"block",mt:.5},children:[n.length-1," previous version",n.length>2?"s":""]})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:6,sm:2,children:[(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Unit Price"}),(0,Y.jsxs)(h.A,{variant:"body1",fontWeight:500,children:["$",s?.price.toFixed(2)]}),s&&(0,Y.jsxs)(h.A,{variant:"caption",color:"text.secondary",fontWeight:500,children:[s.measurement," ",s.unit]})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:6,sm:2,children:[(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Quantity"}),f===t.id?(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(A.A,{type:"number",size:"small",value:b,onChange:e=>I(parseInt(e.target.value)||0),inputProps:{min:0},sx:{width:"80px"}}),(0,Y.jsxs)(j.A,{sx:{display:"flex",gap:.5},children:[(0,Y.jsx)(ce.A,{size:"small",color:"primary",onClick:()=>((e,t)=>{0===b?S({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{V(e,t,0),v(null),I(null),S({open:!1,title:"",message:"",onConfirm:null})}}):b>0&&(V(e,t,b),v(null),I(null))})(e,t),disabled:null===b||b<0,children:(0,Y.jsx)(Wn.A,{fontSize:"small"})}),(0,Y.jsx)(ce.A,{size:"small",color:"error",onClick:K,children:(0,Y.jsx)(In.A,{fontSize:"small"})})]})]}):(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(h.A,{variant:"body1",fontWeight:500,children:t.quantity}),Q(e.status)&&(0,Y.jsx)(ce.A,{size:"small",onClick:()=>{return v((e=t).id),void I(e.quantity);var e},children:(0,Y.jsx)(Ls.A,{fontSize:"small"})})]})]}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:4,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",sm:"flex-end"},alignItems:"center",gap:1,mt:{xs:1,sm:0}},children:[(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Total:"}),(0,Y.jsxs)(h.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)]}),Q(e.status)&&(0,Y.jsx)(ce.A,{size:"small",color:"error",onClick:s=>{s.stopPropagation(),((e,t)=>{S({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{V(e,t,0),S({open:!1,title:"",message:"",onConfirm:null})}})})(e,t)},children:(0,Y.jsx)(Os.A,{fontSize:"small"})})]})})]}),n.length>1&&(0,Y.jsxs)(j.A,{sx:{mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[(0,Y.jsxs)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(qn.A,{fontSize:"small"}),"Order Change History (",n.length-1," ","changes)"]}),(0,Y.jsx)(j.A,{sx:{pl:2},children:n.slice(0,-1).map(((e,t)=>(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1.5,borderRadius:1,mb:1},children:[(0,Y.jsxs)(h.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"120px",fontWeight:500},children:["Change ",t+1]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",gap:3},children:[(0,Y.jsxs)(h.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,Y.jsxs)(h.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount: $",e.orderAmount.toFixed(2)]})]})]},e.id)))})]})]})},t.id)}))}):(0,Y.jsx)(j.A,{sx:{textAlign:"center",py:3,color:"text.secondary"},children:(0,Y.jsx)(h.A,{fontWeight:500,children:"No items found for this order."})})})]}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(ne.A,{sx:{p:{xs:1.5,sm:2},mb:3},children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,md:6,children:[(0,Y.jsxs)(h.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,Y.jsx)($n.A,{})," Order Details"]}),(0,Y.jsxs)(j.A,{sx:{pl:1},children:[e.customOrder&&(0,Y.jsxs)(j.A,{sx:{mb:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Custom Order Instructions"}),(0,Y.jsx)(h.A,{variant:"body2",fontWeight:500,sx:{whiteSpace:"pre-line",bgcolor:"grey.50",p:1.5,borderRadius:1,mt:.5},children:e.customOrder})]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Subtotal"}),(0,Y.jsxs)(h.A,{fontWeight:500,children:["$",e.totalAmount?e.totalAmount.toFixed(2):"0.00"]})]}),void 0!==e.deliveryFee&&(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Fee"}),(0,Y.jsxs)(h.A,{fontWeight:500,children:["$",e.deliveryFee?e.deliveryFee.toFixed(2):"0.00"]})]}),void 0!==e.taxAmount&&(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tax"}),(0,Y.jsxs)(h.A,{fontWeight:500,children:["$",e.taxAmount?e.taxAmount.toFixed(2):"0.00"]})]}),void 0!==e.tipAmount&&(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tip"}),(0,Y.jsxs)(h.A,{fontWeight:500,children:["$",e.tipAmount?e.tipAmount.toFixed(2):"0.00"]})]}),(0,Y.jsx)(kt.A,{sx:{my:1}}),(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Total Amount"}),(0,Y.jsxs)(h.A,{variant:"subtitle1",color:"primary",fontWeight:700,children:["$",e.orderTotalAmount?e.orderTotalAmount.toFixed(2):"0.00"]})]})]})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,md:6,children:[(0,Y.jsxs)(h.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,Y.jsx)(hs.A,{})," Delivery Information"]}),(0,Y.jsxs)(j.A,{sx:{pl:1},children:[(0,Y.jsxs)(j.A,{sx:{mb:1},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"PICKUP"===e.type?"Pickup Location":"Delivery Address"}),(0,Y.jsx)(h.A,{variant:"body2",fontWeight:500,children:"PICKUP"===e.type?e.pickupAddress?.address||"Pickup location not specified":e.address?.address||"No address provided"})]}),e.deliveryInstructions&&(0,Y.jsxs)(j.A,{sx:{mb:1},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Instructions"}),(0,Y.jsx)(h.A,{variant:"body2",fontWeight:500,children:e.deliveryInstructions})]}),e.deliveryDate&&(0,Y.jsxs)(j.A,{sx:{mb:1},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,children:"Expected Delivery Date"}),(0,Y.jsx)(h.A,{variant:"body2",fontWeight:500,children:new Date(e.deliveryDate).toLocaleDateString()})]}),e.cancelMessage&&(0,Y.jsxs)(j.A,{sx:{mb:1},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"error",fontWeight:700,children:"Cancellation Reason"}),(0,Y.jsx)(h.A,{variant:"body2",color:"error",fontWeight:500,children:e.cancelMessage})]})]})]})]})})})]})})})})})]},e.id)))})]})}),(0,Y.jsxs)(Fe.A,{open:n,onClose:M,fullWidth:!0,maxWidth:"sm",children:[(0,Y.jsx)(De.A,{children:"Cancel Order"}),(0,Y.jsxs)(Le.A,{children:[(0,Y.jsx)(Ln.A,{gutterBottom:!0,children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,Y.jsx)(A.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,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:M,color:"primary",children:"No, Keep Order"}),(0,Y.jsx)(J.A,{onClick:()=>{i&&d.trim()&&U.mutate({orderId:i,cancelMessage:d.trim()})},color:"error",variant:"contained",disabled:!d.trim(),children:"Yes, Cancel Order"})]})]}),(0,Y.jsxs)(Fe.A,{open:C.open,onClose:()=>S({open:!1,title:"",message:"",onConfirm:null}),children:[(0,Y.jsx)(De.A,{children:C.title}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(Ln.A,{children:C.message})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>S({open:!1,title:"",message:"",onConfirm:null}),color:"primary",children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:C.onConfirm,color:"error",variant:"contained",children:"Remove"})]})]})]})};var On=s(55629),Nn=s(45402);const Un=()=>{const{userProfile:e,setUserProfile:t,fetchUserProfile:s,isProfileLoading:n,profileError:r}=G(),i=(0,d.Zp)(),[a,o]=(0,x.useState)(0),[l,c]=(0,x.useState)(null),[u,p]=(0,x.useState)(null),[y,f]=(0,x.useState)(!1),v=window.location.origin,{addresses:b,selectedAddressId:I,setSelectedAddressId:C,fetchAddresses:S,isLoading:w,createAddress:P,updateAddress:E,deleteAddress:k}=H(),[F,D]=(0,x.useState)(!1),[L,$]=(0,x.useState)(null),[T,R]=(0,x.useState)(""),[W,q]=(0,x.useState)(!1),[z,O]=(0,x.useState)(!1),[N,U]=(0,x.useState)(!1),[B,M]=(0,x.useState)({open:!1,message:"",severity:"success"}),[_,V]=(0,x.useState)(!1),[K,Q]=(0,x.useState)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ge.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;p(t),await s(t)}}catch(e){}})()}),[s]);const Z=e||l;(0,x.useEffect)((()=>{Z?.id&&S(Z.id)}),[Z?.id,S]);const X=async()=>{try{await(0,Ye.C)(),i("/")}catch(e){}},ee=`${v}/signup?referredby=${e?.referralId}`,se=async()=>{try{await navigator.clipboard.writeText(ee),f(!0),setTimeout((()=>f(!1)),2e3)}catch(e){}};if(n)return(0,Y.jsx)(m.A,{children:(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:[(0,Y.jsx)(g.A,{}),(0,Y.jsx)(h.A,{sx:{ml:2},children:"Loading profile..."})]})});if(r)return(0,Y.jsxs)(m.A,{children:[(0,Y.jsxs)(te.A,{severity:"error",sx:{mt:4},children:["Error loading profile: ",r]}),(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>s(),sx:{mt:2},children:"Retry"})]});if(!e)return(0,Y.jsxs)(m.A,{children:[(0,Y.jsx)(te.A,{severity:"warning",sx:{mt:4},children:"No profile data available. Please try again."}),(0,Y.jsx)(J.A,{variant:"contained",onClick:async()=>{try{const e=await(0,Ge.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;await s(t)}}catch(e){}},sx:{mt:2},children:"Load Profile"})]});return(0,Y.jsxs)(m.A,{maxWidth:"xl",sx:{py:4},children:[(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:3,children:(0,Y.jsxs)(ne.A,{elevation:0,sx:{borderRadius:2,overflow:"hidden"},children:[(0,Y.jsx)(j.A,{sx:{p:2,bgcolor:"primary.main",color:"white"},children:(0,Y.jsx)(h.A,{variant:"h6",children:"My Account"})}),(0,Y.jsxs)(Tt.A,{component:"nav",sx:{pt:0},children:[(0,Y.jsxs)(Wt.A,{selected:0===a,onClick:()=>o(0),sx:{borderRadius:"0 0 0 0","&.Mui-selected":{bgcolor:"rgba(25, 118, 210, 0.08)",borderLeft:"4px solid",borderColor:"primary.main"}},children:[(0,Y.jsx)(ns.A,{children:(0,Y.jsx)(Ke.A,{color:0===a?"primary":"inherit"})}),(0,Y.jsx)(rs.A,{primary:"Profile"})]}),(0,Y.jsxs)(Wt.A,{selected:1===a,onClick:()=>o(1),sx:{"&.Mui-selected":{bgcolor:"rgba(25, 118, 210, 0.08)",borderLeft:"4px solid",borderColor:"primary.main"}},children:[(0,Y.jsx)(ns.A,{children:(0,Y.jsx)(us.A,{color:1===a?"primary":"inherit"})}),(0,Y.jsx)(rs.A,{primary:"Addresses"})]}),(0,Y.jsxs)(Wt.A,{selected:2===a,onClick:()=>o(2),sx:{"&.Mui-selected":{bgcolor:"rgba(25, 118, 210, 0.08)",borderLeft:"4px solid",borderColor:"primary.main"}},children:[(0,Y.jsx)(ns.A,{children:(0,Y.jsx)(xs.A,{color:2===a?"primary":"inherit"})}),(0,Y.jsx)(rs.A,{primary:"Settings"})]})]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:9,children:(0,Y.jsxs)(j.A,{sx:{height:"100%"},children:[0===a&&(0,Y.jsx)(Ae.A,{sx:{height:"100%"},children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Y.jsx)(qt.A,{sx:{width:100,height:100,bgcolor:"primary.main",fontSize:"2.5rem",mr:3},children:e?.firstName?.[0]}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsxs)(h.A,{variant:"h5",gutterBottom:!0,children:[e?.firstName," ",e?.lastName]}),(0,Y.jsxs)(St.A,{direction:"row",spacing:2,alignItems:"center",children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Y.jsx)(Bs.A,{sx:{mr:1,color:"text.secondary"}}),(0,Y.jsx)(h.A,{color:"text.secondary",children:e?.email})]}),e?.mobile&&(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Y.jsx)(Us.A,{sx:{mr:1,color:"text.secondary"}}),(0,Y.jsx)(h.A,{color:"text.secondary",children:e.mobile})]})]})]})]}),(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Referral Program"}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:2},children:[(0,Y.jsx)(A.A,{fullWidth:!0,value:ee,InputProps:{readOnly:!0,endAdornment:(0,Y.jsx)(ye.A,{title:y?"Copied!":"Copy referral link",children:(0,Y.jsx)(ce.A,{onClick:se,children:(0,Y.jsx)(On.A,{})})})}}),(0,Y.jsx)(J.A,{variant:"contained",startIcon:(0,Y.jsx)(Nn.A,{}),onClick:se,children:"Share"})]})]})}),1===a&&(()=>{const e=[...b].sort(((e,t)=>(t.isPrimary?1:0)-(e.isPrimary?1:0)));return(0,Y.jsx)(Ae.A,{sx:{height:"100%"},children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h6",children:"My Addresses"}),(0,Y.jsx)(J.A,{variant:"contained",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>D(!0),children:"Add Address"})]}),w?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",p:4},children:(0,Y.jsx)(g.A,{})}):e.length>0?(0,Y.jsx)(me.Ay,{container:!0,spacing:2,children:e.map((e=>(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:6,children:(0,Y.jsxs)(ne.A,{elevation:2,sx:{p:2,position:"relative",border:e.isPrimary?"2px solid":"1px solid",borderColor:e.isPrimary?"primary.main":"divider"},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",color:"primary",children:e.isPrimary?"Primary Address":"Secondary Address"}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(ce.A,{size:"small",onClick:()=>(e=>{$(e),R(e.address),q(e.isPrimary),D(!0)})(e),children:(0,Y.jsx)(Ls.A,{fontSize:"small"})}),(0,Y.jsx)(ce.A,{size:"small",onClick:()=>{return t=e.id,Q(t),void V(!0);var t},children:(0,Y.jsx)(Os.A,{fontSize:"small"})})]})]}),(0,Y.jsx)(h.A,{variant:"body2",children:e.address})]})},e.id)))}):(0,Y.jsx)(te.A,{severity:"info",sx:{mt:2},children:"You don't have any addresses yet. Add one to get started!"})]})})})(),2===a&&(0,Y.jsx)(Ae.A,{sx:{height:"100%"},children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Account Settings"}),(0,Y.jsxs)(St.A,{spacing:3,children:[(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Notification Preferences"}),(0,Y.jsx)(Pt.A,{control:(0,Y.jsx)(vn.A,{defaultChecked:!0}),label:"Email notifications for orders"}),(0,Y.jsx)(Pt.A,{control:(0,Y.jsx)(vn.A,{defaultChecked:!0}),label:"SMS notifications for delivery updates"})]}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Privacy Settings"}),(0,Y.jsx)(Pt.A,{control:(0,Y.jsx)(vn.A,{defaultChecked:!0}),label:"Share order history with delivery partners"})]}),(0,Y.jsx)(j.A,{children:(0,Y.jsx)(J.A,{variant:"outlined",color:"error",startIcon:(0,Y.jsx)(ps.A,{}),onClick:X,sx:{mt:2},children:"Logout"})})]})]})})]})})]}),(0,Y.jsxs)(Fe.A,{open:F,onClose:()=>D(!1),fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:L?"Edit Address":"Add Address"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(St.A,{spacing:2,mt:1,children:[(0,Y.jsx)(Ht,{value:T,onChange:R,onValidAddress:U}),(0,Y.jsx)(Pt.A,{control:(0,Y.jsx)(vn.A,{checked:W,onChange:e=>q(e.target.checked)}),label:"Set as Primary Address"})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{D(!1),R(""),U(!1)},children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:async()=>{if(Z?.id){O(!0);try{if(!N)return;if(L)if(W){for(const e of b)e.id!==L.id&&e.isPrimary&&await E(e.id,e.address,!1);await E(L.id,T,!0),M({open:!0,message:"Address updated as primary",severity:"success"})}else{L.isPrimary&&1===b.filter((e=>e.isPrimary)).length?(await E(L.id,T,!0),M({open:!0,message:"At least one address must be primary",severity:"warning"})):(await E(L.id,T,!1),M({open:!0,message:"Address updated as secondary",severity:"success"}))}else if(0===b.length)await P(T,Z.id,!0),M({open:!0,message:"Address added successfully",severity:"success"});else if(W){for(const e of b)e.isPrimary&&await E(e.id,e.address,!1);await P(T,Z.id,!0),M({open:!0,message:"Address added as primary",severity:"success"})}else await P(T,Z.id,!1),M({open:!0,message:"Address added as secondary",severity:"success"});await S(Z.id),D(!1),$(null),R(""),q(!1),U(!1)}catch(e){M({open:!0,message:"Failed to save address. Please try again.",severity:"error"})}finally{O(!1)}}else M({open:!0,message:"Could not save address: user information not available",severity:"error"})},variant:"contained",disabled:!T||z||!N,children:z?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(g.A,{size:20,sx:{mr:1}})," Saving..."]}):"Save"})]})]}),(0,Y.jsxs)(Fe.A,{open:_,onClose:()=>V(!1),children:[(0,Y.jsx)(De.A,{children:"Delete Address"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{children:"Are you sure you want to delete this address? This action cannot be undone."})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>V(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:async()=>{try{await k(K),M({open:!0,message:"Address deleted successfully",severity:"success"})}catch(e){M({open:!0,message:"Failed to delete address. Please try again.",severity:"error"})}finally{V(!1),Q(null)}},color:"error",variant:"contained",children:"Delete"})]})]}),(0,Y.jsx)(Ds.A,{open:B.open,autoHideDuration:3e3,onClose:()=>M({...B,open:!1}),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,Y.jsx)(te.A,{onClose:()=>M({...B,open:!1}),severity:B.severity,sx:{width:"100%"},children:B.message})})]})},Bn=()=>{const e=(0,d.Zp)();return(0,Y.jsx)(m.A,{maxWidth:"md",children:(0,Y.jsx)(j.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,Y.jsx)(h.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,Y.jsx)(h.A,{variant:"body1",color:"text.secondary",paragraph:!0,children:"The page you are looking for does not exist or is not available."}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(st),children:"Go to Dashboard"})]})})})},Mn=()=>{const e=(0,d.Zp)();return(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{maxWidth:"md",children:(0,Y.jsx)(j.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,Y.jsx)(h.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,Y.jsx)(h.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,Y.jsx)(J.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(st),children:"Go to Dashboard"})]})})})})},_n=e=>{let{open:t,onClose:s,selectedFee:n,onUpdate:r,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,l]=(0,x.useState)(a);(0,x.useEffect)((()=>{n?l({feeCurrency:n.feeCurrency||"",feeRate:n.feeRate?.toString()||"",limit:n.limit?.toString()||"",type:n.type?.toUpperCase()||"DELIVERY"}):t&&l(a)}),[n,t]),(0,x.useEffect)((()=>{t||l(a)}),[t]);const d=e=>{const{name:t,value:s}=e.target;l((e=>({...e,[t]:s})))};return(0,Y.jsxs)(Fe.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:n?"Edit Fee":"Add New Fee"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(j.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Y.jsxs)(Ps.A,{fullWidth:!0,children:[(0,Y.jsx)(Es.A,{children:"Fee Type"}),(0,Y.jsxs)(ks.A,{name:"type",value:o.type,onChange:d,label:"Fee Type",children:[(0,Y.jsx)(ue.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,Y.jsx)(ue.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,Y.jsx)(A.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:d,fullWidth:!0,placeholder:"e.g., USD"}),(0,Y.jsx)(A.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,Y.jsx)(A.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:s,children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{r({id:n?.id,...o,feeRate:parseFloat(o.feeRate),limit:parseFloat(o.limit)}),n||l(a)},disabled:i,startIcon:i?(0,Y.jsx)(g.A,{size:20}):null,children:i?"Saving...":"Save"})]})]})},Vn=()=>{const[e,t]=(0,x.useState)(""),{userProfile:s,setUserProfile:n}=G(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,A]=(0,x.useState)(""),[p,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,xt.T)();t(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:v}=(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:b,isLoading:I,error:C}=(0,u.I)({queryKey:["storeWithFees",s?.id],queryFn:()=>P("\n query GetStoreWithFees($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:s.id}),enabled:!!s?.id}),S=b?.storesByManager?.[0],{data:w,isLoading:E,error:k,refetch:F}=(0,u.I)({queryKey:["getFeesByStore",S?.id],queryFn:()=>P("\n query GetFeesByStore($storeId: Int!) {\n getFeesByStore(storeId: $storeId) {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n }\n",{storeId:S?.id}),enabled:!!S?.id}),D=w?.getFeesByStore||[],L=(0,Ts.n)({mutationFn:e=>P("\n mutation UpdateFee($input: UpdateFeeInput!) {\n updateFee(input: $input) {\n fee {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:()=>{F(),o(!1),i(null),y("Fee updated successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error updating fee: ${e.message}`)}}),$=(0,Ts.n)({mutationFn:e=>P("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{F(),d(!1),i(null),y("Fee deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error deleting fee: ${e.message}`)}}),T=(0,Ts.n)({mutationFn:e=>P("\n mutation CreateFee($input: CreateFeeInput!) {\n createFee(input: $input) {\n fee {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n error {\n message\n }\n }\n }\n",{input:{...e,storeId:S?.id}}),onSuccess:()=>{F(),o(!1),i(null),y("Fee added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error adding fee: ${e.message}`)}});return v||I||E?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Y.jsx)(g.A,{})})}):C||k?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4},children:(0,Y.jsxs)(te.A,{severity:"error",children:["Error loading data: ",C?.message||k?.message]})})}):(0,Y.jsx)(kn,{children:(0,Y.jsxs)(m.A,{children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Delivery Fees Management"}),p&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:p}),c&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:c}),(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",children:"Fees"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>{i(null),o(!0)},children:"Add Fee"})]}),(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Type"}),(0,Y.jsx)(Is.A,{children:"Currency"}),(0,Y.jsx)(Is.A,{children:"Rate"}),(0,Y.jsx)(Is.A,{children:"Limit"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:D.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.type}),(0,Y.jsx)(Is.A,{children:e.feeCurrency}),(0,Y.jsx)(Is.A,{children:e.feeRate}),(0,Y.jsx)(Is.A,{children:e.limit}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",children:(0,Y.jsx)(Os.A,{})})]})]},e.id)))})]})})]}),(0,Y.jsx)(_n,{open:a,onClose:()=>{o(!1),i(null),A("")},selectedFee:r,onUpdate:e=>{r?L.mutate(e):T.mutate(e)},isLoading:L.isLoading||T.isLoading}),(0,Y.jsxs)(Fe.A,{open:l,onClose:()=>{d(!1),i(null),A("")},children:[(0,Y.jsx)(De.A,{children:"Delete Fee"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{d(!1),i(null)},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isLoading,children:$.isLoading?(0,Y.jsx)(g.A,{size:24}):"Delete"})]})]})]})})},Gn=()=>{const e=(0,d.Zp)(),{user:t,setUser:s}=G(),[n,i]=(0,x.useState)(!0),a=(0,Ce.A)();return(0,x.useEffect)((()=>{(async()=>{try{const t=await(0,Ge.$)();if(t?.tokens?.idToken){const n=t.tokens.idToken.payload.sub,r=t.tokens.idToken.payload["custom:role"]?.toLowerCase();s({id:n,role:r}),e(`/${r}`)}}catch(e){}finally{i(!1)}})()}),[s,e]),n?(0,Y.jsx)(ie,{}):(0,Y.jsx)(j.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,Y.jsxs)(ne.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,Y.jsxs)(j.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,Y.jsx)(h.A,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:"Welcome Back"}),(0,Y.jsx)(h.A,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"Sign in to continue your journey with us"})]}),(0,Y.jsx)(pt,{}),(0,Y.jsxs)(j.A,{sx:{mt:4,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:[(0,Y.jsx)(r.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,Y.jsxs)(h.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:["Don't have an account?"," ",(0,Y.jsx)(r.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 Hn=s(1405);const Kn=(0,s(11848).Ay)(A.A)((e=>{let{theme:t}=e;return{"& .MuiInputBase-root":{minHeight:"120px"}}})),Yn=e=>{let{sectionHeaders:t,answers:s={},onChangeAnswers:n,onSubmit:r}=e;const[i,a]=(0,x.useState)(!1),[o,l]=(0,x.useState)(!1),d=()=>Object.values(s).some((e=>e&&""!==e.trim()));return(0,Y.jsxs)(j.A,{sx:{width:"100%"},children:[(0,Y.jsx)(me.Ay,{container:!0,spacing:3,children:t.map(((e,t)=>(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(ne.A,{elevation:1,sx:{p:3,height:"100%",border:"1px solid",borderColor:"divider",borderRadius:2,boxShadow:2,display:"flex",flexDirection:"column",gap:2,background:"linear-gradient(135deg, #f8fafc 0%, #e0e7ef 100%)"},children:[(0,Y.jsx)(h.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,color:"primary.main",letterSpacing:.2},children:e}),(0,Y.jsx)(Kn,{fullWidth:!0,multiline:!0,minRows:5,placeholder:`Enter items for ${e.toLowerCase()}`,variant:"outlined",value:s[t]||"",onChange:e=>((e,t)=>{const r={...s,[e]:t};n(r)})(t,e.target.value),sx:{"& .MuiOutlinedInput-root":{backgroundColor:"background.paper"}}})]})},t)))}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"flex-end",mt:4},children:(0,Y.jsx)(J.A,{variant:"contained",color:"primary",size:"large",disabled:!d(),sx:{px:5,py:1.5,fontWeight:600,borderRadius:2,boxShadow:1,opacity:d()?1:.6},onClick:()=>{if(!d())return;const e=(()=>{if(!t||0===t.length)return"";const e=[];return t.forEach(((t,n)=>{const r=s[n]?s[n].trim():"";r&&(e.push(t),r.split("\n").forEach((t=>{const s=t.trim();s&&e.push(` • ${s}`)})),e.push(""))})),e.join("\n").trim()})();r(e),l(Object.values(s).some((e=>""!==e.trim()))),a(!0),(()=>{const e={};t.forEach(((t,s)=>{e[s]=""})),n(e)})(),setTimeout((()=>{a(!1)}),3e3)},children:"Submit List"})}),(0,Y.jsxs)(Fe.A,{open:i,onClose:()=>a(!1),PaperProps:{sx:{borderRadius:2,minWidth:"300px"}},children:[(0,Y.jsxs)(De.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Ys.A,{color:"success",sx:{fontSize:28}}),(0,Y.jsx)(h.A,{variant:"h6",sx:{fontWeight:600},children:o?"Items Edited":"Items Added"})]}),(0,Y.jsx)(ce.A,{onClick:()=>a(!1),size:"small",sx:{color:"text.secondary"},children:(0,Y.jsx)(In.A,{})})]}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{variant:"body1",color:"text.secondary",children:o?"Your custom order has been updated in the cart.":"Your custom order has been added to the cart."})}),(0,Y.jsx)(Fs.A,{sx:{px:3,pb:2},children:(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>a(!1),sx:{borderRadius:2,textTransform:"none",px:3},children:"Okay"})})]})]})},Qn=()=>{const[e,t]=(0,x.useState)(!1),[s,n]=(0,x.useState)(!1),[r,i]=(0,x.useState)(!1),{selectedStore:a,setAvailableStores:o,setSelectedStore:l,pickupAddress:d,setCustomOrder:c,listInputAnswers:h,setListInputAnswers:m}=K(),{data:A,isLoading:p,error:j}=(0,u.I)({queryKey:["stores"],queryFn:async()=>await P($)});(0,x.useEffect)((()=>{if(A?.stores&&A.stores.length>0){o(A.stores);const e=localStorage.getItem("selectedStoreId");if(e){const s=A.stores.find((t=>String(t.id)===e));a&&a.id===s?.id||(s?l(s):(localStorage.removeItem("selectedStoreId"),t(!0)))}else a||t(!0)}}),[A,a,o]);if(p)return(0,Y.jsx)(Q,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:(0,Y.jsx)(ie,{})});const g=a?.sectionHeaders?.length>0;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Kt,{open:e,onClose:()=>t(!1)}),a&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(de,{children:(0,Y.jsxs)(Q,{sx:{alignItems:"center",mb:3,mt:2,p:2,backgroundColor:"rgba(0, 0, 0, 0.03)",borderRadius:2},children:[(0,Y.jsxs)(Q,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",width:"100%"},children:[(0,Y.jsxs)(Q,{children:[(0,Y.jsx)(ee,{variant:"h6",children:a.name}),(0,Y.jsx)(ee,{variant:"body2",color:"text.secondary",children:a.address})]}),d&&(0,Y.jsxs)(Z,{variant:"outlined",color:"primary",sx:{display:"flex",flexDirection:"column",alignItems:"flex-end",minWidth:180,borderRadius:2,fontWeight:600,textTransform:"none"},onClick:()=>n(!0),children:[(0,Y.jsx)(ee,{variant:"subtitle2",color:"primary",children:"Change Pickup Location"}),(0,Y.jsx)(ee,{variant:"body2",color:"text.secondary",children:d.address})]})]}),(0,Y.jsxs)(Q,{sx:{mt:1,display:"flex",justifyContent:"space-between"},children:[(0,Y.jsx)(ee,{variant:"body2",color:"text.secondary",children:a.description}),(0,Y.jsx)(ee,{variant:"body2",color:"text.secondary",children:a.tnc})]})]})}),(0,Y.jsx)(Kt,{open:s,onClose:()=>n(!1),forceStep:"pickup",initialStore:a}),(0,Y.jsxs)(de,{children:[g&&(0,Y.jsx)(ne.A,{elevation:0,sx:{p:2,mb:3,backgroundColor:"rgba(0, 0, 0, 0.03)",borderRadius:2,minHeight:72},children:(0,Y.jsxs)(Q,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,Y.jsx)(ee,{variant:"h6",sx:{fontWeight:600},children:r?"Browse Products":"Quick List Entry"}),(0,Y.jsx)(Q,{sx:{minWidth:200,display:"flex",alignItems:"center",justifyContent:"flex-end"},children:(0,Y.jsx)(Pt.A,{control:(0,Y.jsx)(Hn.A,{checked:r,onChange:()=>{i(!r)},color:"primary"}),label:(0,Y.jsx)(ee,{variant:"body2",color:"text.secondary",sx:{width:140,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r?"Manual Browse":"Quick List"}),labelPlacement:"end",sx:{marginLeft:2}})})]})}),g&&!r?(0,Y.jsx)(Yn,{sectionHeaders:a.sectionHeaders,answers:h,onChangeAnswers:m,onSubmit:c}):(0,Y.jsx)(Ve,{})]})]})]})};var Jn=s(37483),Zn=s(28211),Xn=s(51694),er=s(85916),tr=s(11692),sr=s(2183);const nr=e=>{let{size:t=24,sx:s}=e;return(0,Y.jsx)(g.A,{size:t,sx:{color:"inherit",...s}})},rr=e=>{let{userProfile:t,onPhoneUpdate:s}=e;const[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(""),[o,l]=(0,x.useState)(""),{mutate:d,isPending:c}=(0,Ts.n)({mutationFn:e=>P("\n mutation UpdateSecondaryPhone($userId: Int!, $secondaryPhone: String) {\n updateSecondaryPhone(userId: $userId, secondaryPhone: $secondaryPhone) {\n active\n }\n }\n",e),onSuccess:()=>{s(),r(!1),a(""),l("")},onError:e=>{l("Failed to update phone number. Please try again.")}});return t?(0,Y.jsx)(j.A,{sx:{mb:3},children:n?(0,Y.jsxs)(ne.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Us.A,{color:"primary"}),(0,Y.jsx)(h.A,{variant:"subtitle1",sx:{fontWeight:500},children:t.secondaryPhone?"Update Number":"Add Number"})]}),(0,Y.jsx)(A.A,{size:"small",value:i,onChange:e=>{const t=e.target.value.replace(/\D/g,"").slice(0,10);a(t),l("")},placeholder:"Enter 10-digit number",error:!!o,helperText:o,InputProps:{startAdornment:(0,Y.jsx)(h.A,{sx:{mr:1},children:"+1"})}}),(0,Y.jsxs)(j.A,{sx:{display:"flex",gap:1},children:[(0,Y.jsx)(J.A,{variant:"contained",size:"small",onClick:()=>{10===i.length?d({userId:t.id,secondaryPhone:i}):l("Please enter a valid 10-digit phone number")},disabled:c||10!==i.length,startIcon:c?(0,Y.jsx)(nr,{size:20}):(0,Y.jsx)(Us.A,{}),children:c?"Saving...":"Save"}),(0,Y.jsx)(J.A,{variant:"outlined",size:"small",onClick:()=>{r(!1),a(""),l("")},children:"Cancel"})]})]}):(0,Y.jsxs)(ne.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Us.A,{color:"primary"}),(0,Y.jsx)(h.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Secondary Contact"}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"(Update if you want to change)"})]}),t.secondaryPhone?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(h.A,{variant:"body1",children:["+1 ",t.secondaryPhone]}),(0,Y.jsx)(J.A,{variant:"outlined",size:"small",onClick:()=>r(!0),startIcon:(0,Y.jsx)(Us.A,{}),sx:{alignSelf:"flex-start"},children:"Change Number"})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"No secondary number added"}),(0,Y.jsx)(J.A,{variant:"outlined",size:"small",onClick:()=>r(!0),startIcon:(0,Y.jsx)(Us.A,{}),sx:{alignSelf:"flex-start"},children:"Add Number"})]})]})}):null},ir=()=>{const{cart:e,removeFromCart:t,addToCart:s,cartTotal:n,clearCart:i,selectedStore:o,getCartTotals:l,setTipAmount:c,customOrder:u,setCustomOrder:m,pickupAddress:g,setPickupAddress:y,deliveryType:f,setDeliveryType:v,tipAmount:b}=K(),[I,C]=(0,x.useState)(""),[S,w]=(0,x.useState)(!1),[E,k]=(0,x.useState)(""),{userProfile:F,fetchUserProfile:D,isProfileLoading:L,setModalOpen:$,setCurrentForm:T}=G(),R=(0,d.Zp)(),W=(0,a.jE)(),[q,z]=(0,x.useState)(0),[O,N]=(0,x.useState)(""),[U,B]=(0,x.useState)(null),[M,_]=(0,x.useState)(!1);(0,x.useEffect)((()=>{(async()=>{const e=await(0,Ge.$)(),t=e?.tokens?.idToken?.payload?.sub;t&&await D(t)})()}),[D]);const{addresses:V,selectedAddressId:Q,setSelectedAddressId:Z,fetchAddresses:X,isLoading:ee,createAddress:te}=H(),[se,re]=(0,x.useState)(!1),[ie,ae]=(0,x.useState)(""),[oe,le]=(0,x.useState)(!1),[de,xe]=(0,x.useState)(!1),[he,pe]=(0,x.useState)(!1),[ge,ye]=(Object.values(e).reduce(((e,t)=>e+(t.quantity||0)),0),(0,x.useState)({subtotal:0,deliveryFee:0,taxAmount:0,taxPercentage:0,tipAmount:0,total:0}));(0,x.useEffect)((()=>{F?.id&&X(F.id)}),[F?.id,X]),(0,x.useEffect)((()=>{g&&(B(String(g.id)),v("pickup"),Z(null))}),[g,v]),(0,x.useEffect)((()=>{const e=l();ye(e)}),[f,e,l,b]);const{subtotal:be,deliveryFee:Ie,taxAmount:Ce,taxPercentage:Se,tipAmount:we,total:Pe}=ge;(0,x.useEffect)((()=>{if(!M){if(o?.pickupAddresses?.edges?.length>0&&!U&&!Q){const e=o.pickupAddresses.edges[0].node;return B(String(e.id)),v("pickup"),void Z(null)}if(V&&V.length>0&&!U&&!Q){const e=V.find((e=>e.isPrimary))||V[0];return Z(e.id),v("delivery"),void B(null)}o?.pickupAddresses?.edges?.length&&0!==o?.pickupAddresses?.edges?.length||V&&0!==V.length||U||Q||v("pickup")}}),[o?.pickupAddresses?.edges,V,M]);const{mutate:Ee,isPending:ke}=(0,Ts.n)({mutationKey:["createOrder"],mutationFn:async e=>{const t=K.getState().selectedStore;return P("\n mutation CreateOrder(\n $userId: Int!\n $storeId: Int!\n $productItems: [OrderItemInput!]!\n $totalAmount: Float!\n $orderTotalAmount: Float!\n $pickupOrDelivery: String!\n $addressId: Int\n $pickupId: Int\n $deliveryFee: Float\n $tipAmount: Float\n $taxAmount: Float\n $deliveryInstructions: String\n $customOrder: String\n ) {\n createOrder(\n userId: $userId\n storeId: $storeId\n productItems: $productItems\n totalAmount: $totalAmount\n orderTotalAmount: $orderTotalAmount\n pickupOrDelivery: $pickupOrDelivery\n addressId: $addressId\n pickupId: $pickupId\n deliveryFee: $deliveryFee\n tipAmount: $tipAmount\n taxAmount: $taxAmount\n deliveryInstructions: $deliveryInstructions\n customOrder: $customOrder\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=>{i(),m(""),w(!0),setTimeout((()=>{w(!1),R("/")}),2e3),W.invalidateQueries(["userAddresses",F.id])},onError:e=>{k(e.message||"Failed to place order. Please try again.")}});return(0,Y.jsxs)(j.A,{sx:{padding:3},children:[(0,Y.jsxs)(h.A,{variant:"h4",component:"h1",gutterBottom:!0,sx:{fontWeight:600,color:"primary.main",mb:4,display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Zs.A,{})," Your Shopping Cart"]}),S?(0,Y.jsxs)(ne.A,{elevation:4,sx:{mb:3,p:4,display:"flex",flexDirection:"column",alignItems:"center",borderRadius:3,background:"linear-gradient(135deg, #e0ffe8 0%, #f8fff8 100%)",boxShadow:6,border:"2px solid #4caf50"},children:[(0,Y.jsx)(Ys.A,{sx:{fontSize:64,color:"success.main",mb:2}}),(0,Y.jsx)(h.A,{variant:"h4",sx:{fontWeight:700,color:"success.main",mb:1},children:"Order placed successfully!"}),(0,Y.jsx)(h.A,{variant:"h6",sx:{color:"text.secondary",mb:2,textAlign:"center"},children:"Thank you for your purchase. Your order is being processed and you'll receive an update soon!"})]}):(0,Y.jsxs)(me.Ay,{container:!0,spacing:3,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:8,children:(0,Y.jsxs)(ne.A,{elevation:2,sx:{p:3,mb:3},children:[E&&(0,Y.jsx)(Me,{error:E,title:"Order Error",severity:"error"}),Object.values(e).length>0||u?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h.A,{variant:"h6",sx:{mb:2,fontWeight:500},children:"Cart Items"}),Object.values(e).map((e=>(0,Y.jsx)(Ae.A,{sx:{mb:2,position:"relative"},children:(0,Y.jsx)(je.A,{children:(0,Y.jsxs)(me.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:4,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:2},children:[(0,Y.jsx)("img",{src:e.image,alt:e.name,style:{width:60,height:60,objectFit:"cover",borderRadius:8}}),(0,Y.jsx)(h.A,{variant:"subtitle1",sx:{fontWeight:500},children:e.name})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:3,children:(0,Y.jsxs)(h.A,{color:"text.secondary",children:["$",e.price.toFixed(2)," each"]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:3,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(ce.A,{size:"small",onClick:()=>t(e.id),sx:{border:"1px solid",borderColor:"divider"},children:(0,Y.jsx)(fe.A,{fontSize:"small"})}),(0,Y.jsx)(h.A,{sx:{minWidth:40,textAlign:"center"},children:e.quantity}),(0,Y.jsx)(ce.A,{size:"small",onClick:()=>s(e),sx:{border:"1px solid",borderColor:"divider"},children:(0,Y.jsx)(ve.A,{fontSize:"small"})})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:2,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",sx:{fontWeight:600,textAlign:"right"},children:["$",(e.price*e.quantity).toFixed(2)]})})]})})},e.id))),u&&(0,Y.jsx)(Ae.A,{sx:{mb:2,position:"relative",bgcolor:"primary.lighter"},children:(0,Y.jsxs)(je.A,{children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:2,mb:2},children:[(0,Y.jsx)(Zs.A,{color:"primary"}),(0,Y.jsx)(h.A,{variant:"h6",sx:{fontWeight:600,color:"primary.main"},children:"Custom Shopping List"})]}),(0,Y.jsx)(j.A,{sx:{p:2,bgcolor:"background.paper",borderRadius:1,border:"1px solid",borderColor:"divider"},children:(0,Y.jsx)(h.A,{variant:"body1",sx:{whiteSpace:"pre-line",fontFamily:"monospace",lineHeight:1.6},children:u})}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"flex-end",mt:2},children:(0,Y.jsx)(J.A,{variant:"outlined",color:"error",size:"small",onClick:()=>m(""),startIcon:(0,Y.jsx)(fe.A,{}),children:"Remove List"})})]})})]}):(0,Y.jsxs)(j.A,{sx:{textAlign:"center",py:4},children:[(0,Y.jsx)(Zs.A,{sx:{fontSize:60,color:"text.secondary",mb:2}}),(0,Y.jsx)(h.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"Your cart is empty"}),(0,Y.jsx)(J.A,{variant:"contained",component:r.N_,to:"/",startIcon:(0,Y.jsx)(Zs.A,{}),children:"Continue Shopping"})]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(ne.A,{elevation:2,sx:{p:3,position:"sticky",top:24},children:[(0,Y.jsx)(h.A,{variant:"h6",sx:{mb:3,fontWeight:500},children:"Order Summary"}),F&&(0,Y.jsx)(j.A,{sx:{mb:3},children:(0,Y.jsx)(rr,{userProfile:F,onPhoneUpdate:()=>{(async()=>{const e=await(0,Ge.$)(),t=e?.tokens?.idToken?.payload?.sub;t&&await D(t)})()}})}),(0,Y.jsxs)(j.A,{sx:{mt:3},children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Order Summary"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,Y.jsx)(h.A,{children:"Subtotal"}),(0,Y.jsxs)(h.A,{children:["$",be.toFixed(2)]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,Y.jsx)(h.A,{children:"Delivery Fee"}),(0,Y.jsxs)(h.A,{children:["$",Ie.toFixed(2)]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Tax Rate"}),(0,Y.jsxs)(h.A,{children:[Se.toFixed(1),"%"]})]}),(0,Y.jsxs)(j.A,{sx:{textAlign:"right"},children:[(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:"Tax Amount"}),(0,Y.jsxs)(h.A,{children:["$",Ce.toFixed(2)]})]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(j.A,{sx:{mb:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,children:"Add Tip"}),(0,Y.jsxs)(Jn.A,{value:q,exclusive:!0,onChange:(e,t)=>{if(null!==t){z(t),N("");c(be*t/100)}},"aria-label":"tip percentage",size:"small",fullWidth:!0,sx:{mb:1},children:[(0,Y.jsx)(Zn.A,{value:0,"aria-label":"no tip",children:"No Tip"}),(0,Y.jsx)(Zn.A,{value:10,"aria-label":"10%",children:"10%"}),(0,Y.jsx)(Zn.A,{value:15,"aria-label":"15%",children:"15%"}),(0,Y.jsx)(Zn.A,{value:20,"aria-label":"20%",children:"20%"})]}),(0,Y.jsx)(A.A,{fullWidth:!0,size:"small",label:"Custom Tip Amount",type:"number",value:O,onChange:e=>{const t=e.target.value;N(t),z(0);const s=parseFloat(t)||0;c(s)},InputProps:{startAdornment:(0,Y.jsx)(h.A,{sx:{mr:1},children:"$"})},placeholder:"Enter custom amount",sx:{mt:1}})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,Y.jsx)(h.A,{children:"Tip Amount"}),(0,Y.jsxs)(h.A,{children:["$",we.toFixed(2)]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(kt.A,{})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,Y.jsx)(h.A,{variant:"h6",children:"Total"}),(0,Y.jsxs)(h.A,{variant:"h6",children:["$",Pe.toFixed(2)]})]})})]})]}),u&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsxs)(h.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Zs.A,{})," Custom Order Details"]}),(0,Y.jsx)(ne.A,{elevation:0,sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:2,backgroundColor:"background.paper"},children:(0,Y.jsx)(h.A,{variant:"body2",sx:{whiteSpace:"pre-line",color:"text.secondary",fontFamily:"monospace"},children:u})})]}),F&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsxs)(h.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(hs.A,{})," Delivery/Pickup Options"]}),L?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,Y.jsx)(nr,{size:24})}):(0,Y.jsxs)(St.A,{spacing:3,children:[o?.pickupAddresses?.edges?.length>0&&(0,Y.jsxs)(ne.A,{elevation:"pickup"===f?4:1,sx:{p:2,bgcolor:"pickup"===f?"primary.lighter":"grey.50",opacity:"delivery"===f&&Q?.5:1,border:"pickup"===f?"2px solid #1976d2":"1px solid #eee",transition:"all 0.2s"},children:[(0,Y.jsxs)(h.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(_t.A,{fontSize:"small",color:"primary"})," Pickup Address"]}),(0,Y.jsx)(wt.A,{value:U||"",onChange:e=>{const t=e.target.value;B(t),v("pickup"),Z(null);const s=o.pickupAddresses.edges.map((e=>e.node)),n=s.find((e=>String(e.id)===String(t)));n&&y(n)},children:o.pickupAddresses.edges.map((e=>{let{node:t}=e;return(0,Y.jsx)(Pt.A,{value:String(t.id),control:(0,Y.jsx)(Et.A,{color:"primary"}),label:t.address},t.id)}))})]}),(0,Y.jsxs)(ne.A,{elevation:"delivery"===f?4:1,sx:{p:2,bgcolor:"delivery"===f?"secondary.lighter":"grey.50",opacity:"pickup"===f&&U?.5:1,border:"delivery"===f?"2px solid #9c27b0":"1px solid #eee",transition:"all 0.2s"},children:[(0,Y.jsxs)(h.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Xn.A,{fontSize:"small",color:"secondary"})," Home Delivery Address"]}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsxs)(Ps.A,{fullWidth:!0,sx:{mb:2},children:[(0,Y.jsx)(Es.A,{children:"Select Address"}),ee?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,Y.jsx)(nr,{size:24})}):(0,Y.jsx)(ks.A,{value:Q||"",onChange:e=>{Z(e.target.value),v("delivery"),B(null),_(!0)},label:"Select Address",inputProps:{},InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(sr.A,{})})},children:V&&V.length>0?V.map((e=>(0,Y.jsxs)(ue.A,{value:e.id,children:[e.address," ",e.isPrimary?"(Primary)":""]},e.id))):(0,Y.jsx)(ue.A,{disabled:!0,children:"No addresses available"})})]}),(0,Y.jsx)(J.A,{fullWidth:!0,variant:"outlined",startIcon:se?(0,Y.jsx)(er.A,{}):(0,Y.jsx)(tr.A,{}),onClick:()=>re(!se),sx:{mb:2},children:se?"Cancel":"Add New Address"}),(0,Y.jsx)(Dn.A,{in:se,children:(0,Y.jsx)(j.A,{sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:1},children:(0,Y.jsxs)(St.A,{spacing:2,children:[(0,Y.jsx)(Ht,{value:ie,onChange:ae,onValidAddress:pe}),(0,Y.jsx)(Pt.A,{control:(0,Y.jsx)(vn.A,{checked:oe,onChange:e=>le(e.target.checked)}),label:"Set as Primary Address"}),(0,Y.jsx)(J.A,{variant:"contained",onClick:async()=>{if(ie.trim()){xe(!0);try{await te(ie,F.id,oe),re(!1),ae(""),le(!1),W.invalidateQueries(["userAddresses",F.id])}catch(e){k("Failed to add address. Please try again.")}finally{xe(!1)}}else k("Please enter a valid address")},disabled:!ie.trim()||de||!he,startIcon:de?(0,Y.jsx)(nr,{size:20}):(0,Y.jsx)(us.A,{}),children:de?"Adding...":"Add Address"})]})})})]})]})]})]}),F&&(0,Y.jsxs)(j.A,{sx:{mb:3},children:[(0,Y.jsx)(h.A,{variant:"subtitle1",sx:{mb:2},children:"Delivery Instructions"}),(0,Y.jsx)(A.A,{fullWidth:!0,multiline:!0,rows:2,value:I,onChange:e=>C(e.target.value),placeholder:"Add any special instructions for delivery..."})]}),F?(0,Y.jsx)(J.A,{fullWidth:!0,variant:"contained",size:"large",onClick:async()=>{if(k(""),!U&&!Q)return void k("Please select either a pickup location or delivery address");const t=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity})));let s=null;if(U){s=o.pickupAddresses.edges.map((e=>e.node)).find((e=>String(e.id)===String(U)))}let n=null;Q&&(n=V.find((e=>e.id===Q)));const r={userId:F.id,addressId:Q,pickupId:U?parseInt(U,10):null,storeId:o.id,productItems:t,totalAmount:be,orderTotalAmount:Pe,pickupOrDelivery:f,deliveryFee:"pickup"===f?0:Ie,tipAmount:b,taxAmount:Ce,deliveryInstructions:"pickup"===f?null:I,customOrder:u};Ee(r)},disabled:ke||L||!Q&&!U||0===Object.values(e).length&&!u?.trim(),startIcon:ke?(0,Y.jsx)(nr,{size:20}):(0,Y.jsx)(cs.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:ke?"Processing...":"Place Order"}):(0,Y.jsx)(J.A,{fullWidth:!0,variant:"contained",size:"large",onClick:()=>{$(!0),T("login")},startIcon:(0,Y.jsx)(Zs.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"Login to Continue"})]})})]})]})};var ar=s(16099),or=s(98821),lr=s(1309);const dr=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(e);var cr=s(25737),xr=s(55463),ur=s(67046),hr=s(4213);(0,cr.D)();const mr=[{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"}],Ar="\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",pr=()=>{const{userProfile:e}=G(),[t,s]=(0,x.useState)(""),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),[o,l]=(0,x.useState)(!1),[d,c]=(0,x.useState)(null),[m,f]=(0,x.useState)(""),[v,b]=(0,x.useState)(""),[I,C]=(0,x.useState)(""),[S,w]=(0,x.useState)("ALL"),[$,T]=(0,x.useState)("createdAt"),[R,W]=(0,x.useState)("desc"),[q,z]=(0,x.useState)(0),[O,N]=(0,x.useState)(10),[U,B]=(0,x.useState)(""),[M,_]=(0,x.useState)(""),[V,H]=(0,x.useState)(""),[K,Q]=(0,x.useState)(""),[Z,X]=(0,x.useState)({open:!1,message:"",severity:"info"}),[ee,se]=(0,x.useState)(!1),[re,ie]=(0,x.useState)(null),[ae,oe]=(0,x.useState)(1),[le,de]=(0,x.useState)(!1),[xe,he]=(0,x.useState)(null),[pe,ge]=(0,x.useState)(!0);(0,x.useEffect)((()=>{const e=setTimeout((()=>{ge(!1)}),1e3);return()=>clearTimeout(e)}),[]),(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,xt.T)();s(e.sub)}catch(e){}})()}),[]);const{data:fe,isLoading:ve}=(0,u.I)({queryKey:["getUserProfile",t],queryFn:async()=>await P(k,{userId:t}),enabled:!!t}),be=fe?.getUserProfile?.stores?.edges?.[0]?.node?.id,Ie=fe?.getUserProfile?.id,{data:Ce,isLoading:we,error:Pe,refetch:Ee}=(0,u.I)({queryKey:["storeDrivers",be],queryFn:async()=>await P(D,{storeId:be}),enabled:!!be}),{data:ke,isLoading:$e,error:Te,refetch:Re}=(0,u.I)({queryKey:["storeOrders",be],queryFn:async()=>(await P(F,{storeId:be})).getOrdersByStore||[],enabled:!!be}),We=(0,Ts.n)({mutationFn:async e=>await P(E,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onSuccess:()=>{Re(),a(!1),c(null),f(""),_(""),H(""),Q("")},onError:e=>{b(e.message)}}),qe=(0,Ts.n)({mutationFn:async e=>{const{orderId:t,itemId:s,quantity:n,price:r}=e,i=ke.find((e=>e.id===t));if(!i)throw new Error("Order not found");const a=fe?.getUserProfile?.stores?.edges?.[0]?.node?.taxPercentage||0,o=new Map;i.orderItems.edges.forEach((e=>{let{node:t}=e;const s=t.productId;(!o.has(s)||t.id>o.get(s).id)&&o.set(s,t)}));if(!Array.from(o.values()).some((e=>e.id===parseInt(s)?n>0:e.quantity>0)))return await P(Ar,{orderId:parseInt(t),orderItemUpdates:[{orderItemId:parseInt(s),quantityChange:n-re.quantity}],totalAmount:0,orderTotalAmount:0,taxAmount:0});let l=0;o.forEach((e=>{if(e.id===parseInt(s))l+=n*r;else{const t=e.product?.inventoryItems?.edges[0]?.node?.price||0;l+=e.quantity*t}}));const d=l*a/100,c=l+d+(i.deliveryFee||0)+(i.tipAmount||0),x=n-re.quantity;return await P(Ar,{orderId:parseInt(t),orderItemUpdates:[{orderItemId:parseInt(s),quantityChange:x}],totalAmount:l,orderTotalAmount:c,taxAmount:d})},onSuccess:()=>{Re(),se(!1),ie(null),oe(1)},onError:e=>{b(e.message)}}),ze=e=>{$===e?W("asc"===R?"desc":"asc"):(T(e),W("asc"))},Oe=x.useMemo((()=>{if(!ke)return[];let e=[...ke];return I&&(e=e.filter((e=>e.id.toString().includes(I)||(e.deliveryInstructions||"").toLowerCase().includes(I.toLowerCase())))),"ALL"!==S&&(e=e.filter((e=>e.status===S))),e.sort(((e,t)=>{let s=0;return s="totalAmount"===$?e[$]-t[$]:String(e[$]||"").localeCompare(String(t[$]||"")),"asc"===R?s:-s})),e}),[ke,I,S,$,R]),Ne=x.useMemo((()=>{const e=q*O;return Oe.slice(e,e+O)}),[Oe,q,O]),Ue=e=>{if(!e?.edges?.length)return null;const t=new Map;e.edges.forEach((e=>{let{node:s}=e;const n=s.productId;(!t.has(n)||s.id>t.get(n).id)&&t.set(n,s)}));return Array.from(t.values())},Be=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e),Me=async(e,t)=>{try{if("pdf"===t){const t=(e=>{const t=new xr.uE;let s=20;const n=20;return t.internal.pageSize.width,t.setFontSize(16),t.text("Orders Report",n,s),s+=14,t.setFontSize(10),I&&(t.text(`Search Term: ${I}`,n,s),s+=7),"ALL"!==S&&(t.text(`Status Filter: ${S}`,n,s),s+=7),s+=7,e.forEach(((e,r)=>{s>t.internal.pageSize.height-40&&(t.addPage(),s=20),t.setFontSize(12),t.text(`Order #${e.id}`,n,s),s+=7,t.text(`Order Code: ${e.displayCode||"N/A"}`,n,s),s+=10.5,t.setFontSize(10),["Type: "+("PICKUP"===e.type?"Pickup":"Delivery"),`Status: ${mr.find((t=>t.value===e.status))?.label||e.status}`,`Total: $${e.orderTotalAmount}`,`Customer: ${e.creator?.email||"N/A"}`,`Phone: ${e.creator?.mobile||"N/A"}`,`Address: ${"PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A"}`].forEach((e=>{t.text(e,25,s),s+=7})),e.customOrder&&(s+=7,t.setFontSize(11),t.text("Custom Order Details:",25,s),s+=7,e.customOrder.split("\n\n").forEach((e=>{const[n,...r]=e.split("\n");n&&r.length>0&&(t.setFontSize(10),t.text(`Q: ${n}`,30,s),s+=7,r.forEach((e=>{t.text(`A: ${e}`,35,s),s+=7})),s+=3.5)}))),e.orderItems?.edges?.length>0&&(s+=7,t.setFontSize(11),t.text("Items:",25,s),s+=7,e.orderItems.edges.forEach((e=>{let{node:n}=e;const r=n.product?.inventoryItems?.edges[0]?.node?.price||0,i=`${n.product?.name||"N/A"} - Qty: ${n.quantity} - Price: $${r} - Total: $${n.quantity*r}`;t.text(i,30,s),s+=7}))),s+=14})),t})(e);t.save(`orders_${(new Date).toISOString().replace(/[-:]/g,"").replace("T","_").replace("Z","")}.pdf`)}else{const t=(e=>new ur.yoT({sections:[{properties:{},children:[new ur.fzL({children:[new ur.NTc({text:"Orders Report",bold:!0,size:32})]}),new ur.fzL({children:[new ur.NTc({text:I?`Search Term: ${I}`:"",size:24})]}),new ur.fzL({children:[new ur.NTc({text:"ALL"!==S?`Status Filter: ${S}`:"",size:24})]}),...e.map((e=>[new ur.fzL({children:[new ur.NTc({text:`Order #${e.id}`,bold:!0,size:28})]}),new ur.fzL({children:[new ur.NTc({text:`Order Code: ${e.displayCode||"N/A"}`,size:24})]}),new ur.XIK({width:{size:100,type:ur.PsV.PERCENTAGE},rows:[new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL("Type")],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL("PICKUP"===e.type?"Pickup":"Delivery")],width:{size:80,type:ur.PsV.PERCENTAGE}})]}),new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL("Status")],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL(mr.find((t=>t.value===e.status))?.label||e.status)],width:{size:80,type:ur.PsV.PERCENTAGE}})]}),new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL("Total")],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL(`$${e.orderTotalAmount}`)],width:{size:80,type:ur.PsV.PERCENTAGE}})]}),new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL("Customer")],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL(e.creator?.email||"N/A")],width:{size:80,type:ur.PsV.PERCENTAGE}})]}),new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL("Phone")],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL(e.creator?.mobile||"N/A")],width:{size:80,type:ur.PsV.PERCENTAGE}})]}),new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL("Address")],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL("PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A")],width:{size:80,type:ur.PsV.PERCENTAGE}})]})]}),...e.customOrder?[new ur.fzL({children:[new ur.NTc({text:"Custom Order Details",bold:!0,size:24})]}),new ur.XIK({width:{size:100,type:ur.PsV.PERCENTAGE},rows:e.customOrder.split("\n\n").map((e=>{const[t,...s]=e.split("\n");return t&&s.length>0?new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL(t)],width:{size:30,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL({children:s.map(((e,t)=>[new ur.NTc(e),...t0?[new ur.fzL({children:[new ur.NTc({text:"Items",bold:!0,size:24})]}),new ur.XIK({width:{size:100,type:ur.PsV.PERCENTAGE},rows:[new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL("Product")],width:{size:40,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL("Quantity")],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL("Price")],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL("Total")],width:{size:20,type:ur.PsV.PERCENTAGE}})]}),...e.orderItems.edges.map((e=>{let{node:t}=e;const s=t.product?.inventoryItems?.edges[0]?.node?.price||0;return new ur.Hjg({children:[new ur.nA6({children:[new ur.fzL(t.product?.name||"N/A")],width:{size:40,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL(t.quantity.toString())],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL(`$${s}`)],width:{size:20,type:ur.PsV.PERCENTAGE}}),new ur.nA6({children:[new ur.fzL("$"+t.quantity*s)],width:{size:20,type:ur.PsV.PERCENTAGE}})]})}))]})]:[],new ur.fzL({})])).flat()]}]}))(e),s=await ur.ND6.toBlob(t);(0,hr.saveAs)(s,`orders_${(new Date).toISOString().replace(/[-:]/g,"").replace("T","_").replace("Z","")}.docx`)}X({open:!0,message:`Orders downloaded successfully in ${t.toUpperCase()} format!`,severity:"success"})}catch(e){X({open:!0,message:"Failed to download orders. Please try again.",severity:"error"})}de(!1)};return ve||$e||we||pe?(0,Y.jsx)(kn,{children:(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,Y.jsx)(g.A,{})})}):!Te&&!Pe||pe?(0,Y.jsx)(kn,{children:(0,Y.jsxs)(j.A,{sx:{p:3},children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Store Orders"}),v&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:v}),(0,Y.jsx)(Ae.A,{sx:{mb:3},children:(0,Y.jsx)(je.A,{children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:3,children:(0,Y.jsx)(A.A,{fullWidth:!0,placeholder:"Search orders...",value:I,onChange:e=>C(e.target.value),InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)($s.A,{})})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:3,children:(0,Y.jsxs)(A.A,{select:!0,fullWidth:!0,label:"Filter by Status",value:S,onChange:e=>w(e.target.value),InputProps:{startAdornment:(0,Y.jsx)(p.A,{position:"start",children:(0,Y.jsx)(ar.A,{})})},children:[(0,Y.jsx)(ue.A,{value:"ALL",children:"All Statuses"}),mr.map((e=>(0,Y.jsx)(ue.A,{value:e.value,children:e.label},e.value)))]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:3,children:(0,Y.jsxs)(h.A,{variant:"body2",color:"textSecondary",children:["Total Orders: ",Oe.length]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:3,children:(0,Y.jsx)(J.A,{fullWidth:!0,variant:"contained",startIcon:(0,Y.jsx)(or.A,{}),onClick:()=>de(!0),disabled:0===Oe.length,children:"Download Orders"})})]})})}),0===Oe.length?(0,Y.jsx)(te.A,{severity:"info",sx:{mb:2},children:"No orders found."}):(0,Y.jsxs)(ys.A,{component:ne.A,children:[(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>ze("id"),children:["Order ID",(0,Y.jsx)(lr.A,{sx:{ml:1,transform:"id"===$&&"desc"===R?"rotate(180deg)":"none"}})]})}),(0,Y.jsx)(Is.A,{children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>ze("totalAmount"),children:["Total",(0,Y.jsx)(lr.A,{sx:{ml:1,transform:"totalAmount"===$&&"desc"===R?"rotate(180deg)":"none"}})]})}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{children:"Actions"}),(0,Y.jsx)(Is.A,{})]})}),(0,Y.jsx)(Cs.A,{children:Ne.map((e=>{return(0,Y.jsxs)(x.Fragment,{children:[(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.id}),(0,Y.jsxs)(Is.A,{children:["$",e.orderTotalAmount]}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:mr.find((t=>t.value===e.status))?.label||e.status,color:(t=e.status,mr.find((e=>e.value===t))?.color||"default"),size:"small"})}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ye.A,{title:"Edit Order",children:(0,Y.jsx)(ce.A,{size:"small",onClick:()=>(e=>{c(e),f(e.status),_(e.deliveryInstructions||""),a(!0)})(e),disabled:!Be(e.status),children:(0,Y.jsx)(Ls.A,{})})}),(0,Y.jsx)(ye.A,{title:"Cancel Order",children:(0,Y.jsx)(ce.A,{size:"small",onClick:()=>(e=>{c(e),l(!0)})(e),disabled:!Be(e.status),children:(0,Y.jsx)(Qs.A,{})})}),(0,Y.jsx)(ye.A,{title:"Upload File",children:(0,Y.jsx)(ce.A,{size:"small",onClick:()=>(async e=>{const t=document.createElement("input");t.type="file",t.accept="*/*",t.onchange=async()=>{try{const s=t.files[0];if(!s)return;const n=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",r=await fetch(`${n}/s3/generate-upload-url?file_name=${encodeURIComponent(s.name)}&order_id=${e.id}`);if(!r.ok)throw new Error("Failed to get upload URL");const{upload_url:i,content_type:a,file_name:o,key:l}=await r.json(),d=await fetch(i,{method:"PUT",headers:{"Content-Type":a},body:s});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(o)}`,{method:"POST"})).ok)throw new Error("Failed to update bill URL");(await fetch(`${n}/s3/generate-view-url?bill_key=${encodeURIComponent(l)}`)).ok?X({open:!0,message:"File uploaded and verified successfully!",severity:"success"}):X({open:!0,message:"File uploaded but verification failed. Please try viewing the file.",severity:"warning"})}catch(e){X({open:!0,message:"Failed to upload file. Please try again.",severity:"error"})}},t.click()})(e),disabled:!Be(e.status),children:(0,Y.jsx)(Hs.A,{})})}),(0,Y.jsx)(ye.A,{title:"View File",children:(0,Y.jsx)(ce.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 s=null,n=null;if(e.bill_url){const r=await fetch(`${t}/s3/generate-view-url?bill_key=${encodeURIComponent(e.bill_url)}`);if(r.ok){const e=await r.json();s=e.view_url,n=e.file_name}}if(!s){const r=[".pdf",".jpg",".jpeg",".png",".docx"];for(const i of r){const r=await fetch(`${t}/s3/generate-view-url?order_id=${e.id}&file_name=receipt${i}`);if(r.ok){const e=await r.json();s=e.view_url,n=e.file_name;break}}}if(!s)return void X({open:!0,message:"No file found for this order.",severity:"warning"});const r=document.createElement("a");r.href=s,r.target="_blank",r.rel="noopener noreferrer",document.body.appendChild(r),r.click(),document.body.removeChild(r)}catch(e){X({open:!0,message:"Failed to view file. Please try again.",severity:"error"})}})(e),children:(0,Y.jsx)(Xs.A,{})})})]}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(ce.A,{size:"small",onClick:()=>r(n===e.id?null:e.id),children:n===e.id?(0,Y.jsx)(er.A,{}):(0,Y.jsx)(tr.A,{})})})]}),n===e.id&&(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:6,children:(0,Y.jsx)(j.A,{sx:{p:2},children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Information"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(h.A,{children:[(0,Y.jsx)("strong",{children:"Order Code:"})," ",e.displayCode||"N/A"]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(h.A,{children:[(0,Y.jsx)("strong",{children:"Type:"})," ","PICKUP"===e.type?(0,Y.jsxs)(j.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(Zs.A,{fontSize:"small"}),"Pickup Order"]}):(0,Y.jsxs)(j.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Y.jsx)(hs.A,{fontSize:"small"}),"Delivery Order"]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsxs)(h.A,{children:[(0,Y.jsx)("strong",{children:"Address:"})," ","PICKUP"===e.type?e.pickupAddress?.address||"No pickup address":e.address?.address||"No delivery address"]})})]})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Customer Information"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{children:["Email: ",e?.creator?.email||"N/A"]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(h.A,{children:["Phone: ",e?.creator?.mobile||"N/A"]})})]})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Items"}),(0,Y.jsxs)(fs.A,{size:"small",children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Product"}),(0,Y.jsx)(Is.A,{children:"Quantity"}),(0,Y.jsx)(Is.A,{children:"Price"}),(0,Y.jsx)(Is.A,{children:"Total"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:e.orderItems?.edges?.length>0?Ue(e.orderItems)?.map((t=>{const s=(n=t,r=e.orderItems.edges,n&&r?r.map((e=>{let{node:t}=e;return t})).filter((e=>e.productId===n.productId)).sort(((e,t)=>e.id-t.id)):[n]);var n,r;const i=t.product?.inventoryItems?.edges[0]?.node?.price||0;return(0,Y.jsxs)(x.Fragment,{children:[(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:t.product?.name||"N/A"}),(0,Y.jsx)(Is.A,{children:t.quantity}),(0,Y.jsx)(Is.A,{children:dr(i)}),(0,Y.jsx)(Is.A,{children:dr(t.quantity*i)}),(0,Y.jsx)(Is.A,{children:Be(e.status)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ce.A,{size:"small",onClick:()=>{return s=t,n=e.id,ie({...s,orderId:n}),oe(s.quantity),void se(!0);var s,n},sx:{mr:1},children:(0,Y.jsx)(Ls.A,{fontSize:"small"})}),(0,Y.jsx)(ce.A,{size:"small",onClick:()=>{return s=t,n=e.id,ie({...s,orderId:n}),oe(0),void se(!0);var s,n},color:"error",children:(0,Y.jsx)(Os.A,{fontSize:"small"})})]})})]}),s.length>1&&(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:5,children:(0,Y.jsxs)(j.A,{sx:{pl:2,py:1},children:[(0,Y.jsxs)(h.A,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1},children:["Order Change History (",s.length-1," ","changes)"]}),s.slice(0,-1).map(((e,t)=>(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1,borderRadius:1,mb:1},children:[(0,Y.jsxs)(h.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"100px"},children:["Change ",t+1]}),(0,Y.jsxs)(j.A,{sx:{display:"flex",gap:3},children:[(0,Y.jsxs)(h.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,Y.jsxs)(h.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount:"," ",dr(e.orderAmount)]})]})]},e.id)))]})})})]},t.id)})):(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:5,align:"center",children:"No items found for this order"})})})]})]}),e.customOrder&&(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Custom Order Details"}),(0,Y.jsx)(j.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:e.customOrder.split("\n\n").map(((e,t)=>{const[s,...n]=e.split("\n");return s&&n.length>0?(0,Y.jsxs)(j.A,{sx:{mb:2},children:[(0,Y.jsx)(h.A,{variant:"subtitle2",sx:{color:"text.secondary",mb:.5},children:s}),(0,Y.jsx)(j.A,{sx:{pl:2},children:n.map(((e,t)=>(0,Y.jsx)(h.A,{variant:"body2",sx:{mb:.5},children:e},t)))})]},t):null}))})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Summary"}),(0,Y.jsx)(j.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:1,children:[(0,Y.jsx)(me.Ay,{item:!0,xs:6,children:(0,Y.jsx)(h.A,{children:"Subtotal:"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Y.jsx)(h.A,{children:dr(e.totalAmount)})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,children:(0,Y.jsx)(h.A,{children:"Delivery Fee:"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Y.jsx)(h.A,{children:dr(e.deliveryFee)})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,children:(0,Y.jsx)(h.A,{children:"Tax:"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Y.jsx)(h.A,{children:dr(e.taxAmount)})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,children:(0,Y.jsx)(h.A,{children:"Tip:"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Y.jsx)(h.A,{children:dr(e.tipAmount)})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(kt.A,{sx:{my:1}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,children:(0,Y.jsx)(h.A,{sx:{fontWeight:"bold"},children:"Total Amount:"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Y.jsx)(h.A,{sx:{fontWeight:"bold"},children:dr(e.orderTotalAmount)})})]})})]}),e.deliveryInstructions&&(0,Y.jsxs)(me.Ay,{item:!0,xs:12,children:[(0,Y.jsx)(h.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Delivery Instructions"}),(0,Y.jsx)(h.A,{children:e.deliveryInstructions})]})]})})})})]},e.id);var t}))})]}),(0,Y.jsx)(y.A,{component:"div",count:Oe.length,page:q,onPageChange:(e,t)=>{z(t)},rowsPerPage:O,onRowsPerPageChange:e=>{N(parseInt(e.target.value,10)),z(0)},rowsPerPageOptions:[5,10,25,50]})]}),(0,Y.jsxs)(Fe.A,{open:i,onClose:()=>a(!1),maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:"Update Order Status"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{select:!0,fullWidth:!0,label:"Status",value:m,onChange:e=>f(e.target.value),children:mr.map((e=>(0,Y.jsx)(ue.A,{value:e.value,children:e.label},e.value)))})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Delivery Instructions",value:M,onChange:e=>_(e.target.value),multiline:!0,rows:3})}),"READY_FOR_DELIVERY"===m&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,required:!0,children:[(0,Y.jsx)(Es.A,{children:"Delivery Agent"}),(0,Y.jsx)(ks.A,{value:V,onChange:e=>H(e.target.value),label:"Delivery Agent",children:Ce?.getStoreDrivers?.map((e=>(0,Y.jsxs)(ue.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId)))})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:6,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Schedule Time",value:K,onChange:e=>Q(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>a(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:async()=>{try{const e={orderId:d.id,status:m,deliveryInstructions:M};if("READY"===m||"READY_FOR_DELIVERY"===m){if(!V)return void b("Driver ID is required for this status");if(!K)return void b("Schedule time is required for this status");e.driverId=parseInt(V),e.scheduleTime=K}await We.mutateAsync(e)}catch(e){b(e.message)}},variant:"contained",color:"primary",disabled:We.isLoading,children:We.isLoading?"Updating...":"Update"})]})]}),(0,Y.jsxs)(Fe.A,{open:o,onClose:()=>l(!1),children:[(0,Y.jsx)(De.A,{children:"Cancel Order"}),(0,Y.jsxs)(Le.A,{children:[(0,Y.jsx)(h.A,{children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,Y.jsx)(A.A,{fullWidth:!0,label:"Cancellation Reason",value:U,onChange:e=>B(e.target.value),multiline:!0,rows:3,sx:{mt:2},required:!0})]}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>l(!1),children:"No"}),(0,Y.jsx)(J.A,{onClick:async()=>{try{if(!Ie)return void b("User profile not found. Please try again.");await P(L,{orderId:d.id,cancelMessage:U,cancelledByUserId:Ie}),l(!1),B(""),Re(),c(null)}catch(e){b(e.message)}},variant:"contained",color:"error",disabled:!U.trim(),children:"Yes, Cancel Order"})]})]}),(0,Y.jsxs)(Fe.A,{open:ee,onClose:()=>se(!1),maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:0===ae?"Delete Order Item":"Edit Order Item"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsxs)(h.A,{variant:"subtitle1",children:["Product: ",re?.product?.name||"N/A"]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(A.A,{fullWidth:!0,label:"Quantity",type:"number",value:ae,onChange:e=>oe(parseInt(e.target.value)||0),inputProps:{min:0}})})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>se(!1),children:"Cancel"}),(0,Y.jsx)(J.A,{onClick:async()=>{try{await qe.mutateAsync({orderId:re.orderId,itemId:re.id,quantity:ae,price:re.product?.inventoryItems?.edges[0]?.node?.price||0})}catch(e){b(e.message)}},variant:"contained",color:0===ae?"error":"primary",disabled:qe.isLoading,children:qe.isLoading?"Updating...":0===ae?"Delete":"Update"})]})]}),(0,Y.jsxs)(Fe.A,{open:le,onClose:()=>de(!1),maxWidth:"xs",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:"Download Orders"}),(0,Y.jsxs)(Le.A,{children:[(0,Y.jsxs)(h.A,{variant:"body1",gutterBottom:!0,children:["Download ",Oe.length," filtered orders"]}),(0,Y.jsxs)(h.A,{variant:"body2",color:"textSecondary",gutterBottom:!0,children:[I&&`Search term: ${I}`,"ALL"!==S&&`\nStatus: ${S}`]}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Y.jsx)(me.Ay,{item:!0,xs:6,children:(0,Y.jsx)(J.A,{fullWidth:!0,variant:"outlined",onClick:()=>Me(Oe,"pdf"),startIcon:(0,Y.jsx)(or.A,{}),children:"PDF"})}),(0,Y.jsx)(me.Ay,{item:!0,xs:6,children:(0,Y.jsx)(J.A,{fullWidth:!0,variant:"outlined",onClick:()=>Me(Oe,"docx"),startIcon:(0,Y.jsx)(or.A,{}),children:"DOCX"})})]})]}),(0,Y.jsx)(Fs.A,{children:(0,Y.jsx)(J.A,{onClick:()=>de(!1),children:"Cancel"})})]}),(0,Y.jsx)(Ds.A,{open:Z.open,autoHideDuration:6e3,onClose:()=>X({...Z,open:!1}),children:(0,Y.jsx)(te.A,{onClose:()=>X({...Z,open:!1}),severity:Z.severity,sx:{width:"100%"},children:Z.message})})]})}):(0,Y.jsx)(kn,{children:(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:Te?.message||Pe?.message||"An error occurred"})})},jr=[{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"}],gr=[{value:"ACTIVE",label:"Active"},{value:"INACTIVE",label:"Inactive"}],yr=()=>{const{userProfile:e}=G(),[t,s]=(0,x.useState)(null),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)({driverStatus:"",orderStatus:"",dateRange:"all"}),[o,l]=(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?s(t.storesByManager[0].id):c("No store found for this manager")}catch(e){c("Failed to fetch store information")}})()}),[e]);const{data:m,isLoading:p,error:y,refetch:f}=(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&&o}),{data:v,isLoading:b,error:I,refetch:C}=(0,u.I)({queryKey:["storeOrders",t],queryFn:async()=>(await P(F,{storeId:t})).getOrdersByStore||[],enabled:!!t}),S=(e,t)=>{a((s=>({...s,[e]:t})))},w=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"),E=(e,t)=>{if(!e)return[];let s=e.filter((e=>e?.delivery?.driverId===t));if(i.orderStatus&&(s=s.filter((e=>e.status===i.orderStatus))),"all"!==i.dateRange){const e=new Date,t=new Date(e.getFullYear(),e.getMonth(),e.getDate());s=s.filter((e=>{const s=new Date(e.createdAt);switch(i.dateRange){case"today":return s>=t;case"week":const e=new Date(t);return e.setDate(e.getDate()-7),s>=e;case"month":const n=new Date(t);return n.setMonth(n.getMonth()-1),s>=n;default:return!0}}))}return s},k=e=>e?i.driverStatus?e.filter((e=>e.status===i.driverStatus)):e:[],D=p||b,L=y||I||d;return(0,Y.jsx)(kn,{children:(0,Y.jsxs)(j.A,{sx:{p:3},children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Delivery Partners"}),d&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:d}),(0,Y.jsxs)(ne.A,{sx:{p:3,mb:3},children:[(0,Y.jsx)(h.A,{variant:"h6",gutterBottom:!0,children:"Filters"}),(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:4,children:(0,Y.jsxs)(A.A,{select:!0,fullWidth:!0,label:"Driver Status",value:i.driverStatus,onChange:e=>S("driverStatus",e.target.value),children:[(0,Y.jsx)(ue.A,{value:"",children:"All Statuses"}),gr.map((e=>(0,Y.jsx)(ue.A,{value:e.value,children:e.label},e.value)))]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:4,children:(0,Y.jsxs)(A.A,{select:!0,fullWidth:!0,label:"Order Status",value:i.orderStatus,onChange:e=>S("orderStatus",e.target.value),children:[(0,Y.jsx)(ue.A,{value:"",children:"All Statuses"}),jr.map((e=>(0,Y.jsx)(ue.A,{value:e.value,children:e.label},e.value)))]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,sm:4,children:(0,Y.jsxs)(A.A,{select:!0,fullWidth:!0,label:"Date Range",value:i.dateRange,onChange:e=>S("dateRange",e.target.value),children:[(0,Y.jsx)(ue.A,{value:"all",children:"All Time"}),(0,Y.jsx)(ue.A,{value:"today",children:"Today"}),(0,Y.jsx)(ue.A,{value:"week",children:"Last 7 Days"}),(0,Y.jsx)(ue.A,{value:"month",children:"Last 30 Days"})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,children:(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)($s.A,{}),onClick:()=>{l(!0),f(),C()},disabled:!t,children:"Get Data"})})]})]}),D?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",p:3},children:(0,Y.jsx)(g.A,{})}):L?(0,Y.jsx)(te.A,{severity:"error",children:y?.message||I?.message||"An error occurred while fetching data"}):o?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(h.A,{variant:"h6",gutterBottom:!0,children:["Delivery Partners (",k(m?.getStoreDrivers||[]).length,")"]}),(0,Y.jsx)(ys.A,{component:ne.A,children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Driver ID"}),(0,Y.jsx)(Is.A,{children:"Name"}),(0,Y.jsx)(Is.A,{children:"Email"}),(0,Y.jsx)(Is.A,{children:"Phone"}),(0,Y.jsx)(Is.A,{children:"Status"}),(0,Y.jsx)(Is.A,{children:"Orders"}),(0,Y.jsx)(Is.A,{})]})}),(0,Y.jsxs)(Cs.A,{children:[k(m?.getStoreDrivers||[]).map((e=>(0,Y.jsxs)(x.Fragment,{children:[(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e?.userId}),(0,Y.jsx)(Is.A,{children:e.name}),(0,Y.jsx)(Is.A,{children:e?.driver?.email}),(0,Y.jsx)(Is.A,{children:e?.driver?.mobile}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:e?.driver?.active?"Active":"Inactive",color:w(e?.driver?.active),size:"small"})}),(0,Y.jsx)(Is.A,{children:E(v||[],e?.userId).length}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(ce.A,{size:"small",onClick:()=>r(n===e?.userId?null:e?.userId),children:n===e?.userId?(0,Y.jsx)(Tn.A,{}):(0,Y.jsx)(Rn.A,{})})})]}),n===e?.userId&&(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:7,children:(0,Y.jsxs)(j.A,{sx:{p:2},children:[(0,Y.jsxs)(h.A,{variant:"subtitle2",gutterBottom:!0,children:["Orders for ",e.name,":"]}),(0,Y.jsxs)(fs.A,{size:"small",children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Order ID"}),(0,Y.jsx)(Is.A,{children:"Date"}),(0,Y.jsx)(Is.A,{children:"Customer"}),(0,Y.jsx)(Is.A,{children:"Total"}),(0,Y.jsx)(Is.A,{children:"Status"})]})}),(0,Y.jsx)(Cs.A,{children:E(v||[],e?.userId).length>0?E(v||[],e?.userId).map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.id}),(0,Y.jsx)(Is.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,Y.jsx)(Is.A,{children:e.user?.name}),(0,Y.jsxs)(Is.A,{children:["₹",e.totalAmount]}),(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(Se.A,{label:jr.find((t=>t.value===e.status))?.label||e.status,color:w(e.status),size:"small"})})]},e.id))):(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:5,align:"center",children:"No orders found for this driver with the current filters."})})})]})]})})})]},e?.userId))),0===k(m?.getStoreDrivers||[]).length&&(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:7,align:"center",children:"No delivery partners found with the current filters."})})]})]})})]}):(0,Y.jsx)(te.A,{severity:"info",children:'Click the "Get Data" button to fetch delivery partners and their orders.'})]})})};var fr=s(69279);const vr=x.memo((e=>{let{open:t,onClose:s,selectedItem:n,onUpdate:r,isLoading:i}=e;const[a,o]=x.useState(""),[l,d]=x.useState(""),[c,u]=x.useState("");x.useEffect((()=>{n&&(o(n.price?n.price.toString():""),d(n.quantity?n.quantity.toString():""))}),[n]);const m={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"}},A={fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)",marginBottom:"4px",display:"block"};return(0,Y.jsxs)(Fe.A,{open:t,onClose:()=>{u(""),s()},maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:"Edit Inventory Item"}),(0,Y.jsxs)(Le.A,{children:[n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[n.product?.image&&(0,Y.jsx)(pe.A,{component:"img",sx:{width:80,height:80,objectFit:"contain",mr:2},image:n.product.image,alt:n.product.name}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"subtitle1",children:(0,Y.jsx)("strong",{children:n.product?.name})}),(0,Y.jsx)(h.A,{variant:"body2",color:"text.secondary",children:n.product?.category?.name||"Uncategorized"})]})]}),(0,Y.jsx)(kt.A,{sx:{my:2}}),(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)("label",{htmlFor:"edit-price-input",style:A,children:"Price ($)"}),(0,Y.jsx)("input",{id:"edit-price-input",type:"number",value:a,onChange:e=>o(e.target.value),min:"0",step:"0.01",style:m}),(0,Y.jsx)("label",{htmlFor:"edit-quantity-input",style:A,children:"Quantity"}),(0,Y.jsx)("input",{id:"edit-quantity-input",type:"number",value:l,onChange:e=>d(e.target.value),min:"0",style:m})]})]}),c&&(0,Y.jsx)(te.A,{severity:"error",sx:{mt:2},children:c})]}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{u(""),s()},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",onClick:()=>{!a||isNaN(parseFloat(a))||parseFloat(a)<=0?u("Please enter a valid price greater than zero."):!l||isNaN(parseInt(l,10))||parseInt(l,10)<0?u("Please enter a valid quantity (0 or greater)."):(u(""),r({inventoryId:n.id,price:a,quantity:l}))},disabled:i,children:i?(0,Y.jsx)(g.A,{size:24}):"Update"})]})]})})),br=x.memo((e=>{let{open:t,onClose:s,storeId:n,availableProducts:r,onAdd:i,isLoading:a,errorMessage:o}=e;const[l,d]=(0,x.useState)(null),[c,u]=(0,x.useState)({price:"",quantity:"",size:"",unit:"",searchInput:""}),[h,m]=(0,x.useState)(!1),A=(0,x.useRef)(null),p=e=>{const{name:t,value:s}=e.target;u((e=>({...e,[t]:s})))},y=x.useMemo((()=>r.filter((e=>e.name.toLowerCase().includes(c.searchInput.toLowerCase())))),[r,c.searchInput]),f=()=>{d(null),u({price:"",quantity:"",size:"",unit:"",searchInput:""})};x.useEffect((()=>{t||f()}),[t]);const v={width:"100%",padding:"8.5px 14px",fontSize:"1rem",borderRadius:"4px",border:"1px solid rgba(0, 0, 0, 0.23)",marginBottom:"16px",outline:"none"},b={fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)",marginBottom:"4px",display:"block"};return(0,Y.jsxs)(Fe.A,{open:t,onClose:()=>{s(),f()},maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:"Add Product to Inventory"}),(0,Y.jsxs)(Le.A,{children:[(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)("label",{htmlFor:"searchInput",style:b,children:"Search Product"}),(0,Y.jsxs)("div",{style:{position:"relative"},children:[(0,Y.jsx)("input",{id:"searchInput",name:"searchInput",type:"text",placeholder:"Start typing to search...",value:c.searchInput,onChange:e=>{p(e),m(!0)},onFocus:()=>m(!0),style:v,ref:A}),a&&(0,Y.jsx)(g.A,{size:20,style:{position:"absolute",right:"10px",top:"50%",transform:"translateY(-50%)"}})]}),h&&y.length>0&&(0,Y.jsx)("div",{style:{position:"absolute",width:A.current?.offsetWidth,zIndex:1300,backgroundColor:"#fff",border:"1px solid rgba(0, 0, 0, 0.23)",borderRadius:"4px",maxHeight:"300px",overflow:"auto"},children:y.map((e=>(0,Y.jsxs)("div",{onClick:()=>(e=>{d(e),u((t=>({...t,searchInput:e.name}))),m(!1)})(e),style:{padding:"8px 16px",cursor:"pointer",backgroundColor:l?.id===e.id?"rgba(0, 0, 0, 0.04)":"transparent","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.08)"}},children:[(0,Y.jsx)("div",{children:e.name}),(0,Y.jsx)("div",{style:{fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)"},children:e.category.name})]},e.id)))})]}),(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)("label",{htmlFor:"price",style:b,children:"Price ($)"}),(0,Y.jsx)("input",{id:"price",name:"price",type:"number",value:c.price,onChange:p,min:"0",step:"0.01",style:v})]}),(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)("label",{htmlFor:"quantity",style:b,children:"Quantity"}),(0,Y.jsx)("input",{id:"quantity",name:"quantity",type:"number",value:c.quantity,onChange:p,min:"0",style:v})]}),(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)("label",{htmlFor:"size",style:b,children:"Measurement"}),(0,Y.jsx)("input",{id:"size",name:"size",type:"number",value:c.size,onChange:p,min:"0",style:v})]}),(0,Y.jsxs)(j.A,{sx:{mt:2},children:[(0,Y.jsx)("label",{htmlFor:"unit",style:b,children:"Unit"}),(0,Y.jsxs)("select",{id:"unit",name:"unit",value:c.unit,onChange:p,style:{...v,backgroundColor:"transparent",appearance:"auto",height:"40px"},children:[(0,Y.jsx)("option",{value:"",children:"None"}),(0,Y.jsx)("option",{value:"1",children:"Grams (g)"}),(0,Y.jsx)("option",{value:"2",children:"Kilograms (kg)"}),(0,Y.jsx)("option",{value:"3",children:"Milliliters (ml)"}),(0,Y.jsx)("option",{value:"4",children:"Liters (L)"}),(0,Y.jsx)("option",{value:"5",children:"Pieces (pcs)"})]})]}),o&&(0,Y.jsx)(te.A,{severity:"error",sx:{mt:2},children:o})]}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{s(),f()},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",onClick:()=>{l&&i({storeId:n,productId:l.id,price:c.price,quantity:c.quantity,size:c.size||null,measurementUnit:c.unit||null})},disabled:a||!l||!c.price||!c.quantity,children:a?(0,Y.jsx)(g.A,{size:24}):"Add Product"})]})]})})),Ir=()=>{const[e,t]=(0,x.useState)(""),{userProfile:s,setUserProfile:n}=G(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,p]=(0,x.useState)(null),[y,f]=(0,x.useState)(""),[v,b]=(0,x.useState)(""),[I,C]=(0,x.useState)(""),[S,w]=(0,x.useState)(!1),[E,k]=(0,x.useState)(10),[F,D]=(0,x.useState)(1),[L]=(0,x.useState)(10),[$,T]=(0,x.useState)("all"),[R,W]=(0,x.useState)([]),[q,z]=(0,x.useState)(!1),[O,N]=(0,x.useState)(!0);(0,x.useRef)(null),(0,x.useRef)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,xt.T)();t(e.sub)}catch(e){}})()}),[]);const{data:U,isLoading:B}=(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:M,isLoading:_,error:V,refetch:H}=(0,u.I)({queryKey:["storeWithInventory",s?.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:s?.id}),enabled:!!s?.id});(0,x.useEffect)((()=>{M&&M.products&&N(!1)}),[M]);const K=M?.storesByManager&&M.storesByManager[0],Q=K?.inventory?.edges?.map((e=>e.node))||[],Z=M?.products||[],X=x.useMemo((()=>Q.filter((e=>{const t=""===I||e.product?.name?.toLowerCase().includes(I.toLowerCase())||e.product?.description?.toLowerCase().includes(I.toLowerCase()),s=!S||e.quantity<=E,n="all"===$||e.product?.category?.name===$;return t&&s&&n}))),[Q,I,S,E,$]),ee=x.useMemo((()=>X.slice((F-1)*L,F*L)),[X,F,L]);(0,x.useEffect)((()=>{const e=[...new Set(Q.map((e=>e.product?.category?.name||"Uncategorized")).filter(Boolean))].sort();JSON.stringify(e)!==JSON.stringify(R)&&W(e)}),[Q]);const se=(0,Ts.n)({mutationFn:e=>{let{inventoryId:t,price:s,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(s),quantity:parseInt(n,10)})},onSuccess:()=>{H(),o(!1),i(null),b("Inventory item updated successfully"),setTimeout((()=>b("")),3e3)},onError:e=>{f(`Error updating inventory: ${e.message}`)}}),re=(0,Ts.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:()=>{H(),d(!1),i(null),b("Inventory item deleted successfully"),setTimeout((()=>b("")),3e3)},onError:e=>{f(`Error deleting inventory: ${e.message}`)}}),ie=(0,Ts.n)({mutationFn:e=>{let{storeId:t,productId:s,price:n,quantity:r,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(s,10),price:parseFloat(n),quantity:parseInt(r,10),size:i?parseFloat(i):null,measurement_unit:a?parseInt(a,10):null})},onSuccess:()=>{H(),z(!1),b("Product added to inventory successfully"),setTimeout((()=>b("")),3e3)},onError:e=>{f(`Error adding product: ${e.message}`)}}),ae=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||""}},oe=x.memo((e=>{let{searchTerm:t,setSearchTerm:s,filterCategory:n,setFilterCategory:r,lowStockOnly:i,setLowStockOnly:a,lowStockThreshold:o,setLowStockThreshold:l,categories:d}=e;return(0,Y.jsx)(ne.A,{elevation:3,sx:{p:3,mb:4},children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:4,children:(0,Y.jsx)(A.A,{label:"Search Products",variant:"outlined",size:"small",value:t,onChange:e=>s(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,Y.jsx)($s.A,{sx:{mr:1,color:"text.secondary"}})}})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:3,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,size:"small",children:[(0,Y.jsx)(Es.A,{id:"category-select-label",children:"Category"}),(0,Y.jsxs)(ks.A,{labelId:"category-select-label",id:"category-select",value:n,label:"Category",onChange:e=>r(e.target.value),children:[(0,Y.jsx)(ue.A,{value:"all",children:"All Categories"}),d.map((e=>(0,Y.jsx)(ue.A,{value:e,children:e},e)))]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:3,children:(0,Y.jsxs)(Ps.A,{fullWidth:!0,size:"small",children:[(0,Y.jsx)(Es.A,{id:"stock-filter-label",children:"Stock Filter"}),(0,Y.jsxs)(ks.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,Y.jsx)(ue.A,{value:"false",children:"All Items"}),(0,Y.jsx)(ue.A,{value:"true",children:"Low Stock Only"})]})]})}),(0,Y.jsx)(me.Ay,{item:!0,xs:12,md:2,children:(0,Y.jsx)(A.A,{label:"Low Stock Threshold",type:"number",size:"small",value:o,onChange:e=>l(parseInt(e.target.value,10)||0),disabled:!i,fullWidth:!0})})]})})}));return B||_?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Y.jsx)(g.A,{})})}):V?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4},children:(0,Y.jsxs)(te.A,{severity:"error",children:["Error loading inventory data: ",V.message]})})}):(0,Y.jsx)(kn,{children:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Store Inventory Management"}),(0,Y.jsx)(oe,{searchTerm:I,setSearchTerm:C,filterCategory:$,setFilterCategory:T,lowStockOnly:S,setLowStockOnly:w,lowStockThreshold:E,setLowStockThreshold:k,categories:R}),v&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:v}),y&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:y}),(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",children:"Inventory Items"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>z(!0),children:"Add Product"})]}),O?(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,Y.jsx)(g.A,{})}):0===X.length?(0,Y.jsx)(te.A,{severity:"info",sx:{my:2},children:"No inventory items match your filters."}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(ys.A,{component:ne.A,variant:"outlined",children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{}),(0,Y.jsx)(Is.A,{children:"Product"}),(0,Y.jsx)(Is.A,{children:"Category"}),(0,Y.jsx)(Is.A,{children:"Price"}),(0,Y.jsx)(Is.A,{children:"Quantity"}),(0,Y.jsx)(Is.A,{children:"Available"}),(0,Y.jsx)(Is.A,{children:"Listed"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:ee.map((e=>(0,Y.jsxs)(x.Fragment,{children:[(0,Y.jsxs)(bs.A,{sx:{backgroundColor:e?.isAvailable?"inherit":"rgba(255, 0, 0, 0.1)"},children:[(0,Y.jsx)(Is.A,{children:(0,Y.jsx)(ce.A,{size:"small",onClick:()=>{return t=e.id,void p(c===t?null:t);var t},children:c===e.id?(0,Y.jsx)(Tn.A,{}):(0,Y.jsx)(Rn.A,{})})}),(0,Y.jsx)(Is.A,{children:(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center"},children:[e.product?.image&&(0,Y.jsx)(pe.A,{component:"img",sx:{width:50,height:50,objectFit:"contain",mr:2},image:e.product.image,alt:e.product.name}),(0,Y.jsx)(h.A,{children:e.product?.name})]})}),(0,Y.jsx)(Is.A,{children:e.product?.category?.name||"Uncategorized"}),(0,Y.jsxs)(Is.A,{children:["$",e.price.toFixed(2)]}),(0,Y.jsxs)(Is.A,{children:[e.quantity," ",e.measurement?ae(e.measurement):""]}),(0,Y.jsx)(Is.A,{children:e?.isAvailable?(0,Y.jsx)(Se.A,{label:"In Stock",color:"success",size:"small"}):(0,Y.jsx)(Se.A,{label:"Low Stock",color:"error",size:"small"})}),(0,Y.jsx)(Is.A,{children:e?.isListed?(0,Y.jsx)(Se.A,{label:"Listed",color:"success",size:"small"}):(0,Y.jsx)(Se.A,{label:"Not Listed",color:"error",size:"small"})}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{onClick:()=>(e=>{e&&(i(e),o(!0))})(e),size:"small",color:"primary",children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{onClick:()=>(e=>{i(e),d(!0)})(e),size:"small",color:"error",children:(0,Y.jsx)(Os.A,{})})]})]}),(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{sx:{p:0},colSpan:7,children:(0,Y.jsx)(Dn.A,{in:c===e.id,timeout:"auto",unmountOnExit:!0,children:(0,Y.jsx)(j.A,{sx:{p:3,backgroundColor:"rgba(0, 0, 0, 0.03)"},children:(0,Y.jsxs)(me.Ay,{container:!0,spacing:2,children:[(0,Y.jsxs)(me.Ay,{item:!0,xs:12,md:6,children:[(0,Y.jsxs)(h.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,Y.jsx)("strong",{children:"Description:"})," ",e.product?.description||"No description available"]}),(0,Y.jsxs)(h.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,Y.jsx)("strong",{children:"Product ID:"})," ",e.product?.id]})]}),(0,Y.jsxs)(me.Ay,{item:!0,xs:12,md:6,children:[(0,Y.jsxs)(h.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,Y.jsx)("strong",{children:"Last Updated:"})," ",e.updatedAt?new Date(e.updatedAt).toLocaleString():"N/A"]}),(0,Y.jsxs)(h.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,Y.jsx)("strong",{children:"Measurement:"})," ",e.measurement?`${e.measurement} ${ae(e.measurement)}`:"N/A"]})]})]})})})})})]},e.id)))})]})}),(0,Y.jsx)(j.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,Y.jsx)(fr.A,{count:Math.ceil(X.length/L),page:F,onChange:(e,t)=>D(t),color:"primary"})})]})]}),(0,Y.jsx)(vr,{open:a,onClose:()=>{o(!1),f("")},selectedItem:r,onUpdate:e=>se.mutate(e),isLoading:se.isLoading}),(0,Y.jsxs)(Fe.A,{open:l,onClose:()=>{d(!1),f("")},maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:"Delete Inventory Item"}),(0,Y.jsxs)(Le.A,{children:[r&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h.A,{variant:"body1",gutterBottom:!0,children:"Are you sure you want to delete this inventory item?"}),(0,Y.jsxs)(j.A,{sx:{display:"flex",alignItems:"center",mt:2},children:[r.product?.image&&(0,Y.jsx)(pe.A,{component:"img",sx:{width:80,height:80,objectFit:"contain",mr:2},image:r.product.image,alt:r.product.name}),(0,Y.jsxs)(j.A,{children:[(0,Y.jsx)(h.A,{variant:"subtitle1",children:(0,Y.jsx)("strong",{children:r.product?.name})}),(0,Y.jsxs)(h.A,{variant:"body2",color:"text.secondary",children:["Quantity: ",r.quantity]}),(0,Y.jsxs)(h.A,{variant:"body2",color:"text.secondary",children:["Price: $",r.price.toFixed(2)]})]})]})]}),y&&(0,Y.jsx)(te.A,{severity:"error",sx:{mt:2},children:y})]}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{d(!1),f("")},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"error",onClick:()=>re.mutate({inventoryId:r.id}),disabled:re.isLoading,children:re.isLoading?(0,Y.jsx)(g.A,{size:24}):"Delete"})]})]}),(0,Y.jsx)(br,{open:q,onClose:()=>z(!1),storeId:K?.id,availableProducts:Z,onAdd:ie.mutate,isLoading:ie.isLoading,errorMessage:y})]})})},Cr=e=>{let{open:t,onClose:s,selectedLocationCode:n,onUpdate:r,isLoading:i,existingCodes:a}=e;const[o,l]=(0,x.useState)({location:"",code:""}),[d,c]=(0,x.useState)("");(0,x.useEffect)((()=>{l(n?{location:n.location||"",code:n.code||""}:{location:"",code:""}),c("")}),[n,t]);const u=()=>{l({location:"",code:""}),c(""),s()},h=e=>{const{name:t,value:s}=e.target;l((e=>({...e,[t]:s}))),c("")};return(0,Y.jsxs)(Fe.A,{open:t,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:n?"Edit Location Code":"Add New Location Code"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(j.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Y.jsx)(A.A,{name:"location",label:"Location",value:o.location,onChange:h,fullWidth:!0,placeholder:"e.g., Main Branch",error:!!d&&d.includes("Location"),helperText:d&&d.includes("Location")?d:""}),(0,Y.jsx)(A.A,{name:"code",label:"Code",value:o.code,onChange:h,fullWidth:!0,placeholder:"e.g., MB001",error:!!d&&(d.includes("Code")||d.includes("already exists")),helperText:d&&(d.includes("Code")||d.includes("already exists"))?d:""})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:u,children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{(o.location.trim()?o.code.trim()?!a.some((e=>e.code.toLowerCase()===o.code.toLowerCase()&&(!n||e.id!==n.id)))||(c("This code already exists for this store"),0):(c("Code is required"),0):(c("Location is required"),0))&&r({id:n?.id,...o})},disabled:i,startIcon:i?(0,Y.jsx)(g.A,{size:20}):null,children:i?"Saving...":"Save"})]})]})},Sr=()=>{const[e,t]=(0,x.useState)(""),{userProfile:s,setUserProfile:n}=G(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,A]=(0,x.useState)(""),[p,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,xt.T)();t(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:v}=(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:b,isLoading:I,error:C}=(0,u.I)({queryKey:["storeWithLocationCodes",s?.id],queryFn:()=>P("\n query GetStoreWithLocationCodes($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:s?.id}),enabled:!!s?.id}),S=b?.storesByManager&&b.storesByManager[0],{data:w,isLoading:E,error:k,refetch:F}=(0,u.I)({queryKey:["getStoreLocationCodesByStore",S?.id],queryFn:()=>P("\n query GetStoreLocationCodesByStore($storeId: Int!) {\n getStoreLocationCodesByStore(storeId: $storeId) {\n id\n location\n code\n }\n }\n",{storeId:S?.id}),enabled:!!S?.id}),D=w?.getStoreLocationCodesByStore||[],L=(0,Ts.n)({mutationFn:e=>P("\n mutation UpdateStoreLocationCode($input: UpdateStoreLocationCodeInput!) {\n updateStoreLocationCode(input: $input) {\n locationCode {\n id\n location\n code\n }\n error {\n message\n }\n }\n }\n",{input:{...e,storeId:S.id}}),onSuccess:()=>{F(),o(!1),i(null),y("Location code updated successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error updating location code: ${e.message}`)}}),$=(0,Ts.n)({mutationFn:e=>P("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{F(),d(!1),i(null),y("Location code deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error deleting location code: ${e.message}`)}}),T=(0,Ts.n)({mutationFn:e=>P("\n mutation CreateStoreLocationCode($input: CreateStoreLocationCodeInput!) {\n createStoreLocationCode(input: $input) {\n locationCode {\n id\n location\n code\n }\n error {\n message\n }\n }\n }\n",{input:{...e,storeId:S.id}}),onSuccess:()=>{F(),o(!1),i(null),y("Location code added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error adding location code: ${e.message}`)}});return v||I||E?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Y.jsx)(g.A,{})})}):C||k?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4},children:(0,Y.jsxs)(te.A,{severity:"error",children:["Error loading data: ",C?.message||k?.message]})})}):(0,Y.jsx)(kn,{children:(0,Y.jsxs)(m.A,{children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),p&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:p}),c&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:c}),(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",children:"Location Codes"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>{i(null),o(!0)},children:"Add Location Code"})]}),0===D.length?(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Location"}),(0,Y.jsx)(Is.A,{children:"Code"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:(0,Y.jsx)(bs.A,{children:(0,Y.jsx)(Is.A,{colSpan:3,align:"center",children:(0,Y.jsx)(te.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})}):(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Location"}),(0,Y.jsx)(Is.A,{children:"Code"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:D.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.location}),(0,Y.jsx)(Is.A,{children:e.code}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",children:(0,Y.jsx)(Os.A,{})})]})]},e.id)))})]})})]}),(0,Y.jsx)(Cr,{open:a,onClose:()=>{o(!1),i(null),A("")},selectedLocationCode:r,onUpdate:e=>{r?L.mutate(e):T.mutate(e)},isLoading:L.isLoading||T.isLoading,existingCodes:D}),(0,Y.jsxs)(Fe.A,{open:l,onClose:()=>{d(!1),i(null),A("")},children:[(0,Y.jsx)(De.A,{children:"Delete Location Code"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{d(!1),i(null)},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isLoading,children:$.isLoading?(0,Y.jsx)(g.A,{size:24}):"Delete"})]})]})]})})},wr=e=>{let{open:t,onClose:s,selectedPickupAddress:n,onUpdate:r,isLoading:i,existingAddresses:a}=e;const[o,l]=(0,x.useState)({address:""}),[d,c]=(0,x.useState)(""),[u,m]=(0,x.useState)(!1);(0,x.useEffect)((()=>{n?(l({address:n.address||""}),m(!0)):(l({address:""}),m(!1)),c("")}),[n]);return(0,Y.jsxs)(Fe.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,children:[(0,Y.jsx)(De.A,{children:n?"Edit Pickup Address":"Add New Pickup Address"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsxs)(j.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Y.jsx)(Ht,{value:o.address,onChange:e=>{l((t=>({...t,address:e}))),c("")},onValidAddress:m}),d&&(0,Y.jsx)(h.A,{color:"error",variant:"caption",children:d})]})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:s,children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",onClick:()=>{(o.address.trim()?u?!a.some((e=>e.address.toLowerCase()===o.address.toLowerCase()&&(!n||e.id!==n.id)))||(c("This address already exists for this store"),0):(c("Please select a valid address from the suggestions"),0):(c("Address is required"),0))&&r({id:n?.id,...o})},disabled:i||!u,startIcon:i?(0,Y.jsx)(g.A,{size:20}):null,children:i?"Saving...":"Save"})]})]})},Pr=()=>{const[e,t]=(0,x.useState)(""),{userProfile:s,setUserProfile:n}=G(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,A]=(0,x.useState)(""),[p,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,xt.T)();t(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:v}=(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:b,isLoading:I,error:C}=(0,u.I)({queryKey:["storeWithPickupAddresses",s?.id],queryFn:()=>P("\n query GetStoreWithPickupAddresses($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:s?.id}),enabled:!!s?.id}),S=b?.storesByManager&&b.storesByManager[0],{data:w,isLoading:E,error:k,refetch:F}=(0,u.I)({queryKey:["getPickupAddressesByStore",S?.id],queryFn:()=>P("\n query GetPickupAddressesByStore($storeId: Int!) {\n getPickupAddressesByStore(storeId: $storeId) {\n id\n storeId\n address\n }\n }\n",{storeId:S?.id}),enabled:!!S?.id}),D=w?.getPickupAddressesByStore||[],L=(0,Ts.n)({mutationFn:e=>P("\n mutation UpdatePickupAddress($input: UpdatePickupAddressInput!) {\n updatePickupAddress(input: $input) {\n pickupAddress {\n id\n storeId\n address\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:()=>{F(),o(!1),i(null),y("Pickup address updated successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error updating pickup address: ${e.message}`)}}),$=(0,Ts.n)({mutationFn:e=>P("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{F(),d(!1),i(null),y("Pickup address deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error deleting pickup address: ${e.message}`)}}),T=(0,Ts.n)({mutationFn:e=>P("\n mutation CreatePickupAddress($input: PickupAddressInput!) {\n createPickupAddress(input: $input) {\n pickupAddress {\n id\n storeId\n address\n }\n error {\n message\n }\n }\n }\n",{input:{...e,storeId:S.id}}),onSuccess:()=>{F(),o(!1),i(null),y("Pickup address added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{A(`Error adding pickup address: ${e.message}`)}});return v||I||E?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Y.jsx)(g.A,{})})}):C||k?(0,Y.jsx)(kn,{children:(0,Y.jsx)(m.A,{sx:{mt:4},children:(0,Y.jsxs)(te.A,{severity:"error",children:["Error loading data: ",C?.message||k?.message]})})}):(0,Y.jsx)(kn,{children:(0,Y.jsxs)(m.A,{children:[(0,Y.jsx)(h.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),p&&(0,Y.jsx)(te.A,{severity:"success",sx:{mb:2},children:p}),c&&(0,Y.jsx)(te.A,{severity:"error",sx:{mb:2},children:c}),(0,Y.jsxs)(ne.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Y.jsxs)(j.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Y.jsx)(h.A,{variant:"h5",children:"Pickup Addresses"}),(0,Y.jsx)(J.A,{variant:"contained",color:"primary",startIcon:(0,Y.jsx)(ve.A,{}),onClick:()=>{i(null),o(!0)},children:"Add Pickup Address"})]}),0===D.length?(0,Y.jsx)(te.A,{severity:"info",sx:{my:2},children:"No pickup addresses found. Add your first pickup address to get started."}):(0,Y.jsx)(ys.A,{children:(0,Y.jsxs)(fs.A,{children:[(0,Y.jsx)(vs.A,{children:(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:"Address"}),(0,Y.jsx)(Is.A,{children:"Actions"})]})}),(0,Y.jsx)(Cs.A,{children:D.map((e=>(0,Y.jsxs)(bs.A,{children:[(0,Y.jsx)(Is.A,{children:e.address}),(0,Y.jsxs)(Is.A,{children:[(0,Y.jsx)(ce.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",children:(0,Y.jsx)(Ls.A,{})}),(0,Y.jsx)(ce.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",children:(0,Y.jsx)(Os.A,{})})]})]},e.id)))})]})})]}),(0,Y.jsx)(wr,{open:a,onClose:()=>{o(!1),i(null),A("")},selectedPickupAddress:r,onUpdate:e=>{r?L.mutate(e):T.mutate(e)},isLoading:L.isLoading||T.isLoading,existingAddresses:D}),(0,Y.jsxs)(Fe.A,{open:l,onClose:()=>{d(!1),i(null),A("")},children:[(0,Y.jsx)(De.A,{children:"Delete Pickup Address"}),(0,Y.jsx)(Le.A,{children:(0,Y.jsx)(h.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,Y.jsxs)(Fs.A,{children:[(0,Y.jsx)(J.A,{onClick:()=>{d(!1),i(null)},children:"Cancel"}),(0,Y.jsx)(J.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isLoading,children:$.isLoading?(0,Y.jsx)(g.A,{size:24}):"Delete"})]})]})]})})},Er=()=>{const{user:e}=G();return(0,Y.jsxs)(o.A,{theme:c,children:[(0,Y.jsx)(l.Ay,{}),(0,Y.jsxs)(d.BV,{children:[(0,Y.jsx)(d.qh,{path:Je,element:(0,Y.jsx)(Gn,{})}),(0,Y.jsx)(d.qh,{path:at,element:(0,Y.jsx)(ss,{})}),(0,Y.jsx)(d.qh,{path:Ze,element:(0,Y.jsx)(It,{})}),(0,Y.jsx)(d.qh,{path:"/",element:(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsx)(es,{children:(0,Y.jsx)(Qn,{})})})}),(0,Y.jsx)(d.qh,{path:ot,element:(0,Y.jsx)(es,{children:(0,Y.jsx)(ir,{})})}),(0,Y.jsx)(d.qh,{path:`${Xe}/*`,element:(0,Y.jsx)(ts,{role:"admin",children:(0,Y.jsx)(fn,{})})}),(0,Y.jsx)(d.qh,{path:et,element:(0,Y.jsx)(ts,{role:"user",children:(0,Y.jsx)(Qn,{})})}),(0,Y.jsx)(d.qh,{path:tt,element:(0,Y.jsx)(ts,{role:"delivery_agent",children:(0,Y.jsx)(Cn,{})})}),(0,Y.jsx)(d.qh,{path:rt,element:(0,Y.jsx)(ts,{role:"user",children:(0,Y.jsx)(zn,{})})}),(0,Y.jsx)(d.qh,{path:it,element:(0,Y.jsx)(ts,{children:(0,Y.jsx)(Un,{})})}),(0,Y.jsx)(d.qh,{path:st,element:(0,Y.jsx)(ts,{role:"store_manager",children:(0,Y.jsx)(Fn,{})})}),(0,Y.jsx)(d.qh,{path:`${st}/orders`,element:(0,Y.jsx)(ts,{role:"store_manager",children:(0,Y.jsx)(pr,{})})}),(0,Y.jsx)(d.qh,{path:"/store_manager/delivery-partners",element:(0,Y.jsx)(ts,{role:"store_manager",children:(0,Y.jsx)(yr,{})})}),(0,Y.jsx)(d.qh,{path:"/store_manager/inventory",element:(0,Y.jsx)(ts,{role:"store_manager",children:(0,Y.jsx)(Ir,{})})}),(0,Y.jsx)(d.qh,{path:"/store_manager/delivery-fees",element:(0,Y.jsx)(ts,{role:"store_manager",children:(0,Y.jsx)(Vn,{})})}),(0,Y.jsx)(d.qh,{path:"/store_manager/location-codes",element:(0,Y.jsx)(ts,{role:"store_manager",children:(0,Y.jsx)(Sr,{})})}),(0,Y.jsx)(d.qh,{path:"/store_manager/pickup-addresses",element:(0,Y.jsx)(ts,{role:"store_manager",children:(0,Y.jsx)(Pr,{})})}),(0,Y.jsx)(d.qh,{path:`${st}/*`,element:(0,Y.jsx)(ts,{role:"store_manager",children:(0,Y.jsx)(Mn,{})})}),(0,Y.jsx)(d.qh,{path:"*",element:(0,Y.jsx)(Bn,{})})]})]})};var kr=s(85072),Fr=s.n(kr),Dr=s(97825),Lr=s.n(Dr),$r=s(77659),Tr=s.n($r),Rr=s(55056),Wr=s.n(Rr),qr=s(10540),zr=s.n(qr),Or=s(41113),Nr=s.n(Or),Ur=s(14767),Br={};Br.styleTagTransform=Nr(),Br.setAttributes=Wr(),Br.insert=Tr().bind(null,"head"),Br.domAPI=Lr(),Br.insertStyleElement=zr();Fr()(Ur.A,Br);Ur.A&&Ur.A.locals&&Ur.A.locals;const Mr=window.location.href?.includes("http://localhost");let _r="us-east-1_6NtAulnkj",Vr="1361ghg1fpt2grmchv7ttf8bbj";Mr&&(_r="us-east-1_ehhI7OmUk",Vr="1okaltgd288h6sjgc5cedlth45");const Gr={Auth:{Cognito:{region:"us-east-1",userPoolId:_r,userPoolClientId:Vr,loginWith:{email:!0},signUpVerificationMethod:"code",userAttributes:{email:{required:!0}},allowGuestAccess:!0,passwordFormat:{minLength:8,requireLowercase:!0,requireUppercase:!0,requireNumbers:!0,requireSpecialCharacters:!0}}}};s(9023).E.configure(Gr);const Hr=new i.E({defaultOptions:{queries:{retry:3,refetchOnWindowFocus:!1},mutations:{retry:0}}});(0,n.createRoot)(document.getElementById("root")).render((0,Y.jsx)(a.Ht,{client:Hr,children:(0,Y.jsx)(r.Kd,{children:(0,Y.jsx)(Er,{})})}))},14767:(e,t,s)=>{s.d(t,{A:()=>o});var n=s(71354),r=s.n(n),i=s(76314),a=s.n(i)()(r());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 o=a}},a={};function o(e){var t=a[e];if(void 0!==t)return t.exports;var s=a[e]={id:e,exports:{}};return i[e].call(s.exports,s,s.exports,o),s.exports}o.m=i,e=[],o.O=(t,s,n,r)=>{if(!s){var i=1/0;for(c=0;c=r)&&Object.keys(o.O).every((e=>o.O[e](s[l])))?s.splice(l--,1):(a=!1,r0&&e[c-1][2]>r;c--)e[c]=e[c-1];e[c]=[s,n,r]},o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},s=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,o.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 r=Object.create(null);o.r(r);var i={};t=t||[null,s({}),s([]),s(s)];for(var a=2&n&&e;"object"==typeof a&&!~t.indexOf(a);a=s(a))Object.getOwnPropertyNames(a).forEach((t=>i[t]=()=>e[t]));return i.default=()=>e,o.d(r,i),r},o.d=(e,t)=>{for(var s in t)o.o(t,s)&&!o.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce(((t,s)=>(o.f[s](e,t),t)),[])),o.u=e=>"bundle."+{354:"f07ebc5e191c17036f0a",418:"f754bb6fc8d3e0eddb47",661:"e6dbe64eea25e53717de"}[e]+".js",o.miniCssF=e=>{},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n={},r="indimitra-web:",o.l=(e,t,s,i)=>{if(n[e])n[e].push(t);else{var a,l;if(void 0!==s)for(var d=document.getElementsByTagName("script"),c=0;c{a.onerror=a.onload=null,clearTimeout(h);var r=n[e];if(delete n[e],a.parentNode&&a.parentNode.removeChild(a),r&&r.forEach((e=>e(s))),t)return t(s)},h=setTimeout(u.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=u.bind(null,a.onerror),a.onload=u.bind(null,a.onload),l&&document.head.appendChild(a)}},o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.p="/",(()=>{var e={792:0};o.f.j=(t,s)=>{var n=o.o(e,t)?e[t]:void 0;if(0!==n)if(n)s.push(n[2]);else{var r=new Promise(((s,r)=>n=e[t]=[s,r]));s.push(n[2]=r);var i=o.p+o.u(t),a=new Error;o.l(i,(s=>{if(o.o(e,t)&&(0!==(n=e[t])&&(e[t]=void 0),n)){var r=s&&("load"===s.type?"missing":s.type),i=s&&s.target&&s.target.src;a.message="Loading chunk "+t+" failed.\n("+r+": "+i+")",a.name="ChunkLoadError",a.type=r,a.request=i,n[1](a)}}),"chunk-"+t,t)}},o.O.j=t=>0===e[t];var t=(t,s)=>{var n,r,[i,a,l]=s,d=0;if(i.some((t=>0!==e[t]))){for(n in a)o.o(a,n)&&(o.m[n]=a[n]);if(l)var c=l(o)}for(t&&t(s);do(98811)));l=o.O(l)})(); //# sourceMappingURL=bundle.53a75efa50cbbb1ef892.js.map