(()=>{"use strict";var e,s,t,n,r,i={91298:(e,s,t)=>{var n=t(5338),r=t(84976),i=t(15072),a=t(97665),o=t(65793),l=t(14519),d=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);let I="https://indimitra.com/graphql";const S=window.location.href?.includes("http://localhost");S&&(I="http://127.0.0.1:8000/graphql");const C=new b.l4(I,{headers:{"Content-Type":"application/json"}}),w=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 C.request(e,s,{...C.requestConfig.headers,...t})},P={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."},k=e=>{if(e.response?.errors){return e.response.errors.map((e=>{if(e.extensions?.code){const s=e.extensions.code;if(P[s])return P[s]}return e.message?.includes("Pickup address ID is required for pickup orders")?"Please select a valid address to deliver.":e.message?.includes("validation")?P.VALIDATION_ERROR:e.message?.includes("not found")?"The requested item was not found.":e.message?.includes("permission")?P.FORBIDDEN:e.message?.includes("already exists")?"This item already exists.":e.message||P.GENERIC_ERROR})).join(". ")}if(e.message?.includes("Network request failed"))return P.NETWORK_ERROR;if(e.message?.includes("timeout"))return P.TIMEOUT_ERROR;if(e.response?.status)switch(e.response.status){case 401:return P.UNAUTHENTICATED;case 403:return P.FORBIDDEN;case 404:return"The requested resource was not found.";case 500:return P.INTERNAL_SERVER_ERROR;case 503:return P.SERVICE_UNAVAILABLE;default:return`Server error (${e.response.status}). Please try again.`}return e.message||P.GENERIC_ERROR},E=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{const t=await w(e,s);if(t.errors){const e=k({response:t});throw new Error(e)}return t}catch(e){const s=k(e),t=new Error(s);throw t.originalError=e,t.isGraphQLError=!0,t}},F="query getAllUsers {\n getAllUsers {\n id\n email\n type\n cognitoId\n }\n}",D="\n mutation UpdateOrderStatus($input: UpdateOrderStatusInput!) {\n updateOrderStatus(input: $input) {\n id\n status\n deliveryDate\n deliveryInstructions\n }\n }\n",L="\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",$="\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",T="\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",q="\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",R="\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",z="\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",W="\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",O="\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",U="\n mutation DeleteSavedCart($userId: Int!, $storeId: Int!) {\n deleteSavedCart(userId: $userId, storeId: $storeId)\n }\n";var N=t(71511),B=t(87134),M=t(18496);const _="admin",V="user",H="delivery_agent",G="store_manager",K="orders",Y="userStatus",Q=e=>(0,M.ms)((s=>{e=e?.toLowerCase().trim(),e===_&&(s("view",_),s("view",Y)),e===V&&(s("view",V),s("view",K),s("view","cart")),e===H&&s("view",H),e===G&&(s("view",G),s("manage","inventory"))})),J=(0,N.v)((0,B.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};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})},getSelectedStore:()=>s().selectedStore,pickupAddress:null,setPickupAddress:s=>e({pickupAddress: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,l=i*o/100,d=e.tipAmount||0;return{subtotal:i,deliveryFee:a,taxAmount:l,taxPercentage:o,tipAmount:d,total:i+a+l+d}},setTipAmount: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}}})),{name:"indimitra-cart-storage",storage:(0,B.KU)((()=>localStorage)),partialize:e=>({cart:e.cart,customOrder:e.customOrder,listInputAnswers:e.listInputAnswers,deliveryType:e.deliveryType,tipAmount:e.tipAmount,pickupAddress:e.pickupAddress})})),Z=(0,N.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:Q(null)})},fetchUserProfile:async s=>{if(s){e({isProfileLoading:!0});try{const t=await E(L,{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:Q(n.role)})}catch(s){e({isProfileLoading:!1})}}},isProfileLoaded:()=>!!s().userProfile}))),X=(0,N.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 E("\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 E("\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 E("\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 E("\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}}))),ee=J;var se=t(74848);const te=e=>(0,se.jsx)(g.A,{...e});var ne=t(86990);const re=e=>(0,se.jsx)(ne.A,{...e}),ie=e=>(0,se.jsx)(p.A,{...e}),ae=e=>(0,se.jsx)(m.A,{...e});var oe=t(89502);const le=e=>(0,se.jsx)(oe.A,{...e});var de=t(60538);const ce=e=>(0,se.jsx)(de.A,{...e}),xe=e=>{let{size:s=40,thickness:t=3.6,sx:n={}}=e;return(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",...n},children:(0,se.jsx)(j.A,{size:s,thickness:t})})};var ue=t(50790),me=t(29898);const he=e=>{let{fields:s,onSubmit:t,buttonLabel:n,loading:r,error:i,success:a}=e;const o=e=>{switch(e){case"email":return(0,se.jsx)(ue.A,{sx:{color:"#FF6B6B"}});case"password":return(0,se.jsx)(me.A,{sx:{color:"#FF6B6B"}});default:return null}};return(0,se.jsxs)("form",{onSubmit:t,children:[s.map(((e,s)=>(0,se.jsx)(ie,{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,se.jsx)(A.A,{position:"start",children:o(e.type)})}},s))),i&&(0,se.jsx)(le,{severity:"error",sx:{mt:2},children:i}),a&&(0,se.jsx)(le,{severity:"success",sx:{mt:2},children:a}),(0,se.jsx)(re,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:r,sx:{mt:2},children:r?(0,se.jsx)(xe,{size:24,sx:{color:"#fff"}}):n})]})},pe=e=>(0,se.jsx)(h.A,{...e});var Ae=t(11641);const ge=e=>(0,se.jsx)(Ae.A,{...e});var je=t(73896);const ye=e=>(0,se.jsx)(je.A,{...e});var fe=t(8239),be=t(14977),ve=t(87393),Ie=t(37636),Se=t(56826),Ce=t(47839),we=t(1649),Pe=t(99682),ke=t(11235);const Ee={"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 Fe=t(44675),De=t(82022);const Le=e=>{let{categoryName:s}=e;return s?(0,se.jsx)(De.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},$e="grey",Te=e=>{let{product:s}=e;(0,Fe.A)();const{cart:t,addToCart:n,removeFromCart:r}=ee(),{id:i,name:a,price:o,description:l,image:d,categoryName:c,isAvailable:x}=s,u=t[i]?.quantity||0,h=d||(c?(e=>{if(e&&Ee[e.toLowerCase()]){const s=Ee[e.toLowerCase()];return s[Math.floor(Math.random()*s.length)]}return Ee.default})(c):"https://picsum.photos/200");return(0,se.jsxs)(be.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,se.jsx)(Le,{categoryName:c}),(0,se.jsx)(ve.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,se.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,se.jsx)(m.A,{variant:"body1",children:"Sold out"})}),(0,se.jsxs)(Ie.A,{sx:{flexGrow:1,p:2.5,pb:0,display:"flex",flexDirection:"column"},children:[(0,se.jsx)(m.A,{gutterBottom:!0,variant:"h6",sx:{fontWeight:600,fontSize:"1.1rem",mb:1,lineHeight:1.3},children:a}),l&&(0,se.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:l}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:"auto",mb:2},children:[(0,se.jsxs)(m.A,{variant:"h6",sx:{fontWeight:700,color:"primary.main",fontSize:"1.2rem"},children:["$",o.toFixed(2)]}),void 0!==s.quantity&&(0,se.jsxs)(m.A,{variant:"body2",color:"text.secondary",sx:{ml:2,fontWeight:500},children:["Qty: ",s.quantity]})]})]}),(0,se.jsx)(Se.A,{sx:{justifyContent:"center",pb:2.5,px:2.5},children:u>0?(0,se.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,se.jsx)(Ce.A,{title:"Remove from cart",children:(0,se.jsx)(Ae.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,se.jsx)(we.A,{fontSize:"small"})})}),(0,se.jsx)(m.A,{variant:"body1",sx:{color:"#FF6B6B",fontWeight:700,mx:2,minWidth:"24px",textAlign:"center",fontSize:"1.1rem"},children:u}),(0,se.jsx)(Ce.A,{title:"Add to cart",children:(0,se.jsx)(Ae.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,se.jsx)(Pe.A,{fontSize:"small"})})})]}):(0,se.jsx)(ne.A,{size:"medium",sx:{width:"100%",height:"48px",background:"transparent",color:x?"#FF6B6B":$e,borderRadius:"8px",fontWeight:600,fontSize:"0.95rem",textTransform:"none",position:"relative",overflow:"hidden",border:`2px solid ${x?"#FF6B6B":$e}`,transition:"all 0.2s ease","&:hover":{background:"transparent","& .MuiButton-startIcon":{transform:"translateX(2px)"}},"& .MuiButton-startIcon":{transition:"transform 0.2s ease",marginRight:"8px"}},startIcon:(0,se.jsx)(ke.A,{sx:{fontSize:"1.1rem"}}),onClick:()=>n(s),disabled:!x,children:x?"Add to Cart":"Unavailable"})})]})},qe=e=>{let{products:s,title:t}=e;return 0===s.length?(0,se.jsx)(g.A,{sx:{py:8,textAlign:"center"},children:(0,se.jsx)(m.A,{variant:"h6",color:"text.secondary",children:"No products available."})}):(0,se.jsxs)(h.A,{maxWidth:"xl",children:[t&&(0,se.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,se.jsx)(fe.Ay,{container:!0,spacing:3,children:s.map((e=>(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,se.jsx)(Te,{product:e})},e.id)))})]})};var Re=t(58031),ze=t(46831),We=t(22477),Oe=t(58763),Ue=t(39781);const Ne=e=>{let{open:s,onClose:t,children:n,title:r,footer:i,...a}=e;const o=(0,Fe.A)();return(0,se.jsxs)(Re.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,se.jsxs)(ze.A,{sx:{textAlign:"center",background:o.palette.custom.gradientPrimary,color:"white",py:2,position:"relative",flexShrink:0},children:[r,(0,se.jsx)(Ae.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,se.jsx)(Ue.A,{})})]}),(0,se.jsx)(We.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,se.jsx)(Oe.A,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",flexShrink:0},children:i})]})};var Be=t(8532);const Me=e=>(0,se.jsx)(Be.A,{...e,sx:{minHeight:{xs:"64px",sm:"70px"},px:{xs:2,sm:4},...e.sx}}),_e=e=>(0,se.jsx)(Ce.A,{...e,sx:{"& .MuiTooltip-tooltip":{backgroundColor:"rgba(42, 47, 79, 0.9)",fontSize:"0.875rem",borderRadius:"8px",padding:"8px 16px"},...e.sx}});var Ve=t(30781);const He=e=>(0,se.jsx)(Ve.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 Ge=t(97190);const Ke=e=>(0,se.jsx)(Ge.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 Ye=t(54937);const Qe=e=>{let{error:s,title:t="Error",severity:n="error"}=e;return(0,se.jsx)(g.A,{sx:{p:2},children:(0,se.jsxs)(oe.A,{severity:n,children:[(0,se.jsx)(Ye.A,{sx:{fontWeight:"bold"},children:t}),s]})})};var Je=t(99631),Ze=t(82935),Xe=t(83574);const es=e=>{let{images:s=[]}=e;const[t,n]=(0,x.useState)(0),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)("next"),[l,d]=(0,x.useState)(!1),c=(0,x.useRef)(null);if(!s||0===s.length)return(0,se.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,se.jsx)(Je.A,{sx:{fontSize:40,color:"rgba(0,0,0,0.2)",mb:.5}}),(0,se.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"),d(!0),setTimeout((()=>{n((e=>e===s.length-1?0:e+1)),d(!1)}),300)}),4e3))}),[s.length]);(0,x.useEffect)((()=>(r?c.current&&clearInterval(c.current):u(),()=>{c.current&&clearInterval(c.current)})),[r,u]);return(0,se.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,se.jsxs)(g.A,{sx:{width:"100%",height:"100%",position:"relative"},children:[(0,se.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:l?0:1,transform:l?`translateX(${"next"===a?"30px":"-30px"})`:"translateX(0)"},onError:e=>{e.target.style.display="none"}}),s.length>1&&(0,se.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,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Ae.A,{className:"slider-arrow",onClick:()=>{o("prev"),d(!0),setTimeout((()=>{n((e=>0===e?s.length-1:e-1)),d(!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,se.jsx)(Ze.A,{fontSize:"small"})}),(0,se.jsx)(Ae.A,{className:"slider-arrow",onClick:()=>{o("next"),d(!0),setTimeout((()=>{n((e=>e===s.length-1?0:e+1)),d(!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,se.jsx)(Xe.A,{fontSize:"small"})})]}),s.length>1&&(0,se.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,se.jsx)(g.A,{onClick:()=>(e=>{e!==t&&(o(e>t?"next":"prev"),d(!0),setTimeout((()=>{n(e),d(!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 ss=t(30995),ts=t(71543),ns=t(50215),rs=t(17809),is=t(75813),as=t(90509),os=t(68806),ls=t(30425),ds=t(21357),cs=t(57097);const xs=e=>{let{open:s,onClose:t,cartTotal:n,orderItems:r,deliveryType:i,selectedAddressId:a,selectedPickupId:o,userProfile:l,selectedStore:d,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)(3),[S,C]=(0,x.useState)(null),w=A?.isSquareConnected&&A?.squareApplicationId&&A?.squareLocationId,{mutate:P,isPending:k,isSuccess:F}=(0,cs.n)({mutationFn:async e=>await E("\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=>{C(e.createOrderWithPayment),b(null)},onError:e=>{b(e.message||"Payment failed. Please try again.")}});(0,x.useEffect)((()=>{if(F&&v>0){const e=setTimeout((()=>{I(v-1)}),1e3);return()=>clearTimeout(e)}F&&0===v&&(t(),p&&p(S))}),[F,v,t,p,S]);const D=r.reduce(((e,s)=>e+s.quantity),0);return(0,se.jsxs)(Re.A,{open:s,onClose:k||F?void 0:t,disableEscapeKeyDown:k||F,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.1)"}},children:[(0,se.jsxs)(ze.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,se.jsx)(ns.A,{sx:{mr:1,verticalAlign:"middle"}}),"Complete Payment",!k&&!F&&(0,se.jsx)(Ae.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,se.jsx)(rs.A,{})})]}),(0,se.jsx)(We.A,{children:F?(0,se.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",py:4,gap:2},children:[(0,se.jsx)(is.A,{sx:{fontSize:80,color:"success.main"}}),(0,se.jsx)(m.A,{variant:"h5",fontWeight:"bold",color:"success.main",children:"Payment Successful!"}),S&&(0,se.jsxs)(m.A,{variant:"body1",color:"text.secondary",children:["Order #",S.displayCode]}),(0,se.jsxs)(m.A,{variant:"body2",color:"text.secondary",children:["Redirecting in ",v," seconds..."]})]}):(0,se.jsxs)(se.Fragment,{children:[(0,se.jsxs)(g.A,{sx:{mb:3,p:2,bgcolor:"grey.50",borderRadius:1},children:[(0,se.jsxs)(m.A,{variant:"body2",color:"text.secondary",children:[D," ",1===D?"item":"items"," • ","delivery"===i?"Delivery":"Pickup"]}),(0,se.jsxs)(m.A,{variant:"h5",fontWeight:"bold",sx:{mt:1},children:["$",n.toFixed(2)]})]}),f&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:f}),w?(0,se.jsx)(as.A,{applicationId:A?.squareApplicationId,locationId:A?.squareLocationId,cardTokenizeResponseReceived:async(e,s)=>{b(null);const t=r.map((e=>({productId:e.productId,quantity:e.quantity})));P({userId:l.id,storeId:d.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})},createPaymentRequest:()=>({countryCode:"US",currencyCode:"USD",total:{amount:n.toFixed(2),label:"Total"}}),children:(0,se.jsxs)(ss.A,{spacing:2,children:[(0,se.jsxs)(g.A,{children:[(0,se.jsx)(os.A,{}),(0,se.jsx)(g.A,{sx:{mt:1},children:(0,se.jsx)(ls.A,{})})]}),(0,se.jsx)(ts.A,{sx:{my:2},children:(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"OR"})}),(0,se.jsx)(ds.A,{}),k&&(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:2,py:2},children:[(0,se.jsx)(j.A,{size:24}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Processing payment..."})]})]})}):(0,se.jsxs)(ss.A,{spacing:2,children:[(0,se.jsxs)(oe.A,{severity:"info",sx:{mb:2},children:[(0,se.jsx)("strong",{children:"Preview Mode:"})," Square credentials not configured. This is a UI preview only.",(0,se.jsx)("br",{}),(0,se.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,se.jsxs)(g.A,{children:[(0,se.jsxs)(ne.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,se.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,se.jsxs)(ne.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,se.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",style:{marginRight:8},children:(0,se.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,se.jsx)(ts.A,{sx:{my:2},children:(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"OR"})}),(0,se.jsxs)(g.A,{sx:{border:"1px solid",borderColor:"grey.300",borderRadius:1,p:2},children:[(0,se.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"Card Number"}),(0,se.jsx)(g.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1,mb:2},children:(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"•••• •••• •••• ••••"})}),(0,se.jsxs)(g.A,{sx:{display:"flex",gap:2},children:[(0,se.jsxs)(g.A,{sx:{flex:1},children:[(0,se.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"Expiration"}),(0,se.jsx)(g.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1},children:(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"MM/YY"})})]}),(0,se.jsxs)(g.A,{sx:{flex:1},children:[(0,se.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"CVV"}),(0,se.jsx)(g.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1},children:(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"•••"})})]})]}),(0,se.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mt:2,display:"block"},children:"Postal Code"}),(0,se.jsx)(g.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1,mt:1},children:(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"12345"})})]}),(0,se.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{textAlign:"center",fontStyle:"italic"},children:"Payment form will be interactive once Square credentials are configured"})]})]})}),!F&&!k&&(0,se.jsx)(Oe.A,{sx:{px:3,pb:2},children:(0,se.jsx)(ne.A,{onClick:t,color:"inherit",children:"Cancel"})})]})};var us=t(50779),ms=t(69307),hs=t(29428),ps=t(68864),As=t(53215),gs=t(7578),js=t(89388);const ys=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,se.jsxs)(us.A,{component:"fieldset",fullWidth:!0,sx:{mb:3},children:[(0,se.jsx)(ms.A,{component:"legend",sx:{mb:2,fontWeight:500},children:"Select Payment Method"}),(0,se.jsxs)(hs.A,{value:t||"",onChange:e=>n(e.target.value),children:[r&&(0,se.jsx)(ps.A,{value:"square",control:(0,se.jsx)(As.A,{color:"primary"}),label:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(gs.A,{color:"primary"}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"body1",sx:{fontWeight:600},children:"Pay with Card"}),(0,se.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,se.jsx)(ps.A,{value:"cod",control:(0,se.jsx)(As.A,{color:"primary"}),label:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(js.A,{color:"primary"}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"body1",sx:{fontWeight:600},children:"Cash on Delivery"}),(0,se.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,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:"Store payment system unavailable. Please contact store or try again later."})},fs={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 bs=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(0),[r,i]=(0,x.useState)(12),{selectedStore:a}=ee(),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:l,isLoading:d,error:c}=(0,u.I)({queryKey:["storeInventory",a?.id],queryFn:async()=>await E("\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)((()=>l?.getInventoryByStore?.map((e=>{const s=a?.id,t=e.productId,n=fs[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}}))||[]),[l,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,se.jsxs)(m.A,{children:["Error fetching products: ",c.message]}):(0,se.jsxs)(h.A,{children:[(0,se.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,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(f.A,{})})}}),d?(0,se.jsx)(g.A,{display:"flex",justifyContent:"center",my:4,children:(0,se.jsx)(j.A,{})}):0===b.length?(0,se.jsx)(m.A,{variant:"h6",align:"center",sx:{mt:4},children:"No products available in this store."}):(0,se.jsx)(qe,{products:I}),(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,se.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 vs=t(49799),Is=t(44090),Ss=t(57873),Cs=t(82241),ws=t(58620),Ps=t(87980),ks=t(78325),Es=t(54415),Fs=t(84201),Ds=t(15327);const Ls="/login",$s="/forgot-password",Ts="/admin",qs="/user",Rs="/delivery_agent",zs="/store_manager",Ws="/store_manager/orders",Os="/orders",Us="/profile",Ns="/signup",Bs="/cart";var Ms=t(28939),_s=t(48393),Vs=t(80437),Hs=t(58438),Gs=t(62594);const Ks=e=>{let{email:s,onComplete:t,onSuccess:n}=e;const r=(0,d.Zp)(),[i,a]=(0,x.useState)(""),[o,l]=(0,x.useState)(!1),[c,u]=(0,x.useState)(""),[h,A]=(0,x.useState)("");return(0,se.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),l(!0),u(""),A("");try{await(0,Gs.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{l(!1)}},children:[(0,se.jsx)(m.A,{variant:"h4",component:"h1",gutterBottom:!0,children:"Verify OTP"}),(0,se.jsx)(p.A,{label:"Enter OTP",variant:"outlined",fullWidth:!0,margin:"normal",value:i,onChange:e=>a(e.target.value),required:!0}),c&&(0,se.jsx)(oe.A,{severity:"error",sx:{mt:2},children:c}),h&&(0,se.jsx)(oe.A,{severity:"success",sx:{mt:2},children:h}),(0,se.jsx)(ne.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,se.jsx)(j.A,{size:24,sx:{color:"#fff"}}):"Verify OTP"})]})};var Ys=t(5673),Qs=t(76768);const Js=e=>{let{onSuccess:s,onError:t}=e;const n=(0,d.Zp)(),{setUser:r,setAbility:i,setModalOpen:a}=Z(),[o,l]=(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,se.jsx)(g.A,{children:b?(0,se.jsx)(Ks,{email:o,onSuccess:()=>n("/"),onComplete:()=>v(!1)}):(0,se.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),h(!0),f("");try{const e=await(0,_s.J)({username:o,password:c});if("CONFIRM_SIGN_UP"===e.nextStep?.signInStep)return await(0,Vs.h)({username:o}),void v(!0);const t=await(0,Hs.T)(),l=t["custom:role"].toLowerCase();r({email:t.email,role:l});const d=Q(l);i(d),a(!1),s?s():n(`/${l}`)}catch(e){if(e.message.includes("User is not confirmed"))try{await(0,Vs.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,se.jsx)(p.A,{label:"Email",variant:"outlined",fullWidth:!0,value:o,onChange:e=>l(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(ue.A,{sx:{color:"#FF6B6B"}})})}}),(0,se.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,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(me.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,se.jsx)(A.A,{position:"end",children:(0,se.jsx)(Ae.A,{onClick:()=>S((e=>!e)),edge:"end",children:I?(0,se.jsx)(Qs.A,{}):(0,se.jsx)(Ys.A,{})})})}}),y&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:y}),(0,se.jsx)(ne.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:m,sx:{py:1.2,borderRadius:"8px",textTransform:"none",fontSize:"1rem"},children:m?(0,se.jsx)(j.A,{size:24,sx:{color:"#fff"}}):"Login"})]})})};var Zs=t(83728),Xs=t(71432),et=t(19873);const st=e=>{let{referredBy:s="",onSuccess:t}=e;const[n,r]=(0,x.useState)(""),[i,a]=(0,x.useState)(""),[o,l]=(0,x.useState)(""),[d,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,se.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),f(!0),v(""),S("");try{await(0,Zs.H)({username:n,password:d,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,Vs.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,se.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,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(Xs.A,{sx:{color:"#FF6B6B"}})})}}),(0,se.jsx)(p.A,{label:"Last Name",variant:"outlined",fullWidth:!0,value:o,onChange:e=>l(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(Xs.A,{sx:{color:"#FF6B6B"}})})}}),(0,se.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,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(ue.A,{sx:{color:"#FF6B6B"}})})}}),(0,se.jsx)(p.A,{label:"Password",variant:"outlined",type:C?"text":"password",fullWidth:!0,value:d,onChange:e=>c(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(me.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,se.jsx)(A.A,{position:"end",children:(0,se.jsx)(Ae.A,{onClick:()=>w((e=>!e)),edge:"end",children:C?(0,se.jsx)(Qs.A,{}):(0,se.jsx)(Ys.A,{})})})}}),(0,se.jsxs)(g.A,{sx:{display:"flex",gap:1,mb:2},children:[(0,se.jsx)(p.A,{label:"Country Code",variant:"outlined",value:"+1",disabled:!0,sx:{width:"120px"},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(et.A,{sx:{color:"#FF6B6B"}})})}}),(0,se.jsx)(p.A,{label:"Phone Number",variant:"outlined",fullWidth:!0,value:u,onChange:e=>m(e.target.value),required:!0,InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(et.A,{sx:{color:"#FF6B6B"}})})}})]}),(0,se.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,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(ue.A,{sx:{color:"#FF6B6B"}})})}}),b&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:b}),I&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:I}),(0,se.jsx)(ne.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:y,sx:{mt:1,mb:2},children:y?"Processing...":"Sign Up"})]})};var tt=t(15061),nt=t(7888);const rt=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(!1),[l,c]=(0,x.useState)(""),[u,m]=(0,x.useState)(""),[h,p]=(0,x.useState)(1),A=(0,d.Zp)();return(0,se.jsx)(te,{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,se.jsxs)(ce,{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,se.jsxs)(te,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,se.jsx)(ae,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:1===h?"Forgot Password":"Reset Password"}),(0,se.jsx)(ae,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:1===h?"Enter your email address to receive a reset code":"Enter the OTP sent to your email and your new password"})]}),1===h?(0,se.jsx)(he,{fields:[{label:"Email",type:"email",value:e,onChange:s}],onSubmit:async s=>{s.preventDefault(),o(!0),c(""),m("");try{await(0,tt.x)({username:e}),p(2),m("OTP sent successfully! Check your email.")}catch(e){c(e.message||"Failed to send OTP. Try again.")}finally{o(!1)}},buttonLabel:"Send OTP",loading:a,error:l,success:u}):(0,se.jsx)(he,{fields:[{label:"OTP",type:"text",value:t,onChange:n},{label:"New Password",type:"password",value:r,onChange:i}],onSubmit:async s=>{s.preventDefault(),o(!0),c(""),m("");try{await(0,nt.P)({username:e,confirmationCode:t,newPassword:r}),m("Password reset successfully! Redirecting to login..."),setTimeout((()=>A("/")),2e3)}catch(e){c(e.message||"Failed to reset password. Try again.")}finally{o(!1)}},buttonLabel:"Reset Password",loading:a,error:l,success:u})]})})},it=e=>{let{open:s,onClose:t,initialForm:n="login"}=e;const[r,i]=(0,x.useState)(n),[a,o]=(0,x.useState)(""),[l,d]=(0,x.useState)(!1),c=(0,Fe.A)(),u=e=>{i(e),d(!1)};return(0,se.jsx)(Ms.A,{open:s,onClose:t,"aria-labelledby":"modal-modal-title","aria-describedby":"modal-modal-description",sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:(0,se.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,se.jsx)(ne.A,{onClick:t,sx:{position:"absolute",top:8,right:8,minWidth:0,p:.5},children:(0,se.jsx)(Ue.A,{})}),(0,se.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:3},children:[(0,se.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,se.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":""})]}),l&&"login"===r&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:"Email verified successfully! Please login to continue."}),"login"===r?(0,se.jsx)(Js,{onSuccess:t}):"signup"===r?(0,se.jsx)(st,{onSuccess:e=>{o(e),i("otp")}}):"otp"===r?(0,se.jsx)(Ks,{email:a,onSuccess:()=>{d(!0),i("login")}}):(0,se.jsx)(rt,{}),(0,se.jsxs)(g.A,{sx:{mt:3,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:["login"===r&&(0,se.jsx)(ne.A,{onClick:()=>u("forgotPassword"),sx:{color:c.palette.primary.main,textTransform:"none"},children:"Forgot Password?"}),"otp"!==r&&(0,se.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,se.jsx)(ne.A,{color:"primary",onClick:()=>u("login"===r?"signup":"login"),sx:{textTransform:"none"},children:"login"===r?"Sign Up":"Login"})]})]})]})})};var at=t(17532),ot=t(10423),lt=t(10420),dt=t(74202),ct=t(92659),xt=t(37856),ut=t(2223),mt=t(42702),ht=t(28800),pt=t(58407),At=t(37211),gt=t(81385),jt=t(10364),yt=t(2882),ft=t(85873);const bt=e=>{let{store:s,isSelected:t,onSelect:n}=e;const r=s.isActive;return(0,se.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,se.jsx)(Is.Ay,{disablePadding:!0,children:(0,se.jsx)(At.A,{onClick:()=>r&&n(s),selected:t,disabled:!r,sx:{p:0,cursor:r?"pointer":"not-allowed"},children:(0,se.jsx)(g.A,{sx:{width:"100%"},children:(0,se.jsxs)(g.A,{sx:{p:2,backgroundColor:t?"rgba(0, 0, 0, 0.02)":"transparent"},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"flex-start",mb:1},children:[(0,se.jsx)(gt.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,se.jsx)(lt.A,{}):(0,se.jsx)(ft.A,{})}),(0,se.jsxs)(g.A,{sx:{flex:1},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[(0,se.jsx)(m.A,{fontWeight:600,fontSize:"1.1rem",color:"text.primary",children:s.name}),!r&&(0,se.jsx)(De.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,se.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,se.jsx)(yt.A,{sx:{fontSize:"0.9rem",color:r?"text.secondary":"error.main",mr:.5,mt:.2}}),(0,se.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,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,se.jsx)(ut.A,{sx:{fontSize:"0.9rem",color:"text.secondary",mr:.5}}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:s.address})]})]})]}),(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:1},children:[s.radius&&(0,se.jsx)(De.A,{icon:(0,se.jsx)(jt.A,{fontSize:"small"}),label:`${s.radius} mi radius`,size:"small",variant:"outlined",color:t?"primary":"default",sx:{opacity:r?1:.7}}),!r&&(0,se.jsx)(m.A,{variant:"caption",sx:{ml:"auto",color:"error.main",fontStyle:"italic"},children:"Store is currently offline"})]})]})})})})})},vt=e=>{let{availableStores:s,selectedStore:t,handleStoreSelect:n}=e;return(0,se.jsx)(vs.A,{sx:{mt:1},children:s.map((e=>(0,se.jsx)(bt,{store:e,isSelected:t?.id===e.id,onSelect:n},e.id)))})};var It=t(1984);const St=()=>(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:1},children:[(0,se.jsx)(It.A,{}),(0,se.jsx)(m.A,{variant:"h5",fontWeight:600,children:"Select a Store"})]}),Ct=()=>(0,se.jsx)(de.A,{elevation:0,sx:{p:3,textAlign:"center",backgroundColor:"rgba(33, 150, 243, 0.1)",borderRadius:2},children:(0,se.jsx)(m.A,{sx:{fontWeight:500,color:"info.main"},children:"No stores available at the moment."})}),wt=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),[l,d]=(0,x.useState)(!1),[c,u]=(0,x.useState)(null);(0,x.useEffect)((()=>{const e=setTimeout((()=>{try{if("undefined"!=typeof window&&window.google&&window.google.maps&&window.google.maps.places&&i.current){d(!0);const e=i.current;if(!e)return void d(!1);const 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 d(!1),s&&s.trim().length>10?(o(!0),n(!0)):(o(!1),n(!1))}catch(e){d(!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)):!l&&s.trim().length>10&&(o(!0),n(!0))}),[s,n,l]);return(0,se.jsx)(p.A,{inputRef:i,label:"Address",fullWidth:!0,multiline:!0,rows:3,value:s,error:!a&&""!==s,helperText:l?a||""===s?l&&!c?"Start typing to see address suggestions...":"":"Please select a valid address from the suggestions above.":"Enter your complete address (street, city, state, zip code)",onChange:e=>{const s=e.target.value;t(s),l&&c&&s!==c.formatted_address?(o(!1),n(!1),u(null)):l||(s.trim().length>10?(o(!0),n(!0)):(o(!1),n(!1)))},placeholder:l?"Start typing to see address suggestions...":"Enter your complete address (e.g., 123 Main St, City, State 12345)"})},Pt=e=>{let{size:s=24,sx:t}=e;return(0,se.jsx)(j.A,{size:s,sx:{color:"inherit",...t}})},kt=e=>{let{open:s,onClose:t,forceStep:n,initialStore:r}=e;const{selectedStore:i,setSelectedStore:o,availableStores:l,setPickupAddress:d,deliveryType:c,setDeliveryType:u}=ee(),{user:h,userProfile:p,fetchUserProfile:A,isProfileLoading:j,setModalOpen:y,setCurrentForm:f}=Z(),b=(0,a.jE)(),{addresses:I,selectedAddressId:S,setSelectedAddressId:C,fetchAddresses:w,isLoading:P,createAddress:k}=X(),[E,F]=(0,x.useState)("store"),[D,L]=(0,x.useState)(null),[$,T]=(0,x.useState)(null),[q,R]=(0,x.useState)(null),[z,W]=(0,x.useState)(""),[O,U]=(0,x.useState)(!1),[N,B]=(0,x.useState)(""),[M,_]=(0,x.useState)(!1),[V,H]=(0,x.useState)(!1),[G,K]=(0,x.useState)(!1),[Y,Q]=(0,x.useState)(""),[J,te]=(0,x.useState)(0),[re,ie]=(0,x.useState)([]),[ae,le]=(0,x.useState)(""),[ce,xe]=(0,x.useState)(null),ue=p?I:re,me=p?S:ae;(0,x.useEffect)((()=>{const e=!!p;!1===ce&&!0===e&&(ie([]),le(""),p?.id&&"pickup"===E&&D&&w(p.id),R(null),W("")),!0===ce&&!1===e&&C(null),xe(e)}),[p,E,D,w,C,ce]),(0,x.useEffect)((()=>{"pickup"===E&&D&&p?.id&&w(p.id)}),[E,D,p?.id,w]),(0,x.useEffect)((()=>{if(!("pickup"===E&&(1===J||!D?.pickupAddresses?.edges?.length))||p)return;let e=!1;return(async()=>{try{const s=await(0,v.$)(),t=s?.tokens?.idToken?.payload?.sub;t&&!e&&await A(t)}catch{}})(),()=>{e=!0}}),[E,J,p,h,A,D]),(0,x.useEffect)((()=>{s&&n&&(F(n),r&&L(r)),s||(F("store"),L(null),he())}),[s,n,r]);const he=()=>{p?C(null):le(""),B(""),_(!1),H(!1),K(!1),R(null),W(""),T(null),te(0),Q("")},pe=async()=>{U(!0);try{const e=await(0,v.$)(),s=e?.tokens?.idToken?.payload?.sub;if(s){if(p||await A(s),p?.id||s){const e=p?.id;e&&(await w(e),ie([]),le(""))}}else C(null);R(null),W("")}catch(e){}finally{U(!1)}},ge=()=>{y(!0),f("login")},je=async()=>{if(N.trim()&&G)if(ye(N),Q(N),u("delivery"),T(null),p?C(null):le(""),p?.id){if(!I.some((e=>e.address.toLowerCase().trim()===N.toLowerCase().trim()))){H(!0);try{await k(N,p.id,M);const e=(await w(p.id)).find((e=>e.address.toLowerCase().trim()===N.toLowerCase().trim()));e&&C(e.id),b.invalidateQueries(["userAddresses",p.id])}catch(e){}finally{H(!1)}}}else{if(!re.some((e=>e.address.toLowerCase().trim()===N.toLowerCase().trim()))){const e={id:`temp_${Date.now()}`,address:N,isPrimary:0===re.length};ie((s=>[...s,e])),le(e.id)}}},ye=e=>{if(!e||!D)return R(null),void W("");const s=e.match(/\b(\d{5})(?:-\d{4})?\b/g),t=s?s[s.length-1]:null,n=(D?.pincodes||[]).map((e=>String(e).trim())),r=t?String(t).trim():"";r&&n.includes(r)?(R("success"),W("Store delivers here")):(R("error"),W("Store does not deliver here."))},fe=e=>{localStorage.setItem("selectedStoreId",String(e.id)),L(e),F("pickup")},be=()=>{if(!D||!$)return;const e=(D.pickupAddresses?.edges?.map((e=>e.node))||[]).find((e=>String(e.id)===String($)));o(D),d(e),u("pickup"),F("store"),L(null),T(null),he(),t()},ve=()=>{"success"===q&&Y&&(o(D),d(null),u("delivery"),setTimeout((()=>{F("store"),L(null),he(),t()}),1200))},Ie=()=>{F("store"),L(null),he()};if("store"===E)return(0,se.jsx)(Ne,{open:s,onClose:t,title:(0,se.jsx)(St,{}),children:0===l.length?(0,se.jsx)(Ct,{}):(0,se.jsxs)(se.Fragment,{children:[(0,se.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,se.jsx)(vt,{availableStores:l,selectedStore:i,handleStoreSelect:fe})]})});if("pickup"===E){const e=D?.pickupAddresses?.edges?.map((e=>e.node))||[],n=e.length>0,r=(0,se.jsx)(ne.A,{onClick:Ie,variant:"text",color:"inherit",size:"small",startIcon:(0,se.jsx)(ct.A,{}),sx:{fontWeight:500},children:"Back to stores"});return(0,se.jsxs)(Ne,{open:s,onClose:t,title:(0,se.jsx)(St,{}),footer:r,children:[(0,se.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,se.jsx)("b",{children:D?.name})]}),(0,se.jsx)(g.A,{sx:{borderBottom:1,borderColor:"divider",mb:2},children:n?(0,se.jsxs)(at.A,{value:J,onChange:(e,s)=>te(s),variant:"fullWidth",sx:{minHeight:42,"& .MuiTabs-indicator":{height:3,borderRadius:"3px 3px 0 0"}},children:[(0,se.jsx)(ot.A,{icon:(0,se.jsx)(lt.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Pickup",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:42,py:0}}),(0,se.jsx)(ot.A,{icon:(0,se.jsx)(dt.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Delivery",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:42,py:0}})]}):(0,se.jsx)(at.A,{value:0,variant:"fullWidth",sx:{minHeight:42,"& .MuiTabs-indicator":{height:3,borderRadius:"3px 3px 0 0"}},children:(0,se.jsx)(ot.A,{icon:(0,se.jsx)(dt.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Delivery",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:42,py:0}})})}),n&&0===J&&(0,se.jsxs)(ss.A,{spacing:2,children:[e.map((e=>(0,se.jsxs)(de.A,{elevation:0,onClick:()=>{return s={target:{value:String(e.id)}},T(s.target.value),u("pickup"),p?C(null):le(""),R(null),void W("");var s},sx:{p:2,cursor:"pointer",border:"1.5px solid",borderColor:String($)===String(e.id)?"primary.main":"grey.200",borderRadius:2,bgcolor:String($)===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,se.jsx)(As.A,{checked:String($)===String(e.id),value:String(e.id),color:"primary",size:"small",sx:{p:0}}),(0,se.jsx)(m.A,{variant:"body2",children:e.address})]},e.id))),(0,se.jsx)(ne.A,{onClick:be,variant:"contained",color:"primary",fullWidth:!0,startIcon:(0,se.jsx)(xt.A,{}),disabled:!$,sx:{mt:1,fontWeight:600,py:1.2,fontSize:"0.95rem",borderRadius:2},children:"Confirm Pickup"})]}),(!n||1===J)&&(0,se.jsxs)(ss.A,{spacing:2,children:[(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:-1},children:"Enter your delivery address to check availability"}),(0,se.jsx)(wt,{value:N,onChange:e=>{B(e),Y&&(R(null),W(""),Q(""))},onValidAddress:K}),(0,se.jsx)(ne.A,{variant:"contained",size:"small",onClick:je,disabled:!N.trim()||!G||V,startIcon:V?(0,se.jsx)(Pt,{size:18}):(0,se.jsx)(ut.A,{}),sx:{borderRadius:1.5},children:V?"Validating...":"Validate & Use This Address"}),q&&(0,se.jsx)(oe.A,{severity:q,sx:{borderRadius:1.5},icon:"success"===q?(0,se.jsx)(pt.A,{}):void 0,children:z}),p?(0,se.jsx)(se.Fragment,{children:ue.length>0&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(ts.A,{sx:{my:1},children:(0,se.jsx)(De.A,{label:"Your Saved Addresses",size:"small",variant:"outlined"})}),(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"flex-end"},children:(0,se.jsx)(Ce.A,{title:"Refresh addresses",children:(0,se.jsx)(Ae.A,{size:"small",onClick:pe,disabled:O,sx:{border:"1px solid",borderColor:"divider",width:28,height:28},children:O?(0,se.jsx)(Pt,{size:14}):(0,se.jsx)(mt.A,{sx:{fontSize:16}})})})}),P||O?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,se.jsx)(Pt,{size:24})}):(0,se.jsx)(ss.A,{spacing:1.5,children:ue.map((e=>(0,se.jsxs)(de.A,{elevation:0,onClick:()=>(e=>{p?C(e.id):le(e.id),Q(e.address),B(""),K(!1),ye(e.address),u("delivery"),T(null)})(e),sx:{p:1.5,cursor:"pointer",border:"1.5px solid",borderColor:me===e.id?"secondary.main":"grey.200",borderRadius:2,bgcolor:me===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,se.jsx)(As.A,{checked:me===e.id,color:"secondary",size:"small",sx:{p:0}}),(0,se.jsxs)(g.A,{sx:{flex:1,minWidth:0},children:[(0,se.jsx)(m.A,{variant:"body2",noWrap:!0,children:e.address}),e.isPrimary&&(0,se.jsx)(De.A,{label:"Primary",size:"small",color:"secondary",variant:"outlined",sx:{mt:.5,height:20,fontSize:"0.7rem"}})]})]},e.id)))})]})}):(0,se.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,se.jsx)(ht.A,{sx:{fontSize:32,color:"text.disabled",mb:1}}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:"Sign in to use your saved addresses"}),(0,se.jsx)(ne.A,{variant:"outlined",size:"small",startIcon:(0,se.jsx)(ht.A,{}),onClick:ge,sx:{borderRadius:1.5},children:"Login"})]}),(0,se.jsx)(ne.A,{onClick:ve,variant:"contained",color:"secondary",fullWidth:!0,startIcon:(0,se.jsx)(dt.A,{}),disabled:"success"!==q||!Y,sx:{fontWeight:600,py:1.2,fontSize:"0.95rem",borderRadius:2},children:"Confirm Delivery"})]})]})}return null};var Et=t(62274);const Ft=e=>{let{navigate:s,userRole:t}=e;const{setUser:n}=Z();return(0,se.jsx)(ae,{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"})},Dt=()=>{const e=(0,d.Zp)(),[s,t]=(0,x.useState)(null),n=(0,Ds.A)("(max-width: 600px)"),r=ee((e=>e.cartCount())),{user:i,ability:a,logout:o}=Z(),[l,c]=x.useState(null),{modalOpen:u,setModalOpen:m,currentForm:h,setCurrentForm:p}=Z(),[A,g]=(0,x.useState)(null),[j,y]=(0,x.useState)(!1),[f,b]=(0,x.useState)(!1);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,v.$)(),s=await(0,Hs.T)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;g(s)}const n=s["custom:role"]?.toLowerCase();t(n)}catch(e){g(null),t(null)}})()}),[i]);const I=()=>{m(!0),p("login")},S=async()=>{try{await(0,Fs.C)(),o(),g(null),t(null),e("/")}catch(e){}},C=()=>c(null),w=Q(i?.role||"user");(0,x.useEffect)((()=>{!n&&f&&b(!1)}),[n,f]);const P=(0,se.jsxs)(te,{sx:{width:270,height:"100%",bgcolor:"background.paper",boxShadow:3,display:"flex",flexDirection:"column"},role:"presentation",onClick:()=>b(!1),children:[(0,se.jsx)(te,{sx:{display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"#fff",px:2,py:2.5,minHeight:64,boxShadow:1},children:(0,se.jsx)(ae,{variant:"h6",sx:{fontWeight:800,letterSpacing:1,fontSize:"1.35rem",color:"#fff",textAlign:"center"},children:"Menu"})}),(0,se.jsx)(ts.A,{}),(0,se.jsxs)(vs.A,{sx:{flex:1,py:1},children:[!A&&(0,se.jsxs)(Is.Ay,{button:!0,onClick:I,sx:{py:2},children:[(0,se.jsx)(Ss.A,{sx:{color:"primary.main",minWidth:40},children:(0,se.jsx)(Ps.A,{})}),(0,se.jsx)(Cs.A,{primary:(0,se.jsx)(ae,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Sign In"})})]}),(0,se.jsxs)(Is.Ay,{button:!0,onClick:()=>y(!0),sx:{py:2},children:[(0,se.jsx)(Ss.A,{sx:{color:"primary.main",minWidth:40},children:(0,se.jsx)(ks.A,{})}),(0,se.jsx)(Cs.A,{primary:(0,se.jsx)(ae,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Change Store"})})]}),(0,se.jsxs)(Is.Ay,{button:!0,onClick:()=>e(Bs),sx:{py:2},children:[(0,se.jsx)(Ss.A,{sx:{color:"primary.main",minWidth:40},children:(0,se.jsx)(ke.A,{})}),(0,se.jsx)(Cs.A,{primary:(0,se.jsx)(ae,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Cart"})})]}),A&&w?.can("view","orders")&&(0,se.jsxs)(Is.Ay,{button:!0,onClick:()=>e(Os),sx:{py:2},children:[(0,se.jsx)(Ss.A,{sx:{color:"primary.main",minWidth:40},children:(0,se.jsx)(Es.A,{})}),(0,se.jsx)(Cs.A,{primary:(0,se.jsx)(ae,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Orders"})})]}),A&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(ts.A,{sx:{my:1.5}}),(0,se.jsxs)(Is.Ay,{button:!0,onClick:()=>{e(Us)},sx:{py:2},children:[(0,se.jsx)(Ss.A,{sx:{color:"primary.main",minWidth:40},children:(0,se.jsx)(Ps.A,{})}),(0,se.jsx)(Cs.A,{primary:(0,se.jsx)(ae,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Profile"})})]}),(0,se.jsxs)(Is.Ay,{button:!0,onClick:S,sx:{py:2},children:[(0,se.jsx)(Ss.A,{sx:{color:"error.main",minWidth:40},children:(0,se.jsx)(Ps.A,{})}),(0,se.jsx)(Cs.A,{primary:(0,se.jsx)(ae,{sx:{fontWeight:600,fontSize:"1.1rem",color:"error.main"},children:"Logout"})})]})]})]}),(0,se.jsx)(ts.A,{}),(0,se.jsxs)(te,{sx:{p:2,textAlign:"center",color:"text.secondary",fontSize:"0.95rem"},children:["© ",(new Date).getFullYear()," Indimitra"]})]});return(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(te,{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,se.jsxs)(Me,{sx:{minHeight:{xs:"56px",sm:"64px",md:"70px"},px:{xs:1,sm:2,md:4}},children:[(0,se.jsx)(Ft,{navigate:e,userRole:i?.role}),(0,se.jsx)(te,{sx:{flexGrow:1}}),n?(0,se.jsx)(ge,{edge:"end",color:"inherit","aria-label":"menu",onClick:()=>b(!0),sx:{ml:1},children:(0,se.jsx)(Et.A,{})}):(0,se.jsxs)(te,{sx:{display:"flex",alignItems:"center",gap:{xs:.5,sm:1,md:2},flexDirection:{xs:"row",sm:"row"},position:"relative"},children:[!A&&(0,se.jsx)(re,{onClick:I,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&&A&&w&&w.can("view","orders")&&(0,se.jsx)(re,{onClick:()=>e(Os),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"}),(0,se.jsx)(re,{variant:"outlined",startIcon:(0,se.jsx)(ks.A,{sx:{fontSize:{xs:18,sm:22}}}),onClick:()=>y(!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:"Change Store"}),i?w?.can("view","cart")&&(0,se.jsx)(_e,{title:"Cart",children:(0,se.jsx)(ge,{onClick:()=>e(Bs),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,se.jsx)(He,{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,se.jsx)(ke.A,{sx:{fontSize:{xs:20,sm:24}}})})})}):(0,se.jsx)(_e,{title:"Cart",children:(0,se.jsx)(ge,{onClick:()=>e(Bs),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,se.jsx)(He,{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,se.jsx)(ke.A,{sx:{fontSize:{xs:20,sm:24}}})})})}),A&&(0,se.jsx)(_e,{title:"Profile",children:(0,se.jsx)(ge,{onClick:e=>c(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,se.jsx)(Ps.A,{sx:{fontSize:{xs:20,sm:24}}})})})]})]})}),(0,se.jsx)(ws.Ay,{anchor:"right",open:f,onClose:()=>b(!1),children:P}),(0,se.jsxs)(Ke,{anchorEl:l,open:Boolean(l),onClose:C,PaperProps:{elevation:3,sx:{mt:2,minWidth:"200px",borderRadius:"12px",overflow:"hidden"}},children:[n&&w?.can("view","orders")&&(0,se.jsx)(ye,{onClick:()=>{e(Os),C()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,se.jsx)(ae,{variant:"body1",children:"Orders"})}),(0,se.jsx)(ye,{onClick:()=>{e(Us),C()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,se.jsx)(ae,{variant:"body1",children:"Profile"})}),(0,se.jsx)(ye,{onClick:()=>{S(),C()},sx:{py:1.5,px:3,color:"#FF5757","&:hover":{backgroundColor:"rgba(255, 87, 87, 0.1)"}},children:(0,se.jsx)(ae,{variant:"body1",children:"Logout"})})]}),(0,se.jsx)(kt,{open:j,onClose:()=>y(!1)}),(0,se.jsx)(te,{sx:{height:{xs:"56px",sm:"64px",md:"70px"}}}),(0,se.jsx)(it,{open:u,onClose:()=>m(!1),currentForm:h,setCurrentForm:p})]})};var Lt=t(87992),$t=t(61451);const Tt=()=>{const e=ee((e=>e.selectedStore));return(0,se.jsx)(Lt.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,se.jsx)($t.A,{sx:{fontSize:32}})})},qt=e=>{let{children:s}=e;return(0,se.jsxs)(te,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[(0,se.jsx)(Dt,{}),s,(0,se.jsx)(Tt,{})]})},Rt=e=>{let{children:s,role:t}=e;const{user:n,setUser:r,ability:i,setAbility:a}=Z(),[o,l]=(0,x.useState)(!0),[c,u]=(0,x.useState)(!1),[m,h]=(0,x.useState)(null),p=(0,d.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=Q(s);a(t),h(t),u(!0)}else u(!1)}catch(e){u(!1)}finally{l(!1)}})()}),[n,r,a]),o)return(0,se.jsx)(xe,{});if(!c)return(0,se.jsx)(d.C5,{to:"/",replace:!0});if(p.pathname===Us)return(0,se.jsx)(qt,{children:s});const A=(Array.isArray(t)?t:[t]).map((e=>e.toLowerCase()));return m&&A.some((e=>m.can("view",e)))?(0,se.jsx)(qt,{children:s}):(0,se.jsx)(d.C5,{to:"/not-authorized",replace:!0})},zt=()=>{const[e,s]=(0,x.useState)(!1),[t,n]=(0,x.useState)(""),[i]=(0,r.ok)(),a=i.get("referredby")||"";return(0,se.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,se.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,se.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,se.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,se.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,se.jsx)(g.A,{sx:{minHeight:300},children:e?(0,se.jsx)(Ks,{email:t,onComplete:()=>s(!1)}):(0,se.jsx)(st,{referredBy:a,onOtpStep:e=>{n(e),s(!0)}})})]})})};var Wt=t(31117),Ot=t(69377),Ut=t(85685),Nt=t(69634),Bt=t(47027),Mt=t(94654),_t=t(17451);const Vt=e=>{let{title:s,value:t,icon:n,color:r}=e;const i=(0,Fe.A)(),a=(0,Ds.A)(i.breakpoints.down("sm"));return(0,se.jsx)(be.A,{sx:{height:"100%"},children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,se.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,se.jsx)(m.A,{variant:"h6",color:"text.secondary",children:s})]}),(0,se.jsx)(m.A,{variant:a?"h5":"h4",component:"div",sx:{fontWeight:"bold"},children:t})]})})},Ht=()=>{const e=(0,Fe.A)(),s=(0,Ds.A)(e.breakpoints.down("sm")),{data:t,isLoading:n,error:r}=(0,u.I)({queryKey:["dashboardStats"],queryFn:async()=>await E("\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 E("\n query GetOrderStats {\n getOrderStats {\n totalOrders\n recentOrders\n ordersByStatus\n ordersByType\n }\n }\n")}),{data:l,isLoading:d,error:c}=(0,u.I)({queryKey:["stores"],queryFn:async()=>await E(R)}),{data:x,isLoading:h,error:p}=(0,u.I)({queryKey:["allStoresSquareStatus"],queryFn:async()=>await E("\n query AllStoresSquareStatus {\n allStoresSquareStatus {\n storeId\n storeName\n isConnected\n }\n }\n")}),A=t?.getDashboardStats||{},y=i?.getOrderStats||{},f=l?.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,k=f.filter((e=>e.codEnabled)).length;if(n||a||d||h)return(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:(0,se.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,se.jsx)(g.A,{sx:{p:s?2:3},children:(0,se.jsx)(Qe,{error:e,title:"Dashboard Error",severity:"error"})})}return(0,se.jsxs)(g.A,{sx:{p:s?2:3},children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,sx:{mb:4},children:"Dashboard Overview"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Total Users",value:v.toLocaleString(),icon:(0,se.jsx)(Nt.A,{}),color:e.palette.primary.main})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Total Stores",value:I.toLocaleString(),icon:(0,se.jsx)(It.A,{}),color:e.palette.success.main})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Square Connected",value:`${w} / ${P}`,icon:(0,se.jsx)(ns.A,{}),color:e.palette.success.main})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Cash on Delivery",value:`${k} / ${I}`,icon:(0,se.jsx)(ns.A,{}),color:e.palette.info.main})})]}),(0,se.jsx)(g.A,{sx:{mt:4},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Active Drivers",value:S.toLocaleString(),icon:(0,se.jsx)(js.A,{}),color:e.palette.info.main})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Total Orders",value:C.toLocaleString(),icon:(0,se.jsx)(ke.A,{}),color:e.palette.warning.main})})]})}),(0,se.jsxs)(g.A,{sx:{mt:4},children:[(0,se.jsx)(m.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"Detailed Statistics"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Active Users",value:(A.activeUsers||0).toLocaleString(),icon:(0,se.jsx)(Nt.A,{}),color:e.palette.success.main})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Recent Orders (30 days)",value:(y.recentOrders||0).toLocaleString(),icon:(0,se.jsx)(ke.A,{}),color:e.palette.info.main})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Delivery Orders",value:(y.ordersByType?.DELIVERY||0).toLocaleString(),icon:(0,se.jsx)(js.A,{}),color:e.palette.secondary.main})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(Vt,{title:"Pickup Orders",value:(y.ordersByType?.PICKUP||0).toLocaleString(),icon:(0,se.jsx)(It.A,{}),color:e.palette.warning.main})})]})]}),A.usersByType&&Object.keys(A.usersByType).length>0&&(0,se.jsxs)(g.A,{sx:{mt:4},children:[(0,se.jsx)(m.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"User Type Breakdown"}),(0,se.jsx)(fe.Ay,{container:!0,spacing:2,children:Object.entries(A.usersByType).map((e=>{let[s,t]=e;return(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,se.jsx)(be.A,{sx:{height:"100%"},children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()}),(0,se.jsx)(m.A,{variant:"h4",component:"div",sx:{fontWeight:"bold"},children:t.toLocaleString()})]})})},s)}))})]})]})};var Gt=t(33198),Kt=t(64137),Yt=t(96627),Qt=t(86798),Jt=t(14774),Zt=t(43884),Xt=t(29571),en=t(65460),sn=t(95557),tn=t(72297),nn=t(68125);const rn=()=>{const e=(0,Fe.A)(),s=(0,Ds.A)(e.breakpoints.down("sm")),[t,n]=(0,x.useState)(0),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(0),[l,d]=(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)(""),[k,D]=(0,x.useState)({open:!1,message:"",severity:"success"}),[L,$]=(0,x.useState)(null),[T,q]=(0,x.useState)(!1),[R,W]=(0,x.useState)(""),[O,U]=(0,x.useState)([]),{data:N,isLoading:B,error:M,refetch:_}=(0,u.I)({queryKey:["users"],queryFn:async()=>{const e=await E(F);return e?.getAllUsers||[]},enabled:!0}),{data:V,isLoading:H,error:G,refetch:K}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{try{const e=await E(z);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,cs.n)({mutationFn:e=>E("\n mutation UpdateUserType($requesterId: String!, $targetUserId: String!, $newType: String!) {\n updateUserType(requesterId: $requesterId, targetUserId: $targetUserId, newType: $newType) {\n user {\n id\n email\n type\n }\n error {\n message\n }\n }\n }\n",e),onSuccess:(e,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,cs.n)({mutationFn:e=>E("\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({...k,open:!1})},ee=()=>{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},te=()=>R&&Array.isArray(O)?O.find((e=>e.id===parseInt(R))):null;return(0,se.jsxs)(g.A,{sx:{p:s?2:3},children:[(0,se.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,se.jsx)(m.A,{variant:"h5",gutterBottom:!0,children:"User Management"}),(0,se.jsxs)(at.A,{value:t,onChange:(e,s)=>{n(s),o(0)},sx:{mb:3},variant:s?"fullWidth":"standard",children:[(0,se.jsx)(ot.A,{label:"All"}),(0,se.jsx)(ot.A,{label:"Users"}),(0,se.jsx)(ot.A,{label:"Delivery Partners"}),(0,se.jsx)(ot.A,{label:"Store Managers"})]}),(0,se.jsx)(g.A,{sx:{mb:3,display:"flex",gap:2,flexWrap:"wrap"},children:(0,se.jsx)(p.A,{size:"small",placeholder:"Search...",value:r,onChange:e=>{i(e.target.value),o(0)},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(nn.A,{})})},sx:{flexGrow:1,minWidth:200}})}),M&&(0,se.jsxs)(oe.A,{severity:"error",sx:{mb:3},children:["Error loading users: ",M.message]}),B?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,se.jsx)(j.A,{})}):(0,se.jsxs)(se.Fragment,{children:[0===t&&(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"ID"}),(0,se.jsx)(Jt.A,{children:"Email"}),(0,se.jsx)(Jt.A,{children:"Mobile"}),(0,se.jsx)(Jt.A,{children:"Type"}),(0,se.jsx)(Jt.A,{children:"Status"}),(0,se.jsx)(Jt.A,{children:"Referral ID"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:ee().slice(a*l,a*l+l).map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.id}),(0,se.jsx)(Jt.A,{children:e.email}),(0,se.jsx)(Jt.A,{children:e.mobile||"N/A"}),(0,se.jsx)(Jt.A,{children:e.type}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,se.jsx)(Jt.A,{children:e.referralId||"N/A"}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{size:"small",color:"primary",onClick:()=>J(e),children:(0,se.jsx)(tn.A,{})}),"DELIVERY"===e.type&&(0,se.jsx)(Ae.A,{size:"small",color:"secondary",onClick:()=>Z(e),title:"Assign to Store",children:(0,se.jsx)(js.A,{})})]})]},e.id)))})]})}),1===t&&(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"ID"}),(0,se.jsx)(Jt.A,{children:"Email"}),(0,se.jsx)(Jt.A,{children:"Mobile"}),(0,se.jsx)(Jt.A,{children:"Status"}),(0,se.jsx)(Jt.A,{children:"Referral ID"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:ee().slice(a*l,a*l+l).map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.id}),(0,se.jsx)(Jt.A,{children:e.email}),(0,se.jsx)(Jt.A,{children:e.mobile||"N/A"}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,se.jsx)(Jt.A,{children:e.referralId||"N/A"}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(Ae.A,{size:"small",color:"primary",onClick:()=>J(e),children:(0,se.jsx)(tn.A,{})})})]},e.id)))})]})}),2===t&&(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"ID"}),(0,se.jsx)(Jt.A,{children:"Email"}),(0,se.jsx)(Jt.A,{children:"Mobile"}),(0,se.jsx)(Jt.A,{children:"Status"}),(0,se.jsx)(Jt.A,{children:"Referral ID"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:ee().slice(a*l,a*l+l).map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.id}),(0,se.jsx)(Jt.A,{children:e.email}),(0,se.jsx)(Jt.A,{children:e.mobile||"N/A"}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,se.jsx)(Jt.A,{children:e.referralId||"N/A"}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{size:"small",color:"primary",onClick:()=>J(e),children:(0,se.jsx)(tn.A,{})}),(0,se.jsx)(Ae.A,{size:"small",color:"secondary",onClick:()=>Z(e),title:"Assign to Store",children:(0,se.jsx)(js.A,{})})]})]},e.id)))})]})}),3===t&&(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"ID"}),(0,se.jsx)(Jt.A,{children:"Email"}),(0,se.jsx)(Jt.A,{children:"Mobile"}),(0,se.jsx)(Jt.A,{children:"Status"}),(0,se.jsx)(Jt.A,{children:"Referral ID"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:ee().slice(a*l,a*l+l).map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.id}),(0,se.jsx)(Jt.A,{children:e.email}),(0,se.jsx)(Jt.A,{children:e.mobile||"N/A"}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,se.jsx)(Jt.A,{children:e.referralId||"N/A"}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(Ae.A,{size:"small",color:"primary",onClick:()=>J(e),children:(0,se.jsx)(tn.A,{})})})]},e.id)))})]})}),(0,se.jsx)(y.A,{component:"div",count:ee().length,page:a,onPageChange:(e,s)=>{o(s)},rowsPerPage:l,onRowsPerPageChange:e=>{d(parseInt(e.target.value,10)),o(0)},sx:{mt:2}})]})]}),(0,se.jsxs)(Re.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,se.jsx)(ze.A,{sx:{pb:1},children:"Update User Role"}),(0,se.jsx)(We.A,{children:v&&(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsxs)(m.A,{variant:"subtitle1",gutterBottom:!0,children:["User: ",v.email]}),(0,se.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",v.id]}),(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mt:2},children:[(0,se.jsx)(Xt.A,{children:"Role"}),(0,se.jsxs)(en.A,{value:w,onChange:e=>{P(e.target.value)},label:"Role",sx:{mb:2},children:[(0,se.jsx)(je.A,{value:"USER",children:"User"}),(0,se.jsx)(je.A,{value:"ADMIN",children:"Admin"}),(0,se.jsx)(je.A,{value:"DELIVERY",children:"Delivery Partner"}),(0,se.jsx)(je.A,{value:"STORE_MANAGER",children:"Store Manager"})]})]})]})}),(0,se.jsxs)(Oe.A,{sx:{px:3,py:2},children:[(0,se.jsx)(ne.A,{onClick:()=>C(!1),children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{if(!L)return void D({open:!0,message:"Admin ID not available. Please try again.",severity:"error"});Y.mutate({requesterId:L,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,se.jsxs)(Re.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,se.jsx)(ze.A,{sx:{pb:1},children:"Assign Driver to Store"}),(0,se.jsx)(We.A,{children:v&&(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsxs)(m.A,{variant:"subtitle1",gutterBottom:!0,children:["Driver: ",v.email]}),(0,se.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",v.id]}),(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,sx:{mt:2},children:"Select Store"}),H?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,se.jsx)(j.A,{size:24})}):G?(0,se.jsxs)(oe.A,{severity:"error",sx:{mb:2},children:["Error loading stores: ",G.message]}):Array.isArray(O)&&0!==O.length?(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mt:1},children:[(0,se.jsx)(Xt.A,{children:"Store"}),(0,se.jsx)(en.A,{value:R,onChange:e=>{W(e.target.value)},label:"Store",sx:{mb:2},children:O.map((e=>(0,se.jsxs)(je.A,{value:e.id,children:[e.name," - ",e.address]},e.id)))})]}):(0,se.jsx)(oe.A,{severity:"info",sx:{mb:2},children:"No stores available"}),R&&te()&&(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,children:"Current Drivers"}),te()?.drivers?.edges?.length>0?(0,se.jsx)(g.A,{sx:{mt:1},children:te().drivers.edges.map(((e,s)=>(0,se.jsx)(De.A,{label:e.node.driver.email,size:"small",sx:{mr:1,mb:1}},s)))}):(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"No drivers assigned to this store yet"})]})]})}),(0,se.jsxs)(Oe.A,{sx:{px:3,py:2},children:[(0,se.jsx)(ne.A,{onClick:()=>q(!1),children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{R&&v?Q.mutate({storeId:parseInt(R),userId:parseInt(v.id)}):D({open:!0,message:"Please select a store",severity:"error"})},variant:"contained",color:"primary",disabled:!R||Q.isPending,children:Q.isPending?"Assigning...":"Assign to Store"})]})]}),(0,se.jsx)(sn.A,{open:k.open,autoHideDuration:6e3,onClose:X,message:k.message,children:(0,se.jsx)(oe.A,{onClose:X,severity:k.severity,children:k.message})})]})};var an=t(1405),on=t(39738),ln=t(82997),dn=t(47363),cn=t(67110),xn=t(40250),un=t(70765),mn=t(34337),hn=t(72306),pn=t(79432);const An=["Store Information","Inventory","Drivers","Store Managers","Review"],gn=()=>{const[e,s]=(0,x.useState)(0),[t,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(!1),[c,h]=(0,x.useState)({}),y=(0,Fe.A)(),[f,b]=((0,Ds.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,k]=(0,x.useState)([]),[D,L]=(0,x.useState)(!1),[$,T]=(0,x.useState)({open:!1,message:"",severity:"success"}),{data:q,isLoading:R,refetch:W}=(0,u.I)({queryKey:["stores"],queryFn:()=>E(z),enabled:r}),{data:O,isLoading:U}=(0,u.I)({queryKey:["users"],queryFn:async()=>{const e=await E(F);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]),M=(0,x.useMemo)((()=>{if(!N.length)return[];return N.filter((e=>!B.includes(e.id)))}),[N,B]),_=(0,x.useMemo)((()=>{if(!N.length||!C)return M;const e=B.filter((e=>e!==C.managerUserId));return N.filter((s=>!e.includes(s.id)))}),[N,B,C,M]);(0,x.useEffect)((()=>{if(1===e&&!C){const e=M.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,M,e,C]);const V=(0,cs.n)({mutationFn:e=>E("\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:()=>{d(!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"),d(!1)}}),H=(0,cs.n)({mutationFn:e=>E("\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",l=await fetch(`${n}/s3/generate-store-upload-url?store_id=${o}&file_name=${encodeURIComponent(e.name)}`,{method:"GET",headers:a});if(!l.ok){let e="Failed to get upload URL";try{const s=await l.json();e=s.detail||s.message||e}catch(s){e=l.statusText||e}throw new Error(e)}const{upload_url:d,content_type:c,key:x}=await l.json();if(!(await fetch(d,{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?k((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]?k((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),k([])},ee=q?.stores?.filter((e=>e.name.toLowerCase().includes(t.toLowerCase())||e.address.toLowerCase().includes(t.toLowerCase())))||[];return(0,x.useEffect)((()=>{let e;return l&&(e=setTimeout((()=>{d(!1)}),5e3)),()=>{e&&clearTimeout(e)}}),[l]),(0,se.jsxs)(g.A,{children:[(0,se.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,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,se.jsx)(It.A,{sx:{mr:1}}),(0,se.jsx)(m.A,{variant:"h5",children:"Store Management"})]}),(0,se.jsxs)(at.A,{value:e,onChange:(e,t)=>{s(t)},sx:{mb:3},children:[(0,se.jsx)(ot.A,{label:"Store List"}),(0,se.jsx)(ot.A,{label:"Add New Store"})]}),a&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:3},children:a}),l&&(0,se.jsx)(oe.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,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(g.A,{sx:{mb:3},children:(0,se.jsx)(p.A,{fullWidth:!0,variant:"outlined",placeholder:"Search stores...",value:t,onChange:e=>n(e.target.value),InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(nn.A,{})})}})}),r?R?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,se.jsx)(j.A,{})}):0===ee.length?(0,se.jsx)(oe.A,{severity:"info",sx:{mb:3},children:"No stores found matching your criteria"}):(0,se.jsx)(fe.Ay,{container:!0,spacing:3,children:ee.map((e=>(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.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,se.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,se.jsxs)(fe.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,se.jsx)(It.A,{sx:{mr:2,color:"white",fontSize:"2rem"}}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{className:"store-name",variant:"h6",sx:{color:"white",fontWeight:600,transition:"color 0.3s ease-in-out"},children:e.name}),(0,se.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,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",md:"flex-end"},gap:2},children:[(0,se.jsx)(De.A,{label:e.isActive?"Active":"Inactive",color:e.isActive?"success":"error",sx:{fontWeight:600,boxShadow:2,"& .MuiChip-label":{px:1}}}),(0,se.jsx)(g.A,{className:"action-buttons",sx:{display:"flex",gap:1,opacity:.9},children:(0,se.jsx)(ne.A,{size:"small",startIcon:(0,se.jsx)(tn.A,{}),sx:{fontWeight:600,textTransform:"none",color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},onClick:()=>(e=>{w(e),k(e.images||[])})(e),children:"Edit"})})]})})]})}),(0,se.jsx)(g.A,{sx:{p:3},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(g.A,{children:[(0,se.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,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,se.jsx)(Bt.A,{sx:{mr:1.5,color:"primary.main",mt:.3,flexShrink:0,fontSize:"1.2rem"}}),(0,se.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.address})]}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,se.jsx)(un.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,se.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.mobile||"No contact info"})]}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,se.jsx)(mn.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,se.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.email||"No email info"})]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(g.A,{children:[(0,se.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,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,se.jsx)(js.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,se.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Radius: ",e.radius," mi"]})]}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,se.jsx)(hn.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,se.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Delivery Fee: $",e.storeDeliveryFee?.toFixed(2)||"0.00"]})]}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,se.jsx)(pn.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,se.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,se.jsx)(g.A,{sx:{display:"flex",flexWrap:"wrap",gap:.8},children:e.pincodes.map((e=>(0,se.jsx)(De.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,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(g.A,{children:[e.description&&(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.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,se.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.description})]}),e.tnc&&(0,se.jsxs)(g.A,{children:[(0,se.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,se.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.tnc})]})]})})]})})]})},e.id)))}):(0,se.jsxs)(be.A,{sx:{mb:3},children:[(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Stores" to load store data'}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]}),(0,se.jsx)(Se.A,{sx:{justifyContent:"center"},children:(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:(0,se.jsx)(xn.A,{}),onClick:G,children:"Fetch Stores"})})]})]}):1!==e||q?.stores||r?(0,se.jsxs)(g.A,{sx:{maxWidth:{xs:"100%",sm:600,md:800},mx:"auto",p:{xs:1,sm:2}},children:[(0,se.jsx)(g.A,{sx:{overflowX:{xs:"auto",sm:"visible"},mb:{xs:2,sm:4}},children:(0,se.jsx)(on.A,{activeStep:f,sx:{minWidth:500},children:An.map((e=>(0,se.jsx)(ln.A,{children:(0,se.jsx)(dn.A,{children:(0,se.jsx)(m.A,{sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:e})})},e)))})}),(0,se.jsx)(g.A,{sx:{px:{xs:.5,sm:0}},children:(e=>{switch(e){case 0:return(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Basic Store Information"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{required:!0,fullWidth:!0,label:"Store Name",name:"name",value:I.name,onChange:K,error:!!c.name,helperText:c.name})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{required:!0,fullWidth:!0,label:"Address",name:"address",value:I.address,onChange:K,error:!!c.address,helperText:c.address})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(us.A,{required:!0,fullWidth:!0,error:!!c.managerUserId,children:[(0,se.jsx)(Xt.A,{children:"Manager User ID"}),(0,se.jsx)(en.A,{label:"Manager User ID",name:"managerUserId",value:I.managerUserId,onChange:K,children:U?(0,se.jsx)(je.A,{value:"",disabled:!0,children:(0,se.jsx)("em",{children:"Loading..."})}):0===M.length?(0,se.jsx)(je.A,{value:"",disabled:!0,children:(0,se.jsx)("em",{children:"No available managers (all managers are assigned)"})}):M.map((e=>(0,se.jsxs)(je.A,{value:e.id,children:[e.id," - ",e.email," ",e.name?`(${e.name})`:""]},e.id)))}),(0,se.jsx)(m.A,{variant:"caption",color:"error",children:c.managerUserId}),0===M.length&&!U&&(0,se.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,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.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,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.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,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.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,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.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,se.jsx)(A.A,{position:"start",children:"$"})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.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,se.jsx)(A.A,{position:"end",children:"%"})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.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,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{fullWidth:!0,label:"Terms & Conditions",name:"tnc",value:I.tnc,onChange:K,multiline:!0,rows:3})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{fullWidth:!0,label:"Delivery Pincodes",name:"pincodes",value:I.pincodes,onChange:K,helperText:"Enter pincodes separated by commas"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.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,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,se.jsxs)(g.A,{sx:{mb:2},children:[I.sectionHeaders.map(((e,s)=>(0,se.jsxs)(g.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,se.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,se.jsx)(Ae.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,se.jsx)(cn.A,{})})]},s))),(0,se.jsx)(ne.A,{startIcon:(0,se.jsx)(Pe.A,{}),onClick:Y,variant:"outlined",sx:{mt:1},children:"Add Question"})]})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Images"}),(0,se.jsxs)(g.A,{sx:{mb:2},children:[(0,se.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,se.jsx)("label",{htmlFor:"store-image-upload",children:(0,se.jsx)(ne.A,{variant:"outlined",component:"span",startIcon:(0,se.jsx)(Pe.A,{}),disabled:D,sx:{mb:2},children:D?"Uploading...":"Upload Image"})}),I.images&&I.images.length>0&&(0,se.jsx)(g.A,{sx:{display:"flex",flexWrap:"wrap",gap:2,mt:2},children:I.images.map(((e,s)=>(0,se.jsxs)(g.A,{sx:{position:"relative",width:150,height:150},children:[(0,se.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,se.jsx)(Ae.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,se.jsx)(cn.A,{fontSize:"small"})})]},s)))})]})]}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.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,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Cash on Delivery"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Accept cash payments when orders are delivered"})]}),(0,se.jsx)(ps.A,{control:(0,se.jsx)(an.A,{checked:I.codEnabled,onChange:e=>S((s=>({...s,codEnabled:e.target.checked}))),color:"primary"}),label:I.codEnabled?"Enabled":"Disabled",labelPlacement:"start"})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.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,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Inventory Management"}),(0,se.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,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsxs)(de.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Inventory Items"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,se.jsx)(be.A,{variant:"outlined",children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",children:"Product 1"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Grocery"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $9.99"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 50"})]})})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,se.jsx)(be.A,{variant:"outlined",children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",children:"Product 2"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Electronics"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $49.99"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 25"})]})})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,se.jsx)(be.A,{variant:"outlined",children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",children:"Product 3"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Clothing"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $19.99"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 100"})]})})})]})]}),(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,se.jsx)(ne.A,{variant:"outlined",startIcon:(0,se.jsx)(Pe.A,{}),children:"Add Inventory Item"})})]})]});case 2:return(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Driver Management"}),(0,se.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,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsxs)(de.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Drivers"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,se.jsx)(be.A,{variant:"outlined",children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",children:"John Doe"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: john.doe@example.com"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 123-4567"}),(0,se.jsx)(De.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,se.jsx)(be.A,{variant:"outlined",children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",children:"Jane Smith"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: jane.smith@example.com"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 987-6543"}),(0,se.jsx)(De.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,se.jsx)(be.A,{variant:"outlined",children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",children:"Mike Johnson"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: mike.johnson@example.com"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 456-7890"}),(0,se.jsx)(De.A,{label:"Inactive",color:"error",size:"small",sx:{mt:1}})]})})})]})]}),(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,se.jsx)(ne.A,{variant:"outlined",startIcon:(0,se.jsx)(Pe.A,{}),children:"Add Driver"})})]})]});case 3:return(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Store Manager Management"}),(0,se.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,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsxs)(de.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Store Managers"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,children:(0,se.jsx)(be.A,{variant:"outlined",children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",children:"Sarah Williams"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: sarah.williams@example.com"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 234-5678"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Role: Store Manager"}),(0,se.jsx)(De.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,children:(0,se.jsx)(be.A,{variant:"outlined",children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",children:"Robert Brown"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: robert.brown@example.com"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 876-5432"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Role: Assistant Manager"}),(0,se.jsx)(De.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})})]})]}),(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,se.jsx)(ne.A,{variant:"outlined",startIcon:(0,se.jsx)(Pe.A,{}),children:"Add Store Manager"})})]})]});case 4:return(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Review Store Information"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(de.A,{variant:"outlined",sx:{p:2},children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Details"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"Name:"})," ",I.name]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"Address:"})," ",I.address]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"Manager User ID:"})," ",I.managerUserId]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"Delivery Radius:"})," ",I.radius," km"]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"Cash on Delivery:"})," ",I.codEnabled?"Enabled":"Disabled"]})}),I.whatsappNumber&&(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"WhatsApp:"})," ",I.whatsappNumber]})})]}),(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Additional Information (Placeholder)"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"Inventory Items:"})," 3 sample items"]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"Drivers:"})," 3 sample drivers"]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"body2",children:[(0,se.jsx)("strong",{children:"Store Managers:"})," 2 sample managers"]})})]})]})})]});default:return null}})(f)}),(0,se.jsxs)(g.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",mt:3,gap:2},children:[(0,se.jsx)(ne.A,{fullWidth:!0,disabled:0===f,onClick:()=>{b((e=>e-1))},sx:{py:1,fontSize:{xs:"1rem",sm:"1.05rem"}},children:"Back"}),(0,se.jsx)(ne.A,{fullWidth:!0,variant:"contained",color:"primary",onClick:f===An.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,se.jsx)(j.A,{size:24}):f===An.length-1?"Submit":"Next"})]})]}):(0,se.jsxs)(be.A,{sx:{mb:3},children:[(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:"Loading store data for manager availability check..."}),(0,se.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,se.jsx)(Se.A,{sx:{justifyContent:"center"},children:(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:(0,se.jsx)(xn.A,{}),onClick:G,children:"Load Store Data"})})]})]}),(0,se.jsxs)(Re.A,{open:!!C,onClose:X,maxWidth:"md",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(It.A,{}),(0,se.jsx)(m.A,{variant:"h6",children:"Edit Store"})]})}),(0,se.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,se.jsx)(We.A,{children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"name",label:"Store Name",defaultValue:C?.name,required:!0,fullWidth:!0})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"email",label:"Email",type:"email",defaultValue:C?.email,required:!0,fullWidth:!0})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"mobile",label:"Mobile Number",defaultValue:C?.mobile,fullWidth:!0})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(us.A,{required:!0,fullWidth:!0,children:[(0,se.jsx)(Xt.A,{children:"Manager User ID"}),(0,se.jsx)(en.A,{name:"managerUserId",label:"Manager User ID",defaultValue:C?.managerUserId,children:U?(0,se.jsx)(je.A,{value:"",disabled:!0,children:(0,se.jsx)("em",{children:"Loading..."})}):0===_.length?(0,se.jsx)(je.A,{value:"",disabled:!0,children:(0,se.jsx)("em",{children:"No available managers"})}):_.map((e=>(0,se.jsxs)(je.A,{value:e.id,children:[e.id," - ",e.email," ",e.name?`(${e.name})`:""]},e.id)))})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{name:"displayField",label:"Display Field",defaultValue:C?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.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,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Images"}),(0,se.jsxs)(g.A,{sx:{mb:2},children:[(0,se.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,se.jsx)("label",{htmlFor:"edit-store-image-upload",children:(0,se.jsx)(ne.A,{variant:"outlined",component:"span",startIcon:(0,se.jsx)(Pe.A,{}),disabled:D,sx:{mb:2},children:D?"Uploading...":"Upload Image"})}),P&&P.length>0&&(0,se.jsx)(g.A,{sx:{display:"flex",flexWrap:"wrap",gap:2,mt:2},children:P.map(((e,s)=>(0,se.jsxs)(g.A,{sx:{position:"relative",width:150,height:150},children:[(0,se.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,se.jsx)(Ae.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,se.jsx)(cn.A,{fontSize:"small"})})]},s)))})]})]}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{name:"address",label:"Address",defaultValue:C?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:C?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:C?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:"$"})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:C?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,se.jsx)(A.A,{position:"end",children:"%"})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:C?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{name:"description",label:"Description",defaultValue:C?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{name:"tnc",label:"Terms & Conditions",defaultValue:C?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"whatsappNumber",label:"WhatsApp Support Number",placeholder:"+1234567890",defaultValue:C?.whatsappNumber,fullWidth:!0,helperText:"Include country code. Optional."})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(us.A,{fullWidth:!0,children:[(0,se.jsx)(Xt.A,{children:"Store Status"}),(0,se.jsxs)(en.A,{name:"isActive",label:"Store Status",defaultValue:C?.isActive,children:[(0,se.jsx)(je.A,{value:!0,children:"Active"}),(0,se.jsx)(je.A,{value:!1,children:"Inactive"})]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(us.A,{fullWidth:!0,children:[(0,se.jsx)(Xt.A,{children:"Disabled Status"}),(0,se.jsxs)(en.A,{name:"disabled",label:"Disabled Status",defaultValue:C?.disabled,children:[(0,se.jsx)(je.A,{value:!0,children:"Disabled"}),(0,se.jsx)(je.A,{value:!1,children:"Enabled"})]})]})})]})}),(0,se.jsxs)(Oe.A,{sx:{p:3,pt:0},children:[(0,se.jsx)(ne.A,{onClick:X,children:"Cancel"}),(0,se.jsx)(ne.A,{type:"submit",variant:"contained",disabled:H.isPending,startIcon:H.isPending?(0,se.jsx)(j.A,{size:20}):null,children:H.isPending?"Updating...":"Update Store"})]})]})]}),(0,se.jsx)(sn.A,{open:$.open,autoHideDuration:6e3,onClose:()=>T({...$,open:!1}),children:(0,se.jsx)(oe.A,{onClose:()=>T({...$,open:!1}),severity:$.severity,sx:{width:"100%"},children:$.message})})]})};var jn=t(15068);const yn=()=>{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:""}),[l,d]=(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,k]=(0,x.useState)(0),[F,D]=(0,x.useState)(10),[L,$]=(0,x.useState)([]),[T,q]=(0,x.useState)(""),[R,z]=(0,x.useState)(!1),[O,U]=(0,x.useState)({open:!1,message:"",severity:"info"}),[N,B]=(0,x.useState)(""),M=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",{data:_,refetch:V}=(0,u.I)({queryKey:["products",e],queryFn:()=>E(W),enabled:!1}),{data:H,refetch:G}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await E("\n query GetCategories {\n categories {\n id\n name\n }\n }\n")).categories||[]}),K=(0,cs.n)({mutationFn:e=>E("\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:()=>{te(),X(),U({open:!0,message:"Product added successfully!",severity:"success"})}}),Y=(0,cs.n)({mutationFn:e=>{let{productId:s,name:t,description:n,categoryId:r,image:i}=e;return E("\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,cs.n)({mutationFn:e=>E("\n mutation DeleteProduct($productId: Int!) {\n deleteProduct(productId: $productId)\n }\n",{productId:e}),onSuccess:()=>{V()}}),(0,cs.n)({mutationFn:e=>E("\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:""})},ee=e=>{const{name:s,value:t}=e.target;"categoryId"!==s||"new"!==t?(o((e=>({...e,[s]:t}))),B("")):v(!0)},te=()=>{h(!0),f(null),V().then((e=>{e.data?.products&&$(e.data.products),d(!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]),ae=(0,x.useMemo)((()=>{const e=P*F;return ie.slice(e,e+F)}),[ie,P,F]),le=()=>{U((e=>({...e,open:!1})))};return(0,se.jsxs)(g.A,{children:[(0,se.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,se.jsx)(Pe.A,{sx:{mr:1}}),(0,se.jsx)(m.A,{variant:"h5",children:"Product Management"})]}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(us.A,{fullWidth:!0,children:[(0,se.jsx)(Xt.A,{children:"Category"}),(0,se.jsxs)(en.A,{value:e,onChange:e=>s(e.target.value),label:"Category",children:[(0,se.jsx)(je.A,{value:"",children:"All Categories"}),Object.entries(J).map((e=>{let[s,t]=e;return(0,se.jsx)(je.A,{value:s,children:t},s)}))]})]})}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,md:8,sx:{display:"flex",alignItems:"center",gap:2},children:[(0,se.jsx)(ne.A,{variant:"contained",startIcon:(0,se.jsx)(xn.A,{}),onClick:te,disabled:c,sx:{minWidth:150},children:c?(0,se.jsx)(j.A,{size:24}):"Fetch Products"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:(0,se.jsx)(Pe.A,{}),onClick:()=>Z(),children:"Add Product"})]})]}),A&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:3},children:A}),l?c?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,se.jsx)(j.A,{})}):(0,se.jsx)(se.Fragment,{children:(0,se.jsxs)(Gt.A,{component:de.A,children:[(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Image"}),(0,se.jsx)(Jt.A,{children:"Name"}),(0,se.jsx)(Jt.A,{children:"Category"}),(0,se.jsx)(Jt.A,{children:"Description"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:ae.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:(0,se.jsx)("img",{src:e.image,alt:e.name,style:{width:"50px",height:"50px",objectFit:"cover"}})}),(0,se.jsx)(Jt.A,{children:e.name}),(0,se.jsx)(Jt.A,{children:J[e.categoryId]||"Unknown"}),(0,se.jsx)(Jt.A,{children:e.description}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(Ae.A,{size:"small",onClick:()=>Z(e),children:(0,se.jsx)(tn.A,{})})})]},e.id)))})]}),(0,se.jsx)(y.A,{component:"div",count:ie.length,page:P,onPageChange:(e,s)=>{k(s)},rowsPerPage:F,onRowsPerPageChange:e=>{D(parseInt(e.target.value,10)),k(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,se.jsxs)(g.A,{sx:{textAlign:"center",py:4},children:[(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Products" to load product information'}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,se.jsxs)(Re.A,{open:t,onClose:X,maxWidth:"md",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:r?"Edit Product":"Add New Product"}),(0,se.jsxs)(We.A,{children:[N&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:N}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{required:!0,fullWidth:!0,label:"Product Name",name:"name",value:a.name,onChange:ee})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(us.A,{fullWidth:!0,required:!0,children:[(0,se.jsx)(Xt.A,{children:"Category"}),(0,se.jsxs)(en.A,{name:"categoryId",value:a.categoryId,onChange:ee,label:"Category",children:[(0,se.jsx)(je.A,{value:"",children:(0,se.jsx)("em",{children:"Select a category"})}),Object.entries(J).map((e=>{let[s,t]=e;return(0,se.jsx)(je.A,{value:s,children:t},s)})),(0,se.jsx)(je.A,{value:"new",sx:{borderTop:"1px solid #e0e0e0",mt:1},children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",color:"primary.main"},children:[(0,se.jsx)(Pe.A,{sx:{mr:1}}),"Add New Category"]})})]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{required:!0,fullWidth:!0,multiline:!0,rows:3,label:"Description",name:"description",value:a.description,onChange:ee})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",gap:1},children:[(0,se.jsx)(p.A,{fullWidth:!0,label:"Image URL",name:"image",value:a.image,onChange:ee,placeholder:"https://example.com/image.jpg",disabled:R,error:!!T,helperText:T}),(0,se.jsxs)(ne.A,{variant:"outlined",component:"label",startIcon:(0,se.jsx)(jn.A,{}),disabled:R||!a.name||!a.categoryId,children:[R?"Uploading...":"Upload Image",(0,se.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{z(!0),q("");const e=J[a.categoryId]||"uncategorized",t=await fetch(`${M}/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 l=`https://indimitra-dev-order-files.s3.amazonaws.com/${i}`;o((e=>({...e,image:l}))),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{z(!1)}else q("Please upload a valid image file (JPEG, PNG, GIF, or WebP)")},disabled:R})]}),a.image&&(0,se.jsx)(g.A,{sx:{mt:1},children:(0,se.jsx)("img",{src:a.image,alt:"Product preview",style:{maxWidth:"200px",maxHeight:"200px",objectFit:"contain"}})})]})})]})]}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:X,children:"Cancel"}),(0,se.jsx)(ne.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,se.jsx)(j.A,{size:20,color:"inherit"}):null,children:K.isPending||K.isLoading||Y.isPending||Y.isLoading?r?"Updating...":"Creating...":r?"Update":"Add"})]})]}),(0,se.jsxs)(Re.A,{open:b,onClose:()=>v(!1),children:[(0,se.jsx)(ze.A,{children:"Add New Category"}),(0,se.jsx)(We.A,{children:(0,se.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,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>v(!1),children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:re,variant:"contained",disabled:Q.isPending,children:Q.isPending?"Creating...":"Create"})]})]}),(0,se.jsx)(sn.A,{open:O.open,autoHideDuration:6e3,onClose:le,anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,se.jsx)(oe.A,{onClose:le,severity:O.severity,sx:{width:"100%"},children:O.message})})]})};var fn=t(8047),bn=t(89966),vn=t(52653);const In=[{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"}],Sn=("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),[l,d]=(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,k]=(0,x.useState)(""),[F,L]=(0,x.useState)(!1),[$,q]=(0,x.useState)({open:!1,message:"",severity:"info"}),[R,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:()=>E("\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:l}),{data:B}=(0,u.I)({queryKey:["storeDrivers",a?.storeId],queryFn:async()=>a?.storeId?await E(T,{storeId:a.storeId}):null,enabled:!!a?.storeId}),{data:M={stores:[]},isLoading:_}=(0,u.I)({queryKey:["stores"],queryFn:()=>E(z),enabled:l}),V=x.useMemo((()=>{const e={};return(M.stores||[]).forEach((s=>{e[s.id]=s})),e}),[M]),H=(0,cs.n)({mutationFn:async e=>await E(D,{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(""),k(""),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,se.jsx)(is.A,{});case"CANCELLED":return(0,se.jsx)(fn.A,{});case"PENDING":return(0,se.jsx)(bn.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,se.jsxs)(g.A,{children:[(0,se.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,se.jsx)(Es.A,{sx:{mr:1}}),(0,se.jsx)(m.A,{variant:"h5",children:"Orders Management"})]}),c&&R&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:3},onClose:()=>W(!1),children:c}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsx)(p.A,{fullWidth:!0,placeholder:"Search by address or order ID",name:"searchTerm",value:e,onChange:K,InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(nn.A,{})})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(us.A,{fullWidth:!0,children:[(0,se.jsx)(Xt.A,{children:"Status"}),(0,se.jsxs)(en.A,{name:"statusFilter",value:t,onChange:K,label:"Status",children:[(0,se.jsx)(je.A,{value:"",children:"All Status"}),(0,se.jsx)(je.A,{value:"PENDING",children:"Pending"}),(0,se.jsx)(je.A,{value:"ACCEPTED",children:"Accepted"}),(0,se.jsx)(je.A,{value:"READY_FOR_DELIVERY",children:"Ready for Delivery"}),(0,se.jsx)(je.A,{value:"PICKED_UP",children:"Picked Up"}),(0,se.jsx)(je.A,{value:"DELIVERED",children:"Delivered"}),(0,se.jsx)(je.A,{value:"CANCELLED",children:"Cancelled"})]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:(0,se.jsx)(xn.A,{}),onClick:()=>{d(!0),N()},fullWidth:!0,sx:{height:"56px"},children:"Fetch Orders"})})]}),l?U?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,se.jsx)(j.A,{})}):0===Z?.length?(0,se.jsx)(oe.A,{severity:"info",sx:{mb:3},children:"No orders found matching your criteria"}):(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Order ID"}),(0,se.jsx)(Jt.A,{children:"Type"}),(0,se.jsx)(Jt.A,{children:"Address"}),(0,se.jsx)(Jt.A,{children:"Store"}),(0,se.jsx)(Jt.A,{children:"Status"}),(0,se.jsx)(Jt.A,{children:"Total Amount"}),(0,se.jsx)(Jt.A,{children:"Delivery Date"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:Z.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsxs)(Jt.A,{children:["#",e.id]}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:"PICKUP"===e.type?"Pickup":"Delivery",color:"PICKUP"===e.type?"secondary":"primary",size:"small"})}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(m.A,{variant:"body2",children:"PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A"})}),(0,se.jsx)(Jt.A,{children:V[e.storeId]?.name||"N/A"}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{icon:Y(e.status),label:In.find((s=>s.value===e.status))?.label||e.status.replace(/_/g," "),color:In.find((s=>s.value===e.status))?.color||"default",size:"small"})}),(0,se.jsx)(Jt.A,{children:J(e.totalAmount)}),(0,se.jsx)(Jt.A,{children:Q(e.deliveryDate)}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{size:"small",onClick:()=>(e=>{o(e),i(!0)})(e),children:(0,se.jsx)(vn.A,{})}),(0,se.jsx)(Ae.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,se.jsx)(tn.A,{})})]})]},e.id)))})]})}):(0,se.jsx)(be.A,{sx:{mb:3},children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Orders" to load order data'}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]})})]}),(0,se.jsxs)(Re.A,{open:r,onClose:G,maxWidth:"md",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:"Order Details"}),(0,se.jsx)(We.A,{children:a&&(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsxs)(m.A,{variant:"h6",gutterBottom:!0,children:["Order #",a.id]}),(0,se.jsx)(De.A,{label:"PICKUP"===a.type?"Pickup":"Delivery",color:"PICKUP"===a.type?"secondary":"primary",sx:{mb:2}}),(0,se.jsx)(De.A,{icon:Y(a.status),label:In.find((e=>e.value===a.status))?.label||a.status.replace(/_/g," "),color:In.find((e=>e.value===a.status))?.color||"default",sx:{mb:2}})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Information"}),(0,se.jsxs)(m.A,{variant:"body2",children:["Address: ","PICKUP"===a.type?a.pickupAddress?.address:a.address?.address||"N/A"]}),(0,se.jsxs)(m.A,{variant:"body2",children:["Store: ",V[a.storeId]?.name||"N/A"," (",V[a.storeId]?.address||"",")"]}),(0,se.jsxs)(m.A,{variant:"body2",children:["Total Amount: ",J(a.totalAmount)]}),(0,se.jsxs)(m.A,{variant:"body2",children:["Delivery Date: ",Q(a.deliveryDate)]}),a.deliveryInstructions&&(0,se.jsxs)(m.A,{variant:"body2",children:["Delivery Instructions: ",a.deliveryInstructions]})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Items"}),(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{size:"small",children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Product"}),(0,se.jsx)(Jt.A,{children:"Quantity"}),(0,se.jsx)(Jt.A,{children:"Amount"})]})}),(0,se.jsx)(Zt.A,{children:a.orderItems?.edges?.map((e=>{let{node:s}=e;return(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:s.product?.name||"N/A"}),(0,se.jsx)(Jt.A,{children:s.quantity}),(0,se.jsx)(Jt.A,{children:J(s.orderAmount)})]},s.id)}))})]})})]})]})}),(0,se.jsx)(Oe.A,{children:(0,se.jsx)(ne.A,{onClick:G,children:"Close"})})]}),(0,se.jsxs)(Re.A,{open:y,onClose:()=>f(!1),maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:"Update Order Status"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{select:!0,fullWidth:!0,label:"Status",value:b,onChange:e=>v(e.target.value),children:In.map((e=>(0,se.jsx)(je.A,{value:e.value,children:e.label},e.value)))})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.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,se.jsxs)(se.Fragment,{children:[0===B?.getStoreDrivers?.length&&(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(oe.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,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(us.A,{fullWidth:!0,required:!0,children:[(0,se.jsx)(Xt.A,{children:"Delivery Agent"}),(0,se.jsx)(en.A,{value:C,onChange:e=>w(e.target.value),label:"Delivery Agent",children:B?.getStoreDrivers?.length>0?B.getStoreDrivers.map((e=>(0,se.jsxs)(je.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId))):(0,se.jsx)(je.A,{disabled:!0,children:"No delivery agents available for this store"})})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{fullWidth:!0,label:"Schedule Time",value:P,onChange:e=>k(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>f(!1),children:"Cancel"}),(0,se.jsx)(ne.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:F||("READY"===b||"READY_FOR_DELIVERY"===b)&&(!C||0===B?.getStoreDrivers?.length),children:F?"Updating...":"Update"})]})]}),(0,se.jsx)(sn.A,{open:$.open,autoHideDuration:6e3,onClose:()=>q((e=>({...e,open:!1}))),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,se.jsx)(oe.A,{onClose:()=>q((e=>({...e,open:!1}))),severity:$.severity,sx:{width:"100%"},children:$.message})})]})});var Cn=t(77867),wn=t(74229),Pn=t(39804);const kn=()=>{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),[l,d]=(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:()=>E("\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:()=>E("\n query AllStores {\n stores {\n id\n name\n codEnabled\n }\n }\n")}),C=(0,cs.n)({mutationFn:e=>E("\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,cs.n)({mutationFn:e=>E("\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,cs.n)({mutationFn:e=>E("\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 k=()=>{s(!1),i(null)},F=y?.allStoresSquareStatus||[],D=Object.fromEntries((I?.stores||[]).map((e=>[e.id,e.codEnabled])));return(0,se.jsxs)(g.A,{children:[(0,se.jsxs)(de.A,{sx:{p:3},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,se.jsx)(ns.A,{sx:{mr:1,fontSize:32}}),(0,se.jsx)(m.A,{variant:"h5",children:"Square Payment Settings"})]}),c&&(0,se.jsx)(oe.A,{severity:p,sx:{mb:3},onClose:()=>h(null),children:c}),b&&(0,se.jsxs)(oe.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",b.message]}),(0,se.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,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,se.jsx)(j.A,{})}):(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Store Name"}),(0,se.jsx)(Jt.A,{children:"Connection Status"}),(0,se.jsx)(Jt.A,{children:"Merchant ID"}),(0,se.jsx)(Jt.A,{children:"COD"}),(0,se.jsx)(Jt.A,{align:"right",children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:0===F.length?(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:5,align:"center",children:"No stores found"})}):F.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:(0,se.jsx)(m.A,{variant:"body2",fontWeight:"medium",children:e.storeName})}),(0,se.jsx)(Jt.A,{children:e.isConnected?(0,se.jsx)(De.A,{label:"Connected",color:"success",size:"small",icon:(0,se.jsx)(wn.A,{})}):(0,se.jsx)(De.A,{label:"Not Connected",color:"default",size:"small",icon:(0,se.jsx)(Pn.A,{})})}),(0,se.jsx)(Jt.A,{children:e.merchantId||(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"—"})}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(an.A,{checked:D[e.storeId]||!1,onChange:s=>{o(e),d(s.target.checked),n(!0)},size:"small",disabled:P.isPending})}),(0,se.jsx)(Jt.A,{align:"right",children:e.isConnected?(0,se.jsx)(ne.A,{variant:"outlined",color:"error",size:"small",onClick:()=>(e=>{i(e),s(!0)})(e),disabled:w.isLoading,children:"Disconnect"}):(0,se.jsx)(ne.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,se.jsx)(j.A,{size:16}),children:"Connect Square"})})]},e.storeId)))})]})})]}),(0,se.jsxs)(Re.A,{open:e,onClose:k,children:[(0,se.jsx)(ze.A,{children:"Disconnect Square?"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(Cn.A,{children:["Are you sure you want to disconnect Square for ",(0,se.jsx)("strong",{children:r?.storeName}),"?",(0,se.jsx)("br",{}),(0,se.jsx)("br",{}),"Customers will not be able to make card payments until you reconnect."]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:k,disabled:w.isLoading,children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{r&&w.mutate(r.storeId)},color:"error",variant:"contained",disabled:w.isLoading,startIcon:w.isLoading&&(0,se.jsx)(j.A,{size:16}),children:"Disconnect"})]})]}),(0,se.jsxs)(Re.A,{open:t,onClose:()=>{n(!1),o(null)},children:[(0,se.jsxs)(ze.A,{children:[l?"Enable":"Disable"," Cash on Delivery?"]}),(0,se.jsx)(We.A,{children:(0,se.jsx)(Cn.A,{children:l?`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,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{n(!1),o(null)},disabled:P.isPending,children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{a&&P.mutate({storeId:a.storeId,enabled:l})},variant:"contained",color:l?"primary":"error",disabled:P.isPending,startIcon:P.isPending&&(0,se.jsx)(j.A,{size:16}),children:P.isPending?"Saving...":"Confirm"})]})]})]})};var En=t(87558),Fn=t(1275),Dn=t(88116),Ln=t(98708),$n=t(60181);const Tn=()=>{const[e,s]=(0,x.useState)(0),[t,n]=(0,x.useState)(10),[r,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(""),[l,d]=(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),[k,F]=(0,x.useState)(!0),[D,L]=(0,x.useState)({open:!1,message:"",severity:"success"}),[$,T]=(0,x.useState)("table"),[q,R]=(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 E(z);return e?.stores||[]},enabled:!0}),{data:Q,isLoading:J}=(0,u.I)({queryKey:["products"],queryFn:async()=>{const e=await E(W);return e?.products||[]},enabled:f}),{data:Z,isLoading:X,error:ee,refetch:te}=(0,u.I)({queryKey:["storeInventory",a],queryFn:async()=>{if(!a)return[];const e=await E("\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,cs.n)({mutationFn:e=>E("\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,cs.n)({mutationFn:e=>E("\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"}),te(),b(!1),xe()},onError:e=>{L({open:!0,message:`Error adding product to inventory: ${e.message}`,severity:"error"})}}),ae=e=>{d(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=()=>{R(null),U(""),_({price:"",quantity:"",measurement:"",unit:""})},ue=e=>{const{name:s,value:t}=e.target;_((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())))||[],pe=(0,x.useRef)(null),ge=(0,x.useCallback)((()=>{if("grid"!==$||!pe.current)return;const e=pe.current.offsetWidth,s=window.innerHeight-pe.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 ge(),window.addEventListener("resize",ge),()=>window.removeEventListener("resize",ge)}),[$,ge]),(0,x.useEffect)((()=>{"table"===$&&10!==t&&n(10)}),[$,t]);return(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Inventory Management"}),(0,se.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:3,flexWrap:"wrap",gap:2},children:[(0,se.jsxs)(us.A,{sx:{minWidth:200},children:[(0,se.jsx)(Xt.A,{children:"Select Store"}),(0,se.jsx)(en.A,{value:a,onChange:e=>{o(e.target.value),s(0)},label:"Select Store",children:Array.isArray(H)&&H?.map((e=>(0,se.jsx)(je.A,{value:e.id,children:e.name},e.id)))})]}),(0,se.jsx)(p.A,{placeholder:"Search products...",value:r,onChange:e=>{i(e.target.value),s(0)},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(nn.A,{})})},sx:{width:300}}),(0,se.jsx)(ne.A,{variant:"outlined",startIcon:"table"===$?(0,se.jsx)(Ln.A,{}):(0,se.jsx)($n.A,{}),onClick:()=>{T("table"===$?"grid":"table")},children:"table"===$?"Grid View":"Table View"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:(0,se.jsx)(Pe.A,{}),onClick:()=>{a?b(!0):L({open:!0,message:"Please select a store first",severity:"warning"})},disabled:!a,children:"Add Product"})]}),K&&(0,se.jsxs)(oe.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",K.message]}),ee&&(0,se.jsxs)(oe.A,{severity:"error",sx:{mb:3},children:["Error loading inventory: ",ee.message]}),a?X?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,se.jsx)(j.A,{})}):0===me().length?(0,se.jsx)(oe.A,{severity:"info",sx:{my:4},children:"No inventory found for this store."}):(0,se.jsxs)(se.Fragment,{children:["table"===$?(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Product"}),(0,se.jsx)(Jt.A,{children:"Category"}),(0,se.jsx)(Jt.A,{children:"Available"}),(0,se.jsx)(Jt.A,{children:"Listed"}),(0,se.jsx)(Jt.A,{children:"Price"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:me().slice(e*t,e*t+t).map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[e.product.image&&(0,se.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,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"body1",children:e.product.name}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:e.product.description})]})]})}),(0,se.jsx)(Jt.A,{children:e.product.category?.name||"N/A"}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:e.isAvailable?"Available":"Not Available",color:e.isAvailable?"success":"error",size:"small"})}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:e.isListed?"Listed":"Not Listed",color:e.isListed?"success":"error",size:"small"})}),(0,se.jsxs)(Jt.A,{children:["$",e.price.toFixed(2)]}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(Ae.A,{size:"small",color:"primary",onClick:()=>ae(e),children:(0,se.jsx)(tn.A,{})})})]},e.id)))})]})}):(0,se.jsx)(fe.Ay,{container:!0,spacing:3,ref:pe,children:me().slice(e*t,e*t+t).map((e=>(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,se.jsxs)(be.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,se.jsx)(ve.A,{component:"img",height:"140",image:e.product.image||"https://via.placeholder.com/140",alt:e.product.name}),(0,se.jsxs)(Ie.A,{sx:{flexGrow:1},children:[(0,se.jsx)(m.A,{gutterBottom:!0,variant:"h6",component:"div",noWrap:!0,children:e.product.name}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1},children:e.product.category?.name||"N/A"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1},noWrap:!0,children:e.product.description}),(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:2},children:[(0,se.jsx)(De.A,{label:`Qty: ${e.quantity}`,color:e.quantity<10?"error":"success",size:"small"}),(0,se.jsxs)(m.A,{variant:"h6",color:"primary",children:["$",e.price.toFixed(2)]})]}),(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"space-between",mt:2},children:(0,se.jsx)(ne.A,{size:"small",startIcon:(0,se.jsx)(tn.A,{}),onClick:()=>ae(e),children:"Edit"})})]})]})},e.id)))}),(0,se.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"===$&&pe.current){const e=pe.current.offsetWidth,s=window.innerHeight-pe.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,se.jsx)(ze.A,{children:"Edit Inventory Item"}),(0,se.jsx)(We.A,{children:l&&(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[l.product.image&&(0,se.jsx)(g.A,{component:"img",src:l.product.image,alt:l.product.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"subtitle1",children:l.product.name}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:l.product.category?.name||"N/A"})]})]}),(0,se.jsx)(p.A,{label:"Quantity",type:"number",fullWidth:!0,value:v,onChange:e=>I(e.target.value),sx:{mb:2}}),(0,se.jsx)(p.A,{label:"Price ($)",type:"number",fullWidth:!0,value:S,onChange:e=>C(e.target.value),sx:{mb:2}}),(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mb:2},children:[(0,se.jsx)(Xt.A,{children:"Availability"}),(0,se.jsxs)(en.A,{value:w,onChange:e=>P(e.target.value),label:"Availability",children:[(0,se.jsx)(je.A,{value:!0,children:"Available"}),(0,se.jsx)(je.A,{value:!1,children:"Not Available"})]})]}),(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mb:2},children:[(0,se.jsx)(Xt.A,{children:"Listing Status"}),(0,se.jsxs)(en.A,{value:k,onChange:e=>F(e.target.value),label:"Listing Status",children:[(0,se.jsx)(je.A,{value:!0,children:"Listed"}),(0,se.jsx)(je.A,{value:!1,children:"Not Listed"})]})]})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>h(!1),children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{l&&re.mutate({inventoryId:l.id,price:parseFloat(S),quantity:parseInt(v),isAvailable:w,isListed:k})},variant:"contained",color:"primary",disabled:re.isPending,children:re.isPending?"Updating...":"Update"})]})]}),(0,se.jsxs)(Re.A,{open:f,onClose:ce,fullWidth:!0,maxWidth:"md",children:[(0,se.jsx)(ze.A,{children:"Add Product to Inventory"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Select a product to add to the store's inventory"}),(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mt:2,mb:3},children:[(0,se.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,se.jsx)(j.A,{color:"inherit",size:20}):null}}),(0,se.jsx)(En.A,{open:N&&he.length>0,anchorEl:V.current,placement:"bottom-start",style:{width:V.current?.offsetWidth,zIndex:1300},children:(0,se.jsx)(Fn.x,{onClickAway:()=>{B(!1)},children:(0,se.jsx)(de.A,{elevation:3,children:(0,se.jsx)(Dn.A,{sx:{maxHeight:300,overflow:"auto"},children:he.map((e=>(0,se.jsx)(je.A,{onClick:()=>(e=>{R(e),U(e.name),B(!1)})(e),selected:q?.id===e.id,children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[e.image&&(0,se.jsx)(g.A,{component:"img",src:e.image,alt:e.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"body1",children:e.name}),(0,se.jsx)(m.A,{variant:"caption",color:"textSecondary",children:e.categoryId?`Category ID: ${e.categoryId}`:"No category"})]})]})},e.id)))})})})})]}),q&&(0,se.jsxs)(g.A,{sx:{mb:3,p:2,bgcolor:"background.paper",borderRadius:1},children:[(0,se.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,children:"Selected Product:"}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[q.image&&(0,se.jsx)(g.A,{component:"img",src:q.image,alt:q.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"body1",children:q.name}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:q.description})]})]})]}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,children:(0,se.jsx)(p.A,{label:"Price ($)",type:"number",name:"price",fullWidth:!0,value:M.price,onChange:ue,required:!0,inputProps:{min:0,step:.01}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,children:(0,se.jsx)(p.A,{label:"Quantity",type:"number",name:"quantity",fullWidth:!0,value:M.quantity,onChange:ue,required:!0,inputProps:{min:0}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,children:(0,se.jsx)(p.A,{label:"Measurement (optional)",type:"number",name:"measurement",fullWidth:!0,value:M.measurement,onChange:ue,inputProps:{min:0,step:.01}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,children:(0,se.jsx)(p.A,{label:"Unit (optional)",name:"unit",fullWidth:!0,value:M.unit,onChange:ue,placeholder:"e.g., kg, g, L, ml"})})]})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:ce,children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{q?M.price&&M.quantity?ie.mutate({productId:q.id,storeId:parseInt(a),price:parseFloat(M.price),quantity:parseInt(M.quantity),measurement:M.measurement?parseInt(M.measurement):null,unit:M.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,se.jsx)(sn.A,{open:D.open,autoHideDuration:6e3,onClose:le,message:D.message,children:(0,se.jsx)(oe.A,{onClose:le,severity:D.severity,children:D.message})})]})},qn=()=>{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),[l,d]=(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,k]=(0,x.useState)(!1),{data:F,refetch:D}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await E("\n query GetCategories {\n categories {\n id\n name\n createdAt\n }\n }\n")).categories||[],enabled:!1}),L=(0,cs.n)({mutationFn:e=>E("\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,cs.n)({mutationFn:e=>{let{id:s,name:t}=e;return E("\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,cs.n)({mutationFn:e=>E("\n mutation DeleteCategory($categoryId: Int!) {\n deleteCategory(categoryId: $categoryId) {\n success\n }\n }\n",e),onSuccess:()=>{S("Category deleted successfully"),k(!1),D()},onError:e=>{h(e.message)}}),q=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(o(e),d(e.name)):(o(null),d("")),i(!0)},R=()=>{i(!1),o(null),d(""),h(null)},z=()=>{l.trim()?a?$.mutate({id:a.id,name:l.trim()}):L.mutate(l.trim()):h("Category name is required")},W=F?.slice(e*t,e*t+t);return(0,se.jsxs)(g.A,{children:[(0,se.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,se.jsx)(Pe.A,{sx:{mr:1}}),(0,se.jsx)(m.A,{variant:"h5",children:"Category Management"})]}),(0,se.jsx)(fe.Ay,{container:!0,spacing:2,sx:{mb:3},children:(0,se.jsxs)(fe.Ay,{item:!0,xs:12,sx:{display:"flex",gap:2},children:[(0,se.jsx)(ne.A,{variant:"contained",startIcon:(0,se.jsx)(xn.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,se.jsx)(j.A,{size:24}):"Fetch Categories"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:(0,se.jsx)(Pe.A,{}),onClick:()=>q(),children:"Add Category"})]})}),c&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:3},children:c}),b?A?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,se.jsx)(j.A,{})}):(0,se.jsx)(se.Fragment,{children:(0,se.jsxs)(Gt.A,{children:[(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"ID"}),(0,se.jsx)(Jt.A,{children:"Name"}),(0,se.jsx)(Jt.A,{children:"Created At"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:0===W?.length?(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:4,align:"center",children:"No categories found"})}):W?.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.id}),(0,se.jsx)(Jt.A,{children:e.name}),(0,se.jsx)(Jt.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{size:"small",onClick:()=>q(e),children:(0,se.jsx)(tn.A,{})}),(0,se.jsx)(Ae.A,{size:"small",onClick:()=>(e=>{w(e),k(!0)})(e),children:(0,se.jsx)(cn.A,{})})]})]},e.id)))})]}),(0,se.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,se.jsxs)(g.A,{sx:{textAlign:"center",py:4},children:[(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Categories" to load category information'}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,se.jsxs)(Re.A,{open:r,onClose:R,children:[(0,se.jsx)(ze.A,{children:a?"Edit Category":"Add New Category"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(p.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:l,onChange:e=>d(e.target.value),error:!!c,helperText:c,onKeyPress:e=>{"Enter"===e.key&&z()}})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:R,children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:z,variant:"contained",disabled:L.isPending||$.isPending,children:L.isPending||$.isPending?(0,se.jsx)(j.A,{size:24}):a?"Update":"Create"})]})]}),(0,se.jsxs)(Re.A,{open:P,onClose:()=>k(!1),children:[(0,se.jsx)(ze.A,{children:"Delete Category"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(m.A,{children:"Are you sure you want to delete this category?"})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>k(!1),disabled:T.isPending||T.isLoading,children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{C&&T.mutate({categoryId:C.id})},variant:"contained",color:"error",disabled:T.isPending||T.isLoading,startIcon:T.isPending||T.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:T.isPending||T.isLoading?"Deleting...":"Delete"})]})]})]})},Rn=e=>{let{open:s,onClose:t,selectedFee:n,onUpdate:r,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,l]=(0,x.useState)(a);(0,x.useEffect)((()=>{n?l({feeCurrency:n.feeCurrency||"",feeRate:n.feeRate?.toString()||"",limit:n.limit?.toString()||"",type:n.type?.toUpperCase()||"DELIVERY"}):s&&l(a)}),[n,s]),(0,x.useEffect)((()=>{s||l(a)}),[s]);const d=e=>{const{name:s,value:t}=e.target;l((e=>({...e,[s]:t})))};return(0,se.jsxs)(Re.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:n?"Edit Fee":"Add New Fee"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,se.jsxs)(us.A,{fullWidth:!0,children:[(0,se.jsx)(Xt.A,{children:"Fee Type"}),(0,se.jsxs)(en.A,{name:"type",value:o.type,onChange:d,label:"Fee Type",children:[(0,se.jsx)(je.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,se.jsx)(je.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,se.jsx)(p.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:d,fullWidth:!0,placeholder:"e.g., USD"}),(0,se.jsx)(p.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,se.jsx)(p.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:t,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",onClick:()=>{r({id:n?.id,...o,feeRate:parseFloat(o.feeRate),limit:parseFloat(o.limit)}),n||l(a)},disabled:i,startIcon:i?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},zn=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,p]=(0,x.useState)(""),{data:A,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>E("\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:()=>E("\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,cs.n)({mutationFn:e=>E("\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=>{d(`Error updating fee: ${e.message}`)}}),w=(0,cs.n)({mutationFn:e=>E("\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=>{d(`Error deleting fee: ${e.message}`)}}),P=(0,cs.n)({mutationFn:s=>E("\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=>{d(`Error adding fee: ${e.message}`)}});return y?(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})}):(0,se.jsxs)(h.A,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Fees Management"}),(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mb:3},children:[(0,se.jsx)(Xt.A,{children:"Select Store"}),(0,se.jsx)(en.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,se.jsx)(je.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,se.jsx)(oe.A,{severity:"info",sx:{mb:4},children:(0,se.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its fees."})}),e&&(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,se.jsx)(m.A,{variant:"h5",children:"Fees"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):(0,se.jsx)(Pe.A,{}),onClick:()=>{n(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Fee"})]}),v?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,se.jsx)(j.A,{})}):0===S.length?(0,se.jsx)(oe.A,{severity:"info",sx:{my:2},children:"No fees found for this store. Add your first fee to get started."}):(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Type"}),(0,se.jsx)(Jt.A,{children:"Currency"}),(0,se.jsx)(Jt.A,{children:"Rate"}),(0,se.jsx)(Jt.A,{children:"Limit"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:0!==S.length||v?S.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.type}),(0,se.jsx)(Jt.A,{children:e.feeCurrency}),(0,se.jsx)(Jt.A,{children:e.feeRate}),(0,se.jsx)(Jt.A,{children:e.limit}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,se.jsx)(tn.A,{})}),(0,se.jsx)(Ae.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,se.jsx)(cn.A,{})})]})]},e.id))):(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:5,align:"center",children:(0,se.jsx)(oe.A,{severity:"info",sx:{my:2},children:"No fees found for this store."})})})})]})})]}),(0,se.jsx)(Rn,{open:r,onClose:()=>{i(!1),n(null),d("")},selectedFee:t,onUpdate:e=>{t?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading}),(0,se.jsxs)(Re.A,{open:a,onClose:()=>{o(!1),n(null),d("")},children:[(0,se.jsx)(ze.A,{children:"Delete Fee"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(m.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{o(!1),n(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:t.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},Wn=e=>{let{open:s,onClose:t,selectedLocationCode:n,onUpdate:r,isLoading:i,existingCodes:a}=e;const[o,l]=(0,x.useState)({location:"",code:""}),[d,c]=(0,x.useState)("");(0,x.useEffect)((()=>{l(n?{location:n.location||"",code:n.code||""}:{location:"",code:""}),c("")}),[n,s]);const u=()=>{l({location:"",code:""}),c(""),t()},m=e=>{const{name:s,value:t}=e.target;l((e=>({...e,[s]:t}))),c("")};return(0,se.jsxs)(Re.A,{open:s,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:n?"Edit Location Code":"Add New Location Code"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,se.jsx)(p.A,{name:"location",label:"Location",value:o.location,onChange:m,fullWidth:!0,placeholder:"e.g., Main Branch",error:!!d&&d.includes("Location"),helperText:d&&d.includes("Location")?d:""}),(0,se.jsx)(p.A,{name:"code",label:"Code",value:o.code,onChange:m,fullWidth:!0,placeholder:"e.g., MB001",error:!!d&&(d.includes("Code")||d.includes("already exists")),helperText:d&&(d.includes("Code")||d.includes("already exists"))?d:""})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:u,children:"Cancel"}),(0,se.jsx)(ne.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,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},On=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,p]=(0,x.useState)(""),{data:A,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>E("\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:()=>E("\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,cs.n)({mutationFn:e=>E("\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=>{d(`Error updating location code: ${e.message}`)}}),w=(0,cs.n)({mutationFn:e=>E("\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=>{d(`Error deleting location code: ${e.message}`)}}),P=(0,cs.n)({mutationFn:s=>E("\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=>{d(`Error adding location code: ${e.message}`)}});return y?(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})}):(0,se.jsxs)(h.A,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mb:3},children:[(0,se.jsx)(Xt.A,{children:"Select Store"}),(0,se.jsx)(en.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,se.jsx)(je.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,se.jsx)(oe.A,{severity:"info",sx:{mb:4},children:(0,se.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its location codes."})}),e&&(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,se.jsx)(m.A,{variant:"h5",children:"Location Codes"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):(0,se.jsx)(Pe.A,{}),onClick:()=>{n(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Location Code"})]}),v?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,se.jsx)(j.A,{})}):0===S.length?(0,se.jsx)(oe.A,{severity:"info",sx:{my:2},children:"No location codes found for this store. Add your first location code to get started."}):(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Location"}),(0,se.jsx)(Jt.A,{children:"Code"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:0!==S.length||v?S.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.location}),(0,se.jsx)(Jt.A,{children:e.code}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,se.jsx)(tn.A,{})}),(0,se.jsx)(Ae.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,se.jsx)(cn.A,{})})]})]},e.id))):(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:3,align:"center",children:(0,se.jsx)(oe.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})})]}),(0,se.jsx)(Wn,{open:r,onClose:()=>{i(!1),n(null),d("")},selectedLocationCode:t,onUpdate:e=>{t?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading,existingCodes:S}),(0,se.jsxs)(Re.A,{open:a,onClose:()=>{o(!1),n(null),d("")},children:[(0,se.jsx)(ze.A,{children:"Delete Location Code"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(m.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{o(!1),n(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:t.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},Un=e=>{let{open:s,onClose:t,selectedPickupAddress:n,onUpdate:r,isLoading:i,existingAddresses:a}=e;const[o,l]=(0,x.useState)({address:""}),[d,c]=(0,x.useState)(""),[u,h]=(0,x.useState)(!1);x.useEffect((()=>{n?(l({address:n.address||""}),h(!0)):(l({address:""}),h(!1)),c("")}),[n]);return(0,se.jsxs)(Re.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:n?"Edit Pickup Address":"Add New Pickup Address"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,se.jsx)(wt,{value:o.address,onChange:e=>{l((s=>({...s,address:e}))),c("")},onValidAddress:h}),d&&(0,se.jsx)(m.A,{color:"error",variant:"caption",children:d})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:t,children:"Cancel"}),(0,se.jsx)(ne.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,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},Nn=()=>{const[e,s]=(0,x.useState)(""),[t,n]=(0,x.useState)(null),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,p]=(0,x.useState)(""),{data:A,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>E("\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:()=>E("\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,cs.n)({mutationFn:e=>E("\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=>{d(`Error updating pickup address: ${e.message}`)}}),w=(0,cs.n)({mutationFn:e=>E("\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=>{d(`Error deleting pickup address: ${e.message}`)}}),P=(0,cs.n)({mutationFn:s=>E("\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=>{d(`Error adding pickup address: ${e.message}`)}});return y?(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})}):(0,se.jsxs)(h.A,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mb:3},children:[(0,se.jsx)(Xt.A,{children:"Select Store"}),(0,se.jsx)(en.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,se.jsx)(je.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,se.jsx)(oe.A,{severity:"info",sx:{mb:4},children:(0,se.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its pickup addresses."})}),e&&(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,se.jsx)(m.A,{variant:"h5",children:"Pickup Addresses"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):(0,se.jsx)(Pe.A,{}),onClick:()=>{n(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Pickup Address"})]}),v?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,se.jsx)(j.A,{})}):0===S.length?(0,se.jsx)(oe.A,{severity:"info",sx:{my:2},children:"No pickup addresses found for this store. Add your first pickup address to get started."}):(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Address"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:S.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.address}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{onClick:()=>(e=>{n(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,se.jsx)(tn.A,{})}),(0,se.jsx)(Ae.A,{onClick:()=>(e=>{n(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,se.jsx)(cn.A,{})})]})]},e.id)))})]})})]}),(0,se.jsx)(Un,{open:r,onClose:()=>{i(!1),n(null),d("")},selectedPickupAddress:t,onUpdate:e=>{t?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading,existingAddresses:S}),(0,se.jsxs)(Re.A,{open:a,onClose:()=>{o(!1),n(null),d("")},children:[(0,se.jsx)(ze.A,{children:"Delete Pickup Address"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(m.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{o(!1),n(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:t.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},Bn=240,Mn=65,_n=[{text:"Dashboard",icon:(0,se.jsx)(Wt.A,{}),path:"/admin/dashboard"},{text:"Stores",icon:(0,se.jsx)(It.A,{}),path:"/admin/stores"},{text:"Product Management",icon:(0,se.jsx)(Ot.A,{}),path:"/admin/products"},{text:"Inventory Management",icon:(0,se.jsx)(Ut.A,{}),path:"/admin/inventory"},{text:"Orders",icon:(0,se.jsx)(ke.A,{}),path:"/admin/orders"},{text:"Users",icon:(0,se.jsx)(Nt.A,{}),path:"/admin/users"},{text:"Payment Settings",icon:(0,se.jsx)(ns.A,{}),path:"/admin/payment-settings"},{text:"Categories",icon:(0,se.jsx)(Ut.A,{}),path:"/admin/categories"},{text:"Fees Management",icon:(0,se.jsx)(ns.A,{}),path:"/admin/fees"},{text:"Location Codes",icon:(0,se.jsx)(Bt.A,{}),path:"/admin/location-codes"},{text:"Pickup Addresses",icon:(0,se.jsx)(js.A,{}),path:"/admin/pickup-addresses"}],Vn=()=>{const e=(0,Fe.A)(),s=(0,Ds.A)(e.breakpoints.down("sm")),[t,n]=(0,x.useState)(!0),{user:r,ability:i,logout:a}=Z(),o=(0,d.Zp)(),l=(0,d.zy)(),c=(0,se.jsxs)(g.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:t&&!s?"space-between":"center",p:2,minHeight:64},children:[t&&!s&&(0,se.jsx)(m.A,{variant:"h6",noWrap:!0,component:"div",children:"Admin Panel"}),!s&&(0,se.jsx)(Ae.A,{onClick:()=>{n(!t)},children:t?(0,se.jsx)(Ze.A,{}):(0,se.jsx)(Mt.A,{})})]}),(0,se.jsx)(ts.A,{}),(0,se.jsxs)(vs.A,{children:[_n.map((e=>(0,se.jsxs)(Is.Ay,{button:!0,onClick:()=>{return s=e.path,void o(s);var s},selected:l.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,se.jsx)(Ss.A,{sx:{minWidth:0,mr:t&&!s?3:"auto",justifyContent:"center",color:l.pathname===e.path?"white":"inherit"},children:e.icon}),(0,se.jsx)(Cs.A,{primary:e.text,sx:{opacity:t&&!s?1:0}})]},e.text))),(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsxs)(Is.Ay,{button:!0,onClick:()=>{(async()=>{try{await(0,Fs.C)(),a(),o("/")}catch(e){}})()},sx:{minHeight:48,justifyContent:t&&!s?"initial":"center",px:2.5},children:[(0,se.jsx)(Ss.A,{sx:{minWidth:0,mr:t&&!s?3:"auto",justifyContent:"center"},children:(0,se.jsx)(_t.A,{})}),(0,se.jsx)(Cs.A,{primary:"Logout",sx:{opacity:t&&!s?1:0}})]})]})]});return(0,se.jsxs)(g.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,se.jsx)(Dt,{}),(0,se.jsx)(g.A,{component:"nav",sx:{width:s?Mn:t?Bn:Mn,flexShrink:0,position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,se.jsx)(ws.Ay,{variant:"persistent",open:!0,sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:s?Mn:t?Bn:Mn,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,se.jsx)(g.A,{component:"main",sx:{flexGrow:1,p:{xs:0,sm:3},width:{xs:"calc(100% - 65px)",sm:`calc(100% - ${t?Bn:Mn}px)`},ml:{xs:"65px",sm:`${t?Bn:Mn}px`},mt:{xs:"64px",sm:"70px"},transition:e.transitions.create(["width","margin"],{easing:e.transitions.easing.sharp,duration:e.transitions.duration.leavingScreen})},children:(0,se.jsxs)(d.BV,{children:[(0,se.jsx)(d.qh,{path:"/",element:(0,se.jsx)(d.C5,{to:"dashboard",replace:!0})}),(0,se.jsx)(d.qh,{path:"dashboard",element:(0,se.jsx)(Ht,{})}),(0,se.jsx)(d.qh,{path:"users/*",element:(0,se.jsx)(rn,{})}),(0,se.jsx)(d.qh,{path:"stores/*",element:(0,se.jsx)(gn,{})}),(0,se.jsx)(d.qh,{path:"products",element:(0,se.jsx)(yn,{})}),(0,se.jsx)(d.qh,{path:"inventory",element:(0,se.jsx)(Tn,{})}),(0,se.jsx)(d.qh,{path:"orders",element:(0,se.jsx)(Sn,{})}),(0,se.jsx)(d.qh,{path:"payment-settings",element:(0,se.jsx)(kn,{})}),(0,se.jsx)(d.qh,{path:"categories",element:(0,se.jsx)(qn,{})}),(0,se.jsx)(d.qh,{path:"fees",element:(0,se.jsx)(zn,{})}),(0,se.jsx)(d.qh,{path:"location-codes",element:(0,se.jsx)(On,{})}),(0,se.jsx)(d.qh,{path:"pickup-addresses",element:(0,se.jsx)(Nn,{})})]})})]})};var Hn=t(27558),Gn=t(76030);const Kn=()=>{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,l]=(0,x.useState)(""),[d,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),[k,F]=(0,x.useState)({}),[$,T]=(0,x.useState)(!1),{userProfile:R,setUserProfile:z}=Z();(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 E(L,{userId:i});return s?.getUserProfile&&(z(s.getUserProfile),setTimeout((()=>{e()}),200)),s},enabled:!!i,onError:e=>{}}),N=Z.getState().userProfile||R||W?.getUserProfile,{data:B,isLoading:M,error:_,refetch:V}=(0,u.I)({queryKey:["driverDeliveries",N?.id],queryFn:()=>N?.id?E("\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,cs.n)({mutationFn:e=>E(D,{input:{orderId:e.orderId,status:e.status}}),onSuccess:()=>{V(),r(!1),I(""),C(!1)},onError:e=>{}}),G=(0,cs.n)({mutationFn:e=>E(q,{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=>k[e.node.id])),Y=x.useMemo((()=>B?.getDeliveriesByDriver?B.getDeliveriesByDriver.filter((e=>{if("ALL"!==y&&e.status!==y)return!1;if(d){const s=d.toLowerCase(),t=e.orderId.toString().includes(s),n=e.address?.toLowerCase().includes(s);return t||n}return!0})):[]),[B?.getDeliveriesByDriver,y,d]);if(O||M&&N?.id)return(0,se.jsx)(j.A,{sx:{display:"block",mx:"auto",mt:4}});if(U)return(0,se.jsx)(m.A,{color:"error",children:"Error fetching user profile!"});if(_&&N?.id)return(0,se.jsx)(m.A,{color:"error",children:"Error fetching deliveries!"});const Q=B?.getDeliveriesByDriver||[],J=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,se.jsx)(bn.A,{});case"PICKED_UP":return(0,se.jsx)(js.A,{});case"DELIVERED":return(0,se.jsx)(is.A,{});case"CANCELLED":return(0,se.jsx)(fn.A,{});default:return null}},ee=e=>B?.getDeliveriesByDriver?B.getDeliveriesByDriver.filter((s=>s.status===e)).length:0;return(0,se.jsxs)(h.A,{maxWidth:"lg",sx:{mt:4,mb:6},children:[(0,se.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,se.jsx)(m.A,{variant:"h4",fontWeight:"500",sx:{fontSize:{xs:"1.5rem",sm:"2rem"}},children:"Delivery Partner Dashboard"}),(0,se.jsx)(p.A,{size:"small",placeholder:"Search orders...",value:d,onChange:e=>c(e.target.value),InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(nn.A,{fontSize:"small"})})},sx:{width:{xs:"100%",sm:250},"& .MuiOutlinedInput-root":{borderRadius:2}}})]}),(0,se.jsx)(g.A,{sx:{mb:4},children:(0,se.jsxs)(at.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,se.jsx)(ot.A,{label:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:["All Orders",(0,se.jsx)(Ve.A,{badgeContent:Q.length,color:"primary",sx:{ml:2}})]})}),(0,se.jsx)(ot.A,{label:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:["Ready",(0,se.jsx)(Ve.A,{badgeContent:ee("READY_FOR_DELIVERY"),color:"primary",sx:{ml:2}})]})}),(0,se.jsx)(ot.A,{label:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:["In Transit",(0,se.jsx)(Ve.A,{badgeContent:ee("PICKED_UP"),color:"info",sx:{ml:2}})]})}),(0,se.jsx)(ot.A,{label:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:["Delivered",(0,se.jsx)(Ve.A,{badgeContent:ee("DELIVERED"),color:"success",sx:{ml:2}})]})})]})}),(0,se.jsx)(fe.Ay,{container:!0,spacing:{xs:2,sm:3},children:Y.length>0?Y.map((e=>(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,se.jsx)(be.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),l(e.orderStatus||e.status),r(!0),C(!1),I("")})(e),children:(0,se.jsxs)(Ie.A,{sx:{flexGrow:1,p:{xs:2,sm:2.5}},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,se.jsxs)(m.A,{variant:"h6",sx:{fontSize:{xs:"1rem",sm:"1.25rem"},fontWeight:500},children:["Order #",e.orderId]}),(0,se.jsx)(De.A,{icon:X(e.status),label:e.status.replace(/_/g," "),color:J(e.status),size:"small",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},height:{xs:24,sm:28},borderRadius:1.5}})]}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,se.jsx)(Gn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,se.jsx)(m.A,{variant:"body2",sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:new Date(e.schedule).toLocaleString()})]}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,se.jsx)(Bt.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,se.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,se.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,se.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,se.jsx)(g.A,{sx:{mt:1},children:(0,se.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,se.jsx)(fn.A,{fontSize:"small",sx:{mr:.5,flexShrink:0}}),(0,se.jsxs)("span",{style:{lineHeight:1},children:['Cancellation Reason: "',e.order.cancelMessage,'"']})]})}),e.comments&&"CANCELLED"!==e.status&&(0,se.jsx)(g.A,{sx:{mt:1},children:(0,se.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,se.jsxs)("span",{children:['"',e.comments,'"']})})})]})})},e.id))):(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(de.A,{sx:{p:{xs:3,sm:4},borderRadius:2,textAlign:"center"},children:[(0,se.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"No Deliveries Found"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:d||"ALL"!==y?"No deliveries match your search criteria.":"You have no deliveries assigned at this time."})]})})}),(0,se.jsx)(Ms.A,{open:n,onClose:()=>r(!1),"aria-labelledby":"delivery-details-modal",children:(0,se.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,se.jsxs)(se.Fragment,{children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,se.jsxs)(m.A,{variant:"h5",fontWeight:"500",sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"}},children:["Order #",s.orderId]}),(0,se.jsx)(Ae.A,{edge:"end","aria-label":"close",onClick:()=>r(!1),size:"small",children:(0,se.jsx)(rs.A,{})})]}),(0,se.jsx)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:(0,se.jsx)(De.A,{icon:X(s.status),label:s.status.replace(/_/g," "),color:J(s.status),sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}}})}),(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY ADDRESS"}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"flex-start"},children:[(0,se.jsx)(Bt.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,se.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,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"SCHEDULED DELIVERY"}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,se.jsx)(Gn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,se.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(s.schedule).toLocaleString()})]})]}),s.pickedUpTime&&(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"PICKED UP"}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,se.jsx)(js.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,se.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(s.pickedUpTime).toLocaleString()})]})]}),s.deliveredTime&&(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERED"}),(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[(0,se.jsx)(is.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,se.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,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"error",gutterBottom:!0,children:"CANCELLATION REASON"}),(0,se.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,se.jsx)(fn.A,{color:"error",sx:{flexShrink:0}}),(0,se.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,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"COMMENTS"}),(0,se.jsx)(g.A,{sx:{p:2,bgcolor:"rgba(0, 0, 0, 0.03)",borderRadius:1,borderLeft:"3px solid",borderColor:"primary.main"},children:(0,se.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:s.comments})})]}),s.photo&&(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY PROOF"}),(0,se.jsx)("img",{src:s.photo,alt:"Delivery Proof",style:{width:"100%",borderRadius:4}})]}),$&&s?.order?.orderItems&&(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"VERIFY ITEMS TO BE PICKED UP"}),(0,se.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,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:1,p:1,borderRadius:1,bgcolor:"background.default"},children:[(0,se.jsx)(Hn.A,{checked:!!k[s.id],onChange:()=>{return e=s.id,void F((s=>({...s,[e]:!s[e]})));var e},color:"primary"}),(0,se.jsxs)(g.A,{sx:{ml:2,flex:1},children:[(0,se.jsx)(m.A,{variant:"body2",fontWeight:"500",children:s.product.name}),(0,se.jsxs)(m.A,{variant:"caption",color:"text.secondary",children:["Quantity: ",s.quantity," × $",s.orderAmount.toFixed(2)]})]})]},s.id)}))}),!K(s.order.orderItems)&&(0,se.jsx)(oe.A,{severity:"warning",sx:{mt:1},children:"Please verify all items before updating status"})]}),(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"UPDATE STATUS"}),(0,se.jsx)(us.A,{fullWidth:!0,sx:{mb:2},children:(0,se.jsxs)(en.A,{value:o,onChange:e=>{const t=e.target.value;l(t),"READY_FOR_DELIVERY"===s?.status&&"READY_FOR_DELIVERY"!==t?(T(!0),F({})):T(!1),C("CANCELLED"===t)},size:"small",children:[(0,se.jsx)(je.A,{value:"PICKED_UP",children:"Picked Up"}),(0,se.jsx)(je.A,{value:"DELIVERED",children:"Delivered"}),(0,se.jsx)(je.A,{value:"CANCELLED",children:"Cancelled"})]})}),S&&(0,se.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,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"flex-end",mt:3},children:(0,se.jsx)(ne.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,se.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 Yn=t(80669),Qn=t(47922);const Jn=[{text:"Dashboard",icon:(0,se.jsx)(Wt.A,{}),path:zs},{text:"Orders",icon:(0,se.jsx)(ke.A,{}),path:Ws},{text:"Delivery Partners",icon:(0,se.jsx)(js.A,{}),path:"/store_manager/delivery-partners"},{text:"Inventory",icon:(0,se.jsx)(Ot.A,{}),path:"/store_manager/inventory"},{text:"Delivery Fees",icon:(0,se.jsx)(Qn.A,{}),path:"/store_manager/delivery-fees"},{text:"Location Codes",icon:(0,se.jsx)(Bt.A,{}),path:"/store_manager/location-codes"},{text:"Pickup Addresses",icon:(0,se.jsx)(js.A,{}),path:"/store_manager/pickup-addresses"},{text:"Payment Settings",icon:(0,se.jsx)(Qn.A,{}),path:"/store_manager/payment-settings"}],Zn=()=>{const e=(0,Fe.A)(),s=(0,Ds.A)(e.breakpoints.down("sm")),t=(0,d.Zp)(),n=(0,d.zy)(),{open:r,setOpen:i}=x.useContext(Xn),a=(0,se.jsxs)(g.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",justifyContent:r&&!s?"space-between":"center",p:2,minHeight:64},children:[r&&!s&&(0,se.jsx)(m.A,{variant:"h6",noWrap:!0,component:"div",children:"Store Manager"}),!s&&(0,se.jsx)(Ae.A,{onClick:()=>{i(!r)},children:r?(0,se.jsx)(Ze.A,{}):(0,se.jsx)(Mt.A,{})})]}),(0,se.jsx)(ts.A,{}),(0,se.jsx)(vs.A,{children:Jn.map((e=>(0,se.jsxs)(Is.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,se.jsx)(Ss.A,{sx:{minWidth:0,mr:r&&!s?3:"auto",justifyContent:"center",color:n.pathname===e.path?"primary.main":"inherit"},children:e.icon}),(0,se.jsx)(Cs.A,{primary:e.text,sx:{opacity:r&&!s?1:0}})]},e.text)))})]});return(0,se.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,se.jsx)(ws.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})})},Xn=(0,x.createContext)({open:!0,setOpen:()=>{}}),er=e=>{let{children:s}=e;const t=(0,Fe.A)(),[n,r]=((0,Ds.A)(t.breakpoints.down("sm")),(0,x.useState)(!0));return(0,se.jsx)(Xn.Provider,{value:{open:n,setOpen:r},children:(0,se.jsxs)(g.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,se.jsx)(l.Ay,{}),(0,se.jsx)(Dt,{}),(0,se.jsx)(Zn,{}),(0,se.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,se.jsx)(g.A,{sx:{width:"100%"},children:s})})]})})},sr=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=Z(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,y]=(0,x.useState)(null),[f,b]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[C,w]=(0,x.useState)(""),[P,k]=(0,x.useState)(""),[F,D]=(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),[J,X]=((0,x.useRef)(null),(0,x.useState)(0)),[ee,te]=(0,x.useState)(10),[re,ie]=(0,x.useState)(!0),[ae,le]=(0,x.useState)(null),[ce,xe]=(0,x.useState)({open:!1,message:"",severity:"success"}),[ue,me]=(0,x.useState)([]),[he,pe]=(0,x.useState)(!0),[ge,ye]=(0,x.useState)([]),[be,ve]=(0,x.useState)(!1);(0,x.useEffect)((()=>{let e=!0;return(async()=>{try{const t=await(0,Hs.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 E(L,{userId:e})},enabled:!!e});(0,x.useEffect)((()=>{Ie?.getUserProfile&&!t&&n(Ie.getUserProfile)}),[Ie,t,n]);const{data:Ce,isLoading:we,error:ke,refetch:Ee}=(0,u.I)({queryKey:["storeWithInventory",t?.id],queryFn:async()=>t?.id?E("\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}),Fe=Ce?.storesByManager?.[0]||null,Le=Fe?.inventory?.edges?.map((e=>e.node))||[],$e=Ce?.products||[],{data:Te,isLoading:qe}=(0,u.I)({queryKey:["storeSquareStatus",Fe?.id],queryFn:()=>E("\n query StoreSquareStatus($storeId: Int!) {\n storeSquareStatus(storeId: $storeId) {\n storeId\n storeName\n isConnected\n }\n }\n",{storeId:Fe?.id}),enabled:!!Fe?.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,cs.n)({mutationFn:e=>E("\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([]),ye([]),pe(!0)};return Se||we||re||!Fe?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})})}):ke?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4},children:(0,se.jsxs)(oe.A,{severity:"error",children:["Error loading store data: ",ke.message]})})}):Fe||re?(0,se.jsx)(er,{children:(0,se.jsxs)(h.A,{sx:{mb:4},children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Manager Dashboard"}),(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,se.jsx)(m.A,{variant:"h5",children:"Store Information"}),(0,se.jsx)(ne.A,{variant:"outlined",startIcon:(0,se.jsx)(tn.A,{}),onClick:()=>{Fe&&(le(Fe),me(Fe.sectionHeaders||[]),ye(Fe.images||[]),pe(Fe.isActive))},sx:{textTransform:"none"},children:"Edit Store"})]}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Name:"})," ",Fe.name]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Address:"})," ",Fe.address]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Delivery Radius:"})," ",Fe.radius||"Not set"," ",Fe.radius?"mi":""]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Delivery Fee:"})," $",Fe.storeDeliveryFee?.toFixed(2)||"0.00"]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Tax Rate:"})," ",Fe.taxPercentage?.toFixed(1)||"0.0","%"]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Total Products:"})," ",Le.filter((e=>e.isListed)).length]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Display Field:"})," ",Fe.displayField]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Square Payment:"})," ",(0,se.jsx)(De.A,{size:"small",label:Ue?"Connected":"Not Connected",color:Ue?"success":"default"})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Cash on Delivery:"})," ",(0,se.jsx)(De.A,{size:"small",label:Fe?.codEnabled?"Enabled":"Disabled",color:Fe?.codEnabled?"success":"default"})]})}),Fe.whatsappNumber&&(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"WhatsApp:"})," ",Fe.whatsappNumber]})}),Fe.description&&(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Description:"})," ",Fe.description]})}),Fe.pincodes&&Fe.pincodes.length>0&&(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:[(0,se.jsx)("strong",{children:"Delivery Pincodes:"})," ",Fe.pincodes.join(", ")]})}),Fe.sectionHeaders&&Fe.sectionHeaders.length>0&&(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:(0,se.jsx)("strong",{children:"Section Headers:"})}),(0,se.jsx)(g.A,{sx:{pl:2},children:Fe.sectionHeaders.map(((e,s)=>(0,se.jsxs)(m.A,{variant:"body2",sx:{mb:1},children:["• ",e]},s)))})]})]})]}),(0,se.jsxs)(Re.A,{open:!!ae,onClose:Be,maxWidth:"md",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(It.A,{}),(0,se.jsx)(m.A,{variant:"h6",children:"Edit Store"})]})}),(0,se.jsxs)("form",{onSubmit:e=>{if(e.preventDefault(),!ae)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:ae.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:ge,whatsappNumber:s.get("whatsappNumber")||null};Ne.mutate(r)},children:[(0,se.jsx)(We.A,{children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"name",label:"Store Name",defaultValue:ae?.name,required:!0,fullWidth:!0})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"email",label:"Email",type:"email",defaultValue:ae?.email,required:!0,fullWidth:!0})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"mobile",label:"Mobile Number",defaultValue:ae?.mobile,fullWidth:!0})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{name:"address",label:"Address",defaultValue:ae?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:ae?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:ae?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:"$"})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:ae?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,se.jsx)(A.A,{position:"end",children:"%"})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:ae?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{name:"description",label:"Description",defaultValue:ae?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{name:"tnc",label:"Terms & Conditions",defaultValue:ae?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsx)(p.A,{name:"whatsappNumber",label:"WhatsApp Support Number",placeholder:"+1234567890",defaultValue:ae?.whatsappNumber,fullWidth:!0,helperText:"Include country code. Optional."})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{name:"displayField",label:"Display Field",defaultValue:ae?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,se.jsxs)(g.A,{sx:{mb:2},children:[ue.map(((e,s)=>(0,se.jsxs)(g.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,se.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,se.jsx)(Ae.A,{color:"error",onClick:()=>(e=>{me((s=>s.filter(((s,t)=>t!==e))))})(s),sx:{alignSelf:"center"},"aria-label":"Remove question",children:(0,se.jsx)(cn.A,{})})]},s))),(0,se.jsx)(ne.A,{startIcon:(0,se.jsx)(Pe.A,{}),onClick:()=>{me((e=>[...e,""]))},variant:"outlined",sx:{mt:1},"aria-label":"Add question",children:"Add Question"})]})]}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Images / Offers Banner"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(g.A,{sx:{mb:2},children:[(0,se.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&&ae?.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=${ae.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:l}=await i.json();if(!(await fetch(a,{method:"PUT",headers:{"Content-Type":o},body:e})).ok)throw new Error("Failed to upload image");const d=`https://indimitra-dev-order-files.s3.amazonaws.com/${l}`;ye((e=>[...e,d])),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,se.jsx)("label",{htmlFor:"edit-store-image-upload",children:(0,se.jsx)(ne.A,{variant:"outlined",component:"span",startIcon:be?(0,se.jsx)(j.A,{size:16}):(0,se.jsx)(Yn.A,{}),disabled:be,sx:{mb:2},children:be?"Uploading...":"Upload Image"})}),ge.length>0&&(0,se.jsx)(g.A,{sx:{display:"flex",flexWrap:"wrap",gap:2},children:ge.map(((e,s)=>(0,se.jsxs)(g.A,{sx:{position:"relative",width:150,height:150},children:[(0,se.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,se.jsx)(Ae.A,{size:"small",color:"error",onClick:()=>(e=>{ye((s=>s.filter(((s,t)=>t!==e))))})(s),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,se.jsx)(cn.A,{fontSize:"small"})})]},s)))})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(us.A,{fullWidth:!0,children:[(0,se.jsx)(Xt.A,{children:"Store Status"}),(0,se.jsxs)(en.A,{name:"isActive",label:"Store Status",value:he,onChange:e=>{pe(e.target.value)},children:[(0,se.jsx)(je.A,{value:!0,children:"Active"}),(0,se.jsx)(je.A,{value:!1,children:"Inactive"})]})]})})]})}),(0,se.jsxs)(Oe.A,{sx:{p:3,pt:0},children:[(0,se.jsx)(ne.A,{onClick:Be,children:"Cancel"}),(0,se.jsx)(ne.A,{type:"submit",variant:"contained",disabled:Ne.isPending,startIcon:Ne.isPending?(0,se.jsx)(j.A,{size:20}):null,children:Ne.isPending?"Updating...":"Update Store"})]})]})]}),(0,se.jsx)(sn.A,{open:ce.open,autoHideDuration:6e3,onClose:()=>xe({...ce,open:!1}),children:(0,se.jsx)(oe.A,{onClose:()=>xe({...ce,open:!1}),severity:ce.severity,sx:{width:"100%"},children:ce.message})})]})}):(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4},children:(0,se.jsx)(oe.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})};var tr=t(52848),nr=t(79381),rr=t(29682),ir=t(92183),ar=t(69149),or=t(51365);const lr=()=>{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,l]=(0,x.useState)(null),[d,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,Fe.A)(),k=(0,Ds.A)(P.breakpoints.down("sm")),{userProfile:F,setUserProfile:D}=Z();(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:T,error:R}=(0,u.I)({queryKey:["getUserProfile",s],queryFn:async()=>{const t=await E(L,{userId:s});return t?.getUserProfile&&(D(t.getUserProfile),setTimeout((()=>{e()}),200)),t},enabled:!!s,onError:e=>{}}),z=Z.getState().userProfile||F||$?.getUserProfile,{data:W,isLoading:O,error:U,refetch:N}=(0,u.I)({queryKey:["userOrders",z?.id],queryFn:()=>E("\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,cs.n)({mutationFn:e=>E(q,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:z.id}),onSuccess:()=>{N(),_(),c("")}}),M=(0,cs.n)({mutationFn:e=>E("\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()}}),_=()=>{r(!1),a(null)},V=e=>{l(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),l={orderId:parseInt(e.id,10),orderItemUpdates:[{orderItemId:parseInt(s.id,10),quantityChange:n}],totalAmount:i,orderTotalAmount:o,taxAmount:a};M.mutate(l)},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(T||O&&z?.id)return(0,se.jsx)(j.A,{sx:{display:"block",mx:"auto",mt:4}});if(R)return(0,se.jsx)(m.A,{color:"error",children:"Error fetching user profile!"});if(U&&z?.id)return(0,se.jsx)(m.A,{color:"error",children:"Error fetching orders!"});const Q=[...W?.getOrdersByUser||[]].sort(((e,s)=>s.id-e.id));return(0,se.jsxs)(h.A,{maxWidth:"xl",sx:{mt:4,px:{xs:1,sm:2,md:3}},children:[(0,se.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,se.jsx)(m.A,{children:"No orders found!"}):(0,se.jsx)(Gt.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,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{sx:{display:{xs:"none",md:"table-cell"}},children:"Order ID"}),(0,se.jsx)(Jt.A,{children:"Address"}),(0,se.jsx)(Jt.A,{children:"Status"}),(0,se.jsx)(Jt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Total"}),(0,se.jsx)(Jt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Delivery Date"}),(0,se.jsx)(Jt.A,{children:"Bill"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:Q.map((e=>(0,se.jsxs)(x.Fragment,{children:[(0,se.jsxs)(Qt.A,{onClick:()=>V(e.id),sx:{cursor:"pointer"},children:[(0,se.jsx)(Jt.A,{sx:{display:{xs:"none",md:"table-cell"}},children:e.id}),(0,se.jsxs)(Jt.A,{children:[k&&(0,se.jsxs)(m.A,{variant:"caption",sx:{fontWeight:700,color:"primary.main",display:"block",mb:.5},children:["Order #",e.id]}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"PICKUP"===e.type?(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(Es.A,{fontSize:"small"}),e.pickupAddress?.address||"Pickup location not specified"]}):(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(js.A,{fontSize:"small"}),e.address?.address||"No address provided"]})})]}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:In.find((s=>s.value===e.status))?.label||e.status,size:k?"small":"medium",color:In.find((s=>s.value===e.status))?.color||"default"})}),(0,se.jsxs)(Jt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:["$",e.totalAmount.toFixed(2)]}),(0,se.jsx)(Jt.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:e.deliveryDate?new Date(e.deliveryDate).toLocaleDateString():"N/A"}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(g.A,{sx:{display:"flex",gap:1},children:(0,se.jsx)(Ce.A,{title:"Download Bill",children:(0,se.jsx)(Ae.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,se.jsx)(nr.A,{})})})})}),(0,se.jsx)(Jt.A,{children:(0,se.jsxs)(g.A,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,se.jsx)(ne.A,{variant:"contained",color:"error",size:k?"small":"medium",onClick:s=>{var t;s.stopPropagation(),t=e.id,a(t),r(!0)},disabled:!Y(e.status),children:"Cancel"}),(0,se.jsx)(Ae.A,{onClick:s=>{s.stopPropagation(),V(e.id)},size:"small",children:o===e.id?(0,se.jsx)(rr.A,{}):(0,se.jsx)(ir.A,{})})]})})]}),(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{style:{paddingBottom:0,paddingTop:0},colSpan:7,children:(0,se.jsx)(tr.A,{in:o===e.id,timeout:"auto",unmountOnExit:!0,children:(0,se.jsx)(g.A,{sx:{margin:{xs:1,sm:2}},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.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,se.jsx)(Es.A,{})," Order Items"]}),(0,se.jsx)(de.A,{sx:{p:{xs:1.5,sm:2}},children:e.orderItems?.edges?.length>0?(0,se.jsx)(fe.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,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(be.A,{variant:"outlined",sx:{p:{xs:1.5,sm:2},"&:hover":{bgcolor:"grey.50"}},children:[(0,se.jsxs)(fe.Ay,{container:!0,spacing:{xs:1,sm:2},alignItems:"center",children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,sm:4,children:[(0,se.jsx)(m.A,{variant:"subtitle1",fontWeight:600,sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:s.product.name}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:500,children:s.product.category.name}),n.length>1&&(0,se.jsxs)(m.A,{variant:"caption",color:"primary",sx:{display:"block",mt:.5},children:[n.length-1," previous version",n.length>2?"s":""]})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:6,sm:2,children:[(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Unit Price"}),(0,se.jsxs)(m.A,{variant:"body1",fontWeight:500,children:["$",t?.price.toFixed(2)]}),t&&(0,se.jsxs)(m.A,{variant:"caption",color:"text.secondary",fontWeight:500,children:[t.measurement," ",t.unit]})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:6,sm:2,children:[(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Quantity"}),f===s.id?(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(p.A,{type:"number",size:"small",value:I,onChange:e=>S(parseInt(e.target.value)||0),inputProps:{min:0},sx:{width:"80px"}}),(0,se.jsxs)(g.A,{sx:{display:"flex",gap:.5},children:[(0,se.jsx)(Ae.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,se.jsx)(ar.A,{fontSize:"small"})}),(0,se.jsx)(Ae.A,{size:"small",color:"error",onClick:K,children:(0,se.jsx)(rs.A,{fontSize:"small"})})]})]}):(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(m.A,{variant:"body1",fontWeight:500,children:s.quantity}),Y(e.status)&&(0,se.jsx)(Ae.A,{size:"small",onClick:()=>{return b((e=s).id),void S(e.quantity);var e},children:(0,se.jsx)(tn.A,{fontSize:"small"})})]})]}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:4,children:(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",sm:"flex-end"},alignItems:"center",gap:1,mt:{xs:1,sm:0}},children:[(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Total:"}),(0,se.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,se.jsx)(Ae.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,se.jsx)(cn.A,{fontSize:"small"})})]})})]}),n.length>1&&(0,se.jsxs)(g.A,{sx:{mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[(0,se.jsxs)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(or.A,{fontSize:"small"}),"Order Change History (",n.length-1," ","changes)"]}),(0,se.jsx)(g.A,{sx:{pl:2},children:n.slice(0,-1).map(((e,s)=>(0,se.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,se.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"120px",fontWeight:500},children:["Change ",s+1]}),(0,se.jsxs)(g.A,{sx:{display:"flex",gap:3},children:[(0,se.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,se.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount: $",e.orderAmount.toFixed(2)]})]})]},e.id)))})]})]})},s.id)}))}):(0,se.jsx)(g.A,{sx:{textAlign:"center",py:3,color:"text.secondary"},children:(0,se.jsx)(m.A,{fontWeight:500,children:"No items found for this order."})})})]}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(de.A,{sx:{p:{xs:1.5,sm:2},mb:3},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,md:6,children:[(0,se.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,se.jsx)(nr.A,{})," Order Details"]}),(0,se.jsxs)(g.A,{sx:{pl:1},children:[e.customOrder&&(0,se.jsxs)(g.A,{sx:{mb:2},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Custom Order Instructions"}),(0,se.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,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Subtotal"}),(0,se.jsxs)(m.A,{fontWeight:500,children:["$",e.totalAmount?e.totalAmount.toFixed(2):"0.00"]})]}),void 0!==e.deliveryFee&&(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Fee"}),(0,se.jsxs)(m.A,{fontWeight:500,children:["$",e.deliveryFee?e.deliveryFee.toFixed(2):"0.00"]})]}),void 0!==e.taxAmount&&(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tax"}),(0,se.jsxs)(m.A,{fontWeight:500,children:["$",e.taxAmount?e.taxAmount.toFixed(2):"0.00"]})]}),void 0!==e.tipAmount&&(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tip"}),(0,se.jsxs)(m.A,{fontWeight:500,children:["$",e.tipAmount?e.tipAmount.toFixed(2):"0.00"]})]}),(0,se.jsx)(ts.A,{sx:{my:1}}),(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Total Amount"}),(0,se.jsxs)(m.A,{variant:"subtitle1",color:"primary",fontWeight:700,children:["$",e.orderTotalAmount?e.orderTotalAmount.toFixed(2):"0.00"]})]})]})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,md:6,children:[(0,se.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,se.jsx)(js.A,{})," Delivery Information"]}),(0,se.jsxs)(g.A,{sx:{pl:1},children:[(0,se.jsxs)(g.A,{sx:{mb:1},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"PICKUP"===e.type?"Pickup Location":"Delivery Address"}),(0,se.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,se.jsxs)(g.A,{sx:{mb:1},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Instructions"}),(0,se.jsx)(m.A,{variant:"body2",fontWeight:500,children:e.deliveryInstructions})]}),e.deliveryDate&&(0,se.jsxs)(g.A,{sx:{mb:1},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,children:"Expected Delivery Date"}),(0,se.jsx)(m.A,{variant:"body2",fontWeight:500,children:new Date(e.deliveryDate).toLocaleDateString()})]}),e.cancelMessage&&(0,se.jsxs)(g.A,{sx:{mb:1},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"error",fontWeight:700,children:"Cancellation Reason"}),(0,se.jsx)(m.A,{variant:"body2",color:"error",fontWeight:500,children:e.cancelMessage})]})]})]})]})})})]})})})})})]},e.id)))})]})}),(0,se.jsxs)(Re.A,{open:n,onClose:_,fullWidth:!0,maxWidth:"sm",children:[(0,se.jsx)(ze.A,{children:"Cancel Order"}),(0,se.jsxs)(We.A,{children:[(0,se.jsx)(Cn.A,{gutterBottom:!0,children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,se.jsx)(p.A,{autoFocus:!0,margin:"dense",id:"cancelMessage",label:"Reason for Cancellation",type:"text",fullWidth:!0,variant:"outlined",value:d,onChange:e=>c(e.target.value),error:n&&!d.trim(),sx:{mt:2}})]}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:_,color:"primary",children:"No, Keep Order"}),(0,se.jsx)(ne.A,{onClick:()=>{i&&d.trim()&&B.mutate({orderId:i,cancelMessage:d.trim()})},color:"error",variant:"contained",disabled:!d.trim()||B.isPending,startIcon:B.isPending?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:B.isPending?"Cancelling...":"Yes, Cancel Order"})]})]}),(0,se.jsxs)(Re.A,{open:C.open,onClose:()=>w({open:!1,title:"",message:"",onConfirm:null}),children:[(0,se.jsx)(ze.A,{children:C.title}),(0,se.jsx)(We.A,{children:(0,se.jsx)(Cn.A,{children:C.message})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>w({open:!1,title:"",message:"",onConfirm:null}),color:"primary",children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:C.onConfirm,color:"error",variant:"contained",children:"Remove"})]})]})]})};var dr=t(55629),cr=t(45402),xr=t(55764);const ur=()=>{const{userProfile:e,setUserProfile:s,fetchUserProfile:t,isProfileLoading:n,profileError:r}=Z(),i=(0,d.Zp)(),[a,o]=(0,x.useState)(0),[l,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}=X(),[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||l;(0,x.useEffect)((()=>{Y?.id&&w(Y.id)}),[Y?.id,w]);const Q=async()=>{try{await(0,Fs.C)(),i("/")}catch(e){}},J=`${b}/signup?referredby=${e?.referralId}`,ee=async()=>{try{await navigator.clipboard.writeText(J),f(!0),setTimeout((()=>f(!1)),2e3)}catch(e){}};if(n)return(0,se.jsx)(h.A,{children:(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:[(0,se.jsx)(j.A,{}),(0,se.jsx)(m.A,{sx:{ml:2},children:"Loading profile..."})]})});if(r)return(0,se.jsxs)(h.A,{children:[(0,se.jsxs)(oe.A,{severity:"error",sx:{mt:4},children:["Error loading profile: ",r]}),(0,se.jsx)(ne.A,{variant:"contained",onClick:()=>t(),sx:{mt:2},children:"Retry"})]});if(!e)return(0,se.jsxs)(h.A,{children:[(0,se.jsx)(oe.A,{severity:"warning",sx:{mt:4},children:"No profile data available. Please try again."}),(0,se.jsx)(ne.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,se.jsxs)(h.A,{maxWidth:"xl",sx:{py:{xs:1,sm:4},px:{xs:.5,sm:2}},children:[(0,se.jsxs)(g.A,{sx:{display:{xs:"block",md:"flex"},gap:{xs:0,md:3}},children:[(0,se.jsxs)(g.A,{sx:{width:{xs:"100%",md:280},mb:{xs:2,md:0}},children:[(0,se.jsxs)(de.A,{elevation:0,sx:{borderRadius:2,overflow:"hidden",boxShadow:1,mb:0,display:{xs:"none",md:"block"}},children:[(0,se.jsx)(g.A,{sx:{p:2,bgcolor:"primary.main",color:"white",textAlign:"left"},children:(0,se.jsx)(m.A,{variant:"h6",sx:{fontSize:"1.25rem"},children:"My Account"})}),(0,se.jsx)(vs.A,{component:"nav",sx:{pt:0},children:[{label:"Profile",icon:(0,se.jsx)(Ps.A,{}),idx:0},{label:"Addresses",icon:(0,se.jsx)(Bt.A,{}),idx:1},{label:"Settings",icon:(0,se.jsx)(xr.A,{}),idx:2}].map((e=>(0,se.jsxs)(At.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,se.jsx)(Ss.A,{sx:{minWidth:0,mr:2,justifyContent:"center"},children:x.cloneElement(e.icon,{color:a===e.idx?"primary":"inherit"})}),(0,se.jsx)(Cs.A,{primary:e.label})]},e.label)))})]}),(0,se.jsxs)(de.A,{elevation:0,sx:{borderRadius:0,overflow:"hidden",boxShadow:0,mb:1,display:{xs:"block",md:"none"}},children:[(0,se.jsx)(g.A,{sx:{p:2,bgcolor:"primary.main",color:"white",textAlign:"center"},children:(0,se.jsx)(m.A,{variant:"h6",sx:{fontSize:"1.1rem"},children:"My Account"})}),(0,se.jsx)(vs.A,{component:"nav",sx:{pt:0,display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center"},children:[{label:"Profile",icon:Ps.A,idx:0},{label:"Addresses",icon:Bt.A,idx:1},{label:"Settings",icon:xr.A,idx:2}].map((e=>(0,se.jsx)(At.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,se.jsx)(Ss.A,{sx:{minWidth:0,mr:0,justifyContent:"center"},children:(0,se.jsx)(e.icon,{sx:{fontSize:28,color:a===e.idx?"primary.main":"text.secondary"}})})},e.label)))})]})]}),(0,se.jsx)(g.A,{sx:{flexGrow:1,width:{xs:"100%",md:"auto"}},children:(0,se.jsxs)(g.A,{sx:{height:"100%"},children:[0===a&&(0,se.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,se.jsx)(be.A,{sx:{height:"100%",width:{xs:"100%",sm:"auto"},p:{xs:1,sm:0},boxShadow:{xs:2,sm:1}},children:(0,se.jsxs)(Ie.A,{sx:{p:{xs:1,sm:2}},children:[(0,se.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,se.jsx)(gt.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,se.jsxs)(g.A,{sx:{textAlign:{xs:"center",sm:"left"},width:"100%"},children:[(0,se.jsxs)(m.A,{variant:"h5",gutterBottom:!0,sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"},fontWeight:700},children:[e?.firstName," ",e?.lastName]}),(0,se.jsxs)(ss.A,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",flexWrap:"wrap",sx:{rowGap:1,justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,se.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,se.jsx)(mn.A,{sx:{mr:1,color:"primary.main",fontSize:22}}),(0,se.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,se.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,se.jsx)(un.A,{sx:{mr:1,color:"secondary.main",fontSize:22}}),(0,se.jsx)(m.A,{sx:{color:"text.primary",fontWeight:500,fontSize:{xs:"1.1rem",sm:"1.08rem"}},children:e.mobile})]})]})]})]}),(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,sx:{textAlign:{xs:"center",sm:"left"},fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:"Referral Program"}),(0,se.jsxs)(g.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"stretch",sm:"center"},gap:2},children:[(0,se.jsx)(p.A,{fullWidth:!0,value:J,InputProps:{readOnly:!0,endAdornment:(0,se.jsx)(Ce.A,{title:y?"Copied!":"Copy referral link",children:(0,se.jsx)(Ae.A,{onClick:ee,children:(0,se.jsx)(dr.A,{})})})},sx:{mb:{xs:1,sm:0}}}),(0,se.jsx)(ne.A,{variant:"contained",startIcon:(0,se.jsx)(cr.A,{}),onClick:ee,sx:{width:{xs:"100%",sm:"auto"},py:1},children:"Share"})]})]})})}),1===a&&(0,se.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,se.jsx)(be.A,{sx:{height:"100%"},children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,se.jsx)(m.A,{variant:"h6",children:"My Addresses"}),(0,se.jsx)(ne.A,{variant:"contained",startIcon:(0,se.jsx)(Pe.A,{}),onClick:()=>L(!0),children:"Add Address"})]}),P?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",p:4},children:(0,se.jsx)(j.A,{})}):e.length>0?(0,se.jsx)(fe.Ay,{container:!0,spacing:2,children:e.map((e=>(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:6,children:(0,se.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,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[(0,se.jsx)(m.A,{variant:"subtitle2",color:"primary",children:e.isPrimary?"Primary Address":"Secondary Address"}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(Ae.A,{size:"small",onClick:()=>(e=>{T(e),R(e.address),W(e.isPrimary),L(!0)})(e),children:(0,se.jsx)(tn.A,{fontSize:"small"})}),(0,se.jsx)(Ae.A,{size:"small",onClick:()=>{return s=e.id,K(s),void H(!0);var s},children:(0,se.jsx)(cn.A,{fontSize:"small"})})]})]}),(0,se.jsx)(m.A,{variant:"body2",children:e.address})]})},e.id)))}):(0,se.jsx)(oe.A,{severity:"info",sx:{mt:2},children:"You don't have any addresses yet. Add one to get started!"})]})})})()}),2===a&&(0,se.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,se.jsx)(be.A,{sx:{height:"100%"},children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Account Settings"}),(0,se.jsxs)(ss.A,{spacing:3,children:[(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Notification Preferences"}),(0,se.jsx)(ps.A,{control:(0,se.jsx)(Hn.A,{defaultChecked:!0}),label:"Email notifications for orders"}),(0,se.jsx)(ps.A,{control:(0,se.jsx)(Hn.A,{defaultChecked:!0}),label:"SMS notifications for delivery updates"})]}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Privacy Settings"}),(0,se.jsx)(ps.A,{control:(0,se.jsx)(Hn.A,{defaultChecked:!0}),label:"Share order history with delivery partners"})]}),(0,se.jsx)(g.A,{children:(0,se.jsx)(ne.A,{variant:"outlined",color:"error",startIcon:(0,se.jsx)(_t.A,{}),onClick:Q,sx:{mt:2},children:"Logout"})})]})]})})})]})})]}),(0,se.jsxs)(Re.A,{open:D,onClose:()=>L(!1),fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:$?"Edit Address":"Add Address"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(ss.A,{spacing:2,mt:1,children:[(0,se.jsx)(wt,{value:q,onChange:R,onValidAddress:B}),(0,se.jsx)(ps.A,{control:(0,se.jsx)(Hn.A,{checked:z,onChange:e=>W(e.target.checked)}),label:"Set as Primary Address"})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{L(!1),R(""),B(!1)},children:"Cancel"}),(0,se.jsx)(ne.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),_({open:!0,message:"Address updated as primary",severity:"success"})}else{$.isPrimary&&1===I.filter((e=>e.isPrimary)).length?(await E($.id,q,!0),_({open:!0,message:"At least one address must be primary",severity:"warning"})):(await E($.id,q,!1),_({open:!0,message:"Address updated as secondary",severity:"success"}))}else if(0===I.length)await k(q,Y.id,!0),_({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),_({open:!0,message:"Address added as primary",severity:"success"})}else await k(q,Y.id,!1),_({open:!0,message:"Address added as secondary",severity:"success"});await w(Y.id),L(!1),T(null),R(""),W(!1),B(!1)}catch(e){_({open:!0,message:"Failed to save address. Please try again.",severity:"error"})}finally{U(!1)}}else _({open:!0,message:"Could not save address: user information not available",severity:"error"})},variant:"contained",disabled:!q||O||!N,children:O?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(j.A,{size:20,sx:{mr:1}})," Saving..."]}):"Save"})]})]}),(0,se.jsxs)(Re.A,{open:V,onClose:()=>H(!1),children:[(0,se.jsx)(ze.A,{children:"Delete Address"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(m.A,{children:"Are you sure you want to delete this address? This action cannot be undone."})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>H(!1),disabled:P,children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:async()=>{try{await F(G),_({open:!0,message:"Address deleted successfully",severity:"success"})}catch(e){_({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,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:P?"Deleting...":"Delete"})]})]}),(0,se.jsx)(sn.A,{open:M.open,autoHideDuration:3e3,onClose:()=>_({...M,open:!1}),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,se.jsx)(oe.A,{onClose:()=>_({...M,open:!1}),severity:M.severity,sx:{width:"100%"},children:M.message})})]})},mr=()=>{const e=(0,d.Zp)();return(0,se.jsx)(h.A,{maxWidth:"md",children:(0,se.jsx)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,se.jsxs)(de.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,se.jsx)(m.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,se.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,se.jsx)(ne.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(zs),children:"Go to Dashboard"})]})})})},hr=()=>{const e=(0,d.Zp)();return(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{maxWidth:"md",children:(0,se.jsx)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,se.jsxs)(de.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,se.jsx)(m.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,se.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,se.jsx)(ne.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(zs),children:"Go to Dashboard"})]})})})})},pr=e=>{let{open:s,onClose:t,selectedFee:n,onUpdate:r,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,l]=(0,x.useState)(a);(0,x.useEffect)((()=>{n?l({feeCurrency:n.feeCurrency||"",feeRate:n.feeRate?.toString()||"",limit:n.limit?.toString()||"",type:n.type?.toUpperCase()||"DELIVERY"}):s&&l(a)}),[n,s]),(0,x.useEffect)((()=>{s||l(a)}),[s]);const d=e=>{const{name:s,value:t}=e.target;l((e=>({...e,[s]:t})))};return(0,se.jsxs)(Re.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:n?"Edit Fee":"Add New Fee"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,se.jsxs)(us.A,{fullWidth:!0,children:[(0,se.jsx)(Xt.A,{children:"Fee Type"}),(0,se.jsxs)(en.A,{name:"type",value:o.type,onChange:d,label:"Fee Type",children:[(0,se.jsx)(je.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,se.jsx)(je.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,se.jsx)(p.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:d,fullWidth:!0,placeholder:"e.g., USD"}),(0,se.jsx)(p.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,se.jsx)(p.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:t,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",onClick:()=>{r({id:n?.id,...o,feeRate:parseFloat(o.feeRate),limit:parseFloat(o.limit)}),n||l(a)},disabled:i,startIcon:i?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:i?n?"Updating...":"Adding...":"Save"})]})]})},Ar=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=Z(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,p]=(0,x.useState)(""),[A,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Hs.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await E("\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:()=>E("\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:k,refetch:F}=(0,u.I)({queryKey:["getFeesByStore",C?.id],queryFn:()=>E("\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,cs.n)({mutationFn:e=>E("\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,cs.n)({mutationFn:e=>E("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{F(),d(!1),i(null),y("Fee deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error deleting fee: ${e.message}`)}}),T=(0,cs.n)({mutationFn:e=>E("\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,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})})}):S||k?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4},children:(0,se.jsxs)(oe.A,{severity:"error",children:["Error loading data: ",S?.message||k?.message]})})}):(0,se.jsx)(er,{children:(0,se.jsxs)(h.A,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Delivery Fees Management"}),A&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:A}),c&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:c}),(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,se.jsx)(m.A,{variant:"h5",children:"Fees"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:T.isPending||T.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):(0,se.jsx)(Pe.A,{}),onClick:()=>{i(null),o(!0)},disabled:T.isPending||T.isLoading,children:T.isPending||T.isLoading?"Adding...":"Add Fee"})]}),(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Type"}),(0,se.jsx)(Jt.A,{children:"Currency"}),(0,se.jsx)(Jt.A,{children:"Rate"}),(0,se.jsx)(Jt.A,{children:"Limit"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:D.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.type}),(0,se.jsx)(Jt.A,{children:e.feeCurrency}),(0,se.jsx)(Jt.A,{children:e.feeRate}),(0,se.jsx)(Jt.A,{children:e.limit}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,se.jsx)(tn.A,{})}),(0,se.jsx)(Ae.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,se.jsx)(cn.A,{})})]})]},e.id)))})]})})]}),(0,se.jsx)(pr,{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,se.jsxs)(Re.A,{open:l,onClose:()=>{d(!1),i(null),p("")},children:[(0,se.jsx)(ze.A,{children:"Delete Fee"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(m.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{d(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})})};var gr=t(95952);const jr=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:n}=Z(),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(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,Hs.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 E(L,{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:()=>E("\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:k,error:F,refetch:D}=(0,u.I)({queryKey:["storeSquareStatus",w?.id],queryFn:()=>E("\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,cs.n)({mutationFn:e=>E("\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,cs.n)({mutationFn:e=>E("\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"),D()):(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,cs.n)({mutationFn:e=>E("\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"),D(),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"),D(),window.history.replaceState({},"","/store_manager/payment-settings")):t&&(y("error"),p(`OAuth error: ${decodeURIComponent(t)}`),window.history.replaceState({},"","/store_manager/payment-settings"))}),[D]),(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||k?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})})}):S||F?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4},children:(0,se.jsxs)(oe.A,{severity:"error",children:["Error loading data: ",S?.message||F?.message]})})}):w?(0,se.jsx)(er,{children:(0,se.jsxs)(h.A,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Payment Settings"}),(0,se.jsxs)(de.A,{elevation:3,sx:{p:3},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,se.jsx)(ns.A,{sx:{mr:1,fontSize:32}}),(0,se.jsx)(m.A,{variant:"h5",children:"Square Payment Connection"})]}),c&&(0,se.jsx)(oe.A,{severity:A,sx:{mb:3},onClose:()=>p(null),children:c}),(0,se.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,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1},children:[(0,se.jsx)("strong",{children:"Store:"})," ",w.name]}),(0,se.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2},children:[(0,se.jsx)("strong",{children:"Connection Status:"})," ",$?.isConnected?(0,se.jsx)(De.A,{label:"Connected",color:"success",size:"small",icon:(0,se.jsx)(wn.A,{})}):(0,se.jsx)(De.A,{label:"Not Connected",color:"default",size:"small",icon:(0,se.jsx)(Pn.A,{})})]}),$?.isConnected&&$?.merchantId&&(0,se.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2},children:[(0,se.jsx)("strong",{children:"Merchant ID:"})," ",$.merchantId]})]}),(0,se.jsx)(g.A,{children:$?.isConnected?(0,se.jsx)(ne.A,{variant:"outlined",color:"error",onClick:()=>{i(!0)},disabled:q.isPending,startIcon:q.isPending&&(0,se.jsx)(j.A,{size:16}),children:q.isPending?"Disconnecting...":"Disconnect Square"}):(0,se.jsx)(ne.A,{variant:"contained",color:"primary",onClick:()=>{w?.id&&T.mutate(w.id)},disabled:T.isPending,startIcon:T.isPending&&(0,se.jsx)(j.A,{size:16}),children:T.isPending?"Connecting...":"Connect Square Account"})})]}),(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mt:3},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,se.jsx)(gr.A,{sx:{mr:1,fontSize:32}}),(0,se.jsx)(m.A,{variant:"h5",children:"Cash on Delivery"})]}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Accept cash payments when orders are delivered"}),(0,se.jsx)(ps.A,{control:(0,se.jsx)(an.A,{checked:w?.codEnabled||!1,onChange:e=>{d(e.target.checked),o(!0)},disabled:R.isPending,color:"primary"}),label:w?.codEnabled?"Enabled":"Disabled"})]}),(0,se.jsxs)(Re.A,{open:r,onClose:z,children:[(0,se.jsx)(ze.A,{children:"Disconnect Square?"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(Cn.A,{children:["Are you sure you want to disconnect Square for ",(0,se.jsx)("strong",{children:w.name}),"?",(0,se.jsx)("br",{}),(0,se.jsx)("br",{}),"Customers will not be able to make card payments until you reconnect."]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:z,disabled:q.isPending,children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{w?.id&&q.mutate(w.id)},color:"error",variant:"contained",disabled:q.isPending,startIcon:q.isPending&&(0,se.jsx)(j.A,{size:16}),children:q.isPending?"Disconnecting...":"Disconnect"})]})]}),(0,se.jsxs)(Re.A,{open:a,onClose:W,children:[(0,se.jsxs)(ze.A,{children:[l?"Enable":"Disable"," Cash on Delivery?"]}),(0,se.jsx)(We.A,{children:(0,se.jsx)(Cn.A,{children:l?`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,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:W,disabled:R.isPending,children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:()=>{w?.id&&R.mutate({storeId:w.id,enabled:l}),o(!1)},variant:"contained",color:l?"primary":"error",disabled:R.isPending,startIcon:R.isPending&&(0,se.jsx)(j.A,{size:16}),children:R.isPending?"Saving...":"Confirm"})]})]})]})}):(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4},children:(0,se.jsx)(oe.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})},yr=()=>{const e=(0,d.Zp)(),{user:s,setUser:t}=Z(),[n,i]=(0,x.useState)(!0),a=(0,Fe.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,se.jsx)(xe,{}):(0,se.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,se.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,se.jsxs)(g.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,se.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,se.jsx)(m.A,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"Sign in to continue your journey with us"})]}),(0,se.jsx)(Js,{}),(0,se.jsxs)(g.A,{sx:{mt:4,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:[(0,se.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,se.jsxs)(m.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:["Don't have an account?"," ",(0,se.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 fr=(0,t(11848).Ay)(p.A)((e=>{let{theme:s}=e;return{"& .MuiInputBase-root":{minHeight:"120px"}}})),br=e=>{let{sectionHeaders:s,answers:t={},onChangeAnswers:n,onSubmit:r}=e;const[i,a]=(0,x.useState)(!1),[o,l]=(0,x.useState)(!1),d=()=>Object.values(t).some((e=>e&&""!==e.trim()));return(0,se.jsxs)(g.A,{sx:{width:"100%"},children:[(0,se.jsx)(fe.Ay,{container:!0,spacing:3,children:s.map(((e,s)=>(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.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,se.jsx)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,color:"primary.main",letterSpacing:.2},children:e}),(0,se.jsx)(fr,{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,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"flex-end",mt:4},children:(0,se.jsx)(ne.A,{variant:"contained",color:"primary",size:"large",disabled:!d(),sx:{px:5,py:1.5,fontWeight:600,borderRadius:2,boxShadow:1,opacity:d()?1:.6},onClick:()=>{if(!d())return;const e=(()=>{if(!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),l(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,se.jsxs)(Re.A,{open:i,onClose:()=>a(!1),PaperProps:{sx:{borderRadius:2,minWidth:"300px"}},children:[(0,se.jsxs)(ze.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(is.A,{color:"success",sx:{fontSize:28}}),(0,se.jsx)(m.A,{variant:"h6",sx:{fontWeight:600},children:o?"Items Edited":"Items Added"})]}),(0,se.jsx)(Ae.A,{onClick:()=>a(!1),size:"small",sx:{color:"text.secondary"},children:(0,se.jsx)(rs.A,{})})]}),(0,se.jsx)(We.A,{children:(0,se.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,se.jsx)(Oe.A,{sx:{px:3,pb:2},children:(0,se.jsx)(ne.A,{variant:"contained",onClick:()=>a(!1),sx:{borderRadius:2,textTransform:"none",px:3},children:"Okay"})})]})]})};function vr(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 Ir=()=>{const[e,s]=(0,x.useState)(!1),[t,n]=(0,x.useState)(!1),[r,i]=(0,x.useState)(!1),{selectedStore:a,setAvailableStores:o,setSelectedStore:l,pickupAddress:d,setCustomOrder:c,listInputAnswers:m,setListInputAnswers:h}=ee();!function(){const e=Z((e=>e.userProfile)),s=ee((e=>e.selectedStore)),t=ee((e=>e.restoreCart)),n=ee((e=>e.getCartState)),r=(0,x.useRef)(!1),i=(0,x.useRef)(null),a=(0,x.useRef)(null),o=(0,x.useRef)(null),l=(0,x.useRef)(!1),d=e?.id,c=s?.id;(0,x.useEffect)((()=>{if(!d||!c)return void(r.current=!1);const e=i.current!==d,s=a.current!==c;if(i.current=d,a.current=c,!e&&!s&&r.current)return;let o=!1;return async function(){try{const e=await E("\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:d,storeId:c});if(o)return;const s=e?.getSavedCart,r=n(),i=vr(r);if(i&&s?.cartData){t(s.cartData);try{localStorage.setItem(`indimitra-cart-store-${c}`,JSON.stringify(s.cartData))}catch(e){}}else i||await E(O,{userId:d,storeId:c,cartData:r})}catch(e){}finally{o||(r.current=!0)}}(),()=>{o=!0}}),[d,c]),(0,x.useEffect)((()=>{if(!d||!c)return;const e=ee.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(!l.current){l.current=!0;try{const e=ee.getState().getCartState(),s=i.current,t=a.current;if(!s||!t)return;try{localStorage.setItem(`indimitra-cart-store-${t}`,JSON.stringify(e))}catch(e){}vr(e)?await E(U,{userId:s,storeId:t}):await E(O,{userId:s,storeId:t,cartData:e})}catch(e){}finally{l.current=!1}}}),1e3))}));return()=>{e(),o.current&&clearTimeout(o.current)}}),[d,c])}();const{data:p,isLoading:A,error:g}=(0,u.I)({queryKey:["stores"],queryFn:async()=>await E(R)});(0,x.useEffect)((()=>{if(p?.stores&&p.stores.length>0){o(p.stores);const e=localStorage.getItem("selectedStoreId");if(e){const t=p.stores.find((s=>String(s.id)===e));a&&a.id===t?.id||(t?l(t):(localStorage.removeItem("selectedStoreId"),s(!0)))}else a||s(!0)}}),[p,a,o]);if(A)return(0,se.jsx)(te,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:(0,se.jsx)(xe,{})});const j=a?.sectionHeaders?.length>0;return(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(kt,{open:e,onClose:()=>s(!1)}),a&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(pe,{children:(0,se.jsxs)(te,{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,se.jsxs)(te,{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,se.jsxs)(te,{sx:{mb:{xs:1,sm:0}},children:[(0,se.jsx)(ae,{variant:"h6",sx:{fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:a.name}),(0,se.jsx)(ae,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:a.address})]}),d&&(0,se.jsxs)(re,{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,se.jsx)(ae,{variant:"subtitle2",color:"primary",sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:"Change Pickup Location"}),(0,se.jsx)(ae,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.85rem",sm:"0.95rem"}},children:d.address})]})]}),(0,se.jsxs)(te,{sx:{mt:1,display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",gap:{xs:.5,sm:2}},children:[(0,se.jsx)(ae,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:a.description}),(0,se.jsx)(ae,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:a.tnc})]})]})}),(0,se.jsx)(kt,{open:t,onClose:()=>n(!1),forceStep:"pickup",initialStore:a}),(0,se.jsx)(pe,{children:(0,se.jsx)(es,{images:a?.images})}),(0,se.jsxs)(pe,{children:[j&&(0,se.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,se.jsxs)(te,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},gap:{xs:1,sm:0}},children:[(0,se.jsx)(ae,{variant:"h6",sx:{fontWeight:600,fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:r?"Browse Products":"Quick List Entry"}),(0,se.jsx)(te,{sx:{minWidth:{xs:0,sm:200},display:"flex",alignItems:"center",justifyContent:{xs:"flex-start",sm:"flex-end"},width:{xs:"100%",sm:"auto"}},children:(0,se.jsx)(ps.A,{control:(0,se.jsx)(an.A,{checked:r,onChange:()=>{i(!r)},color:"primary"}),label:(0,se.jsx)(ae,{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}}})})]})}),j&&!r?(0,se.jsx)(br,{sectionHeaders:a.sectionHeaders,answers:m,onChangeAnswers:h,onSubmit:c}):(0,se.jsx)(bs,{})]})]})]})};var Sr=t(37483),Cr=t(28211),wr=t(51694),Pr=t(85916),kr=t(11692),Er=t(2183);const Fr=e=>{let{size:s=24,sx:t}=e;return(0,se.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,l]=(0,x.useState)(""),{mutate:d,isPending:c}=(0,cs.n)({mutationFn:e=>E("\n mutation UpdateSecondaryPhone($userId: Int!, $secondaryPhone: String) {\n updateSecondaryPhone(userId: $userId, secondaryPhone: $secondaryPhone) {\n active\n }\n }\n",e),onSuccess:()=>{t(),r(!1),a(""),l("")},onError:e=>{l("Failed to update phone number. Please try again.")}});return s?(0,se.jsx)(g.A,{sx:{mb:3},children:n?(0,se.jsxs)(de.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(un.A,{color:"primary"}),(0,se.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:s.secondaryPhone?"Update Number":"Add Number"})]}),(0,se.jsx)(p.A,{size:"small",value:i,onChange:e=>{const s=e.target.value.replace(/\D/g,"").slice(0,10);a(s),l("")},placeholder:"Enter 10-digit number",error:!!o,helperText:o,InputProps:{startAdornment:(0,se.jsx)(m.A,{sx:{mr:1},children:"+1"})}}),(0,se.jsxs)(g.A,{sx:{display:"flex",gap:1},children:[(0,se.jsx)(ne.A,{variant:"contained",size:"small",onClick:()=>{10===i.length?d({userId:s.id,secondaryPhone:i}):l("Please enter a valid 10-digit phone number")},disabled:c||10!==i.length,startIcon:c?(0,se.jsx)(Fr,{size:20}):(0,se.jsx)(un.A,{}),children:c?"Saving...":"Save"}),(0,se.jsx)(ne.A,{variant:"outlined",size:"small",onClick:()=>{r(!1),a(""),l("")},children:"Cancel"})]})]}):(0,se.jsxs)(de.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(un.A,{color:"primary"}),(0,se.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Secondary Contact"}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"(Update if you want to change)"})]}),s.secondaryPhone?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsxs)(m.A,{variant:"body1",children:["+1 ",s.secondaryPhone]}),(0,se.jsx)(ne.A,{variant:"outlined",size:"small",onClick:()=>r(!0),startIcon:(0,se.jsx)(un.A,{}),sx:{alignSelf:"flex-start"},children:"Change Number"})]}):(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"No secondary number added"}),(0,se.jsx)(ne.A,{variant:"outlined",size:"small",onClick:()=>r(!0),startIcon:(0,se.jsx)(un.A,{}),sx:{alignSelf:"flex-start"},children:"Add Number"})]})]})}):null},Lr=()=>{const{cart:e,removeFromCart:s,addToCart:t,cartTotal:n,clearCart:i,selectedStore:o,getCartTotals:l,setTipAmount:c,customOrder:h,setCustomOrder:y,pickupAddress:f,setPickupAddress:b,deliveryType:I,setDeliveryType:S,tipAmount:C,setListInputAnswers:w}=ee(),[P,k]=(0,x.useState)(""),[F,D]=(0,x.useState)(!1),[L,$]=(0,x.useState)(""),{user:T,userProfile:q,fetchUserProfile:R,isProfileLoading:z,setModalOpen:W,setCurrentForm:O}=Z(),N=(0,d.Zp)(),B=(0,a.jE)(),[M,_]=(0,x.useState)(0),[V,H]=(0,x.useState)(""),[G,K]=(0,x.useState)(f?String(f.id):null),[Y,Q]=(0,x.useState)(!1),[J,te]=(0,x.useState)(!1),[re,ie]=(0,x.useState)(null),[ae,oe]=(0,x.useState)(!(!f&&"delivery"!==I)),le=(0,x.useCallback)((async()=>{if(i(),y(""),w({}),o?.id)try{localStorage.removeItem(`indimitra-cart-store-${o.id}`)}catch(e){}if(q?.id&&o?.id)try{await E(U,{userId:q.id,storeId:o.id}),await new Promise((e=>setTimeout(e,100)))}catch(e){}}),[i,y,w,o,q]);(0,x.useEffect)((()=>{(async()=>{const e=await(0,v.$)(),s=e?.tokens?.idToken?.payload?.sub;s&&await R(s)})()}),[R,T]);const{addresses:ce,selectedAddressId:xe,setSelectedAddressId:ue,fetchAddresses:me,isLoading:he,createAddress:pe}=X(),{data:ge,isLoading:ye}=(0,u.I)({queryKey:["storePaymentConfig",o?.id],queryFn:async()=>E("\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}),ve=ge?.storePaymentConfig||null,[Se,Ce]=(0,x.useState)(!1),[ke,Ee]=(0,x.useState)(""),[Fe,De]=(0,x.useState)(!1),[Le,$e]=(0,x.useState)(!1),[Te,qe]=(0,x.useState)(!1),[Re,ze]=(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)((()=>{q?.id&&me(q.id)}),[q?.id,me]),(0,x.useEffect)((()=>{f&&(K(String(f.id)),S("pickup"),ue(null),oe(!0))}),[f,S,ue]),(0,x.useEffect)((()=>{const e=l();ze(e)}),[I,e,l,C]);const{subtotal:We,deliveryFee:Oe,taxAmount:Ue,taxPercentage:Ne,tipAmount:Be,total:Me}=Re;(0,x.useEffect)((()=>{if(!ae){if(o?.pickupAddresses?.edges?.length>0&&!G&&!xe){const e=o.pickupAddresses.edges[0].node;return K(String(e.id)),S("pickup"),void ue(null)}if(ce&&ce.length>0&&!G&&!xe){const e=ce.find((e=>e.isPrimary))||ce[0];return ue(e.id),S("delivery"),void K(null)}o?.pickupAddresses?.edges?.length&&0!==o?.pickupAddresses?.edges?.length||ce&&0!==ce.length||G||xe||S("delivery")}}),[o?.pickupAddresses?.edges,ce,ae]);const{mutate:_e,isPending:Ve}=(0,cs.n)({mutationKey:["createOrder"],mutationFn:async e=>{const s=ee.getState().selectedStore;return E("\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;s&&s.id?(await le(),D(!0),setTimeout((()=>{D(!1),N("/")}),2e3),B.invalidateQueries(["userAddresses",q.id])):$("Order creation failed. Your cart has been preserved. Please try again.")},onError:e=>{$(e.message||"Failed to place order. Please try again.")}}),{mutate:He,isPending:Ge}=(0,cs.n)({mutationFn:async e=>E("\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;s&&s.id?(await le(),D(!0),setTimeout((()=>{D(!1),N("/")}),2e3)):$("Order creation failed. Your cart has been preserved. Please try again.")},onError:e=>{$(e.message||"Failed to place order. Please try again.")}}),Ke=(0,x.useCallback)((()=>{te(!1)}),[]),Ye=(0,x.useCallback)((async e=>{e&&e.id?(await le(),D(!0),setTimeout((()=>{D(!1),N("/")}),2e3)):$("Order creation failed. Your cart has been preserved. Please try again.")}),[le,N]),Je=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity})));return(0,se.jsxs)(g.A,{sx:{padding:3},children:[(0,se.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,se.jsx)(Es.A,{})," Your Shopping Cart"]}),F?(0,se.jsxs)(de.A,{elevation:4,sx:{mb:3,p:4,display:"flex",flexDirection:"column",alignItems:"center",borderRadius:3,background:"linear-gradient(135deg, #e0ffe8 0%, #f8fff8 100%)",boxShadow:6,border:"2px solid #4caf50"},children:[(0,se.jsx)(is.A,{sx:{fontSize:64,color:"success.main",mb:2}}),(0,se.jsx)(m.A,{variant:"h4",sx:{fontWeight:700,color:"success.main",mb:1},children:"Order placed successfully!"}),(0,se.jsx)(m.A,{variant:"h6",sx:{color:"text.secondary",mb:2,textAlign:"center"},children:"Thank you for your purchase. Your order is being processed and you'll receive an update soon!"})]}):(0,se.jsxs)(fe.Ay,{container:!0,spacing:3,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:8,children:(0,se.jsxs)(de.A,{elevation:2,sx:{p:3,mb:3},children:[L&&(0,se.jsx)(Qe,{error:L,title:"Order Error",severity:"error"}),Object.values(e).length>0||h?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(m.A,{variant:"h6",sx:{mb:2,fontWeight:500},children:"Cart Items"}),Object.values(e).map((e=>(0,se.jsx)(be.A,{sx:{mb:2,position:"relative"},children:(0,se.jsx)(Ie.A,{children:(0,se.jsxs)(fe.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:4,children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:2,flexDirection:{xs:"column",sm:"row"},justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,se.jsx)("img",{src:e.image,alt:e.name,style:{width:"48px",height:"48px",objectFit:"cover",borderRadius:8,marginBottom:4}}),(0,se.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500,textAlign:{xs:"center",sm:"left"},fontSize:{xs:"1rem",sm:"1.1rem"}},children:e.name})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,sm:3,children:(0,se.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,se.jsx)(fe.Ay,{item:!0,xs:6,sm:3,children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:1,justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,se.jsx)(Ae.A,{size:"small",onClick:()=>s(e.id),sx:{border:"1px solid",borderColor:"divider",width:32,height:32},children:(0,se.jsx)(we.A,{fontSize:"small"})}),(0,se.jsx)(m.A,{sx:{minWidth:32,textAlign:"center",fontSize:{xs:"1rem",sm:"1.1rem"}},children:e.quantity}),(0,se.jsx)(Ae.A,{size:"small",onClick:()=>t(e),sx:{border:"1px solid",borderColor:"divider",width:32,height:32},children:(0,se.jsx)(Pe.A,{fontSize:"small"})})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:2,children:(0,se.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,se.jsx)(be.A,{sx:{mb:2,position:"relative",bgcolor:"primary.lighter"},children:(0,se.jsxs)(Ie.A,{children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:2,mb:2},children:[(0,se.jsx)(Es.A,{color:"primary"}),(0,se.jsx)(m.A,{variant:"h6",sx:{fontWeight:600,color:"primary.main"},children:"Custom Shopping List"})]}),(0,se.jsx)(g.A,{sx:{p:2,bgcolor:"background.paper",borderRadius:1,border:"1px solid",borderColor:"divider"},children:(0,se.jsx)(m.A,{variant:"body1",sx:{whiteSpace:"pre-line",fontFamily:"monospace",lineHeight:1.6},children:h})}),(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"flex-end",mt:2},children:(0,se.jsx)(ne.A,{variant:"outlined",color:"error",size:"small",onClick:()=>y(""),startIcon:(0,se.jsx)(we.A,{}),children:"Remove List"})})]})})]}):(0,se.jsxs)(g.A,{sx:{textAlign:"center",py:4},children:[(0,se.jsx)(Es.A,{sx:{fontSize:60,color:"text.secondary",mb:2}}),(0,se.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"Your cart is empty"}),(0,se.jsx)(ne.A,{variant:"contained",component:r.N_,to:"/",startIcon:(0,se.jsx)(Es.A,{}),children:"Continue Shopping"})]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(de.A,{elevation:2,sx:{p:3,position:"sticky",top:24},children:[(0,se.jsx)(m.A,{variant:"h6",sx:{mb:3,fontWeight:500},children:"Order Summary"}),q&&(0,se.jsx)(g.A,{sx:{mb:3},children:(0,se.jsx)(Dr,{userProfile:q,onPhoneUpdate:()=>{(async()=>{const e=await(0,v.$)(),s=e?.tokens?.idToken?.payload?.sub;s&&await R(s)})()}})}),(0,se.jsx)(g.A,{sx:{mt:3},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,se.jsx)(m.A,{children:"Subtotal"}),(0,se.jsxs)(m.A,{children:["$",We.toFixed(2)]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,se.jsx)(m.A,{children:"Delivery Fee"}),(0,se.jsxs)(m.A,{children:["$",Oe.toFixed(2)]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Tax Rate"}),(0,se.jsxs)(m.A,{children:[Ne.toFixed(1),"%"]})]}),(0,se.jsxs)(g.A,{sx:{textAlign:"right"},children:[(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Tax Amount"}),(0,se.jsxs)(m.A,{children:["$",Ue.toFixed(2)]})]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(g.A,{sx:{mb:2},children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Add Tip"}),(0,se.jsxs)(Sr.A,{value:M,exclusive:!0,onChange:(e,s)=>{if(null!==s){_(s),H("");c(We*s/100)}},"aria-label":"tip percentage",size:"small",fullWidth:!0,sx:{mb:1},children:[(0,se.jsx)(Cr.A,{value:0,"aria-label":"no tip",children:"No Tip"}),(0,se.jsx)(Cr.A,{value:10,"aria-label":"10%",children:"10%"}),(0,se.jsx)(Cr.A,{value:15,"aria-label":"15%",children:"15%"}),(0,se.jsx)(Cr.A,{value:20,"aria-label":"20%",children:"20%"})]}),(0,se.jsx)(p.A,{fullWidth:!0,size:"small",label:"Custom Tip Amount",type:"number",value:V,onChange:e=>{const s=e.target.value;H(s),_(0);const t=parseFloat(s)||0;c(t)},InputProps:{startAdornment:(0,se.jsx)(m.A,{sx:{mr:1},children:"$"})},placeholder:"Enter custom amount",sx:{mt:1}})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,se.jsx)(m.A,{children:"Tip Amount"}),(0,se.jsxs)(m.A,{children:["$",Be.toFixed(2)]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(ts.A,{})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,se.jsx)(m.A,{variant:"h6",children:"Total"}),(0,se.jsxs)(m.A,{variant:"h6",children:["$",Me.toFixed(2)]})]})})]})}),h&&(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(Es.A,{})," Custom Order Details"]}),(0,se.jsx)(de.A,{elevation:0,sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:2,backgroundColor:"background.paper"},children:(0,se.jsx)(m.A,{variant:"body2",sx:{whiteSpace:"pre-line",color:"text.secondary",fontFamily:"monospace"},children:h})})]}),q&&(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(js.A,{})," Delivery/Pickup Options"]}),z?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,se.jsx)(Fr,{size:24})}):(0,se.jsxs)(ss.A,{spacing:3,children:[o?.pickupAddresses?.edges?.length>0&&(0,se.jsxs)(de.A,{elevation:"pickup"===I?4:1,sx:{p:2,bgcolor:"pickup"===I?"primary.lighter":"grey.50",opacity:"delivery"===I&&xe?.5:1,border:"pickup"===I?"2px solid #1976d2":"1px solid #eee",transition:"all 0.2s"},children:[(0,se.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(It.A,{fontSize:"small",color:"primary"})," Pickup Address"]}),(0,se.jsx)(hs.A,{value:G||"",onChange:e=>{const s=e.target.value;K(s),S("pickup"),ue(null),oe(!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,se.jsx)(ps.A,{value:String(s.id),control:(0,se.jsx)(As.A,{color:"primary"}),label:s.address},s.id)}))})]}),(0,se.jsxs)(de.A,{elevation:"delivery"===I?4:1,sx:{p:2,bgcolor:"delivery"===I?"secondary.lighter":"grey.50",opacity:"pickup"===I&&G?.5:1,border:"delivery"===I?"2px solid #9c27b0":"1px solid #eee",transition:"all 0.2s"},children:[(0,se.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(wr.A,{fontSize:"small",color:"secondary"})," Home Delivery Address"]}),(0,se.jsxs)(g.A,{children:[(0,se.jsxs)(us.A,{fullWidth:!0,sx:{mb:2},children:[(0,se.jsx)(Xt.A,{children:"Select Address"}),he?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,se.jsx)(Fr,{size:24})}):(0,se.jsx)(en.A,{value:xe||"",onChange:e=>{ue(e.target.value),S("delivery"),K(null),oe(!0)},label:"Select Address",inputProps:{},InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(Er.A,{})})},children:ce&&ce.length>0?ce.map((e=>(0,se.jsxs)(je.A,{value:e.id,children:[e.address," ",e.isPrimary?"(Primary)":""]},e.id))):(0,se.jsx)(je.A,{disabled:!0,children:"No addresses available"})})]}),(0,se.jsx)(ne.A,{fullWidth:!0,variant:"outlined",startIcon:Se?(0,se.jsx)(Pr.A,{}):(0,se.jsx)(kr.A,{}),onClick:()=>Ce(!Se),sx:{mb:2},children:Se?"Cancel":"Add New Address"}),(0,se.jsx)(tr.A,{in:Se,children:(0,se.jsx)(g.A,{sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:1},children:(0,se.jsxs)(ss.A,{spacing:2,children:[(0,se.jsxs)(g.A,{children:[(0,se.jsx)(wt,{value:ke,onChange:e=>{Ee(e),(e=>{if(!e.trim()||!ce)return void Q(!1);const s=e.toLowerCase().trim(),t=ce.some((e=>e.address.toLowerCase().trim()===s));Q(t)})(e)},onValidAddress:qe}),Y&&(0,se.jsx)(m.A,{variant:"body2",color:"error",sx:{mt:.5,fontSize:"0.875rem"},children:"⚠️ This address already exists in your address book"})]}),(0,se.jsx)(ps.A,{control:(0,se.jsx)(Hn.A,{checked:Fe,onChange:e=>De(e.target.checked)}),label:"Set as Primary Address"}),(0,se.jsx)(ne.A,{variant:"contained",onClick:async()=>{if(!ke.trim())return void $("Please enter a valid address");const e=ke.trim().toLowerCase(),s=ce?.some((s=>s.address.toLowerCase().trim()===e));if(s)$("This address already exists in your address book");else{$e(!0),$("");try{await pe(ke,q.id,Fe),Ce(!1),Ee(""),De(!1),B.invalidateQueries(["userAddresses",q.id])}catch(e){$("Failed to add address. Please try again.")}finally{$e(!1)}}},disabled:!ke.trim()||Le||!Te||Y,startIcon:Le?(0,se.jsx)(Fr,{size:20}):(0,se.jsx)(Bt.A,{}),children:Le?"Adding...":"Add Address"})]})})})]})]})]})]}),q&&(0,se.jsxs)(g.A,{sx:{mb:3},children:[(0,se.jsx)(m.A,{variant:"subtitle1",sx:{mb:2},children:"Delivery Instructions"}),(0,se.jsx)(p.A,{fullWidth:!0,multiline:!0,rows:2,value:P,onChange:e=>k(e.target.value),placeholder:"Add any special instructions for delivery..."})]}),q&&(0,se.jsx)(se.Fragment,{children:ye?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mb:3},children:(0,se.jsx)(j.A,{size:24})}):(0,se.jsx)(ys,{paymentConfig:ve,selectedMethod:re,onMethodChange:ie})}),q?(0,se.jsx)(ne.A,{fullWidth:!0,variant:"contained",size:"large",onClick:"cod"===re?()=>{if($(""),!G&&!xe)return void $("Please select either a pickup location or delivery address");const s=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity})));He({userId:q.id,storeId:o.id,productItems:s,pickupOrDelivery:I,addressId:xe,pickupId:G?parseInt(G,10):null,tipAmount:C||0,deliveryInstructions:"pickup"===I?null:P,customOrder:h||null})}:()=>{te(!0)},disabled:z||ye||!re||!xe&&!G||0===Object.values(e).length&&!h?.trim()||Ge,startIcon:"cod"===re?(0,se.jsx)(js.A,{}):(0,se.jsx)(ns.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"cod"===re?"Place Order":"Pay Now"}):(0,se.jsx)(ne.A,{fullWidth:!0,variant:"contained",size:"large",onClick:()=>{W(!0),O("login")},startIcon:(0,se.jsx)(Es.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"Login to Continue"})]})})]}),(0,se.jsx)(xs,{open:J,onClose:Ke,cartTotal:Me,orderItems:Je,deliveryType:I,selectedAddressId:xe,selectedPickupId:G?parseInt(G,10):null,userProfile:q,selectedStore:o,tipAmount:C,deliveryInstructions:P,customOrder:h,onSuccess:Ye,paymentConfig:ve})]})};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}=Z(),[s,t]=(0,x.useState)(""),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),[o,l]=(0,x.useState)(!1),[d,c]=(0,x.useState)(null),[h,f]=(0,x.useState)(""),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[C,w]=(0,x.useState)("ALL"),[P,k]=(0,x.useState)("createdAt"),[F,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"}),[J,X]=(0,x.useState)(!1),[ee,te]=(0,x.useState)(null),[re,ie]=(0,x.useState)(1),[ae,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,Hs.T)();t(e.sub)}catch(e){}})()}),[]);const{data:he,isLoading:pe}=(0,u.I)({queryKey:["getUserProfile",s],queryFn:async()=>await E(L,{userId:s}),enabled:!!s}),ge=he?.getUserProfile?.stores?.edges?.[0]?.node?.id,ye=he?.getUserProfile?.id,{data:ve,isLoading:Se,error:we,refetch:Pe}=(0,u.I)({queryKey:["storeDrivers",ge],queryFn:async()=>await E(T,{storeId:ge}),enabled:!!ge}),{data:ke,isLoading:Ee,error:Fe,refetch:Le}=(0,u.I)({queryKey:["storeOrders",ge],queryFn:async()=>(await E($,{storeId:ge})).getOrdersByStore||[],enabled:!!ge}),$e=(0,cs.n)({mutationFn:async e=>await E(D,{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(""),_(""),H(""),K("")},onError:e=>{v(e.message)}}),Te=(0,cs.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 E(Nr,{orderId:parseInt(s),orderItemUpdates:[{orderItemId:parseInt(t),quantityChange:n-ee.quantity}],totalAmount:0,orderTotalAmount:0,taxAmount:0});let l=0;o.forEach((e=>{if(e.id===parseInt(t))l+=n*r;else{const s=e.product?.inventoryItems?.edges[0]?.node?.price||0;l+=e.quantity*s}}));const d=l*a/100,c=l+d+(i.deliveryFee||0)+(i.tipAmount||0),x=n-ee.quantity;return await E(Nr,{orderId:parseInt(s),orderItemUpdates:[{orderItemId:parseInt(t),quantityChange:x}],totalAmount:l,orderTotalAmount:c,taxAmount:d})},onSuccess:()=>{Le(),X(!1),te(null),ie(1)},onError:e=>{v(e.message)}}),qe=(0,cs.n)({mutationFn:async e=>await E(q,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:e.cancelledByUserId}),onSuccess:()=>{Le(),l(!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"===F?"desc":"asc"):(k(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"===F?t:-t})),e}),[ke,I,C,P,F]),Be=x.useMemo((()=>{const e=z*O;return Ne.slice(e,e+O)}),[Ne,z,O]),Me=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())},_e=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: ${In.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(In.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 pe||Ee||Se||ue?(0,se.jsx)(er,{children:(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,se.jsx)(j.A,{})})}):!Fe&&!we||ue?(0,se.jsx)(er,{children:(0,se.jsxs)(g.A,{sx:{p:3},children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Orders"}),b&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:b}),(0,se.jsx)(be.A,{sx:{mb:3},children:(0,se.jsx)(Ie.A,{children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:3,children:(0,se.jsx)(p.A,{fullWidth:!0,placeholder:"Search orders...",value:I,onChange:e=>S(e.target.value),InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)(nn.A,{})})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:3,children:(0,se.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Filter by Status",value:C,onChange:e=>w(e.target.value),InputProps:{startAdornment:(0,se.jsx)(A.A,{position:"start",children:(0,se.jsx)($r.A,{})})},children:[(0,se.jsx)(je.A,{value:"ALL",children:"All Statuses"}),In.map((e=>(0,se.jsx)(je.A,{value:e.value,children:e.label},e.value)))]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:3,children:(0,se.jsxs)(m.A,{variant:"body2",color:"textSecondary",children:["Total Orders: ",Ne.length]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:3,children:(0,se.jsx)(ne.A,{fullWidth:!0,variant:"contained",startIcon:(0,se.jsx)(Tr.A,{}),onClick:()=>le(!0),disabled:0===Ne.length,children:"Download Orders"})})]})})}),0===Ne.length?(0,se.jsx)(oe.A,{severity:"info",sx:{mb:2},children:"No orders found."}):(0,se.jsxs)(Gt.A,{component:de.A,children:[(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>Ue("id"),children:["Order ID",(0,se.jsx)(qr.A,{sx:{ml:1,transform:"id"===P&&"desc"===F?"rotate(180deg)":"none"}})]})}),(0,se.jsx)(Jt.A,{children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>Ue("totalAmount"),children:["Total",(0,se.jsx)(qr.A,{sx:{ml:1,transform:"totalAmount"===P&&"desc"===F?"rotate(180deg)":"none"}})]})}),(0,se.jsx)(Jt.A,{children:"Status"}),(0,se.jsx)(Jt.A,{children:"Actions"}),(0,se.jsx)(Jt.A,{})]})}),(0,se.jsx)(Zt.A,{children:Be.map((e=>{return(0,se.jsxs)(x.Fragment,{children:[(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.id}),(0,se.jsxs)(Jt.A,{children:["$",e.orderTotalAmount]}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:In.find((s=>s.value===e.status))?.label||e.status,color:(s=e.status,In.find((e=>e.value===s))?.color||"default"),size:"small"})}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ce.A,{title:"Edit Order",children:(0,se.jsx)(Ae.A,{size:"small",onClick:()=>(e=>{c(e),f(e.status),_(e.deliveryInstructions||""),a(!0)})(e),disabled:!_e(e.status),children:(0,se.jsx)(tn.A,{})})}),(0,se.jsx)(Ce.A,{title:"Cancel Order",children:(0,se.jsx)(Ae.A,{size:"small",onClick:()=>(e=>{c(e),l(!0)})(e),disabled:!_e(e.status),children:(0,se.jsx)(fn.A,{})})}),(0,se.jsx)(Ce.A,{title:"Upload File",children:(0,se.jsx)(Ae.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:l}=await r.json(),d=await fetch(i,{method:"PUT",headers:{"Content-Type":a},body:t});if(!d.ok)throw await d.text(),new Error("Failed to upload file");if(!(await fetch(`${n}/orders/${e.id}/set-bill-url?file_name=${encodeURIComponent(o)}`,{method:"POST"})).ok)throw new Error("Failed to update bill URL");(await fetch(`${n}/s3/generate-view-url?bill_key=${encodeURIComponent(l)}`)).ok?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:!_e(e.status),children:(0,se.jsx)(jn.A,{})})}),(0,se.jsx)(Ce.A,{title:"View File",children:(0,se.jsx)(Ae.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,se.jsx)(vn.A,{})})})]}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(Ae.A,{size:"small",onClick:()=>r(n===e.id?null:e.id),children:n===e.id?(0,se.jsx)(Pr.A,{}):(0,se.jsx)(kr.A,{})})})]}),n===e.id&&(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:6,children:(0,se.jsx)(g.A,{sx:{p:2},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Information"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(m.A,{children:[(0,se.jsx)("strong",{children:"Order Code:"})," ",e.displayCode||"N/A"]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(m.A,{children:[(0,se.jsx)("strong",{children:"Type:"})," ","PICKUP"===e.type?(0,se.jsxs)(g.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(Es.A,{fontSize:"small"}),"Pickup Order"]}):(0,se.jsxs)(g.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,se.jsx)(js.A,{fontSize:"small"}),"Delivery Order"]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsxs)(m.A,{children:[(0,se.jsx)("strong",{children:"Address:"})," ","PICKUP"===e.type?e.pickupAddress?.address||"No pickup address":e.address?.address||"No delivery address"]})})]})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Customer Information"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{children:["Email: ",e?.creator?.email||"N/A"]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(m.A,{children:["Phone: ",e?.creator?.mobile||"N/A"]})})]})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Items"}),(0,se.jsxs)(Kt.A,{size:"small",children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Product"}),(0,se.jsx)(Jt.A,{children:"Quantity"}),(0,se.jsx)(Jt.A,{children:"Price"}),(0,se.jsx)(Jt.A,{children:"Total"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:e.orderItems?.edges?.length>0?Me(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,se.jsxs)(x.Fragment,{children:[(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:s.product?.name||"N/A"}),(0,se.jsx)(Jt.A,{children:s.quantity}),(0,se.jsx)(Jt.A,{children:Rr(i)}),(0,se.jsx)(Jt.A,{children:Rr(s.quantity*i)}),(0,se.jsx)(Jt.A,{children:_e(e.status)&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Ae.A,{size:"small",onClick:()=>{return t=s,n=e.id,te({...t,orderId:n}),ie(t.quantity),void X(!0);var t,n},sx:{mr:1},children:(0,se.jsx)(tn.A,{fontSize:"small"})}),(0,se.jsx)(Ae.A,{size:"small",onClick:()=>{return t=s,n=e.id,te({...t,orderId:n}),ie(0),void X(!0);var t,n},color:"error",children:(0,se.jsx)(cn.A,{fontSize:"small"})})]})})]}),t.length>1&&(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:5,children:(0,se.jsxs)(g.A,{sx:{pl:2,py:1},children:[(0,se.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,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1,borderRadius:1,mb:1},children:[(0,se.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"100px"},children:["Change ",s+1]}),(0,se.jsxs)(g.A,{sx:{display:"flex",gap:3},children:[(0,se.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,se.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount:"," ",Rr(e.orderAmount)]})]})]},e.id)))]})})})]},s.id)})):(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:5,align:"center",children:"No items found for this order"})})})]})]}),e.customOrder&&(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Custom Order Details"}),(0,se.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,se.jsxs)(g.A,{sx:{mb:2},children:[(0,se.jsx)(m.A,{variant:"subtitle2",sx:{color:"text.secondary",mb:.5},children:t}),(0,se.jsx)(g.A,{sx:{pl:2},children:n.map(((e,s)=>(0,se.jsx)(m.A,{variant:"body2",sx:{mb:.5},children:e},s)))})]},s):null}))})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Summary"}),(0,se.jsx)(g.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:1,children:[(0,se.jsx)(fe.Ay,{item:!0,xs:6,children:(0,se.jsx)(m.A,{children:"Subtotal:"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,se.jsx)(m.A,{children:Rr(e.totalAmount)})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,children:(0,se.jsx)(m.A,{children:"Delivery Fee:"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,se.jsx)(m.A,{children:Rr(e.deliveryFee)})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,children:(0,se.jsx)(m.A,{children:"Tax:"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,se.jsx)(m.A,{children:Rr(e.taxAmount)})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,children:(0,se.jsx)(m.A,{children:"Tip:"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,se.jsx)(m.A,{children:Rr(e.tipAmount)})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(ts.A,{sx:{my:1}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,children:(0,se.jsx)(m.A,{sx:{fontWeight:"bold"},children:"Total Amount:"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,se.jsx)(m.A,{sx:{fontWeight:"bold"},children:Rr(e.orderTotalAmount)})})]})})]}),e.deliveryInstructions&&(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Delivery Instructions"}),(0,se.jsx)(m.A,{children:e.deliveryInstructions})]})]})})})})]},e.id);var s}))})]}),(0,se.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,se.jsxs)(Re.A,{open:i,onClose:()=>a(!1),maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:"Update Order Status"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{select:!0,fullWidth:!0,label:"Status",value:h,onChange:e=>f(e.target.value),children:In.map((e=>(0,se.jsx)(je.A,{value:e.value,children:e.label},e.value)))})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{fullWidth:!0,label:"Delivery Instructions",value:M,onChange:e=>_(e.target.value),multiline:!0,rows:3})}),"READY_FOR_DELIVERY"===h&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.jsxs)(us.A,{fullWidth:!0,required:!0,children:[(0,se.jsx)(Xt.A,{children:"Delivery Agent"}),(0,se.jsx)(en.A,{value:V,onChange:e=>H(e.target.value),label:"Delivery Agent",children:ve?.getStoreDrivers?.map((e=>(0,se.jsxs)(je.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId)))})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:6,children:(0,se.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,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>a(!1),children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:async()=>{try{const e={orderId:d.id,status:h,deliveryInstructions:M};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,se.jsxs)(Re.A,{open:o,onClose:()=>l(!1),children:[(0,se.jsx)(ze.A,{children:"Cancel Order"}),(0,se.jsxs)(We.A,{children:[(0,se.jsx)(m.A,{children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,se.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,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>l(!1),disabled:qe.isPending||qe.isLoading,children:"No"}),(0,se.jsx)(ne.A,{onClick:async()=>{try{if(!ye)return void v("User profile not found. Please try again.");qe.mutate({orderId:d.id,cancelMessage:N,cancelledByUserId:ye})}catch(e){v(e.message)}},variant:"contained",color:"error",disabled:!N.trim()||qe.isPending||qe.isLoading,startIcon:qe.isPending||qe.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:qe.isPending||qe.isLoading?"Cancelling...":"Yes, Cancel Order"})]})]}),(0,se.jsxs)(Re.A,{open:J,onClose:()=>X(!1),maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:0===re?"Delete Order Item":"Edit Order Item"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsxs)(m.A,{variant:"subtitle1",children:["Product: ",ee?.product?.name||"N/A"]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,children:(0,se.jsx)(p.A,{fullWidth:!0,label:"Quantity",type:"number",value:re,onChange:e=>ie(parseInt(e.target.value)||0),inputProps:{min:0}})})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>X(!1),children:"Cancel"}),(0,se.jsx)(ne.A,{onClick:async()=>{try{await Te.mutateAsync({orderId:ee.orderId,itemId:ee.id,quantity:re,price:ee.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,se.jsxs)(Re.A,{open:ae,onClose:()=>le(!1),maxWidth:"xs",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:"Download Orders"}),(0,se.jsxs)(We.A,{children:[(0,se.jsxs)(m.A,{variant:"body1",gutterBottom:!0,children:["Download ",Ne.length," filtered orders"]}),(0,se.jsxs)(m.A,{variant:"body2",color:"textSecondary",gutterBottom:!0,children:[I&&`Search term: ${I}`,"ALL"!==C&&`\nStatus: ${C}`]}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,se.jsx)(fe.Ay,{item:!0,xs:6,children:(0,se.jsx)(ne.A,{fullWidth:!0,variant:"outlined",onClick:()=>Ve(Ne,"pdf"),startIcon:(0,se.jsx)(Tr.A,{}),children:"PDF"})}),(0,se.jsx)(fe.Ay,{item:!0,xs:6,children:(0,se.jsx)(ne.A,{fullWidth:!0,variant:"outlined",onClick:()=>Ve(Ne,"docx"),startIcon:(0,se.jsx)(Tr.A,{}),children:"DOCX"})})]})]}),(0,se.jsx)(Oe.A,{children:(0,se.jsx)(ne.A,{onClick:()=>le(!1),children:"Cancel"})})]}),(0,se.jsx)(sn.A,{open:Y.open,autoHideDuration:6e3,onClose:()=>Q({...Y,open:!1}),children:(0,se.jsx)(oe.A,{onClose:()=>Q({...Y,open:!1}),severity:Y.severity,sx:{width:"100%"},children:Y.message})})]})}):(0,se.jsx)(er,{children:(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:Fe?.message||we?.message||"An error occurred"})})},Mr=[{value:"ACTIVE",label:"Active"},{value:"INACTIVE",label:"Inactive"}],_r=()=>{const{userProfile:e,setUserProfile:s}=Z(),[t,n]=(0,x.useState)(""),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)({driverStatus:"",orderStatus:"",dateRange:"all"}),[l,d]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Hs.T)();n(e.sub)}catch(e){}})()}),[]);const{data:A,isLoading:y}=(0,u.I)({queryKey:["getUserProfile",t],queryFn:async()=>{const e=await E(L,{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:()=>E("\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&&l}),{data:C,isLoading:w,error:P,refetch:k}=(0,u.I)({queryKey:["storeOrders",f],queryFn:async()=>(await E($,{storeId:f})).getOrdersByStore||[],enabled:!!f}),F=(e,s)=>{o((t=>({...t,[e]:s})))},D=e=>({PENDING:"warning",PROCESSING:"info",READY_FOR_DELIVERY:"primary",OUT_FOR_DELIVERY:"secondary",DELIVERED:"success",CANCELLED:"error",ACTIVE:"success",INACTIVE:"error",BUSY:"warning"}[e]||"default"),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,se.jsx)(er,{children:(0,se.jsxs)(g.A,{sx:{p:3},children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Delivery Partners"}),c&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:c}),y&&(0,se.jsx)(oe.A,{severity:"info",sx:{mb:2},children:"Loading user profile..."}),(0,se.jsxs)(de.A,{sx:{p:3,mb:3},children:[(0,se.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Filters"}),(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:4,children:(0,se.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Driver Status",value:a.driverStatus,onChange:e=>F("driverStatus",e.target.value),children:[(0,se.jsx)(je.A,{value:"",children:"All Statuses"}),Mr.map((e=>(0,se.jsx)(je.A,{value:e.value,children:e.label},e.value)))]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:4,children:(0,se.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Order Status",value:a.orderStatus,onChange:e=>F("orderStatus",e.target.value),children:[(0,se.jsx)(je.A,{value:"",children:"All Statuses"}),In.map((e=>(0,se.jsx)(je.A,{value:e.value,children:e.label},e.value)))]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,sm:4,children:(0,se.jsxs)(p.A,{select:!0,fullWidth:!0,label:"Date Range",value:a.dateRange,onChange:e=>F("dateRange",e.target.value),children:[(0,se.jsx)(je.A,{value:"all",children:"All Time"}),(0,se.jsx)(je.A,{value:"today",children:"Today"}),(0,se.jsx)(je.A,{value:"week",children:"Last 7 Days"}),(0,se.jsx)(je.A,{value:"month",children:"Last 30 Days"})]})}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,children:[(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:(0,se.jsx)(nn.A,{}),onClick:()=>{d(!0),S(),k()},disabled:!f||y,children:y?"Loading Profile...":"Get Data"}),!f&&!y&&(0,se.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,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",p:3},children:(0,se.jsx)(j.A,{})}):z?(0,se.jsx)(oe.A,{severity:"error",children:I?.message||P?.message||"An error occurred while fetching data"}):l?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsxs)(m.A,{variant:"h6",gutterBottom:!0,children:["Delivery Partners (",q(b?.getStoreDrivers||[]).length,")"]}),(0,se.jsx)(Gt.A,{component:de.A,children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Driver ID"}),(0,se.jsx)(Jt.A,{children:"Name"}),(0,se.jsx)(Jt.A,{children:"Email"}),(0,se.jsx)(Jt.A,{children:"Phone"}),(0,se.jsx)(Jt.A,{children:"Status"}),(0,se.jsx)(Jt.A,{children:"Orders"}),(0,se.jsx)(Jt.A,{})]})}),(0,se.jsxs)(Zt.A,{children:[q(b?.getStoreDrivers||[]).map((e=>(0,se.jsxs)(x.Fragment,{children:[(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e?.userId}),(0,se.jsx)(Jt.A,{children:e.name}),(0,se.jsx)(Jt.A,{children:e?.driver?.email}),(0,se.jsx)(Jt.A,{children:e?.driver?.mobile}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:e?.driver?.active?"Active":"Inactive",color:D(e?.driver?.active),size:"small"})}),(0,se.jsx)(Jt.A,{children:T(C||[],e?.userId).length}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(Ae.A,{size:"small",onClick:()=>i(r===e?.userId?null:e?.userId),children:r===e?.userId?(0,se.jsx)(rr.A,{}):(0,se.jsx)(ir.A,{})})})]}),r===e?.userId&&(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:7,children:(0,se.jsxs)(g.A,{sx:{p:2},children:[(0,se.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:["Orders for ",e.name,":"]}),(0,se.jsxs)(Kt.A,{size:"small",children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Order ID"}),(0,se.jsx)(Jt.A,{children:"Date"}),(0,se.jsx)(Jt.A,{children:"Customer"}),(0,se.jsx)(Jt.A,{children:"Total"}),(0,se.jsx)(Jt.A,{children:"Status"})]})}),(0,se.jsx)(Zt.A,{children:T(C||[],e?.userId).length>0?T(C||[],e?.userId).map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.id}),(0,se.jsx)(Jt.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,se.jsx)(Jt.A,{children:e.user?.name}),(0,se.jsxs)(Jt.A,{children:["₹",e.totalAmount]}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(De.A,{label:In.find((s=>s.value===e.status))?.label||e.status,color:D(e.status),size:"small"})})]},e.id))):(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:5,align:"center",children:"No orders found for this driver with the current filters."})})})]})]})})})]},e?.userId))),0===q(b?.getStoreDrivers||[]).length&&(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:7,align:"center",children:"No delivery partners found with the current filters."})})]})]})})]}):(0,se.jsx)(oe.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(""),[l,d]=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():""),d(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,se.jsxs)(Re.A,{open:s,onClose:()=>{y(""),t()},maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:"Edit Inventory Item"}),(0,se.jsxs)(We.A,{children:[n&&(0,se.jsxs)(se.Fragment,{children:[(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[n.product?.image&&(0,se.jsx)(ve.A,{component:"img",sx:{width:80,height:80,objectFit:"contain",mr:2},image:n.product.image,alt:n.product.name}),(0,se.jsxs)(g.A,{children:[(0,se.jsx)(m.A,{variant:"subtitle1",children:(0,se.jsx)("strong",{children:n.product?.name})}),(0,se.jsx)(m.A,{variant:"body2",color:"text.secondary",children:n.product?.category?.name||"Uncategorized"})]})]}),(0,se.jsx)(ts.A,{sx:{my:2}}),(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsx)("label",{htmlFor:"edit-price-input",style:b,children:"Price ($)"}),(0,se.jsx)("input",{id:"edit-price-input",type:"number",value:a,onChange:e=>o(e.target.value),min:"0",step:"0.01",style:f}),(0,se.jsx)("label",{htmlFor:"edit-quantity-input",style:b,children:"Quantity"}),(0,se.jsx)("input",{id:"edit-quantity-input",type:"number",value:l,onChange:e=>d(e.target.value),min:"0",style:f}),(0,se.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,se.jsx)(ps.A,{control:(0,se.jsx)(an.A,{checked:c,onChange:e=>u(e.target.checked),color:"primary"}),label:"Available (In Stock)"}),(0,se.jsx)(ps.A,{control:(0,se.jsx)(an.A,{checked:h,onChange:e=>p(e.target.checked),color:"primary"}),label:"Listed (Visible to Customers)"})]})]})]}),A&&(0,se.jsx)(oe.A,{severity:"error",sx:{mt:2},children:A})]}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{y(""),t()},disabled:i,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",onClick:()=>{!a||isNaN(parseFloat(a))||parseFloat(a)<=0?y("Please enter a valid price greater than zero."):!l||isNaN(parseInt(l,10))||parseInt(l,10)<0?y("Please enter a valid quantity (0 or greater)."):(y(""),r({inventoryId:n.id,price:a,quantity:l,isAvailable:c,isListed:h}))},disabled:i,startIcon:i?(0,se.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[l,d]=(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=()=>{d(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,se.jsxs)(Re.A,{open:s,onClose:()=>{t(),f()},maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:"Add Product to Inventory"}),(0,se.jsxs)(We.A,{children:[(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsx)("label",{htmlFor:"searchInput",style:v,children:"Search Product"}),(0,se.jsxs)("div",{style:{position:"relative"},children:[(0,se.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,se.jsx)(j.A,{size:20,style:{position:"absolute",right:"10px",top:"50%",transform:"translateY(-50%)"}})]}),m&&y.length>0&&(0,se.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,se.jsxs)("div",{onClick:()=>(e=>{d(e),u((s=>({...s,searchInput:e.name}))),h(!1)})(e),style:{padding:"8px 16px",cursor:"pointer",backgroundColor:l?.id===e.id?"rgba(0, 0, 0, 0.04)":"transparent","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.08)"}},children:[(0,se.jsx)("div",{children:e.name}),(0,se.jsx)("div",{style:{fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)"},children:e.category.name})]},e.id)))})]}),(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsx)("label",{htmlFor:"price",style:v,children:"Price ($)"}),(0,se.jsx)("input",{id:"price",name:"price",type:"number",value:c.price,onChange:A,min:"0",step:"0.01",style:b})]}),(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsx)("label",{htmlFor:"quantity",style:v,children:"Quantity"}),(0,se.jsx)("input",{id:"quantity",name:"quantity",type:"number",value:c.quantity,onChange:A,min:"0",style:b})]}),(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsx)("label",{htmlFor:"measurement",style:v,children:"Measurement"}),(0,se.jsx)("input",{id:"measurement",name:"measurement",type:"number",value:c.measurement,onChange:A,min:"0",style:b})]}),(0,se.jsxs)(g.A,{sx:{mt:2},children:[(0,se.jsx)("label",{htmlFor:"unit",style:v,children:"Unit"}),(0,se.jsxs)("select",{id:"unit",name:"unit",value:c.unit,onChange:A,style:{...b,backgroundColor:"transparent",appearance:"auto",height:"40px"},children:[(0,se.jsx)("option",{value:"",children:"None"}),(0,se.jsx)("option",{value:"1",children:"Grams (g)"}),(0,se.jsx)("option",{value:"2",children:"Kilograms (kg)"}),(0,se.jsx)("option",{value:"3",children:"Milliliters (ml)"}),(0,se.jsx)("option",{value:"4",children:"Liters (L)"}),(0,se.jsx)("option",{value:"5",children:"Pieces (pcs)"})]})]}),o&&(0,se.jsx)(oe.A,{severity:"error",sx:{mt:2},children:o})]}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{t(),f()},disabled:a,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",onClick:()=>{l&&i({storeId:n,productId:l.id,price:c.price,quantity:c.quantity,measurement:c.measurement||null,unit:c.unit||null})},disabled:a||!l||!c.price||!c.quantity,startIcon:a?(0,se.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}=Z(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(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,k]=(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,Hs.T)();s(e.sub)}catch(e){}})()}),[]);const{data:O,isLoading:U}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await E("\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:M,refetch:_}=(0,u.I)({queryKey:["storeWithInventory",t?.id],queryFn:()=>E("\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,cs.n)({mutationFn:e=>{let{inventoryId:s,price:t,quantity:n,isAvailable:r,isListed:i}=e;return E("\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:()=>{_(),o(!1),i(null),f("Inventory item updated successfully"),setTimeout((()=>f("")),3e3)},onError:e=>{A(`Error updating inventory: ${e.message}`)}}),J=(0,cs.n)({mutationFn:e=>{let{storeId:s,productId:t,price:n,quantity:r,measurement:i,unit:a}=e;return E("\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:()=>{_(),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:l,categories:d}=e;return(0,se.jsx)(de.A,{elevation:3,sx:{p:3,mb:4},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:4,children:(0,se.jsx)(p.A,{label:"Search Products",variant:"outlined",size:"small",value:s,onChange:e=>t(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,se.jsx)(nn.A,{sx:{mr:1,color:"text.secondary"}})}})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:3,children:(0,se.jsxs)(us.A,{fullWidth:!0,size:"small",children:[(0,se.jsx)(Xt.A,{id:"category-select-label",children:"Category"}),(0,se.jsxs)(en.A,{labelId:"category-select-label",id:"category-select",value:n,label:"Category",onChange:e=>r(e.target.value),children:[(0,se.jsx)(je.A,{value:"all",children:"All Categories"}),d.map((e=>(0,se.jsx)(je.A,{value:e,children:e},e)))]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:3,children:(0,se.jsxs)(us.A,{fullWidth:!0,size:"small",children:[(0,se.jsx)(Xt.A,{id:"stock-filter-label",children:"Stock Filter"}),(0,se.jsxs)(en.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,se.jsx)(je.A,{value:"false",children:"All Items"}),(0,se.jsx)(je.A,{value:"true",children:"Low Stock Only"})]})]})}),(0,se.jsx)(fe.Ay,{item:!0,xs:12,md:2,children:(0,se.jsx)(p.A,{label:"Low Stock Threshold",type:"number",size:"small",value:o,onChange:e=>l(parseInt(e.target.value,10)||0),disabled:!i,fullWidth:!0})})]})})}));return U||B?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})})}):M?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4},children:(0,se.jsxs)(oe.A,{severity:"error",children:["Error loading inventory data: ",M.message]})})}):(0,se.jsx)(er,{children:(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Inventory Management"}),(0,se.jsx)(X,{searchTerm:b,setSearchTerm:v,filterCategory:D,setFilterCategory:L,lowStockOnly:I,setLowStockOnly:S,lowStockThreshold:C,setLowStockThreshold:w,categories:$}),y&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:y}),c&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:c}),(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,se.jsx)(m.A,{variant:"h5",children:"Inventory Items"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:J.isPending||J.isPending?(0,se.jsx)(j.A,{size:18,color:"inherit"}):(0,se.jsx)(Pe.A,{}),onClick:()=>R(!0),disabled:J.isPending||J.isPending,children:J.isPending||J.isPending?"Adding...":"Add Product"})]}),z?(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,se.jsx)(j.A,{})}):0===K.length?(0,se.jsx)(oe.A,{severity:"info",sx:{my:2},children:"No inventory items match your filters."}):(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Gt.A,{component:de.A,variant:"outlined",children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{}),(0,se.jsx)(Jt.A,{children:"Product"}),(0,se.jsx)(Jt.A,{children:"Category"}),(0,se.jsx)(Jt.A,{children:"Price"}),(0,se.jsx)(Jt.A,{children:"Quantity"}),(0,se.jsx)(Jt.A,{children:"Available"}),(0,se.jsx)(Jt.A,{children:"Listed"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:Y.map((e=>(0,se.jsxs)(x.Fragment,{children:[(0,se.jsxs)(Qt.A,{sx:{backgroundColor:e?.isAvailable?"inherit":"rgba(255, 0, 0, 0.1)"},children:[(0,se.jsx)(Jt.A,{children:(0,se.jsx)(Ae.A,{size:"small",onClick:()=>{return s=e.id,void d(l===s?null:s);var s},children:l===e.id?(0,se.jsx)(rr.A,{}):(0,se.jsx)(ir.A,{})})}),(0,se.jsx)(Jt.A,{children:(0,se.jsxs)(g.A,{sx:{display:"flex",alignItems:"center"},children:[e.product?.image&&(0,se.jsx)(ve.A,{component:"img",sx:{width:50,height:50,objectFit:"contain",mr:2},image:e.product.image,alt:e.product.name}),(0,se.jsx)(m.A,{children:e.product?.name})]})}),(0,se.jsx)(Jt.A,{children:e.product?.category?.name||"Uncategorized"}),(0,se.jsxs)(Jt.A,{children:["$",e.price.toFixed(2)]}),(0,se.jsx)(Jt.A,{children:e.quantity}),(0,se.jsx)(Jt.A,{children:e?.isAvailable?(0,se.jsx)(De.A,{label:"In Stock",color:"success",size:"small"}):(0,se.jsx)(De.A,{label:"Low Stock",color:"error",size:"small"})}),(0,se.jsx)(Jt.A,{children:e?.isListed?(0,se.jsx)(De.A,{label:"Listed",color:"success",size:"small"}):(0,se.jsx)(De.A,{label:"Not Listed",color:"error",size:"small"})}),(0,se.jsx)(Jt.A,{children:(0,se.jsx)(Ae.A,{onClick:()=>(e=>{e&&(i(e),o(!0))})(e),size:"small",color:"primary",disabled:Q.isPending||Q.isLoading||J.isPending||J.isLoading,children:(0,se.jsx)(tn.A,{})})})]}),(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{sx:{p:0},colSpan:7,children:(0,se.jsx)(tr.A,{in:l===e.id,timeout:"auto",unmountOnExit:!0,children:(0,se.jsx)(g.A,{sx:{p:3,backgroundColor:"rgba(0, 0, 0, 0.03)"},children:(0,se.jsxs)(fe.Ay,{container:!0,spacing:2,children:[(0,se.jsxs)(fe.Ay,{item:!0,xs:12,md:6,children:[(0,se.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,se.jsx)("strong",{children:"Description:"})," ",e.product?.description||"No description available"]}),(0,se.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,se.jsx)("strong",{children:"Product ID:"})," ",e.product?.id]})]}),(0,se.jsxs)(fe.Ay,{item:!0,xs:12,md:6,children:[(0,se.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,se.jsx)("strong",{children:"Last Updated:"})," ",e.updatedAt?new Date(e.updatedAt).toLocaleString():"N/A"]}),(0,se.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,se.jsx)("strong",{children:"Measurement:"})," ",e.measurement&&e.unit?`${e.measurement} ${e.unit}`:"N/A"]})]})]})})})})})]},e.id)))})]})}),(0,se.jsx)(g.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,se.jsx)(Vr.A,{count:Math.ceil(K.length/F),page:P,onChange:(e,s)=>k(s),color:"primary"})})]})]}),(0,se.jsx)(Hr,{open:a,onClose:()=>{o(!1),A("")},selectedItem:r,onUpdate:e=>Q.mutate(e),isLoading:Q.isPending}),(0,se.jsx)(Gr,{open:q,onClose:()=>R(!1),storeId:V?.id,availableProducts:G,onAdd:J.mutate,isLoading:J.isPending,errorMessage:c})]})})},Yr=e=>{let{open:s,onClose:t,selectedLocationCode:n,onUpdate:r,isLoading:i,existingCodes:a}=e;const[o,l]=(0,x.useState)({location:"",code:""}),[d,c]=(0,x.useState)("");(0,x.useEffect)((()=>{l(n?{location:n.location||"",code:n.code||""}:{location:"",code:""}),c("")}),[n,s]);const u=()=>{l({location:"",code:""}),c(""),t()},m=e=>{const{name:s,value:t}=e.target;l((e=>({...e,[s]:t}))),c("")};return(0,se.jsxs)(Re.A,{open:s,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:n?"Edit Location Code":"Add New Location Code"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,se.jsx)(p.A,{name:"location",label:"Location",value:o.location,onChange:m,fullWidth:!0,placeholder:"e.g., Main Branch",error:!!d&&d.includes("Location"),helperText:d&&d.includes("Location")?d:""}),(0,se.jsx)(p.A,{name:"code",label:"Code",value:o.code,onChange:m,fullWidth:!0,placeholder:"e.g., MB001",error:!!d&&(d.includes("Code")||d.includes("already exists")),helperText:d&&(d.includes("Code")||d.includes("already exists"))?d:""})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:u,children:"Cancel"}),(0,se.jsx)(ne.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,se.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}=Z(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,p]=(0,x.useState)(""),[A,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Hs.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await E("\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:()=>E("\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:k,refetch:F}=(0,u.I)({queryKey:["getStoreLocationCodesByStore",C?.id],queryFn:()=>E("\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,cs.n)({mutationFn:e=>{if(!C?.id)throw new Error("Store not found");return E("\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,cs.n)({mutationFn:e=>E("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{F(),d(!1),i(null),y("Location code deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error deleting location code: ${e.message}`)}}),T=(0,cs.n)({mutationFn:e=>E("\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,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})})}):S||k?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4},children:(0,se.jsxs)(oe.A,{severity:"error",children:["Error loading data: ",S?.message||k?.message]})})}):(0,se.jsx)(er,{children:(0,se.jsxs)(h.A,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),A&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:A}),c&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:c}),(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,se.jsx)(m.A,{variant:"h5",children:"Location Codes"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:T.isPending||T.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):(0,se.jsx)(Pe.A,{}),onClick:()=>{i(null),o(!0)},disabled:T.isPending||T.isLoading,children:T.isPending||T.isLoading?"Adding...":"Add Location Code"})]}),0===D.length?(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Location"}),(0,se.jsx)(Jt.A,{children:"Code"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:(0,se.jsx)(Qt.A,{children:(0,se.jsx)(Jt.A,{colSpan:3,align:"center",children:(0,se.jsx)(oe.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})}):(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Location"}),(0,se.jsx)(Jt.A,{children:"Code"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:D.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.location}),(0,se.jsx)(Jt.A,{children:e.code}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,se.jsx)(tn.A,{})}),(0,se.jsx)(Ae.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,se.jsx)(cn.A,{})})]})]},e.id)))})]})})]}),(0,se.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,se.jsxs)(Re.A,{open:l,onClose:()=>{d(!1),i(null),p("")},children:[(0,se.jsx)(ze.A,{children:"Delete Location Code"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(m.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{d(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,se.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,l]=(0,x.useState)({address:""}),[d,c]=(0,x.useState)(""),[u,h]=(0,x.useState)(!1);(0,x.useEffect)((()=>{n?(l({address:n.address||""}),h(!0)):(l({address:""}),h(!1)),c("")}),[n]);return(0,se.jsxs)(Re.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,se.jsx)(ze.A,{children:n?"Edit Pickup Address":"Add New Pickup Address"}),(0,se.jsx)(We.A,{children:(0,se.jsxs)(g.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,se.jsx)(wt,{value:o.address,onChange:e=>{l((s=>({...s,address:e}))),c("")},onValidAddress:h}),d&&(0,se.jsx)(m.A,{color:"error",variant:"caption",children:d})]})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:t,children:"Cancel"}),(0,se.jsx)(ne.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,se.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}=Z(),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,p]=(0,x.useState)(""),[A,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,Hs.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await E("\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:()=>E("\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:k,refetch:F}=(0,u.I)({queryKey:["getPickupAddressesByStore",C?.id],queryFn:()=>E("\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,cs.n)({mutationFn:e=>E("\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,cs.n)({mutationFn:e=>E("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{F(),d(!1),i(null),y("Pickup address deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{p(`Error deleting pickup address: ${e.message}`)}}),T=(0,cs.n)({mutationFn:e=>E("\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,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,se.jsx)(j.A,{})})}):S||k?(0,se.jsx)(er,{children:(0,se.jsx)(h.A,{sx:{mt:4},children:(0,se.jsxs)(oe.A,{severity:"error",children:["Error loading data: ",S?.message||k?.message]})})}):(0,se.jsx)(er,{children:(0,se.jsxs)(h.A,{children:[(0,se.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),A&&(0,se.jsx)(oe.A,{severity:"success",sx:{mb:2},children:A}),c&&(0,se.jsx)(oe.A,{severity:"error",sx:{mb:2},children:c}),(0,se.jsxs)(de.A,{elevation:3,sx:{p:3,mb:4},children:[(0,se.jsxs)(g.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,se.jsx)(m.A,{variant:"h5",children:"Pickup Addresses"}),(0,se.jsx)(ne.A,{variant:"contained",color:"primary",startIcon:T.isPending||T.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):(0,se.jsx)(Pe.A,{}),onClick:()=>{i(null),o(!0)},disabled:T.isPending||T.isLoading,children:T.isPending||T.isLoading?"Adding...":"Add Pickup Address"})]}),0===D.length?(0,se.jsx)(oe.A,{severity:"info",sx:{my:2},children:"No pickup addresses found. Add your first pickup address to get started."}):(0,se.jsx)(Gt.A,{children:(0,se.jsxs)(Kt.A,{children:[(0,se.jsx)(Yt.A,{children:(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:"Address"}),(0,se.jsx)(Jt.A,{children:"Actions"})]})}),(0,se.jsx)(Zt.A,{children:D.map((e=>(0,se.jsxs)(Qt.A,{children:[(0,se.jsx)(Jt.A,{children:e.address}),(0,se.jsxs)(Jt.A,{children:[(0,se.jsx)(Ae.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,se.jsx)(tn.A,{})}),(0,se.jsx)(Ae.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||T.isPending||T.isLoading,children:(0,se.jsx)(cn.A,{})})]})]},e.id)))})]})})]}),(0,se.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,se.jsxs)(Re.A,{open:l,onClose:()=>{d(!1),i(null),p("")},children:[(0,se.jsx)(ze.A,{children:"Delete Pickup Address"}),(0,se.jsx)(We.A,{children:(0,se.jsx)(m.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,se.jsxs)(Oe.A,{children:[(0,se.jsx)(ne.A,{onClick:()=>{d(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,se.jsx)(ne.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:r.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,se.jsx)(j.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})})},Xr=()=>{const{user:e}=Z();return(0,se.jsxs)(o.A,{theme:c,children:[(0,se.jsx)(l.Ay,{}),(0,se.jsxs)(d.BV,{children:[(0,se.jsx)(d.qh,{path:Ls,element:(0,se.jsx)(yr,{})}),(0,se.jsx)(d.qh,{path:Ns,element:(0,se.jsx)(zt,{})}),(0,se.jsx)(d.qh,{path:$s,element:(0,se.jsx)(rt,{})}),(0,se.jsx)(d.qh,{path:"/",element:(0,se.jsx)(se.Fragment,{children:(0,se.jsx)(qt,{children:(0,se.jsx)(Ir,{})})})}),(0,se.jsx)(d.qh,{path:Bs,element:(0,se.jsx)(qt,{children:(0,se.jsx)(Lr,{})})}),(0,se.jsx)(d.qh,{path:`${Ts}/*`,element:(0,se.jsx)(Rt,{role:"admin",children:(0,se.jsx)(Vn,{})})}),(0,se.jsx)(d.qh,{path:qs,element:(0,se.jsx)(Rt,{role:"user",children:(0,se.jsx)(Ir,{})})}),(0,se.jsx)(d.qh,{path:Rs,element:(0,se.jsx)(Rt,{role:"delivery_agent",children:(0,se.jsx)(Kn,{})})}),(0,se.jsx)(d.qh,{path:Os,element:(0,se.jsx)(Rt,{role:"user",children:(0,se.jsx)(lr,{})})}),(0,se.jsx)(d.qh,{path:Us,element:(0,se.jsx)(Rt,{children:(0,se.jsx)(ur,{})})}),(0,se.jsx)(d.qh,{path:zs,element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(sr,{})})}),(0,se.jsx)(d.qh,{path:`${zs}/orders`,element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(Br,{})})}),(0,se.jsx)(d.qh,{path:"/store_manager/delivery-partners",element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(_r,{})})}),(0,se.jsx)(d.qh,{path:"/store_manager/inventory",element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(Kr,{})})}),(0,se.jsx)(d.qh,{path:"/store_manager/delivery-fees",element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(Ar,{})})}),(0,se.jsx)(d.qh,{path:"/store_manager/location-codes",element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(Qr,{})})}),(0,se.jsx)(d.qh,{path:"/store_manager/pickup-addresses",element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(Zr,{})})}),(0,se.jsx)(d.qh,{path:"/store_manager/payment-settings",element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(jr,{})})}),(0,se.jsx)(d.qh,{path:`${zs}/*`,element:(0,se.jsx)(Rt,{role:"store_manager",children:(0,se.jsx)(hr,{})})}),(0,se.jsx)(d.qh,{path:"*",element:(0,se.jsx)(mr,{})})]})]})};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),li=t(10540),di=t.n(li),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=di();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,se.jsx)(a.Ht,{client:ji,children:(0,se.jsx)(r.Kd,{children:(0,se.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[l])))?t.splice(l--,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,l;if(void 0!==t)for(var d=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),l&&document.head.appendChild(a)}},o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.p="/",(()=>{var e={792:0};o.f.j=(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,l]=t,d=0;if(i.some((s=>0!==e[s]))){for(n in a)o.o(a,n)&&(o.m[n]=a[n]);if(l)var c=l(o)}for(s&&s(t);do(91298)));l=o.O(l)})(); //# sourceMappingURL=bundle.d86d7039df13ed997ff3.js.map