(()=>{"use strict";var e,s,t,n,r,i={25710:(e,s,t)=>{var n=t(5338),r=t(84976),i=t(15072),a=t(97665),o=t(65793),d=t(14519),l=t(47767);const c=(0,t(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=t(96540),u=t(59270),m=t(14073),h=t(97834),p=t(42471),A=t(25239),g=t(69067),j=t(73357),y=t(93959),f=t(64745),b=t(56908),v=t(10548);const I="undefined"!=typeof window&&window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000/graphql":`${window.location.origin}/graphql`,S=new b.l4(I,{headers:{"Content-Type":"application/json"}}),C=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const t=await(async()=>{try{const e=await(0,v.$)(),s=e.tokens?.accessToken?.toString();return s?{Authorization:`Bearer ${s}`}:{}}catch(e){return{}}})();return S.request(e,s,{...S.requestConfig.headers,...t})},w={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."},P=e=>{if(e.response?.errors){return e.response.errors.map((e=>{if(e.extensions?.code){const s=e.extensions.code;if(w[s])return w[s]}return e.message?.includes("Pickup address ID is required for pickup orders")?"Please select a valid address to deliver.":e.message?.includes("validation")?w.VALIDATION_ERROR:e.message?.includes("not found")?"The requested item was not found.":e.message?.includes("permission")?w.FORBIDDEN:e.message?.includes("already exists")?"This item already exists.":e.message||w.GENERIC_ERROR})).join(". ")}if(e.message?.includes("Network request failed"))return w.NETWORK_ERROR;if(e.message?.includes("timeout"))return w.TIMEOUT_ERROR;if(e.response?.status)switch(e.response.status){case 401:return w.UNAUTHENTICATED;case 403:return w.FORBIDDEN;case 404:return"The requested resource was not found.";case 500:return w.INTERNAL_SERVER_ERROR;case 503:return w.SERVICE_UNAVAILABLE;default:return`Server error (${e.response.status}). Please try again.`}return e.message||w.GENERIC_ERROR},k=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{const t=await C(e,s);if(t.errors){const e=P({response:t});throw new Error(e)}return t}catch(e){const s=P(e),t=new Error(s);throw t.originalError=e,t.isGraphQLError=!0,t}},E="query getAllUsers {\n getAllUsers {\n id\n email\n mobile\n type\n cognitoId\n }\n}",F="\n mutation UpdateOrderStatus($input: UpdateOrderStatusInput!) {\n updateOrderStatus(input: $input) {\n id\n status\n deliveryDate\n deliveryInstructions\n }\n }\n",D="\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",L="\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",$="\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",T="\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",q="\n query GetAllStores {\n stores(disabled: false) {\n id\n name\n address\n description\n disabled\n email\n isActive\n managerUserId\n mobile\n pincodes\n radius\n tnc\n storeDeliveryFee\n taxPercentage\n displayField\n sectionHeaders\n images\n codEnabled\n whatsappNumber\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",R="\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 images\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",z="\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",W="\n mutation SaveCart($userId: Int!, $storeId: Int!, $cartData: JSON!) {\n saveCart(userId: $userId, storeId: $storeId, cartData: $cartData) {\n id\n userId\n storeId\n cartData\n updatedAt\n }\n }\n",O="\n mutation DeleteSavedCart($userId: Int!, $storeId: Int!) {\n deleteSavedCart(userId: $userId, storeId: $storeId)\n }\n";var U=t(71511),N=t(87134),B=t(18496);const _="admin",M="user",V="delivery_agent",H="store_manager",G="orders",K="userStatus",Y=e=>(0,B.ms)((s=>{e=e?.toLowerCase().trim(),e===_&&(s("view",_),s("view",K)),e===M&&(s("view",M),s("view",G),s("view","cart")),e===V&&s("view",V),e===H&&(s("view",H),s("manage","inventory"))})),Q=(0,U.v)((0,N.Zr)(((e,s)=>({cart:{},selectedStore:null,availableStores:[],setAvailableStores:s=>e({availableStores:s}),setSelectedStore:t=>{const n=s(),r=n.selectedStore?.id;if(r){const e={cart:n.cart,customOrder:n.customOrder,listInputAnswers:n.listInputAnswers,deliveryType:n.deliveryType,tipAmount:n.tipAmount||0,pickupAddress:n.pickupAddress,deliveryAddressString:n.deliveryAddressString};try{localStorage.setItem(`indimitra-cart-store-${r}`,JSON.stringify(e))}catch(e){}}const i=t?.id;let a=null;if(i)try{const e=localStorage.getItem(`indimitra-cart-store-${i}`);e&&(a=JSON.parse(e))}catch(e){}e({selectedStore:t,cart:a?.cart||{},customOrder:a?.customOrder||"",listInputAnswers:a?.listInputAnswers||{},deliveryType:a?.deliveryType||"pickup",tipAmount:a?.tipAmount||0,pickupAddress:a?.pickupAddress||null,deliveryAddressString:a?.deliveryAddressString||null})},getSelectedStore:()=>s().selectedStore,pickupAddress:null,setPickupAddress:s=>e({pickupAddress:s}),deliveryAddressString:null,setDeliveryAddressString:s=>e({deliveryAddressString:s}),deliveryType:"pickup",setDeliveryType:s=>e({deliveryType:s}),addToCart:s=>e((e=>({cart:{...e.cart,[s.id]:{...e.cart[s.id]||s,quantity:(e.cart[s.id]?.quantity||0)+1}}}))),removeFromCart:s=>e((e=>{if(!e.cart[s])return e;const t={...e.cart};return t[s].quantity>1?t[s].quantity-=1:delete t[s],{cart:t}})),cartCount:()=>{const e=s();return Object.values(e.cart).reduce(((e,s)=>e+(s.quantity||0)),0)+(e.customOrder?1:0)},cartTotal:()=>Object.values(s().cart).reduce(((e,s)=>e+(s?.price||0)*(s?.quantity||0)),0),clearCart:()=>e({cart:{}}),calculateDeliveryFee:(e,s,t)=>{if(!s||!s.fees||!s.fees.edges||0===s.fees.edges.length)return 0;const n=s.fees.edges.map((e=>e.node)).filter((e=>e.type===t.toUpperCase()));if(0===n.length)return 0;const r=n.sort(((e,s)=>e.limit-s.limit));let i=null;for(const s of r)if(e<=s.limit){i=s;break}if(!i&&r.length>0&&(i=r[r.length-1]),!i)return 0;return i.feeRate},getCartTotals:()=>{const e=s(),t=e.cart,n=e.selectedStore,r=e.deliveryType,i=Object.values(t).reduce(((e,s)=>e+(s.price*s.quantity||0)),0),a=s().calculateDeliveryFee(i,n,r),o=n?.taxPercentage||0,d=i*o/100,l=e.tipAmount||0;return{subtotal:i,deliveryFee:a,taxAmount:d,taxPercentage:o,tipAmount:l,total:i+a+d+l}},setTipAmount:s=>e({tipAmount:s}),customOrder:"",setCustomOrder:s=>e({customOrder:s}),listInputAnswers:{},setListInputAnswers:s=>e({listInputAnswers:s}),restoreCart:s=>{s&&e({...void 0!==s.cart&&{cart:s.cart},...void 0!==s.customOrder&&{customOrder:s.customOrder},...void 0!==s.listInputAnswers&&{listInputAnswers:s.listInputAnswers},...void 0!==s.deliveryType&&{deliveryType:s.deliveryType},...void 0!==s.tipAmount&&{tipAmount:s.tipAmount},...void 0!==s.pickupAddress&&{pickupAddress:s.pickupAddress}})},getCartState:()=>{const e=s();return{cart:e.cart,customOrder:e.customOrder,listInputAnswers:e.listInputAnswers,deliveryType:e.deliveryType,tipAmount:e.tipAmount||0,pickupAddress:e.pickupAddress,deliveryAddressString:e.deliveryAddressString}}})),{name:"indimitra-cart-storage",storage:(0,N.KU)((()=>localStorage)),partialize:e=>({cart:e.cart,customOrder:e.customOrder,listInputAnswers:e.listInputAnswers,deliveryType:e.deliveryType,tipAmount:e.tipAmount,pickupAddress:e.pickupAddress,deliveryAddressString:e.deliveryAddressString})})),J=(0,U.v)(((e,s)=>({user:null,userProfile:null,ability:null,isProfileLoading:!1,profileError:null,modalOpen:!1,currentForm:"login",setAbility:s=>{e({ability:s})},setUser:s=>{e({user:s})},setUserProfile:s=>{if(!s)return;const t=JSON.parse(JSON.stringify(s));e((e=>({...e,userProfile:t})))},setModalOpen:s=>{e({modalOpen:s})},getUserProfile:()=>s().userProfile,setCurrentForm:s=>{e({currentForm:s})},setAbility:s=>e({ability:s}),logout:()=>{e({user:null,userProfile:null,ability:Y(null)})},fetchUserProfile:async s=>{if(s){e({isProfileLoading:!0});try{const t=await k(D,{userId:s});if(t.errors)return void e({isProfileLoading:!1});const n=t.getUserProfile||t.data?.getUserProfile;if(!n)return void e({isProfileLoading:!1});e({userProfile:n,isProfileLoading:!1,ability:Y(n.role)})}catch(s){e({isProfileLoading:!1})}}},isProfileLoaded:()=>!!s().userProfile}))),Z=(0,U.v)(((e,s)=>({addresses:[],isLoading:!1,error:null,selectedAddressId:null,setSelectedAddressId:s=>e({selectedAddressId:s}),fetchAddresses:async t=>{if(!t)return[];e({isLoading:!0,error:null});try{const n="string"==typeof t?parseInt(t,10):t,r=await k("\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&&!s().selectedAddressId?i[0].id:s().selectedAddressId}),i}catch(s){return e({error:s.message||"Failed to fetch addresses",isLoading:!1}),[]}},createAddress:async function(s,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!t||!s)return null;e({isLoading:!0,error:null});try{const r="string"==typeof t?parseInt(t,10):t,i=await k("\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:s,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(s){return e({error:s.message||"Failed to create address",isLoading:!1}),null}},updateAddress:async(s,t,n)=>{if(!s)return null;e({isLoading:!0,error:null});try{const r=await k("\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:s,address:t,isPrimary:n});if(r?.updateAddress)return e((e=>({addresses:e.addresses.map((e=>e.id===s?r.updateAddress:e)),isLoading:!1}))),r.updateAddress;throw new Error("Failed to update address")}catch(s){return e({error:s.message||"Failed to update address",isLoading:!1}),null}},deleteAddress:async s=>{if(!s)return!1;e({isLoading:!0,error:null});try{const t=await k("\n mutation DeleteAddress($addressId: Int!) {\n deleteAddress(addressId: $addressId)\n }\n",{addressId:s});if(t?.deleteAddress)return e((e=>({addresses:e.addresses.filter((e=>e.id!==s)),isLoading:!1,selectedAddressId:e.selectedAddressId===s?null:e.selectedAddressId}))),!0;throw new Error("Failed to delete address")}catch(s){return e({error:s.message||"Failed to delete address",isLoading:!1}),!1}},getSelectedAddress:()=>{const{addresses:e,selectedAddressId:t}=s();return e.find((e=>e.id===t))||null}}))),X=Q;var ee=t(74848);const se=e=>(0,ee.jsx)(g.A,{...e});var te=t(86990);const ne=e=>(0,ee.jsx)(te.A,{...e}),re=e=>(0,ee.jsx)(p.A,{...e}),ie=e=>(0,ee.jsx)(m.A,{...e});var ae=t(89502);const oe=e=>(0,ee.jsx)(ae.A,{...e});var de=t(60538);const le=e=>(0,ee.jsx)(de.A,{...e}),ce=e=>{let{size:s=40,thickness:t=3.6,sx:n={}}=e;return(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",...n},children:(0,ee.jsx)(j.A,{size:s,thickness:t})})};var xe=t(50790),ue=t(29898);const me=e=>{let{fields:s,onSubmit:t,buttonLabel:n,loading:r,error:i,success:a}=e;const o=e=>{switch(e){case"email":return(0,ee.jsx)(xe.A,{sx:{color:"#FF6B6B"}});case"password":return(0,ee.jsx)(ue.A,{sx:{color:"#FF6B6B"}});default:return null}};return(0,ee.jsxs)("form",{onSubmit:t,children:[s.map(((e,s)=>(0,ee.jsx)(re,{label:e.label,type:e.type,fullWidth:!0,margin:"normal",value:e.value,onChange:s=>e.onChange(s.target.value),required:!0,InputProps:{startAdornment:e.type&&(0,ee.jsx)(A.A,{position:"start",children:o(e.type)})}},s))),i&&(0,ee.jsx)(oe,{severity:"error",sx:{mt:2},children:i}),a&&(0,ee.jsx)(oe,{severity:"success",sx:{mt:2},children:a}),(0,ee.jsx)(ne,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:r,sx:{mt:2},children:r?(0,ee.jsx)(ce,{size:24,sx:{color:"#fff"}}):n})]})},he=e=>(0,ee.jsx)(h.A,{...e});var pe=t(11641);const Ae=e=>(0,ee.jsx)(pe.A,{...e});var ge=t(73896);const je=e=>(0,ee.jsx)(ge.A,{...e});var ye=t(8239),fe=t(14977),be=t(87393),ve=t(37636),Ie=t(56826),Se=t(47839),Ce=t(1649),we=t(99682),Pe=t(11235);const ke={"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 Ee=t(44675),Fe=t(82022);const De=e=>{let{categoryName:s}=e;return s?(0,ee.jsx)(Fe.A,{label:s,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},Le="grey",$e=e=>{let{product:s}=e;(0,Ee.A)();const{cart:t,addToCart:n,removeFromCart:r}=X(),{id:i,name:a,price:o,description:d,image:l,categoryName:c,isAvailable:x}=s,u=t[i]?.quantity||0,h=l||(c?(e=>{if(e&&ke[e.toLowerCase()]){const s=ke[e.toLowerCase()];return s[Math.floor(Math.random()*s.length)]}return ke.default})(c):"https://picsum.photos/200");return(0,ee.jsxs)(fe.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,ee.jsx)(De,{categoryName:c}),(0,ee.jsx)(be.A,{component:"img",height:"140",image:h,alt:a,sx:{padding:"10px 0 0 0",objectFit:"contain",transition:"transform 0.5s","&:hover":{transform:"scale(1.05)"}}}),!x&&(0,ee.jsx)(g.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,ee.jsx)(m.A,{variant:"body1",children:"Sold out"})}),(0,ee.jsxs)(ve.A,{sx:{flexGrow:1,p:2.5,pb:0,display:"flex",flexDirection:"column"},children:[(0,ee.jsx)(m.A,{gutterBottom:!0,variant:"h6",sx:{fontWeight:600,fontSize:"1.1rem",mb:1,lineHeight:1.3},children:a}),d&&(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1.5,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:"0.85rem",lineHeight:1.4},children:d}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:"auto",mb:2},children:[(0,ee.jsxs)(m.A,{variant:"h6",sx:{fontWeight:700,color:"primary.main",fontSize:"1.2rem"},children:["$",o.toFixed(2)]}),void 0!==s.quantity&&(0,ee.jsxs)(m.A,{variant:"body2",color:"text.secondary",sx:{ml:2,fontWeight:500},children:["Qty: ",s.quantity]})]})]}),(0,ee.jsx)(Ie.A,{sx:{justifyContent:"center",pb:2.5,px:2.5},children:u>0?(0,ee.jsxs)(g.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,ee.jsx)(Se.A,{title:"Remove from cart",children:(0,ee.jsx)(pe.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,ee.jsx)(Ce.A,{fontSize:"small"})})}),(0,ee.jsx)(m.A,{variant:"body1",sx:{color:"#FF6B6B",fontWeight:700,mx:2,minWidth:"24px",textAlign:"center",fontSize:"1.1rem"},children:u}),(0,ee.jsx)(Se.A,{title:"Add to cart",children:(0,ee.jsx)(pe.A,{onClick:()=>n(s),sx:{color:"#FF6B6B",p:1,"&:hover":{backgroundColor:"rgba(255, 107, 107, 0.2)",transform:"scale(1.1)"},transition:"all 0.2s ease"},children:(0,ee.jsx)(we.A,{fontSize:"small"})})})]}):(0,ee.jsx)(te.A,{size:"medium",sx:{width:"100%",height:"48px",background:"transparent",color:x?"#FF6B6B":Le,borderRadius:"8px",fontWeight:600,fontSize:"0.95rem",textTransform:"none",position:"relative",overflow:"hidden",border:`2px solid ${x?"#FF6B6B":Le}`,transition:"all 0.2s ease","&:hover":{background:"transparent","& .MuiButton-startIcon":{transform:"translateX(2px)"}},"& .MuiButton-startIcon":{transition:"transform 0.2s ease",marginRight:"8px"}},startIcon:(0,ee.jsx)(Pe.A,{sx:{fontSize:"1.1rem"}}),onClick:()=>n(s),disabled:!x,children:x?"Add to Cart":"Unavailable"})})]})},Te=e=>{let{products:s,title:t}=e;return 0===s.length?(0,ee.jsx)(g.A,{sx:{py:8,textAlign:"center"},children:(0,ee.jsx)(m.A,{variant:"h6",color:"text.secondary",children:"No products available."})}):(0,ee.jsxs)(h.A,{maxWidth:"xl",children:[t&&(0,ee.jsx)(m.A,{variant:"h5",sx:{mb:4,fontWeight:600,position:"relative",display:"inline-block","&:after":{content:'""',position:"absolute",bottom:-8,left:0,width:"40%",height:"3px",background:"linear-gradient(45deg, #FF6B6B, #FFA07A)",borderRadius:"3px"}},children:t}),(0,ee.jsx)(ye.Ay,{container:!0,spacing:3,children:s.map((e=>(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,ee.jsx)($e,{product:e})},e.id)))})]})};var qe=t(58031),Re=t(46831),ze=t(22477),We=t(58763),Oe=t(39781);const Ue=e=>{let{open:s,onClose:t,children:n,title:r,footer:i,...a}=e;const o=(0,Ee.A)();return(0,ee.jsxs)(qe.A,{open:s,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:3,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.12)",height:"60vh",maxHeight:"60vh",display:"flex",flexDirection:"column"}},...a,children:[r&&(0,ee.jsxs)(Re.A,{sx:{textAlign:"center",background:o.palette.custom.gradientPrimary,color:"white",py:2,position:"relative",flexShrink:0},children:[r,(0,ee.jsx)(pe.A,{"aria-label":"close",onClick:t,sx:{position:"absolute",right:8,top:8,color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},children:(0,ee.jsx)(Oe.A,{})})]}),(0,ee.jsx)(ze.A,{sx:{flex:1,overflowY:"auto",py:2,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-thumb":{backgroundColor:"rgba(0,0,0,0.15)",borderRadius:3}},children:n}),i&&(0,ee.jsx)(We.A,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",flexShrink:0},children:i})]})};var Ne=t(8532);const Be=e=>(0,ee.jsx)(Ne.A,{...e,sx:{minHeight:{xs:"64px",sm:"70px"},px:{xs:2,sm:4},...e.sx}}),_e=e=>(0,ee.jsx)(Se.A,{...e,sx:{"& .MuiTooltip-tooltip":{backgroundColor:"rgba(42, 47, 79, 0.9)",fontSize:"0.875rem",borderRadius:"8px",padding:"8px 16px"},...e.sx}});var Me=t(30781);const Ve=e=>(0,ee.jsx)(Me.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 He=t(97190);const Ge=e=>(0,ee.jsx)(He.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 Ke=t(54937);const Ye=e=>{let{error:s,title:t="Error",severity:n="error"}=e;return(0,ee.jsx)(g.A,{sx:{p:2},children:(0,ee.jsxs)(ae.A,{severity:n,children:[(0,ee.jsx)(Ke.A,{sx:{fontWeight:"bold"},children:t}),s]})})};var Qe=t(99631),Je=t(82935),Ze=t(83574);const Xe=e=>{let{images:s=[]}=e;const[t,n]=(0,x.useState)(0),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)("next"),[d,l]=(0,x.useState)(!1),c=(0,x.useRef)(null);if(!s||0===s.length)return(0,ee.jsxs)(de.A,{elevation:2,sx:{position:"relative",width:"100%",height:{xs:120,sm:150,md:180},mb:{xs:2,sm:3},borderRadius:3,overflow:"hidden",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",background:"linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%)"},children:[(0,ee.jsx)(Qe.A,{sx:{fontSize:40,color:"rgba(0,0,0,0.2)",mb:.5}}),(0,ee.jsx)(m.A,{variant:"body2",sx:{color:"rgba(0,0,0,0.35)"},children:"Offers & promotions coming soon"})]});const u=(0,x.useCallback)((()=>{c.current&&clearInterval(c.current),s.length<=1||(c.current=setInterval((()=>{o("next"),l(!0),setTimeout((()=>{n((e=>e===s.length-1?0:e+1)),l(!1)}),300)}),4e3))}),[s.length]);(0,x.useEffect)((()=>(r?c.current&&clearInterval(c.current):u(),()=>{c.current&&clearInterval(c.current)})),[r,u]);return(0,ee.jsx)(de.A,{elevation:2,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),sx:{position:"relative",width:"100%",height:{xs:120,sm:150,md:180},mb:{xs:2,sm:3},borderRadius:3,overflow:"hidden",backgroundColor:"rgba(0, 0, 0, 0.03)","&:hover .slider-arrow":{opacity:1}},children:(0,ee.jsxs)(g.A,{sx:{width:"100%",height:"100%",position:"relative"},children:[(0,ee.jsx)("img",{src:s[t],alt:`Store offer ${t+1}`,style:{width:"100%",height:"100%",objectFit:"cover",transition:"opacity 0.3s ease-in-out, transform 0.3s ease-in-out",opacity:d?0:1,transform:d?`translateX(${"next"===a?"30px":"-30px"})`:"translateX(0)"},onError:e=>{e.target.style.display="none"}}),s.length>1&&(0,ee.jsx)(g.A,{sx:{position:"absolute",bottom:0,left:0,right:0,height:"40px",background:"linear-gradient(transparent, rgba(0,0,0,0.3))",pointerEvents:"none",zIndex:1}}),s.length>1&&(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(pe.A,{className:"slider-arrow",onClick:()=>{o("prev"),l(!0),setTimeout((()=>{n((e=>0===e?s.length-1:e-1)),l(!1)}),300),r||u()},size:"small",sx:{position:"absolute",left:4,top:"50%",transform:"translateY(-50%)",backgroundColor:"rgba(255, 255, 255, 0.5)",opacity:0,transition:"opacity 0.2s ease, background-color 0.2s ease","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.8)"},zIndex:2,p:.5},children:(0,ee.jsx)(Je.A,{fontSize:"small"})}),(0,ee.jsx)(pe.A,{className:"slider-arrow",onClick:()=>{o("next"),l(!0),setTimeout((()=>{n((e=>e===s.length-1?0:e+1)),l(!1)}),300),r||u()},size:"small",sx:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",backgroundColor:"rgba(255, 255, 255, 0.5)",opacity:0,transition:"opacity 0.2s ease, background-color 0.2s ease","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.8)"},zIndex:2,p:.5},children:(0,ee.jsx)(Ze.A,{fontSize:"small"})})]}),s.length>1&&(0,ee.jsx)(g.A,{sx:{position:"absolute",bottom:8,left:"50%",transform:"translateX(-50%)",display:"flex",gap:.75,zIndex:2},children:s.map(((e,s)=>(0,ee.jsx)(g.A,{onClick:()=>(e=>{e!==t&&(o(e>t?"next":"prev"),l(!0),setTimeout((()=>{n(e),l(!1)}),300),r||u())})(s),sx:{width:t===s?16:6,height:6,borderRadius:3,backgroundColor:t===s?"#fff":"rgba(255, 255, 255, 0.5)",cursor:"pointer",transition:"all 0.3s ease","&:hover":{backgroundColor:t===s?"#fff":"rgba(255, 255, 255, 0.75)"}}},s)))})]})})};var es=t(30995),ss=t(71543),ts=t(50215),ns=t(17809),rs=t(90509),is=t(68806),as=t(30425),os=t(21357),ds=t(57097);const ls=e=>{let{open:s,onClose:t,cartTotal:n,orderItems:r,deliveryType:i,selectedAddressId:a,selectedPickupId:o,userProfile:d,selectedStore:l,tipAmount:c,deliveryInstructions:u,customOrder:h,onSuccess:p,paymentConfig:A}=e;const[y]=(0,x.useState)((()=>crypto.randomUUID())),[f,b]=(0,x.useState)(null),[v,I]=(0,x.useState)(null);(0,x.useEffect)((()=>{b(null),I(null)}),[s]);const S=A?.isSquareConnected&&A?.squareApplicationId&&A?.squareLocationId,{mutate:C,isPending:w,isSuccess:P}=(0,ds.n)({mutationFn:async e=>await k("\n mutation CreateOrderWithPayment(\n $userId: Int!\n $storeId: Int!\n $productItems: [OrderItemInput!]!\n $payment: PaymentInput!\n $pickupOrDelivery: String!\n $addressId: Int\n $pickupId: Int\n $tipAmount: Float\n $deliveryInstructions: String\n $customOrder: String\n ) {\n createOrderWithPayment(\n userId: $userId\n storeId: $storeId\n productItems: $productItems\n payment: $payment\n pickupOrDelivery: $pickupOrDelivery\n addressId: $addressId\n pickupId: $pickupId\n tipAmount: $tipAmount\n deliveryInstructions: $deliveryInstructions\n customOrder: $customOrder\n ) {\n id\n displayCode\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),onSuccess:e=>{const s=e?.createOrderWithPayment;s&&s.id?(I(s),b(null)):b("Your payment was processed but we encountered an error creating your order. Please contact support. Your cart has been preserved.")},onError:e=>{b(e?.message||e?.response?.errors?.[0]?.message||"Payment failed. Please try again.")}});(0,x.useEffect)((()=>{P&&v&&(t(),p&&p(v))}),[P,v,t,p]);const E=e=>{if(e&&e.length>0){const s=e[0],t={INVALID_CARD_DATA:"Invalid card information. Please check your card details and try again.",CARD_DECLINED:"Your card was declined. Please try a different payment method.",NETWORK_ERROR:"Network error. Please check your connection and try again.",UNKNOWN_ERROR:"An error occurred during payment processing. Please try again."},n=s.code||"UNKNOWN_ERROR";b(t[n]||s.message||"Payment processing failed. Please try again.")}else b("Payment processing failed. Please try again.")},F=r.reduce(((e,s)=>e+s.quantity),0);return(0,ee.jsxs)(qe.A,{open:s,onClose:w?void 0:t,disableEscapeKeyDown:w,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.1)"}},children:[(0,ee.jsxs)(Re.A,{sx:{textAlign:"center",background:e=>e.palette.custom?.gradientPrimary||"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",color:"white",py:2.5,mb:2,position:"relative"},children:[(0,ee.jsx)(ts.A,{sx:{mr:1,verticalAlign:"middle"}}),"Complete Payment",!w&&!P&&(0,ee.jsx)(pe.A,{"aria-label":"close",onClick:t,sx:{position:"absolute",right:8,top:8,color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},children:(0,ee.jsx)(ns.A,{})})]}),(0,ee.jsx)(ze.A,{children:w?(0,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",py:4,gap:2},children:[(0,ee.jsx)(j.A,{size:60}),(0,ee.jsx)(m.A,{variant:"body1",color:"text.secondary",children:"Processing payment..."})]}):(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsxs)(g.A,{sx:{mb:3,p:2,bgcolor:"grey.50",borderRadius:1},children:[(0,ee.jsxs)(m.A,{variant:"body2",color:"text.secondary",children:[F," ",1===F?"item":"items"," • ","delivery"===i?"Delivery":"Pickup"]}),(0,ee.jsxs)(m.A,{variant:"h5",fontWeight:"bold",sx:{mt:1},children:["$",n.toFixed(2)]})]}),f&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:f}),S?(0,ee.jsx)(rs.A,{applicationId:A?.squareApplicationId,locationId:A?.squareLocationId,cardTokenizeResponseReceived:async(e,s)=>{if(b(null),!e)return void b("Payment tokenization failed. Please try again.");if(e.errors&&e.errors.length>0)return void E(e.errors);if(!e.token)return void b("Payment tokenization failed. Please try again.");const t=r.map((e=>({productId:e.productId,quantity:e.quantity})));d?.id&&l?.id?C({userId:d.id,storeId:l.id,productItems:t,payment:{paymentToken:e.token,idempotencyKey:y,clientCalculatedAmount:n},pickupOrDelivery:i,addressId:a,pickupId:o,tipAmount:c||0,deliveryInstructions:u||null,customOrder:h||null}):b("Missing required information. Please refresh and try again.")},createPaymentRequest:()=>({countryCode:"US",currencyCode:"USD",total:{amount:n.toFixed(2),label:"Total"}}),onError:E,children:(0,ee.jsxs)(es.A,{spacing:2,children:[(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(is.A,{}),(0,ee.jsx)(g.A,{sx:{mt:1},children:(0,ee.jsx)(as.A,{})})]}),(0,ee.jsx)(ss.A,{sx:{my:2},children:(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"OR"})}),(0,ee.jsx)(os.A,{}),w&&(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:2,py:2},children:[(0,ee.jsx)(j.A,{size:24}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Processing payment..."})]})]})}):(0,ee.jsxs)(es.A,{spacing:2,children:[(0,ee.jsxs)(ae.A,{severity:"info",sx:{mb:2},children:[(0,ee.jsx)("strong",{children:"Preview Mode:"})," Square credentials not configured. This is a UI preview only.",(0,ee.jsx)("br",{}),(0,ee.jsx)(m.A,{variant:"caption",sx:{mt:1,display:"block"},children:"Configure REACT_APP_SQUARE_APPLICATION_ID and REACT_APP_SQUARE_LOCATION_ID to enable payments."})]}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsxs)(te.A,{fullWidth:!0,variant:"outlined",disabled:!0,sx:{py:1.5,borderColor:"grey.300",color:"text.secondary",textTransform:"none",fontSize:"1rem",fontWeight:600},children:[(0,ee.jsx)("img",{src:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%234285F4'%3E%3Cpath d='M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z'/%3E%3Cpath fill='%2334A853' d='M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z'/%3E%3Cpath fill='%23FBBC05' d='M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z'/%3E%3Cpath fill='%23EA4335' d='M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z'/%3E%3C/svg%3E",alt:"Google",style:{width:20,height:20,marginRight:8}}),"Google Pay"]}),(0,ee.jsxs)(te.A,{fullWidth:!0,variant:"outlined",disabled:!0,sx:{mt:1,py:1.5,borderColor:"grey.300",color:"text.secondary",textTransform:"none",fontSize:"1rem",fontWeight:600},children:[(0,ee.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",style:{marginRight:8},children:(0,ee.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z",fill:"#000"})}),"Apple Pay"]})]}),(0,ee.jsx)(ss.A,{sx:{my:2},children:(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"OR"})}),(0,ee.jsxs)(g.A,{sx:{border:"1px solid",borderColor:"grey.300",borderRadius:1,p:2},children:[(0,ee.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"Card Number"}),(0,ee.jsx)(g.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1,mb:2},children:(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"•••• •••• •••• ••••"})}),(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:2},children:[(0,ee.jsxs)(g.A,{sx:{flex:1},children:[(0,ee.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"Expiration"}),(0,ee.jsx)(g.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1},children:(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"MM/YY"})})]}),(0,ee.jsxs)(g.A,{sx:{flex:1},children:[(0,ee.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"CVV"}),(0,ee.jsx)(g.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1},children:(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"•••"})})]})]}),(0,ee.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mt:2,display:"block"},children:"Postal Code"}),(0,ee.jsx)(g.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1,mt:1},children:(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"12345"})})]}),(0,ee.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{textAlign:"center",fontStyle:"italic"},children:"Payment form will be interactive once Square credentials are configured"})]})]})}),!P&&!w&&(0,ee.jsx)(We.A,{sx:{px:3,pb:2},children:(0,ee.jsx)(te.A,{onClick:t,color:"inherit",children:"Cancel"})})]})};var cs=t(50779),xs=t(69307),us=t(29428),ms=t(68864),hs=t(53215),ps=t(7578),As=t(89388);const gs=e=>{let{paymentConfig:s,selectedMethod:t,onMethodChange:n}=e;const r=s?.isSquareConnected&&s?.squareApplicationId&&s?.squareLocationId,i=s?.codEnabled;return(0,x.useEffect)((()=>{t||(r?n("square"):i&&n("cod"))}),[r,i,t,n]),r||i?(0,ee.jsxs)(cs.A,{component:"fieldset",fullWidth:!0,sx:{mb:3},children:[(0,ee.jsx)(xs.A,{component:"legend",sx:{mb:2,fontWeight:500},children:"Select Payment Method"}),(0,ee.jsxs)(us.A,{value:t||"",onChange:e=>n(e.target.value),children:[r&&(0,ee.jsx)(ms.A,{value:"square",control:(0,ee.jsx)(hs.A,{color:"primary"}),label:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(ps.A,{color:"primary"}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"body1",sx:{fontWeight:600},children:"Pay with Card"}),(0,ee.jsx)(m.A,{variant:"caption",color:"text.secondary",children:"Credit/Debit, Apple Pay, Google Pay"})]})]}),sx:{border:"1px solid",borderColor:"square"===t?"primary.main":"divider",borderRadius:1,px:2,py:1.5,mb:1,"&:hover":{bgcolor:"action.hover"}}}),i&&(0,ee.jsx)(ms.A,{value:"cod",control:(0,ee.jsx)(hs.A,{color:"primary"}),label:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(As.A,{color:"primary"}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"body1",sx:{fontWeight:600},children:"Cash on Delivery"}),(0,ee.jsx)(m.A,{variant:"caption",color:"text.secondary",children:"Pay when you receive your order"})]})]}),sx:{border:"1px solid",borderColor:"cod"===t?"primary.main":"divider",borderRadius:1,px:2,py:1.5,mb:1,"&:hover":{bgcolor:"action.hover"}}})]})]}):(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:"Store payment system unavailable. Please contact store or try again later."})},js={1:{2:t.p+"9eb9fe16cf24f64648f4.jpg",3:t.p+"97d88e9949ad49749160.jpg",4:t.p+"1b6333e925b3879a2984.jpg",5:t.p+"d35b1aa413caca3d6aa2.png",6:t.p+"5c2c140bb8e65ee1aa94.png",7:t.p+"0a359809026b5022f2d5.jpg"}};const ys=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(0),[r,i]=(0,x.useState)(12),{selectedStore:a}=X(),o=function(e,s){const[t,n]=(0,x.useState)(e);return(0,x.useEffect)((()=>{const t=setTimeout((()=>{n(e)}),s);return()=>{clearTimeout(t)}}),[e,s]),t}(e,300),{data:d,isLoading:l,error:c}=(0,u.I)({queryKey:["storeInventory",a?.id],queryFn:async()=>await k("\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}),b=(0,x.useMemo)((()=>d?.getInventoryByStore?.map((e=>{const s=a?.id,t=e.productId,n=js[s]||{};return{id:e.productId,name:e.product.name,image:e.product.image||n[t]||"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}}))||[]),[d,a?.id]),v=(0,x.useMemo)((()=>b.filter((e=>e.name.toLowerCase().includes(o.toLowerCase()))).sort(((e,s)=>e.isAvailable===s.isAvailable?0:e.isAvailable?-1:1))),[b,o]),I=(0,x.useMemo)((()=>v.slice(t*r,t*r+r)),[v,t,r]);return c?(0,ee.jsxs)(m.A,{children:["Error fetching products: ",c.message]}):(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(p.A,{label:"Search Products",variant:"outlined",fullWidth:!0,sx:{mb:3},value:e,onChange:e=>s(e.target.value),placeholder:"Search by product name or category...",InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(f.A,{})})}}),l?(0,ee.jsx)(g.A,{display:"flex",justifyContent:"center",my:4,children:(0,ee.jsx)(j.A,{})}):0===b.length?(0,ee.jsx)(m.A,{variant:"h6",align:"center",sx:{mt:4},children:"No products available in this store."}):(0,ee.jsx)(Te,{products:I}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,ee.jsx)(y.A,{rowsPerPageOptions:[8,12,24],component:"div",count:v.length,rowsPerPage:r,page:t,onPageChange:(e,s)=>{n(s)},onRowsPerPageChange:e=>{i(parseInt(e.target.value,10)),n(0)}})})]})};var fs=t(49799),bs=t(44090),vs=t(57873),Is=t(82241),Ss=t(58620),Cs=t(87980),ws=t(78325),Ps=t(54415),ks=t(84201),Es=t(15327);const Fs="/login",Ds="/forgot-password",Ls="/admin",$s="/user",Ts="/delivery_agent",qs="/store_manager",Rs="/store_manager/orders",zs="/orders",Ws="/profile",Os="/signup",Us="/cart";var Ns=t(28939),Bs=t(48393),_s=t(80437),Ms=t(58438),Vs=t(62594);const Hs=e=>{let{email:s,onComplete:t,onSuccess:n}=e;const r=(0,l.Zp)(),[i,a]=(0,x.useState)(""),[o,d]=(0,x.useState)(!1),[c,u]=(0,x.useState)(""),[h,A]=(0,x.useState)("");return(0,ee.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),d(!0),u(""),A("");try{await(0,Vs.z)({username:s,confirmationCode:i}),A("Account verified successfully! Redirecting to login..."),setTimeout((()=>{r("/")}),2e3),n&&n(),t&&t()}catch(e){u(e.message||"OTP verification failed. Please try again.")}finally{d(!1)}},children:[(0,ee.jsx)(m.A,{variant:"h4",component:"h1",gutterBottom:!0,children:"Verify OTP"}),(0,ee.jsx)(p.A,{label:"Enter OTP",variant:"outlined",fullWidth:!0,margin:"normal",value:i,onChange:e=>a(e.target.value),required:!0}),c&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mt:2},children:c}),h&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mt:2},children:h}),(0,ee.jsx)(te.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,ee.jsx)(j.A,{size:24,sx:{color:"#fff"}}):"Verify OTP"})]})};var Gs=t(5673),Ks=t(76768);const Ys=e=>{let{onSuccess:s,onError:t}=e;const n=(0,l.Zp)(),{setUser:r,setAbility:i,setModalOpen:a}=J(),[o,d]=(0,x.useState)(""),[c,u]=(0,x.useState)(""),[m,h]=(0,x.useState)(!1),[y,f]=(0,x.useState)(""),[b,v]=(0,x.useState)(!1),[I,S]=(0,x.useState)(!1);return(0,ee.jsx)(g.A,{children:b?(0,ee.jsx)(Hs,{email:o,onSuccess:()=>n("/"),onComplete:()=>v(!1)}):(0,ee.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),h(!0),f("");try{const e=await(0,Bs.J)({username:o,password:c});if("CONFIRM_SIGN_UP"===e.nextStep?.signInStep)return await(0,_s.h)({username:o}),void v(!0);const t=await(0,Ms.T)(),d=t["custom:role"].toLowerCase();r({email:t.email,role:d});const l=Y(d);i(l),a(!1),s&&s(),n(`/${d}`)}catch(e){if(e.message.includes("User is not confirmed"))try{await(0,_s.h)({username:o}),v(!0)}catch(e){f(e.message||"Error resending OTP.")}else f(e.message||"Login failed. Please try again.")}finally{h(!1)}},children:[(0,ee.jsx)(p.A,{label:"Email",variant:"outlined",fullWidth:!0,value:o,onChange:e=>d(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(xe.A,{sx:{color:"#FF6B6B"}})})}}),(0,ee.jsx)(p.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,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(ue.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,ee.jsx)(A.A,{position:"end",children:(0,ee.jsx)(pe.A,{onClick:()=>S((e=>!e)),edge:"end",children:I?(0,ee.jsx)(Ks.A,{}):(0,ee.jsx)(Gs.A,{})})})}}),y&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:y}),(0,ee.jsx)(te.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:m,sx:{py:1.2,borderRadius:"8px",textTransform:"none",fontSize:"1rem"},children:m?(0,ee.jsx)(j.A,{size:24,sx:{color:"#fff"}}):"Login"})]})})};var Qs=t(83728),Js=t(71432),Zs=t(19873);const Xs=e=>{let{referredBy:s="",onSuccess:t}=e;const[n,r]=(0,x.useState)(""),[i,a]=(0,x.useState)(""),[o,d]=(0,x.useState)(""),[l,c]=(0,x.useState)(""),[u,m]=(0,x.useState)(""),[h,j]=(0,x.useState)(s),[y,f]=(0,x.useState)(!1),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[C,w]=(0,x.useState)(!1);return(0,ee.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),f(!0),v(""),S("");try{await(0,Qs.H)({username:n,password:l,options:{userAttributes:{"custom:given_name":i,"custom:family_name":o,"custom:phone_number":u,"custom:referredBy":h}}}),S("Signup successful! Enter the OTP sent to your email."),t&&t(n)}catch(e){if(e.message.includes("User already exists"))try{await(0,_s.h)({username:n}),S("OTP resent. Please check your email."),t&&t(n)}catch(e){v(e.message||"Error resending OTP.")}else v(e.message||"Signup failed. Please try again.")}finally{f(!1)}},children:[(0,ee.jsx)(p.A,{label:"First Name",variant:"outlined",fullWidth:!0,value:i,onChange:e=>a(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(Js.A,{sx:{color:"#FF6B6B"}})})}}),(0,ee.jsx)(p.A,{label:"Last Name",variant:"outlined",fullWidth:!0,value:o,onChange:e=>d(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(Js.A,{sx:{color:"#FF6B6B"}})})}}),(0,ee.jsx)(p.A,{label:"Email",variant:"outlined",fullWidth:!0,value:n,onChange:e=>r(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(xe.A,{sx:{color:"#FF6B6B"}})})}}),(0,ee.jsx)(p.A,{label:"Password",variant:"outlined",type:C?"text":"password",fullWidth:!0,value:l,onChange:e=>c(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(ue.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,ee.jsx)(A.A,{position:"end",children:(0,ee.jsx)(pe.A,{onClick:()=>w((e=>!e)),edge:"end",children:C?(0,ee.jsx)(Ks.A,{}):(0,ee.jsx)(Gs.A,{})})})}}),(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:1,mb:2},children:[(0,ee.jsx)(p.A,{label:"Country Code",variant:"outlined",value:"+1",disabled:!0,sx:{width:"120px"},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(Zs.A,{sx:{color:"#FF6B6B"}})})}}),(0,ee.jsx)(p.A,{label:"Phone Number",variant:"outlined",fullWidth:!0,value:u,onChange:e=>m(e.target.value),required:!0,InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(Zs.A,{sx:{color:"#FF6B6B"}})})}})]}),(0,ee.jsx)(p.A,{label:"Referral Code",variant:"outlined",fullWidth:!0,value:h,onChange:e=>j(e.target.value),disabled:!!s,sx:{mb:2},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(xe.A,{sx:{color:"#FF6B6B"}})})}}),b&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:b}),I&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:I}),(0,ee.jsx)(te.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:y,sx:{mt:1,mb:2},children:y?"Processing...":"Sign Up"})]})};var et=t(15061),st=t(7888);const tt=e=>{let{onSuccess:s}=e;const[t,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(""),[d,c]=(0,x.useState)(!1),[u,m]=(0,x.useState)(""),[h,p]=(0,x.useState)(""),[A,g]=(0,x.useState)(1),j=(0,l.Zp)();return(0,ee.jsx)(se,{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,ee.jsxs)(le,{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,ee.jsxs)(se,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,ee.jsx)(ie,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:1===A?"Forgot Password":"Reset Password"}),(0,ee.jsx)(ie,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:1===A?"Enter your email address to receive a reset code":"Enter the OTP sent to your email and your new password"})]}),1===A?(0,ee.jsx)(me,{fields:[{label:"Email",type:"email",value:t,onChange:n}],onSubmit:async e=>{e.preventDefault(),c(!0),m(""),p("");try{await(0,et.x)({username:t}),g(2),p("OTP sent successfully! Check your email.")}catch(e){m(e.message||"Failed to send OTP. Try again.")}finally{c(!1)}},buttonLabel:"Send OTP",loading:d,error:u,success:h}):(0,ee.jsx)(me,{fields:[{label:"OTP",type:"text",value:r,onChange:i},{label:"New Password",type:"password",value:a,onChange:o}],onSubmit:async e=>{e.preventDefault(),c(!0),m(""),p("");try{await(0,st.P)({username:t,confirmationCode:r,newPassword:a}),p("Password reset successfully! Redirecting to login..."),setTimeout((()=>{s?s():j("/")}),2e3)}catch(e){m(e.message||"Failed to reset password. Try again.")}finally{c(!1)}},buttonLabel:"Reset Password",loading:d,error:u,success:h})]})})},nt=e=>{let{open:s,onClose:t,initialForm:n="login"}=e;const[r,i]=(0,x.useState)(n),[a,o]=(0,x.useState)(""),[d,l]=(0,x.useState)(!1),c=(0,x.useRef)(0),u=(0,Ee.A)();(0,x.useEffect)((()=>{s&&(i("login"),l(!1),o(""),c.current+=1)}),[s]);const h=e=>{i(e),l(!1)};return(0,ee.jsx)(Ns.A,{open:s,onClose:t,"aria-labelledby":"modal-modal-title","aria-describedby":"modal-modal-description",sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:(0,ee.jsxs)(g.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,ee.jsx)(te.A,{onClick:t,sx:{position:"absolute",top:8,right:8,minWidth:0,p:.5},children:(0,ee.jsx)(Oe.A,{})}),(0,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.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,ee.jsx)(m.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":""})]}),d&&"login"===r&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:"Email verified successfully! Please login to continue."}),"login"===r?(0,ee.jsx)(Ys,{onSuccess:t},`login-form-${c.current}`):"signup"===r?(0,ee.jsx)(Xs,{onSuccess:e=>{o(e),i("otp")}}):"otp"===r?(0,ee.jsx)(Hs,{email:a,onSuccess:()=>{l(!0),i("login")}}):(0,ee.jsx)(tt,{onSuccess:()=>h("login")}),(0,ee.jsxs)(g.A,{sx:{mt:3,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:["login"===r&&(0,ee.jsx)(te.A,{onClick:()=>h("forgotPassword"),sx:{color:u.palette.primary.main,textTransform:"none"},children:"Forgot Password?"}),"otp"!==r&&(0,ee.jsxs)(m.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,ee.jsx)(te.A,{color:"primary",onClick:()=>h("login"===r?"signup":"login"),sx:{textTransform:"none"},children:"login"===r?"Sign Up":"Login"})]})]})]})})};var rt=t(17532),it=t(10423),at=t(10420),ot=t(74202),dt=t(92659),lt=t(37856),ct=t(2223),xt=t(42702),ut=t(28800),mt=t(58407),ht=t(37211),pt=t(81385),At=t(10364),gt=t(2882),jt=t(85873);const yt=e=>{let{store:s,isSelected:t,onSelect:n}=e;const r=s.isActive;return(0,ee.jsx)(de.A,{elevation:0,sx:{mb:2,borderRadius:2,overflow:"hidden",transition:"all 0.2s ease",border:"1px solid",borderColor:t?"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,ee.jsx)(bs.Ay,{disablePadding:!0,children:(0,ee.jsx)(ht.A,{onClick:()=>r&&n(s),selected:t,disabled:!r,sx:{p:0,cursor:r?"pointer":"not-allowed"},children:(0,ee.jsx)(g.A,{sx:{width:"100%"},children:(0,ee.jsxs)(g.A,{sx:{p:2,backgroundColor:t?"rgba(0, 0, 0, 0.02)":"transparent"},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"flex-start",mb:1},children:[(0,ee.jsx)(pt.A,{sx:{bgcolor:r?t?"primary.main":"grey.300":"rgba(211, 47, 47, 0.1)",mr:2,color:r?"inherit":"error.main"},children:r?(0,ee.jsx)(at.A,{}):(0,ee.jsx)(jt.A,{})}),(0,ee.jsxs)(g.A,{sx:{flex:1},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[(0,ee.jsx)(m.A,{fontWeight:600,fontSize:"1.1rem",color:"text.primary",children:s.name}),!r&&(0,ee.jsx)(Fe.A,{label:"Offline",size:"small",sx:{height:20,fontSize:"0.75rem",backgroundColor:"rgba(211, 47, 47, 0.1)",color:"error.main",fontWeight:500}})]}),(!r||s.description)&&(0,ee.jsxs)(g.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,ee.jsx)(gt.A,{sx:{fontSize:"0.9rem",color:r?"text.secondary":"error.main",mr:.5,mt:.2}}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{fontStyle:r?"normal":"italic",fontWeight:r?400:500},children:s.description||"Store timings not available"})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ee.jsx)(ct.A,{sx:{fontSize:"0.9rem",color:"text.secondary",mr:.5}}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:s.address})]})]})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:1},children:[s.radius&&(0,ee.jsx)(Fe.A,{icon:(0,ee.jsx)(At.A,{fontSize:"small"}),label:`${s.radius} mi radius`,size:"small",variant:"outlined",color:t?"primary":"default",sx:{opacity:r?1:.7}}),!r&&(0,ee.jsx)(m.A,{variant:"caption",sx:{ml:"auto",color:"error.main",fontStyle:"italic"},children:"Store is currently offline"})]})]})})})})})},ft=e=>{let{availableStores:s,selectedStore:t,handleStoreSelect:n}=e;return(0,ee.jsx)(fs.A,{sx:{mt:1},children:s.map((e=>(0,ee.jsx)(yt,{store:e,isSelected:t?.id===e.id,onSelect:n},e.id)))})};var bt=t(1984);const vt=()=>(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:1},children:[(0,ee.jsx)(bt.A,{}),(0,ee.jsx)(m.A,{variant:"h5",fontWeight:600,children:"Select a Store"})]}),It=()=>(0,ee.jsx)(de.A,{elevation:0,sx:{p:3,textAlign:"center",backgroundColor:"rgba(33, 150, 243, 0.1)",borderRadius:2},children:(0,ee.jsx)(m.A,{sx:{fontWeight:500,color:"info.main"},children:"No stores available at the moment."})}),St=e=>{let{value:s,onChange:t,onValidAddress:n}=e;const r=(0,x.useRef)(null),i=(0,x.useRef)(null),[a,o]=(0,x.useState)(!1),[d,l]=(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){l(!0);const e=i.current;if(!e)return void l(!1);const s=new window.google.maps.places.Autocomplete(e,{types:["address"],componentRestrictions:{country:"us"}});r.current=s;const a=document.querySelector(".pac-container");a&&(document.body.appendChild(a),a.style.zIndex="99999"),s.addListener("place_changed",(()=>{const e=s.getPlace();e&&e.formatted_address?(u(e),t(e.formatted_address),o(!0),n(!0)):(u(null),o(!1),n(!1))}))}else l(!1),s&&s.trim().length>10?(o(!0),n(!0)):(o(!1),n(!1))}catch(e){l(!1),s&&s.trim().length>10?(o(!0),n(!0)):(o(!1),n(!1))}}),300);return()=>clearTimeout(e)}),[t,n,s]),(0,x.useEffect)((()=>{""===s?(o(!1),n(!1),u(null)):!d&&s.trim().length>10&&(o(!0),n(!0))}),[s,n,d]);return(0,ee.jsx)(p.A,{inputRef:i,label:"Address",fullWidth:!0,multiline:!0,rows:3,value:s,error:!a&&""!==s,helperText:d?a||""===s?d&&!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 s=e.target.value;t(s),d&&c&&s!==c.formatted_address?(o(!1),n(!1),u(null)):d||(s.trim().length>10?(o(!0),n(!0)):(o(!1),n(!1)))},placeholder:d?"Start typing to see address suggestions...":"Enter your complete address (e.g., 123 Main St, City, State 12345)"})},Ct=e=>{let{size:s=24,sx:t}=e;return(0,ee.jsx)(j.A,{size:s,sx:{color:"inherit",...t}})},wt=e=>{let{open:s,onClose:t,forceStep:n,initialStore:r}=e;const{selectedStore:i,setSelectedStore:o,availableStores:d,setPickupAddress:l,deliveryType:c,setDeliveryType:u,setDeliveryAddressString:h}=X(),{user:p,userProfile:A,fetchUserProfile:j,isProfileLoading:y,setModalOpen:f,setCurrentForm:b}=J(),I=(0,a.jE)(),{addresses:S,selectedAddressId:C,setSelectedAddressId:w,fetchAddresses:P,isLoading:k,createAddress:E}=Z(),[F,D]=(0,x.useState)("store"),[L,$]=(0,x.useState)(null),[T,q]=(0,x.useState)(null),[R,z]=(0,x.useState)(null),[W,O]=(0,x.useState)(""),[U,N]=(0,x.useState)(!1),[B,_]=(0,x.useState)(""),[M,V]=(0,x.useState)(!1),[H,G]=(0,x.useState)(!1),[K,Y]=(0,x.useState)(!1),[Q,se]=(0,x.useState)(""),[ne,re]=(0,x.useState)(0),[ie,oe]=(0,x.useState)([]),[le,ce]=(0,x.useState)(""),[xe,ue]=(0,x.useState)(null),me=A?S:ie,he=A?C:le;(0,x.useEffect)((()=>{const e=!!A;!1===xe&&!0===e&&(oe([]),ce(""),A?.id&&"pickup"===F&&L&&P(A.id),z(null),O("")),!0===xe&&!1===e&&w(null),ue(e)}),[A,F,L,P,w,xe]),(0,x.useEffect)((()=>{"pickup"===F&&L&&A?.id&&P(A.id)}),[F,L,A?.id,P]),(0,x.useEffect)((()=>{if(!("pickup"===F&&(1===ne||!L?.pickupAddresses?.edges?.length))||A)return;let e=!1;return(async()=>{try{const s=await(0,v.$)(),t=s?.tokens?.idToken?.payload?.sub;t&&!e&&await j(t)}catch{}})(),()=>{e=!0}}),[F,ne,A,p,j,L]),(0,x.useEffect)((()=>{s&&n&&(D(n),r&&$(r)),s||(D("store"),$(null),Ae())}),[s,n,r]);const Ae=()=>{A?w(null):ce(""),_(""),V(!1),G(!1),Y(!1),z(null),O(""),q(null),re(0),se("")},ge=async()=>{N(!0);try{const e=await(0,v.$)(),s=e?.tokens?.idToken?.payload?.sub;if(s){if(A||await j(s),A?.id||s){const e=A?.id;e&&(await P(e),oe([]),ce(""))}}else w(null);z(null),O("")}catch(e){}finally{N(!1)}},je=()=>{f(!0),b("login")},ye=async()=>{if(B.trim()&&K)if(fe(B),se(B),u("delivery"),q(null),A?w(null):ce(""),A?.id){if(!S.some((e=>e.address.toLowerCase().trim()===B.toLowerCase().trim()))){G(!0);try{await E(B,A.id,M);const e=(await P(A.id)).find((e=>e.address.toLowerCase().trim()===B.toLowerCase().trim()));e&&w(e.id),I.invalidateQueries(["userAddresses",A.id])}catch(e){}finally{G(!1)}}}else{if(!ie.some((e=>e.address.toLowerCase().trim()===B.toLowerCase().trim()))){const e={id:`temp_${Date.now()}`,address:B,isPrimary:0===ie.length};oe((s=>[...s,e])),ce(e.id)}}},fe=e=>{if(!e||!L)return z(null),void O("");const s=e.match(/\b(\d{5})(?:-\d{4})?\b/g),t=s?s[s.length-1]:null,n=(L?.pincodes||[]).map((e=>String(e).trim())),r=t?String(t).trim():"";r&&n.includes(r)?(z("success"),O("Store delivers here")):(z("error"),O("Store does not deliver here."))},be=e=>{localStorage.setItem("selectedStoreId",String(e.id)),$(e),D("pickup")},ve=()=>{if(!L||!T)return;const e=(L.pickupAddresses?.edges?.map((e=>e.node))||[]).find((e=>String(e.id)===String(T)));o(L),l(e),u("pickup"),h(null),D("store"),$(null),q(null),Ae(),t()},Ie=()=>{if("success"===R&&Q){let e=Q;if(A&&C&&S&&S.length>0){const s=S.find((e=>e.id===C));s&&s.address&&(e=s.address)}if(!e||!e.trim())return;o(L),setTimeout((()=>{l(null),u("delivery"),h(e.trim())}),10),setTimeout((()=>{D("store"),$(null),Ae(),t()}),1200)}},Ce=()=>{D("store"),$(null),Ae()};if("store"===F)return(0,ee.jsx)(Ue,{open:s,onClose:t,title:(0,ee.jsx)(vt,{}),children:0===d.length?(0,ee.jsx)(It,{}):(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(m.A,{paragraph:!0,sx:{textAlign:"center",fontWeight:500,color:"text.secondary",mb:3},children:"Please select a store to browse products from"}),(0,ee.jsx)(ft,{availableStores:d,selectedStore:i,handleStoreSelect:be})]})});if("pickup"===F){const e=L?.pickupAddresses?.edges?.map((e=>e.node))||[],n=e.length>0,r=(0,ee.jsx)(te.A,{onClick:Ce,variant:"text",color:"inherit",size:"small",startIcon:(0,ee.jsx)(dt.A,{}),sx:{fontWeight:500},children:"Back to stores"});return(0,ee.jsxs)(Ue,{open:s,onClose:t,title:(0,ee.jsx)(vt,{}),footer:r,children:[(0,ee.jsxs)(m.A,{variant:"body2",sx:{textAlign:"center",color:"text.secondary",mb:2},children:["Choose how you'd like to receive your order from ",(0,ee.jsx)("b",{children:L?.name})]}),(0,ee.jsx)(g.A,{sx:{borderBottom:1,borderColor:"divider",mb:2},children:(0,ee.jsxs)(rt.A,{value:ne,onChange:(e,s)=>re(s),variant:"fullWidth",sx:{minHeight:42,"& .MuiTabs-indicator":{height:3,borderRadius:"3px 3px 0 0"}},children:[(0,ee.jsx)(it.A,{icon:(0,ee.jsx)(at.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Pickup",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:42,py:0}}),(0,ee.jsx)(it.A,{icon:(0,ee.jsx)(ot.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Delivery",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:42,py:0}})]})}),0===ne&&(0,ee.jsx)(es.A,{spacing:2,children:n?(0,ee.jsxs)(ee.Fragment,{children:[e.map((e=>(0,ee.jsxs)(de.A,{elevation:0,onClick:()=>{return s={target:{value:String(e.id)}},q(s.target.value),u("pickup"),h(null),A?w(null):ce(""),z(null),void O("");var s},sx:{p:2,cursor:"pointer",border:"1.5px solid",borderColor:String(T)===String(e.id)?"primary.main":"grey.200",borderRadius:2,bgcolor:String(T)===String(e.id)?"primary.50":"transparent",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:"grey.50"},display:"flex",alignItems:"center",gap:1.5},children:[(0,ee.jsx)(hs.A,{checked:String(T)===String(e.id),value:String(e.id),color:"primary",size:"small",sx:{p:0}}),(0,ee.jsx)(m.A,{variant:"body2",children:e.address})]},e.id))),(0,ee.jsx)(te.A,{onClick:ve,variant:"contained",color:"primary",fullWidth:!0,startIcon:(0,ee.jsx)(lt.A,{}),disabled:!T,sx:{mt:1,fontWeight:600,py:1.2,fontSize:"0.95rem",borderRadius:2},children:"Confirm Pickup"})]}):(0,ee.jsx)(ae.A,{severity:"info",sx:{mt:2},children:(0,ee.jsx)(m.A,{variant:"body2",children:"No pickup points available for this store."})})}),1===ne&&(0,ee.jsxs)(es.A,{spacing:2,children:[(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:-1},children:"Enter your delivery address to check availability"}),(0,ee.jsx)(St,{value:B,onChange:e=>{_(e),Q&&(z(null),O(""),se(""))},onValidAddress:Y}),(0,ee.jsx)(te.A,{variant:"contained",size:"small",onClick:ye,disabled:!B.trim()||!K||H,startIcon:H?(0,ee.jsx)(Ct,{size:18}):(0,ee.jsx)(ct.A,{}),sx:{borderRadius:1.5},children:H?"Validating...":"Validate & Use This Address"}),R&&(0,ee.jsx)(ae.A,{severity:R,sx:{borderRadius:1.5},icon:"success"===R?(0,ee.jsx)(mt.A,{}):void 0,children:W}),A?(0,ee.jsx)(ee.Fragment,{children:me.length>0&&(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(ss.A,{sx:{my:1},children:(0,ee.jsx)(Fe.A,{label:"Your Saved Addresses",size:"small",variant:"outlined"})}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"flex-end"},children:(0,ee.jsx)(Se.A,{title:"Refresh addresses",children:(0,ee.jsx)(pe.A,{size:"small",onClick:ge,disabled:U,sx:{border:"1px solid",borderColor:"divider",width:28,height:28},children:U?(0,ee.jsx)(Ct,{size:14}):(0,ee.jsx)(xt.A,{sx:{fontSize:16}})})})}),k||U?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,ee.jsx)(Ct,{size:24})}):(0,ee.jsx)(es.A,{spacing:1.5,children:me.map((e=>(0,ee.jsxs)(de.A,{elevation:0,onClick:()=>(e=>{A?w(e.id):ce(e.id),se(e.address),_(""),Y(!1),fe(e.address),u("delivery"),q(null)})(e),sx:{p:1.5,cursor:"pointer",border:"1.5px solid",borderColor:he===e.id?"secondary.main":"grey.200",borderRadius:2,bgcolor:he===e.id?"secondary.50":"transparent",transition:"all 0.15s ease","&:hover":{borderColor:"secondary.light",bgcolor:"grey.50"},display:"flex",alignItems:"center",gap:1.5},children:[(0,ee.jsx)(hs.A,{checked:he===e.id,color:"secondary",size:"small",sx:{p:0}}),(0,ee.jsxs)(g.A,{sx:{flex:1,minWidth:0},children:[(0,ee.jsx)(m.A,{variant:"body2",noWrap:!0,children:e.address}),e.isPrimary&&(0,ee.jsx)(Fe.A,{label:"Primary",size:"small",color:"secondary",variant:"outlined",sx:{mt:.5,height:20,fontSize:"0.7rem"}})]})]},e.id)))})]})}):(0,ee.jsxs)(de.A,{elevation:0,sx:{p:2.5,border:"1.5px dashed",borderColor:"grey.300",borderRadius:2,textAlign:"center",bgcolor:"grey.50"},children:[(0,ee.jsx)(ut.A,{sx:{fontSize:32,color:"text.disabled",mb:1}}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:"Sign in to use your saved addresses"}),(0,ee.jsx)(te.A,{variant:"outlined",size:"small",startIcon:(0,ee.jsx)(ut.A,{}),onClick:je,sx:{borderRadius:1.5},children:"Login"})]}),(0,ee.jsx)(te.A,{onClick:Ie,variant:"contained",color:"secondary",fullWidth:!0,startIcon:(0,ee.jsx)(ot.A,{}),disabled:"success"!==R||!Q,sx:{fontWeight:600,py:1.2,fontSize:"0.95rem",borderRadius:2},children:"Confirm Delivery"})]})]})}return null};var Pt=t(62274);const kt=e=>{let{navigate:s,userRole:t}=e;const{setUser:n}=J();return(0,ee.jsx)(ie,{onClick:async()=>{let e=t;if(!e)try{const s=await(0,v.$)();s?.tokens?.idToken&&(e=s.tokens.idToken.payload["custom:role"]?.toLowerCase(),n({role:e}))}catch(e){}s(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"})},Et=()=>{const e=(0,l.Zp)(),[s,t]=(0,x.useState)(null),n=(0,Es.A)("(max-width: 600px)"),r=X((e=>e.cartCount())),i=X((e=>e.selectedStore)),{user:a,ability:o,logout:d}=J(),[c,u]=x.useState(null),{modalOpen:m,setModalOpen:h,currentForm:p,setCurrentForm:A}=J(),[g,j]=(0,x.useState)(null),[y,f]=(0,x.useState)(!1),[b,I]=(0,x.useState)(!1);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,v.$)(),s=await(0,Ms.T)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;j(s)}const n=s["custom:role"]?.toLowerCase();t(n)}catch(e){j(null),t(null)}})()}),[a]);const S=()=>{h(!0),A("login")},C=async()=>{try{await(0,ks.C)(),d(),j(null),t(null),e("/")}catch(e){}},w=()=>u(null),P=Y(a?.role||"user");(0,x.useEffect)((()=>{!n&&b&&I(!1)}),[n,b]);const k=(0,ee.jsxs)(se,{sx:{width:270,height:"100%",bgcolor:"background.paper",boxShadow:3,display:"flex",flexDirection:"column"},role:"presentation",onClick:()=>I(!1),children:[(0,ee.jsx)(se,{sx:{display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"#fff",px:2,py:2.5,minHeight:64,boxShadow:1},children:(0,ee.jsx)(ie,{variant:"h6",sx:{fontWeight:800,letterSpacing:1,fontSize:"1.35rem",color:"#fff",textAlign:"center"},children:"Menu"})}),(0,ee.jsx)(ss.A,{}),(0,ee.jsxs)(fs.A,{sx:{flex:1,py:1},children:[!g&&(0,ee.jsxs)(bs.Ay,{button:!0,onClick:S,sx:{py:2},children:[(0,ee.jsx)(vs.A,{sx:{color:"primary.main",minWidth:40},children:(0,ee.jsx)(Cs.A,{})}),(0,ee.jsx)(Is.A,{primary:(0,ee.jsx)(ie,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Sign In"})})]}),s!==_&&s!==H&&s!==V&&(0,ee.jsxs)(bs.Ay,{button:!0,onClick:()=>f(!0),sx:{py:2},children:[(0,ee.jsx)(vs.A,{sx:{color:"primary.main",minWidth:40},children:(0,ee.jsx)(ws.A,{})}),(0,ee.jsx)(Is.A,{primary:(0,ee.jsx)(ie,{sx:{fontWeight:600,fontSize:"1.1rem"},children:i?"Change Store":"Select Store"})})]}),(0,ee.jsxs)(bs.Ay,{button:!0,onClick:()=>e(Us),sx:{py:2},children:[(0,ee.jsx)(vs.A,{sx:{color:"primary.main",minWidth:40},children:(0,ee.jsx)(Pe.A,{})}),(0,ee.jsx)(Is.A,{primary:(0,ee.jsx)(ie,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Cart"})})]}),g&&P?.can("view","orders")&&(0,ee.jsxs)(bs.Ay,{button:!0,onClick:()=>e(zs),sx:{py:2},children:[(0,ee.jsx)(vs.A,{sx:{color:"primary.main",minWidth:40},children:(0,ee.jsx)(Ps.A,{})}),(0,ee.jsx)(Is.A,{primary:(0,ee.jsx)(ie,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Orders"})})]}),g&&(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(ss.A,{sx:{my:1.5}}),(0,ee.jsxs)(bs.Ay,{button:!0,onClick:()=>{e(Ws)},sx:{py:2},children:[(0,ee.jsx)(vs.A,{sx:{color:"primary.main",minWidth:40},children:(0,ee.jsx)(Cs.A,{})}),(0,ee.jsx)(Is.A,{primary:(0,ee.jsx)(ie,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Profile"})})]}),(0,ee.jsxs)(bs.Ay,{button:!0,onClick:C,sx:{py:2},children:[(0,ee.jsx)(vs.A,{sx:{color:"error.main",minWidth:40},children:(0,ee.jsx)(Cs.A,{})}),(0,ee.jsx)(Is.A,{primary:(0,ee.jsx)(ie,{sx:{fontWeight:600,fontSize:"1.1rem",color:"error.main"},children:"Logout"})})]})]})]}),(0,ee.jsx)(ss.A,{}),(0,ee.jsxs)(se,{sx:{p:2,textAlign:"center",color:"text.secondary",fontSize:"0.95rem"},children:["© ",(new Date).getFullYear()," Indimitra"]})]});return(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(se,{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,ee.jsxs)(Be,{sx:{minHeight:{xs:"56px",sm:"64px",md:"70px"},px:{xs:1,sm:2,md:4}},children:[(0,ee.jsx)(kt,{navigate:e,userRole:a?.role}),(0,ee.jsx)(se,{sx:{flexGrow:1}}),n?(0,ee.jsx)(Ae,{edge:"end",color:"inherit","aria-label":"menu",onClick:()=>I(!0),sx:{ml:1},children:(0,ee.jsx)(Pt.A,{})}):(0,ee.jsxs)(se,{sx:{display:"flex",alignItems:"center",gap:{xs:.5,sm:1,md:2},flexDirection:{xs:"row",sm:"row"},position:"relative"},children:[!g&&(0,ee.jsx)(ne,{onClick:S,sx:{color:"#2A2F4F",textTransform:"none",fontSize:{xs:"0.95rem",sm:"1rem"},fontWeight:500,px:{xs:1,sm:2},py:{xs:.5,sm:1},minWidth:{xs:0,sm:64},"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:"Sign In"}),!n&&g&&P&&P.can("view","orders")&&(0,ee.jsx)(ne,{onClick:()=>e(zs),sx:{color:"#2A2F4F",textTransform:"none",fontSize:{xs:"0.95rem",sm:"1rem"},fontWeight:500,px:{xs:1,sm:2},py:{xs:.5,sm:1},minWidth:{xs:0,sm:64},"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:"Orders"}),s!==_&&s!==H&&s!==V&&(0,ee.jsx)(ne,{variant:"outlined",startIcon:(0,ee.jsx)(ws.A,{sx:{fontSize:{xs:18,sm:22}}}),onClick:()=>f(!0),sx:{color:"#2A2F4F",borderColor:"#2A2F4F",textTransform:"none",fontSize:{xs:"0.95rem",sm:"1rem"},fontWeight:500,px:{xs:1,sm:2},py:{xs:.5,sm:1},minWidth:{xs:0,sm:64},mr:{xs:.5,sm:1},"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:i?"Change Store":"Select Store"}),a?P?.can("view","cart")&&(0,ee.jsx)(_e,{title:"Cart",children:(0,ee.jsx)(Ae,{onClick:()=>e(Us),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white",p:{xs:.75,sm:1},"&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,ee.jsx)(Ve,{badgeContent:r,color:"error",sx:{"& .MuiBadge-badge":{backgroundColor:"#FF6B6B",color:"white",fontWeight:"bold",fontSize:{xs:"0.7rem",sm:"0.8rem"},minWidth:{xs:18,sm:20},height:{xs:18,sm:20}}},children:(0,ee.jsx)(Pe.A,{sx:{fontSize:{xs:20,sm:24}}})})})}):(0,ee.jsx)(_e,{title:"Cart",children:(0,ee.jsx)(Ae,{onClick:()=>e(Us),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white",p:{xs:.75,sm:1},"&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,ee.jsx)(Ve,{badgeContent:r,color:"error",sx:{"& .MuiBadge-badge":{backgroundColor:"#FF6B6B",color:"white",fontWeight:"bold",fontSize:{xs:"0.7rem",sm:"0.8rem"},minWidth:{xs:18,sm:20},height:{xs:18,sm:20}}},children:(0,ee.jsx)(Pe.A,{sx:{fontSize:{xs:20,sm:24}}})})})}),g&&(0,ee.jsx)(_e,{title:"Profile",children:(0,ee.jsx)(Ae,{onClick:e=>u(e.currentTarget),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white",p:{xs:.75,sm:1},ml:{xs:.5,sm:1},"&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,ee.jsx)(Cs.A,{sx:{fontSize:{xs:20,sm:24}}})})})]})]})}),(0,ee.jsx)(Ss.Ay,{anchor:"right",open:b,onClose:()=>I(!1),children:k}),(0,ee.jsxs)(Ge,{anchorEl:c,open:Boolean(c),onClose:w,PaperProps:{elevation:3,sx:{mt:2,minWidth:"200px",borderRadius:"12px",overflow:"hidden"}},children:[n&&P?.can("view","orders")&&(0,ee.jsx)(je,{onClick:()=>{e(zs),w()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,ee.jsx)(ie,{variant:"body1",children:"Orders"})}),(0,ee.jsx)(je,{onClick:()=>{e(Ws),w()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,ee.jsx)(ie,{variant:"body1",children:"Profile"})}),(0,ee.jsx)(je,{onClick:()=>{C(),w()},sx:{py:1.5,px:3,color:"#FF5757","&:hover":{backgroundColor:"rgba(255, 87, 87, 0.1)"}},children:(0,ee.jsx)(ie,{variant:"body1",children:"Logout"})})]}),(0,ee.jsx)(wt,{open:y,onClose:()=>f(!1)}),(0,ee.jsx)(se,{sx:{height:{xs:"56px",sm:"64px",md:"70px"}}}),(0,ee.jsx)(nt,{open:m,onClose:()=>h(!1),currentForm:p,setCurrentForm:A})]})};var Ft=t(87992),Dt=t(61451);const Lt=()=>{const e=X((e=>e.selectedStore));return(0,ee.jsx)(Ft.A,{color:"success","aria-label":"WhatsApp",onClick:()=>{const s=`https://wa.me/${e?.whatsappNumber||"+15627872535"}?text=${encodeURIComponent(`Hello! I have a question about ${e?.name||"your services"}.`)}`;window.open(s,"_blank")},sx:{position:"fixed",bottom:20,right:20,zIndex:1e3,backgroundColor:"#25D366","&:hover":{backgroundColor:"#128C7E"}},children:(0,ee.jsx)(Dt.A,{sx:{fontSize:32}})})},$t=e=>{let{children:s}=e;return(0,ee.jsxs)(se,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[(0,ee.jsx)(Et,{}),s,(0,ee.jsx)(Lt,{})]})},Tt=e=>{let{children:s,role:t}=e;const{user:n,setUser:r,ability:i,setAbility:a}=J(),[o,d]=(0,x.useState)(!0),[c,u]=(0,x.useState)(!1),[m,h]=(0,x.useState)(null),p=(0,l.zy)();if((0,x.useEffect)((()=>{(async()=>{try{const e=await(0,v.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload["custom:role"]?.toLowerCase();n||r({role:s});const t=Y(s);a(t),h(t),u(!0)}else u(!1)}catch(e){u(!1)}finally{d(!1)}})()}),[n,r,a]),o)return(0,ee.jsx)(ce,{});if(!c)return(0,ee.jsx)(l.C5,{to:"/",replace:!0});if(p.pathname===Ws)return(0,ee.jsx)($t,{children:s});const A=(Array.isArray(t)?t:[t]).map((e=>e.toLowerCase()));return m&&A.some((e=>m.can("view",e)))?(0,ee.jsx)($t,{children:s}):(0,ee.jsx)(l.C5,{to:"/not-authorized",replace:!0})},qt=()=>{const[e,s]=(0,x.useState)(!1),[t,n]=(0,x.useState)(""),[i]=(0,r.ok)(),a=i.get("referredby")||"";return(0,ee.jsx)(g.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,ee.jsxs)(de.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,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,ee.jsx)(m.A,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:e?"Verify OTP":"Create Account"}),(0,ee.jsx)(m.A,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:e?"Enter the OTP sent to your email to verify your account":"Join us and start your journey today"})]}),(0,ee.jsx)(g.A,{sx:{minHeight:300},children:e?(0,ee.jsx)(Hs,{email:t,onComplete:()=>s(!1)}):(0,ee.jsx)(Xs,{referredBy:a,onOtpStep:e=>{n(e),s(!0)}})})]})})};var Rt=t(31117),zt=t(69377),Wt=t(85685),Ot=t(69634),Ut=t(47027),Nt=t(94654),Bt=t(17451);const _t=e=>{let{title:s,value:t,icon:n,color:r}=e;const i=(0,Ee.A)(),a=(0,Es.A)(i.breakpoints.down("sm"));return(0,ee.jsx)(fe.A,{sx:{height:"100%"},children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ee.jsx)(g.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,ee.jsx)(m.A,{variant:"h6",color:"text.secondary",children:s})]}),(0,ee.jsx)(m.A,{variant:a?"h5":"h4",component:"div",sx:{fontWeight:"bold"},children:t})]})})},Mt=()=>{const e=(0,Ee.A)(),s=(0,Es.A)(e.breakpoints.down("sm")),{data:t,isLoading:n,error:r}=(0,u.I)({queryKey:["dashboardStats"],queryFn:async()=>await k("\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 k("\n query GetOrderStats {\n getOrderStats {\n totalOrders\n recentOrders\n ordersByStatus\n ordersByType\n }\n }\n")}),{data:d,isLoading:l,error:c}=(0,u.I)({queryKey:["stores"],queryFn:async()=>await k(q)}),{data:x,isLoading:h,error:p}=(0,u.I)({queryKey:["allStoresSquareStatus"],queryFn:async()=>await k("\n query AllStoresSquareStatus {\n allStoresSquareStatus {\n storeId\n storeName\n isConnected\n }\n }\n")}),A=t?.getDashboardStats||{},y=i?.getOrderStats||{},f=d?.stores||[],b=x?.allStoresSquareStatus||[],v=A.totalUsers||0,I=f.length||0,S=A.deliveryAgents||0,C=y.totalOrders||0,w=b.filter((e=>e.isConnected)).length,P=b.length||I,E=f.filter((e=>e.codEnabled)).length;if(n||a||l||h)return(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:(0,ee.jsx)(j.A,{})});if(r||o||c||p){const e=r?.message||o?.message||c?.message||p?.message||"Error loading dashboard data. Please try again later.";return(0,ee.jsx)(g.A,{sx:{p:s?2:3},children:(0,ee.jsx)(Ye,{error:e,title:"Dashboard Error",severity:"error"})})}return(0,ee.jsxs)(g.A,{sx:{p:s?2:3},children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,sx:{mb:4},children:"Dashboard Overview"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Total Users",value:v.toLocaleString(),icon:(0,ee.jsx)(Ot.A,{}),color:e.palette.primary.main})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Total Stores",value:I.toLocaleString(),icon:(0,ee.jsx)(bt.A,{}),color:e.palette.success.main})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Square Connected",value:`${w} / ${P}`,icon:(0,ee.jsx)(ts.A,{}),color:e.palette.success.main})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Cash on Delivery",value:`${E} / ${I}`,icon:(0,ee.jsx)(ts.A,{}),color:e.palette.info.main})})]}),(0,ee.jsx)(g.A,{sx:{mt:4},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Active Drivers",value:S.toLocaleString(),icon:(0,ee.jsx)(As.A,{}),color:e.palette.info.main})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Total Orders",value:C.toLocaleString(),icon:(0,ee.jsx)(Pe.A,{}),color:e.palette.warning.main})})]})}),(0,ee.jsxs)(g.A,{sx:{mt:4},children:[(0,ee.jsx)(m.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"Detailed Statistics"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Active Users",value:(A.activeUsers||0).toLocaleString(),icon:(0,ee.jsx)(Ot.A,{}),color:e.palette.success.main})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Recent Orders (30 days)",value:(y.recentOrders||0).toLocaleString(),icon:(0,ee.jsx)(Pe.A,{}),color:e.palette.info.main})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Delivery Orders",value:(y.ordersByType?.DELIVERY||0).toLocaleString(),icon:(0,ee.jsx)(As.A,{}),color:e.palette.secondary.main})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(_t,{title:"Pickup Orders",value:(y.ordersByType?.PICKUP||0).toLocaleString(),icon:(0,ee.jsx)(bt.A,{}),color:e.palette.warning.main})})]})]}),A.usersByType&&Object.keys(A.usersByType).length>0&&(0,ee.jsxs)(g.A,{sx:{mt:4},children:[(0,ee.jsx)(m.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"User Type Breakdown"}),(0,ee.jsx)(ye.Ay,{container:!0,spacing:2,children:Object.entries(A.usersByType).map((e=>{let[s,t]=e;return(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ee.jsx)(fe.A,{sx:{height:"100%"},children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()}),(0,ee.jsx)(m.A,{variant:"h4",component:"div",sx:{fontWeight:"bold"},children:t.toLocaleString()})]})})},s)}))})]})]})};var Vt=t(33198),Ht=t(64137),Gt=t(96627),Kt=t(86798),Yt=t(14774),Qt=t(43884),Jt=t(29571),Zt=t(65460),Xt=t(95557),en=t(72297),sn=t(68125);const tn=()=>{const e=(0,Ee.A)(),s=(0,Es.A)(e.breakpoints.down("sm")),[t,n]=(0,x.useState)(0),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(0),[d,l]=(0,x.useState)(10),[c,h]=(0,x.useState)(!1),[f,b]=(0,x.useState)(""),[v,I]=(0,x.useState)(null),[S,C]=(0,x.useState)(!1),[w,P]=(0,x.useState)(""),[F,D]=(0,x.useState)({open:!1,message:"",severity:"success"}),[L,$]=(0,x.useState)(null),[T,q]=(0,x.useState)(!1),[z,W]=(0,x.useState)(""),[O,U]=(0,x.useState)([]),{data:N,isLoading:B,error:_,refetch:M}=(0,u.I)({queryKey:["users"],queryFn:async()=>{const e=await k(E);return e?.getAllUsers||[]},enabled:!0}),{data:V,isLoading:H,error:G,refetch:K}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{try{const e=await k(R);let s=[];return e?.stores&&(Array.isArray(e.stores)?s=e.stores:e.stores.edges&&Array.isArray(e.stores.edges)?s=e.stores.edges.map((e=>e.node)):e.stores.nodes&&Array.isArray(e.stores.nodes)?s=e.stores.nodes:"object"!=typeof e.stores||Array.isArray(e.stores)||(s=[e.stores])),s}catch(e){return[]}},enabled:!0}),Y=(0,ds.n)({mutationFn:e=>k("\n mutation UpdateUserType($targetUserId: String!, $newType: String!) {\n updateUserType(targetUserId: $targetUserId, newType: $newType) {\n user {\n id\n email\n type\n }\n error {\n message\n }\n }\n }\n",e),onSuccess:(e,s)=>{const t=e?.updateUserType;t?.user&&(N&&N.forEach((e=>{e.cognitoId===s.targetUserId&&(e.type=s.newType)})),D({open:!0,message:`Successfully updated user role to ${t.user.type}`,severity:"success"})),C(!1)},onError:e=>{D({open:!0,message:"Error updating user role: "+e.message,severity:"error"})}}),Q=(0,ds.n)({mutationFn:e=>k("\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 s=e?.assignDriverToStore;s&&(D({open:!0,message:`Successfully assigned driver to ${s.store.name}`,severity:"success"}),K()),q(!1)},onError:e=>{D({open:!0,message:"Error assigning driver to store: "+e.message,severity:"error"})}});(0,x.useEffect)((()=>{N&&(async()=>{try{if(N&&Array.isArray(N)){const e=N.find((e=>"ADMIN"===e.type));e&&$(e.cognitoId)}}catch(e){}})()}),[N]),(0,x.useEffect)((()=>{V&&Array.isArray(V)?U(V):U([])}),[V]);const J=e=>{I(e),P(e.type),C(!0)},Z=e=>{I(e),W(""),q(!0)},X=()=>{D({...F,open:!1})},se=()=>{if(!N||!Array.isArray(N))return[];let e=N;return 1===t?e=N.filter((e=>"USER"===e.type)):2===t?e=N.filter((e=>"DELIVERY"===e.type)):3===t&&(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},ne=()=>z&&Array.isArray(O)?O.find((e=>e.id===parseInt(z))):null;return(0,ee.jsxs)(g.A,{sx:{p:s?2:3},children:[(0,ee.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,ee.jsx)(m.A,{variant:"h5",gutterBottom:!0,children:"User Management"}),(0,ee.jsxs)(rt.A,{value:t,onChange:(e,s)=>{n(s),o(0)},sx:{mb:3},variant:s?"fullWidth":"standard",children:[(0,ee.jsx)(it.A,{label:"All"}),(0,ee.jsx)(it.A,{label:"Users"}),(0,ee.jsx)(it.A,{label:"Delivery Partners"}),(0,ee.jsx)(it.A,{label:"Store Managers"})]}),(0,ee.jsx)(g.A,{sx:{mb:3,display:"flex",gap:2,flexWrap:"wrap"},children:(0,ee.jsx)(p.A,{size:"small",placeholder:"Search...",value:r,onChange:e=>{i(e.target.value),o(0)},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(sn.A,{})})},sx:{flexGrow:1,minWidth:200}})}),_&&(0,ee.jsxs)(ae.A,{severity:"error",sx:{mb:3},children:["Error loading users: ",_.message]}),B?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ee.jsx)(j.A,{})}):(0,ee.jsxs)(ee.Fragment,{children:[0===t&&(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"ID"}),(0,ee.jsx)(Yt.A,{children:"Email"}),(0,ee.jsx)(Yt.A,{children:"Mobile"}),(0,ee.jsx)(Yt.A,{children:"Type"}),(0,ee.jsx)(Yt.A,{children:"Status"}),(0,ee.jsx)(Yt.A,{children:"Referral ID"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:se().slice(a*d,a*d+d).map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.id}),(0,ee.jsx)(Yt.A,{children:e.email}),(0,ee.jsx)(Yt.A,{children:e.mobile||"N/A"}),(0,ee.jsx)(Yt.A,{children:e.type}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,ee.jsx)(Yt.A,{children:e.referralId||"N/A"}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{size:"small",color:"primary",onClick:()=>J(e),children:(0,ee.jsx)(en.A,{})}),"DELIVERY"===e.type&&(0,ee.jsx)(pe.A,{size:"small",color:"secondary",onClick:()=>Z(e),title:"Assign to Store",children:(0,ee.jsx)(As.A,{})})]})]},e.id)))})]})}),1===t&&(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"ID"}),(0,ee.jsx)(Yt.A,{children:"Email"}),(0,ee.jsx)(Yt.A,{children:"Mobile"}),(0,ee.jsx)(Yt.A,{children:"Status"}),(0,ee.jsx)(Yt.A,{children:"Referral ID"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:se().slice(a*d,a*d+d).map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.id}),(0,ee.jsx)(Yt.A,{children:e.email}),(0,ee.jsx)(Yt.A,{children:e.mobile||"N/A"}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,ee.jsx)(Yt.A,{children:e.referralId||"N/A"}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(pe.A,{size:"small",color:"primary",onClick:()=>J(e),children:(0,ee.jsx)(en.A,{})})})]},e.id)))})]})}),2===t&&(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"ID"}),(0,ee.jsx)(Yt.A,{children:"Email"}),(0,ee.jsx)(Yt.A,{children:"Mobile"}),(0,ee.jsx)(Yt.A,{children:"Status"}),(0,ee.jsx)(Yt.A,{children:"Referral ID"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:se().slice(a*d,a*d+d).map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.id}),(0,ee.jsx)(Yt.A,{children:e.email}),(0,ee.jsx)(Yt.A,{children:e.mobile||"N/A"}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,ee.jsx)(Yt.A,{children:e.referralId||"N/A"}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{size:"small",color:"primary",onClick:()=>J(e),children:(0,ee.jsx)(en.A,{})}),(0,ee.jsx)(pe.A,{size:"small",color:"secondary",onClick:()=>Z(e),title:"Assign to Store",children:(0,ee.jsx)(As.A,{})})]})]},e.id)))})]})}),3===t&&(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"ID"}),(0,ee.jsx)(Yt.A,{children:"Email"}),(0,ee.jsx)(Yt.A,{children:"Mobile"}),(0,ee.jsx)(Yt.A,{children:"Status"}),(0,ee.jsx)(Yt.A,{children:"Referral ID"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:se().slice(a*d,a*d+d).map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.id}),(0,ee.jsx)(Yt.A,{children:e.email}),(0,ee.jsx)(Yt.A,{children:e.mobile||"N/A"}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,ee.jsx)(Yt.A,{children:e.referralId||"N/A"}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(pe.A,{size:"small",color:"primary",onClick:()=>J(e),children:(0,ee.jsx)(en.A,{})})})]},e.id)))})]})}),(0,ee.jsx)(y.A,{component:"div",count:se().length,page:a,onPageChange:(e,s)=>{o(s)},rowsPerPage:d,onRowsPerPageChange:e=>{l(parseInt(e.target.value,10)),o(0)},sx:{mt:2}})]})]}),(0,ee.jsxs)(qe.A,{open:S,onClose:()=>C(!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,ee.jsx)(Re.A,{sx:{pb:1},children:"Update User Role"}),(0,ee.jsx)(ze.A,{children:v&&(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsxs)(m.A,{variant:"subtitle1",gutterBottom:!0,children:["User: ",v.email]}),(0,ee.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",v.id]}),(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mt:2},children:[(0,ee.jsx)(Jt.A,{children:"Role"}),(0,ee.jsxs)(Zt.A,{value:w,onChange:e=>{P(e.target.value)},label:"Role",sx:{mb:2},children:[(0,ee.jsx)(ge.A,{value:"USER",children:"User"}),(0,ee.jsx)(ge.A,{value:"ADMIN",children:"Admin"}),(0,ee.jsx)(ge.A,{value:"DELIVERY",children:"Delivery Partner"}),(0,ee.jsx)(ge.A,{value:"STORE_MANAGER",children:"Store Manager"})]})]})]})}),(0,ee.jsxs)(We.A,{sx:{px:3,py:2},children:[(0,ee.jsx)(te.A,{onClick:()=>C(!1),children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{if(!L)return void D({open:!0,message:"Admin ID not available. Please try again.",severity:"error"});Y.mutate({targetUserId:v.cognitoId,newType:{USER:"USER",ADMIN:"ADMIN",DELIVERY:"DELIVERY_AGENT",STORE_MANAGER:"STORE_MANAGER"}[w]||w})},variant:"contained",color:"primary",disabled:Y.isPending,children:Y.isPending?"Updating...":"Update Role"})]})]}),(0,ee.jsxs)(qe.A,{open:T,onClose:()=>q(!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,ee.jsx)(Re.A,{sx:{pb:1},children:"Assign Driver to Store"}),(0,ee.jsx)(ze.A,{children:v&&(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsxs)(m.A,{variant:"subtitle1",gutterBottom:!0,children:["Driver: ",v.email]}),(0,ee.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",v.id]}),(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,sx:{mt:2},children:"Select Store"}),H?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,ee.jsx)(j.A,{size:24})}):G?(0,ee.jsxs)(ae.A,{severity:"error",sx:{mb:2},children:["Error loading stores: ",G.message]}):Array.isArray(O)&&0!==O.length?(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mt:1},children:[(0,ee.jsx)(Jt.A,{children:"Store"}),(0,ee.jsx)(Zt.A,{value:z,onChange:e=>{W(e.target.value)},label:"Store",sx:{mb:2},children:O.map((e=>(0,ee.jsxs)(ge.A,{value:e.id,children:[e.name," - ",e.address]},e.id)))})]}):(0,ee.jsx)(ae.A,{severity:"info",sx:{mb:2},children:"No stores available"}),z&&ne()&&(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,children:"Current Drivers"}),ne()?.drivers?.edges?.length>0?(0,ee.jsx)(g.A,{sx:{mt:1},children:ne().drivers.edges.map(((e,s)=>(0,ee.jsx)(Fe.A,{label:e.node.driver.email,size:"small",sx:{mr:1,mb:1}},s)))}):(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"No drivers assigned to this store yet"})]})]})}),(0,ee.jsxs)(We.A,{sx:{px:3,py:2},children:[(0,ee.jsx)(te.A,{onClick:()=>q(!1),children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{z&&v?Q.mutate({storeId:parseInt(z),userId:parseInt(v.id)}):D({open:!0,message:"Please select a store",severity:"error"})},variant:"contained",color:"primary",disabled:!z||Q.isPending,children:Q.isPending?"Assigning...":"Assign to Store"})]})]}),(0,ee.jsx)(Xt.A,{open:F.open,autoHideDuration:6e3,onClose:X,message:F.message,children:(0,ee.jsx)(ae.A,{onClose:X,severity:F.severity,children:F.message})})]})};var nn=t(1405),rn=t(39738),an=t(82997),on=t(47363),dn=t(67110),ln=t(40250),cn=t(70765),xn=t(34337),un=t(72306),mn=t(79432);const hn=["Store Information","Inventory","Drivers","Store Managers","Review"],pn=()=>{const[e,s]=(0,x.useState)(0),[t,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[d,l]=(0,x.useState)(!1),[c,h]=(0,x.useState)({}),y=(0,Ee.A)(),[f,b]=((0,Es.A)(y.breakpoints.down("sm")),(0,x.useState)(0)),[I,S]=(0,x.useState)({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",displayField:"",sectionHeaders:[],inventory:[],drivers:[],storeManagers:[],pincodes:"",images:[],codEnabled:!1,whatsappNumber:""}),[C,w]=(0,x.useState)(null),[P,F]=(0,x.useState)([]),[D,L]=(0,x.useState)(!1),[$,T]=(0,x.useState)({open:!1,message:"",severity:"success"}),{data:q,isLoading:z,refetch:W}=(0,u.I)({queryKey:["stores"],queryFn:()=>k(R),enabled:r}),{data:O,isLoading:U}=(0,u.I)({queryKey:["users"],queryFn:async()=>{const e=await k(E);return e?.getAllUsers||[]},enabled:!0}),N=(0,x.useMemo)((()=>O&&Array.isArray(O)?O.filter((e=>{if(!e.type)return!1;const s=e.type.trim().toUpperCase();return"STORE_MANAGER"===s||"STOREMANAGER"===s||s.includes("STORE")&&s.includes("MANAGER")})):[]),[O]),B=(0,x.useMemo)((()=>q?.stores&&Array.isArray(q.stores)?q.stores.map((e=>e.managerUserId)).filter((e=>null!=e)):[]),[q]),_=(0,x.useMemo)((()=>{if(!N.length)return[];return N.filter((e=>!B.includes(e.id)))}),[N,B]),M=(0,x.useMemo)((()=>{if(!N.length||!C)return _;const e=B.filter((e=>e!==C.managerUserId));return N.filter((s=>!e.includes(s.id)))}),[N,B,C,_]);(0,x.useEffect)((()=>{if(1===e&&!C){const e=_.find((e=>String(e.id)===String(I.managerUserId)));e?S((s=>({...s,email:e.email||"",mobile:e.mobile||""}))):I.managerUserId&&!e&&S((e=>({...e,managerUserId:"",email:"",mobile:""})))}}),[I.managerUserId,_,e,C]);const V=(0,ds.n)({mutationFn:e=>k("\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 $images: [String!]\n $codEnabled: Boolean\n $whatsappNumber: 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 images: $images\n codEnabled: $codEnabled\n whatsappNumber: $whatsappNumber\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 images\n codEnabled\n whatsappNumber\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:()=>{l(!0),o(null),S({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",displayField:"",sectionHeaders:[],inventory:[],drivers:[],storeManagers:[],pincodes:"",images:[],codEnabled:!1,whatsappNumber:""}),b(0),W()},onError:e=>{o(e.message||"Failed to create store"),l(!1)}}),H=(0,ds.n)({mutationFn:e=>k("\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 $images: [String!]\n $whatsappNumber: 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 images: $images\n whatsappNumber: $whatsappNumber\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 images\n whatsappNumber\n }\n }\n",e),onSuccess:(e,s)=>{q&&q.stores&&q.stores.forEach((e=>{e.id===s.storeId&&Object.assign(e,s)})),T({open:!0,message:"Store updated successfully",severity:"success"}),w(null)},onError:e=>{T({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),G=()=>{i(!0),W()},K=e=>{const{name:s,value:t}=e.target;S((e=>({...e,[s]:t}))),c[s]&&h((e=>({...e,[s]:null}))),a&&o(null)},Y=()=>{S((e=>({...e,sectionHeaders:[...e.sectionHeaders,""]})))},Q=async function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return;const t=s?C?.id:null;if(!s||t){L(!0);try{const n=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",r=await(0,v.$)(),i=r.tokens?.accessToken?.toString(),a={"Content-Type":"application/json"};i&&(a.Authorization=`Bearer ${i}`);const o=t?t.toString():"new",d=await fetch(`${n}/s3/generate-store-upload-url?store_id=${o}&file_name=${encodeURIComponent(e.name)}`,{method:"GET",headers:a});if(!d.ok){let e="Failed to get upload URL";try{const s=await d.json();e=s.detail||s.message||e}catch(s){e=d.statusText||e}throw new Error(e)}const{upload_url:l,content_type:c,key:x}=await d.json();if(!(await fetch(l,{method:"PUT",headers:{"Content-Type":c},body:e})).ok)throw new Error("Failed to upload image");const u=`https://indimitra-dev-order-files.s3.amazonaws.com/${x}`;s?F((e=>[...e,u])):S((e=>({...e,images:[...e.images,u]}))),T({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){T({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{L(!1)}}else T({open:!0,message:"Store ID is required for image upload",severity:"error"})},J=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?F((s=>s.filter(((s,t)=>t!==e)))):S((s=>({...s,images:s.images.filter(((s,t)=>t!==e))})))},Z=()=>{const e={};return I.name.trim()||(e.name="Store name is required"),I.address.trim()||(e.address="Address is required"),I.email.trim()||(e.email="Manager email is required"),I.mobile.trim()||(e.mobile="Manager mobile is required"),I.managerUserId||(e.managerUserId="Manager User ID is required"),I.radius&&!isNaN(parseFloat(I.radius))||(e.radius="Delivery radius is required"),I.displayField.trim()||(e.displayField="Display Field is required"),h(e),0===Object.keys(e).length},X=()=>{w(null),F([])},se=q?.stores?.filter((e=>e.name.toLowerCase().includes(t.toLowerCase())||e.address.toLowerCase().includes(t.toLowerCase())))||[];return(0,x.useEffect)((()=>{let e;return d&&(e=setTimeout((()=>{l(!1)}),5e3)),()=>{e&&clearTimeout(e)}}),[d]),(0,ee.jsxs)(g.A,{children:[(0,ee.jsxs)(de.A,{sx:{p:{xs:1,sm:3},mb:3,mx:{xs:0,sm:"auto"},width:{xs:"100%",sm:"auto"},boxShadow:{xs:0,sm:3},borderRadius:{xs:0,sm:2}},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ee.jsx)(bt.A,{sx:{mr:1}}),(0,ee.jsx)(m.A,{variant:"h5",children:"Store Management"})]}),(0,ee.jsxs)(rt.A,{value:e,onChange:(e,t)=>{s(t)},sx:{mb:3},children:[(0,ee.jsx)(it.A,{label:"Store List"}),(0,ee.jsx)(it.A,{label:"Add New Store"})]}),a&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:3},children:a}),d&&(0,ee.jsx)(ae.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,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(g.A,{sx:{mb:3},children:(0,ee.jsx)(p.A,{fullWidth:!0,variant:"outlined",placeholder:"Search stores...",value:t,onChange:e=>n(e.target.value),InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(sn.A,{})})}})}),r?z?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,ee.jsx)(j.A,{})}):0===se.length?(0,ee.jsx)(ae.A,{severity:"info",sx:{mb:3},children:"No stores found matching your criteria"}):(0,ee.jsx)(ye.Ay,{container:!0,spacing:3,children:se.map((e=>(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(de.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,ee.jsx)(g.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,ee.jsxs)(ye.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ee.jsx)(bt.A,{sx:{mr:2,color:"white",fontSize:"2rem"}}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{className:"store-name",variant:"h6",sx:{color:"white",fontWeight:600,transition:"color 0.3s ease-in-out"},children:e.name}),(0,ee.jsxs)(m.A,{className:"store-id",variant:"body2",sx:{color:"rgba(255, 255, 255, 0.8)",transition:"color 0.3s ease-in-out"},children:["ID: ",e.id]})]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",md:"flex-end"},gap:2},children:[(0,ee.jsx)(Fe.A,{label:e.isActive?"Active":"Inactive",color:e.isActive?"success":"error",sx:{fontWeight:600,boxShadow:2,"& .MuiChip-label":{px:1}}}),(0,ee.jsx)(g.A,{className:"action-buttons",sx:{display:"flex",gap:1,opacity:.9},children:(0,ee.jsx)(te.A,{size:"small",startIcon:(0,ee.jsx)(en.A,{}),sx:{fontWeight:600,textTransform:"none",color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},onClick:()=>(e=>{w(e),F(e.images||[])})(e),children:"Edit"})})]})})]})}),(0,ee.jsx)(g.A,{sx:{p:3},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"subtitle2",sx:{mb:2,fontWeight:600,color:"primary.main",display:"flex",alignItems:"center","&::before":{content:'""',display:"inline-block",width:4,height:16,backgroundColor:"primary.main",marginRight:1,borderRadius:1}},children:"Contact Information"}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,ee.jsx)(Ut.A,{sx:{mr:1.5,color:"primary.main",mt:.3,flexShrink:0,fontSize:"1.2rem"}}),(0,ee.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.address})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ee.jsx)(cn.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ee.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.mobile||"No contact info"})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ee.jsx)(xn.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ee.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.email||"No email info"})]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"subtitle2",sx:{mb:2,fontWeight:600,color:"primary.main",display:"flex",alignItems:"center","&::before":{content:'""',display:"inline-block",width:4,height:16,backgroundColor:"primary.main",marginRight:1,borderRadius:1}},children:"Delivery Information"}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ee.jsx)(As.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ee.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Radius: ",e.radius," mi"]})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ee.jsx)(un.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ee.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Delivery Fee: $",e.storeDeliveryFee?.toFixed(2)||"0.00"]})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ee.jsx)(mn.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ee.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Tax Rate: ",e.taxPercentage?.toFixed(1)||"0.0","%"]})]}),e.pincodes&&e.pincodes.length>0&&(0,ee.jsx)(g.A,{sx:{display:"flex",flexWrap:"wrap",gap:.8},children:e.pincodes.map((e=>(0,ee.jsx)(Fe.A,{label:e,size:"small",sx:{backgroundColor:"primary.light",color:"primary.contrastText",fontWeight:600,transition:"all 0.2s ease-in-out","&:hover":{backgroundColor:"primary.main",transform:"scale(1.05)"}}},e)))})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(g.A,{children:[e.description&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",sx:{mb:2,fontWeight:600,color:"primary.main",display:"flex",alignItems:"center","&::before":{content:'""',display:"inline-block",width:4,height:16,backgroundColor:"primary.main",marginRight:1,borderRadius:1}},children:"Description"}),(0,ee.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.description})]}),e.tnc&&(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"subtitle2",sx:{mb:2,fontWeight:600,color:"primary.main",display:"flex",alignItems:"center","&::before":{content:'""',display:"inline-block",width:4,height:16,backgroundColor:"primary.main",marginRight:1,borderRadius:1}},children:"Terms & Conditions"}),(0,ee.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.tnc})]})]})})]})})]})},e.id)))}):(0,ee.jsxs)(fe.A,{sx:{mb:3},children:[(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Stores" to load store data'}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]}),(0,ee.jsx)(Ie.A,{sx:{justifyContent:"center"},children:(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:(0,ee.jsx)(ln.A,{}),onClick:G,children:"Fetch Stores"})})]})]}):1!==e||q?.stores||r?(0,ee.jsxs)(g.A,{sx:{maxWidth:{xs:"100%",sm:600,md:800},mx:"auto",p:{xs:1,sm:2}},children:[(0,ee.jsx)(g.A,{sx:{overflowX:{xs:"auto",sm:"visible"},mb:{xs:2,sm:4}},children:(0,ee.jsx)(rn.A,{activeStep:f,sx:{minWidth:500},children:hn.map((e=>(0,ee.jsx)(an.A,{children:(0,ee.jsx)(on.A,{children:(0,ee.jsx)(m.A,{sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:e})})},e)))})}),(0,ee.jsx)(g.A,{sx:{px:{xs:.5,sm:0}},children:(e=>{switch(e){case 0:return(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Basic Store Information"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{required:!0,fullWidth:!0,label:"Store Name",name:"name",value:I.name,onChange:K,error:!!c.name,helperText:c.name})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{required:!0,fullWidth:!0,label:"Address",name:"address",value:I.address,onChange:K,error:!!c.address,helperText:c.address})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(cs.A,{required:!0,fullWidth:!0,error:!!c.managerUserId,children:[(0,ee.jsx)(Jt.A,{children:"Manager User ID"}),(0,ee.jsx)(Zt.A,{label:"Manager User ID",name:"managerUserId",value:I.managerUserId,onChange:K,children:U?(0,ee.jsx)(ge.A,{value:"",disabled:!0,children:(0,ee.jsx)("em",{children:"Loading..."})}):0===_.length?(0,ee.jsx)(ge.A,{value:"",disabled:!0,children:(0,ee.jsx)("em",{children:"No available managers (all managers are assigned)"})}):_.map((e=>(0,ee.jsxs)(ge.A,{value:e.id,children:[e.id," - ",e.email," ",e.name?`(${e.name})`:""]},e.id)))}),(0,ee.jsx)(m.A,{variant:"caption",color:"error",children:c.managerUserId}),0===_.length&&!U&&(0,ee.jsx)(m.A,{variant:"caption",color:"warning.main",sx:{mt:1,display:"block"},children:"All store managers are currently assigned. Please create new manager accounts or unassign existing ones."})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{required:!0,fullWidth:!0,label:"Manager Email",name:"email",type:"email",value:I.email,InputProps:{readOnly:!0},error:!!c.email,helperText:c.email})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{required:!0,fullWidth:!0,label:"Manager Mobile",name:"mobile",value:I.mobile,InputProps:{readOnly:!0},error:!!c.mobile,helperText:c.mobile})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{required:!0,fullWidth:!0,label:"Delivery Radius (mi)",name:"radius",type:"number",value:I.radius,onChange:K,inputProps:{step:"0.1"},error:!!c.radius,helperText:c.radius})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Delivery Fee ($)",name:"storeDeliveryFee",type:"number",value:I.storeDeliveryFee,onChange:K,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:"$"})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Tax Rate (%)",name:"taxPercentage",type:"number",value:I.taxPercentage,onChange:K,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,ee.jsx)(A.A,{position:"end",children:"%"})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Description",name:"description",value:I.description,onChange:K,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Terms & Conditions",name:"tnc",value:I.tnc,onChange:K,multiline:!0,rows:3})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Delivery Pincodes",name:"pincodes",value:I.pincodes,onChange:K,helperText:"Enter pincodes separated by commas"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{required:!0,fullWidth:!0,label:"Display Field",name:"displayField",value:I.displayField,onChange:K,error:!!c.displayField,helperText:c.displayField||"Unique identifier for the store"})}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,ee.jsxs)(g.A,{sx:{mb:2},children:[I.sectionHeaders.map(((e,s)=>(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,ee.jsx)(p.A,{fullWidth:!0,label:`Question ${s+1}`,value:e,onChange:e=>((e,s)=>{const t=[...I.sectionHeaders];t[e]=s,S((e=>({...e,sectionHeaders:t})))})(s,e.target.value),placeholder:"Enter question text"}),(0,ee.jsx)(pe.A,{color:"error",onClick:()=>(e=>{const s=I.sectionHeaders.filter(((s,t)=>t!==e));S((e=>({...e,sectionHeaders:s})))})(s),sx:{alignSelf:"center"},children:(0,ee.jsx)(dn.A,{})})]},s))),(0,ee.jsx)(te.A,{startIcon:(0,ee.jsx)(we.A,{}),onClick:Y,variant:"outlined",sx:{mt:1},children:"Add Question"})]})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Images"}),(0,ee.jsxs)(g.A,{sx:{mb:2},children:[(0,ee.jsx)("input",{accept:"image/*",style:{display:"none"},id:"store-image-upload",type:"file",onChange:e=>{const s=e.target.files[0];s&&Q(s,!1),e.target.value=""}}),(0,ee.jsx)("label",{htmlFor:"store-image-upload",children:(0,ee.jsx)(te.A,{variant:"outlined",component:"span",startIcon:(0,ee.jsx)(we.A,{}),disabled:D,sx:{mb:2},children:D?"Uploading...":"Upload Image"})}),I.images&&I.images.length>0&&(0,ee.jsx)(g.A,{sx:{display:"flex",flexWrap:"wrap",gap:2,mt:2},children:I.images.map(((e,s)=>(0,ee.jsxs)(g.A,{sx:{position:"relative",width:150,height:150},children:[(0,ee.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,ee.jsx)(pe.A,{size:"small",color:"error",onClick:()=>J(s,!1),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,ee.jsx)(dn.A,{fontSize:"small"})})]},s)))})]})]}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:2,border:"1px solid",borderColor:"divider",borderRadius:1,bgcolor:"background.paper"},children:[(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Cash on Delivery"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Accept cash payments when orders are delivered"})]}),(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(nn.A,{checked:I.codEnabled,onChange:e=>S((s=>({...s,codEnabled:e.target.checked}))),color:"primary"}),label:I.codEnabled?"Enabled":"Disabled",labelPlacement:"start"})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{label:"WhatsApp Support Number",placeholder:"+1234567890",value:I.whatsappNumber,onChange:e=>S((s=>({...s,whatsappNumber:e.target.value}))),fullWidth:!0,helperText:"Include country code (e.g., +1 for US). Optional."})})]});case 1:return(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Inventory Management"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",paragraph:!0,children:"This is a placeholder for inventory management. In a real implementation, you would be able to add products to the store."})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsxs)(de.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Inventory Items"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ee.jsx)(fe.A,{variant:"outlined",children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",children:"Product 1"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Grocery"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $9.99"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 50"})]})})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ee.jsx)(fe.A,{variant:"outlined",children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",children:"Product 2"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Electronics"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $49.99"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 25"})]})})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ee.jsx)(fe.A,{variant:"outlined",children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",children:"Product 3"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Clothing"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $19.99"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 100"})]})})})]})]}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,ee.jsx)(te.A,{variant:"outlined",startIcon:(0,ee.jsx)(we.A,{}),children:"Add Inventory Item"})})]})]});case 2:return(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Driver Management"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",paragraph:!0,children:"This is a placeholder for driver management. In a real implementation, you would be able to assign drivers to the store."})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsxs)(de.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Drivers"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ee.jsx)(fe.A,{variant:"outlined",children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",children:"John Doe"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: john.doe@example.com"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 123-4567"}),(0,ee.jsx)(Fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ee.jsx)(fe.A,{variant:"outlined",children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",children:"Jane Smith"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: jane.smith@example.com"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 987-6543"}),(0,ee.jsx)(Fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ee.jsx)(fe.A,{variant:"outlined",children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",children:"Mike Johnson"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: mike.johnson@example.com"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 456-7890"}),(0,ee.jsx)(Fe.A,{label:"Inactive",color:"error",size:"small",sx:{mt:1}})]})})})]})]}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,ee.jsx)(te.A,{variant:"outlined",startIcon:(0,ee.jsx)(we.A,{}),children:"Add Driver"})})]})]});case 3:return(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Store Manager Management"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",paragraph:!0,children:"This is a placeholder for store manager management. In a real implementation, you would be able to assign managers to the store."})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsxs)(de.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Store Managers"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,children:(0,ee.jsx)(fe.A,{variant:"outlined",children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",children:"Sarah Williams"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: sarah.williams@example.com"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 234-5678"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Role: Store Manager"}),(0,ee.jsx)(Fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,children:(0,ee.jsx)(fe.A,{variant:"outlined",children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",children:"Robert Brown"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: robert.brown@example.com"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 876-5432"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Role: Assistant Manager"}),(0,ee.jsx)(Fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})})]})]}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,ee.jsx)(te.A,{variant:"outlined",startIcon:(0,ee.jsx)(we.A,{}),children:"Add Store Manager"})})]})]});case 4:return(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Review Store Information"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(de.A,{variant:"outlined",sx:{p:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Details"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"Name:"})," ",I.name]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"Address:"})," ",I.address]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"Manager User ID:"})," ",I.managerUserId]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"Delivery Radius:"})," ",I.radius," km"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"Cash on Delivery:"})," ",I.codEnabled?"Enabled":"Disabled"]})}),I.whatsappNumber&&(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"WhatsApp:"})," ",I.whatsappNumber]})})]}),(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Additional Information (Placeholder)"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"Inventory Items:"})," 3 sample items"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"Drivers:"})," 3 sample drivers"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"body2",children:[(0,ee.jsx)("strong",{children:"Store Managers:"})," 2 sample managers"]})})]})]})})]});default:return null}})(f)}),(0,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",mt:3,gap:2},children:[(0,ee.jsx)(te.A,{fullWidth:!0,disabled:0===f,onClick:()=>{b((e=>e-1))},sx:{py:1,fontSize:{xs:"1rem",sm:"1.05rem"}},children:"Back"}),(0,ee.jsx)(te.A,{fullWidth:!0,variant:"contained",color:"primary",onClick:f===hn.length-1?()=>{if(!Z())return void o("Please fill in all required fields");const e=I.pincodes,s=e?e.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],t={name:I.name,address:I.address,managerUserId:parseInt(I.managerUserId,10),radius:parseFloat(I.radius),email:I.email,mobile:I.mobile,description:I.description||null,storeDeliveryFee:I.storeDeliveryFee?parseFloat(I.storeDeliveryFee):null,taxPercentage:I.taxPercentage?parseFloat(I.taxPercentage):null,tnc:I.tnc||null,displayField:I.displayField,sectionHeaders:I.sectionHeaders.filter((e=>e.trim().length>0)),pincodes:s,images:I.images||[],is_active:!0,disabled:!1,codEnabled:I.codEnabled,whatsappNumber:I.whatsappNumber||null};V.mutate(t)}:()=>{0!==f||Z()?b((e=>e+1)):o("Please fill in all required fields")},disabled:V.isLoading,sx:{py:1,fontSize:{xs:"1rem",sm:"1.05rem"}},children:V.isLoading?(0,ee.jsx)(j.A,{size:24}):f===hn.length-1?"Submit":"Next"})]})]}):(0,ee.jsxs)(fe.A,{sx:{mb:3},children:[(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:"Loading store data for manager availability check..."}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"We need to check which managers are already assigned before showing available options."})]}),(0,ee.jsx)(Ie.A,{sx:{justifyContent:"center"},children:(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:(0,ee.jsx)(ln.A,{}),onClick:G,children:"Load Store Data"})})]})]}),(0,ee.jsxs)(qe.A,{open:!!C,onClose:X,maxWidth:"md",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(bt.A,{}),(0,ee.jsx)(m.A,{variant:"h6",children:"Edit Store"})]})}),(0,ee.jsxs)("form",{onSubmit:e=>{e.preventDefault();const s=new FormData(e.target),t=s.get("pincodes"),n=t?t.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],r=s.get("sectionHeaders"),i=r?r.split("\n").map((e=>e.trim())).filter((e=>e.length>0)):[],a={storeId:C.id,name:s.get("name"),address:s.get("address"),email:s.get("email"),mobile:s.get("mobile")||null,managerUserId:parseInt(s.get("managerUserId")),radius:parseFloat(s.get("radius")),isActive:"true"===s.get("isActive"),disabled:"true"===s.get("disabled"),description:s.get("description")||null,pincodes:n,tnc:s.get("tnc")||null,storeDeliveryFee:parseFloat(s.get("storeDeliveryFee"))||null,taxPercentage:parseFloat(s.get("taxPercentage"))||null,displayField:s.get("displayField"),sectionHeaders:i,images:P,whatsappNumber:s.get("whatsappNumber")||null};H.mutate(a)},children:[(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"name",label:"Store Name",defaultValue:C?.name,required:!0,fullWidth:!0})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"email",label:"Email",type:"email",defaultValue:C?.email,required:!0,fullWidth:!0})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"mobile",label:"Mobile Number",defaultValue:C?.mobile,fullWidth:!0})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(cs.A,{required:!0,fullWidth:!0,children:[(0,ee.jsx)(Jt.A,{children:"Manager User ID"}),(0,ee.jsx)(Zt.A,{name:"managerUserId",label:"Manager User ID",defaultValue:C?.managerUserId,children:U?(0,ee.jsx)(ge.A,{value:"",disabled:!0,children:(0,ee.jsx)("em",{children:"Loading..."})}):0===M.length?(0,ee.jsx)(ge.A,{value:"",disabled:!0,children:(0,ee.jsx)("em",{children:"No available managers"})}):M.map((e=>(0,ee.jsxs)(ge.A,{value:e.id,children:[e.id," - ",e.email," ",e.name?`(${e.name})`:""]},e.id)))})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{name:"displayField",label:"Display Field",defaultValue:C?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.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,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Images"}),(0,ee.jsxs)(g.A,{sx:{mb:2},children:[(0,ee.jsx)("input",{accept:"image/*",style:{display:"none"},id:"edit-store-image-upload",type:"file",onChange:e=>{const s=e.target.files[0];s&&Q(s,!0),e.target.value=""}}),(0,ee.jsx)("label",{htmlFor:"edit-store-image-upload",children:(0,ee.jsx)(te.A,{variant:"outlined",component:"span",startIcon:(0,ee.jsx)(we.A,{}),disabled:D,sx:{mb:2},children:D?"Uploading...":"Upload Image"})}),P&&P.length>0&&(0,ee.jsx)(g.A,{sx:{display:"flex",flexWrap:"wrap",gap:2,mt:2},children:P.map(((e,s)=>(0,ee.jsxs)(g.A,{sx:{position:"relative",width:150,height:150},children:[(0,ee.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,ee.jsx)(pe.A,{size:"small",color:"error",onClick:()=>J(s,!0),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,ee.jsx)(dn.A,{fontSize:"small"})})]},s)))})]})]}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{name:"address",label:"Address",defaultValue:C?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:C?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:C?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:"$"})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:C?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,ee.jsx)(A.A,{position:"end",children:"%"})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:C?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{name:"description",label:"Description",defaultValue:C?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{name:"tnc",label:"Terms & Conditions",defaultValue:C?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"whatsappNumber",label:"WhatsApp Support Number",placeholder:"+1234567890",defaultValue:C?.whatsappNumber,fullWidth:!0,helperText:"Include country code. Optional."})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,children:[(0,ee.jsx)(Jt.A,{children:"Store Status"}),(0,ee.jsxs)(Zt.A,{name:"isActive",label:"Store Status",defaultValue:C?.isActive,children:[(0,ee.jsx)(ge.A,{value:!0,children:"Active"}),(0,ee.jsx)(ge.A,{value:!1,children:"Inactive"})]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,children:[(0,ee.jsx)(Jt.A,{children:"Disabled Status"}),(0,ee.jsxs)(Zt.A,{name:"disabled",label:"Disabled Status",defaultValue:C?.disabled,children:[(0,ee.jsx)(ge.A,{value:!0,children:"Disabled"}),(0,ee.jsx)(ge.A,{value:!1,children:"Enabled"})]})]})})]})}),(0,ee.jsxs)(We.A,{sx:{p:3,pt:0},children:[(0,ee.jsx)(te.A,{onClick:X,children:"Cancel"}),(0,ee.jsx)(te.A,{type:"submit",variant:"contained",disabled:H.isPending,startIcon:H.isPending?(0,ee.jsx)(j.A,{size:20}):null,children:H.isPending?"Updating...":"Update Store"})]})]})]}),(0,ee.jsx)(Xt.A,{open:$.open,autoHideDuration:6e3,onClose:()=>T({...$,open:!1}),children:(0,ee.jsx)(ae.A,{onClose:()=>T({...$,open:!1}),severity:$.severity,sx:{width:"100%"},children:$.message})})]})};var An=t(15068);const gn=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(!1),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)({name:"",description:"",categoryId:"",image:""}),[d,l]=(0,x.useState)(!1),[c,h]=(0,x.useState)(!1),[A,f]=(0,x.useState)(null),[b,v]=(0,x.useState)(!1),[I,S]=(0,x.useState)(""),[C,w]=(0,x.useState)(""),[P,E]=(0,x.useState)(0),[F,D]=(0,x.useState)(10),[L,$]=(0,x.useState)([]),[T,q]=(0,x.useState)(""),[R,W]=(0,x.useState)(!1),[O,U]=(0,x.useState)({open:!1,message:"",severity:"info"}),[N,B]=(0,x.useState)(""),_=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",{data:M,refetch:V}=(0,u.I)({queryKey:["products",e],queryFn:()=>k(z),enabled:!1}),{data:H,refetch:G}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await k("\n query GetCategories {\n categories {\n id\n name\n }\n }\n")).categories||[]}),K=(0,ds.n)({mutationFn:e=>k("\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:()=>{ne(),X(),U({open:!0,message:"Product added successfully!",severity:"success"})}}),Y=(0,ds.n)({mutationFn:e=>{let{productId:s,name:t,description:n,categoryId:r,image:i}=e;return k("\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:s,name:t,description:n,categoryId:parseInt(r,10),image:i||null})},onSuccess:(e,s)=>{$((e=>e.map((e=>e.id===s.productId?{...e,name:s.name,description:s.description,categoryId:s.categoryId,image:s.image}:e)))),X(),U({open:!0,message:"Product updated successfully!",severity:"success"})},onError:e=>{U({open:!0,message:`Failed to update product: ${e.message}`,severity:"error"})}}),Q=((0,ds.n)({mutationFn:e=>k("\n mutation DeleteProduct($productId: Int!) {\n deleteProduct(productId: $productId)\n }\n",{productId:e}),onSuccess:()=>{V()}}),(0,ds.n)({mutationFn:e=>k("\n mutation CreateCategory($name: String!) {\n createCategory(name: $name) {\n category {\n id\n name\n }\n }\n }\n",{name:e}),onSuccess:()=>{v(!1),S(""),w(""),G()},onError:e=>{w(e.message||"Failed to create category")}})),J=(0,x.useMemo)((()=>H?H.reduce(((e,s)=>(e[s.id]=s.name,e)),{}):{}),[H]),Z=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)},X=()=>{n(!1),i(null),o({name:"",description:"",categoryId:"",image:""})},se=e=>{const{name:s,value:t}=e.target;"categoryId"!==s||"new"!==t?(o((e=>({...e,[s]:t}))),B("")):v(!0)},ne=()=>{h(!0),f(null),V().then((e=>{e.data?.products&&$(e.data.products),l(!0),h(!1)})).catch((e=>{f("Failed to load products. Please try again."),h(!1)}))},re=()=>{I.trim()?Q.mutate(I.trim()):w("Category name is required")},ie=(0,x.useMemo)((()=>e?L.filter((s=>s.categoryId===parseInt(e))):L),[L,e]),oe=(0,x.useMemo)((()=>{const e=P*F;return ie.slice(e,e+F)}),[ie,P,F]),le=()=>{U((e=>({...e,open:!1})))};return(0,ee.jsxs)(g.A,{children:[(0,ee.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ee.jsx)(we.A,{sx:{mr:1}}),(0,ee.jsx)(m.A,{variant:"h5",children:"Product Management"})]}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,children:[(0,ee.jsx)(Jt.A,{children:"Category"}),(0,ee.jsxs)(Zt.A,{value:e,onChange:e=>s(e.target.value),label:"Category",children:[(0,ee.jsx)(ge.A,{value:"",children:"All Categories"}),Object.entries(J).map((e=>{let[s,t]=e;return(0,ee.jsx)(ge.A,{value:s,children:t},s)}))]})]})}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,md:8,sx:{display:"flex",alignItems:"center",gap:2},children:[(0,ee.jsx)(te.A,{variant:"contained",startIcon:(0,ee.jsx)(ln.A,{}),onClick:ne,disabled:c,sx:{minWidth:150},children:c?(0,ee.jsx)(j.A,{size:24}):"Fetch Products"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:(0,ee.jsx)(we.A,{}),onClick:()=>Z(),children:"Add Product"})]})]}),A&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:3},children:A}),d?c?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ee.jsx)(j.A,{})}):(0,ee.jsx)(ee.Fragment,{children:(0,ee.jsxs)(Vt.A,{component:de.A,children:[(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Image"}),(0,ee.jsx)(Yt.A,{children:"Name"}),(0,ee.jsx)(Yt.A,{children:"Category"}),(0,ee.jsx)(Yt.A,{children:"Description"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:oe.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)("img",{src:e.image,alt:e.name,style:{width:"50px",height:"50px",objectFit:"cover"}})}),(0,ee.jsx)(Yt.A,{children:e.name}),(0,ee.jsx)(Yt.A,{children:J[e.categoryId]||"Unknown"}),(0,ee.jsx)(Yt.A,{children:e.description}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(pe.A,{size:"small",onClick:()=>Z(e),children:(0,ee.jsx)(en.A,{})})})]},e.id)))})]}),(0,ee.jsx)(y.A,{component:"div",count:ie.length,page:P,onPageChange:(e,s)=>{E(s)},rowsPerPage:F,onRowsPerPageChange:e=>{D(parseInt(e.target.value,10)),E(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,ee.jsxs)(g.A,{sx:{textAlign:"center",py:4},children:[(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Products" to load product information'}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,ee.jsxs)(qe.A,{open:t,onClose:X,maxWidth:"md",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:r?"Edit Product":"Add New Product"}),(0,ee.jsxs)(ze.A,{children:[N&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:N}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{required:!0,fullWidth:!0,label:"Product Name",name:"name",value:a.name,onChange:se})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,required:!0,children:[(0,ee.jsx)(Jt.A,{children:"Category"}),(0,ee.jsxs)(Zt.A,{name:"categoryId",value:a.categoryId,onChange:se,label:"Category",children:[(0,ee.jsx)(ge.A,{value:"",children:(0,ee.jsx)("em",{children:"Select a category"})}),Object.entries(J).map((e=>{let[s,t]=e;return(0,ee.jsx)(ge.A,{value:s,children:t},s)})),(0,ee.jsx)(ge.A,{value:"new",sx:{borderTop:"1px solid #e0e0e0",mt:1},children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",color:"primary.main"},children:[(0,ee.jsx)(we.A,{sx:{mr:1}}),"Add New Category"]})})]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{required:!0,fullWidth:!0,multiline:!0,rows:3,label:"Description",name:"description",value:a.description,onChange:se})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",gap:1},children:[(0,ee.jsx)(p.A,{fullWidth:!0,label:"Image URL",name:"image",value:a.image,onChange:se,placeholder:"https://example.com/image.jpg",disabled:R,error:!!T,helperText:T}),(0,ee.jsxs)(te.A,{variant:"outlined",component:"label",startIcon:(0,ee.jsx)(An.A,{}),disabled:R||!a.name||!a.categoryId,children:[R?"Uploading...":"Upload Image",(0,ee.jsx)("input",{type:"file",hidden:!0,accept:"image/*",onChange:async e=>{const s=e.target.files[0];if(!s)return;if(["image/jpeg","image/png","image/gif","image/webp"].includes(s.type))if(s.size>5242880)q("Image size should be less than 5MB");else try{W(!0),q("");const e=J[a.categoryId]||"uncategorized",t=await fetch(`${_}/s3/generate-product-upload-url?product_name=${encodeURIComponent(a.name)}&category_name=${encodeURIComponent(e)}&file_name=${encodeURIComponent(s.name)}`);if(!t.ok)throw new Error("Failed to get upload URL");const{upload_url:n,content_type:r,key:i}=await t.json();if(!(await fetch(n,{method:"PUT",headers:{"Content-Type":r},body:s})).ok)throw new Error("Failed to upload image");const d=`https://indimitra-dev-order-files.s3.amazonaws.com/${i}`;o((e=>({...e,image:d}))),U({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){q("Failed to upload image. Please try again."),U({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{W(!1)}else q("Please upload a valid image file (JPEG, PNG, GIF, or WebP)")},disabled:R})]}),a.image&&(0,ee.jsx)(g.A,{sx:{mt:1},children:(0,ee.jsx)("img",{src:a.image,alt:"Product preview",style:{maxWidth:"200px",maxHeight:"200px",objectFit:"contain"}})})]})})]})]}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:X,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",onClick:()=>{if(a.name.trim()&&a.description.trim()&&a.categoryId&&a.image)if(B(""),r)Y.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.isPending||K.isLoading||Y.isPending||Y.isLoading,startIcon:K.isPending||K.isLoading||Y.isPending||Y.isLoading?(0,ee.jsx)(j.A,{size:20,color:"inherit"}):null,children:K.isPending||K.isLoading||Y.isPending||Y.isLoading?r?"Updating...":"Creating...":r?"Update":"Add"})]})]}),(0,ee.jsxs)(qe.A,{open:b,onClose:()=>v(!1),children:[(0,ee.jsx)(Re.A,{children:"Add New Category"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(p.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:I,onChange:e=>S(e.target.value),error:!!C,helperText:C,onKeyPress:e=>{"Enter"===e.key&&re()}})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>v(!1),children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:re,variant:"contained",disabled:Q.isPending,children:Q.isPending?"Creating...":"Create"})]})]}),(0,ee.jsx)(Xt.A,{open:O.open,autoHideDuration:6e3,onClose:le,anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,ee.jsx)(ae.A,{onClose:le,severity:O.severity,sx:{width:"100%"},children:O.message})})]})};var jn=t(75813),yn=t(8047),fn=t(89966),bn=t(52653);const vn=[{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"}],In=("sandbox-preview-mode"?.startsWith("sandbox-"),()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[d,l]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null),[y,f]=(0,x.useState)(!1),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[C,w]=(0,x.useState)(""),[P,E]=(0,x.useState)(""),[D,L]=(0,x.useState)(!1),[T,q]=(0,x.useState)({open:!1,message:"",severity:"info"}),[z,W]=(0,x.useState)(!1);(0,x.useEffect)((()=>{if(c){W(!0);const e=setTimeout((()=>{W(!1),h(null)}),4e3);return()=>clearTimeout(e)}}),[c]);const{data:O,isLoading:U,refetch:N}=(0,u.I)({queryKey:["orders",t,e],queryFn:()=>k("\nquery GetAllOrders {\n getAllOrders {\n id\n creator {\n email\n mobile\n }\n type\n pickupId\n pickupAddress {\n id\n address\n storeId\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:d}),{data:B}=(0,u.I)({queryKey:["storeDrivers",a?.storeId],queryFn:async()=>a?.storeId?await k($,{storeId:a.storeId}):null,enabled:!!a?.storeId}),{data:_={stores:[]},isLoading:M}=(0,u.I)({queryKey:["stores"],queryFn:()=>k(R),enabled:d}),V=x.useMemo((()=>{const e={};return(_.stores||[]).forEach((s=>{e[s.id]=s})),e}),[_]),H=(0,ds.n)({mutationFn:async e=>await k(F,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onMutate:()=>{L(!0)},onSuccess:(e,s)=>{L(!1),O&&O.getAllOrders&&O.getAllOrders.forEach((e=>{e.id===s.orderId&&Object.assign(e,s)})),f(!1),o(null),v(""),S(""),w(""),E(""),q({open:!0,message:"Order status updated successfully!",severity:"success"})},onError:e=>{L(!1),h(e.message),f(!1),q({open:!0,message:`Failed to update order status: ${e.message}`,severity:"error"})}}),G=()=>{i(!1),o(null)},K=e=>{const{name:t,value:r}=e.target;"searchTerm"===t?s(r):"statusFilter"===t&&n(r)},Y=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,ee.jsx)(jn.A,{});case"CANCELLED":return(0,ee.jsx)(yn.A,{});case"PENDING":return(0,ee.jsx)(fn.A,{});default:return null}},Q=e=>{if(!e)return"Not scheduled";return new Date(e).toLocaleString()},J=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e),Z=O?.getAllOrders?.filter((s=>{const n="PICKUP"===s.type?s.pickupAddress?.address:s.address?.address,r=""===e||n?.toLowerCase().includes(e.toLowerCase())||s.id.toString().includes(e),i=""===t||s.status===t;return r&&i}));return(0,ee.jsxs)(g.A,{children:[(0,ee.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ee.jsx)(Ps.A,{sx:{mr:1}}),(0,ee.jsx)(m.A,{variant:"h5",children:"Orders Management"})]}),c&&z&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:3},onClose:()=>W(!1),children:c}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsx)(p.A,{fullWidth:!0,placeholder:"Search by address or order ID",name:"searchTerm",value:e,onChange:K,InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(sn.A,{})})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,children:[(0,ee.jsx)(Jt.A,{children:"Status"}),(0,ee.jsxs)(Zt.A,{name:"statusFilter",value:t,onChange:K,label:"Status",children:[(0,ee.jsx)(ge.A,{value:"",children:"All Status"}),(0,ee.jsx)(ge.A,{value:"PENDING",children:"Pending"}),(0,ee.jsx)(ge.A,{value:"ACCEPTED",children:"Accepted"}),(0,ee.jsx)(ge.A,{value:"READY_FOR_DELIVERY",children:"Ready for Delivery"}),(0,ee.jsx)(ge.A,{value:"PICKED_UP",children:"Picked Up"}),(0,ee.jsx)(ge.A,{value:"DELIVERED",children:"Delivered"}),(0,ee.jsx)(ge.A,{value:"CANCELLED",children:"Cancelled"})]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:(0,ee.jsx)(ln.A,{}),onClick:()=>{l(!0),N()},fullWidth:!0,sx:{height:"56px"},children:"Fetch Orders"})})]}),d?U?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,ee.jsx)(j.A,{})}):0===Z?.length?(0,ee.jsx)(ae.A,{severity:"info",sx:{mb:3},children:"No orders found matching your criteria"}):(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Order ID"}),(0,ee.jsx)(Yt.A,{children:"Type"}),(0,ee.jsx)(Yt.A,{children:"Address"}),(0,ee.jsx)(Yt.A,{children:"Store"}),(0,ee.jsx)(Yt.A,{children:"Status"}),(0,ee.jsx)(Yt.A,{children:"Total Amount"}),(0,ee.jsx)(Yt.A,{children:"Delivery Date"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:Z.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsxs)(Yt.A,{children:["#",e.id]}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:"PICKUP"===e.type?"Pickup":"Delivery",color:"PICKUP"===e.type?"secondary":"primary",size:"small"})}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(m.A,{variant:"body2",children:"PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A"})}),(0,ee.jsx)(Yt.A,{children:V[e.storeId]?.name||"N/A"}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{icon:Y(e.status),label:vn.find((s=>s.value===e.status))?.label||e.status.replace(/_/g," "),color:vn.find((s=>s.value===e.status))?.color||"default",size:"small"})}),(0,ee.jsx)(Yt.A,{children:J(e.totalAmount)}),(0,ee.jsx)(Yt.A,{children:Q(e.deliveryDate)}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{size:"small",onClick:()=>(e=>{o(e),i(!0)})(e),children:(0,ee.jsx)(bn.A,{})}),(0,ee.jsx)(pe.A,{size:"small",onClick:()=>(e=>{o(e),v(e.status),S(e.deliveryInstructions||""),f(!0)})(e),disabled:"CANCELLED"===e.status||"DELIVERED"===e.status,children:(0,ee.jsx)(en.A,{})})]})]},e.id)))})]})}):(0,ee.jsx)(fe.A,{sx:{mb:3},children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Orders" to load order data'}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]})})]}),(0,ee.jsxs)(qe.A,{open:r,onClose:G,maxWidth:"md",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:"Order Details"}),(0,ee.jsx)(ze.A,{children:a&&(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsxs)(m.A,{variant:"h6",gutterBottom:!0,children:["Order #",a.id]}),(0,ee.jsx)(Fe.A,{label:"PICKUP"===a.type?"Pickup":"Delivery",color:"PICKUP"===a.type?"secondary":"primary",sx:{mb:2}}),(0,ee.jsx)(Fe.A,{icon:Y(a.status),label:vn.find((e=>e.value===a.status))?.label||a.status.replace(/_/g," "),color:vn.find((e=>e.value===a.status))?.color||"default",sx:{mb:2}})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Information"}),(0,ee.jsxs)(m.A,{variant:"body2",children:["Address: ","PICKUP"===a.type?a.pickupAddress?.address:a.address?.address||"N/A"]}),(0,ee.jsxs)(m.A,{variant:"body2",children:["Store: ",V[a.storeId]?.name||"N/A"," (",V[a.storeId]?.address||"",")"]}),(0,ee.jsxs)(m.A,{variant:"body2",children:["Total Amount: ",J(a.totalAmount)]}),(0,ee.jsxs)(m.A,{variant:"body2",children:["Delivery Date: ",Q(a.deliveryDate)]}),a.deliveryInstructions&&(0,ee.jsxs)(m.A,{variant:"body2",children:["Delivery Instructions: ",a.deliveryInstructions]})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Items"}),(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{size:"small",children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Product"}),(0,ee.jsx)(Yt.A,{children:"Quantity"}),(0,ee.jsx)(Yt.A,{children:"Amount"})]})}),(0,ee.jsx)(Qt.A,{children:a.orderItems?.edges?.map((e=>{let{node:s}=e;return(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:s.product?.name||"N/A"}),(0,ee.jsx)(Yt.A,{children:s.quantity}),(0,ee.jsx)(Yt.A,{children:J(s.orderAmount)})]},s.id)}))})]})})]})]})}),(0,ee.jsx)(We.A,{children:(0,ee.jsx)(te.A,{onClick:G,children:"Close"})})]}),(0,ee.jsxs)(qe.A,{open:y,onClose:()=>f(!1),maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:"Update Order Status"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{select:!0,fullWidth:!0,label:"Status",value:b,onChange:e=>v(e.target.value),children:vn.map((e=>(0,ee.jsx)(ge.A,{value:e.value,children:e.label},e.value)))})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Delivery Instructions",value:I,onChange:e=>S(e.target.value),multiline:!0,rows:3})}),("READY"===b||"READY_FOR_DELIVERY"===b)&&(0,ee.jsxs)(ee.Fragment,{children:[0===B?.getStoreDrivers?.length&&(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(ae.A,{severity:"warning",sx:{mb:2},children:"No delivery agents are assigned to this store. Please assign delivery agents before updating the order status."})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,required:!0,children:[(0,ee.jsx)(Jt.A,{children:"Delivery Agent"}),(0,ee.jsx)(Zt.A,{value:C,onChange:e=>w(e.target.value),label:"Delivery Agent",children:B?.getStoreDrivers?.length>0?B.getStoreDrivers.map((e=>(0,ee.jsxs)(ge.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId))):(0,ee.jsx)(ge.A,{disabled:!0,children:"No delivery agents available for this store"})})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Schedule Time",value:P,onChange:e=>E(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>f(!1),children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{if(!a)return;const e="DELIVERY"===a.type,s=a.address?.address,t=s&&""!==s.trim(),n=Array.isArray(a.orderItems?.edges)&&a.orderItems.edges.some((e=>{let{node:s}=e;return s.quantity>0}));if(e&&!t||!n)return h("Order must have a valid address and at least one product to update status."),void f(!1);const r={orderId:a.id,status:b,deliveryInstructions:I};if("READY"===b||"READY_FOR_DELIVERY"===b){if(!C)return void q({open:!0,message:"Driver ID is required for this status",severity:"error"});if(!P)return void q({open:!0,message:"Schedule time is required for this status",severity:"error"});r.driverId=parseInt(C),r.scheduleTime=P}H.mutate(r)},variant:"contained",color:"primary",disabled:D||("READY"===b||"READY_FOR_DELIVERY"===b)&&(!C||0===B?.getStoreDrivers?.length),children:D?"Updating...":"Update"})]})]}),(0,ee.jsx)(Xt.A,{open:T.open,autoHideDuration:6e3,onClose:()=>q((e=>({...e,open:!1}))),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,ee.jsx)(ae.A,{onClose:()=>q((e=>({...e,open:!1}))),severity:T.severity,sx:{width:"100%"},children:T.message})})]})});var Sn=t(77867),Cn=t(74229),wn=t(39804);const Pn=()=>{const[e,s]=(0,x.useState)(!1),[t,n]=(0,x.useState)(!1),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(null),[d,l]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null),[p,A]=(0,x.useState)("info"),{data:y,isLoading:f,error:b,refetch:v}=(0,u.I)({queryKey:["allStoresSquareStatus"],queryFn:()=>k("\n query AllStoresSquareStatus {\n allStoresSquareStatus {\n storeId\n storeName\n isConnected\n merchantId\n }\n }\n")}),{data:I,refetch:S}=(0,u.I)({queryKey:["allStoresCod"],queryFn:()=>k("\n query AllStores {\n stores {\n id\n name\n codEnabled\n }\n }\n")}),C=(0,ds.n)({mutationFn:e=>k("\n mutation ConnectSquare($storeId: Int!) {\n connectSquare(storeId: $storeId) {\n authorizationUrl\n message\n }\n }\n",{storeId:e}),onSuccess:e=>{const s=e.connectSquare?.authorizationUrl;s?window.location.href=s:(A("error"),h(e.connectSquare?.message||"Failed to generate authorization URL"))},onError:e=>{A("error"),h(e.message||"Failed to initiate Square connection")}}),w=(0,ds.n)({mutationFn:e=>k("\n mutation DisconnectSquare($storeId: Int!) {\n disconnectSquare(storeId: $storeId) {\n success\n message\n }\n }\n",{storeId:e}),onSuccess:e=>{s(!1),i(null),e.disconnectSquare?.success?(A("success"),h("Square account disconnected successfully"),v()):(A("error"),h(e.disconnectSquare?.message||"Failed to disconnect Square"))},onError:e=>{s(!1),i(null),A("error"),h(e.message||"Failed to disconnect Square account")}}),P=(0,ds.n)({mutationFn:e=>k("\n mutation ToggleCod($storeId: Int!, $enabled: Boolean!) {\n toggleCod(storeId: $storeId, enabled: $enabled) {\n id\n codEnabled\n }\n }\n",e),onSuccess:e=>{n(!1),o(null),e.toggleCod&&(A("success"),h(e.toggleCod.codEnabled?"Cash on Delivery enabled":"Cash on Delivery disabled"),S())},onError:e=>{n(!1),o(null),A("error"),h(e.message||"Failed to update COD settings")}});(0,x.useEffect)((()=>{const e=new URLSearchParams(window.location.search),s=e.get("oauth_success"),t=e.get("oauth_error"),n=e.get("store_id");"true"===s?(A("success"),h("Square account connected successfully"+(n?` for store ID ${n}`:"")),v(),window.history.replaceState({},"","/admin/payment-settings")):t&&(A("error"),h(`OAuth error: ${decodeURIComponent(t)}`),window.history.replaceState({},"","/admin/payment-settings"))}),[v]),(0,x.useEffect)((()=>{if(c){const e=setTimeout((()=>{h(null)}),5e3);return()=>clearTimeout(e)}}),[c]);const E=()=>{s(!1),i(null)},F=y?.allStoresSquareStatus||[],D=Object.fromEntries((I?.stores||[]).map((e=>[e.id,e.codEnabled])));return(0,ee.jsxs)(g.A,{children:[(0,ee.jsxs)(de.A,{sx:{p:3},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ee.jsx)(ts.A,{sx:{mr:1,fontSize:32}}),(0,ee.jsx)(m.A,{variant:"h5",children:"Square Payment Settings"})]}),c&&(0,ee.jsx)(ae.A,{severity:p,sx:{mb:3},onClose:()=>h(null),children:c}),b&&(0,ee.jsxs)(ae.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",b.message]}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Manage Square payment connections for all stores. Connect a store to enable online card payments."}),f?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ee.jsx)(j.A,{})}):(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Store Name"}),(0,ee.jsx)(Yt.A,{children:"Connection Status"}),(0,ee.jsx)(Yt.A,{children:"Merchant ID"}),(0,ee.jsx)(Yt.A,{children:"COD"}),(0,ee.jsx)(Yt.A,{align:"right",children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:0===F.length?(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:5,align:"center",children:"No stores found"})}):F.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(m.A,{variant:"body2",fontWeight:"medium",children:e.storeName})}),(0,ee.jsx)(Yt.A,{children:e.isConnected?(0,ee.jsx)(Fe.A,{label:"Connected",color:"success",size:"small",icon:(0,ee.jsx)(Cn.A,{})}):(0,ee.jsx)(Fe.A,{label:"Not Connected",color:"default",size:"small",icon:(0,ee.jsx)(wn.A,{})})}),(0,ee.jsx)(Yt.A,{children:e.merchantId||(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"—"})}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(nn.A,{checked:D[e.storeId]||!1,onChange:s=>{o(e),l(s.target.checked),n(!0)},size:"small",disabled:P.isPending})}),(0,ee.jsx)(Yt.A,{align:"right",children:e.isConnected?(0,ee.jsx)(te.A,{variant:"outlined",color:"error",size:"small",onClick:()=>(e=>{i(e),s(!0)})(e),disabled:w.isLoading,children:"Disconnect"}):(0,ee.jsx)(te.A,{variant:"contained",color:"primary",size:"small",onClick:()=>{return s=e.storeId,void C.mutate(s);var s},disabled:C.isLoading,startIcon:C.isLoading&&(0,ee.jsx)(j.A,{size:16}),children:"Connect Square"})})]},e.storeId)))})]})})]}),(0,ee.jsxs)(qe.A,{open:e,onClose:E,children:[(0,ee.jsx)(Re.A,{children:"Disconnect Square?"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(Sn.A,{children:["Are you sure you want to disconnect Square for ",(0,ee.jsx)("strong",{children:r?.storeName}),"?",(0,ee.jsx)("br",{}),(0,ee.jsx)("br",{}),"Customers will not be able to make card payments until you reconnect."]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:E,disabled:w.isLoading,children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{r&&w.mutate(r.storeId)},color:"error",variant:"contained",disabled:w.isLoading,startIcon:w.isLoading&&(0,ee.jsx)(j.A,{size:16}),children:"Disconnect"})]})]}),(0,ee.jsxs)(qe.A,{open:t,onClose:()=>{n(!1),o(null)},children:[(0,ee.jsxs)(Re.A,{children:[d?"Enable":"Disable"," Cash on Delivery?"]}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(Sn.A,{children:d?`Customers will be able to pay with cash when orders from ${a?.storeName} are delivered.`:`Cash on Delivery will be disabled for ${a?.storeName}. Orders already in progress will not be affected.`})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{n(!1),o(null)},disabled:P.isPending,children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{a&&P.mutate({storeId:a.storeId,enabled:d})},variant:"contained",color:d?"primary":"error",disabled:P.isPending,startIcon:P.isPending&&(0,ee.jsx)(j.A,{size:16}),children:P.isPending?"Saving...":"Confirm"})]})]})]})};var kn=t(87558),En=t(1275),Fn=t(88116),Dn=t(98708),Ln=t(60181);const $n=()=>{const[e,s]=(0,x.useState)(0),[t,n]=(0,x.useState)(10),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(""),[d,l]=(0,x.useState)(null),[c,h]=(0,x.useState)(!1),[f,b]=(0,x.useState)(!1),[v,I]=(0,x.useState)(""),[S,C]=(0,x.useState)(""),[w,P]=(0,x.useState)(!0),[E,F]=(0,x.useState)(!0),[D,L]=(0,x.useState)({open:!1,message:"",severity:"success"}),[$,T]=(0,x.useState)("table"),[q,W]=(0,x.useState)(null),[O,U]=(0,x.useState)(""),[N,B]=(0,x.useState)(!1),[_,M]=(0,x.useState)({price:"",quantity:"",measurement:"",unit:""}),V=(0,x.useRef)(null),{data:H=[],isLoading:G,error:K,refetch:Y}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{const e=await k(R);return e?.stores||[]},enabled:!0}),{data:Q,isLoading:J}=(0,u.I)({queryKey:["products"],queryFn:async()=>{const e=await k(z);return e?.products||[]},enabled:f}),{data:Z,isLoading:X,error:se,refetch:ne}=(0,u.I)({queryKey:["storeInventory",a],queryFn:async()=>{if(!a)return[];const e=await k("\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}),re=(0,ds.n)({mutationFn:e=>k("\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:(e,s)=>{Z&&Z.forEach((e=>{e.id===s.inventoryId&&Object.assign(e,s)})),L({open:!0,message:"Inventory item updated successfully",severity:"success"}),h(!1)},onError:e=>{L({open:!0,message:`Error updating inventory: ${e.message}`,severity:"error"})}}),ie=(0,ds.n)({mutationFn:e=>k("\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:()=>{L({open:!0,message:"Product added to inventory successfully",severity:"success"}),ne(),b(!1),xe()},onError:e=>{L({open:!0,message:`Error adding product to inventory: ${e.message}`,severity:"error"})}}),oe=e=>{l(e),I(e.quantity.toString()),C(e.price.toString()),P(e.isAvailable),F(e.isListed),h(!0)},le=()=>{L({...D,open:!1})},ce=()=>{b(!1),xe()},xe=()=>{W(null),U(""),M({price:"",quantity:"",measurement:"",unit:""})},ue=e=>{const{name:s,value:t}=e.target;M((e=>({...e,[s]:t})))},me=()=>Z?Z.filter((e=>e.product.name.toLowerCase().includes(r.toLowerCase()))):[],he=Q?.filter((e=>e.name.toLowerCase().includes(O.toLowerCase())))||[],Ae=(0,x.useRef)(null),je=(0,x.useCallback)((()=>{if("grid"!==$||!Ae.current)return;const e=Ae.current.offsetWidth,s=window.innerHeight-Ae.current.getBoundingClientRect().top-150,r=Math.max(1,Math.floor(e/270))*Math.max(1,Math.floor(s/260));r!==t&&n(r)}),[$,t]);(0,x.useEffect)((()=>{if("grid"===$)return je(),window.addEventListener("resize",je),()=>window.removeEventListener("resize",je)}),[$,je]),(0,x.useEffect)((()=>{"table"===$&&10!==t&&n(10)}),[$,t]);return(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Inventory Management"}),(0,ee.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:3,flexWrap:"wrap",gap:2},children:[(0,ee.jsxs)(cs.A,{sx:{minWidth:200},children:[(0,ee.jsx)(Jt.A,{children:"Select Store"}),(0,ee.jsx)(Zt.A,{value:a,onChange:e=>{o(e.target.value),s(0)},label:"Select Store",children:Array.isArray(H)&&H?.map((e=>(0,ee.jsx)(ge.A,{value:e.id,children:e.name},e.id)))})]}),(0,ee.jsx)(p.A,{placeholder:"Search products...",value:r,onChange:e=>{i(e.target.value),s(0)},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(sn.A,{})})},sx:{width:300}}),(0,ee.jsx)(te.A,{variant:"outlined",startIcon:"table"===$?(0,ee.jsx)(Dn.A,{}):(0,ee.jsx)(Ln.A,{}),onClick:()=>{T("table"===$?"grid":"table")},children:"table"===$?"Grid View":"Table View"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:(0,ee.jsx)(we.A,{}),onClick:()=>{a?b(!0):L({open:!0,message:"Please select a store first",severity:"warning"})},disabled:!a,children:"Add Product"})]}),K&&(0,ee.jsxs)(ae.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",K.message]}),se&&(0,ee.jsxs)(ae.A,{severity:"error",sx:{mb:3},children:["Error loading inventory: ",se.message]}),a?X?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ee.jsx)(j.A,{})}):0===me().length?(0,ee.jsx)(ae.A,{severity:"info",sx:{my:4},children:"No inventory found for this store."}):(0,ee.jsxs)(ee.Fragment,{children:["table"===$?(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Product"}),(0,ee.jsx)(Yt.A,{children:"Category"}),(0,ee.jsx)(Yt.A,{children:"Available"}),(0,ee.jsx)(Yt.A,{children:"Listed"}),(0,ee.jsx)(Yt.A,{children:"Price"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:me().slice(e*t,e*t+t).map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[e.product.image&&(0,ee.jsx)(g.A,{component:"img",src:e.product.image,alt:e.product.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"body1",children:e.product.name}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:e.product.description})]})]})}),(0,ee.jsx)(Yt.A,{children:e.product.category?.name||"N/A"}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:e.isAvailable?"Available":"Not Available",color:e.isAvailable?"success":"error",size:"small"})}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:e.isListed?"Listed":"Not Listed",color:e.isListed?"success":"error",size:"small"})}),(0,ee.jsxs)(Yt.A,{children:["$",e.price.toFixed(2)]}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(pe.A,{size:"small",color:"primary",onClick:()=>oe(e),children:(0,ee.jsx)(en.A,{})})})]},e.id)))})]})}):(0,ee.jsx)(ye.Ay,{container:!0,spacing:3,ref:Ae,children:me().slice(e*t,e*t+t).map((e=>(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,ee.jsxs)(fe.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,ee.jsx)(be.A,{component:"img",height:"140",image:e.product.image||"https://via.placeholder.com/140",alt:e.product.name}),(0,ee.jsxs)(ve.A,{sx:{flexGrow:1},children:[(0,ee.jsx)(m.A,{gutterBottom:!0,variant:"h6",component:"div",noWrap:!0,children:e.product.name}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1},children:e.product.category?.name||"N/A"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1},noWrap:!0,children:e.product.description}),(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:2},children:[(0,ee.jsx)(Fe.A,{label:`Qty: ${e.quantity}`,color:e.quantity<10?"error":"success",size:"small"}),(0,ee.jsxs)(m.A,{variant:"h6",color:"primary",children:["$",e.price.toFixed(2)]})]}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"space-between",mt:2},children:(0,ee.jsx)(te.A,{size:"small",startIcon:(0,ee.jsx)(en.A,{}),onClick:()=>oe(e),children:"Edit"})})]})]})},e.id)))}),(0,ee.jsx)(y.A,{component:"div",count:me().length,page:e,onPageChange:(e,t)=>{s(t)},rowsPerPage:t,onRowsPerPageChange:e=>{n(parseInt(e.target.value,10)),s(0)},rowsPerPageOptions:(()=>{if("grid"===$&&Ae.current){const e=Ae.current.offsetWidth,s=window.innerHeight-Ae.current.getBoundingClientRect().top-150,t=270,n=260,r=Math.max(1,Math.floor(e/t));Math.max(1,Math.floor(s/n));return[...[1*r,2*r,3*r,4*r,5*r].filter((e=>eh(!1),fullWidth:!0,maxWidth:"sm",children:[(0,ee.jsx)(Re.A,{children:"Edit Inventory Item"}),(0,ee.jsx)(ze.A,{children:d&&(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[d.product.image&&(0,ee.jsx)(g.A,{component:"img",src:d.product.image,alt:d.product.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"subtitle1",children:d.product.name}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:d.product.category?.name||"N/A"})]})]}),(0,ee.jsx)(p.A,{label:"Quantity",type:"number",fullWidth:!0,value:v,onChange:e=>I(e.target.value),sx:{mb:2}}),(0,ee.jsx)(p.A,{label:"Price ($)",type:"number",fullWidth:!0,value:S,onChange:e=>C(e.target.value),sx:{mb:2}}),(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mb:2},children:[(0,ee.jsx)(Jt.A,{children:"Availability"}),(0,ee.jsxs)(Zt.A,{value:w,onChange:e=>P(e.target.value),label:"Availability",children:[(0,ee.jsx)(ge.A,{value:!0,children:"Available"}),(0,ee.jsx)(ge.A,{value:!1,children:"Not Available"})]})]}),(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mb:2},children:[(0,ee.jsx)(Jt.A,{children:"Listing Status"}),(0,ee.jsxs)(Zt.A,{value:E,onChange:e=>F(e.target.value),label:"Listing Status",children:[(0,ee.jsx)(ge.A,{value:!0,children:"Listed"}),(0,ee.jsx)(ge.A,{value:!1,children:"Not Listed"})]})]})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>h(!1),children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{d&&re.mutate({inventoryId:d.id,price:parseFloat(S),quantity:parseInt(v),isAvailable:w,isListed:E})},variant:"contained",color:"primary",disabled:re.isPending,children:re.isPending?"Updating...":"Update"})]})]}),(0,ee.jsxs)(qe.A,{open:f,onClose:ce,fullWidth:!0,maxWidth:"md",children:[(0,ee.jsx)(Re.A,{children:"Add Product to Inventory"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Select a product to add to the store's inventory"}),(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mt:2,mb:3},children:[(0,ee.jsx)(p.A,{ref:V,label:"Search Product",placeholder:"Start typing to search...",value:O,onChange:e=>{U(e.target.value),B(!0)},onFocus:()=>B(!0),onClick:()=>B(!0),fullWidth:!0,InputProps:{endAdornment:J?(0,ee.jsx)(j.A,{color:"inherit",size:20}):null}}),(0,ee.jsx)(kn.A,{open:N&&he.length>0,anchorEl:V.current,placement:"bottom-start",style:{width:V.current?.offsetWidth,zIndex:1300},children:(0,ee.jsx)(En.x,{onClickAway:()=>{B(!1)},children:(0,ee.jsx)(de.A,{elevation:3,children:(0,ee.jsx)(Fn.A,{sx:{maxHeight:300,overflow:"auto"},children:he.map((e=>(0,ee.jsx)(ge.A,{onClick:()=>(e=>{W(e),U(e.name),B(!1)})(e),selected:q?.id===e.id,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[e.image&&(0,ee.jsx)(g.A,{component:"img",src:e.image,alt:e.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"body1",children:e.name}),(0,ee.jsx)(m.A,{variant:"caption",color:"textSecondary",children:e.categoryId?`Category ID: ${e.categoryId}`:"No category"})]})]})},e.id)))})})})})]}),q&&(0,ee.jsxs)(g.A,{sx:{mb:3,p:2,bgcolor:"background.paper",borderRadius:1},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,children:"Selected Product:"}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[q.image&&(0,ee.jsx)(g.A,{component:"img",src:q.image,alt:q.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"body1",children:q.name}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:q.description})]})]})]}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,children:(0,ee.jsx)(p.A,{label:"Price ($)",type:"number",name:"price",fullWidth:!0,value:_.price,onChange:ue,required:!0,inputProps:{min:0,step:.01}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,children:(0,ee.jsx)(p.A,{label:"Quantity",type:"number",name:"quantity",fullWidth:!0,value:_.quantity,onChange:ue,required:!0,inputProps:{min:0}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,children:(0,ee.jsx)(p.A,{label:"Measurement (optional)",type:"number",name:"measurement",fullWidth:!0,value:_.measurement,onChange:ue,inputProps:{min:0,step:.01}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,children:(0,ee.jsx)(p.A,{label:"Unit (optional)",name:"unit",fullWidth:!0,value:_.unit,onChange:ue,placeholder:"e.g., kg, g, L, ml"})})]})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:ce,children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{q?_.price&&_.quantity?ie.mutate({productId:q.id,storeId:parseInt(a),price:parseFloat(_.price),quantity:parseInt(_.quantity),measurement:_.measurement?parseInt(_.measurement):null,unit:_.unit||""}):L({open:!0,message:"Please fill in all required fields",severity:"warning"}):L({open:!0,message:"Please select a product",severity:"warning"})},variant:"contained",color:"primary",disabled:ie.isPending||!q,children:ie.isPending?"Adding...":"Add to Inventory"})]})]}),(0,ee.jsx)(Xt.A,{open:D.open,autoHideDuration:6e3,onClose:le,message:D.message,children:(0,ee.jsx)(ae.A,{onClose:le,severity:D.severity,children:D.message})})]})},Tn=()=>{const[e,s]=(0,x.useState)(0),[t,n]=(0,x.useState)(10),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[d,l]=(0,x.useState)(""),[c,h]=(0,x.useState)(null),[A,f]=(0,x.useState)(!1),[b,v]=(0,x.useState)(!1),[I,S]=(0,x.useState)(null),[C,w]=(0,x.useState)(null),[P,E]=(0,x.useState)(!1),{data:F,refetch:D}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await k("\n query GetCategories {\n categories {\n id\n name\n createdAt\n }\n }\n")).categories||[],enabled:!1}),L=(0,ds.n)({mutationFn:e=>k("\n mutation CreateCategory($name: String!) {\n createCategory(name: $name) {\n category {\n id\n name\n }\n }\n }\n",{name:e}),onSuccess:()=>{R(),D()},onError:e=>{h(e.message||"Failed to create category")}}),$=(0,ds.n)({mutationFn:e=>{let{id:s,name:t}=e;return k("\n mutation UpdateCategory($categoryId: Int!, $name: String!) {\n updateCategory(categoryId: $categoryId, name: $name) {\n category {\n id\n name\n }\n }\n }\n",{categoryId:s,name:t})},onSuccess:(e,s)=>{F&&F.forEach((e=>{e.id===s.id&&(e.name=s.name)})),R(),S("Category updated successfully")},onError:e=>{h(e.message||"Failed to update category")}}),T=(0,ds.n)({mutationFn:e=>k("\n mutation DeleteCategory($categoryId: Int!) {\n deleteCategory(categoryId: $categoryId) {\n success\n }\n }\n",e),onSuccess:()=>{S("Category deleted successfully"),E(!1),D()},onError:e=>{h(e.message)}}),q=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(o(e),l(e.name)):(o(null),l("")),i(!0)},R=()=>{i(!1),o(null),l(""),h(null)},z=()=>{d.trim()?a?$.mutate({id:a.id,name:d.trim()}):L.mutate(d.trim()):h("Category name is required")},W=F?.slice(e*t,e*t+t);return(0,ee.jsxs)(g.A,{children:[(0,ee.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ee.jsx)(we.A,{sx:{mr:1}}),(0,ee.jsx)(m.A,{variant:"h5",children:"Category Management"})]}),(0,ee.jsx)(ye.Ay,{container:!0,spacing:2,sx:{mb:3},children:(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,sx:{display:"flex",gap:2},children:[(0,ee.jsx)(te.A,{variant:"contained",startIcon:(0,ee.jsx)(ln.A,{}),onClick:()=>{f(!0),h(null),D().then((()=>{v(!0),f(!1)})).catch((e=>{h("Failed to load categories. Please try again."),f(!1)}))},disabled:A,sx:{minWidth:150},children:A?(0,ee.jsx)(j.A,{size:24}):"Fetch Categories"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:(0,ee.jsx)(we.A,{}),onClick:()=>q(),children:"Add Category"})]})}),c&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:3},children:c}),b?A?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ee.jsx)(j.A,{})}):(0,ee.jsx)(ee.Fragment,{children:(0,ee.jsxs)(Vt.A,{children:[(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"ID"}),(0,ee.jsx)(Yt.A,{children:"Name"}),(0,ee.jsx)(Yt.A,{children:"Created At"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:0===W?.length?(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:4,align:"center",children:"No categories found"})}):W?.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.id}),(0,ee.jsx)(Yt.A,{children:e.name}),(0,ee.jsx)(Yt.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{size:"small",onClick:()=>q(e),children:(0,ee.jsx)(en.A,{})}),(0,ee.jsx)(pe.A,{size:"small",onClick:()=>(e=>{w(e),E(!0)})(e),children:(0,ee.jsx)(dn.A,{})})]})]},e.id)))})]}),(0,ee.jsx)(y.A,{component:"div",count:F?.length||0,page:e,onPageChange:(e,t)=>{s(t)},rowsPerPage:t,onRowsPerPageChange:e=>{n(parseInt(e.target.value,10)),s(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,ee.jsxs)(g.A,{sx:{textAlign:"center",py:4},children:[(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Categories" to load category information'}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,ee.jsxs)(qe.A,{open:r,onClose:R,children:[(0,ee.jsx)(Re.A,{children:a?"Edit Category":"Add New Category"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(p.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:d,onChange:e=>l(e.target.value),error:!!c,helperText:c,onKeyPress:e=>{"Enter"===e.key&&z()}})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:R,children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:z,variant:"contained",disabled:L.isPending||$.isPending,children:L.isPending||$.isPending?(0,ee.jsx)(j.A,{size:24}):a?"Update":"Create"})]})]}),(0,ee.jsxs)(qe.A,{open:P,onClose:()=>E(!1),children:[(0,ee.jsx)(Re.A,{children:"Delete Category"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.A,{children:"Are you sure you want to delete this category?"})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>E(!1),disabled:T.isPending||T.isLoading,children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{C&&T.mutate({categoryId:C.id})},variant:"contained",color:"error",disabled:T.isPending||T.isLoading,startIcon:T.isPending||T.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:T.isPending||T.isLoading?"Deleting...":"Delete"})]})]})]})},qn=e=>{let{open:s,onClose:t,selectedFee:n,onUpdate:r,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,d]=(0,x.useState)(a);(0,x.useEffect)((()=>{n?d({feeCurrency:n.feeCurrency||"",feeRate:n.feeRate?.toString()||"",limit:n.limit?.toString()||"",type:n.type?.toUpperCase()||"DELIVERY"}):s&&d(a)}),[n,s]),(0,x.useEffect)((()=>{s||d(a)}),[s]);const l=e=>{const{name:s,value:t}=e.target;d((e=>({...e,[s]:t})))};return(0,ee.jsxs)(qe.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:n?"Edit Fee":"Add New Fee"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ee.jsxs)(cs.A,{fullWidth:!0,children:[(0,ee.jsx)(Jt.A,{children:"Fee Type"}),(0,ee.jsxs)(Zt.A,{name:"type",value:o.type,onChange:l,label:"Fee Type",children:[(0,ee.jsx)(ge.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,ee.jsx)(ge.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,ee.jsx)(p.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:l,fullWidth:!0,placeholder:"e.g., USD"}),(0,ee.jsx)(p.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:l,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,ee.jsx)(p.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:l,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:t,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",onClick:()=>{r({id:n?.id,...o,feeRate:parseFloat(o.feeRate),limit:parseFloat(o.limit)}),n||d(a)},disabled:i,startIcon:i?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},Rn=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(""),[c,p]=(0,x.useState)(""),{data:A,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>k("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=A?.stores||[],{data:b,isLoading:v,refetch:I}=(0,u.I)({queryKey:["getFeesByStore",e],queryFn:()=>k("\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}),S=b?.getFeesByStore||[],C=(0,ds.n)({mutationFn:e=>k("\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:(e,s)=>{b&&b.getFeesByStore&&b.getFeesByStore.forEach((e=>{e.id===s.id&&Object.assign(e,s)})),i(!1),n(null),p("Fee updated successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error updating fee: ${e.message}`)}}),w=(0,ds.n)({mutationFn:e=>k("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),n(null),p("Fee deleted successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error deleting fee: ${e.message}`)}}),P=(0,ds.n)({mutationFn:s=>k("\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:{...s,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),n(null),p("Fee added successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error adding fee: ${e.message}`)}});return y?(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})}):(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Fees Management"}),(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mb:3},children:[(0,ee.jsx)(Jt.A,{children:"Select Store"}),(0,ee.jsx)(Zt.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,ee.jsx)(ge.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:c}),d&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:d}),!e&&(0,ee.jsx)(ae.A,{severity:"info",sx:{mb:4},children:(0,ee.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its fees."})}),e&&(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.A,{variant:"h5",children:"Fees"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):(0,ee.jsx)(we.A,{}),onClick:()=>{n(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Fee"})]}),v?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ee.jsx)(j.A,{})}):0===S.length?(0,ee.jsx)(ae.A,{severity:"info",sx:{my:2},children:"No fees found for this store. Add your first fee to get started."}):(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Type"}),(0,ee.jsx)(Yt.A,{children:"Currency"}),(0,ee.jsx)(Yt.A,{children:"Rate"}),(0,ee.jsx)(Yt.A,{children:"Limit"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:0!==S.length||v?S.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.type}),(0,ee.jsx)(Yt.A,{children:e.feeCurrency}),(0,ee.jsx)(Yt.A,{children:e.feeRate}),(0,ee.jsx)(Yt.A,{children:e.limit}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ee.jsx)(en.A,{})}),(0,ee.jsx)(pe.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ee.jsx)(dn.A,{})})]})]},e.id))):(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:5,align:"center",children:(0,ee.jsx)(ae.A,{severity:"info",sx:{my:2},children:"No fees found for this store."})})})})]})})]}),(0,ee.jsx)(qn,{open:r,onClose:()=>{i(!1),n(null),l("")},selectedFee:t,onUpdate:e=>{t?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading}),(0,ee.jsxs)(qe.A,{open:a,onClose:()=>{o(!1),n(null),l("")},children:[(0,ee.jsx)(Re.A,{children:"Delete Fee"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{o(!1),n(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:t.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},zn=e=>{let{open:s,onClose:t,selectedLocationCode:n,onUpdate:r,isLoading:i,existingCodes:a}=e;const[o,d]=(0,x.useState)({location:"",code:""}),[l,c]=(0,x.useState)("");(0,x.useEffect)((()=>{d(n?{location:n.location||"",code:n.code||""}:{location:"",code:""}),c("")}),[n,s]);const u=()=>{d({location:"",code:""}),c(""),t()},m=e=>{const{name:s,value:t}=e.target;d((e=>({...e,[s]:t}))),c("")};return(0,ee.jsxs)(qe.A,{open:s,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:n?"Edit Location Code":"Add New Location Code"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ee.jsx)(p.A,{name:"location",label:"Location",value:o.location,onChange:m,fullWidth:!0,placeholder:"e.g., Main Branch",error:!!l&&l.includes("Location"),helperText:l&&l.includes("Location")?l:""}),(0,ee.jsx)(p.A,{name:"code",label:"Code",value:o.code,onChange:m,fullWidth:!0,placeholder:"e.g., MB001",error:!!l&&(l.includes("Code")||l.includes("already exists")),helperText:l&&(l.includes("Code")||l.includes("already exists"))?l:""})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:u,children:"Cancel"}),(0,ee.jsx)(te.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,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},Wn=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(""),[c,p]=(0,x.useState)(""),{data:A,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>k("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=A?.stores||[],{data:b,isLoading:v,refetch:I}=(0,u.I)({queryKey:["getStoreLocationCodesByStore",e],queryFn:()=>k("\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}),S=b?.getStoreLocationCodesByStore||[],C=(0,ds.n)({mutationFn:e=>k("\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:(e,s)=>{b&&b.getStoreLocationCodesByStore&&b.getStoreLocationCodesByStore.forEach((e=>{e.id===s.id&&Object.assign(e,s)})),i(!1),n(null),p("Location code updated successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error updating location code: ${e.message}`)}}),w=(0,ds.n)({mutationFn:e=>k("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),n(null),p("Location code deleted successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error deleting location code: ${e.message}`)}}),P=(0,ds.n)({mutationFn:s=>k("\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:{...s,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),n(null),p("Location code added successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error adding location code: ${e.message}`)}});return y?(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})}):(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mb:3},children:[(0,ee.jsx)(Jt.A,{children:"Select Store"}),(0,ee.jsx)(Zt.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,ee.jsx)(ge.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:c}),d&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:d}),!e&&(0,ee.jsx)(ae.A,{severity:"info",sx:{mb:4},children:(0,ee.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its location codes."})}),e&&(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.A,{variant:"h5",children:"Location Codes"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):(0,ee.jsx)(we.A,{}),onClick:()=>{n(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Location Code"})]}),v?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ee.jsx)(j.A,{})}):0===S.length?(0,ee.jsx)(ae.A,{severity:"info",sx:{my:2},children:"No location codes found for this store. Add your first location code to get started."}):(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Location"}),(0,ee.jsx)(Yt.A,{children:"Code"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:0!==S.length||v?S.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.location}),(0,ee.jsx)(Yt.A,{children:e.code}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ee.jsx)(en.A,{})}),(0,ee.jsx)(pe.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ee.jsx)(dn.A,{})})]})]},e.id))):(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:3,align:"center",children:(0,ee.jsx)(ae.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})})]}),(0,ee.jsx)(zn,{open:r,onClose:()=>{i(!1),n(null),l("")},selectedLocationCode:t,onUpdate:e=>{t?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading,existingCodes:S}),(0,ee.jsxs)(qe.A,{open:a,onClose:()=>{o(!1),n(null),l("")},children:[(0,ee.jsx)(Re.A,{children:"Delete Location Code"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{o(!1),n(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:t.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},On=e=>{let{open:s,onClose:t,selectedPickupAddress:n,onUpdate:r,isLoading:i,existingAddresses:a}=e;const[o,d]=(0,x.useState)({address:""}),[l,c]=(0,x.useState)(""),[u,h]=(0,x.useState)(!1);x.useEffect((()=>{n?(d({address:n.address||""}),h(!0)):(d({address:""}),h(!1)),c("")}),[n]);return(0,ee.jsxs)(qe.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:n?"Edit Pickup Address":"Add New Pickup Address"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ee.jsx)(St,{value:o.address,onChange:e=>{d((s=>({...s,address:e}))),c("")},onValidAddress:h}),l&&(0,ee.jsx)(m.A,{color:"error",variant:"caption",children:l})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:t,children:"Cancel"}),(0,ee.jsx)(te.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,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},Un=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(""),[c,p]=(0,x.useState)(""),{data:A,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>k("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=A?.stores||[],{data:b,isLoading:v,refetch:I}=(0,u.I)({queryKey:["getPickupAddressesByStore",e],queryFn:()=>k("\n query GetPickupAddressesByStore($storeId: Int!) {\n getPickupAddressesByStore(storeId: $storeId) {\n id\n storeId\n address\n }\n }\n",{storeId:parseInt(e)}),enabled:!!e}),S=b?.getPickupAddressesByStore||[],C=(0,ds.n)({mutationFn:e=>k("\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:(e,s)=>{b&&b.getPickupAddressesByStore&&b.getPickupAddressesByStore.forEach((e=>{e.id===s.id&&Object.assign(e,s)})),i(!1),n(null),p("Pickup address updated successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error updating pickup address: ${e.message}`)}}),w=(0,ds.n)({mutationFn:e=>k("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),n(null),p("Pickup address deleted successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error deleting pickup address: ${e.message}`)}}),P=(0,ds.n)({mutationFn:s=>k("\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:{...s,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),n(null),p("Pickup address added successfully"),setTimeout((()=>p("")),3e3)},onError:e=>{l(`Error adding pickup address: ${e.message}`)}});return y?(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})}):(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mb:3},children:[(0,ee.jsx)(Jt.A,{children:"Select Store"}),(0,ee.jsx)(Zt.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,ee.jsx)(ge.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:c}),d&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:d}),!e&&(0,ee.jsx)(ae.A,{severity:"info",sx:{mb:4},children:(0,ee.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its pickup addresses."})}),e&&(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.A,{variant:"h5",children:"Pickup Addresses"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):(0,ee.jsx)(we.A,{}),onClick:()=>{n(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Pickup Address"})]}),v?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ee.jsx)(j.A,{})}):0===S.length?(0,ee.jsx)(ae.A,{severity:"info",sx:{my:2},children:"No pickup addresses found for this store. Add your first pickup address to get started."}):(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Address"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:S.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.address}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ee.jsx)(en.A,{})}),(0,ee.jsx)(pe.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ee.jsx)(dn.A,{})})]})]},e.id)))})]})})]}),(0,ee.jsx)(On,{open:r,onClose:()=>{i(!1),n(null),l("")},selectedPickupAddress:t,onUpdate:e=>{t?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading,existingAddresses:S}),(0,ee.jsxs)(qe.A,{open:a,onClose:()=>{o(!1),n(null),l("")},children:[(0,ee.jsx)(Re.A,{children:"Delete Pickup Address"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{o(!1),n(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:t.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},Nn=240,Bn=65,_n=[{text:"Dashboard",icon:(0,ee.jsx)(Rt.A,{}),path:"/admin/dashboard"},{text:"Stores",icon:(0,ee.jsx)(bt.A,{}),path:"/admin/stores"},{text:"Product Management",icon:(0,ee.jsx)(zt.A,{}),path:"/admin/products"},{text:"Inventory Management",icon:(0,ee.jsx)(Wt.A,{}),path:"/admin/inventory"},{text:"Orders",icon:(0,ee.jsx)(Pe.A,{}),path:"/admin/orders"},{text:"Users",icon:(0,ee.jsx)(Ot.A,{}),path:"/admin/users"},{text:"Payment Settings",icon:(0,ee.jsx)(ts.A,{}),path:"/admin/payment-settings"},{text:"Categories",icon:(0,ee.jsx)(Wt.A,{}),path:"/admin/categories"},{text:"Fees Management",icon:(0,ee.jsx)(ts.A,{}),path:"/admin/fees"},{text:"Location Codes",icon:(0,ee.jsx)(Ut.A,{}),path:"/admin/location-codes"},{text:"Pickup Addresses",icon:(0,ee.jsx)(As.A,{}),path:"/admin/pickup-addresses"}],Mn=()=>{const e=(0,Ee.A)(),s=(0,Es.A)(e.breakpoints.down("sm")),[t,n]=(0,x.useState)(!0),{user:r,ability:i,logout:a}=J(),o=(0,l.Zp)(),d=(0,l.zy)(),c=(0,ee.jsxs)(g.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:t&&!s?"space-between":"center",p:2,minHeight:64},children:[t&&!s&&(0,ee.jsx)(m.A,{variant:"h6",noWrap:!0,component:"div",children:"Admin Panel"}),!s&&(0,ee.jsx)(pe.A,{onClick:()=>{n(!t)},children:t?(0,ee.jsx)(Je.A,{}):(0,ee.jsx)(Nt.A,{})})]}),(0,ee.jsx)(ss.A,{}),(0,ee.jsxs)(fs.A,{children:[_n.map((e=>(0,ee.jsxs)(bs.Ay,{button:!0,onClick:()=>{return s=e.path,void o(s);var s},selected:d.pathname===e.path,sx:{minHeight:48,justifyContent:t&&!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,ee.jsx)(vs.A,{sx:{minWidth:0,mr:t&&!s?3:"auto",justifyContent:"center",color:d.pathname===e.path?"white":"inherit"},children:e.icon}),(0,ee.jsx)(Is.A,{primary:e.text,sx:{opacity:t&&!s?1:0}})]},e.text))),(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsxs)(bs.Ay,{button:!0,onClick:()=>{(async()=>{try{await(0,ks.C)(),a(),o("/")}catch(e){}})()},sx:{minHeight:48,justifyContent:t&&!s?"initial":"center",px:2.5},children:[(0,ee.jsx)(vs.A,{sx:{minWidth:0,mr:t&&!s?3:"auto",justifyContent:"center"},children:(0,ee.jsx)(Bt.A,{})}),(0,ee.jsx)(Is.A,{primary:"Logout",sx:{opacity:t&&!s?1:0}})]})]})]});return(0,ee.jsxs)(g.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,ee.jsx)(Et,{}),(0,ee.jsx)(g.A,{component:"nav",sx:{width:s?Bn:t?Nn:Bn,flexShrink:0,position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,ee.jsx)(Ss.Ay,{variant:"persistent",open:!0,sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:s?Bn:t?Nn:Bn,top:{xs:"64px",sm:"70px"},transition:e.transitions.create("width",{easing:e.transitions.easing.sharp,duration:e.transitions.duration.enteringScreen}),overflowX:"hidden"}},children:c})}),(0,ee.jsx)(g.A,{component:"main",sx:{flexGrow:1,p:{xs:0,sm:3},width:{xs:"calc(100% - 65px)",sm:`calc(100% - ${t?Nn:Bn}px)`},ml:{xs:"65px",sm:`${t?Nn:Bn}px`},mt:{xs:"64px",sm:"70px"},transition:e.transitions.create(["width","margin"],{easing:e.transitions.easing.sharp,duration:e.transitions.duration.leavingScreen})},children:(0,ee.jsxs)(l.BV,{children:[(0,ee.jsx)(l.qh,{path:"/",element:(0,ee.jsx)(l.C5,{to:"dashboard",replace:!0})}),(0,ee.jsx)(l.qh,{path:"dashboard",element:(0,ee.jsx)(Mt,{})}),(0,ee.jsx)(l.qh,{path:"users/*",element:(0,ee.jsx)(tn,{})}),(0,ee.jsx)(l.qh,{path:"stores/*",element:(0,ee.jsx)(pn,{})}),(0,ee.jsx)(l.qh,{path:"products",element:(0,ee.jsx)(gn,{})}),(0,ee.jsx)(l.qh,{path:"inventory",element:(0,ee.jsx)($n,{})}),(0,ee.jsx)(l.qh,{path:"orders",element:(0,ee.jsx)(In,{})}),(0,ee.jsx)(l.qh,{path:"payment-settings",element:(0,ee.jsx)(Pn,{})}),(0,ee.jsx)(l.qh,{path:"categories",element:(0,ee.jsx)(Tn,{})}),(0,ee.jsx)(l.qh,{path:"fees",element:(0,ee.jsx)(Rn,{})}),(0,ee.jsx)(l.qh,{path:"location-codes",element:(0,ee.jsx)(Wn,{})}),(0,ee.jsx)(l.qh,{path:"pickup-addresses",element:(0,ee.jsx)(Un,{})})]})})]})};var Vn=t(27558),Hn=t(76030);const Gn=()=>{const[,e]=(0,x.useReducer)((e=>e+1),0),[s,t]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[o,d]=(0,x.useState)(""),[l,c]=(0,x.useState)(""),[y,f]=(0,x.useState)("ALL"),[b,I]=(0,x.useState)(""),[S,C]=(0,x.useState)(!1),[w,P]=(0,x.useState)(0),[E,L]=(0,x.useState)({}),[$,q]=(0,x.useState)(!1),{userProfile:R,setUserProfile:z}=J();(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,v.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;a(s)}}catch(e){}})()}),[]);const{data:W,isLoading:O,error:U}=(0,u.I)({queryKey:["getUserProfile",i],queryFn:async()=>{const s=await k(D,{userId:i});return s?.getUserProfile&&(z(s.getUserProfile),setTimeout((()=>{e()}),200)),s},enabled:!!i,onError:e=>{}}),N=J.getState().userProfile||R||W?.getUserProfile,{data:B,isLoading:_,error:M,refetch:V}=(0,u.I)({queryKey:["driverDeliveries",N?.id],queryFn:()=>N?.id?k("\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}),H=(0,ds.n)({mutationFn:e=>k(F,{input:{orderId:e.orderId,status:e.status}}),onSuccess:()=>{V(),r(!1),I(""),C(!1)},onError:e=>{}}),G=(0,ds.n)({mutationFn:e=>k(T,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:N?.id}),onSuccess:()=>{V(),r(!1),I(""),C(!1)},onError:e=>{}}),K=e=>!!e?.edges?.length&&e.edges.every((e=>E[e.node.id])),Y=x.useMemo((()=>B?.getDeliveriesByDriver?B.getDeliveriesByDriver.filter((e=>{if("ALL"!==y&&e.status!==y)return!1;if(l){const s=l.toLowerCase(),t=e.orderId.toString().includes(s),n=e.address?.toLowerCase().includes(s);return t||n}return!0})):[]),[B?.getDeliveriesByDriver,y,l]);if(O||_&&N?.id)return(0,ee.jsx)(j.A,{sx:{display:"block",mx:"auto",mt:4}});if(U)return(0,ee.jsx)(m.A,{color:"error",children:"Error fetching user profile!"});if(M&&N?.id)return(0,ee.jsx)(m.A,{color:"error",children:"Error fetching deliveries!"});const Q=B?.getDeliveriesByDriver||[],Z=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"}},X=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,ee.jsx)(fn.A,{});case"PICKED_UP":return(0,ee.jsx)(As.A,{});case"DELIVERED":return(0,ee.jsx)(jn.A,{});case"CANCELLED":return(0,ee.jsx)(yn.A,{});default:return null}},se=e=>B?.getDeliveriesByDriver?B.getDeliveriesByDriver.filter((s=>s.status===e)).length:0;return(0,ee.jsxs)(h.A,{maxWidth:"lg",sx:{mt:4,mb:6},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:4,flexDirection:{xs:"column",sm:"row"},gap:{xs:2,sm:0}},children:[(0,ee.jsx)(m.A,{variant:"h4",fontWeight:"500",sx:{fontSize:{xs:"1.5rem",sm:"2rem"}},children:"Delivery Partner Dashboard"}),(0,ee.jsx)(p.A,{size:"small",placeholder:"Search orders...",value:l,onChange:e=>c(e.target.value),InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(sn.A,{fontSize:"small"})})},sx:{width:{xs:"100%",sm:250},"& .MuiOutlinedInput-root":{borderRadius:2}}})]}),(0,ee.jsx)(g.A,{sx:{mb:4},children:(0,ee.jsxs)(rt.A,{value:w,onChange:(e,s)=>{P(s),0===s?f("ALL"):1===s?f("READY_FOR_DELIVERY"):2===s?f("PICKED_UP"):3===s&&f("DELIVERED")},variant:"scrollable",scrollButtons:"auto",sx:{borderBottom:1,borderColor:"divider","& .MuiTab-root":{minWidth:120,textTransform:"none",fontSize:"0.875rem"}},children:[(0,ee.jsx)(it.A,{label:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:["All Orders",(0,ee.jsx)(Me.A,{badgeContent:Q.length,color:"primary",sx:{ml:2}})]})}),(0,ee.jsx)(it.A,{label:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:["Ready",(0,ee.jsx)(Me.A,{badgeContent:se("READY_FOR_DELIVERY"),color:"primary",sx:{ml:2}})]})}),(0,ee.jsx)(it.A,{label:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:["In Transit",(0,ee.jsx)(Me.A,{badgeContent:se("PICKED_UP"),color:"info",sx:{ml:2}})]})}),(0,ee.jsx)(it.A,{label:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:["Delivered",(0,ee.jsx)(Me.A,{badgeContent:se("DELIVERED"),color:"success",sx:{ml:2}})]})})]})}),(0,ee.jsx)(ye.Ay,{container:!0,spacing:{xs:2,sm:3},children:Y.length>0?Y.map((e=>(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ee.jsx)(fe.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=>{t(e),d(e.orderStatus||e.status),r(!0),C(!1),I("")})(e),children:(0,ee.jsxs)(ve.A,{sx:{flexGrow:1,p:{xs:2,sm:2.5}},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,ee.jsxs)(m.A,{variant:"h6",sx:{fontSize:{xs:"1rem",sm:"1.25rem"},fontWeight:500},children:["Order #",e.orderId]}),(0,ee.jsx)(Fe.A,{icon:X(e.status),label:e.status.replace(/_/g," "),color:Z(e.status),size:"small",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},height:{xs:24,sm:28},borderRadius:1.5}})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ee.jsx)(Hn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,ee.jsx)(m.A,{variant:"body2",sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:new Date(e.schedule).toLocaleString()})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,ee.jsx)(Ut.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,ee.jsx)(m.A,{variant:"body2",sx:{flexGrow:1,fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:e?.order?.address?.address||"No address provided"})]}),e.pickedUpTime&&(0,ee.jsxs)(m.A,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},mb:1},children:["Picked up: ",new Date(e.pickedUpTime).toLocaleString()]}),e.deliveredTime&&(0,ee.jsxs)(m.A,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"}},children:["Delivered: ",new Date(e.deliveredTime).toLocaleString()]}),"CANCELLED"===e.status&&e.order?.cancelMessage&&(0,ee.jsx)(g.A,{sx:{mt:1},children:(0,ee.jsxs)(m.A,{variant:"body2",color:"error",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},fontStyle:"italic",bgcolor:"error.lightest",p:1,borderRadius:1,display:"flex",alignItems:"center"},children:[(0,ee.jsx)(yn.A,{fontSize:"small",sx:{mr:.5,flexShrink:0}}),(0,ee.jsxs)("span",{style:{lineHeight:1},children:['Cancellation Reason: "',e.order.cancelMessage,'"']})]})}),e.comments&&"CANCELLED"!==e.status&&(0,ee.jsx)(g.A,{sx:{mt:1},children:(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},fontStyle:"italic",display:"flex",alignItems:"flex-start"},children:(0,ee.jsxs)("span",{children:['"',e.comments,'"']})})})]})})},e.id))):(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(de.A,{sx:{p:{xs:3,sm:4},borderRadius:2,textAlign:"center"},children:[(0,ee.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"No Deliveries Found"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:l||"ALL"!==y?"No deliveries match your search criteria.":"You have no deliveries assigned at this time."})]})})}),(0,ee.jsx)(Ns.A,{open:n,onClose:()=>r(!1),"aria-labelledby":"delivery-details-modal",children:(0,ee.jsx)(g.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:s&&(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,ee.jsxs)(m.A,{variant:"h5",fontWeight:"500",sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"}},children:["Order #",s.orderId]}),(0,ee.jsx)(pe.A,{edge:"end","aria-label":"close",onClick:()=>r(!1),size:"small",children:(0,ee.jsx)(ns.A,{})})]}),(0,ee.jsx)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:(0,ee.jsx)(Fe.A,{icon:X(s.status),label:s.status.replace(/_/g," "),color:Z(s.status),sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}}})}),(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY ADDRESS"}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"flex-start"},children:[(0,ee.jsx)(Ut.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,ee.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:s.order?.pickupAddress?.address||s.order?.address?.address||s.address||"No address provided"})]})]}),(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"SCHEDULED DELIVERY"}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ee.jsx)(Hn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,ee.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(s.schedule).toLocaleString()})]})]}),s.pickedUpTime&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"PICKED UP"}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ee.jsx)(As.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,ee.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(s.pickedUpTime).toLocaleString()})]})]}),s.deliveredTime&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERED"}),(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ee.jsx)(jn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,ee.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(s.deliveredTime).toLocaleString()})]})]}),"CANCELLED"===s.status&&s.order?.cancelMessage&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"error",gutterBottom:!0,children:"CANCELLATION REASON"}),(0,ee.jsxs)(g.A,{sx:{p:2,bgcolor:"error.lightest",borderRadius:1,borderLeft:"3px solid",borderColor:"error.main",display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(yn.A,{color:"error",sx:{flexShrink:0}}),(0,ee.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"},color:"error.main",lineHeight:1.2},children:s.order.cancelMessage})]})]}),s.comments&&"CANCELLED"!==s.status&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"COMMENTS"}),(0,ee.jsx)(g.A,{sx:{p:2,bgcolor:"rgba(0, 0, 0, 0.03)",borderRadius:1,borderLeft:"3px solid",borderColor:"primary.main"},children:(0,ee.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:s.comments})})]}),s.photo&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY PROOF"}),(0,ee.jsx)("img",{src:s.photo,alt:"Delivery Proof",style:{width:"100%",borderRadius:4}})]}),$&&s?.order?.orderItems&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"VERIFY ITEMS TO BE PICKED UP"}),(0,ee.jsx)(de.A,{sx:{p:2,maxHeight:300,overflow:"auto"},children:s.order.orderItems.edges.filter((e=>{let{node:s}=e;return null===s.updatedOrderitemsId&&s.quantity>0})).map((e=>{let{node:s}=e;return(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:1,p:1,borderRadius:1,bgcolor:"background.default"},children:[(0,ee.jsx)(Vn.A,{checked:!!E[s.id],onChange:()=>{return e=s.id,void L((s=>({...s,[e]:!s[e]})));var e},color:"primary"}),(0,ee.jsxs)(g.A,{sx:{ml:2,flex:1},children:[(0,ee.jsx)(m.A,{variant:"body2",fontWeight:"500",children:s.product.name}),(0,ee.jsxs)(m.A,{variant:"caption",color:"text.secondary",children:["Quantity: ",s.quantity," × $",s.orderAmount.toFixed(2)]})]})]},s.id)}))}),!K(s.order.orderItems)&&(0,ee.jsx)(ae.A,{severity:"warning",sx:{mt:1},children:"Please verify all items before updating status"})]}),(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"UPDATE STATUS"}),(0,ee.jsx)(cs.A,{fullWidth:!0,sx:{mb:2},children:(0,ee.jsxs)(Zt.A,{value:o,onChange:e=>{const t=e.target.value;d(t),"READY_FOR_DELIVERY"===s?.status&&"READY_FOR_DELIVERY"!==t?(q(!0),L({})):q(!1),C("CANCELLED"===t)},size:"small",children:[(0,ee.jsx)(ge.A,{value:"PICKED_UP",children:"Picked Up"}),(0,ee.jsx)(ge.A,{value:"DELIVERED",children:"Delivered"}),(0,ee.jsx)(ge.A,{value:"CANCELLED",children:"Cancelled"})]})}),S&&(0,ee.jsx)(p.A,{fullWidth:!0,label:"Cancellation Reason",multiline:!0,rows:3,value:b,onChange:e=>I(e.target.value),sx:{mb:2},required:!0,size:"small"}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"flex-end",mt:3},children:(0,ee.jsx)(te.A,{onClick:()=>{s&&o&&("READY_FOR_DELIVERY"!==s.status||"READY_FOR_DELIVERY"===o||K(s.order.orderItems))&&("CANCELLED"===o?G.mutate({orderId:s.orderId,cancelMessage:b}):H.mutate({orderId:s.orderId,status:o}))},variant:"contained",color:"primary",disabled:("CANCELLED"===o?G.isPending||G.isLoading:H.isPending||H.isLoading)||o===s.orderStatus||"CANCELLED"===o&&!b||$&&!K(s.order.orderItems),startIcon:("CANCELLED"===o?G.isPending||G.isLoading:H.isPending||H.isLoading)?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,sx:{minWidth:120},children:("CANCELLED"===o?G.isPending||G.isLoading:H.isPending||H.isLoading)?"Updating...":"Update"})})]})})})]})};var Kn=t(80669),Yn=t(47922);const Qn=[{text:"Dashboard",icon:(0,ee.jsx)(Rt.A,{}),path:qs},{text:"Orders",icon:(0,ee.jsx)(Pe.A,{}),path:Rs},{text:"Delivery Partners",icon:(0,ee.jsx)(As.A,{}),path:"/store_manager/delivery-partners"},{text:"Inventory",icon:(0,ee.jsx)(zt.A,{}),path:"/store_manager/inventory"},{text:"Delivery Fees",icon:(0,ee.jsx)(Yn.A,{}),path:"/store_manager/delivery-fees"},{text:"Location Codes",icon:(0,ee.jsx)(Ut.A,{}),path:"/store_manager/location-codes"},{text:"Pickup Addresses",icon:(0,ee.jsx)(As.A,{}),path:"/store_manager/pickup-addresses"},{text:"Payment Settings",icon:(0,ee.jsx)(Yn.A,{}),path:"/store_manager/payment-settings"}],Jn=()=>{const e=(0,Ee.A)(),s=(0,Es.A)(e.breakpoints.down("sm")),t=(0,l.Zp)(),n=(0,l.zy)(),{open:r,setOpen:i}=x.useContext(Zn),a=(0,ee.jsxs)(g.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:r&&!s?"space-between":"center",p:2,minHeight:64},children:[r&&!s&&(0,ee.jsx)(m.A,{variant:"h6",noWrap:!0,component:"div",children:"Store Manager"}),!s&&(0,ee.jsx)(pe.A,{onClick:()=>{i(!r)},children:r?(0,ee.jsx)(Je.A,{}):(0,ee.jsx)(Nt.A,{})})]}),(0,ee.jsx)(ss.A,{}),(0,ee.jsx)(fs.A,{children:Qn.map((e=>(0,ee.jsxs)(bs.Ay,{button:!0,onClick:()=>{return s=e.path,void t(s);var s},selected:n.pathname===e.path,sx:{minHeight:48,justifyContent:r&&!s?"initial":"center",px:2.5,"&.Mui-selected":{backgroundColor:"primary.light","&:hover":{backgroundColor:"primary.light"}}},children:[(0,ee.jsx)(vs.A,{sx:{minWidth:0,mr:r&&!s?3:"auto",justifyContent:"center",color:n.pathname===e.path?"primary.main":"inherit"},children:e.icon}),(0,ee.jsx)(Is.A,{primary:e.text,sx:{opacity:r&&!s?1:0}})]},e.text)))})]});return(0,ee.jsx)(g.A,{component:"nav",sx:{width:s?65:r?240:65,flexShrink:0,position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,ee.jsx)(Ss.Ay,{variant:"persistent",open:!0,sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:s?65: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:a})})},Zn=(0,x.createContext)({open:!0,setOpen:()=>{}}),Xn=e=>{let{children:s}=e;const t=(0,Ee.A)(),[n,r]=((0,Es.A)(t.breakpoints.down("sm")),(0,x.useState)(!0));return(0,ee.jsx)(Zn.Provider,{value:{open:n,setOpen:r},children:(0,ee.jsxs)(g.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,ee.jsx)(d.Ay,{}),(0,ee.jsx)(Et,{}),(0,ee.jsx)(Jn,{}),(0,ee.jsx)(g.A,{component:"main",sx:{flexGrow:1,p:{xs:0,sm:3},width:{xs:"calc(100% - 65px)",sm:`calc(100% - ${n?240:65}px)`},ml:{xs:"65px",sm:(n?240:65)+"px"},transition:t.transitions.create(["width","margin"],{easing:t.transitions.easing.sharp,duration:t.transitions.duration.leavingScreen}),display:"flex",flexDirection:"column",alignItems:"center",maxWidth:"100%",overflow:"hidden"},children:(0,ee.jsx)(g.A,{sx:{width:"100%"},children:s})})]})})},er=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=J(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(!1),[c,y]=(0,x.useState)(null),[f,b]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[C,w]=(0,x.useState)(""),[P,E]=(0,x.useState)(""),[F,L]=(0,x.useState)(""),[$,T]=(0,x.useState)(""),[q,R]=(0,x.useState)(""),[z,W]=(0,x.useState)(""),[O,U]=(0,x.useState)(""),[N,B]=(0,x.useState)(!1),[_,M]=(0,x.useState)(10),[V,H]=(0,x.useState)(""),[G,K]=(0,x.useState)([]),[Y,Q]=(0,x.useState)(!1),[Z,X]=((0,x.useRef)(null),(0,x.useState)(0)),[se,ne]=(0,x.useState)(10),[re,ie]=(0,x.useState)(!0),[oe,le]=(0,x.useState)(null),[ce,xe]=(0,x.useState)({open:!1,message:"",severity:"success"}),[ue,me]=(0,x.useState)([]),[he,Ae]=(0,x.useState)(!0),[je,fe]=(0,x.useState)([]),[be,ve]=(0,x.useState)(!1);(0,x.useEffect)((()=>{let e=!0;return(async()=>{try{const t=await(0,Ms.T)();e&&s(t.sub)}catch(e){}})(),()=>{e=!1}}),[]),(0,x.useEffect)((()=>{const e=setTimeout((()=>{ie(!1)}),1e3);return()=>clearTimeout(e)}),[]);const{data:Ie,isLoading:Se}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{if(!e)return null;return await k(D,{userId:e})},enabled:!!e});(0,x.useEffect)((()=>{Ie?.getUserProfile&&!t&&n(Ie.getUserProfile)}),[Ie,t,n]);const{data:Ce,isLoading:Pe,error:ke,refetch:Ee}=(0,u.I)({queryKey:["storeWithInventory",t?.id],queryFn:async()=>t?.id?k("\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 images\n codEnabled\n whatsappNumber\n inventory {\n edges {\n node {\n id\n storeId\n productId\n quantity\n price\n measurement\n unit\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 }\n",{managerId:t.id}):null,enabled:!!t?.id}),De=Ce?.storesByManager?.[0]||null,Le=De?.inventory?.edges?.map((e=>e.node))||[],$e=Ce?.products||[],{data:Te,isLoading:Oe}=(0,u.I)({queryKey:["storeSquareStatus",De?.id],queryFn:()=>k("\n query StoreSquareStatus($storeId: Int!) {\n storeSquareStatus(storeId: $storeId) {\n storeId\n storeName\n isConnected\n }\n }\n",{storeId:De?.id}),enabled:!!De?.id}),Ue=Te?.storeSquareStatus?.isConnected||!1;(0,x.useEffect)((()=>{if($e.length)if(""===V.trim())K($e);else{const e=$e.filter((e=>e.name.toLowerCase().includes(V.toLowerCase())));K(e)}}),[V,$e]);const Ne=(0,ds.n)({mutationFn:e=>k("\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 $images: [String!]\n $whatsappNumber: 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 images: $images\n whatsappNumber: $whatsappNumber\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 images\n whatsappNumber\n }\n }\n",e),onSuccess:()=>{xe({open:!0,message:"Store updated successfully",severity:"success"}),le(null),Ee()},onError:e=>{xe({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),Be=()=>{le(null),me([]),fe([]),Ae(!0)};return Se||Pe||re||!De?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})})}):ke?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4},children:(0,ee.jsxs)(ae.A,{severity:"error",children:["Error loading store data: ",ke.message]})})}):De||re?(0,ee.jsx)(Xn,{children:(0,ee.jsxs)(h.A,{sx:{mb:4},children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Manager Dashboard"}),(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,ee.jsx)(m.A,{variant:"h5",children:"Store Information"}),(0,ee.jsx)(te.A,{variant:"outlined",startIcon:(0,ee.jsx)(en.A,{}),onClick:()=>{De&&(le(De),me(De.sectionHeaders||[]),fe(De.images||[]),Ae(De.isActive))},sx:{textTransform:"none"},children:"Edit Store"})]}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Name:"})," ",De.name]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Address:"})," ",De.address]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Delivery Radius:"})," ",De.radius||"Not set"," ",De.radius?"mi":""]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Delivery Fee:"})," $",De.storeDeliveryFee?.toFixed(2)||"0.00"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Tax Rate:"})," ",De.taxPercentage?.toFixed(1)||"0.0","%"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Total Products:"})," ",Le.filter((e=>e.isListed)).length]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Display Field:"})," ",De.displayField]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Square Payment:"})," ",(0,ee.jsx)(Fe.A,{size:"small",label:Ue?"Connected":"Not Connected",color:Ue?"success":"default"})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Cash on Delivery:"})," ",(0,ee.jsx)(Fe.A,{size:"small",label:De?.codEnabled?"Enabled":"Disabled",color:De?.codEnabled?"success":"default"})]})}),De.whatsappNumber&&(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"WhatsApp:"})," ",De.whatsappNumber]})}),De.description&&(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Description:"})," ",De.description]})}),De.pincodes&&De.pincodes.length>0&&(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:[(0,ee.jsx)("strong",{children:"Delivery Pincodes:"})," ",De.pincodes.join(", ")]})}),De.sectionHeaders&&De.sectionHeaders.length>0&&(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:(0,ee.jsx)("strong",{children:"Section Headers:"})}),(0,ee.jsx)(g.A,{sx:{pl:2},children:De.sectionHeaders.map(((e,s)=>(0,ee.jsxs)(m.A,{variant:"body2",sx:{mb:1},children:["• ",e]},s)))})]})]})]}),(0,ee.jsxs)(qe.A,{open:!!oe,onClose:Be,maxWidth:"md",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(bt.A,{}),(0,ee.jsx)(m.A,{variant:"h6",children:"Edit Store"})]})}),(0,ee.jsxs)("form",{onSubmit:e=>{if(e.preventDefault(),!oe)return;const s=new FormData(e.target),t=s.get("pincodes"),n=t?t.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],r={storeId:oe.id,name:s.get("name"),address:s.get("address"),email:s.get("email"),mobile:s.get("mobile")||null,radius:parseFloat(s.get("radius")),isActive:"true"===s.get("isActive"),description:s.get("description")||null,pincodes:n,tnc:s.get("tnc")||null,storeDeliveryFee:parseFloat(s.get("storeDeliveryFee"))||null,taxPercentage:parseFloat(s.get("taxPercentage"))||null,displayField:s.get("displayField"),sectionHeaders:ue.filter((e=>e.trim().length>0)),images:je,whatsappNumber:s.get("whatsappNumber")||null};Ne.mutate(r)},children:[(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"name",label:"Store Name",defaultValue:oe?.name,required:!0,fullWidth:!0})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"email",label:"Email",type:"email",defaultValue:oe?.email,required:!0,fullWidth:!0})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"mobile",label:"Mobile Number",defaultValue:oe?.mobile,fullWidth:!0})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{name:"address",label:"Address",defaultValue:oe?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:oe?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:oe?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:"$"})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:oe?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,ee.jsx)(A.A,{position:"end",children:"%"})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:oe?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{name:"description",label:"Description",defaultValue:oe?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{name:"tnc",label:"Terms & Conditions",defaultValue:oe?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{name:"whatsappNumber",label:"WhatsApp Support Number",placeholder:"+1234567890",defaultValue:oe?.whatsappNumber,fullWidth:!0,helperText:"Include country code. Optional."})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{name:"displayField",label:"Display Field",defaultValue:oe?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,ee.jsxs)(g.A,{sx:{mb:2},children:[ue.map(((e,s)=>(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,ee.jsx)(p.A,{fullWidth:!0,label:`Question ${s+1}`,value:e,onChange:e=>((e,s)=>{me((t=>{const n=[...t];return n[e]=s,n}))})(s,e.target.value),placeholder:"Enter question text",inputProps:{"aria-label":`Question ${s+1}`}}),(0,ee.jsx)(pe.A,{color:"error",onClick:()=>(e=>{me((s=>s.filter(((s,t)=>t!==e))))})(s),sx:{alignSelf:"center"},"aria-label":"Remove question",children:(0,ee.jsx)(dn.A,{})})]},s))),(0,ee.jsx)(te.A,{startIcon:(0,ee.jsx)(we.A,{}),onClick:()=>{me((e=>[...e,""]))},variant:"outlined",sx:{mt:1},"aria-label":"Add question",children:"Add Question"})]})]}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Images / Offers Banner"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{mb:2},children:[(0,ee.jsx)("input",{accept:"image/*",style:{display:"none"},id:"edit-store-image-upload",type:"file",onChange:e=>{const s=e.target.files[0];s&&(async e=>{if(e&&oe?.id){ve(!0);try{const s=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",t=await(0,v.$)(),n=t.tokens?.accessToken?.toString(),r={"Content-Type":"application/json"};n&&(r.Authorization=`Bearer ${n}`);const i=await fetch(`${s}/s3/generate-store-upload-url?store_id=${oe.id}&file_name=${encodeURIComponent(e.name)}`,{method:"GET",headers:r});if(!i.ok){let e="Failed to get upload URL";try{const s=await i.json();e=s.detail||s.message||e}catch(s){e=i.statusText||e}throw new Error(e)}const{upload_url:a,content_type:o,key:d}=await i.json();if(!(await fetch(a,{method:"PUT",headers:{"Content-Type":o},body:e})).ok)throw new Error("Failed to upload image");const l=`https://indimitra-dev-order-files.s3.amazonaws.com/${d}`;fe((e=>[...e,l])),xe({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){xe({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{ve(!1)}}})(s),e.target.value=""}}),(0,ee.jsx)("label",{htmlFor:"edit-store-image-upload",children:(0,ee.jsx)(te.A,{variant:"outlined",component:"span",startIcon:be?(0,ee.jsx)(j.A,{size:16}):(0,ee.jsx)(Kn.A,{}),disabled:be,sx:{mb:2},children:be?"Uploading...":"Upload Image"})}),je.length>0&&(0,ee.jsx)(g.A,{sx:{display:"flex",flexWrap:"wrap",gap:2},children:je.map(((e,s)=>(0,ee.jsxs)(g.A,{sx:{position:"relative",width:150,height:150},children:[(0,ee.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,ee.jsx)(pe.A,{size:"small",color:"error",onClick:()=>(e=>{fe((s=>s.filter(((s,t)=>t!==e))))})(s),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,ee.jsx)(dn.A,{fontSize:"small"})})]},s)))})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,children:[(0,ee.jsx)(Jt.A,{children:"Store Status"}),(0,ee.jsxs)(Zt.A,{name:"isActive",label:"Store Status",value:he,onChange:e=>{Ae(e.target.value)},children:[(0,ee.jsx)(ge.A,{value:!0,children:"Active"}),(0,ee.jsx)(ge.A,{value:!1,children:"Inactive"})]})]})})]})}),(0,ee.jsxs)(We.A,{sx:{p:3,pt:0},children:[(0,ee.jsx)(te.A,{onClick:Be,children:"Cancel"}),(0,ee.jsx)(te.A,{type:"submit",variant:"contained",disabled:Ne.isPending,startIcon:Ne.isPending?(0,ee.jsx)(j.A,{size:20}):null,children:Ne.isPending?"Updating...":"Update Store"})]})]})]}),(0,ee.jsx)(Xt.A,{open:ce.open,autoHideDuration:6e3,onClose:()=>xe({...ce,open:!1}),children:(0,ee.jsx)(ae.A,{onClose:()=>xe({...ce,open:!1}),severity:ce.severity,sx:{width:"100%"},children:ce.message})})]})}):(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4},children:(0,ee.jsx)(ae.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})};var sr=t(52848),tr=t(79381),nr=t(29682),rr=t(92183),ir=t(69149),ar=t(51365);const or=()=>{const[,e]=(0,x.useReducer)((e=>e+1),0),[s,t]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[o,d]=(0,x.useState)(null),[l,c]=(0,x.useState)(""),[A,y]=(0,x.useState)(!1),[f,b]=(0,x.useState)(null),[I,S]=(0,x.useState)(null),[C,w]=(0,x.useState)({open:!1,title:"",message:"",onConfirm:null}),P=(0,Ee.A)(),E=(0,Es.A)(P.breakpoints.down("sm")),{userProfile:F,setUserProfile:L}=J();(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,v.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;t(s)}}catch(e){}})()}),[]);const{data:$,isLoading:q,error:R}=(0,u.I)({queryKey:["getUserProfile",s],queryFn:async()=>{const t=await k(D,{userId:s});return t?.getUserProfile&&(L(t.getUserProfile),setTimeout((()=>{e()}),200)),t},enabled:!!s,onError:e=>{}}),z=J.getState().userProfile||F||$?.getUserProfile,{data:W,isLoading:O,error:U,refetch:N}=(0,u.I)({queryKey:["userOrders",z?.id],queryFn:()=>k("\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:z.id}),enabled:!!z?.id}),B=(0,ds.n)({mutationFn:e=>k(T,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:z.id}),onSuccess:()=>{N(),M(),c("")}}),_=(0,ds.n)({mutationFn:e=>k("\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)},V=e=>{d(o===e?null:e)},H=(e,s,t)=>{if(!s||!s.id)return;const n=t-s.quantity,r=(s.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),d={orderId:parseInt(e.id,10),orderItemUpdates:[{orderItemId:parseInt(s.id,10),quantityChange:n}],totalAmount:i,orderTotalAmount:o,taxAmount:a};_.mutate(d)},G=e=>{if(!e?.edges?.length)return null;const s=new Map;e.edges.forEach((e=>{let{node:t}=e;s.set(t.id,t)}));return e.edges.map((e=>{let{node:s}=e;return s})).filter((e=>null===e.updatedOrderitemsId))},K=()=>{b(null),S(null)},Y=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e);if(q||O&&z?.id)return(0,ee.jsx)(j.A,{sx:{display:"block",mx:"auto",mt:4}});if(R)return(0,ee.jsx)(m.A,{color:"error",children:"Error fetching user profile!"});if(U&&z?.id)return(0,ee.jsx)(m.A,{color:"error",children:"Error fetching orders!"});const Q=[...W?.getOrdersByUser||[]].sort(((e,s)=>s.id-e.id));return(0,ee.jsxs)(h.A,{maxWidth:"xl",sx:{mt:4,px:{xs:1,sm:2,md:3}},children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,sx:{fontSize:{xs:"1.5rem",sm:"2rem",md:"2.125rem"},mb:{xs:2,sm:3}},children:"My Orders"}),0===Q.length?(0,ee.jsx)(m.A,{children:"No orders found!"}):(0,ee.jsx)(Vt.A,{component:de.A,sx:{mt:2,overflowX:"auto","& .MuiTableCell-root":{px:{xs:1,sm:2},py:{xs:1.5,sm:2},whiteSpace:"nowrap"}},children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{sx:{display:{xs:"none",md:"table-cell"}},children:"Order ID"}),(0,ee.jsx)(Yt.A,{children:"Address"}),(0,ee.jsx)(Yt.A,{children:"Status"}),(0,ee.jsx)(Yt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Total"}),(0,ee.jsx)(Yt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Delivery Date"}),(0,ee.jsx)(Yt.A,{children:"Bill"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:Q.map((e=>(0,ee.jsxs)(x.Fragment,{children:[(0,ee.jsxs)(Kt.A,{onClick:()=>V(e.id),sx:{cursor:"pointer"},children:[(0,ee.jsx)(Yt.A,{sx:{display:{xs:"none",md:"table-cell"}},children:e.id}),(0,ee.jsxs)(Yt.A,{children:[E&&(0,ee.jsxs)(m.A,{variant:"caption",sx:{fontWeight:700,color:"primary.main",display:"block",mb:.5},children:["Order #",e.id]}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"PICKUP"===e.type?(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(Ps.A,{fontSize:"small"}),e.pickupAddress?.address||"Pickup location not specified"]}):(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(As.A,{fontSize:"small"}),e.address?.address||"No address provided"]})})]}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:vn.find((s=>s.value===e.status))?.label||e.status,size:E?"small":"medium",color:vn.find((s=>s.value===e.status))?.color||"default"})}),(0,ee.jsxs)(Yt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:["$",e.totalAmount.toFixed(2)]}),(0,ee.jsx)(Yt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:e.deliveryDate?new Date(e.deliveryDate).toLocaleDateString():"N/A"}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(g.A,{sx:{display:"flex",gap:1},children:(0,ee.jsx)(Se.A,{title:"Download Bill",children:(0,ee.jsx)(pe.A,{size:"small",onClick:s=>{s.stopPropagation(),(async e=>{if(!A)try{y(!0);const s=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",t=await fetch(`${s}/s3/generate-view-url?order_id=${e}&file_name=order_${e}.jpeg`);if(200===t.status){const e=await t.json();if(e?.view_url){const s=document.createElement("a");return s.href=e.view_url,s.download=e.file_name,s.target="_blank",document.body.appendChild(s),s.click(),void document.body.removeChild(s)}}alert("No bill available for this order")}catch(e){alert("Error downloading the bill. Please try again.")}finally{y(!1)}})(e.id)},children:(0,ee.jsx)(tr.A,{})})})})}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,ee.jsx)(te.A,{variant:"contained",color:"error",size:E?"small":"medium",onClick:s=>{var t;s.stopPropagation(),t=e.id,a(t),r(!0)},disabled:!Y(e.status),children:"Cancel"}),(0,ee.jsx)(pe.A,{onClick:s=>{s.stopPropagation(),V(e.id)},size:"small",children:o===e.id?(0,ee.jsx)(nr.A,{}):(0,ee.jsx)(rr.A,{})})]})})]}),(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{style:{paddingBottom:0,paddingTop:0},colSpan:7,children:(0,ee.jsx)(sr.A,{in:o===e.id,timeout:"auto",unmountOnExit:!0,children:(0,ee.jsx)(g.A,{sx:{margin:{xs:1,sm:2}},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsxs)(m.A,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1,color:"primary.main",fontWeight:600,fontSize:{xs:"1rem",sm:"1.25rem"}},children:[(0,ee.jsx)(Ps.A,{})," Order Items"]}),(0,ee.jsx)(de.A,{sx:{p:{xs:1.5,sm:2}},children:e.orderItems?.edges?.length>0?(0,ee.jsx)(ye.Ay,{container:!0,spacing:{xs:1,sm:2},children:G(e.orderItems).map((s=>{const t=s.product.inventoryItems?.edges[0]?.node,n=((e,s)=>{const t=new Map;s.forEach((e=>{let{node:s}=e;t.set(s.id,s)}));const n=[e];let r=e.id;for(;;){const e=Array.from(t.values()).find((e=>e.updatedOrderitemsId===r));if(!e)break;n.push(e),r=e.id}return n.reverse()})(s,e.orderItems.edges);return(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(fe.A,{variant:"outlined",sx:{p:{xs:1.5,sm:2},"&:hover":{bgcolor:"grey.50"}},children:[(0,ee.jsxs)(ye.Ay,{container:!0,spacing:{xs:1,sm:2},alignItems:"center",children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,sm:4,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",fontWeight:600,sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:s.product.name}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:500,children:s.product.category.name}),n.length>1&&(0,ee.jsxs)(m.A,{variant:"caption",color:"primary",sx:{display:"block",mt:.5},children:[n.length-1," previous version",n.length>2?"s":""]})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:6,sm:2,children:[(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Unit Price"}),(0,ee.jsxs)(m.A,{variant:"body1",fontWeight:500,children:["$",t?.price.toFixed(2)]}),t&&(0,ee.jsxs)(m.A,{variant:"caption",color:"text.secondary",fontWeight:500,children:[t.measurement," ",t.unit]})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:6,sm:2,children:[(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Quantity"}),f===s.id?(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(p.A,{type:"number",size:"small",value:I,onChange:e=>S(parseInt(e.target.value)||0),inputProps:{min:0},sx:{width:"80px"}}),(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:.5},children:[(0,ee.jsx)(pe.A,{size:"small",color:"primary",onClick:()=>((e,s)=>{0===I?w({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{H(e,s,0),b(null),S(null),w({open:!1,title:"",message:"",onConfirm:null})}}):I>0&&(H(e,s,I),b(null),S(null))})(e,s),disabled:null===I||I<0,children:(0,ee.jsx)(ir.A,{fontSize:"small"})}),(0,ee.jsx)(pe.A,{size:"small",color:"error",onClick:K,children:(0,ee.jsx)(ns.A,{fontSize:"small"})})]})]}):(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(m.A,{variant:"body1",fontWeight:500,children:s.quantity}),Y(e.status)&&(0,ee.jsx)(pe.A,{size:"small",onClick:()=>{return b((e=s).id),void S(e.quantity);var e},children:(0,ee.jsx)(en.A,{fontSize:"small"})})]})]}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:4,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",sm:"flex-end"},alignItems:"center",gap:1,mt:{xs:1,sm:0}},children:[(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Total:"}),(0,ee.jsxs)(m.A,{variant:"h6",color:"primary",fontWeight:700,sx:{fontSize:{xs:"1rem",sm:"1.25rem"}},children:["$",(s.quantity*(s.product.inventoryItems?.edges[0]?.node?.price||0)).toFixed(2)]}),Y(e.status)&&(0,ee.jsx)(pe.A,{size:"small",color:"error",onClick:t=>{t.stopPropagation(),((e,s)=>{w({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{H(e,s,0),w({open:!1,title:"",message:"",onConfirm:null})}})})(e,s)},children:(0,ee.jsx)(dn.A,{fontSize:"small"})})]})})]}),n.length>1&&(0,ee.jsxs)(g.A,{sx:{mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[(0,ee.jsxs)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(ar.A,{fontSize:"small"}),"Order Change History (",n.length-1," ","changes)"]}),(0,ee.jsx)(g.A,{sx:{pl:2},children:n.slice(0,-1).map(((e,s)=>(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1.5,borderRadius:1,mb:1},children:[(0,ee.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"120px",fontWeight:500},children:["Change ",s+1]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:3},children:[(0,ee.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,ee.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount: $",e.orderAmount.toFixed(2)]})]})]},e.id)))})]})]})},s.id)}))}):(0,ee.jsx)(g.A,{sx:{textAlign:"center",py:3,color:"text.secondary"},children:(0,ee.jsx)(m.A,{fontWeight:500,children:"No items found for this order."})})})]}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(de.A,{sx:{p:{xs:1.5,sm:2},mb:3},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,md:6,children:[(0,ee.jsxs)(m.A,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1,color:"primary.main",fontWeight:600,mb:1,fontSize:{xs:"1rem",sm:"1.25rem"}},children:[(0,ee.jsx)(tr.A,{})," Order Details"]}),(0,ee.jsxs)(g.A,{sx:{pl:1},children:[e.customOrder&&(0,ee.jsxs)(g.A,{sx:{mb:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Custom Order Instructions"}),(0,ee.jsx)(m.A,{variant:"body2",fontWeight:500,sx:{whiteSpace:"pre-line",bgcolor:"grey.50",p:1.5,borderRadius:1,mt:.5},children:e.customOrder})]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Subtotal"}),(0,ee.jsxs)(m.A,{fontWeight:500,children:["$",e.totalAmount?e.totalAmount.toFixed(2):"0.00"]})]}),void 0!==e.deliveryFee&&(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Fee"}),(0,ee.jsxs)(m.A,{fontWeight:500,children:["$",e.deliveryFee?e.deliveryFee.toFixed(2):"0.00"]})]}),void 0!==e.taxAmount&&(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tax"}),(0,ee.jsxs)(m.A,{fontWeight:500,children:["$",e.taxAmount?e.taxAmount.toFixed(2):"0.00"]})]}),void 0!==e.tipAmount&&(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tip"}),(0,ee.jsxs)(m.A,{fontWeight:500,children:["$",e.tipAmount?e.tipAmount.toFixed(2):"0.00"]})]}),(0,ee.jsx)(ss.A,{sx:{my:1}}),(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Total Amount"}),(0,ee.jsxs)(m.A,{variant:"subtitle1",color:"primary",fontWeight:700,children:["$",e.orderTotalAmount?e.orderTotalAmount.toFixed(2):"0.00"]})]})]})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,md:6,children:[(0,ee.jsxs)(m.A,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1,color:"primary.main",fontWeight:600,mb:1,fontSize:{xs:"1rem",sm:"1.25rem"}},children:[(0,ee.jsx)(As.A,{})," Delivery Information"]}),(0,ee.jsxs)(g.A,{sx:{pl:1},children:[(0,ee.jsxs)(g.A,{sx:{mb:1},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"PICKUP"===e.type?"Pickup Location":"Delivery Address"}),(0,ee.jsx)(m.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,ee.jsxs)(g.A,{sx:{mb:1},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Instructions"}),(0,ee.jsx)(m.A,{variant:"body2",fontWeight:500,children:e.deliveryInstructions})]}),e.deliveryDate&&(0,ee.jsxs)(g.A,{sx:{mb:1},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,children:"Expected Delivery Date"}),(0,ee.jsx)(m.A,{variant:"body2",fontWeight:500,children:new Date(e.deliveryDate).toLocaleDateString()})]}),e.cancelMessage&&(0,ee.jsxs)(g.A,{sx:{mb:1},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"error",fontWeight:700,children:"Cancellation Reason"}),(0,ee.jsx)(m.A,{variant:"body2",color:"error",fontWeight:500,children:e.cancelMessage})]})]})]})]})})})]})})})})})]},e.id)))})]})}),(0,ee.jsxs)(qe.A,{open:n,onClose:M,fullWidth:!0,maxWidth:"sm",children:[(0,ee.jsx)(Re.A,{children:"Cancel Order"}),(0,ee.jsxs)(ze.A,{children:[(0,ee.jsx)(Sn.A,{gutterBottom:!0,children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,ee.jsx)(p.A,{autoFocus:!0,margin:"dense",id:"cancelMessage",label:"Reason for Cancellation",type:"text",fullWidth:!0,variant:"outlined",value:l,onChange:e=>c(e.target.value),error:n&&!l.trim(),sx:{mt:2}})]}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:M,color:"primary",children:"No, Keep Order"}),(0,ee.jsx)(te.A,{onClick:()=>{i&&l.trim()&&B.mutate({orderId:i,cancelMessage:l.trim()})},color:"error",variant:"contained",disabled:!l.trim()||B.isPending,startIcon:B.isPending?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:B.isPending?"Cancelling...":"Yes, Cancel Order"})]})]}),(0,ee.jsxs)(qe.A,{open:C.open,onClose:()=>w({open:!1,title:"",message:"",onConfirm:null}),children:[(0,ee.jsx)(Re.A,{children:C.title}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(Sn.A,{children:C.message})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>w({open:!1,title:"",message:"",onConfirm:null}),color:"primary",children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:C.onConfirm,color:"error",variant:"contained",children:"Remove"})]})]})]})};var dr=t(55629),lr=t(45402),cr=t(55764);const xr=()=>{const{userProfile:e,setUserProfile:s,fetchUserProfile:t,isProfileLoading:n,profileError:r}=J(),i=(0,l.Zp)(),[a,o]=(0,x.useState)(0),[d,c]=(0,x.useState)(null),[u,A]=(0,x.useState)(null),[y,f]=(0,x.useState)(!1),b=window.location.origin,{addresses:I,selectedAddressId:S,setSelectedAddressId:C,fetchAddresses:w,isLoading:P,createAddress:k,updateAddress:E,deleteAddress:F}=Z(),[D,L]=(0,x.useState)(!1),[$,T]=(0,x.useState)(null),[q,R]=(0,x.useState)(""),[z,W]=(0,x.useState)(!1),[O,U]=(0,x.useState)(!1),[N,B]=(0,x.useState)(!1),[_,M]=(0,x.useState)({open:!1,message:"",severity:"success"}),[V,H]=(0,x.useState)(!1),[G,K]=(0,x.useState)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,v.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;A(s),await t(s)}}catch(e){}})()}),[t]);const Y=e||d;(0,x.useEffect)((()=>{Y?.id&&w(Y.id)}),[Y?.id,w]);const Q=async()=>{try{await(0,ks.C)(),i("/")}catch(e){}},X=`${b}/signup?referredby=${e?.referralId}`,se=async()=>{try{await navigator.clipboard.writeText(X),f(!0),setTimeout((()=>f(!1)),2e3)}catch(e){}};if(n)return(0,ee.jsx)(h.A,{children:(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:[(0,ee.jsx)(j.A,{}),(0,ee.jsx)(m.A,{sx:{ml:2},children:"Loading profile..."})]})});if(r)return(0,ee.jsxs)(h.A,{children:[(0,ee.jsxs)(ae.A,{severity:"error",sx:{mt:4},children:["Error loading profile: ",r]}),(0,ee.jsx)(te.A,{variant:"contained",onClick:()=>t(),sx:{mt:2},children:"Retry"})]});if(!e)return(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(ae.A,{severity:"warning",sx:{mt:4},children:"No profile data available. Please try again."}),(0,ee.jsx)(te.A,{variant:"contained",onClick:async()=>{try{const e=await(0,v.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;await t(s)}}catch(e){}},sx:{mt:2},children:"Load Profile"})]});return(0,ee.jsxs)(h.A,{maxWidth:"xl",sx:{py:{xs:1,sm:4},px:{xs:.5,sm:2}},children:[(0,ee.jsxs)(g.A,{sx:{display:{xs:"block",md:"flex"},gap:{xs:0,md:3}},children:[(0,ee.jsxs)(g.A,{sx:{width:{xs:"100%",md:280},mb:{xs:2,md:0}},children:[(0,ee.jsxs)(de.A,{elevation:0,sx:{borderRadius:2,overflow:"hidden",boxShadow:1,mb:0,display:{xs:"none",md:"block"}},children:[(0,ee.jsx)(g.A,{sx:{p:2,bgcolor:"primary.main",color:"white",textAlign:"left"},children:(0,ee.jsx)(m.A,{variant:"h6",sx:{fontSize:"1.25rem"},children:"My Account"})}),(0,ee.jsx)(fs.A,{component:"nav",sx:{pt:0},children:[{label:"Profile",icon:(0,ee.jsx)(Cs.A,{}),idx:0},{label:"Addresses",icon:(0,ee.jsx)(Ut.A,{}),idx:1},{label:"Settings",icon:(0,ee.jsx)(cr.A,{}),idx:2}].map((e=>(0,ee.jsxs)(ht.A,{selected:a===e.idx,onClick:()=>o(e.idx),sx:{borderRadius:0,"&.Mui-selected":{bgcolor:"rgba(25, 118, 210, 0.08)",borderLeft:"4px solid",borderColor:"primary.main"}},children:[(0,ee.jsx)(vs.A,{sx:{minWidth:0,mr:2,justifyContent:"center"},children:x.cloneElement(e.icon,{color:a===e.idx?"primary":"inherit"})}),(0,ee.jsx)(Is.A,{primary:e.label})]},e.label)))})]}),(0,ee.jsxs)(de.A,{elevation:0,sx:{borderRadius:0,overflow:"hidden",boxShadow:0,mb:1,display:{xs:"block",md:"none"}},children:[(0,ee.jsx)(g.A,{sx:{p:2,bgcolor:"primary.main",color:"white",textAlign:"center"},children:(0,ee.jsx)(m.A,{variant:"h6",sx:{fontSize:"1.1rem"},children:"My Account"})}),(0,ee.jsx)(fs.A,{component:"nav",sx:{pt:0,display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center"},children:[{label:"Profile",icon:Cs.A,idx:0},{label:"Addresses",icon:Ut.A,idx:1},{label:"Settings",icon:cr.A,idx:2}].map((e=>(0,ee.jsx)(ht.A,{selected:a===e.idx,onClick:()=>o(e.idx),sx:{borderRadius:2,mx:.5,my:.5,minWidth:80,flex:1,justifyContent:"center","&.Mui-selected":{bgcolor:"primary.light"}},children:(0,ee.jsx)(vs.A,{sx:{minWidth:0,mr:0,justifyContent:"center"},children:(0,ee.jsx)(e.icon,{sx:{fontSize:28,color:a===e.idx?"primary.main":"text.secondary"}})})},e.label)))})]})]}),(0,ee.jsx)(g.A,{sx:{flexGrow:1,width:{xs:"100%",md:"auto"}},children:(0,ee.jsxs)(g.A,{sx:{height:"100%"},children:[0===a&&(0,ee.jsx)(g.A,{sx:{p:{xs:1,sm:2},bgcolor:{xs:"background.paper",sm:"transparent"},borderRadius:{xs:2,sm:2},boxShadow:{xs:1,sm:0},mb:{xs:2,sm:0},maxWidth:{xs:420,sm:"none"},mx:{xs:"auto",sm:0}},children:(0,ee.jsx)(fe.A,{sx:{height:"100%",width:{xs:"100%",sm:"auto"},p:{xs:1,sm:0},boxShadow:{xs:2,sm:1}},children:(0,ee.jsxs)(ve.A,{sx:{p:{xs:1,sm:2}},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"center",sm:"center"},mb:3,gap:{xs:2,sm:0}},children:[(0,ee.jsx)(pt.A,{sx:{width:{xs:72,sm:64},height:{xs:72,sm:64},bgcolor:"primary.main",fontSize:{xs:"2.2rem",sm:"1.8rem"},mb:{xs:1,sm:0},mr:{xs:0,sm:2.5}},children:e?.firstName?.[0]}),(0,ee.jsxs)(g.A,{sx:{textAlign:{xs:"center",sm:"left"},width:"100%"},children:[(0,ee.jsxs)(m.A,{variant:"h5",gutterBottom:!0,sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"},fontWeight:700},children:[e?.firstName," ",e?.lastName]}),(0,ee.jsxs)(es.A,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",flexWrap:"wrap",sx:{rowGap:1,justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",bgcolor:"rgba(255,107,107,0.08)",px:1.5,py:.5,borderRadius:2,mb:{xs:1,sm:0},justifyContent:"center"},children:[(0,ee.jsx)(xn.A,{sx:{mr:1,color:"primary.main",fontSize:22}}),(0,ee.jsx)(m.A,{sx:{color:"text.primary",fontWeight:600,fontSize:{xs:"1.12rem",sm:"1.1rem"},wordBreak:"break-all"},children:e?.email})]}),e?.mobile&&(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",bgcolor:"rgba(76,205,196,0.08)",px:1.5,py:.5,borderRadius:2,justifyContent:"center"},children:[(0,ee.jsx)(cn.A,{sx:{mr:1,color:"secondary.main",fontSize:22}}),(0,ee.jsx)(m.A,{sx:{color:"text.primary",fontWeight:500,fontSize:{xs:"1.1rem",sm:"1.08rem"}},children:e.mobile})]})]})]})]}),(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,sx:{textAlign:{xs:"center",sm:"left"},fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:"Referral Program"}),(0,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"stretch",sm:"center"},gap:2},children:[(0,ee.jsx)(p.A,{fullWidth:!0,value:X,InputProps:{readOnly:!0,endAdornment:(0,ee.jsx)(Se.A,{title:y?"Copied!":"Copy referral link",children:(0,ee.jsx)(pe.A,{onClick:se,children:(0,ee.jsx)(dr.A,{})})})},sx:{mb:{xs:1,sm:0}}}),(0,ee.jsx)(te.A,{variant:"contained",startIcon:(0,ee.jsx)(lr.A,{}),onClick:se,sx:{width:{xs:"100%",sm:"auto"},py:1},children:"Share"})]})]})})}),1===a&&(0,ee.jsx)(g.A,{sx:{p:{xs:1,sm:2},bgcolor:{xs:"background.paper",sm:"transparent"},borderRadius:{xs:2,sm:2},boxShadow:{xs:1,sm:0},mb:{xs:2,sm:0},maxWidth:{xs:420,sm:"none"},mx:{xs:"auto",sm:0}},children:(()=>{const e=[...I].sort(((e,s)=>(s.isPrimary?1:0)-(e.isPrimary?1:0)));return(0,ee.jsx)(fe.A,{sx:{height:"100%"},children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.A,{variant:"h6",children:"My Addresses"}),(0,ee.jsx)(te.A,{variant:"contained",startIcon:(0,ee.jsx)(we.A,{}),onClick:()=>L(!0),children:"Add Address"})]}),P?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",p:4},children:(0,ee.jsx)(j.A,{})}):e.length>0?(0,ee.jsx)(ye.Ay,{container:!0,spacing:2,children:e.map((e=>(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:6,children:(0,ee.jsxs)(de.A,{elevation:2,sx:{p:2,position:"relative",border:e.isPrimary?"2px solid":"1px solid",borderColor:e.isPrimary?"primary.main":"divider"},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",color:"primary",children:e.isPrimary?"Primary Address":"Secondary Address"}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(pe.A,{size:"small",onClick:()=>(e=>{T(e),R(e.address),W(e.isPrimary),L(!0)})(e),children:(0,ee.jsx)(en.A,{fontSize:"small"})}),(0,ee.jsx)(pe.A,{size:"small",onClick:()=>{return s=e.id,K(s),void H(!0);var s},children:(0,ee.jsx)(dn.A,{fontSize:"small"})})]})]}),(0,ee.jsx)(m.A,{variant:"body2",children:e.address})]})},e.id)))}):(0,ee.jsx)(ae.A,{severity:"info",sx:{mt:2},children:"You don't have any addresses yet. Add one to get started!"})]})})})()}),2===a&&(0,ee.jsx)(g.A,{sx:{p:{xs:1,sm:2},bgcolor:{xs:"background.paper",sm:"transparent"},borderRadius:{xs:2,sm:2},boxShadow:{xs:1,sm:0},mb:{xs:2,sm:0},maxWidth:{xs:420,sm:"none"},mx:{xs:"auto",sm:0}},children:(0,ee.jsx)(fe.A,{sx:{height:"100%"},children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Account Settings"}),(0,ee.jsxs)(es.A,{spacing:3,children:[(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Notification Preferences"}),(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(Vn.A,{defaultChecked:!0}),label:"Email notifications for orders"}),(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(Vn.A,{defaultChecked:!0}),label:"SMS notifications for delivery updates"})]}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Privacy Settings"}),(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(Vn.A,{defaultChecked:!0}),label:"Share order history with delivery partners"})]}),(0,ee.jsx)(g.A,{children:(0,ee.jsx)(te.A,{variant:"outlined",color:"error",startIcon:(0,ee.jsx)(Bt.A,{}),onClick:Q,sx:{mt:2},children:"Logout"})})]})]})})})]})})]}),(0,ee.jsxs)(qe.A,{open:D,onClose:()=>L(!1),fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:$?"Edit Address":"Add Address"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(es.A,{spacing:2,mt:1,children:[(0,ee.jsx)(St,{value:q,onChange:R,onValidAddress:B}),(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(Vn.A,{checked:z,onChange:e=>W(e.target.checked)}),label:"Set as Primary Address"})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{L(!1),R(""),B(!1)},children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:async()=>{if(Y?.id){U(!0);try{if(!N)return;if($)if(z){for(const e of I)e.id!==$.id&&e.isPrimary&&await E(e.id,e.address,!1);await E($.id,q,!0),M({open:!0,message:"Address updated as primary",severity:"success"})}else{$.isPrimary&&1===I.filter((e=>e.isPrimary)).length?(await E($.id,q,!0),M({open:!0,message:"At least one address must be primary",severity:"warning"})):(await E($.id,q,!1),M({open:!0,message:"Address updated as secondary",severity:"success"}))}else if(0===I.length)await k(q,Y.id,!0),M({open:!0,message:"Address added successfully",severity:"success"});else if(z){for(const e of I)e.isPrimary&&await E(e.id,e.address,!1);await k(q,Y.id,!0),M({open:!0,message:"Address added as primary",severity:"success"})}else await k(q,Y.id,!1),M({open:!0,message:"Address added as secondary",severity:"success"});await w(Y.id),L(!1),T(null),R(""),W(!1),B(!1)}catch(e){M({open:!0,message:"Failed to save address. Please try again.",severity:"error"})}finally{U(!1)}}else M({open:!0,message:"Could not save address: user information not available",severity:"error"})},variant:"contained",disabled:!q||O||!N,children:O?(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(j.A,{size:20,sx:{mr:1}})," Saving..."]}):"Save"})]})]}),(0,ee.jsxs)(qe.A,{open:V,onClose:()=>H(!1),children:[(0,ee.jsx)(Re.A,{children:"Delete Address"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.A,{children:"Are you sure you want to delete this address? This action cannot be undone."})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>H(!1),disabled:P,children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:async()=>{try{await F(G),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{H(!1),K(null)}},color:"error",variant:"contained",disabled:P,startIcon:P?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:P?"Deleting...":"Delete"})]})]}),(0,ee.jsx)(Xt.A,{open:_.open,autoHideDuration:3e3,onClose:()=>M({..._,open:!1}),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,ee.jsx)(ae.A,{onClose:()=>M({..._,open:!1}),severity:_.severity,sx:{width:"100%"},children:_.message})})]})},ur=()=>{const e=(0,l.Zp)();return(0,ee.jsx)(h.A,{maxWidth:"md",children:(0,ee.jsx)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,ee.jsxs)(de.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,ee.jsx)(m.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,ee.jsx)(m.A,{variant:"body1",color:"text.secondary",paragraph:!0,children:"The page you are looking for does not exist or is not available."}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(qs),children:"Go to Dashboard"})]})})})},mr=()=>{const e=(0,l.Zp)();return(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{maxWidth:"md",children:(0,ee.jsx)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,ee.jsxs)(de.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,ee.jsx)(m.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,ee.jsx)(m.A,{variant:"body1",color:"text.secondary",paragraph:!0,children:"The page you are looking for does not exist or is not available in the Store Manager section."}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(qs),children:"Go to Dashboard"})]})})})})},hr=e=>{let{open:s,onClose:t,selectedFee:n,onUpdate:r,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,d]=(0,x.useState)(a);(0,x.useEffect)((()=>{n?d({feeCurrency:n.feeCurrency||"",feeRate:n.feeRate?.toString()||"",limit:n.limit?.toString()||"",type:n.type?.toUpperCase()||"DELIVERY"}):s&&d(a)}),[n,s]),(0,x.useEffect)((()=>{s||d(a)}),[s]);const l=e=>{const{name:s,value:t}=e.target;d((e=>({...e,[s]:t})))};return(0,ee.jsxs)(qe.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:n?"Edit Fee":"Add New Fee"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ee.jsxs)(cs.A,{fullWidth:!0,children:[(0,ee.jsx)(Jt.A,{children:"Fee Type"}),(0,ee.jsxs)(Zt.A,{name:"type",value:o.type,onChange:l,label:"Fee Type",children:[(0,ee.jsx)(ge.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,ee.jsx)(ge.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,ee.jsx)(p.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:l,fullWidth:!0,placeholder:"e.g., USD"}),(0,ee.jsx)(p.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:l,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,ee.jsx)(p.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:l,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:t,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",onClick:()=>{r({id:n?.id,...o,feeRate:parseFloat(o.feeRate),limit:parseFloat(o.limit)}),n||d(a)},disabled:i,startIcon:i?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},pr=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=J(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(!1),[c,p]=(0,x.useState)(""),[A,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ms.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await k("\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 s?.getUserProfile&&n(s.getUserProfile),s},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,u.I)({queryKey:["storeWithFees",t?.id],queryFn:()=>k("\n query GetStoreWithFees($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:t.id}),enabled:!!t?.id}),C=v?.storesByManager?.[0],{data:w,isLoading:P,error:E,refetch:F}=(0,u.I)({queryKey:["getFeesByStore",C?.id],queryFn:()=>k("\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:C?.id}),enabled:!!C?.id}),D=w?.getFeesByStore||[],L=(0,ds.n)({mutationFn:e=>k("\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=>{p(`Error updating fee: ${e.message}`)}}),$=(0,ds.n)({mutationFn:e=>k("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{F(),l(!1),i(null),y("Fee deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error deleting fee: ${e.message}`)}}),T=(0,ds.n)({mutationFn:e=>k("\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:C?.id}}),onSuccess:()=>{F(),o(!1),i(null),y("Fee added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error adding fee: ${e.message}`)}});return b||I||P?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})})}):S||E?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4},children:(0,ee.jsxs)(ae.A,{severity:"error",children:["Error loading data: ",S?.message||E?.message]})})}):(0,ee.jsx)(Xn,{children:(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Delivery Fees Management"}),A&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:A}),c&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:c}),(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.A,{variant:"h5",children:"Fees"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:T.isPending||T.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):(0,ee.jsx)(we.A,{}),onClick:()=>{i(null),o(!0)},disabled:T.isPending||T.isLoading,children:T.isPending||T.isLoading?"Adding...":"Add Fee"})]}),(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Type"}),(0,ee.jsx)(Yt.A,{children:"Currency"}),(0,ee.jsx)(Yt.A,{children:"Rate"}),(0,ee.jsx)(Yt.A,{children:"Limit"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:D.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.type}),(0,ee.jsx)(Yt.A,{children:e.feeCurrency}),(0,ee.jsx)(Yt.A,{children:e.feeRate}),(0,ee.jsx)(Yt.A,{children:e.limit}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,ee.jsx)(en.A,{})}),(0,ee.jsx)(pe.A,{onClick:()=>(e=>{i(e),l(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,ee.jsx)(dn.A,{})})]})]},e.id)))})]})})]}),(0,ee.jsx)(hr,{open:a,onClose:()=>{o(!1),i(null),p("")},selectedFee:r,onUpdate:e=>{r?L.mutate(e):T.mutate(e)},isLoading:L.isPending||L.isLoading||T.isPending||T.isLoading}),(0,ee.jsxs)(qe.A,{open:d,onClose:()=>{l(!1),i(null),p("")},children:[(0,ee.jsx)(Re.A,{children:"Delete Fee"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{l(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})})};var Ar=t(95952);const gr=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=J(),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(!1),[c,p]=(0,x.useState)(null),[A,y]=(0,x.useState)("info");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ms.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{if(!e)return null;const s=await k(D,{userId:e});return s?.getUserProfile&&n(s.getUserProfile),s},enabled:!!e}),{data:v,isLoading:I,error:S,refetch:C}=(0,u.I)({queryKey:["storeInfo",t?.id],queryFn:()=>k("\n query GetStoreInfo($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n address\n radius\n codEnabled\n }\n }\n",{managerId:t.id}),enabled:!!t?.id}),w=v?.storesByManager?.[0],{data:P,isLoading:E,error:F,refetch:L}=(0,u.I)({queryKey:["storeSquareStatus",w?.id],queryFn:()=>k("\n query StoreSquareStatus($storeId: Int!) {\n storeSquareStatus(storeId: $storeId) {\n storeId\n storeName\n isConnected\n merchantId\n }\n }\n",{storeId:w?.id}),enabled:!!w?.id}),$=P?.storeSquareStatus,T=(0,ds.n)({mutationFn:e=>k("\n mutation ConnectSquare($storeId: Int!) {\n connectSquare(storeId: $storeId) {\n authorizationUrl\n message\n }\n }\n",{storeId:e}),onSuccess:e=>{const s=e.connectSquare?.authorizationUrl;s?window.location.href=s:(y("error"),p(e.connectSquare?.message||"Failed to generate authorization URL"))},onError:e=>{y("error"),p(e.message||"Failed to initiate Square connection")}}),q=(0,ds.n)({mutationFn:e=>k("\n mutation DisconnectSquare($storeId: Int!) {\n disconnectSquare(storeId: $storeId) {\n success\n message\n }\n }\n",{storeId:e}),onSuccess:e=>{i(!1),e.disconnectSquare?.success?(y("success"),p("Square account disconnected successfully"),L()):(y("error"),p(e.disconnectSquare?.message||"Failed to disconnect Square"))},onError:e=>{i(!1),y("error"),p(e.message||"Failed to disconnect Square account")}}),R=(0,ds.n)({mutationFn:e=>k("\n mutation ToggleCod($storeId: Int!, $enabled: Boolean!) {\n toggleCod(storeId: $storeId, enabled: $enabled) {\n id\n codEnabled\n }\n }\n",e),onSuccess:e=>{e.toggleCod?(y("success"),p(e.toggleCod.codEnabled?"Cash on Delivery enabled successfully":"Cash on Delivery disabled successfully"),L(),C()):(y("error"),p("Failed to update COD settings"))},onError:e=>{y("error"),p(e.message||"Failed to update COD settings")}});(0,x.useEffect)((()=>{const e=new URLSearchParams(window.location.search),s=e.get("oauth_success"),t=e.get("oauth_error");"true"===s?(y("success"),p("Square account connected successfully"),L(),window.history.replaceState({},"","/store_manager/payment-settings")):t&&(y("error"),p(`OAuth error: ${decodeURIComponent(t)}`),window.history.replaceState({},"","/store_manager/payment-settings"))}),[L]),(0,x.useEffect)((()=>{if(c&&"success"===A){const e=setTimeout((()=>{p(null)}),5e3);return()=>clearTimeout(e)}}),[c,A]);const z=()=>{i(!1)},W=()=>{o(!1)};return b||I||E?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})})}):S||F?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4},children:(0,ee.jsxs)(ae.A,{severity:"error",children:["Error loading data: ",S?.message||F?.message]})})}):w?(0,ee.jsx)(Xn,{children:(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Payment Settings"}),(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ee.jsx)(ts.A,{sx:{mr:1,fontSize:32}}),(0,ee.jsx)(m.A,{variant:"h5",children:"Square Payment Connection"})]}),c&&(0,ee.jsx)(ae.A,{severity:A,sx:{mb:3},onClose:()=>p(null),children:c}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Connect your store to Square to enable online card payments for your customers."}),(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1},children:[(0,ee.jsx)("strong",{children:"Store:"})," ",w.name]}),(0,ee.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2},children:[(0,ee.jsx)("strong",{children:"Connection Status:"})," ",$?.isConnected?(0,ee.jsx)(Fe.A,{label:"Connected",color:"success",size:"small",icon:(0,ee.jsx)(Cn.A,{})}):(0,ee.jsx)(Fe.A,{label:"Not Connected",color:"default",size:"small",icon:(0,ee.jsx)(wn.A,{})})]}),$?.isConnected&&$?.merchantId&&(0,ee.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2},children:[(0,ee.jsx)("strong",{children:"Merchant ID:"})," ",$.merchantId]})]}),(0,ee.jsx)(g.A,{children:$?.isConnected?(0,ee.jsx)(te.A,{variant:"outlined",color:"error",onClick:()=>{i(!0)},disabled:q.isPending,startIcon:q.isPending&&(0,ee.jsx)(j.A,{size:16}),children:q.isPending?"Disconnecting...":"Disconnect Square"}):(0,ee.jsx)(te.A,{variant:"contained",color:"primary",onClick:()=>{w?.id&&T.mutate(w.id)},disabled:T.isPending,startIcon:T.isPending&&(0,ee.jsx)(j.A,{size:16}),children:T.isPending?"Connecting...":"Connect Square Account"})})]}),(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mt:3},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ee.jsx)(Ar.A,{sx:{mr:1,fontSize:32}}),(0,ee.jsx)(m.A,{variant:"h5",children:"Cash on Delivery"})]}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Accept cash payments when orders are delivered"}),(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(nn.A,{checked:w?.codEnabled||!1,onChange:e=>{l(e.target.checked),o(!0)},disabled:R.isPending,color:"primary"}),label:w?.codEnabled?"Enabled":"Disabled"})]}),(0,ee.jsxs)(qe.A,{open:r,onClose:z,children:[(0,ee.jsx)(Re.A,{children:"Disconnect Square?"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(Sn.A,{children:["Are you sure you want to disconnect Square for ",(0,ee.jsx)("strong",{children:w.name}),"?",(0,ee.jsx)("br",{}),(0,ee.jsx)("br",{}),"Customers will not be able to make card payments until you reconnect."]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:z,disabled:q.isPending,children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{w?.id&&q.mutate(w.id)},color:"error",variant:"contained",disabled:q.isPending,startIcon:q.isPending&&(0,ee.jsx)(j.A,{size:16}),children:q.isPending?"Disconnecting...":"Disconnect"})]})]}),(0,ee.jsxs)(qe.A,{open:a,onClose:W,children:[(0,ee.jsxs)(Re.A,{children:[d?"Enable":"Disable"," Cash on Delivery?"]}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(Sn.A,{children:d?`Customers will be able to pay with cash when their orders from ${w?.name} are delivered.`:`Customers will no longer see Cash on Delivery as a payment option for ${w?.name}. Orders already in progress will not be affected.`})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:W,disabled:R.isPending,children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:()=>{w?.id&&R.mutate({storeId:w.id,enabled:d}),o(!1)},variant:"contained",color:d?"primary":"error",disabled:R.isPending,startIcon:R.isPending&&(0,ee.jsx)(j.A,{size:16}),children:R.isPending?"Saving...":"Confirm"})]})]})]})}):(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4},children:(0,ee.jsx)(ae.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})},jr=()=>{const e=(0,l.Zp)(),{user:s,setUser:t}=J(),[n,i]=(0,x.useState)(!0),a=(0,Ee.A)();return(0,x.useEffect)((()=>{(async()=>{try{const s=await(0,v.$)();if(s?.tokens?.idToken){const n=s.tokens.idToken.payload.sub,r=s.tokens.idToken.payload["custom:role"]?.toLowerCase();t({id:n,role:r}),e(`/${r}`)}}catch(e){}finally{i(!1)}})()}),[t,e]),n?(0,ee.jsx)(ce,{}):(0,ee.jsx)(g.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,ee.jsxs)(de.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,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,ee.jsx)(m.A,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:"Welcome Back"}),(0,ee.jsx)(m.A,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"Sign in to continue your journey with us"})]}),(0,ee.jsx)(Ys,{}),(0,ee.jsxs)(g.A,{sx:{mt:4,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:[(0,ee.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,ee.jsxs)(m.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:["Don't have an account?"," ",(0,ee.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"})]})]})]})})};const yr=(0,t(11848).Ay)(p.A)((e=>{let{theme:s}=e;return{"& .MuiInputBase-root":{minHeight:"120px"}}})),fr=e=>{let{sectionHeaders:s,answers:t={},onChangeAnswers:n,onSubmit:r}=e;const[i,a]=(0,x.useState)(!1),[o,d]=(0,x.useState)(!1),l=()=>Object.values(t).some((e=>e&&""!==e.trim()));return(0,ee.jsxs)(g.A,{sx:{width:"100%"},children:[(0,ee.jsx)(ye.Ay,{container:!0,spacing:3,children:s.map(((e,s)=>(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(de.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,ee.jsx)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,color:"primary.main",letterSpacing:.2},children:e}),(0,ee.jsx)(yr,{fullWidth:!0,multiline:!0,minRows:5,placeholder:`Enter items for ${e.toLowerCase()}`,variant:"outlined",value:t[s]||"",onChange:e=>((e,s)=>{const r={...t,[e]:s};n(r)})(s,e.target.value),sx:{"& .MuiOutlinedInput-root":{backgroundColor:"background.paper"}}})]})},s)))}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"flex-end",mt:4},children:(0,ee.jsx)(te.A,{variant:"contained",color:"primary",size:"large",disabled:!l(),sx:{px:5,py:1.5,fontWeight:600,borderRadius:2,boxShadow:1,opacity:l()?1:.6},onClick:()=>{if(!l())return;const e=(()=>{if(!s||0===s.length)return"";const e=[];return s.forEach(((s,n)=>{const r=t[n]?t[n].trim():"";r&&(e.push(s),r.split("\n").forEach((s=>{const t=s.trim();t&&e.push(` • ${t}`)})),e.push(""))})),e.join("\n").trim()})();r(e),d(Object.values(t).some((e=>""!==e.trim()))),a(!0),(()=>{const e={};s.forEach(((s,t)=>{e[t]=""})),n(e)})(),setTimeout((()=>{a(!1)}),3e3)},children:"Submit List"})}),(0,ee.jsxs)(qe.A,{open:i,onClose:()=>a(!1),PaperProps:{sx:{borderRadius:2,minWidth:"300px"}},children:[(0,ee.jsxs)(Re.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(jn.A,{color:"success",sx:{fontSize:28}}),(0,ee.jsx)(m.A,{variant:"h6",sx:{fontWeight:600},children:o?"Items Edited":"Items Added"})]}),(0,ee.jsx)(pe.A,{onClick:()=>a(!1),size:"small",sx:{color:"text.secondary"},children:(0,ee.jsx)(ns.A,{})})]}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.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,ee.jsx)(We.A,{sx:{px:3,pb:2},children:(0,ee.jsx)(te.A,{variant:"contained",onClick:()=>a(!1),sx:{borderRadius:2,textTransform:"none",px:3},children:"Okay"})})]})]})};function br(e){if(!e)return!0;const s=e.cart&&Object.keys(e.cart).length>0,t=!!e.customOrder,n=e.listInputAnswers&&Object.keys(e.listInputAnswers).length>0;return!s&&!t&&!n}const vr=()=>{const[e,s]=(0,x.useState)(!1),[t,n]=(0,x.useState)(!1),[r,i]=(0,x.useState)(!1),{selectedStore:a,setAvailableStores:o,setSelectedStore:d,pickupAddress:l,deliveryType:c,deliveryAddressString:m,setCustomOrder:h,listInputAnswers:p,setListInputAnswers:A}=X();!function(){const e=J((e=>e.userProfile)),s=X((e=>e.selectedStore)),t=X((e=>e.restoreCart)),n=X((e=>e.getCartState)),r=(0,x.useRef)(!1),i=(0,x.useRef)(null),a=(0,x.useRef)(null),o=(0,x.useRef)(null),d=(0,x.useRef)(!1),l=e?.id,c=s?.id;(0,x.useEffect)((()=>{if(!l||!c)return void(r.current=!1);const e=i.current!==l,s=a.current!==c;if(i.current=l,a.current=c,!e&&!s&&r.current)return;let o=!1;return async function(){try{const e=await k("\n query GetSavedCart($userId: Int!, $storeId: Int!) {\n getSavedCart(userId: $userId, storeId: $storeId) {\n id\n userId\n storeId\n cartData\n updatedAt\n }\n }\n",{userId:l,storeId:c});if(o)return;const s=e?.getSavedCart,r=n(),i=br(r);if(i&&s?.cartData){t(s.cartData);try{localStorage.setItem(`indimitra-cart-store-${c}`,JSON.stringify(s.cartData))}catch(e){}}else i||await k(W,{userId:l,storeId:c,cartData:r})}catch(e){}finally{o||(r.current=!0)}}(),()=>{o=!0}}),[l,c]),(0,x.useEffect)((()=>{if(!l||!c)return;const e=X.subscribe(((e,s)=>{r.current&&(e.cart!==s.cart||e.customOrder!==s.customOrder||e.listInputAnswers!==s.listInputAnswers||e.deliveryType!==s.deliveryType||e.tipAmount!==s.tipAmount||e.pickupAddress!==s.pickupAddress)&&(o.current&&clearTimeout(o.current),o.current=setTimeout((async()=>{if(!d.current){d.current=!0;try{const e=X.getState().getCartState(),s=i.current,t=a.current;if(!s||!t)return;try{localStorage.setItem(`indimitra-cart-store-${t}`,JSON.stringify(e))}catch(e){}br(e)?await k(O,{userId:s,storeId:t}):await k(W,{userId:s,storeId:t,cartData:e})}catch(e){}finally{d.current=!1}}}),1e3))}));return()=>{e(),o.current&&clearTimeout(o.current)}}),[l,c])}();const{data:g,isLoading:j,error:y}=(0,u.I)({queryKey:["stores"],queryFn:async()=>await k(q)});(0,x.useEffect)((()=>{if(g?.stores&&g.stores.length>0){o(g.stores);const e=localStorage.getItem("selectedStoreId");if(e){const t=g.stores.find((s=>String(s.id)===e));a&&a.id===t?.id||(t?d(t):(localStorage.removeItem("selectedStoreId"),s(!0)))}else a||s(!0)}}),[g,a,o]);if(j)return(0,ee.jsx)(se,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:(0,ee.jsx)(ce,{})});const f=a?.sectionHeaders?.length>0;return(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(wt,{open:e,onClose:()=>s(!1)}),a&&(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(he,{children:(0,ee.jsxs)(se,{sx:{alignItems:"center",mb:{xs:2,sm:3},mt:{xs:1,sm:2},p:{xs:1,sm:2},backgroundColor:"rgba(0, 0, 0, 0.03)",borderRadius:2},children:[(0,ee.jsxs)(se,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},width:"100%",gap:{xs:1.5,sm:0}},children:[(0,ee.jsxs)(se,{sx:{mb:{xs:1,sm:0}},children:[(0,ee.jsx)(ie,{variant:"h6",sx:{fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:a.name}),(0,ee.jsx)(ie,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:a.address})]}),(l||m)&&(0,ee.jsxs)(ne,{variant:"outlined",color:"primary",sx:{display:"flex",flexDirection:"column",alignItems:{xs:"flex-start",sm:"flex-end"},minWidth:{xs:0,sm:180},borderRadius:2,fontWeight:600,textTransform:"none",fontSize:{xs:"0.95rem",sm:"1rem"},mt:{xs:1,sm:0},px:{xs:1.5,sm:2},py:{xs:.5,sm:1}},onClick:()=>n(!0),children:[(0,ee.jsx)(ie,{variant:"subtitle2",color:"primary",sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:"delivery"===c?"Change Delivery Address":"Change Pickup Location"}),(0,ee.jsx)(ie,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.85rem",sm:"0.95rem"}},children:"delivery"===c?m||"No address selected":l?.address||"No pickup location selected"})]})]}),(0,ee.jsxs)(se,{sx:{mt:1,display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",gap:{xs:.5,sm:2}},children:[(0,ee.jsx)(ie,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:a.description}),(0,ee.jsx)(ie,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:a.tnc})]})]})}),(0,ee.jsx)(wt,{open:t,onClose:()=>n(!1),forceStep:"pickup",initialStore:a}),(0,ee.jsx)(he,{children:(0,ee.jsx)(Xe,{images:a?.images})}),(0,ee.jsxs)(he,{children:[f&&(0,ee.jsx)(de.A,{elevation:0,sx:{p:{xs:1.5,sm:2},mb:{xs:2,sm:3},backgroundColor:"rgba(0, 0, 0, 0.03)",borderRadius:2,minHeight:{xs:56,sm:72}},children:(0,ee.jsxs)(se,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},gap:{xs:1,sm:0}},children:[(0,ee.jsx)(ie,{variant:"h6",sx:{fontWeight:600,fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:r?"Browse Products":"Quick List Entry"}),(0,ee.jsx)(se,{sx:{minWidth:{xs:0,sm:200},display:"flex",alignItems:"center",justifyContent:{xs:"flex-start",sm:"flex-end"},width:{xs:"100%",sm:"auto"}},children:(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(nn.A,{checked:r,onChange:()=>{i(!r)},color:"primary"}),label:(0,ee.jsx)(ie,{variant:"body2",color:"text.secondary",sx:{width:140,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:{xs:"0.95rem",sm:"1rem"}},children:r?"Manual Browse":"Quick List"}),labelPlacement:"end",sx:{marginLeft:{xs:0,sm:2}}})})]})}),f&&!r?(0,ee.jsx)(fr,{sectionHeaders:a.sectionHeaders,answers:p,onChangeAnswers:A,onSubmit:h}):(0,ee.jsx)(ys,{})]})]})]})};var Ir=t(37483),Sr=t(28211);const Cr=e=>{let{open:s,onClose:t,orderCode:n,onNavigate:r,onViewOrder:i}=e;const[a,o]=(0,x.useState)(3);(0,x.useEffect)((()=>{s&&o(3)}),[s]);const d=()=>{t(),r&&r()};return(0,x.useEffect)((()=>{if(s&&a>0){const e=setTimeout((()=>{o(a-1)}),1e3);return()=>clearTimeout(e)}s&&0===a&&d()}),[s,a,t,r]),(0,ee.jsx)(qe.A,{open:s,onClose:d,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:3,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.12)"}},children:(0,ee.jsx)(ze.A,{sx:{p:4},children:(0,ee.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",py:2,gap:2},children:[(0,ee.jsx)(jn.A,{sx:{fontSize:80,color:"success.main"}}),(0,ee.jsx)(m.A,{variant:"h5",fontWeight:"bold",color:"success.main",textAlign:"center",children:"Order Placed Successfully!"}),n&&(0,ee.jsxs)(m.A,{variant:"body1",color:"text.secondary",children:["Order #",n]}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",textAlign:"center",sx:{mt:1},children:"Thank you for your purchase. Your order is being processed and you'll receive an update soon!"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mt:1},children:a>0?`Redirecting in ${a} seconds...`:"Redirecting..."}),(0,ee.jsxs)(es.A,{direction:"row",spacing:2,sx:{mt:3,width:"100%",justifyContent:"center"},children:[(0,ee.jsx)(te.A,{variant:"outlined",color:"primary",onClick:()=>{t(),i&&i()},sx:{px:4,py:1.2,borderRadius:2,fontWeight:600,textTransform:"none",flex:1,maxWidth:200},children:"View Order"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",onClick:d,sx:{px:4,py:1.2,borderRadius:2,fontWeight:600,textTransform:"none",flex:1,maxWidth:200},children:"OK"})]})]})})})};var wr=t(51694),Pr=t(85916),kr=t(11692),Er=t(2183);const Fr=e=>{let{size:s=24,sx:t}=e;return(0,ee.jsx)(j.A,{size:s,sx:{color:"inherit",...t}})},Dr=e=>{let{userProfile:s,onPhoneUpdate:t}=e;const[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(""),[o,d]=(0,x.useState)(""),{mutate:l,isPending:c}=(0,ds.n)({mutationFn:e=>k("\n mutation UpdateSecondaryPhone($userId: Int!, $secondaryPhone: String) {\n updateSecondaryPhone(userId: $userId, secondaryPhone: $secondaryPhone) {\n active\n }\n }\n",e),onSuccess:()=>{t(),r(!1),a(""),d("")},onError:e=>{d("Failed to update phone number. Please try again.")}});return s?(0,ee.jsx)(g.A,{sx:{mb:3},children:n?(0,ee.jsxs)(de.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(cn.A,{color:"primary"}),(0,ee.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:s.secondaryPhone?"Update Number":"Add Number"})]}),(0,ee.jsx)(p.A,{size:"small",value:i,onChange:e=>{const s=e.target.value.replace(/\D/g,"").slice(0,10);a(s),d("")},placeholder:"Enter 10-digit number",error:!!o,helperText:o,InputProps:{startAdornment:(0,ee.jsx)(m.A,{sx:{mr:1},children:"+1"})}}),(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:1},children:[(0,ee.jsx)(te.A,{variant:"contained",size:"small",onClick:()=>{10===i.length?l({userId:s.id,secondaryPhone:i}):d("Please enter a valid 10-digit phone number")},disabled:c||10!==i.length,startIcon:c?(0,ee.jsx)(Fr,{size:20}):(0,ee.jsx)(cn.A,{}),children:c?"Saving...":"Save"}),(0,ee.jsx)(te.A,{variant:"outlined",size:"small",onClick:()=>{r(!1),a(""),d("")},children:"Cancel"})]})]}):(0,ee.jsxs)(de.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(cn.A,{color:"primary"}),(0,ee.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Secondary Contact"}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"(Update if you want to change)"})]}),s.secondaryPhone?(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsxs)(m.A,{variant:"body1",children:["+1 ",s.secondaryPhone]}),(0,ee.jsx)(te.A,{variant:"outlined",size:"small",onClick:()=>r(!0),startIcon:(0,ee.jsx)(cn.A,{}),sx:{alignSelf:"flex-start"},children:"Change Number"})]}):(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"No secondary number added"}),(0,ee.jsx)(te.A,{variant:"outlined",size:"small",onClick:()=>r(!0),startIcon:(0,ee.jsx)(cn.A,{}),sx:{alignSelf:"flex-start"},children:"Add Number"})]})]})}):null},Lr=()=>{const{cart:e,removeFromCart:s,addToCart:t,cartTotal:n,clearCart:i,selectedStore:o,getCartTotals:d,setTipAmount:c,customOrder:h,setCustomOrder:y,pickupAddress:f,setPickupAddress:b,deliveryType:I,setDeliveryType:S,tipAmount:C,setListInputAnswers:w}=X(),[P,E]=(0,x.useState)(""),[F,D]=(0,x.useState)(!1),[L,$]=(0,x.useState)(null),[T,q]=(0,x.useState)(""),{user:R,userProfile:z,fetchUserProfile:W,isProfileLoading:U,setModalOpen:N,setCurrentForm:B}=J(),_=(0,l.Zp)(),M=(0,a.jE)(),[V,H]=(0,x.useState)(0),[G,K]=(0,x.useState)(""),[Y,Q]=(0,x.useState)(f?String(f.id):null),[se,ne]=(0,x.useState)(!1),[re,ie]=(0,x.useState)(!1),[ae,oe]=(0,x.useState)(null),[le,ce]=(0,x.useState)(!(!f&&"delivery"!==I)),xe=(0,x.useCallback)((async()=>{if(i(),y(""),w({}),o?.id)try{localStorage.removeItem(`indimitra-cart-store-${o.id}`)}catch(e){}if(z?.id&&o?.id)try{await k(O,{userId:z.id,storeId:o.id}),await new Promise((e=>setTimeout(e,100)))}catch(e){}}),[i,y,w,o,z]);(0,x.useEffect)((()=>{(async()=>{const e=await(0,v.$)(),s=e?.tokens?.idToken?.payload?.sub;s&&await W(s)})()}),[W,R]);const{addresses:ue,selectedAddressId:me,setSelectedAddressId:he,fetchAddresses:Ae,isLoading:je,createAddress:be}=Z(),{data:Ie,isLoading:Se}=(0,u.I)({queryKey:["storePaymentConfig",o?.id],queryFn:async()=>k("\n query StorePaymentConfig($storeId: Int!) {\n storePaymentConfig(storeId: $storeId) {\n storeId\n isSquareConnected\n codEnabled\n squareApplicationId\n squareLocationId\n }\n }\n",{storeId:o.id}),enabled:!!o?.id}),Pe=Ie?.storePaymentConfig||null,[ke,Ee]=(0,x.useState)(!1),[Fe,De]=(0,x.useState)(""),[Le,$e]=(0,x.useState)(!1),[Te,qe]=(0,x.useState)(!1),[Re,ze]=(0,x.useState)(!1),[We,Oe]=(Object.values(e).reduce(((e,s)=>e+(s.quantity||0)),0),(0,x.useState)({subtotal:0,deliveryFee:0,taxAmount:0,taxPercentage:0,tipAmount:0,total:0}));(0,x.useEffect)((()=>{z?.id&&Ae(z.id)}),[z?.id,Ae]),(0,x.useEffect)((()=>{f&&(Q(String(f.id)),S("pickup"),he(null),ce(!0))}),[f,S,he]),(0,x.useEffect)((()=>{const e=d();Oe(e)}),[I,e,d,C]);const{subtotal:Ue,deliveryFee:Ne,taxAmount:Be,taxPercentage:_e,tipAmount:Me,total:Ve}=We;(0,x.useEffect)((()=>{if(!le){if(o?.pickupAddresses?.edges?.length>0&&!Y&&!me){const e=o.pickupAddresses.edges[0].node;return Q(String(e.id)),S("pickup"),void he(null)}if(ue&&ue.length>0&&!Y&&!me){const e=ue.find((e=>e.isPrimary))||ue[0];return he(e.id),S("delivery"),void Q(null)}o?.pickupAddresses?.edges?.length&&0!==o?.pickupAddresses?.edges?.length||ue&&0!==ue.length||Y||me||S("delivery")}}),[o?.pickupAddresses?.edges,ue,le]);const{mutate:He,isPending:Ge}=(0,ds.n)({mutationKey:["createOrder"],mutationFn:async e=>{const s=X.getState().selectedStore;return k("\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:s.id})},onSuccess:async e=>{const s=e?.createOrder;if(s&&s.id)try{await xe(),$(s.displayCode||`#${s.id}`),D(!0),q(""),M.invalidateQueries(["userAddresses",z.id])}catch(e){$(s.displayCode||`#${s.id}`),D(!0)}else q("Order creation failed. Your cart has been preserved. Please try again.")},onError:e=>{q(e?.message||e?.response?.errors?.[0]?.message||e?.graphQLErrors?.[0]?.message||"Failed to place order. Please try again.")}}),{mutate:Ke,isPending:Qe}=(0,ds.n)({mutationFn:async e=>k("\n mutation CreateOrderWithCod(\n $userId: Int!\n $storeId: Int!\n $productItems: [OrderItemInput!]!\n $pickupOrDelivery: String!\n $addressId: Int\n $pickupId: Int\n $tipAmount: Float\n $deliveryInstructions: String\n $customOrder: String\n ) {\n createOrderWithCod(\n userId: $userId\n storeId: $storeId\n productItems: $productItems\n pickupOrDelivery: $pickupOrDelivery\n addressId: $addressId\n pickupId: $pickupId\n tipAmount: $tipAmount\n deliveryInstructions: $deliveryInstructions\n customOrder: $customOrder\n ) {\n id\n displayCode\n status\n orderTotalAmount\n }\n }\n",e),onSuccess:async e=>{const s=e?.createOrderWithCod;if(s&&s.id)try{await xe(),$(s.displayCode||`#${s.id}`),D(!0),q("")}catch(e){$(s.displayCode||`#${s.id}`),D(!0)}else q("Order creation failed. Your cart has been preserved. Please try again.")},onError:e=>{q(e?.message||e?.response?.errors?.[0]?.message||e?.graphQLErrors?.[0]?.message||"Failed to place order. Please try again.")}}),Je=(0,x.useCallback)((()=>{ie(!1)}),[]),Ze=(0,x.useCallback)((async e=>{if(e)if(e.id)try{await xe(),$(e.displayCode||`#${e.id}`),D(!0),q("")}catch(s){$(e.displayCode||`#${e.id}`),D(!0)}else{const s=e.error||"Order creation failed. Your cart has been preserved. Please try again.";q(s)}else q("Order creation failed. Your cart has been preserved. Please try again.")}),[xe]),Xe=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity})));return(0,ee.jsxs)(g.A,{sx:{padding:3},children:[(0,ee.jsxs)(m.A,{variant:"h4",component:"h1",gutterBottom:!0,sx:{fontWeight:600,color:"primary.main",mb:4,display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(Ps.A,{})," Your Shopping Cart"]}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:3,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:8,children:(0,ee.jsxs)(de.A,{elevation:2,sx:{p:3,mb:3},children:[T&&(0,ee.jsx)(Ye,{error:T,title:"Order Error",severity:"error"}),Object.values(e).length>0||h?(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(m.A,{variant:"h6",sx:{mb:2,fontWeight:500},children:"Cart Items"}),Object.values(e).map((e=>(0,ee.jsx)(fe.A,{sx:{mb:2,position:"relative"},children:(0,ee.jsx)(ve.A,{children:(0,ee.jsxs)(ye.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:4,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:2,flexDirection:{xs:"column",sm:"row"},justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,ee.jsx)("img",{src:e.image,alt:e.name,style:{width:"48px",height:"48px",objectFit:"cover",borderRadius:8,marginBottom:4}}),(0,ee.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500,textAlign:{xs:"center",sm:"left"},fontSize:{xs:"1rem",sm:"1.1rem"}},children:e.name})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,sm:3,children:(0,ee.jsxs)(m.A,{color:"text.secondary",sx:{fontSize:{xs:"0.98rem",sm:"1rem"},textAlign:{xs:"center",sm:"left"}},children:["$",e.price.toFixed(2)," each"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,sm:3,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1,justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,ee.jsx)(pe.A,{size:"small",onClick:()=>s(e.id),sx:{border:"1px solid",borderColor:"divider",width:32,height:32},children:(0,ee.jsx)(Ce.A,{fontSize:"small"})}),(0,ee.jsx)(m.A,{sx:{minWidth:32,textAlign:"center",fontSize:{xs:"1rem",sm:"1.1rem"}},children:e.quantity}),(0,ee.jsx)(pe.A,{size:"small",onClick:()=>t(e),sx:{border:"1px solid",borderColor:"divider",width:32,height:32},children:(0,ee.jsx)(we.A,{fontSize:"small"})})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:2,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",sx:{fontWeight:600,textAlign:{xs:"center",sm:"right"},fontSize:{xs:"1rem",sm:"1.1rem"},mt:{xs:1,sm:0}},children:["$",(e.price*e.quantity).toFixed(2)]})})]})})},e.id))),h&&(0,ee.jsx)(fe.A,{sx:{mb:2,position:"relative",bgcolor:"primary.lighter"},children:(0,ee.jsxs)(ve.A,{children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:2,mb:2},children:[(0,ee.jsx)(Ps.A,{color:"primary"}),(0,ee.jsx)(m.A,{variant:"h6",sx:{fontWeight:600,color:"primary.main"},children:"Custom Shopping List"})]}),(0,ee.jsx)(g.A,{sx:{p:2,bgcolor:"background.paper",borderRadius:1,border:"1px solid",borderColor:"divider"},children:(0,ee.jsx)(m.A,{variant:"body1",sx:{whiteSpace:"pre-line",fontFamily:"monospace",lineHeight:1.6},children:h})}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"flex-end",mt:2},children:(0,ee.jsx)(te.A,{variant:"outlined",color:"error",size:"small",onClick:()=>y(""),startIcon:(0,ee.jsx)(Ce.A,{}),children:"Remove List"})})]})})]}):(0,ee.jsxs)(g.A,{sx:{textAlign:"center",py:4},children:[(0,ee.jsx)(Ps.A,{sx:{fontSize:60,color:"text.secondary",mb:2}}),(0,ee.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"Your cart is empty"}),(0,ee.jsx)(te.A,{variant:"contained",component:r.N_,to:"/",startIcon:(0,ee.jsx)(Ps.A,{}),children:"Continue Shopping"})]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(de.A,{elevation:2,sx:{p:3,position:"sticky",top:24},children:[(0,ee.jsx)(m.A,{variant:"h6",sx:{mb:3,fontWeight:500},children:"Order Summary"}),z&&(0,ee.jsx)(g.A,{sx:{mb:3},children:(0,ee.jsx)(Dr,{userProfile:z,onPhoneUpdate:()=>{(async()=>{const e=await(0,v.$)(),s=e?.tokens?.idToken?.payload?.sub;s&&await W(s)})()}})}),(0,ee.jsx)(g.A,{sx:{mt:3},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ee.jsx)(m.A,{children:"Subtotal"}),(0,ee.jsxs)(m.A,{children:["$",Ue.toFixed(2)]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ee.jsx)(m.A,{children:"Delivery Fee"}),(0,ee.jsxs)(m.A,{children:["$",Ne.toFixed(2)]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Tax Rate"}),(0,ee.jsxs)(m.A,{children:[_e.toFixed(1),"%"]})]}),(0,ee.jsxs)(g.A,{sx:{textAlign:"right"},children:[(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Tax Amount"}),(0,ee.jsxs)(m.A,{children:["$",Be.toFixed(2)]})]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{mb:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Add Tip"}),(0,ee.jsxs)(Ir.A,{value:V,exclusive:!0,onChange:(e,s)=>{if(null!==s){H(s),K("");c(Ue*s/100)}},"aria-label":"tip percentage",size:"small",fullWidth:!0,sx:{mb:1},children:[(0,ee.jsx)(Sr.A,{value:0,"aria-label":"no tip",children:"No Tip"}),(0,ee.jsx)(Sr.A,{value:10,"aria-label":"10%",children:"10%"}),(0,ee.jsx)(Sr.A,{value:15,"aria-label":"15%",children:"15%"}),(0,ee.jsx)(Sr.A,{value:20,"aria-label":"20%",children:"20%"})]}),(0,ee.jsx)(p.A,{fullWidth:!0,size:"small",label:"Custom Tip Amount",type:"number",value:G,onChange:e=>{const s=e.target.value;K(s),H(0);const t=parseFloat(s)||0;c(t)},InputProps:{startAdornment:(0,ee.jsx)(m.A,{sx:{mr:1},children:"$"})},placeholder:"Enter custom amount",sx:{mt:1}})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,ee.jsx)(m.A,{children:"Tip Amount"}),(0,ee.jsxs)(m.A,{children:["$",Me.toFixed(2)]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(ss.A,{})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ee.jsx)(m.A,{variant:"h6",children:"Total"}),(0,ee.jsxs)(m.A,{variant:"h6",children:["$",Ve.toFixed(2)]})]})})]})}),h&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(Ps.A,{})," Custom Order Details"]}),(0,ee.jsx)(de.A,{elevation:0,sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:2,backgroundColor:"background.paper"},children:(0,ee.jsx)(m.A,{variant:"body2",sx:{whiteSpace:"pre-line",color:"text.secondary",fontFamily:"monospace"},children:h})})]}),z&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(As.A,{})," Delivery/Pickup Options"]}),U?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,ee.jsx)(Fr,{size:24})}):(0,ee.jsxs)(es.A,{spacing:3,children:[o?.pickupAddresses?.edges?.length>0&&(0,ee.jsxs)(de.A,{elevation:"pickup"===I?4:1,sx:{p:2,bgcolor:"pickup"===I?"primary.lighter":"grey.50",opacity:"delivery"===I&&me?.5:1,border:"pickup"===I?"2px solid #1976d2":"1px solid #eee",transition:"all 0.2s"},children:[(0,ee.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(bt.A,{fontSize:"small",color:"primary"})," Pickup Address"]}),(0,ee.jsx)(us.A,{value:Y||"",onChange:e=>{const s=e.target.value;Q(s),S("pickup"),he(null),ce(!0);const t=o.pickupAddresses.edges.map((e=>e.node)),n=t.find((e=>String(e.id)===String(s)));n&&b(n)},children:o.pickupAddresses.edges.map((e=>{let{node:s}=e;return(0,ee.jsx)(ms.A,{value:String(s.id),control:(0,ee.jsx)(hs.A,{color:"primary"}),label:s.address},s.id)}))})]}),(0,ee.jsxs)(de.A,{elevation:"delivery"===I?4:1,sx:{p:2,bgcolor:"delivery"===I?"secondary.lighter":"grey.50",opacity:"pickup"===I&&Y?.5:1,border:"delivery"===I?"2px solid #9c27b0":"1px solid #eee",transition:"all 0.2s"},children:[(0,ee.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(wr.A,{fontSize:"small",color:"secondary"})," Home Delivery Address"]}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsxs)(cs.A,{fullWidth:!0,sx:{mb:2},children:[(0,ee.jsx)(Jt.A,{children:"Select Address"}),je?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,ee.jsx)(Fr,{size:24})}):(0,ee.jsx)(Zt.A,{value:me||"",onChange:e=>{he(e.target.value),S("delivery"),Q(null),ce(!0)},label:"Select Address",inputProps:{},InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(Er.A,{})})},children:ue&&ue.length>0?ue.map((e=>(0,ee.jsxs)(ge.A,{value:e.id,children:[e.address," ",e.isPrimary?"(Primary)":""]},e.id))):(0,ee.jsx)(ge.A,{disabled:!0,children:"No addresses available"})})]}),(0,ee.jsx)(te.A,{fullWidth:!0,variant:"outlined",startIcon:ke?(0,ee.jsx)(Pr.A,{}):(0,ee.jsx)(kr.A,{}),onClick:()=>Ee(!ke),sx:{mb:2},children:ke?"Cancel":"Add New Address"}),(0,ee.jsx)(sr.A,{in:ke,children:(0,ee.jsx)(g.A,{sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:1},children:(0,ee.jsxs)(es.A,{spacing:2,children:[(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(St,{value:Fe,onChange:e=>{De(e),(e=>{if(!e.trim()||!ue)return void ne(!1);const s=e.toLowerCase().trim(),t=ue.some((e=>e.address.toLowerCase().trim()===s));ne(t)})(e)},onValidAddress:ze}),se&&(0,ee.jsx)(m.A,{variant:"body2",color:"error",sx:{mt:.5,fontSize:"0.875rem"},children:"⚠️ This address already exists in your address book"})]}),(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(Vn.A,{checked:Le,onChange:e=>$e(e.target.checked)}),label:"Set as Primary Address"}),(0,ee.jsx)(te.A,{variant:"contained",onClick:async()=>{if(!Fe.trim())return void q("Please enter a valid address");const e=Fe.trim().toLowerCase(),s=ue?.some((s=>s.address.toLowerCase().trim()===e));if(s)q("This address already exists in your address book");else{qe(!0),q("");try{await be(Fe,z.id,Le),Ee(!1),De(""),$e(!1),M.invalidateQueries(["userAddresses",z.id])}catch(e){q("Failed to add address. Please try again.")}finally{qe(!1)}}},disabled:!Fe.trim()||Te||!Re||se,startIcon:Te?(0,ee.jsx)(Fr,{size:20}):(0,ee.jsx)(Ut.A,{}),children:Te?"Adding...":"Add Address"})]})})})]})]})]})]}),z&&(0,ee.jsxs)(g.A,{sx:{mb:3},children:[(0,ee.jsx)(m.A,{variant:"subtitle1",sx:{mb:2},children:"Delivery Instructions"}),(0,ee.jsx)(p.A,{fullWidth:!0,multiline:!0,rows:2,value:P,onChange:e=>E(e.target.value),placeholder:"Add any special instructions for delivery..."})]}),z&&(0,ee.jsx)(ee.Fragment,{children:Se?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mb:3},children:(0,ee.jsx)(j.A,{size:24})}):(0,ee.jsx)(gs,{paymentConfig:Pe,selectedMethod:ae,onMethodChange:oe})}),z?(0,ee.jsx)(te.A,{fullWidth:!0,variant:"contained",size:"large",onClick:"cod"===ae?()=>{if(q(""),!z||!z.id)return q("Please log in to place an order"),N(!0),void B("login");if(!o||!o.id)return void q("Please select a store");if(0===Object.values(e).length&&!h)return void q("Your cart is empty. Please add items before placing an order");if(!Y&&!me)return void q("Please select either a pickup location or delivery address");const s=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity})));Ke({userId:z.id,storeId:o.id,productItems:s,pickupOrDelivery:I,addressId:me,pickupId:Y?parseInt(Y,10):null,tipAmount:C||0,deliveryInstructions:"pickup"===I?null:P,customOrder:h||null})}:()=>{ie(!0)},disabled:U||Se||!ae||!me&&!Y||0===Object.values(e).length&&!h?.trim()||Qe,startIcon:"cod"===ae?(0,ee.jsx)(As.A,{}):(0,ee.jsx)(ts.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"cod"===ae?"Place Order":"Pay Now"}):(0,ee.jsx)(te.A,{fullWidth:!0,variant:"contained",size:"large",onClick:()=>{N(!0),B("login")},startIcon:(0,ee.jsx)(Ps.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"Login to Continue"})]})})]}),(0,ee.jsx)(ls,{open:re,onClose:Je,cartTotal:Ve,orderItems:Xe,deliveryType:I,selectedAddressId:me,selectedPickupId:Y?parseInt(Y,10):null,userProfile:z,selectedStore:o,tipAmount:C,deliveryInstructions:P,customOrder:h,onSuccess:Ze,paymentConfig:Pe}),(0,ee.jsx)(Cr,{open:F,onClose:()=>D(!1),orderCode:L,onNavigate:()=>_("/"),onViewOrder:()=>_("/orders")})]})};var $r=t(16099),Tr=t(98821),qr=t(1309);const Rr=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(e);var zr=t(25737),Wr=t(55463),Or=t(67046),Ur=t(4213);(0,zr.D)();const Nr="\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",Br=()=>{const{userProfile:e}=J(),[s,t]=(0,x.useState)(""),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),[o,d]=(0,x.useState)(!1),[l,c]=(0,x.useState)(null),[h,f]=(0,x.useState)(""),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[C,w]=(0,x.useState)("ALL"),[P,E]=(0,x.useState)("createdAt"),[q,R]=(0,x.useState)("desc"),[z,W]=(0,x.useState)(0),[O,U]=(0,x.useState)(10),[N,B]=(0,x.useState)(""),[_,M]=(0,x.useState)(""),[V,H]=(0,x.useState)(""),[G,K]=(0,x.useState)(""),[Y,Q]=(0,x.useState)({open:!1,message:"",severity:"info"}),[Z,X]=(0,x.useState)(!1),[se,ne]=(0,x.useState)(null),[re,ie]=(0,x.useState)(1),[oe,le]=(0,x.useState)(!1),[ce,xe]=(0,x.useState)(null),[ue,me]=(0,x.useState)(!0);(0,x.useEffect)((()=>{const e=setTimeout((()=>{me(!1)}),1e3);return()=>clearTimeout(e)}),[]),(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ms.T)();t(e.sub)}catch(e){}})()}),[]);const{data:he,isLoading:Ae}=(0,u.I)({queryKey:["getUserProfile",s],queryFn:async()=>await k(D,{userId:s}),enabled:!!s}),je=he?.getUserProfile?.stores?.edges?.[0]?.node?.id,be=he?.getUserProfile?.id,{data:Ie,isLoading:Ce,error:we,refetch:Pe}=(0,u.I)({queryKey:["storeDrivers",je],queryFn:async()=>await k($,{storeId:je}),enabled:!!je}),{data:ke,isLoading:Ee,error:De,refetch:Le}=(0,u.I)({queryKey:["storeOrders",je],queryFn:async()=>(await k(L,{storeId:je})).getOrdersByStore||[],enabled:!!je}),$e=(0,ds.n)({mutationFn:async e=>await k(F,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onSuccess:()=>{Le(),a(!1),c(null),f(""),M(""),H(""),K("")},onError:e=>{v(e.message)}}),Te=(0,ds.n)({mutationFn:async e=>{const{orderId:s,itemId:t,quantity:n,price:r}=e,i=ke.find((e=>e.id===s));if(!i)throw new Error("Order not found");const a=he?.getUserProfile?.stores?.edges?.[0]?.node?.taxPercentage||0,o=new Map;i.orderItems.edges.forEach((e=>{let{node:s}=e;const t=s.productId;(!o.has(t)||s.id>o.get(t).id)&&o.set(t,s)}));if(!Array.from(o.values()).some((e=>e.id===parseInt(t)?n>0:e.quantity>0)))return await k(Nr,{orderId:parseInt(s),orderItemUpdates:[{orderItemId:parseInt(t),quantityChange:n-se.quantity}],totalAmount:0,orderTotalAmount:0,taxAmount:0});let d=0;o.forEach((e=>{if(e.id===parseInt(t))d+=n*r;else{const s=e.product?.inventoryItems?.edges[0]?.node?.price||0;d+=e.quantity*s}}));const l=d*a/100,c=d+l+(i.deliveryFee||0)+(i.tipAmount||0),x=n-se.quantity;return await k(Nr,{orderId:parseInt(s),orderItemUpdates:[{orderItemId:parseInt(t),quantityChange:x}],totalAmount:d,orderTotalAmount:c,taxAmount:l})},onSuccess:()=>{Le(),X(!1),ne(null),ie(1)},onError:e=>{v(e.message)}}),Oe=(0,ds.n)({mutationFn:async e=>await k(T,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:e.cancelledByUserId}),onSuccess:()=>{Le(),d(!1),B(""),c(null),Q({open:!0,message:"Order cancelled successfully",severity:"success"})},onError:e=>{v(e.message),Q({open:!0,message:"Failed to cancel order. Please try again.",severity:"error"})}}),Ue=e=>{P===e?R("asc"===q?"desc":"asc"):(E(e),R("asc"))},Ne=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"!==C&&(e=e.filter((e=>e.status===C))),e.sort(((e,s)=>{let t=0;return t="totalAmount"===P?e[P]-s[P]:String(e[P]||"").localeCompare(String(s[P]||"")),"asc"===q?t:-t})),e}),[ke,I,C,P,q]),Be=x.useMemo((()=>{const e=z*O;return Ne.slice(e,e+O)}),[Ne,z,O]),_e=e=>{if(!e?.edges?.length)return null;const s=new Map;e.edges.forEach((e=>{let{node:t}=e;const n=t.productId;(!s.has(n)||t.id>s.get(n).id)&&s.set(n,t)}));return Array.from(s.values())},Me=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e),Ve=async(e,s)=>{try{if("pdf"===s){const s=(e=>{const s=new Wr.uE;let t=20;const n=20;return s.internal.pageSize.width,s.setFontSize(16),s.text("Orders Report",n,t),t+=14,s.setFontSize(10),I&&(s.text(`Search Term: ${I}`,n,t),t+=7),"ALL"!==C&&(s.text(`Status Filter: ${C}`,n,t),t+=7),t+=7,e.forEach(((e,r)=>{t>s.internal.pageSize.height-40&&(s.addPage(),t=20),s.setFontSize(12),s.text(`Order #${e.id}`,n,t),t+=7,s.text(`Order Code: ${e.displayCode||"N/A"}`,n,t),t+=10.5,s.setFontSize(10),["Type: "+("PICKUP"===e.type?"Pickup":"Delivery"),`Status: ${vn.find((s=>s.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=>{s.text(e,25,t),t+=7})),e.customOrder&&(t+=7,s.setFontSize(11),s.text("Custom Order Details:",25,t),t+=7,e.customOrder.split("\n\n").forEach((e=>{const[n,...r]=e.split("\n");n&&r.length>0&&(s.setFontSize(10),s.text(`Q: ${n}`,30,t),t+=7,r.forEach((e=>{s.text(`A: ${e}`,35,t),t+=7})),t+=3.5)}))),e.orderItems?.edges?.length>0&&(t+=7,s.setFontSize(11),s.text("Items:",25,t),t+=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}`;s.text(i,30,t),t+=7}))),t+=14})),s})(e);s.save(`orders_${(new Date).toISOString().replace(/[-:]/g,"").replace("T","_").replace("Z","")}.pdf`)}else{const s=(e=>new Or.yoT({sections:[{properties:{},children:[new Or.fzL({children:[new Or.NTc({text:"Orders Report",bold:!0,size:32})]}),new Or.fzL({children:[new Or.NTc({text:I?`Search Term: ${I}`:"",size:24})]}),new Or.fzL({children:[new Or.NTc({text:"ALL"!==C?`Status Filter: ${C}`:"",size:24})]}),...e.map((e=>[new Or.fzL({children:[new Or.NTc({text:`Order #${e.id}`,bold:!0,size:28})]}),new Or.fzL({children:[new Or.NTc({text:`Order Code: ${e.displayCode||"N/A"}`,size:24})]}),new Or.XIK({width:{size:100,type:Or.PsV.PERCENTAGE},rows:[new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL("Type")],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL("PICKUP"===e.type?"Pickup":"Delivery")],width:{size:80,type:Or.PsV.PERCENTAGE}})]}),new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL("Status")],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL(vn.find((s=>s.value===e.status))?.label||e.status)],width:{size:80,type:Or.PsV.PERCENTAGE}})]}),new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL("Total")],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL(`$${e.orderTotalAmount}`)],width:{size:80,type:Or.PsV.PERCENTAGE}})]}),new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL("Customer")],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL(e.creator?.email||"N/A")],width:{size:80,type:Or.PsV.PERCENTAGE}})]}),new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL("Phone")],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL(e.creator?.mobile||"N/A")],width:{size:80,type:Or.PsV.PERCENTAGE}})]}),new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL("Address")],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL("PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A")],width:{size:80,type:Or.PsV.PERCENTAGE}})]})]}),...e.customOrder?[new Or.fzL({children:[new Or.NTc({text:"Custom Order Details",bold:!0,size:24})]}),new Or.XIK({width:{size:100,type:Or.PsV.PERCENTAGE},rows:e.customOrder.split("\n\n").map((e=>{const[s,...t]=e.split("\n");return s&&t.length>0?new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL(s)],width:{size:30,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL({children:t.map(((e,s)=>[new Or.NTc(e),...s0?[new Or.fzL({children:[new Or.NTc({text:"Items",bold:!0,size:24})]}),new Or.XIK({width:{size:100,type:Or.PsV.PERCENTAGE},rows:[new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL("Product")],width:{size:40,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL("Quantity")],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL("Price")],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL("Total")],width:{size:20,type:Or.PsV.PERCENTAGE}})]}),...e.orderItems.edges.map((e=>{let{node:s}=e;const t=s.product?.inventoryItems?.edges[0]?.node?.price||0;return new Or.Hjg({children:[new Or.nA6({children:[new Or.fzL(s.product?.name||"N/A")],width:{size:40,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL(s.quantity.toString())],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL(`$${t}`)],width:{size:20,type:Or.PsV.PERCENTAGE}}),new Or.nA6({children:[new Or.fzL("$"+s.quantity*t)],width:{size:20,type:Or.PsV.PERCENTAGE}})]})}))]})]:[],new Or.fzL({})])).flat()]}]}))(e),t=await Or.ND6.toBlob(s);(0,Ur.saveAs)(t,`orders_${(new Date).toISOString().replace(/[-:]/g,"").replace("T","_").replace("Z","")}.docx`)}Q({open:!0,message:`Orders downloaded successfully in ${s.toUpperCase()} format!`,severity:"success"})}catch(e){Q({open:!0,message:"Failed to download orders. Please try again.",severity:"error"})}le(!1)};return Ae||Ee||Ce||ue?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,ee.jsx)(j.A,{})})}):!De&&!we||ue?(0,ee.jsx)(Xn,{children:(0,ee.jsxs)(g.A,{sx:{p:3},children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Orders"}),b&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:b}),(0,ee.jsx)(fe.A,{sx:{mb:3},children:(0,ee.jsx)(ve.A,{children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:3,children:(0,ee.jsx)(p.A,{fullWidth:!0,placeholder:"Search orders...",value:I,onChange:e=>S(e.target.value),InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)(sn.A,{})})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:3,children:(0,ee.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Filter by Status",value:C,onChange:e=>w(e.target.value),InputProps:{startAdornment:(0,ee.jsx)(A.A,{position:"start",children:(0,ee.jsx)($r.A,{})})},children:[(0,ee.jsx)(ge.A,{value:"ALL",children:"All Statuses"}),vn.map((e=>(0,ee.jsx)(ge.A,{value:e.value,children:e.label},e.value)))]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:3,children:(0,ee.jsxs)(m.A,{variant:"body2",color:"textSecondary",children:["Total Orders: ",Ne.length]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:3,children:(0,ee.jsx)(te.A,{fullWidth:!0,variant:"contained",startIcon:(0,ee.jsx)(Tr.A,{}),onClick:()=>le(!0),disabled:0===Ne.length,children:"Download Orders"})})]})})}),0===Ne.length?(0,ee.jsx)(ae.A,{severity:"info",sx:{mb:2},children:"No orders found."}):(0,ee.jsxs)(Vt.A,{component:de.A,children:[(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>Ue("id"),children:["Order ID",(0,ee.jsx)(qr.A,{sx:{ml:1,transform:"id"===P&&"desc"===q?"rotate(180deg)":"none"}})]})}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>Ue("totalAmount"),children:["Total",(0,ee.jsx)(qr.A,{sx:{ml:1,transform:"totalAmount"===P&&"desc"===q?"rotate(180deg)":"none"}})]})}),(0,ee.jsx)(Yt.A,{children:"Status"}),(0,ee.jsx)(Yt.A,{children:"Actions"}),(0,ee.jsx)(Yt.A,{})]})}),(0,ee.jsx)(Qt.A,{children:Be.map((e=>{return(0,ee.jsxs)(x.Fragment,{children:[(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.id}),(0,ee.jsxs)(Yt.A,{children:["$",e.orderTotalAmount]}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:vn.find((s=>s.value===e.status))?.label||e.status,color:(s=e.status,vn.find((e=>e.value===s))?.color||"default"),size:"small"})}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(Se.A,{title:"Edit Order",children:(0,ee.jsx)(pe.A,{size:"small",onClick:()=>(e=>{c(e),f(e.status),M(e.deliveryInstructions||""),a(!0)})(e),disabled:!Me(e.status),children:(0,ee.jsx)(en.A,{})})}),(0,ee.jsx)(Se.A,{title:"Cancel Order",children:(0,ee.jsx)(pe.A,{size:"small",onClick:()=>(e=>{c(e),d(!0)})(e),disabled:!Me(e.status),children:(0,ee.jsx)(yn.A,{})})}),(0,ee.jsx)(Se.A,{title:"Upload File",children:(0,ee.jsx)(pe.A,{size:"small",onClick:()=>(async e=>{const s=document.createElement("input");s.type="file",s.accept="*/*",s.onchange=async()=>{try{const t=s.files[0];if(!t)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(t.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:d}=await r.json(),l=await fetch(i,{method:"PUT",headers:{"Content-Type":a},body:t});if(!l.ok)throw await l.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(d)}`)).ok?Q({open:!0,message:"File uploaded and verified successfully!",severity:"success"}):Q({open:!0,message:"File uploaded but verification failed. Please try viewing the file.",severity:"warning"})}catch(e){Q({open:!0,message:"Failed to upload file. Please try again.",severity:"error"})}},s.click()})(e),disabled:!Me(e.status),children:(0,ee.jsx)(An.A,{})})}),(0,ee.jsx)(Se.A,{title:"View File",children:(0,ee.jsx)(pe.A,{size:"small",onClick:()=>(async e=>{try{const s=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com";let t=null,n=null;if(e.bill_url){const r=await fetch(`${s}/s3/generate-view-url?bill_key=${encodeURIComponent(e.bill_url)}`);if(r.ok){const e=await r.json();t=e.view_url,n=e.file_name}}if(!t){const r=[".pdf",".jpg",".jpeg",".png",".docx"];for(const i of r){const r=await fetch(`${s}/s3/generate-view-url?order_id=${e.id}&file_name=receipt${i}`);if(r.ok){const e=await r.json();t=e.view_url,n=e.file_name;break}}}if(!t)return void Q({open:!0,message:"No file found for this order.",severity:"warning"});const r=document.createElement("a");r.href=t,r.target="_blank",r.rel="noopener noreferrer",document.body.appendChild(r),r.click(),document.body.removeChild(r)}catch(e){Q({open:!0,message:"Failed to view file. Please try again.",severity:"error"})}})(e),children:(0,ee.jsx)(bn.A,{})})})]}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(pe.A,{size:"small",onClick:()=>r(n===e.id?null:e.id),children:n===e.id?(0,ee.jsx)(Pr.A,{}):(0,ee.jsx)(kr.A,{})})})]}),n===e.id&&(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:6,children:(0,ee.jsx)(g.A,{sx:{p:2},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Information"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(m.A,{children:[(0,ee.jsx)("strong",{children:"Order Code:"})," ",e.displayCode||"N/A"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(m.A,{children:[(0,ee.jsx)("strong",{children:"Type:"})," ","PICKUP"===e.type?(0,ee.jsxs)(g.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(Ps.A,{fontSize:"small"}),"Pickup Order"]}):(0,ee.jsxs)(g.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ee.jsx)(As.A,{fontSize:"small"}),"Delivery Order"]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsxs)(m.A,{children:[(0,ee.jsx)("strong",{children:"Address:"})," ","PICKUP"===e.type?e.pickupAddress?.address||"No pickup address":e.address?.address||"No delivery address"]})})]})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Customer Information"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{children:["Email: ",e?.creator?.email||"N/A"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(m.A,{children:["Phone: ",e?.creator?.mobile||"N/A"]})})]})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Items"}),(0,ee.jsxs)(Ht.A,{size:"small",children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Product"}),(0,ee.jsx)(Yt.A,{children:"Quantity"}),(0,ee.jsx)(Yt.A,{children:"Price"}),(0,ee.jsx)(Yt.A,{children:"Total"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:e.orderItems?.edges?.length>0?_e(e.orderItems)?.map((s=>{const t=(n=s,r=e.orderItems.edges,n&&r?r.map((e=>{let{node:s}=e;return s})).filter((e=>e.productId===n.productId)).sort(((e,s)=>e.id-s.id)):[n]);var n,r;const i=s.product?.inventoryItems?.edges[0]?.node?.price||0;return(0,ee.jsxs)(x.Fragment,{children:[(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:s.product?.name||"N/A"}),(0,ee.jsx)(Yt.A,{children:s.quantity}),(0,ee.jsx)(Yt.A,{children:Rr(i)}),(0,ee.jsx)(Yt.A,{children:Rr(s.quantity*i)}),(0,ee.jsx)(Yt.A,{children:Me(e.status)&&(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(pe.A,{size:"small",onClick:()=>{return t=s,n=e.id,ne({...t,orderId:n}),ie(t.quantity),void X(!0);var t,n},sx:{mr:1},children:(0,ee.jsx)(en.A,{fontSize:"small"})}),(0,ee.jsx)(pe.A,{size:"small",onClick:()=>{return t=s,n=e.id,ne({...t,orderId:n}),ie(0),void X(!0);var t,n},color:"error",children:(0,ee.jsx)(dn.A,{fontSize:"small"})})]})})]}),t.length>1&&(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:5,children:(0,ee.jsxs)(g.A,{sx:{pl:2,py:1},children:[(0,ee.jsxs)(m.A,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1},children:["Order Change History (",t.length-1," ","changes)"]}),t.slice(0,-1).map(((e,s)=>(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1,borderRadius:1,mb:1},children:[(0,ee.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"100px"},children:["Change ",s+1]}),(0,ee.jsxs)(g.A,{sx:{display:"flex",gap:3},children:[(0,ee.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,ee.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount:"," ",Rr(e.orderAmount)]})]})]},e.id)))]})})})]},s.id)})):(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:5,align:"center",children:"No items found for this order"})})})]})]}),e.customOrder&&(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Custom Order Details"}),(0,ee.jsx)(g.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:e.customOrder.split("\n\n").map(((e,s)=>{const[t,...n]=e.split("\n");return t&&n.length>0?(0,ee.jsxs)(g.A,{sx:{mb:2},children:[(0,ee.jsx)(m.A,{variant:"subtitle2",sx:{color:"text.secondary",mb:.5},children:t}),(0,ee.jsx)(g.A,{sx:{pl:2},children:n.map(((e,s)=>(0,ee.jsx)(m.A,{variant:"body2",sx:{mb:.5},children:e},s)))})]},s):null}))})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Summary"}),(0,ee.jsx)(g.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:1,children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:6,children:(0,ee.jsx)(m.A,{children:"Subtotal:"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ee.jsx)(m.A,{children:Rr(e.totalAmount)})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,children:(0,ee.jsx)(m.A,{children:"Delivery Fee:"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ee.jsx)(m.A,{children:Rr(e.deliveryFee)})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,children:(0,ee.jsx)(m.A,{children:"Tax:"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ee.jsx)(m.A,{children:Rr(e.taxAmount)})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,children:(0,ee.jsx)(m.A,{children:"Tip:"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ee.jsx)(m.A,{children:Rr(e.tipAmount)})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(ss.A,{sx:{my:1}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,children:(0,ee.jsx)(m.A,{sx:{fontWeight:"bold"},children:"Total Amount:"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ee.jsx)(m.A,{sx:{fontWeight:"bold"},children:Rr(e.orderTotalAmount)})})]})})]}),e.deliveryInstructions&&(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Delivery Instructions"}),(0,ee.jsx)(m.A,{children:e.deliveryInstructions})]})]})})})})]},e.id);var s}))})]}),(0,ee.jsx)(y.A,{component:"div",count:Ne.length,page:z,onPageChange:(e,s)=>{W(s)},rowsPerPage:O,onRowsPerPageChange:e=>{U(parseInt(e.target.value,10)),W(0)},rowsPerPageOptions:[5,10,25,50]})]}),(0,ee.jsxs)(qe.A,{open:i,onClose:()=>a(!1),maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:"Update Order Status"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{select:!0,fullWidth:!0,label:"Status",value:h,onChange:e=>f(e.target.value),children:vn.map((e=>(0,ee.jsx)(ge.A,{value:e.value,children:e.label},e.value)))})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Delivery Instructions",value:_,onChange:e=>M(e.target.value),multiline:!0,rows:3})}),"READY_FOR_DELIVERY"===h&&(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,required:!0,children:[(0,ee.jsx)(Jt.A,{children:"Delivery Agent"}),(0,ee.jsx)(Zt.A,{value:V,onChange:e=>H(e.target.value),label:"Delivery Agent",children:Ie?.getStoreDrivers?.map((e=>(0,ee.jsxs)(ge.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId)))})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:6,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Schedule Time",value:G,onChange:e=>K(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>a(!1),children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:async()=>{try{const e={orderId:l.id,status:h,deliveryInstructions:_};if("READY"===h||"READY_FOR_DELIVERY"===h){if(!V)return void v("Driver ID is required for this status");if(!G)return void v("Schedule time is required for this status");e.driverId=parseInt(V),e.scheduleTime=G}await $e.mutateAsync(e)}catch(e){v(e.message)}},variant:"contained",color:"primary",disabled:$e.isPending,children:$e.isPending?"Updating...":"Update"})]})]}),(0,ee.jsxs)(qe.A,{open:o,onClose:()=>d(!1),children:[(0,ee.jsx)(Re.A,{children:"Cancel Order"}),(0,ee.jsxs)(ze.A,{children:[(0,ee.jsx)(m.A,{children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,ee.jsx)(p.A,{fullWidth:!0,label:"Cancellation Reason",value:N,onChange:e=>B(e.target.value),multiline:!0,rows:3,sx:{mt:2},required:!0})]}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>d(!1),disabled:Oe.isPending||Oe.isLoading,children:"No"}),(0,ee.jsx)(te.A,{onClick:async()=>{try{if(!be)return void v("User profile not found. Please try again.");Oe.mutate({orderId:l.id,cancelMessage:N,cancelledByUserId:be})}catch(e){v(e.message)}},variant:"contained",color:"error",disabled:!N.trim()||Oe.isPending||Oe.isLoading,startIcon:Oe.isPending||Oe.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:Oe.isPending||Oe.isLoading?"Cancelling...":"Yes, Cancel Order"})]})]}),(0,ee.jsxs)(qe.A,{open:Z,onClose:()=>X(!1),maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:0===re?"Delete Order Item":"Edit Order Item"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsxs)(m.A,{variant:"subtitle1",children:["Product: ",se?.product?.name||"N/A"]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,children:(0,ee.jsx)(p.A,{fullWidth:!0,label:"Quantity",type:"number",value:re,onChange:e=>ie(parseInt(e.target.value)||0),inputProps:{min:0}})})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>X(!1),children:"Cancel"}),(0,ee.jsx)(te.A,{onClick:async()=>{try{await Te.mutateAsync({orderId:se.orderId,itemId:se.id,quantity:re,price:se.product?.inventoryItems?.edges[0]?.node?.price||0})}catch(e){v(e.message)}},variant:"contained",color:0===re?"error":"primary",disabled:Te.isLoading,children:Te.isLoading?"Updating...":0===re?"Delete":"Update"})]})]}),(0,ee.jsxs)(qe.A,{open:oe,onClose:()=>le(!1),maxWidth:"xs",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:"Download Orders"}),(0,ee.jsxs)(ze.A,{children:[(0,ee.jsxs)(m.A,{variant:"body1",gutterBottom:!0,children:["Download ",Ne.length," filtered orders"]}),(0,ee.jsxs)(m.A,{variant:"body2",color:"textSecondary",gutterBottom:!0,children:[I&&`Search term: ${I}`,"ALL"!==C&&`\nStatus: ${C}`]}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:6,children:(0,ee.jsx)(te.A,{fullWidth:!0,variant:"outlined",onClick:()=>Ve(Ne,"pdf"),startIcon:(0,ee.jsx)(Tr.A,{}),children:"PDF"})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:6,children:(0,ee.jsx)(te.A,{fullWidth:!0,variant:"outlined",onClick:()=>Ve(Ne,"docx"),startIcon:(0,ee.jsx)(Tr.A,{}),children:"DOCX"})})]})]}),(0,ee.jsx)(We.A,{children:(0,ee.jsx)(te.A,{onClick:()=>le(!1),children:"Cancel"})})]}),(0,ee.jsx)(Xt.A,{open:Y.open,autoHideDuration:6e3,onClose:()=>Q({...Y,open:!1}),children:(0,ee.jsx)(ae.A,{onClose:()=>Q({...Y,open:!1}),severity:Y.severity,sx:{width:"100%"},children:Y.message})})]})}):(0,ee.jsx)(Xn,{children:(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:De?.message||we?.message||"An error occurred"})})},_r=[{value:"ACTIVE",label:"Active"},{value:"INACTIVE",label:"Inactive"}],Mr=()=>{const{userProfile:e,setUserProfile:s}=J(),[t,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)({driverStatus:"",orderStatus:"",dateRange:"all"}),[d,l]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ms.T)();n(e.sub)}catch(e){}})()}),[]);const{data:A,isLoading:y}=(0,u.I)({queryKey:["getUserProfile",t],queryFn:async()=>{const e=await k(D,{userId:t});return e?.getUserProfile&&s(e.getUserProfile),e},enabled:!!t}),f=A?.getUserProfile?.stores?.edges?.[0]?.node?.id,{data:b,isLoading:v,error:I,refetch:S}=(0,u.I)({queryKey:["driversByStore",f],queryFn:()=>k("\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:f}),enabled:!!f&&d}),{data:C,isLoading:w,error:P,refetch:E}=(0,u.I)({queryKey:["storeOrders",f],queryFn:async()=>(await k(L,{storeId:f})).getOrdersByStore||[],enabled:!!f}),F=(e,s)=>{o((t=>({...t,[e]:s})))},$=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"),T=(e,s)=>{if(!e)return[];let t=e.filter((e=>e?.delivery?.driverId===s));if(a.orderStatus&&(t=t.filter((e=>e.status===a.orderStatus))),"all"!==a.dateRange){const e=new Date,s=new Date(e.getFullYear(),e.getMonth(),e.getDate());t=t.filter((e=>{const t=new Date(e.createdAt);switch(a.dateRange){case"today":return t>=s;case"week":const e=new Date(s);return e.setDate(e.getDate()-7),t>=e;case"month":const n=new Date(s);return n.setMonth(n.getMonth()-1),t>=n;default:return!0}}))}return t},q=e=>e?a.driverStatus?e.filter((e=>e.status===a.driverStatus)):e:[],R=v||w||y,z=I||P||c;return(0,ee.jsx)(Xn,{children:(0,ee.jsxs)(g.A,{sx:{p:3},children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Delivery Partners"}),c&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:c}),y&&(0,ee.jsx)(ae.A,{severity:"info",sx:{mb:2},children:"Loading user profile..."}),(0,ee.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,ee.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Filters"}),(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:4,children:(0,ee.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Driver Status",value:a.driverStatus,onChange:e=>F("driverStatus",e.target.value),children:[(0,ee.jsx)(ge.A,{value:"",children:"All Statuses"}),_r.map((e=>(0,ee.jsx)(ge.A,{value:e.value,children:e.label},e.value)))]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:4,children:(0,ee.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Order Status",value:a.orderStatus,onChange:e=>F("orderStatus",e.target.value),children:[(0,ee.jsx)(ge.A,{value:"",children:"All Statuses"}),vn.map((e=>(0,ee.jsx)(ge.A,{value:e.value,children:e.label},e.value)))]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,sm:4,children:(0,ee.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Date Range",value:a.dateRange,onChange:e=>F("dateRange",e.target.value),children:[(0,ee.jsx)(ge.A,{value:"all",children:"All Time"}),(0,ee.jsx)(ge.A,{value:"today",children:"Today"}),(0,ee.jsx)(ge.A,{value:"week",children:"Last 7 Days"}),(0,ee.jsx)(ge.A,{value:"month",children:"Last 30 Days"})]})}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,children:[(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:(0,ee.jsx)(sn.A,{}),onClick:()=>{l(!0),S(),E()},disabled:!f||y,children:y?"Loading Profile...":"Get Data"}),!f&&!y&&(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mt:1},children:"Store ID not available. Please check if you have a store assigned."})]})]})]}),R?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",p:3},children:(0,ee.jsx)(j.A,{})}):z?(0,ee.jsx)(ae.A,{severity:"error",children:I?.message||P?.message||"An error occurred while fetching data"}):d?(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsxs)(m.A,{variant:"h6",gutterBottom:!0,children:["Delivery Partners (",q(b?.getStoreDrivers||[]).length,")"]}),(0,ee.jsx)(Vt.A,{component:de.A,children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Driver ID"}),(0,ee.jsx)(Yt.A,{children:"Name"}),(0,ee.jsx)(Yt.A,{children:"Email"}),(0,ee.jsx)(Yt.A,{children:"Phone"}),(0,ee.jsx)(Yt.A,{children:"Status"}),(0,ee.jsx)(Yt.A,{children:"Orders"}),(0,ee.jsx)(Yt.A,{})]})}),(0,ee.jsxs)(Qt.A,{children:[q(b?.getStoreDrivers||[]).map((e=>(0,ee.jsxs)(x.Fragment,{children:[(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e?.userId}),(0,ee.jsx)(Yt.A,{children:e.name}),(0,ee.jsx)(Yt.A,{children:e?.driver?.email}),(0,ee.jsx)(Yt.A,{children:e?.driver?.mobile}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:e?.driver?.active?"Active":"Inactive",color:$(e?.driver?.active),size:"small"})}),(0,ee.jsx)(Yt.A,{children:T(C||[],e?.userId).length}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(pe.A,{size:"small",onClick:()=>i(r===e?.userId?null:e?.userId),children:r===e?.userId?(0,ee.jsx)(nr.A,{}):(0,ee.jsx)(rr.A,{})})})]}),r===e?.userId&&(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:7,children:(0,ee.jsxs)(g.A,{sx:{p:2},children:[(0,ee.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:["Orders for ",e.name,":"]}),(0,ee.jsxs)(Ht.A,{size:"small",children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Order ID"}),(0,ee.jsx)(Yt.A,{children:"Date"}),(0,ee.jsx)(Yt.A,{children:"Customer"}),(0,ee.jsx)(Yt.A,{children:"Total"}),(0,ee.jsx)(Yt.A,{children:"Status"})]})}),(0,ee.jsx)(Qt.A,{children:T(C||[],e?.userId).length>0?T(C||[],e?.userId).map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.id}),(0,ee.jsx)(Yt.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,ee.jsx)(Yt.A,{children:e.user?.name}),(0,ee.jsxs)(Yt.A,{children:["₹",e.totalAmount]}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(Fe.A,{label:vn.find((s=>s.value===e.status))?.label||e.status,color:$(e.status),size:"small"})})]},e.id))):(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:5,align:"center",children:"No orders found for this driver with the current filters."})})})]})]})})})]},e?.userId))),0===q(b?.getStoreDrivers||[]).length&&(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:7,align:"center",children:"No delivery partners found with the current filters."})})]})]})})]}):(0,ee.jsx)(ae.A,{severity:"info",children:'Click the "Get Data" button to fetch delivery partners and their orders.'})]})})};var Vr=t(69279);const Hr=x.memo((e=>{let{open:s,onClose:t,selectedItem:n,onUpdate:r,isLoading:i}=e;const[a,o]=x.useState(""),[d,l]=x.useState(""),[c,u]=x.useState(!0),[h,p]=x.useState(!0),[A,y]=x.useState("");x.useEffect((()=>{n&&(o(n.price?n.price.toString():""),l(n.quantity?n.quantity.toString():""),u(void 0===n.isAvailable||n.isAvailable),p(void 0===n.isListed||n.isListed))}),[n]);const f={width:"100%",padding:"8.5px 14px",fontSize:"1rem",borderRadius:"4px",border:"1px solid rgba(0, 0, 0, 0.23)",marginBottom:"16px",outline:"none","&:focus":{borderColor:"#1976d2",borderWidth:"2px"}},b={fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)",marginBottom:"4px",display:"block"};return(0,ee.jsxs)(qe.A,{open:s,onClose:()=>{y(""),t()},maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:"Edit Inventory Item"}),(0,ee.jsxs)(ze.A,{children:[n&&(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[n.product?.image&&(0,ee.jsx)(be.A,{component:"img",sx:{width:80,height:80,objectFit:"contain",mr:2},image:n.product.image,alt:n.product.name}),(0,ee.jsxs)(g.A,{children:[(0,ee.jsx)(m.A,{variant:"subtitle1",children:(0,ee.jsx)("strong",{children:n.product?.name})}),(0,ee.jsx)(m.A,{variant:"body2",color:"text.secondary",children:n.product?.category?.name||"Uncategorized"})]})]}),(0,ee.jsx)(ss.A,{sx:{my:2}}),(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsx)("label",{htmlFor:"edit-price-input",style:b,children:"Price ($)"}),(0,ee.jsx)("input",{id:"edit-price-input",type:"number",value:a,onChange:e=>o(e.target.value),min:"0",step:"0.01",style:f}),(0,ee.jsx)("label",{htmlFor:"edit-quantity-input",style:b,children:"Quantity"}),(0,ee.jsx)("input",{id:"edit-quantity-input",type:"number",value:d,onChange:e=>l(e.target.value),min:"0",style:f}),(0,ee.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(nn.A,{checked:c,onChange:e=>u(e.target.checked),color:"primary"}),label:"Available (In Stock)"}),(0,ee.jsx)(ms.A,{control:(0,ee.jsx)(nn.A,{checked:h,onChange:e=>p(e.target.checked),color:"primary"}),label:"Listed (Visible to Customers)"})]})]})]}),A&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mt:2},children:A})]}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{y(""),t()},disabled:i,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",onClick:()=>{!a||isNaN(parseFloat(a))||parseFloat(a)<=0?y("Please enter a valid price greater than zero."):!d||isNaN(parseInt(d,10))||parseInt(d,10)<0?y("Please enter a valid quantity (0 or greater)."):(y(""),r({inventoryId:n.id,price:a,quantity:d,isAvailable:c,isListed:h}))},disabled:i,startIcon:i?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?"Updating...":"Update"})]})]})})),Gr=x.memo((e=>{let{open:s,onClose:t,storeId:n,availableProducts:r,onAdd:i,isLoading:a,errorMessage:o}=e;const[d,l]=(0,x.useState)(null),[c,u]=(0,x.useState)({price:"",quantity:"",measurement:"",unit:"",searchInput:""}),[m,h]=(0,x.useState)(!1),p=(0,x.useRef)(null),A=e=>{const{name:s,value:t}=e.target;u((e=>({...e,[s]:t})))},y=x.useMemo((()=>r.filter((e=>e.name.toLowerCase().includes(c.searchInput.toLowerCase())))),[r,c.searchInput]),f=()=>{l(null),u({price:"",quantity:"",measurement:"",unit:"",searchInput:""})};x.useEffect((()=>{s||f()}),[s]);const b={width:"100%",padding:"8.5px 14px",fontSize:"1rem",borderRadius:"4px",border:"1px solid rgba(0, 0, 0, 0.23)",marginBottom:"16px",outline:"none"},v={fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)",marginBottom:"4px",display:"block"};return(0,ee.jsxs)(qe.A,{open:s,onClose:()=>{t(),f()},maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:"Add Product to Inventory"}),(0,ee.jsxs)(ze.A,{children:[(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsx)("label",{htmlFor:"searchInput",style:v,children:"Search Product"}),(0,ee.jsxs)("div",{style:{position:"relative"},children:[(0,ee.jsx)("input",{id:"searchInput",name:"searchInput",type:"text",placeholder:"Start typing to search...",value:c.searchInput,onChange:e=>{A(e),h(!0)},onFocus:()=>h(!0),style:b,ref:p}),a&&(0,ee.jsx)(j.A,{size:20,style:{position:"absolute",right:"10px",top:"50%",transform:"translateY(-50%)"}})]}),m&&y.length>0&&(0,ee.jsx)("div",{style:{position:"absolute",width:p.current?.offsetWidth,zIndex:1300,backgroundColor:"#fff",border:"1px solid rgba(0, 0, 0, 0.23)",borderRadius:"4px",maxHeight:"300px",overflow:"auto"},children:y.map((e=>(0,ee.jsxs)("div",{onClick:()=>(e=>{l(e),u((s=>({...s,searchInput:e.name}))),h(!1)})(e),style:{padding:"8px 16px",cursor:"pointer",backgroundColor:d?.id===e.id?"rgba(0, 0, 0, 0.04)":"transparent","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.08)"}},children:[(0,ee.jsx)("div",{children:e.name}),(0,ee.jsx)("div",{style:{fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)"},children:e.category.name})]},e.id)))})]}),(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsx)("label",{htmlFor:"price",style:v,children:"Price ($)"}),(0,ee.jsx)("input",{id:"price",name:"price",type:"number",value:c.price,onChange:A,min:"0",step:"0.01",style:b})]}),(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsx)("label",{htmlFor:"quantity",style:v,children:"Quantity"}),(0,ee.jsx)("input",{id:"quantity",name:"quantity",type:"number",value:c.quantity,onChange:A,min:"0",style:b})]}),(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsx)("label",{htmlFor:"measurement",style:v,children:"Measurement"}),(0,ee.jsx)("input",{id:"measurement",name:"measurement",type:"number",value:c.measurement,onChange:A,min:"0",style:b})]}),(0,ee.jsxs)(g.A,{sx:{mt:2},children:[(0,ee.jsx)("label",{htmlFor:"unit",style:v,children:"Unit"}),(0,ee.jsxs)("select",{id:"unit",name:"unit",value:c.unit,onChange:A,style:{...b,backgroundColor:"transparent",appearance:"auto",height:"40px"},children:[(0,ee.jsx)("option",{value:"",children:"None"}),(0,ee.jsx)("option",{value:"1",children:"Grams (g)"}),(0,ee.jsx)("option",{value:"2",children:"Kilograms (kg)"}),(0,ee.jsx)("option",{value:"3",children:"Milliliters (ml)"}),(0,ee.jsx)("option",{value:"4",children:"Liters (L)"}),(0,ee.jsx)("option",{value:"5",children:"Pieces (pcs)"})]})]}),o&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mt:2},children:o})]}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{t(),f()},disabled:a,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",onClick:()=>{d&&i({storeId:n,productId:d.id,price:c.price,quantity:c.quantity,measurement:c.measurement||null,unit:c.unit||null})},disabled:a||!d||!c.price||!c.quantity,startIcon:a?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:a?"Adding Product...":"Add Product"})]})]})})),Kr=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=J(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(null),[c,A]=(0,x.useState)(""),[y,f]=(0,x.useState)(""),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)(!1),[C,w]=(0,x.useState)(10),[P,E]=(0,x.useState)(1),[F]=(0,x.useState)(10),[D,L]=(0,x.useState)("all"),[$,T]=(0,x.useState)([]),[q,R]=(0,x.useState)(!1),[z,W]=(0,x.useState)(!0);(0,x.useRef)(null),(0,x.useRef)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ms.T)();s(e.sub)}catch(e){}})()}),[]);const{data:O,isLoading:U}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await k("\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 s?.getUserProfile&&n(s.getUserProfile),s},enabled:!!e}),{data:N,isLoading:B,error:_,refetch:M}=(0,u.I)({queryKey:["storeWithInventory",t?.id],queryFn:()=>k("\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 storeId\n productId\n quantity\n price\n measurement\n unit\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:t?.id}),enabled:!!t?.id});(0,x.useEffect)((()=>{N&&N.products&&W(!1)}),[N]);const V=N?.storesByManager&&N.storesByManager[0],H=V?.inventory?.edges?.map((e=>e.node))||[],G=N?.products||[],K=x.useMemo((()=>H.filter((e=>{const s=""===b||e.product?.name?.toLowerCase().includes(b.toLowerCase())||e.product?.description?.toLowerCase().includes(b.toLowerCase()),t=!I||e.quantity<=C,n="all"===D||e.product?.category?.name===D;return s&&t&&n}))),[H,b,I,C,D]),Y=x.useMemo((()=>K.slice((P-1)*F,P*F)),[K,P,F]);(0,x.useEffect)((()=>{const e=[...new Set(H.map((e=>e.product?.category?.name||"Uncategorized")).filter(Boolean))].sort();JSON.stringify(e)!==JSON.stringify($)&&T(e)}),[H]);const Q=(0,ds.n)({mutationFn:e=>{let{inventoryId:s,price:t,quantity:n,isAvailable:r,isListed:i}=e;return k("\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 price\n quantity\n isAvailable\n isListed\n updatedAt\n }\n }\n",{inventoryId:s,price:parseFloat(t),quantity:parseInt(n,10),isAvailable:void 0!==r?r:null,isListed:void 0!==i?i:null})},onSuccess:()=>{M(),o(!1),i(null),f("Inventory item updated successfully"),setTimeout((()=>f("")),3e3)},onError:e=>{A(`Error updating inventory: ${e.message}`)}}),Z=(0,ds.n)({mutationFn:e=>{let{storeId:s,productId:t,price:n,quantity:r,measurement:i,unit:a}=e;return k("\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 updatedAt\n product {\n id\n name\n description\n category {\n id\n name\n }\n image\n }\n }\n }\n",{storeId:parseInt(s,10),productId:parseInt(t,10),price:parseFloat(n),quantity:parseInt(r,10),measurement:i?parseInt(i,10):null,unit:a||null})},onSuccess:()=>{M(),R(!1),f("Product added to inventory successfully"),setTimeout((()=>f("")),3e3)},onError:e=>{A(`Error adding product: ${e.message}`)}}),X=x.memo((e=>{let{searchTerm:s,setSearchTerm:t,filterCategory:n,setFilterCategory:r,lowStockOnly:i,setLowStockOnly:a,lowStockThreshold:o,setLowStockThreshold:d,categories:l}=e;return(0,ee.jsx)(de.A,{elevation:3,sx:{p:3,mb:4},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:4,children:(0,ee.jsx)(p.A,{label:"Search Products",variant:"outlined",size:"small",value:s,onChange:e=>t(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,ee.jsx)(sn.A,{sx:{mr:1,color:"text.secondary"}})}})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:3,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,size:"small",children:[(0,ee.jsx)(Jt.A,{id:"category-select-label",children:"Category"}),(0,ee.jsxs)(Zt.A,{labelId:"category-select-label",id:"category-select",value:n,label:"Category",onChange:e=>r(e.target.value),children:[(0,ee.jsx)(ge.A,{value:"all",children:"All Categories"}),l.map((e=>(0,ee.jsx)(ge.A,{value:e,children:e},e)))]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:3,children:(0,ee.jsxs)(cs.A,{fullWidth:!0,size:"small",children:[(0,ee.jsx)(Jt.A,{id:"stock-filter-label",children:"Stock Filter"}),(0,ee.jsxs)(Zt.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,ee.jsx)(ge.A,{value:"false",children:"All Items"}),(0,ee.jsx)(ge.A,{value:"true",children:"Low Stock Only"})]})]})}),(0,ee.jsx)(ye.Ay,{item:!0,xs:12,md:2,children:(0,ee.jsx)(p.A,{label:"Low Stock Threshold",type:"number",size:"small",value:o,onChange:e=>d(parseInt(e.target.value,10)||0),disabled:!i,fullWidth:!0})})]})})}));return U||B?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})})}):_?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4},children:(0,ee.jsxs)(ae.A,{severity:"error",children:["Error loading inventory data: ",_.message]})})}):(0,ee.jsx)(Xn,{children:(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Inventory Management"}),(0,ee.jsx)(X,{searchTerm:b,setSearchTerm:v,filterCategory:D,setFilterCategory:L,lowStockOnly:I,setLowStockOnly:S,lowStockThreshold:C,setLowStockThreshold:w,categories:$}),y&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:y}),c&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:c}),(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.A,{variant:"h5",children:"Inventory Items"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:Z.isPending||Z.isPending?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):(0,ee.jsx)(we.A,{}),onClick:()=>R(!0),disabled:Z.isPending||Z.isPending,children:Z.isPending||Z.isPending?"Adding...":"Add Product"})]}),z?(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,ee.jsx)(j.A,{})}):0===K.length?(0,ee.jsx)(ae.A,{severity:"info",sx:{my:2},children:"No inventory items match your filters."}):(0,ee.jsxs)(ee.Fragment,{children:[(0,ee.jsx)(Vt.A,{component:de.A,variant:"outlined",children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{}),(0,ee.jsx)(Yt.A,{children:"Product"}),(0,ee.jsx)(Yt.A,{children:"Category"}),(0,ee.jsx)(Yt.A,{children:"Price"}),(0,ee.jsx)(Yt.A,{children:"Quantity"}),(0,ee.jsx)(Yt.A,{children:"Available"}),(0,ee.jsx)(Yt.A,{children:"Listed"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:Y.map((e=>(0,ee.jsxs)(x.Fragment,{children:[(0,ee.jsxs)(Kt.A,{sx:{backgroundColor:e?.isAvailable?"inherit":"rgba(255, 0, 0, 0.1)"},children:[(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(pe.A,{size:"small",onClick:()=>{return s=e.id,void l(d===s?null:s);var s},children:d===e.id?(0,ee.jsx)(nr.A,{}):(0,ee.jsx)(rr.A,{})})}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[e.product?.image&&(0,ee.jsx)(be.A,{component:"img",sx:{width:50,height:50,objectFit:"contain",mr:2},image:e.product.image,alt:e.product.name}),(0,ee.jsx)(m.A,{children:e.product?.name})]})}),(0,ee.jsx)(Yt.A,{children:e.product?.category?.name||"Uncategorized"}),(0,ee.jsxs)(Yt.A,{children:["$",e.price.toFixed(2)]}),(0,ee.jsx)(Yt.A,{children:e.quantity}),(0,ee.jsx)(Yt.A,{children:e?.isAvailable?(0,ee.jsx)(Fe.A,{label:"In Stock",color:"success",size:"small"}):(0,ee.jsx)(Fe.A,{label:"Low Stock",color:"error",size:"small"})}),(0,ee.jsx)(Yt.A,{children:e?.isListed?(0,ee.jsx)(Fe.A,{label:"Listed",color:"success",size:"small"}):(0,ee.jsx)(Fe.A,{label:"Not Listed",color:"error",size:"small"})}),(0,ee.jsx)(Yt.A,{children:(0,ee.jsx)(pe.A,{onClick:()=>(e=>{e&&(i(e),o(!0))})(e),size:"small",color:"primary",disabled:Q.isPending||Q.isLoading||Z.isPending||Z.isLoading,children:(0,ee.jsx)(en.A,{})})})]}),(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{sx:{p:0},colSpan:7,children:(0,ee.jsx)(sr.A,{in:d===e.id,timeout:"auto",unmountOnExit:!0,children:(0,ee.jsx)(g.A,{sx:{p:3,backgroundColor:"rgba(0, 0, 0, 0.03)"},children:(0,ee.jsxs)(ye.Ay,{container:!0,spacing:2,children:[(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,md:6,children:[(0,ee.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,ee.jsx)("strong",{children:"Description:"})," ",e.product?.description||"No description available"]}),(0,ee.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,ee.jsx)("strong",{children:"Product ID:"})," ",e.product?.id]})]}),(0,ee.jsxs)(ye.Ay,{item:!0,xs:12,md:6,children:[(0,ee.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,ee.jsx)("strong",{children:"Last Updated:"})," ",e.updatedAt?new Date(e.updatedAt).toLocaleString():"N/A"]}),(0,ee.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,ee.jsx)("strong",{children:"Measurement:"})," ",e.measurement&&e.unit?`${e.measurement} ${e.unit}`:"N/A"]})]})]})})})})})]},e.id)))})]})}),(0,ee.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,ee.jsx)(Vr.A,{count:Math.ceil(K.length/F),page:P,onChange:(e,s)=>E(s),color:"primary"})})]})]}),(0,ee.jsx)(Hr,{open:a,onClose:()=>{o(!1),A("")},selectedItem:r,onUpdate:e=>Q.mutate(e),isLoading:Q.isPending}),(0,ee.jsx)(Gr,{open:q,onClose:()=>R(!1),storeId:V?.id,availableProducts:G,onAdd:Z.mutate,isLoading:Z.isPending,errorMessage:c})]})})},Yr=e=>{let{open:s,onClose:t,selectedLocationCode:n,onUpdate:r,isLoading:i,existingCodes:a}=e;const[o,d]=(0,x.useState)({location:"",code:""}),[l,c]=(0,x.useState)("");(0,x.useEffect)((()=>{d(n?{location:n.location||"",code:n.code||""}:{location:"",code:""}),c("")}),[n,s]);const u=()=>{d({location:"",code:""}),c(""),t()},m=e=>{const{name:s,value:t}=e.target;d((e=>({...e,[s]:t}))),c("")};return(0,ee.jsxs)(qe.A,{open:s,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:n?"Edit Location Code":"Add New Location Code"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ee.jsx)(p.A,{name:"location",label:"Location",value:o.location,onChange:m,fullWidth:!0,placeholder:"e.g., Main Branch",error:!!l&&l.includes("Location"),helperText:l&&l.includes("Location")?l:""}),(0,ee.jsx)(p.A,{name:"code",label:"Code",value:o.code,onChange:m,fullWidth:!0,placeholder:"e.g., MB001",error:!!l&&(l.includes("Code")||l.includes("already exists")),helperText:l&&(l.includes("Code")||l.includes("already exists"))?l:""})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:u,children:"Cancel"}),(0,ee.jsx)(te.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,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},Qr=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=J(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(!1),[c,p]=(0,x.useState)(""),[A,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ms.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await k("\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 s?.getUserProfile&&n(s.getUserProfile),s},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,u.I)({queryKey:["storeWithLocationCodes",t?.id],queryFn:()=>k("\n query GetStoreWithLocationCodes($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:t?.id}),enabled:!!t?.id}),C=v?.storesByManager&&v.storesByManager[0],{data:w,isLoading:P,error:E,refetch:F}=(0,u.I)({queryKey:["getStoreLocationCodesByStore",C?.id],queryFn:()=>k("\n query GetStoreLocationCodesByStore($storeId: Int!) {\n getStoreLocationCodesByStore(storeId: $storeId) {\n id\n location\n code\n }\n }\n",{storeId:C?.id}),enabled:!!C?.id}),D=w?.getStoreLocationCodesByStore||[],L=(0,ds.n)({mutationFn:e=>{if(!C?.id)throw new Error("Store not found");return k("\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})},onSuccess:()=>{F(),o(!1),i(null),y("Location code updated successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error updating location code: ${e.message}`),setTimeout((()=>p("")),5e3)}}),$=(0,ds.n)({mutationFn:e=>k("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{F(),l(!1),i(null),y("Location code deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error deleting location code: ${e.message}`)}}),T=(0,ds.n)({mutationFn:e=>k("\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:C.id}}),onSuccess:()=>{F(),o(!1),i(null),y("Location code added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error adding location code: ${e.message}`)}});return b||I||P?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})})}):S||E?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4},children:(0,ee.jsxs)(ae.A,{severity:"error",children:["Error loading data: ",S?.message||E?.message]})})}):(0,ee.jsx)(Xn,{children:(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),A&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:A}),c&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:c}),(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.A,{variant:"h5",children:"Location Codes"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:T.isPending||T.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):(0,ee.jsx)(we.A,{}),onClick:()=>{i(null),o(!0)},disabled:T.isPending||T.isLoading,children:T.isPending||T.isLoading?"Adding...":"Add Location Code"})]}),0===D.length?(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Location"}),(0,ee.jsx)(Yt.A,{children:"Code"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:(0,ee.jsx)(Kt.A,{children:(0,ee.jsx)(Yt.A,{colSpan:3,align:"center",children:(0,ee.jsx)(ae.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})}):(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Location"}),(0,ee.jsx)(Yt.A,{children:"Code"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:D.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.location}),(0,ee.jsx)(Yt.A,{children:e.code}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,ee.jsx)(en.A,{})}),(0,ee.jsx)(pe.A,{onClick:()=>(e=>{i(e),l(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,ee.jsx)(dn.A,{})})]})]},e.id)))})]})})]}),(0,ee.jsx)(Yr,{open:a,onClose:()=>{o(!1),i(null),p("")},selectedLocationCode:r,onUpdate:e=>{r?L.mutate(e):T.mutate(e)},isLoading:L.isPending||L.isLoading||T.isPending||T.isLoading,existingCodes:D}),(0,ee.jsxs)(qe.A,{open:d,onClose:()=>{l(!1),i(null),p("")},children:[(0,ee.jsx)(Re.A,{children:"Delete Location Code"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{l(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})})},Jr=e=>{let{open:s,onClose:t,selectedPickupAddress:n,onUpdate:r,isLoading:i,existingAddresses:a}=e;const[o,d]=(0,x.useState)({address:""}),[l,c]=(0,x.useState)(""),[u,h]=(0,x.useState)(!1);(0,x.useEffect)((()=>{n?(d({address:n.address||""}),h(!0)):(d({address:""}),h(!1)),c("")}),[n]);return(0,ee.jsxs)(qe.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,ee.jsx)(Re.A,{children:n?"Edit Pickup Address":"Add New Pickup Address"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ee.jsx)(St,{value:o.address,onChange:e=>{d((s=>({...s,address:e}))),c("")},onValidAddress:h}),l&&(0,ee.jsx)(m.A,{color:"error",variant:"caption",children:l})]})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:t,children:"Cancel"}),(0,ee.jsx)(te.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,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},Zr=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=J(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[d,l]=(0,x.useState)(!1),[c,p]=(0,x.useState)(""),[A,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Ms.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await k("\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 s?.getUserProfile&&n(s.getUserProfile),s},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,u.I)({queryKey:["storeWithPickupAddresses",t?.id],queryFn:()=>k("\n query GetStoreWithPickupAddresses($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:t?.id}),enabled:!!t?.id}),C=v?.storesByManager&&v.storesByManager[0],{data:w,isLoading:P,error:E,refetch:F}=(0,u.I)({queryKey:["getPickupAddressesByStore",C?.id],queryFn:()=>k("\n query GetPickupAddressesByStore($storeId: Int!) {\n getPickupAddressesByStore(storeId: $storeId) {\n id\n storeId\n address\n }\n }\n",{storeId:C?.id}),enabled:!!C?.id}),D=w?.getPickupAddressesByStore||[],L=(0,ds.n)({mutationFn:e=>k("\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=>{p(`Error updating pickup address: ${e.message}`)}}),$=(0,ds.n)({mutationFn:e=>k("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{F(),l(!1),i(null),y("Pickup address deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error deleting pickup address: ${e.message}`)}}),T=(0,ds.n)({mutationFn:e=>k("\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:C.id}}),onSuccess:()=>{F(),o(!1),i(null),y("Pickup address added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error adding pickup address: ${e.message}`)}});return b||I||P?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ee.jsx)(j.A,{})})}):S||E?(0,ee.jsx)(Xn,{children:(0,ee.jsx)(h.A,{sx:{mt:4},children:(0,ee.jsxs)(ae.A,{severity:"error",children:["Error loading data: ",S?.message||E?.message]})})}):(0,ee.jsx)(Xn,{children:(0,ee.jsxs)(h.A,{children:[(0,ee.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),A&&(0,ee.jsx)(ae.A,{severity:"success",sx:{mb:2},children:A}),c&&(0,ee.jsx)(ae.A,{severity:"error",sx:{mb:2},children:c}),(0,ee.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ee.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ee.jsx)(m.A,{variant:"h5",children:"Pickup Addresses"}),(0,ee.jsx)(te.A,{variant:"contained",color:"primary",startIcon:T.isPending||T.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):(0,ee.jsx)(we.A,{}),onClick:()=>{i(null),o(!0)},disabled:T.isPending||T.isLoading,children:T.isPending||T.isLoading?"Adding...":"Add Pickup Address"})]}),0===D.length?(0,ee.jsx)(ae.A,{severity:"info",sx:{my:2},children:"No pickup addresses found. Add your first pickup address to get started."}):(0,ee.jsx)(Vt.A,{children:(0,ee.jsxs)(Ht.A,{children:[(0,ee.jsx)(Gt.A,{children:(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:"Address"}),(0,ee.jsx)(Yt.A,{children:"Actions"})]})}),(0,ee.jsx)(Qt.A,{children:D.map((e=>(0,ee.jsxs)(Kt.A,{children:[(0,ee.jsx)(Yt.A,{children:e.address}),(0,ee.jsxs)(Yt.A,{children:[(0,ee.jsx)(pe.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,ee.jsx)(en.A,{})}),(0,ee.jsx)(pe.A,{onClick:()=>(e=>{i(e),l(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,ee.jsx)(dn.A,{})})]})]},e.id)))})]})})]}),(0,ee.jsx)(Jr,{open:a,onClose:()=>{o(!1),i(null),p("")},selectedPickupAddress:r,onUpdate:e=>{r?L.mutate(e):T.mutate(e)},isLoading:L.isPending||L.isLoading||T.isPending||T.isLoading,existingAddresses:D}),(0,ee.jsxs)(qe.A,{open:d,onClose:()=>{l(!1),i(null),p("")},children:[(0,ee.jsx)(Re.A,{children:"Delete Pickup Address"}),(0,ee.jsx)(ze.A,{children:(0,ee.jsx)(m.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,ee.jsxs)(We.A,{children:[(0,ee.jsx)(te.A,{onClick:()=>{l(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,ee.jsx)(te.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,ee.jsx)(j.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})})},Xr=()=>{const{user:e}=J();return(0,ee.jsxs)(o.A,{theme:c,children:[(0,ee.jsx)(d.Ay,{}),(0,ee.jsxs)(l.BV,{children:[(0,ee.jsx)(l.qh,{path:Fs,element:(0,ee.jsx)(jr,{})}),(0,ee.jsx)(l.qh,{path:Os,element:(0,ee.jsx)(qt,{})}),(0,ee.jsx)(l.qh,{path:Ds,element:(0,ee.jsx)(tt,{})}),(0,ee.jsx)(l.qh,{path:"/",element:(0,ee.jsx)(ee.Fragment,{children:(0,ee.jsx)($t,{children:(0,ee.jsx)(vr,{})})})}),(0,ee.jsx)(l.qh,{path:Us,element:(0,ee.jsx)($t,{children:(0,ee.jsx)(Lr,{})})}),(0,ee.jsx)(l.qh,{path:`${Ls}/*`,element:(0,ee.jsx)(Tt,{role:"admin",children:(0,ee.jsx)(Mn,{})})}),(0,ee.jsx)(l.qh,{path:$s,element:(0,ee.jsx)(Tt,{role:"user",children:(0,ee.jsx)(vr,{})})}),(0,ee.jsx)(l.qh,{path:Ts,element:(0,ee.jsx)(Tt,{role:"delivery_agent",children:(0,ee.jsx)(Gn,{})})}),(0,ee.jsx)(l.qh,{path:zs,element:(0,ee.jsx)(Tt,{role:"user",children:(0,ee.jsx)(or,{})})}),(0,ee.jsx)(l.qh,{path:Ws,element:(0,ee.jsx)(Tt,{children:(0,ee.jsx)(xr,{})})}),(0,ee.jsx)(l.qh,{path:qs,element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(er,{})})}),(0,ee.jsx)(l.qh,{path:`${qs}/orders`,element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(Br,{})})}),(0,ee.jsx)(l.qh,{path:"/store_manager/delivery-partners",element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(Mr,{})})}),(0,ee.jsx)(l.qh,{path:"/store_manager/inventory",element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(Kr,{})})}),(0,ee.jsx)(l.qh,{path:"/store_manager/delivery-fees",element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(pr,{})})}),(0,ee.jsx)(l.qh,{path:"/store_manager/location-codes",element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(Qr,{})})}),(0,ee.jsx)(l.qh,{path:"/store_manager/pickup-addresses",element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(Zr,{})})}),(0,ee.jsx)(l.qh,{path:"/store_manager/payment-settings",element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(gr,{})})}),(0,ee.jsx)(l.qh,{path:`${qs}/*`,element:(0,ee.jsx)(Tt,{role:"store_manager",children:(0,ee.jsx)(mr,{})})}),(0,ee.jsx)(l.qh,{path:"*",element:(0,ee.jsx)(ur,{})})]})]})};var ei=t(85072),si=t.n(ei),ti=t(97825),ni=t.n(ti),ri=t(77659),ii=t.n(ri),ai=t(55056),oi=t.n(ai),di=t(10540),li=t.n(di),ci=t(41113),xi=t.n(ci),ui=t(14767),mi={};mi.styleTagTransform=xi(),mi.setAttributes=oi(),mi.insert=ii().bind(null,"head"),mi.domAPI=ni(),mi.insertStyleElement=li();si()(ui.A,mi);ui.A&&ui.A.locals&&ui.A.locals;const hi=window.location.href?.includes("http://localhost");let pi="us-east-1_6NtAulnkj",Ai="1361ghg1fpt2grmchv7ttf8bbj";hi&&(pi="us-east-1_ehhI7OmUk",Ai="1okaltgd288h6sjgc5cedlth45");const gi={Auth:{Cognito:{region:"us-east-1",userPoolId:pi,userPoolClientId:Ai,loginWith:{email:!0},signUpVerificationMethod:"code",userAttributes:{email:{required:!0}},allowGuestAccess:!0,passwordFormat:{minLength:8,requireLowercase:!0,requireUppercase:!0,requireNumbers:!0,requireSpecialCharacters:!0}}}};t(9023).E.configure(gi);const ji=new i.E({defaultOptions:{queries:{retry:3,refetchOnWindowFocus:!1},mutations:{retry:0}}});(0,n.createRoot)(document.getElementById("root")).render((0,ee.jsx)(a.Ht,{client:ji,children:(0,ee.jsx)(r.Kd,{children:(0,ee.jsx)(Xr,{})})}))},14767:(e,s,t)=>{t.d(s,{A:()=>o});var n=t(71354),r=t.n(n),i=t(76314),a=t.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 s=a[e];if(void 0!==s)return s.exports;var t=a[e]={id:e,exports:{}};return i[e].call(t.exports,t,t.exports,o),t.exports}o.m=i,e=[],o.O=(s,t,n,r)=>{if(!t){var i=1/0;for(c=0;c=r)&&Object.keys(o.O).every((e=>o.O[e](t[d])))?t.splice(d--,1):(a=!1,r0&&e[c-1][2]>r;c--)e[c]=e[c-1];e[c]=[t,n,r]},o.n=e=>{var s=e&&e.__esModule?()=>e.default:()=>e;return o.d(s,{a:s}),s},t=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={};s=s||[null,t({}),t([]),t(t)];for(var a=2&n&&e;"object"==typeof a&&!~s.indexOf(a);a=t(a))Object.getOwnPropertyNames(a).forEach((s=>i[s]=()=>e[s]));return i.default=()=>e,o.d(r,i),r},o.d=(e,s)=>{for(var t in s)o.o(s,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:s[t]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce(((s,t)=>(o.f[t](e,s),s)),[])),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,s)=>Object.prototype.hasOwnProperty.call(e,s),n={},r="indimitra-web:",o.l=(e,s,t,i)=>{if(n[e])n[e].push(s);else{var a,d;if(void 0!==t)for(var l=document.getElementsByTagName("script"),c=0;c{a.onerror=a.onload=null,clearTimeout(m);var r=n[e];if(delete n[e],a.parentNode&&a.parentNode.removeChild(a),r&&r.forEach((e=>e(t))),s)return s(t)},m=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),d&&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=(s,t)=>{var n=o.o(e,s)?e[s]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(((t,r)=>n=e[s]=[t,r]));t.push(n[2]=r);var i=o.p+o.u(s),a=new Error;o.l(i,(t=>{if(o.o(e,s)&&(0!==(n=e[s])&&(e[s]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;a.message="Loading chunk "+s+" failed.\n("+r+": "+i+")",a.name="ChunkLoadError",a.type=r,a.request=i,n[1](a)}}),"chunk-"+s,s)}},o.O.j=s=>0===e[s];var s=(s,t)=>{var n,r,[i,a,d]=t,l=0;if(i.some((s=>0!==e[s]))){for(n in a)o.o(a,n)&&(o.m[n]=a[n]);if(d)var c=d(o)}for(s&&s(t);lo(25710)));d=o.O(d)})(); //# sourceMappingURL=bundle.faf0bb3e036219522810.js.map