(()=>{"use strict";var e,s,t,r,n,i={49384:(e,s,t)=>{var r=t(5338),n=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(69067),A=t(73357),g=t(93959),j=t(56908),y=t(10548);const f="undefined"!=typeof window&&window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000/graphql":`${window.location.origin}/graphql`,b=new j.l4(f,{headers:{"Content-Type":"application/json"}}),v=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const t=await(async()=>{try{const e=await(0,y.$)(),s=e.tokens?.accessToken?.toString();return s?{Authorization:`Bearer ${s}`}:{}}catch(e){return{}}})();return b.request(e,s,{...b.requestConfig.headers,...t})},I={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."},S=e=>{if(e.response?.errors){return e.response.errors.map((e=>{if(e.extensions?.code){const s=e.extensions.code;if(I[s])return I[s]}return e.message?.includes("Pickup address ID is required for pickup orders")?"Please select a valid address to deliver.":e.message?.includes("validation")?I.VALIDATION_ERROR:e.message?.includes("not found")?"The requested item was not found.":e.message?.includes("permission")?I.FORBIDDEN:e.message?.includes("already exists")?"This item already exists.":e.message||I.GENERIC_ERROR})).join(". ")}if(e.message?.includes("Network request failed"))return I.NETWORK_ERROR;if(e.message?.includes("timeout"))return I.TIMEOUT_ERROR;if(e.response?.status)switch(e.response.status){case 401:return I.UNAUTHENTICATED;case 403:return I.FORBIDDEN;case 404:return"The requested resource was not found.";case 500:return I.INTERNAL_SERVER_ERROR;case 503:return I.SERVICE_UNAVAILABLE;default:return`Server error (${e.response.status}). Please try again.`}return e.message||I.GENERIC_ERROR},C=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{const t=await v(e,s);if(t.errors){const e=S({response:t});throw new Error(e)}return t}catch(e){const s=S(e),t=new Error(s);throw t.originalError=e,t.isGraphQLError=!0,t}},w="query getAllUsers {\n getAllUsers {\n id\n email\n mobile\n type\n cognitoId\n }\n}",P="\n mutation UpdateOrderStatus($input: UpdateOrderStatusInput!) {\n updateOrderStatus(input: $input) {\n id\n status\n deliveryDate\n deliveryInstructions\n }\n }\n",k="\n query GetUserProfile($userId: String!) {\n getUserProfile(userId: $userId) {\n active\n createdAt\n email\n id\n mobile\n referralId\n secondaryPhone\n type\n updatedAt\n stores {\n edges {\n node {\n id\n name\n taxPercentage\n }\n }\n }\n }\n }\n",F="\n query GetOrdersByStore($storeId: Int!) {\n getOrdersByStore(storeId: $storeId) {\n id\n addressId\n billUrl\n cancelMessage\n cancelledAt\n cancelledByUserId\n createdByUserId\n customOrder\n deliveryDate\n deliveryFee\n deliveryInstructions\n displayCode\n id\n orderTotalAmount\n paymentId\n pickupId\n status\n storeId\n taxAmount\n tipAmount\n totalAmount\n type\n pickupAddress {\n address\n id\n storeId\n }\n address {\n address\n id\n userId\n }\n creator {\n email\n id\n mobile\n }\n delivery {\n driverId\n }\n orderItems {\n edges {\n node {\n id\n inventoryId\n orderAmount\n orderId\n productId\n quantity\n updatedOrderitemsId\n product {\n id\n name\n description\n inventoryItems {\n edges {\n node {\n price\n measurement\n unit\n }\n }\n }\n }\n }\n }\n }\n }\n }\n",E="\n query GetStoreDrivers($storeId: Int!) {\n getStoreDrivers(storeId: $storeId) {\n id\n storeId\n userId\n driver {\n active\n email\n mobile\n referralId\n referredBy\n type\n }\n }\n }\n",D="\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",L="\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",$="\n query GetStores {\n stores {\n id\n name\n address\n description\n disabled\n email\n isActive\n managerUserId\n mobile\n pincodes\n radius\n tnc\n storeDeliveryFee\n taxPercentage\n displayField\n sectionHeaders\n images\n drivers {\n edges {\n node {\n driver {\n active\n id\n email\n mobile\n referredBy\n type\n }\n }\n }\n }\n }\n }\n",z="\n query GetProducts {\n products {\n id\n name\n description\n categoryId\n image\n inventoryItems {\n edges {\n node {\n id\n }\n }\n }\n }\n }\n",R="\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",T="\n mutation DeleteSavedCart($userId: Int!, $storeId: Int!) {\n deleteSavedCart(userId: $userId, storeId: $storeId)\n }\n";var W=t(71511),q=t(87134),O=t(18496);const B="admin",U="user",N="delivery_agent",M="store_manager",_="orders",V="userStatus",H=e=>(0,O.ms)((s=>{e=e?.toLowerCase().trim(),e===B&&(s("view",B),s("view",V)),e===U&&(s("view",U),s("view",_),s("view","cart")),e===N&&s("view",N),e===M&&(s("view",M),s("manage","inventory"))})),G=(0,W.v)((0,q.Zr)(((e,s)=>({cart:{},selectedStore:null,availableStores:[],setAvailableStores:s=>e({availableStores:s}),setSelectedStore:t=>{const r=s(),n=r.selectedStore?.id;if(n){const e={cart:r.cart,customOrder:r.customOrder,listInputAnswers:r.listInputAnswers,deliveryType:r.deliveryType,tipAmount:r.tipAmount||0,pickupAddress:r.pickupAddress,deliveryAddressString:r.deliveryAddressString};try{localStorage.setItem(`indimitra-cart-store-${n}`,JSON.stringify(e))}catch(e){}}const i=t?.id;let a=null;if(i)try{const e=localStorage.getItem(`indimitra-cart-store-${i}`);e&&(a=JSON.parse(e))}catch(e){}e({selectedStore:t,cart:a?.cart||{},customOrder:a?.customOrder||"",listInputAnswers:a?.listInputAnswers||{},deliveryType:a?.deliveryType||"pickup",tipAmount:a?.tipAmount||0,pickupAddress:a?.pickupAddress||null,deliveryAddressString:a?.deliveryAddressString||null})},getSelectedStore:()=>s().selectedStore,pickupAddress:null,setPickupAddress:s=>e({pickupAddress:s}),deliveryAddressString:null,setDeliveryAddressString:s=>e({deliveryAddressString:s}),deliveryType:"pickup",setDeliveryType:s=>e({deliveryType:s}),addToCart:s=>e((e=>({cart:{...e.cart,[s.id]:{...e.cart[s.id]||s,quantity:(e.cart[s.id]?.quantity||0)+1}}}))),removeFromCart:s=>e((e=>{if(!e.cart[s])return e;const t={...e.cart};return t[s].quantity>1?t[s].quantity-=1:delete t[s],{cart:t}})),cartCount:()=>{const e=s();return Object.values(e.cart).reduce(((e,s)=>e+(s.quantity||0)),0)+(e.customOrder?1:0)},cartTotal:()=>Object.values(s().cart).reduce(((e,s)=>e+(s?.price||0)*(s?.quantity||0)),0),clearCart:()=>e({cart:{}}),calculateDeliveryFee:(e,s,t)=>{if(!s||!s.fees||!s.fees.edges||0===s.fees.edges.length)return 0;const r=s.fees.edges.map((e=>e.node)).filter((e=>e.type===t.toUpperCase()));if(0===r.length)return 0;const n=r.sort(((e,s)=>e.limit-s.limit));let i=null;for(const s of n)if(e<=s.limit){i=s;break}if(!i&&n.length>0&&(i=n[n.length-1]),!i)return 0;return i.feeRate},getCartTotals:()=>{const e=s(),t=e.cart,r=e.selectedStore,n=e.deliveryType,i=Object.values(t).reduce(((e,s)=>e+(s.price*s.quantity||0)),0),a=s().calculateDeliveryFee(i,r,n),o=r?.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,deliveryAddressString:e.deliveryAddressString}}})),{name:"indimitra-cart-storage",storage:(0,q.KU)((()=>localStorage)),partialize:e=>({cart:e.cart,customOrder:e.customOrder,listInputAnswers:e.listInputAnswers,deliveryType:e.deliveryType,tipAmount:e.tipAmount,pickupAddress:e.pickupAddress,deliveryAddressString:e.deliveryAddressString})})),K=(0,W.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:H(null)})},fetchUserProfile:async s=>{if(s){e({isProfileLoading:!0});try{const t=await C(k,{userId:s});if(t.errors)return void e({isProfileLoading:!1});const r=t.getUserProfile||t.data?.getUserProfile;if(!r)return void e({isProfileLoading:!1});e({userProfile:r,isProfileLoading:!1,ability:H(r.role)})}catch(s){e({isProfileLoading:!1})}}},isProfileLoaded:()=>!!s().userProfile}))),Y=(0,W.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 r="string"==typeof t?parseInt(t,10):t,n=await C("\n query GetAddressesByUser($userId: Int!) {\n getAddressesByUser(userId: $userId) {\n id\n address\n isPrimary\n }\n }\n",{userId:r}),i=n?.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 r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!t||!s)return null;e({isLoading:!0,error:null});try{const n="string"==typeof t?parseInt(t,10):t,i=await C("\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:n,isPrimary:r});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,r)=>{if(!s)return null;e({isLoading:!0,error:null});try{const n=await C("\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:r});if(n?.updateAddress)return e((e=>({addresses:e.addresses.map((e=>e.id===s?n.updateAddress:e)),isLoading:!1}))),n.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 C("\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}}))),Q=G;var Z=t(74848);const J=e=>(0,Z.jsx)(p.A,{...e});var X=t(86990);const ee=e=>(0,Z.jsx)(X.A,{...e});var se=t(42471);const te=e=>(0,Z.jsx)(se.A,{...e}),re=e=>(0,Z.jsx)(m.A,{...e});var ne=t(89502);const ie=e=>(0,Z.jsx)(ne.A,{...e});var ae=t(60538);const oe=e=>(0,Z.jsx)(ae.A,{...e}),le=e=>{let{size:s=40,thickness:t=3.6,sx:r={}}=e;return(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",...r},children:(0,Z.jsx)(A.A,{size:s,thickness:t})})};var de=t(50790),ce=t(29898),xe=t(25239);const ue=e=>{let{fields:s,onSubmit:t,buttonLabel:r,loading:n,error:i,success:a}=e;const o=e=>{switch(e){case"email":return(0,Z.jsx)(de.A,{sx:{color:"#FF6B6B"}});case"password":return(0,Z.jsx)(ce.A,{sx:{color:"#FF6B6B"}});default:return null}};return(0,Z.jsxs)("form",{onSubmit:t,children:[s.map(((e,s)=>(0,Z.jsx)(te,{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,Z.jsx)(xe.A,{position:"start",children:o(e.type)})}},s))),i&&(0,Z.jsx)(ie,{severity:"error",sx:{mt:2},children:i}),a&&(0,Z.jsx)(ie,{severity:"success",sx:{mt:2},children:a}),(0,Z.jsx)(ee,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:n,sx:{mt:2},children:n?(0,Z.jsx)(le,{size:24,sx:{color:"#fff"}}):r})]})},me=e=>(0,Z.jsx)(h.A,{...e});var he=t(11641);const pe=e=>(0,Z.jsx)(he.A,{...e});var Ae=t(73896);const ge=e=>(0,Z.jsx)(Ae.A,{...e});var je=t(8239),ye=t(14977),fe=t(87393),be=t(37636),ve=t(56826),Ie=t(47839),Se=t(1649),Ce=t(99682),we=t(11235);const Pe={"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 ke=t(44675),Fe=t(82022);const Ee=e=>{let{categoryName:s}=e;return s?(0,Z.jsx)(Fe.A,{label:s,size:"small",sx:{position:"absolute",top:12,right:12,zIndex:1,backgroundColor:"rgba(255, 255, 255, 0.9)",fontWeight:600,fontSize:"0.7rem",borderRadius:"12px",boxShadow:"0 2px 5px rgba(0,0,0,0.1)"}}):null},De="grey",Le=e=>{let{product:s}=e;(0,ke.A)();const{cart:t,addToCart:r,removeFromCart:n}=Q(),{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&&Pe[e.toLowerCase()]){const s=Pe[e.toLowerCase()];return s[Math.floor(Math.random()*s.length)]}return Pe.default})(c):"https://picsum.photos/200");return(0,Z.jsxs)(ye.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,Z.jsx)(Ee,{categoryName:c}),(0,Z.jsx)(fe.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,Z.jsx)(p.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,Z.jsx)(m.A,{variant:"body1",children:"Sold out"})}),(0,Z.jsxs)(be.A,{sx:{flexGrow:1,p:2.5,pb:0,display:"flex",flexDirection:"column"},children:[(0,Z.jsx)(m.A,{gutterBottom:!0,variant:"h6",sx:{fontWeight:600,fontSize:"1.1rem",mb:1,lineHeight:1.3},children:a}),l&&(0,Z.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,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:"auto",mb:2},children:[(0,Z.jsxs)(m.A,{variant:"h6",sx:{fontWeight:700,color:"primary.main",fontSize:"1.2rem"},children:["$",o.toFixed(2)]}),void 0!==s.quantity&&(0,Z.jsxs)(m.A,{variant:"body2",color:"text.secondary",sx:{ml:2,fontWeight:500},children:["Qty: ",s.quantity]})]})]}),(0,Z.jsx)(ve.A,{sx:{justifyContent:"center",pb:2.5,px:2.5},children:u>0?(0,Z.jsxs)(p.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,Z.jsx)(Ie.A,{title:"Remove from cart",children:(0,Z.jsx)(he.A,{onClick:()=>n(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,Z.jsx)(Se.A,{fontSize:"small"})})}),(0,Z.jsx)(m.A,{variant:"body1",sx:{color:"#FF6B6B",fontWeight:700,mx:2,minWidth:"24px",textAlign:"center",fontSize:"1.1rem"},children:u}),(0,Z.jsx)(Ie.A,{title:"Add to cart",children:(0,Z.jsx)(he.A,{onClick:()=>r(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,Z.jsx)(Ce.A,{fontSize:"small"})})})]}):(0,Z.jsx)(X.A,{size:"medium",sx:{width:"100%",height:"48px",background:"transparent",color:x?"#FF6B6B":De,borderRadius:"8px",fontWeight:600,fontSize:"0.95rem",textTransform:"none",position:"relative",overflow:"hidden",border:`2px solid ${x?"#FF6B6B":De}`,transition:"all 0.2s ease","&:hover":{background:"transparent","& .MuiButton-startIcon":{transform:"translateX(2px)"}},"& .MuiButton-startIcon":{transition:"transform 0.2s ease",marginRight:"8px"}},startIcon:(0,Z.jsx)(we.A,{sx:{fontSize:"1.1rem"}}),onClick:()=>r(s),disabled:!x,children:x?"Add to Cart":"Unavailable"})})]})},$e=e=>{let{products:s,title:t}=e;return 0===s.length?(0,Z.jsx)(p.A,{sx:{py:8,textAlign:"center"},children:(0,Z.jsx)(m.A,{variant:"h6",color:"text.secondary",children:"No products available."})}):(0,Z.jsxs)(h.A,{maxWidth:"xl",children:[t&&(0,Z.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,Z.jsx)(je.Ay,{container:!0,spacing:3,children:s.map((e=>(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,Z.jsx)(Le,{product:e})},e.id)))})]})};var ze=t(8451),Re=t(27562),Te=t(64569);const We=e=>{let{categories:s,selectedCategoryId:t,onSelectCategory:r}=e;const n=(0,x.useRef)(null),[i,a]=(0,x.useState)(!1),[o,l]=(0,x.useState)(!1),d=(0,x.useCallback)((()=>{const e=n.current;if(!e)return;const{scrollLeft:s,scrollWidth:t,clientWidth:r}=e,i=t-r;a(s>4),l(i>4&&s{d()}),[s,d]),(0,x.useEffect)((()=>{const e=n.current;if(!e)return;d(),e.addEventListener("scroll",d,{passive:!0});const s=new ResizeObserver(d);return s.observe(e),()=>{e.removeEventListener("scroll",d),s.disconnect()}}),[d]);const c=e=>{const s=n.current;s&&s.scrollBy({left:.75*s.clientWidth*e,behavior:"smooth"})},u=[{id:null,name:"All",isAll:!0},...s.map((e=>{let[s,t]=e;return{id:s,name:t,isAll:!1}}))],h={width:36,height:36,bgcolor:"#fff",color:"#FF6B6B",border:"2px solid #FF6B6B",boxShadow:"0 2px 8px rgba(0,0,0,0.15)",zIndex:2,transition:"all 0.2s ease","&:hover":{bgcolor:"#FF6B6B",color:"#fff",transform:"scale(1.15)",boxShadow:"0 4px 12px rgba(255,107,107,0.4)"},"&.Mui-disabled":{bgcolor:"#f5f5f5",color:"#bbb",border:"2px solid #ddd",boxShadow:"0 1px 4px rgba(0,0,0,0.08)"}};return(0,Z.jsxs)(p.A,{sx:{position:"relative",mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",sx:{mb:1.5,fontWeight:600,color:"text.secondary",fontSize:"0.8rem",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Browse by Category"}),(0,Z.jsxs)(p.A,{sx:{position:"relative"},children:[(0,Z.jsx)(he.A,{onClick:()=>c(-1),disabled:!i,"aria-label":"Scroll categories left",sx:{...h,position:"absolute",left:-4,top:"50%",transform:"translateY(-50%)"},children:(0,Z.jsx)(ze.A,{})}),(0,Z.jsx)(p.A,{ref:n,sx:{display:"flex",gap:{xs:1.5,md:2},overflowX:"auto",overflowY:"hidden",py:1,px:5,scrollSnapType:"x mandatory",WebkitOverflowScrolling:"touch",scrollbarWidth:"none",msOverflowStyle:"none","&::-webkit-scrollbar":{display:"none"}},role:"tablist","aria-label":"Filter products by category",children:u.map((e=>{let{id:s,name:n,isAll:i}=e;const a=i?null===t:t===s,o=i?null:function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e&&Pe[e.toLowerCase()]){const t=Pe[e.toLowerCase()];return t[s%t.length]}return Pe.default}(n,0);return(0,Z.jsxs)(p.A,{component:"button",type:"button",onClick:()=>r(s),role:"tab","aria-selected":a,"aria-label":i?"Show all categories":`Category: ${n}`,sx:{flex:"0 0 auto",scrollSnapAlign:"start",width:{xs:100,md:120,lg:130},height:{xs:110,md:130,lg:140},borderRadius:"16px",border:"2px solid",borderColor:a?"#FF6B6B":"transparent",cursor:"pointer",position:"relative",overflow:"hidden",p:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-end",background:i?"linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%)":"none",boxShadow:a?"0 4px 16px rgba(255,107,107,0.3)":"0 2px 8px rgba(0,0,0,0.08)",transition:"all 0.25s ease","&:hover":{transform:"translateY(-4px)",boxShadow:a?"0 8px 24px rgba(255,107,107,0.35)":"0 6px 20px rgba(0,0,0,0.12)"},"&:focus-visible":{outline:"2px solid #FF6B6B",outlineOffset:2}},children:[!i&&o&&(0,Z.jsx)(p.A,{sx:{position:"absolute",inset:0,backgroundImage:`url(${o})`,backgroundSize:"cover",backgroundPosition:"center",filter:a?"brightness(0.75)":"brightness(0.85)",transition:"filter 0.25s ease"}}),!i&&(0,Z.jsx)(p.A,{sx:{position:"absolute",inset:0,background:"linear-gradient(to top, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0.05) 60%)"}}),i&&(0,Z.jsx)(Te.A,{sx:{color:"#fff",fontSize:{xs:"1.6rem",md:"2rem"},mb:.5,zIndex:1,filter:"drop-shadow(0 1px 2px rgba(0,0,0,0.2))"}}),(0,Z.jsx)(m.A,{variant:"caption",component:"span",sx:{position:"relative",zIndex:1,color:"#fff",fontWeight:a?700:600,fontSize:{xs:"0.7rem",md:"0.78rem"},lineHeight:1.25,textAlign:"center",px:1,pb:{xs:1,md:1.25},width:"100%",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",textShadow:"0 1px 3px rgba(0,0,0,0.4)"},children:i?"All":n}),a&&(0,Z.jsx)(p.A,{sx:{position:"absolute",bottom:0,left:"15%",right:"15%",height:3,borderRadius:"3px 3px 0 0",background:"linear-gradient(90deg, #FF6B6B, #FFA07A)"}})]},i?"all":s)}))}),(0,Z.jsx)(he.A,{onClick:()=>c(1),disabled:!o,"aria-label":"Scroll categories right",sx:{...h,position:"absolute",right:-4,top:"50%",transform:"translateY(-50%)"},children:(0,Z.jsx)(Re.A,{})})]})]})};var qe=t(15327),Oe=t(65460),Be=t(52848),Ue=t(68864),Ne=t(1405),Me=t(69486),_e=t(64745),Ve=t(55759),He=t(65697),Ge=t(39781);const Ke=[{value:"default",label:"Relevance"},{value:"price_asc",label:"Price: Low → High"},{value:"price_desc",label:"Price: High → Low"},{value:"name_asc",label:"Name: A → Z"},{value:"name_desc",label:"Name: Z → A"}],Ye=e=>{let{search:s,onSearchChange:t,sortBy:r,onSortChange:n,inStockOnly:i,onInStockOnlyChange:a,priceRange:o,onPriceRangeChange:l,priceBounds:d,activeFilterCount:c,onClearFilters:u}=e;const[h,A]=(0,x.useState)(!1),g=(0,qe.A)("(max-width: 600px)"),j=d[0],y=d[1],f=y>j;return(0,Z.jsxs)(p.A,{sx:{mb:2},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,Z.jsx)(se.A,{size:"small",placeholder:"Search products…",value:s,onChange:e=>t(e.target.value),InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(_e.A,{sx:{color:"text.secondary",fontSize:20}})})},sx:{flex:1,"& .MuiOutlinedInput-root":{borderRadius:"12px",backgroundColor:"#fafafa",fontSize:"0.9rem","&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"#FF6B6B"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"#FF6B6B",borderWidth:2}}}}),(0,Z.jsx)(Oe.A,{value:r,onChange:e=>n(e.target.value),size:"small",displayEmpty:!0,renderValue:e=>{if(g)return(0,Z.jsx)(He.A,{sx:{fontSize:20,color:"text.secondary",mt:.3}});const s=Ke.find((s=>s.value===e));return(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:.5},children:[(0,Z.jsx)(He.A,{sx:{fontSize:18,color:"text.secondary"}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{fontSize:"0.85rem"},children:s?.label||"Sort"})]})},sx:{minWidth:g?48:180,borderRadius:"12px",backgroundColor:"#fafafa",fontSize:"0.85rem","& .MuiOutlinedInput-notchedOutline":{borderColor:"default"!==r?"#FF6B6B":void 0},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"#FF6B6B"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"#FF6B6B",borderWidth:2}},MenuProps:{PaperProps:{sx:{borderRadius:"12px",mt:.5}}},children:Ke.map((e=>(0,Z.jsx)(Ae.A,{value:e.value,sx:{fontSize:"0.9rem"},children:e.label},e.value)))}),(0,Z.jsx)(Ie.A,{title:h?"Hide filters":"Show filters",children:(0,Z.jsxs)(he.A,{onClick:()=>A((e=>!e)),sx:{width:40,height:40,borderRadius:"12px",border:"1px solid",borderColor:h||c>0?"#FF6B6B":"divider",backgroundColor:h?"rgba(255,107,107,0.08)":"#fafafa",position:"relative",transition:"all 0.2s ease","&:hover":{backgroundColor:"rgba(255,107,107,0.12)",borderColor:"#FF6B6B"}},children:[(0,Z.jsx)(Ve.A,{sx:{fontSize:20,color:h||c>0?"#FF6B6B":"text.secondary"}}),c>0&&(0,Z.jsx)(p.A,{sx:{position:"absolute",top:-4,right:-4,width:18,height:18,borderRadius:"50%",backgroundColor:"#FF6B6B",color:"#fff",fontSize:"0.65rem",fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center"},children:c})]})})]}),(0,Z.jsx)(Be.A,{in:h,timeout:250,children:(0,Z.jsx)(p.A,{sx:{mt:1.5,p:{xs:1.5,sm:2},borderRadius:"14px",backgroundColor:"#fafafa",border:"1px solid",borderColor:"divider"},children:(0,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},gap:{xs:2,sm:3},alignItems:{xs:"stretch",sm:"center"}},children:[(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(Ne.A,{checked:i,onChange:e=>a(e.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"#FF6B6B"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{backgroundColor:"#FF6B6B"}}}),label:(0,Z.jsx)(m.A,{variant:"body2",sx:{fontSize:"0.85rem",fontWeight:500},children:"In stock only"}),sx:{m:0}}),f&&(0,Z.jsxs)(p.A,{sx:{flex:1,minWidth:160},children:[(0,Z.jsxs)(m.A,{variant:"body2",sx:{fontSize:"0.8rem",fontWeight:500,color:"text.secondary",mb:.5},children:["Price: $",o[0].toFixed(0)," – $",o[1].toFixed(0)]}),(0,Z.jsx)(Me.Ay,{value:o,onChange:(e,s)=>l(s),min:j,max:y,step:.5,valueLabelDisplay:"auto",valueLabelFormat:e=>`$${e.toFixed(0)}`,size:"small",sx:{color:"#FF6B6B","& .MuiSlider-thumb":{width:16,height:16,"&:hover, &.Mui-focusVisible":{boxShadow:"0 0 0 6px rgba(255,107,107,0.16)"}},"& .MuiSlider-valueLabel":{backgroundColor:"#FF6B6B",borderRadius:"8px",fontSize:"0.7rem"}}})]}),c>0&&(0,Z.jsx)(Fe.A,{label:"Clear filters",size:"small",onDelete:u,deleteIcon:(0,Z.jsx)(Ge.A,{sx:{fontSize:14}}),onClick:u,sx:{borderRadius:"8px",fontWeight:600,fontSize:"0.78rem",color:"#FF6B6B",borderColor:"#FF6B6B","& .MuiChip-deleteIcon":{color:"#FF6B6B"}},variant:"outlined"})]})})}),!h&&c>0&&(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:.75,mt:1,flexWrap:"wrap",alignItems:"center"},children:[i&&(0,Z.jsx)(Fe.A,{label:"In stock",size:"small",onDelete:()=>a(!1),sx:{borderRadius:"8px",fontSize:"0.75rem",fontWeight:600,backgroundColor:"rgba(255,107,107,0.1)",color:"#FF6B6B","& .MuiChip-deleteIcon":{color:"#FF6B6B",fontSize:16}}}),f&&(o[0]>j||o[1]l([j,y]),sx:{borderRadius:"8px",fontSize:"0.75rem",fontWeight:600,backgroundColor:"rgba(255,107,107,0.1)",color:"#FF6B6B","& .MuiChip-deleteIcon":{color:"#FF6B6B",fontSize:16}}}),"default"!==r&&(0,Z.jsx)(Fe.A,{label:Ke.find((e=>e.value===r))?.label,size:"small",onDelete:()=>n("default"),sx:{borderRadius:"8px",fontSize:"0.75rem",fontWeight:600,backgroundColor:"rgba(255,107,107,0.1)",color:"#FF6B6B","& .MuiChip-deleteIcon":{color:"#FF6B6B",fontSize:16}}}),(0,Z.jsx)(Fe.A,{label:"Clear all",size:"small",onClick:u,variant:"outlined",sx:{borderRadius:"8px",fontSize:"0.72rem",fontWeight:600,color:"text.secondary",borderColor:"divider",cursor:"pointer"}})]})]})};var Qe=t(58031),Ze=t(46831),Je=t(22477),Xe=t(58763);const es=e=>{let{open:s,onClose:t,children:r,title:n,footer:i,hideClose:a=!1,...o}=e;const l=(0,ke.A)();return(0,Z.jsxs)(Qe.A,{open:s,maxWidth:"sm",fullWidth:!0,onClose:a?void 0:t,PaperProps:{sx:{borderRadius:3,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.12)",height:"60vh",maxHeight:"60vh",display:"flex",flexDirection:"column"}},...o,children:[n&&(0,Z.jsxs)(Ze.A,{sx:{textAlign:"center",background:l.palette.custom.gradientPrimary,color:"white",py:2,position:"relative",flexShrink:0},children:[n,!a&&(0,Z.jsx)(he.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,Z.jsx)(Ge.A,{})})]}),(0,Z.jsx)(Je.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:r}),i&&(0,Z.jsx)(Xe.A,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",flexShrink:0},children:i})]})};var ss=t(8532);const ts=e=>(0,Z.jsx)(ss.A,{...e,sx:{minHeight:{xs:"64px",sm:"70px"},px:{xs:2,sm:4},...e.sx}}),rs=e=>(0,Z.jsx)(Ie.A,{...e,sx:{"& .MuiTooltip-tooltip":{backgroundColor:"rgba(42, 47, 79, 0.9)",fontSize:"0.875rem",borderRadius:"8px",padding:"8px 16px"},...e.sx}});var ns=t(30781);const is=e=>(0,Z.jsx)(ns.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 as=t(97190);const os=e=>(0,Z.jsx)(as.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 ls=t(54937);const ds=e=>{let{error:s,title:t="Error",severity:r="error"}=e;return(0,Z.jsx)(p.A,{sx:{p:2},children:(0,Z.jsxs)(ne.A,{severity:r,children:[(0,Z.jsx)(ls.A,{sx:{fontWeight:"bold"},children:t}),s]})})};var cs=t(47027),xs=t(99631),us=t(82935),ms=t(83574);const hs=e=>{let{images:s=[],storeAddress:t,storeDescription:r,deliveryLabel:n,deliverySubtext:i,onChangeAddress:a}=e;const[o,l]=(0,x.useState)(0),[d,c]=(0,x.useState)(!1),[u,h]=(0,x.useState)("next"),[A,g]=(0,x.useState)(!1),j=(0,x.useRef)(null),y=s&&s.length>0?s:[],f=y.length>0,b=(0,x.useCallback)((()=>{j.current&&clearInterval(j.current),!f||y.length<=1||(j.current=setInterval((()=>{h("next"),g(!0),setTimeout((()=>{l((e=>e===y.length-1?0:e+1)),g(!1)}),300)}),4e3))}),[f,y.length]);(0,x.useEffect)((()=>(d?j.current&&clearInterval(j.current):b(),()=>{j.current&&clearInterval(j.current)})),[d,b]);const v=e=>{h(e),g(!0),setTimeout((()=>{l((s=>"next"===e?s===y.length-1?0:s+1:0===s?y.length-1:s-1)),g(!1)}),300),d||b()},I=(0,Z.jsxs)(p.A,{sx:{position:"absolute",bottom:0,left:0,right:0,zIndex:3,background:"linear-gradient(to top, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.35) 60%, transparent 100%)",px:{xs:2,sm:3},pb:{xs:1.5,sm:2},pt:{xs:4,sm:5},display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"flex-end"},gap:{xs:1,sm:2}},children:[(0,Z.jsxs)(p.A,{sx:{minWidth:0,flex:1},children:[t&&(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.25},children:[(0,Z.jsx)(cs.A,{sx:{color:"rgba(255,255,255,0.8)",fontSize:"0.9rem"}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{color:"rgba(255,255,255,0.9)",fontSize:{xs:"0.8rem",sm:"0.88rem"},textShadow:"0 1px 3px rgba(0,0,0,0.4)"},children:t})]}),r&&(0,Z.jsx)(m.A,{variant:"body2",sx:{color:"rgba(255,255,255,0.75)",fontSize:{xs:"0.75rem",sm:"0.82rem"},mt:.25,textShadow:"0 1px 2px rgba(0,0,0,0.3)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:{xs:"normal",sm:"nowrap"},maxWidth:"100%"},children:r})]}),n&&a&&(0,Z.jsxs)(X.A,{variant:"contained",size:"small",onClick:a,sx:{flexShrink:0,bgcolor:"rgba(255,255,255,0.2)",color:"#fff",backdropFilter:"blur(8px)",border:"1px solid rgba(255,255,255,0.3)",borderRadius:2,textTransform:"none",fontWeight:600,fontSize:{xs:"0.78rem",sm:"0.85rem"},px:{xs:1.5,sm:2},py:{xs:.5,sm:.75},minWidth:0,boxShadow:"none",display:"flex",flexDirection:"column",alignItems:{xs:"flex-start",sm:"flex-end"},"&:hover":{bgcolor:"rgba(255,255,255,0.3)",boxShadow:"0 2px 12px rgba(0,0,0,0.2)"}},children:[(0,Z.jsx)("span",{children:n}),i&&(0,Z.jsx)(m.A,{component:"span",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},color:"rgba(255,255,255,0.8)",fontWeight:400,mt:.25,maxWidth:{xs:200,sm:240},overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",textAlign:"inherit"},children:i})]})]});return f?(0,Z.jsx)(ae.A,{elevation:2,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),sx:{position:"relative",width:"100%",height:{xs:180,sm:220,md:260},mb:{xs:2,sm:3},borderRadius:3,overflow:"hidden",backgroundColor:"rgba(0, 0, 0, 0.03)","&:hover .slider-arrow":{opacity:1}},children:(0,Z.jsxs)(p.A,{sx:{width:"100%",height:"100%",position:"relative"},children:[(0,Z.jsx)("img",{src:y[o],alt:`Store offer ${o+1}`,style:{width:"100%",height:"100%",objectFit:"cover",transition:"opacity 0.3s ease-in-out, transform 0.3s ease-in-out",opacity:A?0:1,transform:A?`translateX(${"next"===u?"30px":"-30px"})`:"translateX(0)"},onError:e=>{e.target.style.display="none"}}),I,y.length>1&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(he.A,{className:"slider-arrow",onClick:()=>v("prev"),size:"small",sx:{position:"absolute",left:4,top:"40%",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:4,p:.5},children:(0,Z.jsx)(us.A,{fontSize:"small"})}),(0,Z.jsx)(he.A,{className:"slider-arrow",onClick:()=>v("next"),size:"small",sx:{position:"absolute",right:4,top:"40%",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:4,p:.5},children:(0,Z.jsx)(ms.A,{fontSize:"small"})})]}),y.length>1&&(0,Z.jsx)(p.A,{sx:{position:"absolute",bottom:{xs:40,sm:48},left:"50%",transform:"translateX(-50%)",display:"flex",gap:.75,zIndex:4},children:y.map(((e,s)=>(0,Z.jsx)(p.A,{onClick:()=>(e=>{e!==o&&(h(e>o?"next":"prev"),g(!0),setTimeout((()=>{l(e),g(!1)}),300),d||b())})(s),sx:{width:o===s?16:6,height:6,borderRadius:3,backgroundColor:o===s?"#fff":"rgba(255, 255, 255, 0.5)",cursor:"pointer",transition:"all 0.3s ease","&:hover":{backgroundColor:o===s?"#fff":"rgba(255, 255, 255, 0.75)"}}},s)))})]})}):(0,Z.jsx)(ae.A,{elevation:2,sx:{position:"relative",width:"100%",height:{xs:160,sm:200,md:220},mb:{xs:2,sm:3},borderRadius:3,overflow:"hidden",background:"linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%)"},children:t||r||n&&a?(0,Z.jsxs)(p.A,{sx:{position:"absolute",bottom:0,left:0,right:0,zIndex:3,background:"linear-gradient(to top, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.15) 70%, transparent 100%)",px:{xs:2,sm:3},pb:{xs:1.5,sm:2},pt:{xs:3,sm:4},display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"flex-end"},gap:{xs:1,sm:2}},children:[(0,Z.jsxs)(p.A,{sx:{minWidth:0,flex:1},children:[t&&(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.25},children:[(0,Z.jsx)(cs.A,{sx:{color:"rgba(255,255,255,0.8)",fontSize:"0.9rem"}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{color:"rgba(255,255,255,0.9)",fontSize:{xs:"0.8rem",sm:"0.88rem"}},children:t})]}),r&&(0,Z.jsx)(m.A,{variant:"body2",sx:{color:"rgba(255,255,255,0.7)",fontSize:{xs:"0.75rem",sm:"0.82rem"},mt:.25},children:r})]}),n&&a&&(0,Z.jsxs)(X.A,{variant:"contained",size:"small",onClick:a,sx:{flexShrink:0,bgcolor:"rgba(255,255,255,0.2)",color:"#fff",backdropFilter:"blur(8px)",border:"1px solid rgba(255,255,255,0.3)",borderRadius:2,textTransform:"none",fontWeight:600,fontSize:{xs:"0.78rem",sm:"0.85rem"},px:{xs:1.5,sm:2},py:{xs:.5,sm:.75},boxShadow:"none",display:"flex",flexDirection:"column",alignItems:{xs:"flex-start",sm:"flex-end"},"&:hover":{bgcolor:"rgba(255,255,255,0.3)"}},children:[(0,Z.jsx)("span",{children:n}),i&&(0,Z.jsx)(m.A,{component:"span",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},color:"rgba(255,255,255,0.8)",fontWeight:400,mt:.25},children:i})]})]}):(0,Z.jsxs)(p.A,{sx:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:[(0,Z.jsx)(xs.A,{sx:{fontSize:40,color:"rgba(0,0,0,0.2)",mb:.5}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{color:"rgba(0,0,0,0.35)"},children:"Offers & promotions coming soon"})]})})};var ps=t(30995),As=t(71543),gs=t(50215),js=t(17809),ys=t(90509),fs=t(68806),bs=t(30425),vs=t(21357),Is=t(57097);const Ss=e=>{let{open:s,onClose:t,cartTotal:r,orderItems:n,deliveryType:i,selectedAddressId:a,selectedPickupId:o,userProfile:l,selectedStore:d,tipAmount:c,deliveryInstructions:u,customOrder:h,onSuccess:g,paymentConfig:j}=e;const[y]=(0,x.useState)((()=>crypto.randomUUID())),[f,b]=(0,x.useState)(null),[v,I]=(0,x.useState)(null);(0,x.useEffect)((()=>{b(null),I(null)}),[s]);const S=j?.isSquareConnected&&j?.squareApplicationId&&j?.squareLocationId,{mutate:w,isPending:P,isSuccess:k}=(0,Is.n)({mutationFn:async e=>await C("\n mutation CreateOrderWithPayment(\n $userId: Int!\n $storeId: Int!\n $productItems: [OrderItemInput!]!\n $payment: PaymentInput!\n $pickupOrDelivery: String!\n $addressId: Int\n $pickupId: Int\n $tipAmount: Float\n $deliveryInstructions: String\n $customOrder: String\n ) {\n createOrderWithPayment(\n userId: $userId\n storeId: $storeId\n productItems: $productItems\n payment: $payment\n pickupOrDelivery: $pickupOrDelivery\n addressId: $addressId\n pickupId: $pickupId\n tipAmount: $tipAmount\n deliveryInstructions: $deliveryInstructions\n customOrder: $customOrder\n ) {\n id\n displayCode\n status\n totalAmount\n orderTotalAmount\n deliveryFee\n tipAmount\n taxAmount\n deliveryInstructions\n deliveryDate\n address {\n id\n address\n }\n orderItems {\n edges {\n node {\n id\n quantity\n orderAmount\n product {\n id\n name\n }\n }\n }\n }\n }\n }\n",e),onSuccess:e=>{const s=e?.createOrderWithPayment;s&&s.id?(I(s),b(null)):b("Your payment was processed but we encountered an error creating your order. Please contact support. Your cart has been preserved.")},onError:e=>{b(e?.message||e?.response?.errors?.[0]?.message||"Payment failed. Please try again.")}});(0,x.useEffect)((()=>{k&&v&&(t(),g&&g(v))}),[k,v,t,g]);const F=e=>{if(e&&e.length>0){const s=e[0],t={INVALID_CARD_DATA:"Invalid card information. Please check your card details and try again.",CARD_DECLINED:"Your card was declined. Please try a different payment method.",NETWORK_ERROR:"Network error. Please check your connection and try again.",UNKNOWN_ERROR:"An error occurred during payment processing. Please try again."},r=s.code||"UNKNOWN_ERROR";b(t[r]||s.message||"Payment processing failed. Please try again.")}else b("Payment processing failed. Please try again.")},E=n.reduce(((e,s)=>e+s.quantity),0);return(0,Z.jsxs)(Qe.A,{open:s,onClose:P?void 0:t,disableEscapeKeyDown:P,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.1)"}},children:[(0,Z.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,Z.jsx)(gs.A,{sx:{mr:1,verticalAlign:"middle"}}),"Complete Payment",!P&&!k&&(0,Z.jsx)(he.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,Z.jsx)(js.A,{})})]}),(0,Z.jsx)(Je.A,{children:P?(0,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",py:4,gap:2},children:[(0,Z.jsx)(A.A,{size:60}),(0,Z.jsx)(m.A,{variant:"body1",color:"text.secondary",children:"Processing payment..."})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(p.A,{sx:{mb:3,p:2,bgcolor:"grey.50",borderRadius:1},children:[(0,Z.jsxs)(m.A,{variant:"body2",color:"text.secondary",children:[E," ",1===E?"item":"items"," • ","delivery"===i?"Delivery":"Pickup"]}),(0,Z.jsxs)(m.A,{variant:"h5",fontWeight:"bold",sx:{mt:1},children:["$",r.toFixed(2)]})]}),f&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:f}),S?(0,Z.jsx)(ys.A,{applicationId:j?.squareApplicationId,locationId:j?.squareLocationId,cardTokenizeResponseReceived:async(e,s)=>{if(b(null),!e)return void b("Payment tokenization failed. Please try again.");if(e.errors&&e.errors.length>0)return void F(e.errors);if(!e.token)return void b("Payment tokenization failed. Please try again.");const t=n.map((e=>({productId:e.productId,quantity:e.quantity})));l?.id&&d?.id?w({userId:l.id,storeId:d.id,productItems:t,payment:{paymentToken:e.token,idempotencyKey:y,clientCalculatedAmount:r},pickupOrDelivery:i,addressId:a,pickupId:o,tipAmount:c||0,deliveryInstructions:u||null,customOrder:h||null}):b("Missing required information. Please refresh and try again.")},createPaymentRequest:()=>({countryCode:"US",currencyCode:"USD",total:{amount:r.toFixed(2),label:"Total"}}),onError:F,children:(0,Z.jsxs)(ps.A,{spacing:2,children:[(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(fs.A,{}),(0,Z.jsx)(p.A,{sx:{mt:1},children:(0,Z.jsx)(bs.A,{})})]}),(0,Z.jsx)(As.A,{sx:{my:2},children:(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"OR"})}),(0,Z.jsx)(vs.A,{}),P&&(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:2,py:2},children:[(0,Z.jsx)(A.A,{size:24}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Processing payment..."})]})]})}):(0,Z.jsxs)(ps.A,{spacing:2,children:[(0,Z.jsxs)(ne.A,{severity:"info",sx:{mb:2},children:[(0,Z.jsx)("strong",{children:"Preview Mode:"})," Square credentials not configured. This is a UI preview only.",(0,Z.jsx)("br",{}),(0,Z.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,Z.jsxs)(p.A,{children:[(0,Z.jsxs)(X.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,Z.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,Z.jsxs)(X.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,Z.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",style:{marginRight:8},children:(0,Z.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,Z.jsx)(As.A,{sx:{my:2},children:(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"OR"})}),(0,Z.jsxs)(p.A,{sx:{border:"1px solid",borderColor:"grey.300",borderRadius:1,p:2},children:[(0,Z.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"Card Number"}),(0,Z.jsx)(p.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1,mb:2},children:(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"•••• •••• •••• ••••"})}),(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:2},children:[(0,Z.jsxs)(p.A,{sx:{flex:1},children:[(0,Z.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"Expiration"}),(0,Z.jsx)(p.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1},children:(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"MM/YY"})})]}),(0,Z.jsxs)(p.A,{sx:{flex:1},children:[(0,Z.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"CVV"}),(0,Z.jsx)(p.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1},children:(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"•••"})})]})]}),(0,Z.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{mt:2,display:"block"},children:"Postal Code"}),(0,Z.jsx)(p.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1,mt:1},children:(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"12345"})})]}),(0,Z.jsx)(m.A,{variant:"caption",color:"text.secondary",sx:{textAlign:"center",fontStyle:"italic"},children:"Payment form will be interactive once Square credentials are configured"})]})]})}),!k&&!P&&(0,Z.jsx)(Xe.A,{sx:{px:3,pb:2},children:(0,Z.jsx)(X.A,{onClick:t,color:"inherit",children:"Cancel"})})]})};var Cs=t(50779),ws=t(69307),Ps=t(29428),ks=t(53215),Fs=t(7578),Es=t(89388);const Ds=e=>{let{paymentConfig:s,selectedMethod:t,onMethodChange:r}=e;const n=s?.isSquareConnected&&s?.squareApplicationId&&s?.squareLocationId,i=s?.codEnabled;return(0,x.useEffect)((()=>{t||(n?r("square"):i&&r("cod"))}),[n,i,t,r]),n||i?(0,Z.jsxs)(Cs.A,{component:"fieldset",fullWidth:!0,sx:{mb:3},children:[(0,Z.jsx)(ws.A,{component:"legend",sx:{mb:2,fontWeight:500},children:"Select Payment Method"}),(0,Z.jsxs)(Ps.A,{value:t||"",onChange:e=>r(e.target.value),children:[n&&(0,Z.jsx)(Ue.A,{value:"square",control:(0,Z.jsx)(ks.A,{color:"primary"}),label:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Fs.A,{color:"primary"}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"body1",sx:{fontWeight:600},children:"Pay with Card"}),(0,Z.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,Z.jsx)(Ue.A,{value:"cod",control:(0,Z.jsx)(ks.A,{color:"primary"}),label:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Es.A,{color:"primary"}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"body1",sx:{fontWeight:600},children:"Cash on Delivery"}),(0,Z.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,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:"Store payment system unavailable. Please contact store or try again later."})},Ls={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 $s=()=>{const[e,s]=(0,x.useState)(""),[t,r]=(0,x.useState)(0),[n,i]=(0,x.useState)(12),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)("default"),[c,j]=(0,x.useState)(!1),[y,f]=(0,x.useState)([0,0]),{selectedStore:b}=Q(),v=function(e,s){const[t,r]=(0,x.useState)(e);return(0,x.useEffect)((()=>{const t=setTimeout((()=>{r(e)}),s);return()=>{clearTimeout(t)}}),[e,s]),t}(e,300),{data:I,isLoading:S,error:w}=(0,u.I)({queryKey:["storeInventory",b?.id],queryFn:async()=>await C("\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:b.id,isListed:!0}),enabled:!!b?.id}),P=(0,x.useMemo)((()=>I?.getInventoryByStore?.map((e=>{const s=b?.id,t=e.productId,r=Ls[s]||{};return{id:e.productId,name:e.product.name,image:e.product.image||r[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}}))||[]),[I,b?.id]),k=(0,x.useMemo)((()=>{const e=new Map;return P.forEach((s=>{null!=s.categoryId&&s.categoryName&&e.set(s.categoryId,s.categoryName)})),Array.from(e.entries()).sort(((e,s)=>e[1].localeCompare(s[1],void 0,{sensitivity:"base"})))}),[P]),F=(0,x.useMemo)((()=>{if(0===P.length)return[0,0];const e=P.map((e=>e.price));return[Math.floor(Math.min(...e)),Math.ceil(Math.max(...e))]}),[P]);(0,x.useEffect)((()=>{f(F)}),[F]),(0,x.useEffect)((()=>{o(null),d("default"),j(!1),r(0)}),[b?.id]),(0,x.useEffect)((()=>{r(0)}),[v,a,l,c,y]);const E=(0,x.useMemo)((()=>{let e=0;return c&&(e+=1),F[1]>F[0]&&(y[0]>F[0]||y[1]{d("default"),j(!1),f(F)}),[F]),L=(0,x.useMemo)((()=>{const e=v.trim().toLowerCase();return P.filter((s=>(null===a||s.categoryId===a)&&(!(c&&!s.isAvailable)&&(!(s.pricey[1])&&(!e||(s.name.toLowerCase().includes(e)||s.categoryName?.toLowerCase().includes(e))))))).sort(((e,s)=>{switch(l){case"price_asc":return e.price-s.price;case"price_desc":return s.price-e.price;case"name_asc":return e.name.localeCompare(s.name,void 0,{sensitivity:"base"});case"name_desc":return s.name.localeCompare(e.name,void 0,{sensitivity:"base"});default:return e.isAvailable===s.isAvailable?0:e.isAvailable?-1:1}}))}),[P,v,a,l,c,y]),$=(0,x.useMemo)((()=>L.slice(t*n,t*n+n)),[L,t,n]);return w?(0,Z.jsxs)(m.A,{children:["Error fetching products: ",w.message]}):(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(Ye,{search:e,onSearchChange:s,sortBy:l,onSortChange:d,inStockOnly:c,onInStockOnlyChange:j,priceRange:y,onPriceRangeChange:f,priceBounds:F,activeFilterCount:E,onClearFilters:D}),!S&&P.length>0&&(0,Z.jsx)(We,{categories:k,selectedCategoryId:a,onSelectCategory:o}),S?(0,Z.jsx)(p.A,{display:"flex",justifyContent:"center",my:4,children:(0,Z.jsx)(A.A,{})}):0===P.length?(0,Z.jsx)(m.A,{variant:"h6",align:"center",sx:{mt:4},children:"No products available in this store."}):0===L.length?(0,Z.jsx)(m.A,{variant:"body1",align:"center",sx:{mt:4,color:"text.secondary"},children:"No products match your filters. Try adjusting your search or filters."}):(0,Z.jsx)($e,{products:$}),L.length>0&&(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,Z.jsx)(g.A,{rowsPerPageOptions:[8,12,24],component:"div",count:L.length,rowsPerPage:n,page:t,onPageChange:(e,s)=>{r(s)},onRowsPerPageChange:e=>{i(parseInt(e.target.value,10)),r(0)}})})]})};var zs=t(49799),Rs=t(44090),Ts=t(57873),Ws=t(82241),qs=t(58620),Os=t(87980),Bs=t(78325),Us=t(54415),Ns=t(84201);const Ms="/login",_s="/forgot-password",Vs="/admin",Hs="/user",Gs="/delivery_agent",Ks="/store_manager",Ys="/store_manager/orders",Qs="/orders",Zs="/profile",Js="/signup",Xs="/cart";var et=t(28939),st=t(48393),tt=t(80437),rt=t(58438),nt=t(62594);const it=e=>{let{email:s,onComplete:t,onSuccess:r}=e;const n=(0,d.Zp)(),[i,a]=(0,x.useState)(""),[o,l]=(0,x.useState)(!1),[c,u]=(0,x.useState)(""),[h,p]=(0,x.useState)("");return(0,Z.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),l(!0),u(""),p("");try{await(0,nt.z)({username:s,confirmationCode:i}),p("Account verified successfully! Redirecting to login..."),setTimeout((()=>{n("/")}),2e3),r&&r(),t&&t()}catch(e){u(e.message||"OTP verification failed. Please try again.")}finally{l(!1)}},children:[(0,Z.jsx)(m.A,{variant:"h4",component:"h1",gutterBottom:!0,children:"Verify OTP"}),(0,Z.jsx)(se.A,{label:"Enter OTP",variant:"outlined",fullWidth:!0,margin:"normal",value:i,onChange:e=>a(e.target.value),required:!0}),c&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mt:2},children:c}),h&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mt:2},children:h}),(0,Z.jsx)(X.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,Z.jsx)(A.A,{size:24,sx:{color:"#fff"}}):"Verify OTP"})]})};var at=t(5673),ot=t(76768);const lt=e=>{let{onSuccess:s,onError:t}=e;const r=(0,d.Zp)(),{setUser:n,setAbility:i,setModalOpen:a}=K(),[o,l]=(0,x.useState)(""),[c,u]=(0,x.useState)(""),[m,h]=(0,x.useState)(!1),[g,j]=(0,x.useState)(""),[y,f]=(0,x.useState)(!1),[b,v]=(0,x.useState)(!1);return(0,Z.jsx)(p.A,{children:y?(0,Z.jsx)(it,{email:o,onSuccess:()=>r("/"),onComplete:()=>f(!1)}):(0,Z.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),h(!0),j("");try{const e=await(0,st.J)({username:o,password:c});if("CONFIRM_SIGN_UP"===e.nextStep?.signInStep)return await(0,tt.h)({username:o}),void f(!0);const t=await(0,rt.T)(),l=t["custom:role"].toLowerCase();n({email:t.email,role:l});const d=H(l);i(d),a(!1),s&&s(),r(`/${l}`)}catch(e){if(e.message.includes("User is not confirmed"))try{await(0,tt.h)({username:o}),f(!0)}catch(e){j(e.message||"Error resending OTP.")}else j(e.message||"Login failed. Please try again.")}finally{h(!1)}},children:[(0,Z.jsx)(se.A,{label:"Email",variant:"outlined",fullWidth:!0,value:o,onChange:e=>l(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(de.A,{sx:{color:"#FF6B6B"}})})}}),(0,Z.jsx)(se.A,{label:"Password",variant:"outlined",type:b?"text":"password",fullWidth:!0,value:c,onChange:e=>u(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(ce.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,Z.jsx)(xe.A,{position:"end",children:(0,Z.jsx)(he.A,{onClick:()=>v((e=>!e)),edge:"end",children:b?(0,Z.jsx)(ot.A,{}):(0,Z.jsx)(at.A,{})})})}}),g&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:g}),(0,Z.jsx)(X.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:m,sx:{py:1.2,borderRadius:"8px",textTransform:"none",fontSize:"1rem"},children:m?(0,Z.jsx)(A.A,{size:24,sx:{color:"#fff"}}):"Login"})]})})};var dt=t(83728),ct=t(71432),xt=t(19873);const ut=e=>{let{referredBy:s="",onSuccess:t}=e;const[r,n]=(0,x.useState)(""),[i,a]=(0,x.useState)(""),[o,l]=(0,x.useState)(""),[d,c]=(0,x.useState)(""),[u,m]=(0,x.useState)(""),[h,A]=(0,x.useState)(s),[g,j]=(0,x.useState)(!1),[y,f]=(0,x.useState)(""),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)(!1);return(0,Z.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),j(!0),f(""),v("");try{await(0,dt.H)({username:r,password:d,options:{userAttributes:{"custom:given_name":i,"custom:family_name":o,"custom:phone_number":u,"custom:referredBy":h}}}),v("Signup successful! Enter the OTP sent to your email."),t&&t(r)}catch(e){if(e.message.includes("User already exists"))try{await(0,tt.h)({username:r}),v("OTP resent. Please check your email."),t&&t(r)}catch(e){f(e.message||"Error resending OTP.")}else f(e.message||"Signup failed. Please try again.")}finally{j(!1)}},children:[(0,Z.jsx)(se.A,{label:"First Name",variant:"outlined",fullWidth:!0,value:i,onChange:e=>a(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(ct.A,{sx:{color:"#FF6B6B"}})})}}),(0,Z.jsx)(se.A,{label:"Last Name",variant:"outlined",fullWidth:!0,value:o,onChange:e=>l(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(ct.A,{sx:{color:"#FF6B6B"}})})}}),(0,Z.jsx)(se.A,{label:"Email",variant:"outlined",fullWidth:!0,value:r,onChange:e=>n(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(de.A,{sx:{color:"#FF6B6B"}})})}}),(0,Z.jsx)(se.A,{label:"Password",variant:"outlined",type:I?"text":"password",fullWidth:!0,value:d,onChange:e=>c(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(ce.A,{sx:{color:"#FF6B6B"}})}),endAdornment:(0,Z.jsx)(xe.A,{position:"end",children:(0,Z.jsx)(he.A,{onClick:()=>S((e=>!e)),edge:"end",children:I?(0,Z.jsx)(ot.A,{}):(0,Z.jsx)(at.A,{})})})}}),(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:1,mb:2},children:[(0,Z.jsx)(se.A,{label:"Country Code",variant:"outlined",value:"+1",disabled:!0,sx:{width:"120px"},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(xt.A,{sx:{color:"#FF6B6B"}})})}}),(0,Z.jsx)(se.A,{label:"Phone Number",variant:"outlined",fullWidth:!0,value:u,onChange:e=>m(e.target.value),required:!0,InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(xt.A,{sx:{color:"#FF6B6B"}})})}})]}),(0,Z.jsx)(se.A,{label:"Referral Code",variant:"outlined",fullWidth:!0,value:h,onChange:e=>A(e.target.value),disabled:!!s,sx:{mb:2},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(de.A,{sx:{color:"#FF6B6B"}})})}}),y&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:y}),b&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:b}),(0,Z.jsx)(X.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:g,sx:{mt:1,mb:2},children:g?"Processing...":"Sign Up"})]})};var mt=t(15061),ht=t(7888);const pt=e=>{let{onSuccess:s}=e;const[t,r]=(0,x.useState)(""),[n,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(""),[l,c]=(0,x.useState)(!1),[u,m]=(0,x.useState)(""),[h,p]=(0,x.useState)(""),[A,g]=(0,x.useState)(1),j=(0,d.Zp)();return(0,Z.jsx)(J,{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,Z.jsxs)(oe,{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,Z.jsxs)(J,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,Z.jsx)(re,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:1===A?"Forgot Password":"Reset Password"}),(0,Z.jsx)(re,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:1===A?"Enter your email address to receive a reset code":"Enter the OTP sent to your email and your new password"})]}),1===A?(0,Z.jsx)(ue,{fields:[{label:"Email",type:"email",value:t,onChange:r}],onSubmit:async e=>{e.preventDefault(),c(!0),m(""),p("");try{await(0,mt.x)({username:t}),g(2),p("OTP sent successfully! Check your email.")}catch(e){m(e.message||"Failed to send OTP. Try again.")}finally{c(!1)}},buttonLabel:"Send OTP",loading:l,error:u,success:h}):(0,Z.jsx)(ue,{fields:[{label:"OTP",type:"text",value:n,onChange:i},{label:"New Password",type:"password",value:a,onChange:o}],onSubmit:async e=>{e.preventDefault(),c(!0),m(""),p("");try{await(0,ht.P)({username:t,confirmationCode:n,newPassword:a}),p("Password reset successfully! Redirecting to login..."),setTimeout((()=>{s?s():j("/")}),2e3)}catch(e){m(e.message||"Failed to reset password. Try again.")}finally{c(!1)}},buttonLabel:"Reset Password",loading:l,error:u,success:h})]})})},At=e=>{let{open:s,onClose:t,initialForm:r="login"}=e;const[n,i]=(0,x.useState)(r),[a,o]=(0,x.useState)(""),[l,d]=(0,x.useState)(!1),c=(0,x.useRef)(0),u=(0,ke.A)();(0,x.useEffect)((()=>{s&&(i("login"),d(!1),o(""),c.current+=1)}),[s]);const h=e=>{i(e),d(!1)};return(0,Z.jsx)(et.A,{open:s,onClose:t,"aria-labelledby":"modal-modal-title","aria-describedby":"modal-modal-description",sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:(0,Z.jsxs)(p.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,Z.jsx)(X.A,{onClick:t,sx:{position:"absolute",top:8,right:8,minWidth:0,p:.5},children:(0,Z.jsx)(Ge.A,{})}),(0,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.5rem",sm:"1.75rem"}},children:"login"===n?"Welcome Back":"signup"===n?"Create Account":"otp"===n?"Verify Email":""}),(0,Z.jsx)(m.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"login"===n?"Sign in to continue your journey with us":"signup"===n?"Join us and start your adventure":"otp"===n?"Enter the OTP sent to your email":""})]}),l&&"login"===n&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:"Email verified successfully! Please login to continue."}),"login"===n?(0,Z.jsx)(lt,{onSuccess:t},`login-form-${c.current}`):"signup"===n?(0,Z.jsx)(ut,{onSuccess:e=>{o(e),i("otp")}}):"otp"===n?(0,Z.jsx)(it,{email:a,onSuccess:()=>{d(!0),i("login")}}):(0,Z.jsx)(pt,{onSuccess:()=>h("login")}),(0,Z.jsxs)(p.A,{sx:{mt:3,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:["login"===n&&(0,Z.jsx)(X.A,{onClick:()=>h("forgotPassword"),sx:{color:u.palette.primary.main,textTransform:"none"},children:"Forgot Password?"}),"otp"!==n&&(0,Z.jsxs)(m.A,{variant:"body2",sx:{color:"text.secondary"},children:["login"===n?"Don't have an account?":"signup"===n?"Already have an account?":"Remember your password?",(0,Z.jsx)(X.A,{color:"primary",onClick:()=>h("login"===n?"signup":"login"),sx:{textTransform:"none"},children:"login"===n?"Sign Up":"Login"})]})]})]})})};var gt=t(17532),jt=t(10423),yt=t(10420),ft=t(74202),bt=t(92659),vt=t(37856),It=t(2223),St=t(42702),Ct=t(28800),wt=t(58407),Pt=t(72048),kt=t(37211),Ft=t(81385),Et=t(10364),Dt=t(2882),Lt=t(85873);const $t=e=>{let{store:s,isSelected:t,onSelect:r}=e;const n=s.isActive;return(0,Z.jsx)(ae.A,{elevation:0,sx:{mb:2,borderRadius:2,overflow:"hidden",transition:"all 0.2s ease",border:"1px solid",borderColor:t?"primary.main":n?"rgba(0, 0, 0, 0.08)":"rgba(211, 47, 47, 0.3)",backgroundColor:n?"transparent":"rgba(0, 0, 0, 0.01)","&:hover":{transform:n?"translateY(-2px)":"none",boxShadow:n?2:0}},children:(0,Z.jsx)(Rs.Ay,{disablePadding:!0,children:(0,Z.jsx)(kt.A,{onClick:()=>n&&r(s),selected:t,disabled:!n,sx:{p:0,cursor:n?"pointer":"not-allowed"},children:(0,Z.jsx)(p.A,{sx:{width:"100%"},children:(0,Z.jsxs)(p.A,{sx:{p:2,backgroundColor:t?"rgba(0, 0, 0, 0.02)":"transparent"},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"flex-start",mb:1},children:[(0,Z.jsx)(Ft.A,{sx:{bgcolor:n?t?"primary.main":"grey.300":"rgba(211, 47, 47, 0.1)",mr:2,color:n?"inherit":"error.main"},children:n?(0,Z.jsx)(yt.A,{}):(0,Z.jsx)(Lt.A,{})}),(0,Z.jsxs)(p.A,{sx:{flex:1},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[(0,Z.jsx)(m.A,{fontWeight:600,fontSize:"1.1rem",color:"text.primary",children:s.name}),!n&&(0,Z.jsx)(Fe.A,{label:"Offline",size:"small",sx:{height:20,fontSize:"0.75rem",backgroundColor:"rgba(211, 47, 47, 0.1)",color:"error.main",fontWeight:500}})]}),(!n||s.description)&&(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"flex-start",mb:1,backgroundColor:n?"transparent":"rgba(0, 0, 0, 0.02)",p:n?0:1,borderRadius:1},children:[(0,Z.jsx)(Dt.A,{sx:{fontSize:"0.9rem",color:n?"text.secondary":"error.main",mr:.5,mt:.2}}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{fontStyle:n?"normal":"italic",fontWeight:n?400:500},children:s.description||"Store timings not available"})]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Z.jsx)(It.A,{sx:{fontSize:"0.9rem",color:"text.secondary",mr:.5}}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:s.address})]})]})]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:1},children:[s.radius&&(0,Z.jsx)(Fe.A,{icon:(0,Z.jsx)(Et.A,{fontSize:"small"}),label:`${s.radius} mi radius`,size:"small",variant:"outlined",color:t?"primary":"default",sx:{opacity:n?1:.7}}),!n&&(0,Z.jsx)(m.A,{variant:"caption",sx:{ml:"auto",color:"error.main",fontStyle:"italic"},children:"Store is currently offline"})]})]})})})})})},zt=e=>{let{availableStores:s,selectedStore:t,handleStoreSelect:r}=e;return(0,Z.jsx)(zs.A,{sx:{mt:1},children:s.map((e=>(0,Z.jsx)($t,{store:e,isSelected:t?.id===e.id,onSelect:r},e.id)))})};var Rt=t(1984);const Tt=()=>(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:1},children:[(0,Z.jsx)(Rt.A,{}),(0,Z.jsx)(m.A,{variant:"h5",fontWeight:600,children:"Select a Store"})]}),Wt=()=>(0,Z.jsx)(ae.A,{elevation:0,sx:{p:3,textAlign:"center",backgroundColor:"rgba(33, 150, 243, 0.1)",borderRadius:2},children:(0,Z.jsx)(m.A,{sx:{fontWeight:500,color:"info.main"},children:"No stores available at the moment."})}),qt=e=>{let{value:s,onChange:t,onValidAddress:r}=e;const n=(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"}});n.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),r(!0)):(u(null),o(!1),r(!1))}))}else d(!1),s&&s.trim().length>10?(o(!0),r(!0)):(o(!1),r(!1))}catch(e){d(!1),s&&s.trim().length>10?(o(!0),r(!0)):(o(!1),r(!1))}}),300);return()=>clearTimeout(e)}),[t,r,s]),(0,x.useEffect)((()=>{""===s?(o(!1),r(!1),u(null)):!l&&s.trim().length>10&&(o(!0),r(!0))}),[s,r,l]);return(0,Z.jsx)(se.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),r(!1),u(null)):l||(s.trim().length>10?(o(!0),r(!0)):(o(!1),r(!1)))},placeholder:l?"Start typing to see address suggestions...":"Enter your complete address (e.g., 123 Main St, City, State 12345)"})},Ot=e=>{let{size:s=24,sx:t}=e;return(0,Z.jsx)(A.A,{size:s,sx:{color:"inherit",...t}})},Bt=e=>{let{pincodes:s=[]}=e;const[t,r]=(0,x.useState)(!1),[n,i]=(0,x.useState)(""),a=(0,x.useMemo)((()=>[...s].map((e=>String(e).trim())).filter(Boolean).sort(((e,s)=>e.localeCompare(s)))),[s]),o=(0,x.useMemo)((()=>{if(!n.trim())return a;const e=n.trim();return a.filter((s=>s.includes(e)))}),[a,n]),l=a.length>30;return 0===a.length?null:(0,Z.jsxs)(ae.A,{elevation:0,sx:{border:"1px solid",borderColor:"divider",borderRadius:2,overflow:"hidden"},children:[(0,Z.jsxs)(p.A,{onClick:()=>r((e=>!e)),sx:{display:"flex",alignItems:"center",gap:1,px:2,py:1.25,cursor:"pointer",userSelect:"none","&:hover":{bgcolor:"grey.50"},transition:"background-color 0.15s"},children:[(0,Z.jsx)(vt.A,{sx:{fontSize:18,color:"text.secondary"}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{flex:1,fontWeight:600,fontSize:"0.85rem"},children:"Serviceable pincodes"}),(0,Z.jsx)(Fe.A,{label:a.length,size:"small",sx:{height:22,fontSize:"0.72rem",fontWeight:700,bgcolor:"rgba(0,0,0,0.06)"}}),(0,Z.jsx)(Pt.A,{sx:{fontSize:20,color:"text.secondary",transition:"transform 0.25s",transform:t?"rotate(180deg)":"rotate(0deg)"}})]}),(0,Z.jsxs)(Be.A,{in:t,timeout:250,children:[(0,Z.jsx)(As.A,{}),(0,Z.jsxs)(p.A,{sx:{px:2,py:1.5},children:[l&&(0,Z.jsx)(se.A,{size:"small",placeholder:"Search pincode…",value:n,onChange:e=>i(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(_e.A,{sx:{fontSize:18,color:"text.disabled"}})})},sx:{mb:1.5,"& .MuiOutlinedInput-root":{borderRadius:"10px",fontSize:"0.85rem",height:36}}}),0===o.length?(0,Z.jsxs)(m.A,{variant:"body2",color:"text.disabled",sx:{textAlign:"center",py:1,fontSize:"0.82rem"},children:['No pincodes match "',n,'"']}):(0,Z.jsx)(p.A,{sx:{display:"flex",flexWrap:"wrap",gap:.75,maxHeight:160,overflowY:"auto",scrollbarWidth:"thin","&::-webkit-scrollbar":{width:4},"&::-webkit-scrollbar-thumb":{backgroundColor:"rgba(0,0,0,0.12)",borderRadius:2}},children:o.map((e=>(0,Z.jsx)(Fe.A,{label:e,size:"small",variant:"outlined",sx:{fontSize:"0.75rem",fontWeight:500,height:26,borderRadius:"8px",borderColor:"grey.300"}},e)))})]})]})]})},Ut=e=>{let{open:s,onClose:t,forceStep:r,initialStore:n}=e;const{selectedStore:i,setSelectedStore:o,availableStores:l,setPickupAddress:d,deliveryType:c,setDeliveryType:u,setDeliveryAddressString:h}=Q(),{user:A,userProfile:g,fetchUserProfile:j,isProfileLoading:f,setModalOpen:b,setCurrentForm:v}=K(),I=(0,a.jE)(),{addresses:S,selectedAddressId:C,setSelectedAddressId:w,fetchAddresses:P,isLoading:k,createAddress:F}=Y(),[E,D]=(0,x.useState)("store"),[L,$]=(0,x.useState)(null),[z,R]=(0,x.useState)(null),[T,W]=(0,x.useState)(null),[q,O]=(0,x.useState)(""),[B,U]=(0,x.useState)(!1),[N,M]=(0,x.useState)(""),[_,V]=(0,x.useState)(!1),[H,G]=(0,x.useState)(!1),[J,ee]=(0,x.useState)(!1),[se,te]=(0,x.useState)(""),[re,ie]=(0,x.useState)(0),[oe,le]=(0,x.useState)([]),[de,ce]=(0,x.useState)(""),[xe,ue]=(0,x.useState)(null),me=g?S:oe,pe=g?C:de;(0,x.useEffect)((()=>{const e=!!g;!1===xe&&!0===e&&(le([]),ce(""),g?.id&&"pickup"===E&&L&&P(g.id),W(null),O("")),!0===xe&&!1===e&&w(null),ue(e)}),[g,E,L,P,w,xe]),(0,x.useEffect)((()=>{"pickup"===E&&L&&g?.id&&P(g.id)}),[E,L,g?.id,P]),(0,x.useEffect)((()=>{if(!("pickup"===E&&(1===re||!L?.pickupAddresses?.edges?.length))||g)return;let e=!1;return(async()=>{try{const s=await(0,y.$)(),t=s?.tokens?.idToken?.payload?.sub;t&&!e&&await j(t)}catch{}})(),()=>{e=!0}}),[E,re,g,A,j,L]),(0,x.useEffect)((()=>{s&&r&&(D(r),n&&$(n)),s||(D("store"),$(null),Ae())}),[s,r,n]);const Ae=()=>{g?w(null):ce(""),M(""),V(!1),G(!1),ee(!1),W(null),O(""),R(null),ie(0),te("")},ge=async()=>{U(!0);try{const e=await(0,y.$)(),s=e?.tokens?.idToken?.payload?.sub;if(s){if(g||await j(s),g?.id||s){const e=g?.id;e&&(await P(e),le([]),ce(""))}}else w(null);W(null),O("")}catch(e){}finally{U(!1)}},je=()=>{b(!0),v("login")},ye=async()=>{if(N.trim()&&J)if(fe(N),te(N),u("delivery"),R(null),g?w(null):ce(""),g?.id){if(!S.some((e=>e.address.toLowerCase().trim()===N.toLowerCase().trim()))){G(!0);try{await F(N,g.id,_);const e=(await P(g.id)).find((e=>e.address.toLowerCase().trim()===N.toLowerCase().trim()));e&&w(e.id),I.invalidateQueries(["userAddresses",g.id])}catch(e){}finally{G(!1)}}}else{if(!oe.some((e=>e.address.toLowerCase().trim()===N.toLowerCase().trim()))){const e={id:`temp_${Date.now()}`,address:N,isPrimary:0===oe.length};le((s=>[...s,e])),ce(e.id)}}},fe=e=>{if(!e||!L)return W(null),void O("");const s=e.match(/\b(\d{5})(?:-\d{4})?\b/g),t=s?s[s.length-1]:null,r=(L?.pincodes||[]).map((e=>String(e).trim())),n=t?String(t).trim():"";n&&r.includes(n)?(W("success"),O("Store delivers here")):(W("error"),O("Store does not deliver here."))},be=e=>{localStorage.setItem("selectedStoreId",String(e.id)),$(e),D("pickup")},ve=()=>{if(!L||!z)return;const e=(L.pickupAddresses?.edges?.map((e=>e.node))||[]).find((e=>String(e.id)===String(z)));o(L),d(e),u("pickup"),h(null),D("store"),$(null),R(null),Ae(),t()},Se=()=>{if("success"===T&&se){let e=se;if(g&&C&&S&&S.length>0){const s=S.find((e=>e.id===C));s&&s.address&&(e=s.address)}if(!e||!e.trim())return;o(L),setTimeout((()=>{d(null),u("delivery"),h(e.trim())}),10),setTimeout((()=>{D("store"),$(null),Ae(),t()}),1200)}},Ce=()=>{D("store"),$(null),Ae()},we=!i;if("store"===E)return(0,Z.jsx)(es,{open:s,onClose:t,title:(0,Z.jsx)(Tt,{}),hideClose:we,children:0===l.length?(0,Z.jsx)(Wt,{}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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,Z.jsx)(zt,{availableStores:l,selectedStore:i,handleStoreSelect:be})]})});if("pickup"===E){const e=L?.pickupAddresses?.edges?.map((e=>e.node))||[],r=e.length>0,n=(0,Z.jsx)(X.A,{onClick:Ce,variant:"text",color:"inherit",size:"small",startIcon:(0,Z.jsx)(bt.A,{}),sx:{fontWeight:500},children:"Back to stores"});return(0,Z.jsxs)(es,{open:s,onClose:t,title:(0,Z.jsx)(Tt,{}),footer:n,hideClose:we,children:[(0,Z.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,Z.jsx)("b",{children:L?.name})]}),(0,Z.jsx)(p.A,{sx:{borderBottom:1,borderColor:"divider",mb:2},children:(0,Z.jsxs)(gt.A,{value:re,onChange:(e,s)=>ie(s),variant:"fullWidth",sx:{minHeight:42,"& .MuiTabs-indicator":{height:3,borderRadius:"3px 3px 0 0"}},children:[(0,Z.jsx)(jt.A,{icon:(0,Z.jsx)(yt.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Pickup",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:42,py:0}}),(0,Z.jsx)(jt.A,{icon:(0,Z.jsx)(ft.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Delivery",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:42,py:0}})]})}),0===re&&(0,Z.jsx)(ps.A,{spacing:2,children:r?(0,Z.jsxs)(Z.Fragment,{children:[e.map((e=>(0,Z.jsxs)(ae.A,{elevation:0,onClick:()=>{return s={target:{value:String(e.id)}},R(s.target.value),u("pickup"),h(null),g?w(null):ce(""),W(null),void O("");var s},sx:{p:2,cursor:"pointer",border:"1.5px solid",borderColor:String(z)===String(e.id)?"primary.main":"grey.200",borderRadius:2,bgcolor:String(z)===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,Z.jsx)(ks.A,{checked:String(z)===String(e.id),value:String(e.id),color:"primary",size:"small",sx:{p:0}}),(0,Z.jsx)(m.A,{variant:"body2",children:e.address})]},e.id))),(0,Z.jsx)(X.A,{onClick:ve,variant:"contained",color:"primary",fullWidth:!0,startIcon:(0,Z.jsx)(vt.A,{}),disabled:!z,sx:{mt:1,fontWeight:600,py:1.2,fontSize:"0.95rem",borderRadius:2},children:"Confirm Pickup"})]}):(0,Z.jsx)(ne.A,{severity:"info",sx:{mt:2},children:(0,Z.jsx)(m.A,{variant:"body2",children:"No pickup points available for this store."})})}),1===re&&(0,Z.jsxs)(ps.A,{spacing:2,children:[(0,Z.jsx)(Bt,{pincodes:L?.pincodes}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:-1},children:"Enter your delivery address to check availability"}),(0,Z.jsx)(qt,{value:N,onChange:e=>{M(e),se&&(W(null),O(""),te(""))},onValidAddress:ee}),(0,Z.jsx)(X.A,{variant:"contained",size:"small",onClick:ye,disabled:!N.trim()||!J||H,startIcon:H?(0,Z.jsx)(Ot,{size:18}):(0,Z.jsx)(It.A,{}),sx:{borderRadius:1.5},children:H?"Validating...":"Validate & Use This Address"}),T&&(0,Z.jsx)(ne.A,{severity:T,sx:{borderRadius:1.5},icon:"success"===T?(0,Z.jsx)(wt.A,{}):void 0,children:q}),g?(0,Z.jsx)(Z.Fragment,{children:me.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(As.A,{sx:{my:1},children:(0,Z.jsx)(Fe.A,{label:"Your Saved Addresses",size:"small",variant:"outlined"})}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"flex-end"},children:(0,Z.jsx)(Ie.A,{title:"Refresh addresses",children:(0,Z.jsx)(he.A,{size:"small",onClick:ge,disabled:B,sx:{border:"1px solid",borderColor:"divider",width:28,height:28},children:B?(0,Z.jsx)(Ot,{size:14}):(0,Z.jsx)(St.A,{sx:{fontSize:16}})})})}),k||B?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,Z.jsx)(Ot,{size:24})}):(0,Z.jsx)(ps.A,{spacing:1.5,children:me.map((e=>(0,Z.jsxs)(ae.A,{elevation:0,onClick:()=>(e=>{g?w(e.id):ce(e.id),te(e.address),M(""),ee(!1),fe(e.address),u("delivery"),R(null)})(e),sx:{p:1.5,cursor:"pointer",border:"1.5px solid",borderColor:pe===e.id?"secondary.main":"grey.200",borderRadius:2,bgcolor:pe===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,Z.jsx)(ks.A,{checked:pe===e.id,color:"secondary",size:"small",sx:{p:0}}),(0,Z.jsxs)(p.A,{sx:{flex:1,minWidth:0},children:[(0,Z.jsx)(m.A,{variant:"body2",noWrap:!0,children:e.address}),e.isPrimary&&(0,Z.jsx)(Fe.A,{label:"Primary",size:"small",color:"secondary",variant:"outlined",sx:{mt:.5,height:20,fontSize:"0.7rem"}})]})]},e.id)))})]})}):(0,Z.jsxs)(ae.A,{elevation:0,sx:{p:2.5,border:"1.5px dashed",borderColor:"grey.300",borderRadius:2,textAlign:"center",bgcolor:"grey.50"},children:[(0,Z.jsx)(Ct.A,{sx:{fontSize:32,color:"text.disabled",mb:1}}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:"Sign in to use your saved addresses"}),(0,Z.jsx)(X.A,{variant:"outlined",size:"small",startIcon:(0,Z.jsx)(Ct.A,{}),onClick:je,sx:{borderRadius:1.5},children:"Login"})]}),(0,Z.jsx)(X.A,{onClick:Se,variant:"contained",color:"secondary",fullWidth:!0,startIcon:(0,Z.jsx)(ft.A,{}),disabled:"success"!==T||!se,sx:{fontWeight:600,py:1.2,fontSize:"0.95rem",borderRadius:2},children:"Confirm Delivery"})]})]})}return null};var Nt=t(62274);const Mt=e=>{let{navigate:s,userRole:t,storeName:r}=e;const{setUser:n}=K();return r?(0,Z.jsx)(re,{onClick:async()=>{let e=t;if(!e)try{const s=await(0,y.$)();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.2rem",sm:"1.5rem",md:"1.75rem"},background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",letterSpacing:"0.5px",maxWidth:{xs:180,sm:280,md:"none"},overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}):null},_t=()=>{const e=(0,d.Zp)(),[s,t]=(0,x.useState)(null),r=(0,qe.A)("(max-width: 600px)"),n=Q((e=>e.cartCount())),i=Q((e=>e.selectedStore)),{user:a,ability:o,logout:l}=K(),[c,u]=x.useState(null),{modalOpen:m,setModalOpen:h,currentForm:p,setCurrentForm:A}=K(),[g,j]=(0,x.useState)(null),[f,b]=(0,x.useState)(!1),[v,I]=(0,x.useState)(!1);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,y.$)(),s=await(0,rt.T)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;j(s)}const r=s["custom:role"]?.toLowerCase();t(r)}catch(e){j(null),t(null)}})()}),[a]);const S=()=>{h(!0),A("login")},C=async()=>{try{await(0,Ns.C)(),l(),j(null),t(null),e("/")}catch(e){}},w=()=>u(null),P=H(a?.role||"user");(0,x.useEffect)((()=>{!r&&v&&I(!1)}),[r,v]);const k=(0,Z.jsxs)(J,{sx:{width:270,height:"100%",bgcolor:"background.paper",boxShadow:3,display:"flex",flexDirection:"column"},role:"presentation",onClick:()=>I(!1),children:[(0,Z.jsx)(J,{sx:{display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"#fff",px:2,py:2.5,minHeight:64,boxShadow:1},children:(0,Z.jsx)(re,{variant:"h6",sx:{fontWeight:800,letterSpacing:1,fontSize:"1.35rem",color:"#fff",textAlign:"center"},children:"Menu"})}),(0,Z.jsx)(As.A,{}),(0,Z.jsxs)(zs.A,{sx:{flex:1,py:1},children:[!g&&(0,Z.jsxs)(Rs.Ay,{button:!0,onClick:S,sx:{py:2},children:[(0,Z.jsx)(Ts.A,{sx:{color:"primary.main",minWidth:40},children:(0,Z.jsx)(Os.A,{})}),(0,Z.jsx)(Ws.A,{primary:(0,Z.jsx)(re,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Sign In"})})]}),s!==B&&s!==M&&s!==N&&(0,Z.jsxs)(Rs.Ay,{button:!0,onClick:()=>b(!0),sx:{py:2},children:[(0,Z.jsx)(Ts.A,{sx:{color:"primary.main",minWidth:40},children:(0,Z.jsx)(Bs.A,{})}),(0,Z.jsx)(Ws.A,{primary:(0,Z.jsx)(re,{sx:{fontWeight:600,fontSize:"1.1rem"},children:i?"Change Store":"Select Store"})})]}),(0,Z.jsxs)(Rs.Ay,{button:!0,onClick:()=>e(Xs),sx:{py:2},children:[(0,Z.jsx)(Ts.A,{sx:{color:"primary.main",minWidth:40},children:(0,Z.jsx)(we.A,{})}),(0,Z.jsx)(Ws.A,{primary:(0,Z.jsx)(re,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Cart"})})]}),g&&P?.can("view","orders")&&(0,Z.jsxs)(Rs.Ay,{button:!0,onClick:()=>e(Qs),sx:{py:2},children:[(0,Z.jsx)(Ts.A,{sx:{color:"primary.main",minWidth:40},children:(0,Z.jsx)(Us.A,{})}),(0,Z.jsx)(Ws.A,{primary:(0,Z.jsx)(re,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Orders"})})]}),g&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(As.A,{sx:{my:1.5}}),(0,Z.jsxs)(Rs.Ay,{button:!0,onClick:()=>{e(Zs)},sx:{py:2},children:[(0,Z.jsx)(Ts.A,{sx:{color:"primary.main",minWidth:40},children:(0,Z.jsx)(Os.A,{})}),(0,Z.jsx)(Ws.A,{primary:(0,Z.jsx)(re,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Profile"})})]}),(0,Z.jsxs)(Rs.Ay,{button:!0,onClick:C,sx:{py:2},children:[(0,Z.jsx)(Ts.A,{sx:{color:"error.main",minWidth:40},children:(0,Z.jsx)(Os.A,{})}),(0,Z.jsx)(Ws.A,{primary:(0,Z.jsx)(re,{sx:{fontWeight:600,fontSize:"1.1rem",color:"error.main"},children:"Logout"})})]})]})]}),(0,Z.jsx)(As.A,{}),(0,Z.jsxs)(J,{sx:{p:2,textAlign:"center",color:"text.secondary",fontSize:"0.95rem"},children:["© ",(new Date).getFullYear()," Indimitra"]})]});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(J,{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,Z.jsxs)(ts,{sx:{minHeight:{xs:"56px",sm:"64px",md:"70px"},px:{xs:1,sm:2,md:4}},children:[(0,Z.jsx)(Mt,{navigate:e,userRole:a?.role,storeName:i?.name}),(0,Z.jsx)(J,{sx:{flexGrow:1}}),r?(0,Z.jsx)(pe,{edge:"end",color:"inherit","aria-label":"menu",onClick:()=>I(!0),sx:{ml:1},children:(0,Z.jsx)(Nt.A,{})}):(0,Z.jsxs)(J,{sx:{display:"flex",alignItems:"center",gap:{xs:.5,sm:1,md:2},flexDirection:{xs:"row",sm:"row"},position:"relative"},children:[!g&&(0,Z.jsx)(ee,{onClick:S,sx:{color:"#2A2F4F",textTransform:"none",fontSize:{xs:"0.95rem",sm:"1rem"},fontWeight:500,px:{xs:1,sm:2},py:{xs:.5,sm:1},minWidth:{xs:0,sm:64},"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:"Sign In"}),!r&&g&&P&&P.can("view","orders")&&(0,Z.jsx)(ee,{onClick:()=>e(Qs),sx:{color:"#2A2F4F",textTransform:"none",fontSize:{xs:"0.95rem",sm:"1rem"},fontWeight:500,px:{xs:1,sm:2},py:{xs:.5,sm:1},minWidth:{xs:0,sm:64},"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:"Orders"}),s!==B&&s!==M&&s!==N&&(0,Z.jsx)(ee,{variant:"outlined",startIcon:(0,Z.jsx)(Bs.A,{sx:{fontSize:{xs:18,sm:22}}}),onClick:()=>b(!0),sx:{color:"#2A2F4F",borderColor:"#2A2F4F",textTransform:"none",fontSize:{xs:"0.95rem",sm:"1rem"},fontWeight:500,px:{xs:1,sm:2},py:{xs:.5,sm:1},minWidth:{xs:0,sm:64},mr:{xs:.5,sm:1},"&:hover":{backgroundColor:"rgba(42, 47, 79, 0.08)"}},children:i?"Change Store":"Select Store"}),a?P?.can("view","cart")&&(0,Z.jsx)(rs,{title:"Cart",children:(0,Z.jsx)(pe,{onClick:()=>e(Xs),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,Z.jsx)(is,{badgeContent:n,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,Z.jsx)(we.A,{sx:{fontSize:{xs:20,sm:24}}})})})}):(0,Z.jsx)(rs,{title:"Cart",children:(0,Z.jsx)(pe,{onClick:()=>e(Xs),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,Z.jsx)(is,{badgeContent:n,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,Z.jsx)(we.A,{sx:{fontSize:{xs:20,sm:24}}})})})}),g&&(0,Z.jsx)(rs,{title:"Profile",children:(0,Z.jsx)(pe,{onClick:e=>u(e.currentTarget),sx:{background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"white",p:{xs:.75,sm:1},ml:{xs:.5,sm:1},"&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)"}},children:(0,Z.jsx)(Os.A,{sx:{fontSize:{xs:20,sm:24}}})})})]})]})}),(0,Z.jsx)(qs.Ay,{anchor:"right",open:v,onClose:()=>I(!1),children:k}),(0,Z.jsxs)(os,{anchorEl:c,open:Boolean(c),onClose:w,PaperProps:{elevation:3,sx:{mt:2,minWidth:"200px",borderRadius:"12px",overflow:"hidden"}},children:[r&&P?.can("view","orders")&&(0,Z.jsx)(ge,{onClick:()=>{e(Qs),w()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,Z.jsx)(re,{variant:"body1",children:"Orders"})}),(0,Z.jsx)(ge,{onClick:()=>{e(Zs),w()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:"rgba(145, 127, 179, 0.1)"}},children:(0,Z.jsx)(re,{variant:"body1",children:"Profile"})}),(0,Z.jsx)(ge,{onClick:()=>{C(),w()},sx:{py:1.5,px:3,color:"#FF5757","&:hover":{backgroundColor:"rgba(255, 87, 87, 0.1)"}},children:(0,Z.jsx)(re,{variant:"body1",children:"Logout"})})]}),(0,Z.jsx)(Ut,{open:f,onClose:()=>b(!1)}),(0,Z.jsx)(J,{sx:{height:{xs:"56px",sm:"64px",md:"70px"}}}),(0,Z.jsx)(At,{open:m,onClose:()=>h(!1),currentForm:p,setCurrentForm:A})]})};var Vt=t(87992),Ht=t(61451);const Gt=()=>{const e=Q((e=>e.selectedStore));return(0,Z.jsx)(Vt.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,Z.jsx)(Ht.A,{sx:{fontSize:32}})})},Kt=()=>{const e=(0,d.Zp)(),s=(0,qe.A)("(max-width: 600px)"),t=Q((e=>e.cartCount()));return s?(0,Z.jsx)(Vt.A,{"aria-label":"Cart",onClick:()=>e(Xs),sx:{position:"fixed",bottom:84,right:20,zIndex:1e3,width:52,height:52,background:"linear-gradient(45deg, #FF6B6B 30%, #FF8E53 90%)",color:"#fff",boxShadow:"0 4px 14px rgba(255,107,107,0.4)","&:hover":{background:"linear-gradient(45deg, #FF8E53 30%, #FF6B6B 90%)",boxShadow:"0 6px 20px rgba(255,107,107,0.5)"}},children:(0,Z.jsx)(ns.A,{badgeContent:t,sx:{"& .MuiBadge-badge":{backgroundColor:"#fff",color:"#FF6B6B",fontWeight:700,fontSize:"0.7rem",minWidth:18,height:18,top:-4,right:-4}},children:(0,Z.jsx)(we.A,{sx:{fontSize:26}})})}):null},Yt=e=>{let{children:s}=e;return(0,Z.jsxs)(J,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[(0,Z.jsx)(_t,{}),s,(0,Z.jsx)(Kt,{}),(0,Z.jsx)(Gt,{})]})},Qt=e=>{let{children:s,role:t}=e;const{user:r,setUser:n,ability:i,setAbility:a}=K(),[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,y.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload["custom:role"]?.toLowerCase();r||n({role:s});const t=H(s);a(t),h(t),u(!0)}else u(!1)}catch(e){u(!1)}finally{l(!1)}})()}),[r,n,a]),o)return(0,Z.jsx)(le,{});if(!c)return(0,Z.jsx)(d.C5,{to:"/",replace:!0});if(p.pathname===Zs)return(0,Z.jsx)(Yt,{children:s});const A=(Array.isArray(t)?t:[t]).map((e=>e.toLowerCase()));return m&&A.some((e=>m.can("view",e)))?(0,Z.jsx)(Yt,{children:s}):(0,Z.jsx)(d.C5,{to:"/not-authorized",replace:!0})},Zt=()=>{const[e,s]=(0,x.useState)(!1),[t,r]=(0,x.useState)(""),[i]=(0,n.ok)(),a=i.get("referredby")||"";return(0,Z.jsx)(p.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,Z.jsxs)(ae.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,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,Z.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,Z.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,Z.jsx)(p.A,{sx:{minHeight:300},children:e?(0,Z.jsx)(it,{email:t,onComplete:()=>s(!1)}):(0,Z.jsx)(ut,{referredBy:a,onOtpStep:e=>{r(e),s(!0)}})})]})})};var Jt=t(31117),Xt=t(69377),er=t(85685),sr=t(69634),tr=t(94654),rr=t(17451);const nr=e=>{let{title:s,value:t,icon:r,color:n}=e;const i=(0,ke.A)(),a=(0,qe.A)(i.breakpoints.down("sm"));return(0,Z.jsx)(ye.A,{sx:{height:"100%"},children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Z.jsx)(p.A,{sx:{backgroundColor:`${n}15`,borderRadius:"50%",p:1,mr:2,display:"flex",alignItems:"center",justifyContent:"center"},children:x.cloneElement(r,{sx:{color:n}})}),(0,Z.jsx)(m.A,{variant:"h6",color:"text.secondary",children:s})]}),(0,Z.jsx)(m.A,{variant:a?"h5":"h4",component:"div",sx:{fontWeight:"bold"},children:t})]})})},ir=()=>{const e=(0,ke.A)(),s=(0,qe.A)(e.breakpoints.down("sm")),{data:t,isLoading:r,error:n}=(0,u.I)({queryKey:["dashboardStats"],queryFn:async()=>await C("\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 C("\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 C(L)}),{data:x,isLoading:h,error:g}=(0,u.I)({queryKey:["allStoresSquareStatus"],queryFn:async()=>await C("\n query AllStoresSquareStatus {\n allStoresSquareStatus {\n storeId\n storeName\n isConnected\n }\n }\n")}),j=t?.getDashboardStats||{},y=i?.getOrderStats||{},f=l?.stores||[],b=x?.allStoresSquareStatus||[],v=j.totalUsers||0,I=f.length||0,S=j.deliveryAgents||0,w=y.totalOrders||0,P=b.filter((e=>e.isConnected)).length,k=b.length||I,F=f.filter((e=>e.codEnabled)).length;if(r||a||d||h)return(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:(0,Z.jsx)(A.A,{})});if(n||o||c||g){const e=n?.message||o?.message||c?.message||g?.message||"Error loading dashboard data. Please try again later.";return(0,Z.jsx)(p.A,{sx:{p:s?2:3},children:(0,Z.jsx)(ds,{error:e,title:"Dashboard Error",severity:"error"})})}return(0,Z.jsxs)(p.A,{sx:{p:s?2:3},children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,sx:{mb:4},children:"Dashboard Overview"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Total Users",value:v.toLocaleString(),icon:(0,Z.jsx)(sr.A,{}),color:e.palette.primary.main})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Total Stores",value:I.toLocaleString(),icon:(0,Z.jsx)(Rt.A,{}),color:e.palette.success.main})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Square Connected",value:`${P} / ${k}`,icon:(0,Z.jsx)(gs.A,{}),color:e.palette.success.main})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Cash on Delivery",value:`${F} / ${I}`,icon:(0,Z.jsx)(gs.A,{}),color:e.palette.info.main})})]}),(0,Z.jsx)(p.A,{sx:{mt:4},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Active Drivers",value:S.toLocaleString(),icon:(0,Z.jsx)(Es.A,{}),color:e.palette.info.main})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Total Orders",value:w.toLocaleString(),icon:(0,Z.jsx)(we.A,{}),color:e.palette.warning.main})})]})}),(0,Z.jsxs)(p.A,{sx:{mt:4},children:[(0,Z.jsx)(m.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"Detailed Statistics"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Active Users",value:(j.activeUsers||0).toLocaleString(),icon:(0,Z.jsx)(sr.A,{}),color:e.palette.success.main})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Recent Orders (30 days)",value:(y.recentOrders||0).toLocaleString(),icon:(0,Z.jsx)(we.A,{}),color:e.palette.info.main})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Delivery Orders",value:(y.ordersByType?.DELIVERY||0).toLocaleString(),icon:(0,Z.jsx)(Es.A,{}),color:e.palette.secondary.main})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(nr,{title:"Pickup Orders",value:(y.ordersByType?.PICKUP||0).toLocaleString(),icon:(0,Z.jsx)(Rt.A,{}),color:e.palette.warning.main})})]})]}),j.usersByType&&Object.keys(j.usersByType).length>0&&(0,Z.jsxs)(p.A,{sx:{mt:4},children:[(0,Z.jsx)(m.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"User Type Breakdown"}),(0,Z.jsx)(je.Ay,{container:!0,spacing:2,children:Object.entries(j.usersByType).map((e=>{let[s,t]=e;return(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,Z.jsx)(ye.A,{sx:{height:"100%"},children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:s.charAt(0).toUpperCase()+s.slice(1).toLowerCase()}),(0,Z.jsx)(m.A,{variant:"h4",component:"div",sx:{fontWeight:"bold"},children:t.toLocaleString()})]})})},s)}))})]})]})};var ar=t(33198),or=t(64137),lr=t(96627),dr=t(86798),cr=t(14774),xr=t(43884),ur=t(29571),mr=t(95557),hr=t(72297),pr=t(68125);const Ar=()=>{const e=(0,ke.A)(),s=(0,qe.A)(e.breakpoints.down("sm")),[t,r]=(0,x.useState)(0),[n,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(0),[l,d]=(0,x.useState)(10),[c,h]=(0,x.useState)(!1),[j,y]=(0,x.useState)(""),[f,b]=(0,x.useState)(null),[v,I]=(0,x.useState)(!1),[S,P]=(0,x.useState)(""),[k,F]=(0,x.useState)({open:!1,message:"",severity:"success"}),[E,D]=(0,x.useState)(null),[L,z]=(0,x.useState)(!1),[R,T]=(0,x.useState)(""),[W,q]=(0,x.useState)([]),{data:O,isLoading:B,error:U,refetch:N}=(0,u.I)({queryKey:["users"],queryFn:async()=>{const e=await C(w);return e?.getAllUsers||[]},enabled:!0}),{data:M,isLoading:_,error:V,refetch:H}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{try{const e=await C($);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}),G=(0,Is.n)({mutationFn:e=>C("\n mutation UpdateUserType($targetUserId: String!, $newType: String!) {\n updateUserType(targetUserId: $targetUserId, newType: $newType) {\n user {\n id\n email\n type\n }\n error {\n message\n }\n }\n }\n",e),onSuccess:(e,s)=>{const t=e?.updateUserType;t?.user&&(O&&O.forEach((e=>{e.cognitoId===s.targetUserId&&(e.type=s.newType)})),F({open:!0,message:`Successfully updated user role to ${t.user.type}`,severity:"success"})),I(!1)},onError:e=>{F({open:!0,message:"Error updating user role: "+e.message,severity:"error"})}}),K=(0,Is.n)({mutationFn:e=>C("\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&&(F({open:!0,message:`Successfully assigned driver to ${s.store.name}`,severity:"success"}),H()),z(!1)},onError:e=>{F({open:!0,message:"Error assigning driver to store: "+e.message,severity:"error"})}});(0,x.useEffect)((()=>{O&&(async()=>{try{if(O&&Array.isArray(O)){const e=O.find((e=>"ADMIN"===e.type));e&&D(e.cognitoId)}}catch(e){}})()}),[O]),(0,x.useEffect)((()=>{M&&Array.isArray(M)?q(M):q([])}),[M]);const Y=e=>{b(e),P(e.type),I(!0)},Q=e=>{b(e),T(""),z(!0)},J=()=>{F({...k,open:!1})},ee=()=>{if(!O||!Array.isArray(O))return[];let e=O;return 1===t?e=O.filter((e=>"USER"===e.type)):2===t?e=O.filter((e=>"DELIVERY"===e.type)):3===t&&(e=O.filter((e=>"STORE_MANAGER"===e.type))),n&&(e=e.filter((e=>e.email?.toLowerCase().includes(n.toLowerCase())||e.mobile&&e.mobile.includes(n)||e.referralId&&e.referralId.toLowerCase().includes(n.toLowerCase())))),e},te=()=>R&&Array.isArray(W)?W.find((e=>e.id===parseInt(R))):null;return(0,Z.jsxs)(p.A,{sx:{p:s?2:3},children:[(0,Z.jsxs)(ae.A,{sx:{p:3,mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",gutterBottom:!0,children:"User Management"}),(0,Z.jsxs)(gt.A,{value:t,onChange:(e,s)=>{r(s),o(0)},sx:{mb:3},variant:s?"fullWidth":"standard",children:[(0,Z.jsx)(jt.A,{label:"All"}),(0,Z.jsx)(jt.A,{label:"Users"}),(0,Z.jsx)(jt.A,{label:"Delivery Partners"}),(0,Z.jsx)(jt.A,{label:"Store Managers"})]}),(0,Z.jsx)(p.A,{sx:{mb:3,display:"flex",gap:2,flexWrap:"wrap"},children:(0,Z.jsx)(se.A,{size:"small",placeholder:"Search...",value:n,onChange:e=>{i(e.target.value),o(0)},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(pr.A,{})})},sx:{flexGrow:1,minWidth:200}})}),U&&(0,Z.jsxs)(ne.A,{severity:"error",sx:{mb:3},children:["Error loading users: ",U.message]}),B?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Z.jsx)(A.A,{})}):(0,Z.jsxs)(Z.Fragment,{children:[0===t&&(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"ID"}),(0,Z.jsx)(cr.A,{children:"Email"}),(0,Z.jsx)(cr.A,{children:"Mobile"}),(0,Z.jsx)(cr.A,{children:"Type"}),(0,Z.jsx)(cr.A,{children:"Status"}),(0,Z.jsx)(cr.A,{children:"Referral ID"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:ee().slice(a*l,a*l+l).map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.id}),(0,Z.jsx)(cr.A,{children:e.email}),(0,Z.jsx)(cr.A,{children:e.mobile||"N/A"}),(0,Z.jsx)(cr.A,{children:e.type}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,Z.jsx)(cr.A,{children:e.referralId||"N/A"}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{size:"small",color:"primary",onClick:()=>Y(e),children:(0,Z.jsx)(hr.A,{})}),"DELIVERY"===e.type&&(0,Z.jsx)(he.A,{size:"small",color:"secondary",onClick:()=>Q(e),title:"Assign to Store",children:(0,Z.jsx)(Es.A,{})})]})]},e.id)))})]})}),1===t&&(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"ID"}),(0,Z.jsx)(cr.A,{children:"Email"}),(0,Z.jsx)(cr.A,{children:"Mobile"}),(0,Z.jsx)(cr.A,{children:"Status"}),(0,Z.jsx)(cr.A,{children:"Referral ID"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:ee().slice(a*l,a*l+l).map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.id}),(0,Z.jsx)(cr.A,{children:e.email}),(0,Z.jsx)(cr.A,{children:e.mobile||"N/A"}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,Z.jsx)(cr.A,{children:e.referralId||"N/A"}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(he.A,{size:"small",color:"primary",onClick:()=>Y(e),children:(0,Z.jsx)(hr.A,{})})})]},e.id)))})]})}),2===t&&(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"ID"}),(0,Z.jsx)(cr.A,{children:"Email"}),(0,Z.jsx)(cr.A,{children:"Mobile"}),(0,Z.jsx)(cr.A,{children:"Status"}),(0,Z.jsx)(cr.A,{children:"Referral ID"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:ee().slice(a*l,a*l+l).map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.id}),(0,Z.jsx)(cr.A,{children:e.email}),(0,Z.jsx)(cr.A,{children:e.mobile||"N/A"}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,Z.jsx)(cr.A,{children:e.referralId||"N/A"}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{size:"small",color:"primary",onClick:()=>Y(e),children:(0,Z.jsx)(hr.A,{})}),(0,Z.jsx)(he.A,{size:"small",color:"secondary",onClick:()=>Q(e),title:"Assign to Store",children:(0,Z.jsx)(Es.A,{})})]})]},e.id)))})]})}),3===t&&(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"ID"}),(0,Z.jsx)(cr.A,{children:"Email"}),(0,Z.jsx)(cr.A,{children:"Mobile"}),(0,Z.jsx)(cr.A,{children:"Status"}),(0,Z.jsx)(cr.A,{children:"Referral ID"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:ee().slice(a*l,a*l+l).map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.id}),(0,Z.jsx)(cr.A,{children:e.email}),(0,Z.jsx)(cr.A,{children:e.mobile||"N/A"}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,Z.jsx)(cr.A,{children:e.referralId||"N/A"}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(he.A,{size:"small",color:"primary",onClick:()=>Y(e),children:(0,Z.jsx)(hr.A,{})})})]},e.id)))})]})}),(0,Z.jsx)(g.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,Z.jsxs)(Qe.A,{open:v,onClose:()=>I(!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,Z.jsx)(Ze.A,{sx:{pb:1},children:"Update User Role"}),(0,Z.jsx)(Je.A,{children:f&&(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsxs)(m.A,{variant:"subtitle1",gutterBottom:!0,children:["User: ",f.email]}),(0,Z.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",f.id]}),(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mt:2},children:[(0,Z.jsx)(ur.A,{children:"Role"}),(0,Z.jsxs)(Oe.A,{value:S,onChange:e=>{P(e.target.value)},label:"Role",sx:{mb:2},children:[(0,Z.jsx)(Ae.A,{value:"USER",children:"User"}),(0,Z.jsx)(Ae.A,{value:"ADMIN",children:"Admin"}),(0,Z.jsx)(Ae.A,{value:"DELIVERY",children:"Delivery Partner"}),(0,Z.jsx)(Ae.A,{value:"STORE_MANAGER",children:"Store Manager"})]})]})]})}),(0,Z.jsxs)(Xe.A,{sx:{px:3,py:2},children:[(0,Z.jsx)(X.A,{onClick:()=>I(!1),children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{if(!E)return void F({open:!0,message:"Admin ID not available. Please try again.",severity:"error"});G.mutate({targetUserId:f.cognitoId,newType:{USER:"USER",ADMIN:"ADMIN",DELIVERY:"DELIVERY_AGENT",STORE_MANAGER:"STORE_MANAGER"}[S]||S})},variant:"contained",color:"primary",disabled:G.isPending,children:G.isPending?"Updating...":"Update Role"})]})]}),(0,Z.jsxs)(Qe.A,{open:L,onClose:()=>z(!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,Z.jsx)(Ze.A,{sx:{pb:1},children:"Assign Driver to Store"}),(0,Z.jsx)(Je.A,{children:f&&(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsxs)(m.A,{variant:"subtitle1",gutterBottom:!0,children:["Driver: ",f.email]}),(0,Z.jsxs)(m.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",f.id]}),(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,sx:{mt:2},children:"Select Store"}),_?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,Z.jsx)(A.A,{size:24})}):V?(0,Z.jsxs)(ne.A,{severity:"error",sx:{mb:2},children:["Error loading stores: ",V.message]}):Array.isArray(W)&&0!==W.length?(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mt:1},children:[(0,Z.jsx)(ur.A,{children:"Store"}),(0,Z.jsx)(Oe.A,{value:R,onChange:e=>{T(e.target.value)},label:"Store",sx:{mb:2},children:W.map((e=>(0,Z.jsxs)(Ae.A,{value:e.id,children:[e.name," - ",e.address]},e.id)))})]}):(0,Z.jsx)(ne.A,{severity:"info",sx:{mb:2},children:"No stores available"}),R&&te()&&(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,children:"Current Drivers"}),te()?.drivers?.edges?.length>0?(0,Z.jsx)(p.A,{sx:{mt:1},children:te().drivers.edges.map(((e,s)=>(0,Z.jsx)(Fe.A,{label:e.node.driver.email,size:"small",sx:{mr:1,mb:1}},s)))}):(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"No drivers assigned to this store yet"})]})]})}),(0,Z.jsxs)(Xe.A,{sx:{px:3,py:2},children:[(0,Z.jsx)(X.A,{onClick:()=>z(!1),children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{R&&f?K.mutate({storeId:parseInt(R),userId:parseInt(f.id)}):F({open:!0,message:"Please select a store",severity:"error"})},variant:"contained",color:"primary",disabled:!R||K.isPending,children:K.isPending?"Assigning...":"Assign to Store"})]})]}),(0,Z.jsx)(mr.A,{open:k.open,autoHideDuration:6e3,onClose:J,message:k.message,children:(0,Z.jsx)(ne.A,{onClose:J,severity:k.severity,children:k.message})})]})};var gr=t(39738),jr=t(82997),yr=t(47363),fr=t(67110),br=t(40250),vr=t(70765),Ir=t(34337),Sr=t(72306),Cr=t(79432),wr=t(35520);const Pr=["Store Information","Inventory","Drivers","Store Managers","Review"],kr=()=>{const[e,s]=(0,x.useState)(0),[t,r]=(0,x.useState)(""),[n,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(!1),[c,h]=(0,x.useState)({}),g=(0,ke.A)(),[j,f]=((0,qe.A)(g.breakpoints.down("sm")),(0,x.useState)(0)),[b,v]=(0,x.useState)({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",displayField:"",sectionHeaders:[],inventory:[],drivers:[],storeManagers:[],pincodes:"",images:[],codEnabled:!1,whatsappNumber:""}),[I,S]=(0,x.useState)(null),[P,k]=(0,x.useState)([]),[F,E]=(0,x.useState)(!1),[D,L]=(0,x.useState)({open:!1,message:"",severity:"success"}),{data:z,isLoading:R,refetch:T}=(0,u.I)({queryKey:["stores"],queryFn:()=>C($),enabled:n}),{data:W,isLoading:q}=(0,u.I)({queryKey:["users"],queryFn:async()=>{const e=await C(w);return e?.getAllUsers||[]},enabled:!0}),O=(0,x.useMemo)((()=>W&&Array.isArray(W)?W.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")})):[]),[W]),B=(0,x.useMemo)((()=>z?.stores&&Array.isArray(z.stores)?z.stores.map((e=>e.managerUserId)).filter((e=>null!=e)):[]),[z]),U=(0,x.useMemo)((()=>{if(!O.length)return[];return O.filter((e=>!B.includes(e.id)))}),[O,B]),N=(0,x.useMemo)((()=>{if(!O.length||!I)return U;const e=B.filter((e=>e!==I.managerUserId));return O.filter((s=>!e.includes(s.id)))}),[O,B,I,U]);(0,x.useEffect)((()=>{if(1===e&&!I){const e=U.find((e=>String(e.id)===String(b.managerUserId)));e?v((s=>({...s,email:e.email||"",mobile:e.mobile||""}))):b.managerUserId&&!e&&v((e=>({...e,managerUserId:"",email:"",mobile:""})))}}),[b.managerUserId,U,e,I]);const M=(0,Is.n)({mutationFn:e=>C("\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,images:e.images||[],codEnabled:e.codEnabled??!1,whatsappNumber:e.whatsappNumber||null}),onSuccess:()=>{d(!0),o(null),v({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",displayField:"",sectionHeaders:[],inventory:[],drivers:[],storeManagers:[],pincodes:"",images:[],codEnabled:!1,whatsappNumber:""}),f(0),T()},onError:e=>{o(e.message||"Failed to create store"),d(!1)}}),_=(0,Is.n)({mutationFn:e=>C("\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)=>{z&&z.stores&&z.stores.forEach((e=>{e.id===s.storeId&&Object.assign(e,s)})),L({open:!0,message:"Store updated successfully",severity:"success"}),S(null)},onError:e=>{L({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),V=()=>{i(!0),T()},H=e=>{const{name:s,value:t}=e.target;v((e=>({...e,[s]:t}))),c[s]&&h((e=>({...e,[s]:null}))),a&&o(null)},G=()=>{v((e=>({...e,sectionHeaders:[...e.sectionHeaders,""]})))},K=async function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return;const t=s?I?.id:null;if(!s||t){E(!0);try{const r=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",n=await(0,y.$)(),i=n.tokens?.accessToken?.toString(),a={"Content-Type":"application/json"};i&&(a.Authorization=`Bearer ${i}`);const o=t?t.toString():"new",l=await fetch(`${r}/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=d.split("?")[0];s?k((e=>[...e,u])):v((e=>({...e,images:[...e.images,u]}))),L({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){L({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{E(!1)}}else L({open:!0,message:"Store ID is required for image upload",severity:"error"})},Y=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?k((s=>s.filter(((s,t)=>t!==e)))):v((s=>({...s,images:s.images.filter(((s,t)=>t!==e))})))},Q=()=>{const e={};return b.name.trim()||(e.name="Store name is required"),b.address.trim()||(e.address="Address is required"),b.email.trim()||(e.email="Manager email is required"),b.mobile.trim()||(e.mobile="Manager mobile is required"),b.managerUserId||(e.managerUserId="Manager User ID is required"),b.radius&&!isNaN(parseFloat(b.radius))||(e.radius="Delivery radius is required"),b.displayField.trim()||(e.displayField="Display Field is required"),h(e),0===Object.keys(e).length},J=()=>{S(null),k([])},ee=z?.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,Z.jsxs)(p.A,{children:[(0,Z.jsxs)(ae.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,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Z.jsx)(Rt.A,{sx:{mr:1}}),(0,Z.jsx)(m.A,{variant:"h5",children:"Store Management"})]}),(0,Z.jsxs)(gt.A,{value:e,onChange:(e,t)=>{s(t)},sx:{mb:3},children:[(0,Z.jsx)(jt.A,{label:"Store List"}),(0,Z.jsx)(jt.A,{label:"Add New Store"})]}),a&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:3},children:a}),l&&(0,Z.jsx)(ne.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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(p.A,{sx:{mb:3},children:(0,Z.jsx)(se.A,{fullWidth:!0,variant:"outlined",placeholder:"Search stores...",value:t,onChange:e=>r(e.target.value),InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(pr.A,{})})}})}),n?R?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,Z.jsx)(A.A,{})}):0===ee.length?(0,Z.jsx)(ne.A,{severity:"info",sx:{mb:3},children:"No stores found matching your criteria"}):(0,Z.jsx)(je.Ay,{container:!0,spacing:3,children:ee.map((e=>(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(ae.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,Z.jsx)(p.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,Z.jsxs)(je.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Z.jsx)(Rt.A,{sx:{mr:2,color:"white",fontSize:"2rem"}}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{className:"store-name",variant:"h6",sx:{color:"white",fontWeight:600,transition:"color 0.3s ease-in-out"},children:e.name}),(0,Z.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,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",md:"flex-end"},gap:2},children:[(0,Z.jsx)(Fe.A,{label:e.isActive?"Active":"Inactive",color:e.isActive?"success":"error",sx:{fontWeight:600,boxShadow:2,"& .MuiChip-label":{px:1}}}),(0,Z.jsx)(p.A,{className:"action-buttons",sx:{display:"flex",gap:1,opacity:.9},children:(0,Z.jsx)(X.A,{size:"small",startIcon:(0,Z.jsx)(hr.A,{}),sx:{fontWeight:600,textTransform:"none",color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},onClick:()=>(e=>{S(e),k(e.images||[])})(e),children:"Edit"})})]})})]})}),(0,Z.jsx)(p.A,{sx:{p:3},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(p.A,{children:[(0,Z.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,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,Z.jsx)(cs.A,{sx:{mr:1.5,color:"primary.main",mt:.3,flexShrink:0,fontSize:"1.2rem"}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.address})]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Z.jsx)(vr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.mobile||"No contact info"})]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Z.jsx)(Ir.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.email||"No email info"})]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(p.A,{children:[(0,Z.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,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Z.jsx)(Es.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Z.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Radius: ",e.radius," mi"]})]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Z.jsx)(Sr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Z.jsxs)(m.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Delivery Fee: $",e.storeDeliveryFee?.toFixed(2)||"0.00"]})]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Z.jsx)(Cr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,Z.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,Z.jsx)(p.A,{sx:{display:"flex",flexWrap:"wrap",gap:.8},children:e.pincodes.map((e=>(0,Z.jsx)(Fe.A,{label:e,size:"small",sx:{backgroundColor:"primary.light",color:"primary.contrastText",fontWeight:600,transition:"all 0.2s ease-in-out","&:hover":{backgroundColor:"primary.main",transform:"scale(1.05)"}}},e)))})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(p.A,{children:[e.description&&(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.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,Z.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.description})]}),e.tnc&&(0,Z.jsxs)(p.A,{children:[(0,Z.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,Z.jsx)(m.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.tnc})]})]})}),e.images&&e.images.length>0&&(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(As.A,{sx:{mb:2}}),(0,Z.jsxs)(m.A,{variant:"subtitle2",sx:{mb:1.5,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:[(0,Z.jsx)(wr.A,{sx:{fontSize:"1rem",mr:.5}}),"Store Images (",e.images.length,")"]}),(0,Z.jsx)(p.A,{sx:{display:"flex",gap:1.5,overflowX:"auto",pb:1,scrollbarWidth:"thin"},children:e.images.map(((e,s)=>(0,Z.jsx)(p.A,{sx:{flex:"0 0 auto",width:120,height:80,borderRadius:2,overflow:"hidden",border:"1px solid",borderColor:"divider"},children:(0,Z.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},s)))})]})]})})]})},e.id)))}):(0,Z.jsxs)(ye.A,{sx:{mb:3},children:[(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Stores" to load store data'}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]}),(0,Z.jsx)(ve.A,{sx:{justifyContent:"center"},children:(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:(0,Z.jsx)(br.A,{}),onClick:V,children:"Fetch Stores"})})]})]}):1!==e||z?.stores||n?(0,Z.jsxs)(p.A,{sx:{maxWidth:{xs:"100%",sm:600,md:800},mx:"auto",p:{xs:1,sm:2}},children:[(0,Z.jsx)(p.A,{sx:{overflowX:{xs:"auto",sm:"visible"},mb:{xs:2,sm:4}},children:(0,Z.jsx)(gr.A,{activeStep:j,sx:{minWidth:500},children:Pr.map((e=>(0,Z.jsx)(jr.A,{children:(0,Z.jsx)(yr.A,{children:(0,Z.jsx)(m.A,{sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:e})})},e)))})}),(0,Z.jsx)(p.A,{sx:{px:{xs:.5,sm:0}},children:(e=>{switch(e){case 0:return(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Basic Store Information"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{required:!0,fullWidth:!0,label:"Store Name",name:"name",value:b.name,onChange:H,error:!!c.name,helperText:c.name})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{required:!0,fullWidth:!0,label:"Address",name:"address",value:b.address,onChange:H,error:!!c.address,helperText:c.address})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(Cs.A,{required:!0,fullWidth:!0,error:!!c.managerUserId,children:[(0,Z.jsx)(ur.A,{children:"Manager User ID"}),(0,Z.jsx)(Oe.A,{label:"Manager User ID",name:"managerUserId",value:b.managerUserId,onChange:H,children:q?(0,Z.jsx)(Ae.A,{value:"",disabled:!0,children:(0,Z.jsx)("em",{children:"Loading..."})}):0===U.length?(0,Z.jsx)(Ae.A,{value:"",disabled:!0,children:(0,Z.jsx)("em",{children:"No available managers (all managers are assigned)"})}):U.map((e=>(0,Z.jsxs)(Ae.A,{value:e.id,children:[e.id," - ",e.email," ",e.name?`(${e.name})`:""]},e.id)))}),(0,Z.jsx)(m.A,{variant:"caption",color:"error",children:c.managerUserId}),0===U.length&&!q&&(0,Z.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,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{required:!0,fullWidth:!0,label:"Manager Email",name:"email",type:"email",value:b.email,InputProps:{readOnly:!0},error:!!c.email,helperText:c.email})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{required:!0,fullWidth:!0,label:"Manager Mobile",name:"mobile",value:b.mobile,InputProps:{readOnly:!0},error:!!c.mobile,helperText:c.mobile})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{required:!0,fullWidth:!0,label:"Delivery Radius (mi)",name:"radius",type:"number",value:b.radius,onChange:H,inputProps:{step:"0.1"},error:!!c.radius,helperText:c.radius})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Delivery Fee ($)",name:"storeDeliveryFee",type:"number",value:b.storeDeliveryFee,onChange:H,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:"$"})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Tax Rate (%)",name:"taxPercentage",type:"number",value:b.taxPercentage,onChange:H,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,Z.jsx)(xe.A,{position:"end",children:"%"})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Description",name:"description",value:b.description,onChange:H,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Terms & Conditions",name:"tnc",value:b.tnc,onChange:H,multiline:!0,rows:3})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Delivery Pincodes",name:"pincodes",value:b.pincodes,onChange:H,helperText:"Enter pincodes separated by commas"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{required:!0,fullWidth:!0,label:"Display Field",name:"displayField",value:b.displayField,onChange:H,error:!!c.displayField,helperText:c.displayField||"Unique identifier for the store"})}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,Z.jsxs)(p.A,{sx:{mb:2},children:[b.sectionHeaders.map(((e,s)=>(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,Z.jsx)(se.A,{fullWidth:!0,label:`Question ${s+1}`,value:e,onChange:e=>((e,s)=>{const t=[...b.sectionHeaders];t[e]=s,v((e=>({...e,sectionHeaders:t})))})(s,e.target.value),placeholder:"Enter question text"}),(0,Z.jsx)(he.A,{color:"error",onClick:()=>(e=>{const s=b.sectionHeaders.filter(((s,t)=>t!==e));v((e=>({...e,sectionHeaders:s})))})(s),sx:{alignSelf:"center"},children:(0,Z.jsx)(fr.A,{})})]},s))),(0,Z.jsx)(X.A,{startIcon:(0,Z.jsx)(Ce.A,{}),onClick:G,variant:"outlined",sx:{mt:1},children:"Add Question"})]})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Images"}),(0,Z.jsxs)(p.A,{sx:{mb:2},children:[(0,Z.jsx)("input",{accept:"image/*",style:{display:"none"},id:"store-image-upload",type:"file",onChange:e=>{const s=e.target.files[0];s&&K(s,!1),e.target.value=""}}),(0,Z.jsx)("label",{htmlFor:"store-image-upload",children:(0,Z.jsx)(X.A,{variant:"outlined",component:"span",startIcon:(0,Z.jsx)(Ce.A,{}),disabled:F,sx:{mb:2},children:F?"Uploading...":"Upload Image"})}),b.images&&b.images.length>0&&(0,Z.jsx)(p.A,{sx:{display:"flex",flexWrap:"wrap",gap:2,mt:2},children:b.images.map(((e,s)=>(0,Z.jsxs)(p.A,{sx:{position:"relative",width:150,height:150},children:[(0,Z.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,Z.jsx)(he.A,{size:"small",color:"error",onClick:()=>Y(s,!1),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,Z.jsx)(fr.A,{fontSize:"small"})})]},s)))})]})]}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:2,border:"1px solid",borderColor:"divider",borderRadius:1,bgcolor:"background.paper"},children:[(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Cash on Delivery"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Accept cash payments when orders are delivered"})]}),(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(Ne.A,{checked:b.codEnabled,onChange:e=>v((s=>({...s,codEnabled:e.target.checked}))),color:"primary"}),label:b.codEnabled?"Enabled":"Disabled",labelPlacement:"start"})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{label:"WhatsApp Support Number",placeholder:"+1234567890",value:b.whatsappNumber,onChange:e=>v((s=>({...s,whatsappNumber:e.target.value}))),fullWidth:!0,helperText:"Include country code (e.g., +1 for US). Optional."})})]});case 1:return(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Inventory Management"}),(0,Z.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,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsxs)(ae.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Inventory Items"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Z.jsx)(ye.A,{variant:"outlined",children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",children:"Product 1"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Grocery"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $9.99"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 50"})]})})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Z.jsx)(ye.A,{variant:"outlined",children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",children:"Product 2"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Electronics"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $49.99"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 25"})]})})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Z.jsx)(ye.A,{variant:"outlined",children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",children:"Product 3"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Category: Clothing"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Price: $19.99"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Stock: 100"})]})})})]})]}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,Z.jsx)(X.A,{variant:"outlined",startIcon:(0,Z.jsx)(Ce.A,{}),children:"Add Inventory Item"})})]})]});case 2:return(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Driver Management"}),(0,Z.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,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsxs)(ae.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Drivers"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Z.jsx)(ye.A,{variant:"outlined",children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",children:"John Doe"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: john.doe@example.com"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 123-4567"}),(0,Z.jsx)(Fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Z.jsx)(ye.A,{variant:"outlined",children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",children:"Jane Smith"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: jane.smith@example.com"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 987-6543"}),(0,Z.jsx)(Fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Z.jsx)(ye.A,{variant:"outlined",children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",children:"Mike Johnson"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: mike.johnson@example.com"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 456-7890"}),(0,Z.jsx)(Fe.A,{label:"Inactive",color:"error",size:"small",sx:{mt:1}})]})})})]})]}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,Z.jsx)(X.A,{variant:"outlined",startIcon:(0,Z.jsx)(Ce.A,{}),children:"Add Driver"})})]})]});case 3:return(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Store Manager Management"}),(0,Z.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,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsxs)(ae.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Store Managers"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,children:(0,Z.jsx)(ye.A,{variant:"outlined",children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",children:"Sarah Williams"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: sarah.williams@example.com"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 234-5678"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Role: Store Manager"}),(0,Z.jsx)(Fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,children:(0,Z.jsx)(ye.A,{variant:"outlined",children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",children:"Robert Brown"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Email: robert.brown@example.com"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 876-5432"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Role: Assistant Manager"}),(0,Z.jsx)(Fe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})})]})]}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,Z.jsx)(X.A,{variant:"outlined",startIcon:(0,Z.jsx)(Ce.A,{}),children:"Add Store Manager"})})]})]});case 4:return(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Review Store Information"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(ae.A,{variant:"outlined",sx:{p:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Details"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"Name:"})," ",b.name]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"Address:"})," ",b.address]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"Manager User ID:"})," ",b.managerUserId]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"Delivery Radius:"})," ",b.radius," km"]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"Cash on Delivery:"})," ",b.codEnabled?"Enabled":"Disabled"]})}),b.whatsappNumber&&(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"WhatsApp:"})," ",b.whatsappNumber]})})]}),(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Additional Information (Placeholder)"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"Inventory Items:"})," 3 sample items"]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"Drivers:"})," 3 sample drivers"]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"body2",children:[(0,Z.jsx)("strong",{children:"Store Managers:"})," 2 sample managers"]})})]})]})})]});default:return null}})(j)}),(0,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",mt:3,gap:2},children:[(0,Z.jsx)(X.A,{fullWidth:!0,disabled:0===j,onClick:()=>{f((e=>e-1))},sx:{py:1,fontSize:{xs:"1rem",sm:"1.05rem"}},children:"Back"}),(0,Z.jsx)(X.A,{fullWidth:!0,variant:"contained",color:"primary",onClick:j===Pr.length-1?()=>{if(!Q())return void o("Please fill in all required fields");const e=b.pincodes,s=e?e.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],t={name:b.name,address:b.address,managerUserId:parseInt(b.managerUserId,10),radius:parseFloat(b.radius),email:b.email,mobile:b.mobile,description:b.description||null,storeDeliveryFee:b.storeDeliveryFee?parseFloat(b.storeDeliveryFee):null,taxPercentage:b.taxPercentage?parseFloat(b.taxPercentage):null,tnc:b.tnc||null,displayField:b.displayField,sectionHeaders:b.sectionHeaders.filter((e=>e.trim().length>0)),pincodes:s,images:b.images||[],is_active:!0,disabled:!1,codEnabled:b.codEnabled,whatsappNumber:b.whatsappNumber||null};M.mutate(t)}:()=>{0!==j||Q()?f((e=>e+1)):o("Please fill in all required fields")},disabled:M.isLoading,sx:{py:1,fontSize:{xs:"1rem",sm:"1.05rem"}},children:M.isLoading?(0,Z.jsx)(A.A,{size:24}):j===Pr.length-1?"Submit":"Next"})]})]}):(0,Z.jsxs)(ye.A,{sx:{mb:3},children:[(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:"Loading store data for manager availability check..."}),(0,Z.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,Z.jsx)(ve.A,{sx:{justifyContent:"center"},children:(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:(0,Z.jsx)(br.A,{}),onClick:V,children:"Load Store Data"})})]})]}),(0,Z.jsxs)(Qe.A,{open:!!I,onClose:J,maxWidth:"md",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Rt.A,{}),(0,Z.jsx)(m.A,{variant:"h6",children:"Edit Store"})]})}),(0,Z.jsxs)("form",{onSubmit:e=>{e.preventDefault();const s=new FormData(e.target),t=s.get("pincodes"),r=t?t.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],n=s.get("sectionHeaders"),i=n?n.split("\n").map((e=>e.trim())).filter((e=>e.length>0)):[],a={storeId:I.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:r,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};_.mutate(a)},children:[(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"name",label:"Store Name",defaultValue:I?.name,required:!0,fullWidth:!0})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"email",label:"Email",type:"email",defaultValue:I?.email,required:!0,fullWidth:!0})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"mobile",label:"Mobile Number",defaultValue:I?.mobile,fullWidth:!0})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(Cs.A,{required:!0,fullWidth:!0,children:[(0,Z.jsx)(ur.A,{children:"Manager User ID"}),(0,Z.jsx)(Oe.A,{name:"managerUserId",label:"Manager User ID",defaultValue:I?.managerUserId,children:q?(0,Z.jsx)(Ae.A,{value:"",disabled:!0,children:(0,Z.jsx)("em",{children:"Loading..."})}):0===N.length?(0,Z.jsx)(Ae.A,{value:"",disabled:!0,children:(0,Z.jsx)("em",{children:"No available managers"})}):N.map((e=>(0,Z.jsxs)(Ae.A,{value:e.id,children:[e.id," - ",e.email," ",e.name?`(${e.name})`:""]},e.id)))})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"displayField",label:"Display Field",defaultValue:I?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"sectionHeaders",label:"Section Headers",defaultValue:I?.sectionHeaders?.join("\n"),fullWidth:!0,multiline:!0,rows:3,helperText:"Enter each section header on a new line"})}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Images"}),(0,Z.jsxs)(p.A,{sx:{mb:2},children:[(0,Z.jsx)("input",{accept:"image/*",style:{display:"none"},id:"edit-store-image-upload",type:"file",onChange:e=>{const s=e.target.files[0];s&&K(s,!0),e.target.value=""}}),(0,Z.jsx)("label",{htmlFor:"edit-store-image-upload",children:(0,Z.jsx)(X.A,{variant:"outlined",component:"span",startIcon:(0,Z.jsx)(Ce.A,{}),disabled:F,sx:{mb:2},children:F?"Uploading...":"Upload Image"})}),P&&P.length>0&&(0,Z.jsx)(p.A,{sx:{display:"flex",flexWrap:"wrap",gap:2,mt:2},children:P.map(((e,s)=>(0,Z.jsxs)(p.A,{sx:{position:"relative",width:150,height:150},children:[(0,Z.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,Z.jsx)(he.A,{size:"small",color:"error",onClick:()=>Y(s,!0),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,Z.jsx)(fr.A,{fontSize:"small"})})]},s)))})]})]}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"address",label:"Address",defaultValue:I?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:I?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:I?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:"$"})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:I?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,Z.jsx)(xe.A,{position:"end",children:"%"})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:I?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"description",label:"Description",defaultValue:I?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"tnc",label:"Terms & Conditions",defaultValue:I?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"whatsappNumber",label:"WhatsApp Support Number",placeholder:"+1234567890",defaultValue:I?.whatsappNumber,fullWidth:!0,helperText:"Include country code. Optional."})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,children:[(0,Z.jsx)(ur.A,{children:"Store Status"}),(0,Z.jsxs)(Oe.A,{name:"isActive",label:"Store Status",defaultValue:I?.isActive,children:[(0,Z.jsx)(Ae.A,{value:!0,children:"Active"}),(0,Z.jsx)(Ae.A,{value:!1,children:"Inactive"})]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,children:[(0,Z.jsx)(ur.A,{children:"Disabled Status"}),(0,Z.jsxs)(Oe.A,{name:"disabled",label:"Disabled Status",defaultValue:I?.disabled,children:[(0,Z.jsx)(Ae.A,{value:!0,children:"Disabled"}),(0,Z.jsx)(Ae.A,{value:!1,children:"Enabled"})]})]})})]})}),(0,Z.jsxs)(Xe.A,{sx:{p:3,pt:0},children:[(0,Z.jsx)(X.A,{onClick:J,children:"Cancel"}),(0,Z.jsx)(X.A,{type:"submit",variant:"contained",disabled:_.isPending,startIcon:_.isPending?(0,Z.jsx)(A.A,{size:20}):null,children:_.isPending?"Updating...":"Update Store"})]})]})]}),(0,Z.jsx)(mr.A,{open:D.open,autoHideDuration:6e3,onClose:()=>L({...D,open:!1}),children:(0,Z.jsx)(ne.A,{onClose:()=>L({...D,open:!1}),severity:D.severity,sx:{width:"100%"},children:D.message})})]})};var Fr=t(15068);const Er=()=>{const[e,s]=(0,x.useState)(""),[t,r]=(0,x.useState)(!1),[n,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),[j,f]=(0,x.useState)(null),[b,v]=(0,x.useState)(!1),[I,S]=(0,x.useState)(""),[w,P]=(0,x.useState)(""),[k,F]=(0,x.useState)(0),[E,D]=(0,x.useState)(10),[L,$]=(0,x.useState)([]),[R,T]=(0,x.useState)(""),[W,q]=(0,x.useState)(!1),[O,B]=(0,x.useState)({open:!1,message:"",severity:"info"}),[U,N]=(0,x.useState)(""),M=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":window.location.origin,{data:_,refetch:V}=(0,u.I)({queryKey:["products",e],queryFn:()=>C(z),enabled:!1}),{data:H,refetch:G}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await C("\n query GetCategories {\n categories {\n id\n name\n }\n }\n")).categories||[]}),K=(0,Is.n)({mutationFn:e=>C("\n mutation CreateProduct($name: String!, $description: String!, $categoryId: Int!, $image: String) {\n createProduct(name: $name, description: $description, categoryId: $categoryId, image: $image) {\n id\n name\n description\n categoryId\n image\n }\n }\n",{name:e.name,description:e.description,categoryId:e.categoryId,image:e.image}),onSuccess:()=>{ie(),te(),B({open:!0,message:"Product added successfully!",severity:"success"})}}),Y=(0,Is.n)({mutationFn:e=>{let{productId:s,name:t,description:r,categoryId:n,image:i}=e;return C("\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:r,categoryId:parseInt(n,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)))),te(),B({open:!0,message:"Product updated successfully!",severity:"success"})},onError:e=>{B({open:!0,message:`Failed to update product: ${e.message}`,severity:"error"})}}),Q=((0,Is.n)({mutationFn:e=>C("\n mutation DeleteProduct($productId: Int!) {\n deleteProduct(productId: $productId)\n }\n",{productId:e}),onSuccess:()=>{V()}}),(0,Is.n)({mutationFn:e=>C("\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(""),P(""),G()},onError:e=>{P(e.message||"Failed to create category")}})),J=(0,x.useMemo)((()=>H?H.reduce(((e,s)=>(e[s.id]=s.name,e)),{}):{}),[H]),ee=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(i(e),o({name:e.name,description:e.description,categoryId:e.categoryId,image:e.image})):(i(null),o({name:"",description:"",categoryId:"",image:""})),r(!0)},te=()=>{r(!1),i(null),o({name:"",description:"",categoryId:"",image:""})},re=e=>{const{name:s,value:t}=e.target;"categoryId"!==s||"new"!==t?(o((e=>({...e,[s]:t}))),N("")):v(!0)},ie=()=>{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)}))},oe=()=>{I.trim()?Q.mutate(I.trim()):P("Category name is required")},le=(0,x.useMemo)((()=>e?L.filter((s=>s.categoryId===parseInt(e))):L),[L,e]),de=(0,x.useMemo)((()=>{const e=k*E;return le.slice(e,e+E)}),[le,k,E]),ce=()=>{B((e=>({...e,open:!1})))};return(0,Z.jsxs)(p.A,{children:[(0,Z.jsxs)(ae.A,{sx:{p:3,mb:3},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Z.jsx)(Ce.A,{sx:{mr:1}}),(0,Z.jsx)(m.A,{variant:"h5",children:"Product Management"})]}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,children:[(0,Z.jsx)(ur.A,{children:"Category"}),(0,Z.jsxs)(Oe.A,{value:e,onChange:e=>s(e.target.value),label:"Category",children:[(0,Z.jsx)(Ae.A,{value:"",children:"All Categories"}),Object.entries(J).map((e=>{let[s,t]=e;return(0,Z.jsx)(Ae.A,{value:s,children:t},s)}))]})]})}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,md:8,sx:{display:"flex",alignItems:"center",gap:2},children:[(0,Z.jsx)(X.A,{variant:"contained",startIcon:(0,Z.jsx)(br.A,{}),onClick:ie,disabled:c,sx:{minWidth:150},children:c?(0,Z.jsx)(A.A,{size:24}):"Fetch Products"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:(0,Z.jsx)(Ce.A,{}),onClick:()=>ee(),children:"Add Product"})]})]}),j&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:3},children:j}),l?c?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Z.jsx)(A.A,{})}):(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)(ar.A,{component:ae.A,children:[(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Image"}),(0,Z.jsx)(cr.A,{children:"Name"}),(0,Z.jsx)(cr.A,{children:"Category"}),(0,Z.jsx)(cr.A,{children:"Description"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:de.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:(0,Z.jsx)("img",{src:e.image,alt:e.name,style:{width:"50px",height:"50px",objectFit:"cover"}})}),(0,Z.jsx)(cr.A,{children:e.name}),(0,Z.jsx)(cr.A,{children:J[e.categoryId]||"Unknown"}),(0,Z.jsx)(cr.A,{children:e.description}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(he.A,{size:"small",onClick:()=>ee(e),children:(0,Z.jsx)(hr.A,{})})})]},e.id)))})]}),(0,Z.jsx)(g.A,{component:"div",count:le.length,page:k,onPageChange:(e,s)=>{F(s)},rowsPerPage:E,onRowsPerPageChange:e=>{D(parseInt(e.target.value,10)),F(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,Z.jsxs)(p.A,{sx:{textAlign:"center",py:4},children:[(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Products" to load product information'}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,Z.jsxs)(Qe.A,{open:t,onClose:te,maxWidth:"md",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:n?"Edit Product":"Add New Product"}),(0,Z.jsxs)(Je.A,{children:[U&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:U}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{required:!0,fullWidth:!0,label:"Product Name",name:"name",value:a.name,onChange:re})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,required:!0,children:[(0,Z.jsx)(ur.A,{children:"Category"}),(0,Z.jsxs)(Oe.A,{name:"categoryId",value:a.categoryId,onChange:re,label:"Category",children:[(0,Z.jsx)(Ae.A,{value:"",children:(0,Z.jsx)("em",{children:"Select a category"})}),Object.entries(J).map((e=>{let[s,t]=e;return(0,Z.jsx)(Ae.A,{value:s,children:t},s)})),(0,Z.jsx)(Ae.A,{value:"new",sx:{borderTop:"1px solid #e0e0e0",mt:1},children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",color:"primary.main"},children:[(0,Z.jsx)(Ce.A,{sx:{mr:1}}),"Add New Category"]})})]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{required:!0,fullWidth:!0,multiline:!0,rows:3,label:"Description",name:"description",value:a.description,onChange:re})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:"column",gap:1},children:[(0,Z.jsx)(se.A,{fullWidth:!0,label:"Image URL",name:"image",value:a.image,onChange:re,placeholder:"https://example.com/image.jpg",disabled:W,error:!!R,helperText:R}),(0,Z.jsxs)(X.A,{variant:"outlined",component:"label",startIcon:(0,Z.jsx)(Fr.A,{}),disabled:W||!a.name||!a.categoryId,children:[W?"Uploading...":"Upload Image",(0,Z.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)T("Image size should be less than 5MB");else try{q(!0),T("");const e=J[a.categoryId]||"uncategorized",t=await(0,y.$)(),r=t?.tokens?.idToken?.toString?.()||t?.tokens?.accessToken?.toString?.();if(!r)throw new Error("Not authenticated");const n=await fetch(`${M}/s3/generate-product-upload-url?product_name=${encodeURIComponent(a.name)}&category_name=${encodeURIComponent(e)}&file_name=${encodeURIComponent(s.name)}`,{headers:{Authorization:`Bearer ${r}`}});if(!n.ok)throw new Error("Failed to get upload URL");const{upload_url:i,content_type:l,key:d}=await n.json();if(!(await fetch(i,{method:"PUT",headers:{"Content-Type":l},body:s})).ok)throw new Error("Failed to upload image");const c=i.split("?")[0]+`?t=${Date.now()}`;o((e=>({...e,image:c}))),B({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){T("Failed to upload image. Please try again."),B({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{q(!1)}else T("Please upload a valid image file (JPEG, PNG, GIF, or WebP)")},disabled:W})]}),a.image&&(0,Z.jsx)(p.A,{sx:{mt:1},children:(0,Z.jsx)("img",{src:a.image,alt:"Product preview",style:{maxWidth:"200px",maxHeight:"200px",objectFit:"contain"}})})]})})]})]}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:te,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>{if(a.name.trim()&&a.description.trim()&&a.categoryId&&a.image)if(N(""),n)Y.mutate({productId:n.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 N("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,Z.jsx)(A.A,{size:20,color:"inherit"}):null,children:K.isPending||K.isLoading||Y.isPending||Y.isLoading?n?"Updating...":"Creating...":n?"Update":"Add"})]})]}),(0,Z.jsxs)(Qe.A,{open:b,onClose:()=>v(!1),children:[(0,Z.jsx)(Ze.A,{children:"Add New Category"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(se.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:I,onChange:e=>S(e.target.value),error:!!w,helperText:w,onKeyPress:e=>{"Enter"===e.key&&oe()}})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>v(!1),children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:oe,variant:"contained",disabled:Q.isPending,children:Q.isPending?"Creating...":"Create"})]})]}),(0,Z.jsx)(mr.A,{open:O.open,autoHideDuration:6e3,onClose:ce,anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,Z.jsx)(ne.A,{onClose:ce,severity:O.severity,sx:{width:"100%"},children:O.message})})]})};var Dr=t(75813),Lr=t(8047),$r=t(89966),zr=t(52653);const Rr=[{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"}],Tr=("sandbox-preview-mode"?.startsWith("sandbox-"),()=>{const[e,s]=(0,x.useState)(""),[t,r]=(0,x.useState)(""),[n,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null),[g,j]=(0,x.useState)(!1),[y,f]=(0,x.useState)(""),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[w,k]=(0,x.useState)(""),[F,D]=(0,x.useState)(!1),[L,z]=(0,x.useState)({open:!1,message:"",severity:"info"}),[R,T]=(0,x.useState)(!1);(0,x.useEffect)((()=>{if(c){T(!0);const e=setTimeout((()=>{T(!1),h(null)}),4e3);return()=>clearTimeout(e)}}),[c]);const{data:W,isLoading:q,refetch:O}=(0,u.I)({queryKey:["orders",t,e],queryFn:()=>C("\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 C(E,{storeId:a.storeId}):null,enabled:!!a?.storeId}),{data:U={stores:[]},isLoading:N}=(0,u.I)({queryKey:["stores"],queryFn:()=>C($),enabled:l}),M=x.useMemo((()=>{const e={};return(U.stores||[]).forEach((s=>{e[s.id]=s})),e}),[U]),_=(0,Is.n)({mutationFn:async e=>await C(P,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onMutate:()=>{D(!0)},onSuccess:(e,s)=>{D(!1),W&&W.getAllOrders&&W.getAllOrders.forEach((e=>{e.id===s.orderId&&Object.assign(e,s)})),j(!1),o(null),f(""),v(""),S(""),k(""),z({open:!0,message:"Order status updated successfully!",severity:"success"})},onError:e=>{D(!1),h(e.message),j(!1),z({open:!0,message:`Failed to update order status: ${e.message}`,severity:"error"})}}),V=()=>{i(!1),o(null)},H=e=>{const{name:t,value:n}=e.target;"searchTerm"===t?s(n):"statusFilter"===t&&r(n)},G=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,Z.jsx)(Dr.A,{});case"CANCELLED":return(0,Z.jsx)(Lr.A,{});case"PENDING":return(0,Z.jsx)($r.A,{});default:return null}},K=e=>{if(!e)return"Not scheduled";return new Date(e).toLocaleString()},Y=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e),Q=W?.getAllOrders?.filter((s=>{const r="PICKUP"===s.type?s.pickupAddress?.address:s.address?.address,n=""===e||r?.toLowerCase().includes(e.toLowerCase())||s.id.toString().includes(e),i=""===t||s.status===t;return n&&i}));return(0,Z.jsxs)(p.A,{children:[(0,Z.jsxs)(ae.A,{sx:{p:3,mb:3},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Z.jsx)(Us.A,{sx:{mr:1}}),(0,Z.jsx)(m.A,{variant:"h5",children:"Orders Management"})]}),c&&R&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:3},onClose:()=>T(!1),children:c}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsx)(se.A,{fullWidth:!0,placeholder:"Search by address or order ID",name:"searchTerm",value:e,onChange:H,InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(pr.A,{})})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,children:[(0,Z.jsx)(ur.A,{children:"Status"}),(0,Z.jsxs)(Oe.A,{name:"statusFilter",value:t,onChange:H,label:"Status",children:[(0,Z.jsx)(Ae.A,{value:"",children:"All Status"}),(0,Z.jsx)(Ae.A,{value:"PENDING",children:"Pending"}),(0,Z.jsx)(Ae.A,{value:"ACCEPTED",children:"Accepted"}),(0,Z.jsx)(Ae.A,{value:"READY_FOR_DELIVERY",children:"Ready for Delivery"}),(0,Z.jsx)(Ae.A,{value:"PICKED_UP",children:"Picked Up"}),(0,Z.jsx)(Ae.A,{value:"DELIVERED",children:"Delivered"}),(0,Z.jsx)(Ae.A,{value:"CANCELLED",children:"Cancelled"})]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:(0,Z.jsx)(br.A,{}),onClick:()=>{d(!0),O()},fullWidth:!0,sx:{height:"56px"},children:"Fetch Orders"})})]}),l?q?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,Z.jsx)(A.A,{})}):0===Q?.length?(0,Z.jsx)(ne.A,{severity:"info",sx:{mb:3},children:"No orders found matching your criteria"}):(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Order ID"}),(0,Z.jsx)(cr.A,{children:"Type"}),(0,Z.jsx)(cr.A,{children:"Address"}),(0,Z.jsx)(cr.A,{children:"Store"}),(0,Z.jsx)(cr.A,{children:"Status"}),(0,Z.jsx)(cr.A,{children:"Total Amount"}),(0,Z.jsx)(cr.A,{children:"Delivery Date"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:Q.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsxs)(cr.A,{children:["#",e.id]}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:"PICKUP"===e.type?"Pickup":"Delivery",color:"PICKUP"===e.type?"secondary":"primary",size:"small"})}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(m.A,{variant:"body2",children:"PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A"})}),(0,Z.jsx)(cr.A,{children:M[e.storeId]?.name||"N/A"}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{icon:G(e.status),label:Rr.find((s=>s.value===e.status))?.label||e.status.replace(/_/g," "),color:Rr.find((s=>s.value===e.status))?.color||"default",size:"small"})}),(0,Z.jsx)(cr.A,{children:Y(e.totalAmount)}),(0,Z.jsx)(cr.A,{children:K(e.deliveryDate)}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{size:"small",onClick:()=>(e=>{o(e),i(!0)})(e),children:(0,Z.jsx)(zr.A,{})}),(0,Z.jsx)(he.A,{size:"small",onClick:()=>(e=>{o(e),f(e.status),v(e.deliveryInstructions||""),j(!0)})(e),disabled:"CANCELLED"===e.status||"DELIVERED"===e.status,children:(0,Z.jsx)(hr.A,{})})]})]},e.id)))})]})}):(0,Z.jsx)(ye.A,{sx:{mb:3},children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Orders" to load order data'}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]})})]}),(0,Z.jsxs)(Qe.A,{open:n,onClose:V,maxWidth:"md",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:"Order Details"}),(0,Z.jsx)(Je.A,{children:a&&(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsxs)(m.A,{variant:"h6",gutterBottom:!0,children:["Order #",a.id]}),(0,Z.jsx)(Fe.A,{label:"PICKUP"===a.type?"Pickup":"Delivery",color:"PICKUP"===a.type?"secondary":"primary",sx:{mb:2}}),(0,Z.jsx)(Fe.A,{icon:G(a.status),label:Rr.find((e=>e.value===a.status))?.label||a.status.replace(/_/g," "),color:Rr.find((e=>e.value===a.status))?.color||"default",sx:{mb:2}})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Information"}),(0,Z.jsxs)(m.A,{variant:"body2",children:["Address: ","PICKUP"===a.type?a.pickupAddress?.address:a.address?.address||"N/A"]}),(0,Z.jsxs)(m.A,{variant:"body2",children:["Store: ",M[a.storeId]?.name||"N/A"," (",M[a.storeId]?.address||"",")"]}),(0,Z.jsxs)(m.A,{variant:"body2",children:["Total Amount: ",Y(a.totalAmount)]}),(0,Z.jsxs)(m.A,{variant:"body2",children:["Delivery Date: ",K(a.deliveryDate)]}),a.deliveryInstructions&&(0,Z.jsxs)(m.A,{variant:"body2",children:["Delivery Instructions: ",a.deliveryInstructions]})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Items"}),(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{size:"small",children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Product"}),(0,Z.jsx)(cr.A,{children:"Quantity"}),(0,Z.jsx)(cr.A,{children:"Amount"})]})}),(0,Z.jsx)(xr.A,{children:a.orderItems?.edges?.map((e=>{let{node:s}=e;return(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:s.product?.name||"N/A"}),(0,Z.jsx)(cr.A,{children:s.quantity}),(0,Z.jsx)(cr.A,{children:Y(s.orderAmount)})]},s.id)}))})]})})]})]})}),(0,Z.jsx)(Xe.A,{children:(0,Z.jsx)(X.A,{onClick:V,children:"Close"})})]}),(0,Z.jsxs)(Qe.A,{open:g,onClose:()=>j(!1),maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:"Update Order Status"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{select:!0,fullWidth:!0,label:"Status",value:y,onChange:e=>f(e.target.value),children:Rr.map((e=>(0,Z.jsx)(Ae.A,{value:e.value,children:e.label},e.value)))})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Delivery Instructions",value:b,onChange:e=>v(e.target.value),multiline:!0,rows:3})}),("READY"===y||"READY_FOR_DELIVERY"===y)&&(0,Z.jsxs)(Z.Fragment,{children:[0===B?.getStoreDrivers?.length&&(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(ne.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,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,required:!0,children:[(0,Z.jsx)(ur.A,{children:"Delivery Agent"}),(0,Z.jsx)(Oe.A,{value:I,onChange:e=>S(e.target.value),label:"Delivery Agent",children:B?.getStoreDrivers?.length>0?B.getStoreDrivers.map((e=>(0,Z.jsxs)(Ae.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId))):(0,Z.jsx)(Ae.A,{disabled:!0,children:"No delivery agents available for this store"})})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Schedule Time",value:w,onChange:e=>k(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>j(!1),children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{if(!a)return;const e="DELIVERY"===a.type,s=a.address?.address,t=s&&""!==s.trim(),r=Array.isArray(a.orderItems?.edges)&&a.orderItems.edges.some((e=>{let{node:s}=e;return s.quantity>0}));if(e&&!t||!r)return h("Order must have a valid address and at least one product to update status."),void j(!1);const n={orderId:a.id,status:y,deliveryInstructions:b};if("READY"===y||"READY_FOR_DELIVERY"===y){if(!I)return void z({open:!0,message:"Driver ID is required for this status",severity:"error"});if(!w)return void z({open:!0,message:"Schedule time is required for this status",severity:"error"});n.driverId=parseInt(I),n.scheduleTime=w}_.mutate(n)},variant:"contained",color:"primary",disabled:F||("READY"===y||"READY_FOR_DELIVERY"===y)&&(!I||0===B?.getStoreDrivers?.length),children:F?"Updating...":"Update"})]})]}),(0,Z.jsx)(mr.A,{open:L.open,autoHideDuration:6e3,onClose:()=>z((e=>({...e,open:!1}))),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,Z.jsx)(ne.A,{onClose:()=>z((e=>({...e,open:!1}))),severity:L.severity,sx:{width:"100%"},children:L.message})})]})});var Wr=t(77867),qr=t(74229),Or=t(39804);const Br=()=>{const[e,s]=(0,x.useState)(!1),[t,r]=(0,x.useState)(!1),[n,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null),[g,j]=(0,x.useState)("info"),{data:y,isLoading:f,error:b,refetch:v}=(0,u.I)({queryKey:["allStoresSquareStatus"],queryFn:()=>C("\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:()=>C("\n query AllStores {\n stores {\n id\n name\n codEnabled\n }\n }\n")}),w=(0,Is.n)({mutationFn:e=>C("\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:(j("error"),h(e.connectSquare?.message||"Failed to generate authorization URL"))},onError:e=>{j("error"),h(e.message||"Failed to initiate Square connection")}}),P=(0,Is.n)({mutationFn:e=>C("\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?(j("success"),h("Square account disconnected successfully"),v()):(j("error"),h(e.disconnectSquare?.message||"Failed to disconnect Square"))},onError:e=>{s(!1),i(null),j("error"),h(e.message||"Failed to disconnect Square account")}}),k=(0,Is.n)({mutationFn:e=>C("\n mutation ToggleCod($storeId: Int!, $enabled: Boolean!) {\n toggleCod(storeId: $storeId, enabled: $enabled) {\n id\n codEnabled\n }\n }\n",e),onSuccess:e=>{r(!1),o(null),e.toggleCod&&(j("success"),h(e.toggleCod.codEnabled?"Cash on Delivery enabled":"Cash on Delivery disabled"),S())},onError:e=>{r(!1),o(null),j("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"),r=e.get("store_id");"true"===s?(j("success"),h("Square account connected successfully"+(r?` for store ID ${r}`:"")),v(),window.history.replaceState({},"","/admin/payment-settings")):t&&(j("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 F=()=>{s(!1),i(null)},E=y?.allStoresSquareStatus||[],D=Object.fromEntries((I?.stores||[]).map((e=>[e.id,e.codEnabled])));return(0,Z.jsxs)(p.A,{children:[(0,Z.jsxs)(ae.A,{sx:{p:3},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Z.jsx)(gs.A,{sx:{mr:1,fontSize:32}}),(0,Z.jsx)(m.A,{variant:"h5",children:"Square Payment Settings"})]}),c&&(0,Z.jsx)(ne.A,{severity:g,sx:{mb:3},onClose:()=>h(null),children:c}),b&&(0,Z.jsxs)(ne.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",b.message]}),(0,Z.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,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Z.jsx)(A.A,{})}):(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Store Name"}),(0,Z.jsx)(cr.A,{children:"Connection Status"}),(0,Z.jsx)(cr.A,{children:"Merchant ID"}),(0,Z.jsx)(cr.A,{children:"COD"}),(0,Z.jsx)(cr.A,{align:"right",children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:0===E.length?(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:5,align:"center",children:"No stores found"})}):E.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(m.A,{variant:"body2",fontWeight:"medium",children:e.storeName})}),(0,Z.jsx)(cr.A,{children:e.isConnected?(0,Z.jsx)(Fe.A,{label:"Connected",color:"success",size:"small",icon:(0,Z.jsx)(qr.A,{})}):(0,Z.jsx)(Fe.A,{label:"Not Connected",color:"default",size:"small",icon:(0,Z.jsx)(Or.A,{})})}),(0,Z.jsx)(cr.A,{children:e.merchantId||(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"—"})}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Ne.A,{checked:D[e.storeId]||!1,onChange:s=>{o(e),d(s.target.checked),r(!0)},size:"small",disabled:k.isPending})}),(0,Z.jsx)(cr.A,{align:"right",children:e.isConnected?(0,Z.jsx)(X.A,{variant:"outlined",color:"error",size:"small",onClick:()=>(e=>{i(e),s(!0)})(e),disabled:P.isLoading,children:"Disconnect"}):(0,Z.jsx)(X.A,{variant:"contained",color:"primary",size:"small",onClick:()=>{return s=e.storeId,void w.mutate(s);var s},disabled:w.isLoading,startIcon:w.isLoading&&(0,Z.jsx)(A.A,{size:16}),children:"Connect Square"})})]},e.storeId)))})]})})]}),(0,Z.jsxs)(Qe.A,{open:e,onClose:F,children:[(0,Z.jsx)(Ze.A,{children:"Disconnect Square?"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(Wr.A,{children:["Are you sure you want to disconnect Square for ",(0,Z.jsx)("strong",{children:n?.storeName}),"?",(0,Z.jsx)("br",{}),(0,Z.jsx)("br",{}),"Customers will not be able to make card payments until you reconnect."]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:F,disabled:P.isLoading,children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{n&&P.mutate(n.storeId)},color:"error",variant:"contained",disabled:P.isLoading,startIcon:P.isLoading&&(0,Z.jsx)(A.A,{size:16}),children:"Disconnect"})]})]}),(0,Z.jsxs)(Qe.A,{open:t,onClose:()=>{r(!1),o(null)},children:[(0,Z.jsxs)(Ze.A,{children:[l?"Enable":"Disable"," Cash on Delivery?"]}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(Wr.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,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{r(!1),o(null)},disabled:k.isPending,children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{a&&k.mutate({storeId:a.storeId,enabled:l})},variant:"contained",color:l?"primary":"error",disabled:k.isPending,startIcon:k.isPending&&(0,Z.jsx)(A.A,{size:16}),children:k.isPending?"Saving...":"Confirm"})]})]})]})};var Ur=t(87558),Nr=t(1275),Mr=t(88116),_r=t(98708),Vr=t(60181);const Hr=()=>{const[e,s]=(0,x.useState)(0),[t,r]=(0,x.useState)(10),[n,i]=(0,x.useState)(""),[a,o]=(0,x.useState)(""),[l,d]=(0,x.useState)(null),[c,h]=(0,x.useState)(!1),[j,y]=(0,x.useState)(!1),[f,b]=(0,x.useState)(""),[v,I]=(0,x.useState)(""),[S,w]=(0,x.useState)(!0),[P,k]=(0,x.useState)(!0),[F,E]=(0,x.useState)({open:!1,message:"",severity:"success"}),[D,L]=(0,x.useState)("table"),[R,T]=(0,x.useState)(null),[W,q]=(0,x.useState)(""),[O,B]=(0,x.useState)(!1),[U,N]=(0,x.useState)({price:"",quantity:"",measurement:"",unit:""}),M=(0,x.useRef)(null),{data:_=[],isLoading:V,error:H,refetch:G}=(0,u.I)({queryKey:["stores"],queryFn:async()=>{const e=await C($);return e?.stores||[]},enabled:!0}),{data:K,isLoading:Y}=(0,u.I)({queryKey:["products"],queryFn:async()=>{const e=await C(z);return e?.products||[]},enabled:j}),{data:Q,isLoading:J,error:ee,refetch:te}=(0,u.I)({queryKey:["storeInventory",a],queryFn:async()=>{if(!a)return[];const e=await C("\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,Is.n)({mutationFn:e=>C("\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)=>{Q&&Q.forEach((e=>{e.id===s.inventoryId&&Object.assign(e,s)})),E({open:!0,message:"Inventory item updated successfully",severity:"success"}),h(!1)},onError:e=>{E({open:!0,message:`Error updating inventory: ${e.message}`,severity:"error"})}}),ie=(0,Is.n)({mutationFn:e=>C("\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:()=>{E({open:!0,message:"Product added to inventory successfully",severity:"success"}),te(),y(!1),ce()},onError:e=>{E({open:!0,message:`Error adding product to inventory: ${e.message}`,severity:"error"})}}),oe=e=>{d(e),b(e.quantity.toString()),I(e.price.toString()),w(e.isAvailable),k(e.isListed),h(!0)},le=()=>{E({...F,open:!1})},de=()=>{y(!1),ce()},ce=()=>{T(null),q(""),N({price:"",quantity:"",measurement:"",unit:""})},ue=e=>{const{name:s,value:t}=e.target;N((e=>({...e,[s]:t})))},me=()=>Q?Q.filter((e=>e.product.name.toLowerCase().includes(n.toLowerCase()))):[],pe=K?.filter((e=>e.name.toLowerCase().includes(W.toLowerCase())))||[],ge=(0,x.useRef)(null),ve=(0,x.useCallback)((()=>{if("grid"!==D||!ge.current)return;const e=ge.current.offsetWidth,s=window.innerHeight-ge.current.getBoundingClientRect().top-150,n=Math.max(1,Math.floor(e/270))*Math.max(1,Math.floor(s/260));n!==t&&r(n)}),[D,t]);(0,x.useEffect)((()=>{if("grid"===D)return ve(),window.addEventListener("resize",ve),()=>window.removeEventListener("resize",ve)}),[D,ve]),(0,x.useEffect)((()=>{"table"===D&&10!==t&&r(10)}),[D,t]);return(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Inventory Management"}),(0,Z.jsxs)(ae.A,{sx:{p:3,mb:3},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",mb:3,flexWrap:"wrap",gap:2},children:[(0,Z.jsxs)(Cs.A,{sx:{minWidth:200},children:[(0,Z.jsx)(ur.A,{children:"Select Store"}),(0,Z.jsx)(Oe.A,{value:a,onChange:e=>{o(e.target.value),s(0)},label:"Select Store",children:Array.isArray(_)&&_?.map((e=>(0,Z.jsx)(Ae.A,{value:e.id,children:e.name},e.id)))})]}),(0,Z.jsx)(se.A,{placeholder:"Search products...",value:n,onChange:e=>{i(e.target.value),s(0)},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(pr.A,{})})},sx:{width:300}}),(0,Z.jsx)(X.A,{variant:"outlined",startIcon:"table"===D?(0,Z.jsx)(_r.A,{}):(0,Z.jsx)(Vr.A,{}),onClick:()=>{L("table"===D?"grid":"table")},children:"table"===D?"Grid View":"Table View"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:(0,Z.jsx)(Ce.A,{}),onClick:()=>{a?y(!0):E({open:!0,message:"Please select a store first",severity:"warning"})},disabled:!a,children:"Add Product"})]}),H&&(0,Z.jsxs)(ne.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",H.message]}),ee&&(0,Z.jsxs)(ne.A,{severity:"error",sx:{mb:3},children:["Error loading inventory: ",ee.message]}),a?J?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Z.jsx)(A.A,{})}):0===me().length?(0,Z.jsx)(ne.A,{severity:"info",sx:{my:4},children:"No inventory found for this store."}):(0,Z.jsxs)(Z.Fragment,{children:["table"===D?(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Product"}),(0,Z.jsx)(cr.A,{children:"Category"}),(0,Z.jsx)(cr.A,{children:"Available"}),(0,Z.jsx)(cr.A,{children:"Listed"}),(0,Z.jsx)(cr.A,{children:"Price"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:me().slice(e*t,e*t+t).map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[e.product.image&&(0,Z.jsx)(p.A,{component:"img",src:e.product.image,alt:e.product.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"body1",children:e.product.name}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:e.product.description})]})]})}),(0,Z.jsx)(cr.A,{children:e.product.category?.name||"N/A"}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:e.isAvailable?"Available":"Not Available",color:e.isAvailable?"success":"error",size:"small"})}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:e.isListed?"Listed":"Not Listed",color:e.isListed?"success":"error",size:"small"})}),(0,Z.jsxs)(cr.A,{children:["$",e.price.toFixed(2)]}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(he.A,{size:"small",color:"primary",onClick:()=>oe(e),children:(0,Z.jsx)(hr.A,{})})})]},e.id)))})]})}):(0,Z.jsx)(je.Ay,{container:!0,spacing:3,ref:ge,children:me().slice(e*t,e*t+t).map((e=>(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,Z.jsxs)(ye.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,Z.jsx)(fe.A,{component:"img",height:"140",image:e.product.image||"https://via.placeholder.com/140",alt:e.product.name}),(0,Z.jsxs)(be.A,{sx:{flexGrow:1},children:[(0,Z.jsx)(m.A,{gutterBottom:!0,variant:"h6",component:"div",noWrap:!0,children:e.product.name}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1},children:e.product.category?.name||"N/A"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:1},noWrap:!0,children:e.product.description}),(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:2},children:[(0,Z.jsx)(Fe.A,{label:`Qty: ${e.quantity}`,color:e.quantity<10?"error":"success",size:"small"}),(0,Z.jsxs)(m.A,{variant:"h6",color:"primary",children:["$",e.price.toFixed(2)]})]}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"space-between",mt:2},children:(0,Z.jsx)(X.A,{size:"small",startIcon:(0,Z.jsx)(hr.A,{}),onClick:()=>oe(e),children:"Edit"})})]})]})},e.id)))}),(0,Z.jsx)(g.A,{component:"div",count:me().length,page:e,onPageChange:(e,t)=>{s(t)},rowsPerPage:t,onRowsPerPageChange:e=>{r(parseInt(e.target.value,10)),s(0)},rowsPerPageOptions:(()=>{if("grid"===D&&ge.current){const e=ge.current.offsetWidth,s=window.innerHeight-ge.current.getBoundingClientRect().top-150,t=270,r=260,n=Math.max(1,Math.floor(e/t));Math.max(1,Math.floor(s/r));return[...[1*n,2*n,3*n,4*n,5*n].filter((e=>eh(!1),fullWidth:!0,maxWidth:"sm",children:[(0,Z.jsx)(Ze.A,{children:"Edit Inventory Item"}),(0,Z.jsx)(Je.A,{children:l&&(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[l.product.image&&(0,Z.jsx)(p.A,{component:"img",src:l.product.image,alt:l.product.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"subtitle1",children:l.product.name}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:l.product.category?.name||"N/A"})]})]}),(0,Z.jsx)(se.A,{label:"Quantity",type:"number",fullWidth:!0,value:f,onChange:e=>b(e.target.value),sx:{mb:2}}),(0,Z.jsx)(se.A,{label:"Price ($)",type:"number",fullWidth:!0,value:v,onChange:e=>I(e.target.value),sx:{mb:2}}),(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mb:2},children:[(0,Z.jsx)(ur.A,{children:"Availability"}),(0,Z.jsxs)(Oe.A,{value:S,onChange:e=>w(e.target.value),label:"Availability",children:[(0,Z.jsx)(Ae.A,{value:!0,children:"Available"}),(0,Z.jsx)(Ae.A,{value:!1,children:"Not Available"})]})]}),(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mb:2},children:[(0,Z.jsx)(ur.A,{children:"Listing Status"}),(0,Z.jsxs)(Oe.A,{value:P,onChange:e=>k(e.target.value),label:"Listing Status",children:[(0,Z.jsx)(Ae.A,{value:!0,children:"Listed"}),(0,Z.jsx)(Ae.A,{value:!1,children:"Not Listed"})]})]})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>h(!1),children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{l&&re.mutate({inventoryId:l.id,price:parseFloat(v),quantity:parseInt(f),isAvailable:S,isListed:P})},variant:"contained",color:"primary",disabled:re.isPending,children:re.isPending?"Updating...":"Update"})]})]}),(0,Z.jsxs)(Qe.A,{open:j,onClose:de,fullWidth:!0,maxWidth:"md",children:[(0,Z.jsx)(Ze.A,{children:"Add Product to Inventory"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Select a product to add to the store's inventory"}),(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mt:2,mb:3},children:[(0,Z.jsx)(se.A,{ref:M,label:"Search Product",placeholder:"Start typing to search...",value:W,onChange:e=>{q(e.target.value),B(!0)},onFocus:()=>B(!0),onClick:()=>B(!0),fullWidth:!0,InputProps:{endAdornment:Y?(0,Z.jsx)(A.A,{color:"inherit",size:20}):null}}),(0,Z.jsx)(Ur.A,{open:O&&pe.length>0,anchorEl:M.current,placement:"bottom-start",style:{width:M.current?.offsetWidth,zIndex:1300},children:(0,Z.jsx)(Nr.x,{onClickAway:()=>{B(!1)},children:(0,Z.jsx)(ae.A,{elevation:3,children:(0,Z.jsx)(Mr.A,{sx:{maxHeight:300,overflow:"auto"},children:pe.map((e=>(0,Z.jsx)(Ae.A,{onClick:()=>(e=>{T(e),q(e.name),B(!1)})(e),selected:R?.id===e.id,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[e.image&&(0,Z.jsx)(p.A,{component:"img",src:e.image,alt:e.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"body1",children:e.name}),(0,Z.jsx)(m.A,{variant:"caption",color:"textSecondary",children:e.categoryId?`Category ID: ${e.categoryId}`:"No category"})]})]})},e.id)))})})})})]}),R&&(0,Z.jsxs)(p.A,{sx:{mb:3,p:2,bgcolor:"background.paper",borderRadius:1},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",gutterBottom:!0,children:"Selected Product:"}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[R.image&&(0,Z.jsx)(p.A,{component:"img",src:R.image,alt:R.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"body1",children:R.name}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:R.description})]})]})]}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,children:(0,Z.jsx)(se.A,{label:"Price ($)",type:"number",name:"price",fullWidth:!0,value:U.price,onChange:ue,required:!0,inputProps:{min:0,step:.01}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,children:(0,Z.jsx)(se.A,{label:"Quantity",type:"number",name:"quantity",fullWidth:!0,value:U.quantity,onChange:ue,required:!0,inputProps:{min:0}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,children:(0,Z.jsx)(se.A,{label:"Measurement (optional)",type:"number",name:"measurement",fullWidth:!0,value:U.measurement,onChange:ue,inputProps:{min:0,step:.01}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,children:(0,Z.jsx)(se.A,{label:"Unit (optional)",name:"unit",fullWidth:!0,value:U.unit,onChange:ue,placeholder:"e.g., kg, g, L, ml"})})]})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:de,children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{R?U.price&&U.quantity?ie.mutate({productId:R.id,storeId:parseInt(a),price:parseFloat(U.price),quantity:parseInt(U.quantity),measurement:U.measurement?parseInt(U.measurement):null,unit:U.unit||""}):E({open:!0,message:"Please fill in all required fields",severity:"warning"}):E({open:!0,message:"Please select a product",severity:"warning"})},variant:"contained",color:"primary",disabled:ie.isPending||!R,children:ie.isPending?"Adding...":"Add to Inventory"})]})]}),(0,Z.jsx)(mr.A,{open:F.open,autoHideDuration:6e3,onClose:le,message:F.message,children:(0,Z.jsx)(ne.A,{onClose:le,severity:F.severity,children:F.message})})]})},Gr=()=>{const[e,s]=(0,x.useState)(0),[t,r]=(0,x.useState)(10),[n,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[l,d]=(0,x.useState)(""),[c,h]=(0,x.useState)(null),[j,y]=(0,x.useState)(!1),[f,b]=(0,x.useState)(!1),[v,I]=(0,x.useState)(null),[S,w]=(0,x.useState)(null),[P,k]=(0,x.useState)(!1),{data:F,refetch:E}=(0,u.I)({queryKey:["categories"],queryFn:async()=>(await C("\n query GetCategories {\n categories {\n id\n name\n createdAt\n }\n }\n")).categories||[],enabled:!1}),D=(0,Is.n)({mutationFn:e=>C("\n mutation CreateCategory($name: String!) {\n createCategory(name: $name) {\n category {\n id\n name\n }\n }\n }\n",{name:e}),onSuccess:()=>{R(),E()},onError:e=>{h(e.message||"Failed to create category")}}),L=(0,Is.n)({mutationFn:e=>{let{id:s,name:t}=e;return C("\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(),I("Category updated successfully")},onError:e=>{h(e.message||"Failed to update category")}}),$=(0,Is.n)({mutationFn:e=>C("\n mutation DeleteCategory($categoryId: Int!) {\n deleteCategory(categoryId: $categoryId) {\n success\n }\n }\n",e),onSuccess:()=>{I("Category deleted successfully"),k(!1),E()},onError:e=>{h(e.message)}}),z=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)},T=()=>{l.trim()?a?L.mutate({id:a.id,name:l.trim()}):D.mutate(l.trim()):h("Category name is required")},W=F?.slice(e*t,e*t+t);return(0,Z.jsxs)(p.A,{children:[(0,Z.jsxs)(ae.A,{sx:{p:3,mb:3},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Z.jsx)(Ce.A,{sx:{mr:1}}),(0,Z.jsx)(m.A,{variant:"h5",children:"Category Management"})]}),(0,Z.jsx)(je.Ay,{container:!0,spacing:2,sx:{mb:3},children:(0,Z.jsxs)(je.Ay,{item:!0,xs:12,sx:{display:"flex",gap:2},children:[(0,Z.jsx)(X.A,{variant:"contained",startIcon:(0,Z.jsx)(br.A,{}),onClick:()=>{y(!0),h(null),E().then((()=>{b(!0),y(!1)})).catch((e=>{h("Failed to load categories. Please try again."),y(!1)}))},disabled:j,sx:{minWidth:150},children:j?(0,Z.jsx)(A.A,{size:24}):"Fetch Categories"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:(0,Z.jsx)(Ce.A,{}),onClick:()=>z(),children:"Add Category"})]})}),c&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:3},children:c}),f?j?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Z.jsx)(A.A,{})}):(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)(ar.A,{children:[(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"ID"}),(0,Z.jsx)(cr.A,{children:"Name"}),(0,Z.jsx)(cr.A,{children:"Created At"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:0===W?.length?(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:4,align:"center",children:"No categories found"})}):W?.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.id}),(0,Z.jsx)(cr.A,{children:e.name}),(0,Z.jsx)(cr.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{size:"small",onClick:()=>z(e),children:(0,Z.jsx)(hr.A,{})}),(0,Z.jsx)(he.A,{size:"small",onClick:()=>(e=>{w(e),k(!0)})(e),children:(0,Z.jsx)(fr.A,{})})]})]},e.id)))})]}),(0,Z.jsx)(g.A,{component:"div",count:F?.length||0,page:e,onPageChange:(e,t)=>{s(t)},rowsPerPage:t,onRowsPerPageChange:e=>{r(parseInt(e.target.value,10)),s(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,Z.jsxs)(p.A,{sx:{textAlign:"center",py:4},children:[(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Categories" to load category information'}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,Z.jsxs)(Qe.A,{open:n,onClose:R,children:[(0,Z.jsx)(Ze.A,{children:a?"Edit Category":"Add New Category"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(se.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&&T()}})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:R,children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:T,variant:"contained",disabled:D.isPending||L.isPending,children:D.isPending||L.isPending?(0,Z.jsx)(A.A,{size:24}):a?"Update":"Create"})]})]}),(0,Z.jsxs)(Qe.A,{open:P,onClose:()=>k(!1),children:[(0,Z.jsx)(Ze.A,{children:"Delete Category"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(m.A,{children:"Are you sure you want to delete this category?"})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>k(!1),disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{S&&$.mutate({categoryId:S.id})},variant:"contained",color:"error",disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})},Kr=e=>{let{open:s,onClose:t,selectedFee:r,onUpdate:n,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,l]=(0,x.useState)(a);(0,x.useEffect)((()=>{r?l({feeCurrency:r.feeCurrency||"",feeRate:r.feeRate?.toString()||"",limit:r.limit?.toString()||"",type:r.type?.toUpperCase()||"DELIVERY"}):s&&l(a)}),[r,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,Z.jsxs)(Qe.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:r?"Edit Fee":"Add New Fee"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(p.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Z.jsxs)(Cs.A,{fullWidth:!0,children:[(0,Z.jsx)(ur.A,{children:"Fee Type"}),(0,Z.jsxs)(Oe.A,{name:"type",value:o.type,onChange:d,label:"Fee Type",children:[(0,Z.jsx)(Ae.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,Z.jsx)(Ae.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,Z.jsx)(se.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:d,fullWidth:!0,placeholder:"e.g., USD"}),(0,Z.jsx)(se.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,Z.jsx)(se.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:t,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>{n({id:r?.id,...o,feeRate:parseFloat(o.feeRate),limit:parseFloat(o.limit)}),r||l(a)},disabled:i,startIcon:i?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},Yr=()=>{const[e,s]=(0,x.useState)(""),[t,r]=(0,x.useState)(null),[n,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,g]=(0,x.useState)(""),{data:j,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>C("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=j?.stores||[],{data:b,isLoading:v,refetch:I}=(0,u.I)({queryKey:["getFeesByStore",e],queryFn:()=>C("\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||[],w=(0,Is.n)({mutationFn:e=>C("\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),r(null),g("Fee updated successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error updating fee: ${e.message}`)}}),P=(0,Is.n)({mutationFn:e=>C("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),r(null),g("Fee deleted successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error deleting fee: ${e.message}`)}}),k=(0,Is.n)({mutationFn:s=>C("\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),r(null),g("Fee added successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error adding fee: ${e.message}`)}});return y?(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})}):(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Fees Management"}),(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mb:3},children:[(0,Z.jsx)(ur.A,{children:"Select Store"}),(0,Z.jsx)(Oe.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,Z.jsx)(Ae.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,Z.jsx)(ne.A,{severity:"info",sx:{mb:4},children:(0,Z.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its fees."})}),e&&(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",children:"Fees"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:k.isPending||k.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):(0,Z.jsx)(Ce.A,{}),onClick:()=>{r(null),i(!0)},disabled:k.isPending||k.isLoading,children:k.isPending||k.isLoading?"Adding...":"Add Fee"})]}),v?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Z.jsx)(A.A,{})}):0===S.length?(0,Z.jsx)(ne.A,{severity:"info",sx:{my:2},children:"No fees found for this store. Add your first fee to get started."}):(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Type"}),(0,Z.jsx)(cr.A,{children:"Currency"}),(0,Z.jsx)(cr.A,{children:"Rate"}),(0,Z.jsx)(cr.A,{children:"Limit"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:0!==S.length||v?S.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.type}),(0,Z.jsx)(cr.A,{children:e.feeCurrency}),(0,Z.jsx)(cr.A,{children:e.feeRate}),(0,Z.jsx)(cr.A,{children:e.limit}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{onClick:()=>(e=>{r(e),i(!0)})(e),color:"primary",disabled:w.isPending||w.isLoading||P.isPending||P.isLoading,children:(0,Z.jsx)(hr.A,{})}),(0,Z.jsx)(he.A,{onClick:()=>(e=>{r(e),o(!0)})(e),color:"error",disabled:w.isPending||w.isLoading||P.isPending||P.isLoading,children:(0,Z.jsx)(fr.A,{})})]})]},e.id))):(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:5,align:"center",children:(0,Z.jsx)(ne.A,{severity:"info",sx:{my:2},children:"No fees found for this store."})})})})]})})]}),(0,Z.jsx)(Kr,{open:n,onClose:()=>{i(!1),r(null),d("")},selectedFee:t,onUpdate:e=>{t?w.mutate(e):k.mutate(e)},isLoading:w.isPending||w.isLoading||k.isPending||k.isLoading}),(0,Z.jsxs)(Qe.A,{open:a,onClose:()=>{o(!1),r(null),d("")},children:[(0,Z.jsx)(Ze.A,{children:"Delete Fee"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(m.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{o(!1),r(null)},disabled:P.isPending||P.isLoading,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",color:"error",onClick:()=>P.mutate({id:t.id}),disabled:P.isPending||P.isLoading,startIcon:P.isPending||P.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:P.isPending||P.isLoading?"Deleting...":"Delete"})]})]})]})},Qr=e=>{let{open:s,onClose:t,selectedLocationCode:r,onUpdate:n,isLoading:i,existingCodes:a}=e;const[o,l]=(0,x.useState)({location:"",code:""}),[d,c]=(0,x.useState)("");(0,x.useEffect)((()=>{l(r?{location:r.location||"",code:r.code||""}:{location:"",code:""}),c("")}),[r,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,Z.jsxs)(Qe.A,{open:s,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:r?"Edit Location Code":"Add New Location Code"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(p.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Z.jsx)(se.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,Z.jsx)(se.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,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:u,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>{(o.location.trim()?o.code.trim()?!a.some((e=>e.code.toLowerCase()===o.code.toLowerCase()&&(!r||e.id!==r.id)))||(c("This code already exists for this store"),0):(c("Code is required"),0):(c("Location is required"),0))&&n({id:r?.id,...o})},disabled:i,startIcon:i?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},Zr=()=>{const[e,s]=(0,x.useState)(""),[t,r]=(0,x.useState)(null),[n,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,g]=(0,x.useState)(""),{data:j,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>C("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=j?.stores||[],{data:b,isLoading:v,refetch:I}=(0,u.I)({queryKey:["getStoreLocationCodesByStore",e],queryFn:()=>C("\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||[],w=(0,Is.n)({mutationFn:e=>C("\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),r(null),g("Location code updated successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error updating location code: ${e.message}`)}}),P=(0,Is.n)({mutationFn:e=>C("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),r(null),g("Location code deleted successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error deleting location code: ${e.message}`)}}),k=(0,Is.n)({mutationFn:s=>C("\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),r(null),g("Location code added successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error adding location code: ${e.message}`)}});return y?(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})}):(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mb:3},children:[(0,Z.jsx)(ur.A,{children:"Select Store"}),(0,Z.jsx)(Oe.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,Z.jsx)(Ae.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,Z.jsx)(ne.A,{severity:"info",sx:{mb:4},children:(0,Z.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its location codes."})}),e&&(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",children:"Location Codes"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:k.isPending||k.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):(0,Z.jsx)(Ce.A,{}),onClick:()=>{r(null),i(!0)},disabled:k.isPending||k.isLoading,children:k.isPending||k.isLoading?"Adding...":"Add Location Code"})]}),v?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Z.jsx)(A.A,{})}):0===S.length?(0,Z.jsx)(ne.A,{severity:"info",sx:{my:2},children:"No location codes found for this store. Add your first location code to get started."}):(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Location"}),(0,Z.jsx)(cr.A,{children:"Code"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:0!==S.length||v?S.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.location}),(0,Z.jsx)(cr.A,{children:e.code}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{onClick:()=>(e=>{r(e),i(!0)})(e),color:"primary",disabled:w.isPending||w.isLoading||P.isPending||P.isLoading,children:(0,Z.jsx)(hr.A,{})}),(0,Z.jsx)(he.A,{onClick:()=>(e=>{r(e),o(!0)})(e),color:"error",disabled:w.isPending||w.isLoading||P.isPending||P.isLoading,children:(0,Z.jsx)(fr.A,{})})]})]},e.id))):(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:3,align:"center",children:(0,Z.jsx)(ne.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})})]}),(0,Z.jsx)(Qr,{open:n,onClose:()=>{i(!1),r(null),d("")},selectedLocationCode:t,onUpdate:e=>{t?w.mutate(e):k.mutate(e)},isLoading:w.isPending||w.isLoading||k.isPending||k.isLoading,existingCodes:S}),(0,Z.jsxs)(Qe.A,{open:a,onClose:()=>{o(!1),r(null),d("")},children:[(0,Z.jsx)(Ze.A,{children:"Delete Location Code"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(m.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{o(!1),r(null)},disabled:P.isPending||P.isLoading,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",color:"error",onClick:()=>P.mutate({id:t.id}),disabled:P.isPending||P.isLoading,startIcon:P.isPending||P.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:P.isPending||P.isLoading?"Deleting...":"Delete"})]})]})]})},Jr=e=>{let{open:s,onClose:t,selectedPickupAddress:r,onUpdate:n,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((()=>{r?(l({address:r.address||""}),h(!0)):(l({address:""}),h(!1)),c("")}),[r]);return(0,Z.jsxs)(Qe.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:r?"Edit Pickup Address":"Add New Pickup Address"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(p.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Z.jsx)(qt,{value:o.address,onChange:e=>{l((s=>({...s,address:e}))),c("")},onValidAddress:h}),d&&(0,Z.jsx)(m.A,{color:"error",variant:"caption",children:d})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:t,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>{(o.address.trim()?u?!a.some((e=>e.address.toLowerCase()===o.address.toLowerCase()&&(!r||e.id!==r.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))&&n({id:r?.id,...o})},disabled:i||!u,startIcon:i?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},Xr=()=>{const[e,s]=(0,x.useState)(""),[t,r]=(0,x.useState)(null),[n,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(""),[c,g]=(0,x.useState)(""),{data:j,isLoading:y}=(0,u.I)({queryKey:["getAllStores"],queryFn:()=>C("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),f=j?.stores||[],{data:b,isLoading:v,refetch:I}=(0,u.I)({queryKey:["getPickupAddressesByStore",e],queryFn:()=>C("\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||[],w=(0,Is.n)({mutationFn:e=>C("\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),r(null),g("Pickup address updated successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error updating pickup address: ${e.message}`)}}),P=(0,Is.n)({mutationFn:e=>C("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),r(null),g("Pickup address deleted successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error deleting pickup address: ${e.message}`)}}),k=(0,Is.n)({mutationFn:s=>C("\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),r(null),g("Pickup address added successfully"),setTimeout((()=>g("")),3e3)},onError:e=>{d(`Error adding pickup address: ${e.message}`)}});return y?(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})}):(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mb:3},children:[(0,Z.jsx)(ur.A,{children:"Select Store"}),(0,Z.jsx)(Oe.A,{value:e,onChange:e=>s(e.target.value),label:"Select Store",children:f.map((e=>(0,Z.jsx)(Ae.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,Z.jsx)(ne.A,{severity:"info",sx:{mb:4},children:(0,Z.jsx)(m.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its pickup addresses."})}),e&&(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",children:"Pickup Addresses"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:k.isPending||k.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):(0,Z.jsx)(Ce.A,{}),onClick:()=>{r(null),i(!0)},disabled:k.isPending||k.isLoading,children:k.isPending||k.isLoading?"Adding...":"Add Pickup Address"})]}),v?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,Z.jsx)(A.A,{})}):0===S.length?(0,Z.jsx)(ne.A,{severity:"info",sx:{my:2},children:"No pickup addresses found for this store. Add your first pickup address to get started."}):(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Address"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:S.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.address}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{onClick:()=>(e=>{r(e),i(!0)})(e),color:"primary",disabled:w.isPending||w.isLoading||P.isPending||P.isLoading,children:(0,Z.jsx)(hr.A,{})}),(0,Z.jsx)(he.A,{onClick:()=>(e=>{r(e),o(!0)})(e),color:"error",disabled:w.isPending||w.isLoading||P.isPending||P.isLoading,children:(0,Z.jsx)(fr.A,{})})]})]},e.id)))})]})})]}),(0,Z.jsx)(Jr,{open:n,onClose:()=>{i(!1),r(null),d("")},selectedPickupAddress:t,onUpdate:e=>{t?w.mutate(e):k.mutate(e)},isLoading:w.isPending||w.isLoading||k.isPending||k.isLoading,existingAddresses:S}),(0,Z.jsxs)(Qe.A,{open:a,onClose:()=>{o(!1),r(null),d("")},children:[(0,Z.jsx)(Ze.A,{children:"Delete Pickup Address"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(m.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{o(!1),r(null)},disabled:P.isPending||P.isLoading,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",color:"error",onClick:()=>P.mutate({id:t.id}),disabled:P.isPending||P.isLoading,startIcon:P.isPending||P.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:P.isPending||P.isLoading?"Deleting...":"Delete"})]})]})]})},en=240,sn=65,tn=[{text:"Dashboard",icon:(0,Z.jsx)(Jt.A,{}),path:"/admin/dashboard"},{text:"Stores",icon:(0,Z.jsx)(Rt.A,{}),path:"/admin/stores"},{text:"Product Management",icon:(0,Z.jsx)(Xt.A,{}),path:"/admin/products"},{text:"Inventory Management",icon:(0,Z.jsx)(er.A,{}),path:"/admin/inventory"},{text:"Orders",icon:(0,Z.jsx)(we.A,{}),path:"/admin/orders"},{text:"Users",icon:(0,Z.jsx)(sr.A,{}),path:"/admin/users"},{text:"Payment Settings",icon:(0,Z.jsx)(gs.A,{}),path:"/admin/payment-settings"},{text:"Categories",icon:(0,Z.jsx)(er.A,{}),path:"/admin/categories"},{text:"Fees Management",icon:(0,Z.jsx)(gs.A,{}),path:"/admin/fees"},{text:"Location Codes",icon:(0,Z.jsx)(cs.A,{}),path:"/admin/location-codes"},{text:"Pickup Addresses",icon:(0,Z.jsx)(Es.A,{}),path:"/admin/pickup-addresses"}],rn=()=>{const e=(0,ke.A)(),s=(0,qe.A)(e.breakpoints.down("sm")),[t,r]=(0,x.useState)(!0),{user:n,ability:i,logout:a}=K(),o=(0,d.Zp)(),l=(0,d.zy)(),c=(0,Z.jsxs)(p.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",justifyContent:t&&!s?"space-between":"center",p:2,minHeight:64},children:[t&&!s&&(0,Z.jsx)(m.A,{variant:"h6",noWrap:!0,component:"div",children:"Admin Panel"}),!s&&(0,Z.jsx)(he.A,{onClick:()=>{r(!t)},children:t?(0,Z.jsx)(us.A,{}):(0,Z.jsx)(tr.A,{})})]}),(0,Z.jsx)(As.A,{}),(0,Z.jsxs)(zs.A,{children:[tn.map((e=>(0,Z.jsxs)(Rs.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,Z.jsx)(Ts.A,{sx:{minWidth:0,mr:t&&!s?3:"auto",justifyContent:"center",color:l.pathname===e.path?"white":"inherit"},children:e.icon}),(0,Z.jsx)(Ws.A,{primary:e.text,sx:{opacity:t&&!s?1:0}})]},e.text))),(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsxs)(Rs.Ay,{button:!0,onClick:()=>{(async()=>{try{await(0,Ns.C)(),a(),o("/")}catch(e){}})()},sx:{minHeight:48,justifyContent:t&&!s?"initial":"center",px:2.5},children:[(0,Z.jsx)(Ts.A,{sx:{minWidth:0,mr:t&&!s?3:"auto",justifyContent:"center"},children:(0,Z.jsx)(rr.A,{})}),(0,Z.jsx)(Ws.A,{primary:"Logout",sx:{opacity:t&&!s?1:0}})]})]})]});return(0,Z.jsxs)(p.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,Z.jsx)(_t,{}),(0,Z.jsx)(p.A,{component:"nav",sx:{width:s?sn:t?en:sn,flexShrink:0,position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,Z.jsx)(qs.Ay,{variant:"persistent",open:!0,sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:s?sn:t?en:sn,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,Z.jsx)(p.A,{component:"main",sx:{flexGrow:1,p:{xs:0,sm:3},width:{xs:"calc(100% - 65px)",sm:`calc(100% - ${t?en:sn}px)`},ml:{xs:"65px",sm:`${t?en:sn}px`},mt:{xs:"64px",sm:"70px"},transition:e.transitions.create(["width","margin"],{easing:e.transitions.easing.sharp,duration:e.transitions.duration.leavingScreen})},children:(0,Z.jsxs)(d.BV,{children:[(0,Z.jsx)(d.qh,{path:"/",element:(0,Z.jsx)(d.C5,{to:"dashboard",replace:!0})}),(0,Z.jsx)(d.qh,{path:"dashboard",element:(0,Z.jsx)(ir,{})}),(0,Z.jsx)(d.qh,{path:"users/*",element:(0,Z.jsx)(Ar,{})}),(0,Z.jsx)(d.qh,{path:"stores/*",element:(0,Z.jsx)(kr,{})}),(0,Z.jsx)(d.qh,{path:"products",element:(0,Z.jsx)(Er,{})}),(0,Z.jsx)(d.qh,{path:"inventory",element:(0,Z.jsx)(Hr,{})}),(0,Z.jsx)(d.qh,{path:"orders",element:(0,Z.jsx)(Tr,{})}),(0,Z.jsx)(d.qh,{path:"payment-settings",element:(0,Z.jsx)(Br,{})}),(0,Z.jsx)(d.qh,{path:"categories",element:(0,Z.jsx)(Gr,{})}),(0,Z.jsx)(d.qh,{path:"fees",element:(0,Z.jsx)(Yr,{})}),(0,Z.jsx)(d.qh,{path:"location-codes",element:(0,Z.jsx)(Zr,{})}),(0,Z.jsx)(d.qh,{path:"pickup-addresses",element:(0,Z.jsx)(Xr,{})})]})})]})};var nn=t(27558),an=t(76030);const on=()=>{const[,e]=(0,x.useReducer)((e=>e+1),0),[s,t]=(0,x.useState)(null),[r,n]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[o,l]=(0,x.useState)(""),[d,c]=(0,x.useState)(""),[g,j]=(0,x.useState)("ALL"),[f,b]=(0,x.useState)(""),[v,I]=(0,x.useState)(!1),[S,w]=(0,x.useState)(0),[F,E]=(0,x.useState)({}),[L,$]=(0,x.useState)(!1),{userProfile:z,setUserProfile:R}=K();(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,y.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;a(s)}}catch(e){}})()}),[]);const{data:T,isLoading:W,error:q}=(0,u.I)({queryKey:["getUserProfile",i],queryFn:async()=>{const s=await C(k,{userId:i});return s?.getUserProfile&&(R(s.getUserProfile),setTimeout((()=>{e()}),200)),s},enabled:!!i,onError:e=>{}}),O=K.getState().userProfile||z||T?.getUserProfile,{data:B,isLoading:U,error:N,refetch:M}=(0,u.I)({queryKey:["driverDeliveries",O?.id],queryFn:()=>O?.id?C("\n query GetDeliveriesByDriver($driverId: Int!) {\n getDeliveriesByDriver(driverId: $driverId) {\n id\n orderId\n schedule\n pickedUpTime\n deliveredTime\n status\n comments\n order {\n addressId\n cancelMessage\n cancelledAt\n cancelledByUserId\n createdByUserId\n deliveryDate\n deliveryInstructions\n id\n paymentId\n status\n storeId\n totalAmount\n address {\n address\n }\n orderItems {\n edges {\n node {\n id\n inventoryId\n orderAmount\n orderId\n productId\n quantity\n updatedOrderitemsId\n product {\n categoryId\n description\n id\n image\n name\n }\n }\n }\n }\n }\n }\n }\n",{driverId:O.id}):null,enabled:!!O?.id}),_=(0,Is.n)({mutationFn:e=>C(P,{input:{orderId:e.orderId,status:e.status}}),onSuccess:()=>{M(),n(!1),b(""),I(!1)},onError:e=>{}}),V=(0,Is.n)({mutationFn:e=>C(D,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:O?.id}),onSuccess:()=>{M(),n(!1),b(""),I(!1)},onError:e=>{}}),H=e=>!!e?.edges?.length&&e.edges.every((e=>F[e.node.id])),G=x.useMemo((()=>B?.getDeliveriesByDriver?B.getDeliveriesByDriver.filter((e=>{if("ALL"!==g&&e.status!==g)return!1;if(d){const s=d.toLowerCase(),t=e.orderId.toString().includes(s),r=e.address?.toLowerCase().includes(s);return t||r}return!0})):[]),[B?.getDeliveriesByDriver,g,d]);if(W||U&&O?.id)return(0,Z.jsx)(A.A,{sx:{display:"block",mx:"auto",mt:4}});if(q)return(0,Z.jsx)(m.A,{color:"error",children:"Error fetching user profile!"});if(N&&O?.id)return(0,Z.jsx)(m.A,{color:"error",children:"Error fetching deliveries!"});const Y=B?.getDeliveriesByDriver||[],Q=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"}},J=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,Z.jsx)($r.A,{});case"PICKED_UP":return(0,Z.jsx)(Es.A,{});case"DELIVERED":return(0,Z.jsx)(Dr.A,{});case"CANCELLED":return(0,Z.jsx)(Lr.A,{});default:return null}},ee=e=>B?.getDeliveriesByDriver?B.getDeliveriesByDriver.filter((s=>s.status===e)).length:0;return(0,Z.jsxs)(h.A,{maxWidth:"lg",sx:{mt:4,mb:6},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:4,flexDirection:{xs:"column",sm:"row"},gap:{xs:2,sm:0}},children:[(0,Z.jsx)(m.A,{variant:"h4",fontWeight:"500",sx:{fontSize:{xs:"1.5rem",sm:"2rem"}},children:"Delivery Partner Dashboard"}),(0,Z.jsx)(se.A,{size:"small",placeholder:"Search orders...",value:d,onChange:e=>c(e.target.value),InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(pr.A,{fontSize:"small"})})},sx:{width:{xs:"100%",sm:250},"& .MuiOutlinedInput-root":{borderRadius:2}}})]}),(0,Z.jsx)(p.A,{sx:{mb:4},children:(0,Z.jsxs)(gt.A,{value:S,onChange:(e,s)=>{w(s),0===s?j("ALL"):1===s?j("READY_FOR_DELIVERY"):2===s?j("PICKED_UP"):3===s&&j("DELIVERED")},variant:"scrollable",scrollButtons:"auto",sx:{borderBottom:1,borderColor:"divider","& .MuiTab-root":{minWidth:120,textTransform:"none",fontSize:"0.875rem"}},children:[(0,Z.jsx)(jt.A,{label:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:["All Orders",(0,Z.jsx)(ns.A,{badgeContent:Y.length,color:"primary",sx:{ml:2}})]})}),(0,Z.jsx)(jt.A,{label:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:["Ready",(0,Z.jsx)(ns.A,{badgeContent:ee("READY_FOR_DELIVERY"),color:"primary",sx:{ml:2}})]})}),(0,Z.jsx)(jt.A,{label:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:["In Transit",(0,Z.jsx)(ns.A,{badgeContent:ee("PICKED_UP"),color:"info",sx:{ml:2}})]})}),(0,Z.jsx)(jt.A,{label:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:["Delivered",(0,Z.jsx)(ns.A,{badgeContent:ee("DELIVERED"),color:"success",sx:{ml:2}})]})})]})}),(0,Z.jsx)(je.Ay,{container:!0,spacing:{xs:2,sm:3},children:G.length>0?G.map((e=>(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,Z.jsx)(ye.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),n(!0),I(!1),b("")})(e),children:(0,Z.jsxs)(be.A,{sx:{flexGrow:1,p:{xs:2,sm:2.5}},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,Z.jsxs)(m.A,{variant:"h6",sx:{fontSize:{xs:"1rem",sm:"1.25rem"},fontWeight:500},children:["Order #",e.orderId]}),(0,Z.jsx)(Fe.A,{icon:J(e.status),label:e.status.replace(/_/g," "),color:Q(e.status),size:"small",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},height:{xs:24,sm:28},borderRadius:1.5}})]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,Z.jsx)(an.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,Z.jsx)(m.A,{variant:"body2",sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:new Date(e.schedule).toLocaleString()})]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,Z.jsx)(cs.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,Z.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,Z.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,Z.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,Z.jsx)(p.A,{sx:{mt:1},children:(0,Z.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,Z.jsx)(Lr.A,{fontSize:"small",sx:{mr:.5,flexShrink:0}}),(0,Z.jsxs)("span",{style:{lineHeight:1},children:['Cancellation Reason: "',e.order.cancelMessage,'"']})]})}),e.comments&&"CANCELLED"!==e.status&&(0,Z.jsx)(p.A,{sx:{mt:1},children:(0,Z.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,Z.jsxs)("span",{children:['"',e.comments,'"']})})})]})})},e.id))):(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(ae.A,{sx:{p:{xs:3,sm:4},borderRadius:2,textAlign:"center"},children:[(0,Z.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"No Deliveries Found"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:d||"ALL"!==g?"No deliveries match your search criteria.":"You have no deliveries assigned at this time."})]})})}),(0,Z.jsx)(et.A,{open:r,onClose:()=>n(!1),"aria-labelledby":"delivery-details-modal",children:(0,Z.jsx)(p.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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,Z.jsxs)(m.A,{variant:"h5",fontWeight:"500",sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"}},children:["Order #",s.orderId]}),(0,Z.jsx)(he.A,{edge:"end","aria-label":"close",onClick:()=>n(!1),size:"small",children:(0,Z.jsx)(js.A,{})})]}),(0,Z.jsx)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:(0,Z.jsx)(Fe.A,{icon:J(s.status),label:s.status.replace(/_/g," "),color:Q(s.status),sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}}})}),(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY ADDRESS"}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"flex-start"},children:[(0,Z.jsx)(cs.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,Z.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,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"SCHEDULED DELIVERY"}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Z.jsx)(an.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,Z.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(s.schedule).toLocaleString()})]})]}),s.pickedUpTime&&(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"PICKED UP"}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Z.jsx)(Es.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,Z.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(s.pickedUpTime).toLocaleString()})]})]}),s.deliveredTime&&(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERED"}),(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[(0,Z.jsx)(Dr.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,Z.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,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"error",gutterBottom:!0,children:"CANCELLATION REASON"}),(0,Z.jsxs)(p.A,{sx:{p:2,bgcolor:"error.lightest",borderRadius:1,borderLeft:"3px solid",borderColor:"error.main",display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Lr.A,{color:"error",sx:{flexShrink:0}}),(0,Z.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,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"COMMENTS"}),(0,Z.jsx)(p.A,{sx:{p:2,bgcolor:"rgba(0, 0, 0, 0.03)",borderRadius:1,borderLeft:"3px solid",borderColor:"primary.main"},children:(0,Z.jsx)(m.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:s.comments})})]}),s.photo&&(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY PROOF"}),(0,Z.jsx)("img",{src:s.photo,alt:"Delivery Proof",style:{width:"100%",borderRadius:4}})]}),L&&s?.order?.orderItems&&(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"VERIFY ITEMS TO BE PICKED UP"}),(0,Z.jsx)(ae.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,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:1,p:1,borderRadius:1,bgcolor:"background.default"},children:[(0,Z.jsx)(nn.A,{checked:!!F[s.id],onChange:()=>{return e=s.id,void E((s=>({...s,[e]:!s[e]})));var e},color:"primary"}),(0,Z.jsxs)(p.A,{sx:{ml:2,flex:1},children:[(0,Z.jsx)(m.A,{variant:"body2",fontWeight:"500",children:s.product.name}),(0,Z.jsxs)(m.A,{variant:"caption",color:"text.secondary",children:["Quantity: ",s.quantity," × $",s.orderAmount.toFixed(2)]})]})]},s.id)}))}),!H(s.order.orderItems)&&(0,Z.jsx)(ne.A,{severity:"warning",sx:{mt:1},children:"Please verify all items before updating status"})]}),(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"UPDATE STATUS"}),(0,Z.jsx)(Cs.A,{fullWidth:!0,sx:{mb:2},children:(0,Z.jsxs)(Oe.A,{value:o,onChange:e=>{const t=e.target.value;l(t),"READY_FOR_DELIVERY"===s?.status&&"READY_FOR_DELIVERY"!==t?($(!0),E({})):$(!1),I("CANCELLED"===t)},size:"small",children:[(0,Z.jsx)(Ae.A,{value:"PICKED_UP",children:"Picked Up"}),(0,Z.jsx)(Ae.A,{value:"DELIVERED",children:"Delivered"}),(0,Z.jsx)(Ae.A,{value:"CANCELLED",children:"Cancelled"})]})}),v&&(0,Z.jsx)(se.A,{fullWidth:!0,label:"Cancellation Reason",multiline:!0,rows:3,value:f,onChange:e=>b(e.target.value),sx:{mb:2},required:!0,size:"small"}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"flex-end",mt:3},children:(0,Z.jsx)(X.A,{onClick:()=>{s&&o&&("READY_FOR_DELIVERY"!==s.status||"READY_FOR_DELIVERY"===o||H(s.order.orderItems))&&("CANCELLED"===o?V.mutate({orderId:s.orderId,cancelMessage:f}):_.mutate({orderId:s.orderId,status:o}))},variant:"contained",color:"primary",disabled:("CANCELLED"===o?V.isPending||V.isLoading:_.isPending||_.isLoading)||o===s.orderStatus||"CANCELLED"===o&&!f||L&&!H(s.order.orderItems),startIcon:("CANCELLED"===o?V.isPending||V.isLoading:_.isPending||_.isLoading)?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,sx:{minWidth:120},children:("CANCELLED"===o?V.isPending||V.isLoading:_.isPending||_.isLoading)?"Updating...":"Update"})})]})})})]})};var ln=t(80669),dn=t(47922);const cn=[{text:"Dashboard",icon:(0,Z.jsx)(Jt.A,{}),path:Ks},{text:"Orders",icon:(0,Z.jsx)(we.A,{}),path:Ys},{text:"Delivery Partners",icon:(0,Z.jsx)(Es.A,{}),path:"/store_manager/delivery-partners"},{text:"Inventory",icon:(0,Z.jsx)(Xt.A,{}),path:"/store_manager/inventory"},{text:"Delivery Fees",icon:(0,Z.jsx)(dn.A,{}),path:"/store_manager/delivery-fees"},{text:"Location Codes",icon:(0,Z.jsx)(cs.A,{}),path:"/store_manager/location-codes"},{text:"Pickup Addresses",icon:(0,Z.jsx)(Es.A,{}),path:"/store_manager/pickup-addresses"},{text:"Payment Settings",icon:(0,Z.jsx)(dn.A,{}),path:"/store_manager/payment-settings"}],xn=()=>{const e=(0,ke.A)(),s=(0,qe.A)(e.breakpoints.down("sm")),t=(0,d.Zp)(),r=(0,d.zy)(),{open:n,setOpen:i}=x.useContext(un),a=(0,Z.jsxs)(p.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",justifyContent:n&&!s?"space-between":"center",p:2,minHeight:64},children:[n&&!s&&(0,Z.jsx)(m.A,{variant:"h6",noWrap:!0,component:"div",children:"Store Manager"}),!s&&(0,Z.jsx)(he.A,{onClick:()=>{i(!n)},children:n?(0,Z.jsx)(us.A,{}):(0,Z.jsx)(tr.A,{})})]}),(0,Z.jsx)(As.A,{}),(0,Z.jsx)(zs.A,{children:cn.map((e=>(0,Z.jsxs)(Rs.Ay,{button:!0,onClick:()=>{return s=e.path,void t(s);var s},selected:r.pathname===e.path,sx:{minHeight:48,justifyContent:n&&!s?"initial":"center",px:2.5,"&.Mui-selected":{backgroundColor:"primary.light","&:hover":{backgroundColor:"primary.light"}}},children:[(0,Z.jsx)(Ts.A,{sx:{minWidth:0,mr:n&&!s?3:"auto",justifyContent:"center",color:r.pathname===e.path?"primary.main":"inherit"},children:e.icon}),(0,Z.jsx)(Ws.A,{primary:e.text,sx:{opacity:n&&!s?1:0}})]},e.text)))})]});return(0,Z.jsx)(p.A,{component:"nav",sx:{width:s?65:n?240:65,flexShrink:0,position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,Z.jsx)(qs.Ay,{variant:"persistent",open:!0,sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:s?65:n?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})})},un=(0,x.createContext)({open:!0,setOpen:()=>{}}),mn=e=>{let{children:s}=e;const t=(0,ke.A)(),[r,n]=((0,qe.A)(t.breakpoints.down("sm")),(0,x.useState)(!0));return(0,Z.jsx)(un.Provider,{value:{open:r,setOpen:n},children:(0,Z.jsxs)(p.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,Z.jsx)(l.Ay,{}),(0,Z.jsx)(_t,{}),(0,Z.jsx)(xn,{}),(0,Z.jsx)(p.A,{component:"main",sx:{flexGrow:1,p:{xs:0,sm:3},width:{xs:"calc(100% - 65px)",sm:`calc(100% - ${r?240:65}px)`},ml:{xs:"65px",sm:(r?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,Z.jsx)(p.A,{sx:{width:"100%"},children:s})})]})})},hn=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:r}=K(),[n,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,g]=(0,x.useState)(null),[j,f]=(0,x.useState)(""),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)(""),[w,P]=(0,x.useState)(""),[F,E]=(0,x.useState)(""),[D,L]=(0,x.useState)(""),[$,z]=(0,x.useState)(""),[R,T]=(0,x.useState)(""),[W,q]=(0,x.useState)(""),[O,B]=(0,x.useState)(!1),[U,N]=(0,x.useState)(10),[M,_]=(0,x.useState)(""),[V,H]=(0,x.useState)([]),[G,Y]=(0,x.useState)(!1),[Q,J]=((0,x.useRef)(null),(0,x.useState)(0)),[ee,te]=(0,x.useState)(10),[re,ie]=(0,x.useState)(!0),[oe,le]=(0,x.useState)(null),[de,ce]=(0,x.useState)({open:!1,message:"",severity:"success"}),[ue,me]=(0,x.useState)([]),[pe,ge]=(0,x.useState)(!0),[ye,fe]=(0,x.useState)([]),[be,ve]=(0,x.useState)(!1);(0,x.useEffect)((()=>{let e=!0;return(async()=>{try{const t=await(0,rt.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 C(k,{userId:e})},enabled:!!e});(0,x.useEffect)((()=>{Ie?.getUserProfile&&!t&&r(Ie.getUserProfile)}),[Ie,t,r]);const{data:we,isLoading:Pe,error:ke,refetch:Ee}=(0,u.I)({queryKey:["storeWithInventory",t?.id],queryFn:async()=>t?.id?C("\n query GetStoreWithInventory($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n address\n description\n disabled\n email\n isActive\n mobile\n pincodes\n radius\n tnc\n storeDeliveryFee\n taxPercentage\n displayField\n sectionHeaders\n images\n codEnabled\n whatsappNumber\n inventory {\n edges {\n node {\n id\n storeId\n productId\n quantity\n price\n measurement\n unit\n isAvailable\n isListed\n updatedAt\n product {\n id\n name\n description\n category {\n id\n name\n }\n image\n }\n }\n }\n }\n }\n }\n",{managerId:t.id}):null,enabled:!!t?.id}),De=we?.storesByManager?.[0]||null,Le=De?.inventory?.edges?.map((e=>e.node))||[],$e=we?.products||[],{data:ze,isLoading:Re}=(0,u.I)({queryKey:["storeSquareStatus",De?.id],queryFn:()=>C("\n query StoreSquareStatus($storeId: Int!) {\n storeSquareStatus(storeId: $storeId) {\n storeId\n storeName\n isConnected\n }\n }\n",{storeId:De?.id}),enabled:!!De?.id}),Te=ze?.storeSquareStatus?.isConnected||!1;(0,x.useEffect)((()=>{if($e.length)if(""===M.trim())H($e);else{const e=$e.filter((e=>e.name.toLowerCase().includes(M.toLowerCase())));H(e)}}),[M,$e]);const We=(0,Is.n)({mutationFn:e=>C("\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:()=>{ce({open:!0,message:"Store updated successfully",severity:"success"}),le(null),Ee()},onError:e=>{ce({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),qe=()=>{le(null),me([]),fe([]),ge(!0)};return Se||Pe||re||!De?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})})}):ke?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4},children:(0,Z.jsxs)(ne.A,{severity:"error",children:["Error loading store data: ",ke.message]})})}):De||re?(0,Z.jsx)(mn,{children:(0,Z.jsxs)(h.A,{sx:{mb:4},children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Manager Dashboard"}),(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,Z.jsx)(m.A,{variant:"h5",children:"Store Information"}),(0,Z.jsx)(X.A,{variant:"outlined",startIcon:(0,Z.jsx)(hr.A,{}),onClick:()=>{De&&(le(De),me(De.sectionHeaders||[]),fe(De.images||[]),ge(De.isActive))},sx:{textTransform:"none"},children:"Edit Store"})]}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Name:"})," ",De.name]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Address:"})," ",De.address]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Delivery Radius:"})," ",De.radius||"Not set"," ",De.radius?"mi":""]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Delivery Fee:"})," $",De.storeDeliveryFee?.toFixed(2)||"0.00"]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Tax Rate:"})," ",De.taxPercentage?.toFixed(1)||"0.0","%"]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Total Products:"})," ",Le.filter((e=>e.isListed)).length]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Display Field:"})," ",De.displayField]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Square Payment:"})," ",(0,Z.jsx)(Fe.A,{size:"small",label:Te?"Connected":"Not Connected",color:Te?"success":"default"})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Cash on Delivery:"})," ",(0,Z.jsx)(Fe.A,{size:"small",label:De?.codEnabled?"Enabled":"Disabled",color:De?.codEnabled?"success":"default"})]})}),De.whatsappNumber&&(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"WhatsApp:"})," ",De.whatsappNumber]})}),De.description&&(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Description:"})," ",De.description]})}),De.pincodes&&De.pincodes.length>0&&(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:[(0,Z.jsx)("strong",{children:"Delivery Pincodes:"})," ",De.pincodes.join(", ")]})}),De.sectionHeaders&&De.sectionHeaders.length>0&&(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:(0,Z.jsx)("strong",{children:"Section Headers:"})}),(0,Z.jsx)(p.A,{sx:{pl:2},children:De.sectionHeaders.map(((e,s)=>(0,Z.jsxs)(m.A,{variant:"body2",sx:{mb:1},children:["• ",e]},s)))})]})]})]}),(0,Z.jsxs)(Qe.A,{open:!!oe,onClose:qe,maxWidth:"md",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Rt.A,{}),(0,Z.jsx)(m.A,{variant:"h6",children:"Edit Store"})]})}),(0,Z.jsxs)("form",{onSubmit:e=>{if(e.preventDefault(),!oe)return;const s=new FormData(e.target),t=s.get("pincodes"),r=t?t.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],n={storeId:oe.id,name:s.get("name"),address:s.get("address"),email:s.get("email"),mobile:s.get("mobile")||null,radius:parseFloat(s.get("radius")),isActive:"true"===s.get("isActive"),description:s.get("description")||null,pincodes:r,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:ye,whatsappNumber:s.get("whatsappNumber")||null};We.mutate(n)},children:[(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"name",label:"Store Name",defaultValue:oe?.name,required:!0,fullWidth:!0})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"email",label:"Email",type:"email",defaultValue:oe?.email,required:!0,fullWidth:!0})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"mobile",label:"Mobile Number",defaultValue:oe?.mobile,fullWidth:!0})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"address",label:"Address",defaultValue:oe?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:oe?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:oe?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:"$"})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:oe?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,Z.jsx)(xe.A,{position:"end",children:"%"})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:oe?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"description",label:"Description",defaultValue:oe?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"tnc",label:"Terms & Conditions",defaultValue:oe?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{name:"whatsappNumber",label:"WhatsApp Support Number",placeholder:"+1234567890",defaultValue:oe?.whatsappNumber,fullWidth:!0,helperText:"Include country code. Optional."})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{name:"displayField",label:"Display Field",defaultValue:oe?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,Z.jsxs)(p.A,{sx:{mb:2},children:[ue.map(((e,s)=>(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,Z.jsx)(se.A,{fullWidth:!0,label:`Question ${s+1}`,value:e,onChange:e=>((e,s)=>{me((t=>{const r=[...t];return r[e]=s,r}))})(s,e.target.value),placeholder:"Enter question text",inputProps:{"aria-label":`Question ${s+1}`}}),(0,Z.jsx)(he.A,{color:"error",onClick:()=>(e=>{me((s=>s.filter(((s,t)=>t!==e))))})(s),sx:{alignSelf:"center"},"aria-label":"Remove question",children:(0,Z.jsx)(fr.A,{})})]},s))),(0,Z.jsx)(X.A,{startIcon:(0,Z.jsx)(Ce.A,{}),onClick:()=>{me((e=>[...e,""]))},variant:"outlined",sx:{mt:1},"aria-label":"Add question",children:"Add Question"})]})]}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Images / Offers Banner"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{mb:2},children:[(0,Z.jsx)("input",{accept:"image/*",style:{display:"none"},id:"edit-store-image-upload",type:"file",onChange:e=>{const s=e.target.files[0];s&&(async e=>{if(e&&oe?.id){ve(!0);try{const s=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",t=await(0,y.$)(),r=t.tokens?.accessToken?.toString(),n={"Content-Type":"application/json"};r&&(n.Authorization=`Bearer ${r}`);const i=await fetch(`${s}/s3/generate-store-upload-url?store_id=${oe.id}&file_name=${encodeURIComponent(e.name)}`,{method:"GET",headers:n});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=a.split("?")[0];fe((e=>[...e,d])),ce({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){ce({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{ve(!1)}}})(s),e.target.value=""}}),(0,Z.jsx)("label",{htmlFor:"edit-store-image-upload",children:(0,Z.jsx)(X.A,{variant:"outlined",component:"span",startIcon:be?(0,Z.jsx)(A.A,{size:16}):(0,Z.jsx)(ln.A,{}),disabled:be,sx:{mb:2},children:be?"Uploading...":"Upload Image"})}),ye.length>0&&(0,Z.jsx)(p.A,{sx:{display:"flex",flexWrap:"wrap",gap:2},children:ye.map(((e,s)=>(0,Z.jsxs)(p.A,{sx:{position:"relative",width:150,height:150},children:[(0,Z.jsx)("img",{src:e,alt:`Store image ${s+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,Z.jsx)(he.A,{size:"small",color:"error",onClick:()=>(e=>{fe((s=>s.filter(((s,t)=>t!==e))))})(s),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,Z.jsx)(fr.A,{fontSize:"small"})})]},s)))})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(m.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,children:[(0,Z.jsx)(ur.A,{children:"Store Status"}),(0,Z.jsxs)(Oe.A,{name:"isActive",label:"Store Status",value:pe,onChange:e=>{ge(e.target.value)},children:[(0,Z.jsx)(Ae.A,{value:!0,children:"Active"}),(0,Z.jsx)(Ae.A,{value:!1,children:"Inactive"})]})]})})]})}),(0,Z.jsxs)(Xe.A,{sx:{p:3,pt:0},children:[(0,Z.jsx)(X.A,{onClick:qe,children:"Cancel"}),(0,Z.jsx)(X.A,{type:"submit",variant:"contained",disabled:We.isPending,startIcon:We.isPending?(0,Z.jsx)(A.A,{size:20}):null,children:We.isPending?"Updating...":"Update Store"})]})]})]}),(0,Z.jsx)(mr.A,{open:de.open,autoHideDuration:6e3,onClose:()=>ce({...de,open:!1}),children:(0,Z.jsx)(ne.A,{onClose:()=>ce({...de,open:!1}),severity:de.severity,sx:{width:"100%"},children:de.message})})]})}):(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4},children:(0,Z.jsx)(ne.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})};var pn=t(79381),An=t(29682),gn=t(92183),jn=t(69149),yn=t(51365);const fn=()=>{const[,e]=(0,x.useReducer)((e=>e+1),0),[s,t]=(0,x.useState)(null),[r,n]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[o,l]=(0,x.useState)(null),[d,c]=(0,x.useState)(""),[g,j]=(0,x.useState)(!1),[f,b]=(0,x.useState)(null),[v,I]=(0,x.useState)(null),[S,w]=(0,x.useState)({open:!1,title:"",message:"",onConfirm:null}),P=(0,ke.A)(),F=(0,qe.A)(P.breakpoints.down("sm")),{userProfile:E,setUserProfile:L}=K();(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,y.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;t(s)}}catch(e){}})()}),[]);const{data:$,isLoading:z,error:R}=(0,u.I)({queryKey:["getUserProfile",s],queryFn:async()=>{const t=await C(k,{userId:s});return t?.getUserProfile&&(L(t.getUserProfile),setTimeout((()=>{e()}),200)),t},enabled:!!s,onError:e=>{}}),T=K.getState().userProfile||E||$?.getUserProfile,{data:W,isLoading:q,error:O,refetch:B}=(0,u.I)({queryKey:["userOrders",T?.id],queryFn:()=>C("\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:T.id}),enabled:!!T?.id}),U=(0,Is.n)({mutationFn:e=>C(D,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:T.id}),onSuccess:()=>{B(),M(),c("")}}),N=(0,Is.n)({mutationFn:e=>C("\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:()=>{B()}}),M=()=>{n(!1),a(null)},_=e=>{l(o===e?null:e)},V=(e,s,t)=>{if(!s||!s.id)return;const r=t-s.quantity,n=(s.product.inventoryItems?.edges[0]?.node?.price||0)*r,i=e.totalAmount+n,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:r}],totalAmount:i,orderTotalAmount:o,taxAmount:a};N.mutate(l)},H=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))},G=()=>{b(null),I(null)},Y=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e);if(z||q&&T?.id)return(0,Z.jsx)(A.A,{sx:{display:"block",mx:"auto",mt:4}});if(R)return(0,Z.jsx)(m.A,{color:"error",children:"Error fetching user profile!"});if(O&&T?.id)return(0,Z.jsx)(m.A,{color:"error",children:"Error fetching orders!"});const Q=[...W?.getOrdersByUser||[]].sort(((e,s)=>s.id-e.id));return(0,Z.jsxs)(h.A,{maxWidth:"xl",sx:{mt:4,px:{xs:1,sm:2,md:3}},children:[(0,Z.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,Z.jsx)(m.A,{children:"No orders found!"}):(0,Z.jsx)(ar.A,{component:ae.A,sx:{mt:2,overflowX:"auto","& .MuiTableCell-root":{px:{xs:1,sm:2},py:{xs:1.5,sm:2},whiteSpace:"nowrap"}},children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{sx:{display:{xs:"none",md:"table-cell"}},children:"Order ID"}),(0,Z.jsx)(cr.A,{children:"Address"}),(0,Z.jsx)(cr.A,{children:"Status"}),(0,Z.jsx)(cr.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Total"}),(0,Z.jsx)(cr.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Delivery Date"}),(0,Z.jsx)(cr.A,{children:"Bill"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:Q.map((e=>(0,Z.jsxs)(x.Fragment,{children:[(0,Z.jsxs)(dr.A,{onClick:()=>_(e.id),sx:{cursor:"pointer"},children:[(0,Z.jsx)(cr.A,{sx:{display:{xs:"none",md:"table-cell"}},children:e.id}),(0,Z.jsxs)(cr.A,{children:[F&&(0,Z.jsxs)(m.A,{variant:"caption",sx:{fontWeight:700,color:"primary.main",display:"block",mb:.5},children:["Order #",e.id]}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"PICKUP"===e.type?(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Us.A,{fontSize:"small"}),e.pickupAddress?.address||"Pickup location not specified"]}):(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Es.A,{fontSize:"small"}),e.address?.address||"No address provided"]})})]}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:Rr.find((s=>s.value===e.status))?.label||e.status,size:F?"small":"medium",color:Rr.find((s=>s.value===e.status))?.color||"default"})}),(0,Z.jsxs)(cr.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:["$",e.totalAmount.toFixed(2)]}),(0,Z.jsx)(cr.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:e.deliveryDate?new Date(e.deliveryDate).toLocaleDateString():"N/A"}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(p.A,{sx:{display:"flex",gap:1},children:(0,Z.jsx)(Ie.A,{title:"Download Bill",children:(0,Z.jsx)(he.A,{size:"small",onClick:s=>{s.stopPropagation(),(async e=>{if(!g)try{j(!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{j(!1)}})(e.id)},children:(0,Z.jsx)(pn.A,{})})})})}),(0,Z.jsx)(cr.A,{children:(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,Z.jsx)(X.A,{variant:"contained",color:"error",size:F?"small":"medium",onClick:s=>{var t;s.stopPropagation(),t=e.id,a(t),n(!0)},disabled:!Y(e.status),children:"Cancel"}),(0,Z.jsx)(he.A,{onClick:s=>{s.stopPropagation(),_(e.id)},size:"small",children:o===e.id?(0,Z.jsx)(An.A,{}):(0,Z.jsx)(gn.A,{})})]})})]}),(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{style:{paddingBottom:0,paddingTop:0},colSpan:7,children:(0,Z.jsx)(Be.A,{in:o===e.id,timeout:"auto",unmountOnExit:!0,children:(0,Z.jsx)(p.A,{sx:{margin:{xs:1,sm:2}},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.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,Z.jsx)(Us.A,{})," Order Items"]}),(0,Z.jsx)(ae.A,{sx:{p:{xs:1.5,sm:2}},children:e.orderItems?.edges?.length>0?(0,Z.jsx)(je.Ay,{container:!0,spacing:{xs:1,sm:2},children:H(e.orderItems).map((s=>{const t=s.product.inventoryItems?.edges[0]?.node,r=((e,s)=>{const t=new Map;s.forEach((e=>{let{node:s}=e;t.set(s.id,s)}));const r=[e];let n=e.id;for(;;){const e=Array.from(t.values()).find((e=>e.updatedOrderitemsId===n));if(!e)break;r.push(e),n=e.id}return r.reverse()})(s,e.orderItems.edges);return(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(ye.A,{variant:"outlined",sx:{p:{xs:1.5,sm:2},"&:hover":{bgcolor:"grey.50"}},children:[(0,Z.jsxs)(je.Ay,{container:!0,spacing:{xs:1,sm:2},alignItems:"center",children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,sm:4,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",fontWeight:600,sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:s.product.name}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:500,children:s.product.category.name}),r.length>1&&(0,Z.jsxs)(m.A,{variant:"caption",color:"primary",sx:{display:"block",mt:.5},children:[r.length-1," previous version",r.length>2?"s":""]})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:6,sm:2,children:[(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Unit Price"}),(0,Z.jsxs)(m.A,{variant:"body1",fontWeight:500,children:["$",t?.price.toFixed(2)]}),t&&(0,Z.jsxs)(m.A,{variant:"caption",color:"text.secondary",fontWeight:500,children:[t.measurement," ",t.unit]})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:6,sm:2,children:[(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Quantity"}),f===s.id?(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(se.A,{type:"number",size:"small",value:v,onChange:e=>I(parseInt(e.target.value)||0),inputProps:{min:0},sx:{width:"80px"}}),(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:.5},children:[(0,Z.jsx)(he.A,{size:"small",color:"primary",onClick:()=>((e,s)=>{0===v?w({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{V(e,s,0),b(null),I(null),w({open:!1,title:"",message:"",onConfirm:null})}}):v>0&&(V(e,s,v),b(null),I(null))})(e,s),disabled:null===v||v<0,children:(0,Z.jsx)(jn.A,{fontSize:"small"})}),(0,Z.jsx)(he.A,{size:"small",color:"error",onClick:G,children:(0,Z.jsx)(js.A,{fontSize:"small"})})]})]}):(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(m.A,{variant:"body1",fontWeight:500,children:s.quantity}),Y(e.status)&&(0,Z.jsx)(he.A,{size:"small",onClick:()=>{return b((e=s).id),void I(e.quantity);var e},children:(0,Z.jsx)(hr.A,{fontSize:"small"})})]})]}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:4,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",sm:"flex-end"},alignItems:"center",gap:1,mt:{xs:1,sm:0}},children:[(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Total:"}),(0,Z.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,Z.jsx)(he.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:()=>{V(e,s,0),w({open:!1,title:"",message:"",onConfirm:null})}})})(e,s)},children:(0,Z.jsx)(fr.A,{fontSize:"small"})})]})})]}),r.length>1&&(0,Z.jsxs)(p.A,{sx:{mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[(0,Z.jsxs)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(yn.A,{fontSize:"small"}),"Order Change History (",r.length-1," ","changes)"]}),(0,Z.jsx)(p.A,{sx:{pl:2},children:r.slice(0,-1).map(((e,s)=>(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1.5,borderRadius:1,mb:1},children:[(0,Z.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"120px",fontWeight:500},children:["Change ",s+1]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:3},children:[(0,Z.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,Z.jsxs)(m.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount: $",e.orderAmount.toFixed(2)]})]})]},e.id)))})]})]})},s.id)}))}):(0,Z.jsx)(p.A,{sx:{textAlign:"center",py:3,color:"text.secondary"},children:(0,Z.jsx)(m.A,{fontWeight:500,children:"No items found for this order."})})})]}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(ae.A,{sx:{p:{xs:1.5,sm:2},mb:3},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,md:6,children:[(0,Z.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,Z.jsx)(pn.A,{})," Order Details"]}),(0,Z.jsxs)(p.A,{sx:{pl:1},children:[e.customOrder&&(0,Z.jsxs)(p.A,{sx:{mb:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Custom Order Instructions"}),(0,Z.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,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Subtotal"}),(0,Z.jsxs)(m.A,{fontWeight:500,children:["$",e.totalAmount?e.totalAmount.toFixed(2):"0.00"]})]}),void 0!==e.deliveryFee&&(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Fee"}),(0,Z.jsxs)(m.A,{fontWeight:500,children:["$",e.deliveryFee?e.deliveryFee.toFixed(2):"0.00"]})]}),void 0!==e.taxAmount&&(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tax"}),(0,Z.jsxs)(m.A,{fontWeight:500,children:["$",e.taxAmount?e.taxAmount.toFixed(2):"0.00"]})]}),void 0!==e.tipAmount&&(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tip"}),(0,Z.jsxs)(m.A,{fontWeight:500,children:["$",e.tipAmount?e.tipAmount.toFixed(2):"0.00"]})]}),(0,Z.jsx)(As.A,{sx:{my:1}}),(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Total Amount"}),(0,Z.jsxs)(m.A,{variant:"subtitle1",color:"primary",fontWeight:700,children:["$",e.orderTotalAmount?e.orderTotalAmount.toFixed(2):"0.00"]})]})]})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,md:6,children:[(0,Z.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,Z.jsx)(Es.A,{})," Delivery Information"]}),(0,Z.jsxs)(p.A,{sx:{pl:1},children:[(0,Z.jsxs)(p.A,{sx:{mb:1},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"PICKUP"===e.type?"Pickup Location":"Delivery Address"}),(0,Z.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,Z.jsxs)(p.A,{sx:{mb:1},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Instructions"}),(0,Z.jsx)(m.A,{variant:"body2",fontWeight:500,children:e.deliveryInstructions})]}),e.deliveryDate&&(0,Z.jsxs)(p.A,{sx:{mb:1},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,children:"Expected Delivery Date"}),(0,Z.jsx)(m.A,{variant:"body2",fontWeight:500,children:new Date(e.deliveryDate).toLocaleDateString()})]}),e.cancelMessage&&(0,Z.jsxs)(p.A,{sx:{mb:1},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"error",fontWeight:700,children:"Cancellation Reason"}),(0,Z.jsx)(m.A,{variant:"body2",color:"error",fontWeight:500,children:e.cancelMessage})]})]})]})]})})})]})})})})})]},e.id)))})]})}),(0,Z.jsxs)(Qe.A,{open:r,onClose:M,fullWidth:!0,maxWidth:"sm",children:[(0,Z.jsx)(Ze.A,{children:"Cancel Order"}),(0,Z.jsxs)(Je.A,{children:[(0,Z.jsx)(Wr.A,{gutterBottom:!0,children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,Z.jsx)(se.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:r&&!d.trim(),sx:{mt:2}})]}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:M,color:"primary",children:"No, Keep Order"}),(0,Z.jsx)(X.A,{onClick:()=>{i&&d.trim()&&U.mutate({orderId:i,cancelMessage:d.trim()})},color:"error",variant:"contained",disabled:!d.trim()||U.isPending,startIcon:U.isPending?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:U.isPending?"Cancelling...":"Yes, Cancel Order"})]})]}),(0,Z.jsxs)(Qe.A,{open:S.open,onClose:()=>w({open:!1,title:"",message:"",onConfirm:null}),children:[(0,Z.jsx)(Ze.A,{children:S.title}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(Wr.A,{children:S.message})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>w({open:!1,title:"",message:"",onConfirm:null}),color:"primary",children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:S.onConfirm,color:"error",variant:"contained",children:"Remove"})]})]})]})};var bn=t(55629),vn=t(45402),In=t(55764);const Sn=()=>{const{userProfile:e,setUserProfile:s,fetchUserProfile:t,isProfileLoading:r,profileError:n}=K(),i=(0,d.Zp)(),[a,o]=(0,x.useState)(0),[l,c]=(0,x.useState)(null),[u,g]=(0,x.useState)(null),[j,f]=(0,x.useState)(!1),b=window.location.origin,{addresses:v,selectedAddressId:I,setSelectedAddressId:S,fetchAddresses:C,isLoading:w,createAddress:P,updateAddress:k,deleteAddress:F}=Y(),[E,D]=(0,x.useState)(!1),[L,$]=(0,x.useState)(null),[z,R]=(0,x.useState)(""),[T,W]=(0,x.useState)(!1),[q,O]=(0,x.useState)(!1),[B,U]=(0,x.useState)(!1),[N,M]=(0,x.useState)({open:!1,message:"",severity:"success"}),[_,V]=(0,x.useState)(!1),[H,G]=(0,x.useState)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,y.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;g(s),await t(s)}}catch(e){}})()}),[t]);const Q=e||l;(0,x.useEffect)((()=>{Q?.id&&C(Q.id)}),[Q?.id,C]);const J=async()=>{try{await(0,Ns.C)(),i("/")}catch(e){}},ee=`${b}/signup?referredby=${e?.referralId}`,te=async()=>{try{await navigator.clipboard.writeText(ee),f(!0),setTimeout((()=>f(!1)),2e3)}catch(e){}};if(r)return(0,Z.jsx)(h.A,{children:(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:[(0,Z.jsx)(A.A,{}),(0,Z.jsx)(m.A,{sx:{ml:2},children:"Loading profile..."})]})});if(n)return(0,Z.jsxs)(h.A,{children:[(0,Z.jsxs)(ne.A,{severity:"error",sx:{mt:4},children:["Error loading profile: ",n]}),(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>t(),sx:{mt:2},children:"Retry"})]});if(!e)return(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(ne.A,{severity:"warning",sx:{mt:4},children:"No profile data available. Please try again."}),(0,Z.jsx)(X.A,{variant:"contained",onClick:async()=>{try{const e=await(0,y.$)();if(e?.tokens?.idToken){const s=e.tokens.idToken.payload.sub;await t(s)}}catch(e){}},sx:{mt:2},children:"Load Profile"})]});return(0,Z.jsxs)(h.A,{maxWidth:"xl",sx:{py:{xs:1,sm:4},px:{xs:.5,sm:2}},children:[(0,Z.jsxs)(p.A,{sx:{display:{xs:"block",md:"flex"},gap:{xs:0,md:3}},children:[(0,Z.jsxs)(p.A,{sx:{width:{xs:"100%",md:280},mb:{xs:2,md:0}},children:[(0,Z.jsxs)(ae.A,{elevation:0,sx:{borderRadius:2,overflow:"hidden",boxShadow:1,mb:0,display:{xs:"none",md:"block"}},children:[(0,Z.jsx)(p.A,{sx:{p:2,bgcolor:"primary.main",color:"white",textAlign:"left"},children:(0,Z.jsx)(m.A,{variant:"h6",sx:{fontSize:"1.25rem"},children:"My Account"})}),(0,Z.jsx)(zs.A,{component:"nav",sx:{pt:0},children:[{label:"Profile",icon:(0,Z.jsx)(Os.A,{}),idx:0},{label:"Addresses",icon:(0,Z.jsx)(cs.A,{}),idx:1},{label:"Settings",icon:(0,Z.jsx)(In.A,{}),idx:2}].map((e=>(0,Z.jsxs)(kt.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,Z.jsx)(Ts.A,{sx:{minWidth:0,mr:2,justifyContent:"center"},children:x.cloneElement(e.icon,{color:a===e.idx?"primary":"inherit"})}),(0,Z.jsx)(Ws.A,{primary:e.label})]},e.label)))})]}),(0,Z.jsxs)(ae.A,{elevation:0,sx:{borderRadius:0,overflow:"hidden",boxShadow:0,mb:1,display:{xs:"block",md:"none"}},children:[(0,Z.jsx)(p.A,{sx:{p:2,bgcolor:"primary.main",color:"white",textAlign:"center"},children:(0,Z.jsx)(m.A,{variant:"h6",sx:{fontSize:"1.1rem"},children:"My Account"})}),(0,Z.jsx)(zs.A,{component:"nav",sx:{pt:0,display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center"},children:[{label:"Profile",icon:Os.A,idx:0},{label:"Addresses",icon:cs.A,idx:1},{label:"Settings",icon:In.A,idx:2}].map((e=>(0,Z.jsx)(kt.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,Z.jsx)(Ts.A,{sx:{minWidth:0,mr:0,justifyContent:"center"},children:(0,Z.jsx)(e.icon,{sx:{fontSize:28,color:a===e.idx?"primary.main":"text.secondary"}})})},e.label)))})]})]}),(0,Z.jsx)(p.A,{sx:{flexGrow:1,width:{xs:"100%",md:"auto"}},children:(0,Z.jsxs)(p.A,{sx:{height:"100%"},children:[0===a&&(0,Z.jsx)(p.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,Z.jsx)(ye.A,{sx:{height:"100%",width:{xs:"100%",sm:"auto"},p:{xs:1,sm:0},boxShadow:{xs:2,sm:1}},children:(0,Z.jsxs)(be.A,{sx:{p:{xs:1,sm:2}},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"center",sm:"center"},mb:3,gap:{xs:2,sm:0}},children:[(0,Z.jsx)(Ft.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,Z.jsxs)(p.A,{sx:{textAlign:{xs:"center",sm:"left"},width:"100%"},children:[(0,Z.jsxs)(m.A,{variant:"h5",gutterBottom:!0,sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"},fontWeight:700},children:[e?.firstName," ",e?.lastName]}),(0,Z.jsxs)(ps.A,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",flexWrap:"wrap",sx:{rowGap:1,justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,Z.jsxs)(p.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,Z.jsx)(Ir.A,{sx:{mr:1,color:"primary.main",fontSize:22}}),(0,Z.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,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",bgcolor:"rgba(76,205,196,0.08)",px:1.5,py:.5,borderRadius:2,justifyContent:"center"},children:[(0,Z.jsx)(vr.A,{sx:{mr:1,color:"secondary.main",fontSize:22}}),(0,Z.jsx)(m.A,{sx:{color:"text.primary",fontWeight:500,fontSize:{xs:"1.1rem",sm:"1.08rem"}},children:e.mobile})]})]})]})]}),(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,sx:{textAlign:{xs:"center",sm:"left"},fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:"Referral Program"}),(0,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"stretch",sm:"center"},gap:2},children:[(0,Z.jsx)(se.A,{fullWidth:!0,value:ee,InputProps:{readOnly:!0,endAdornment:(0,Z.jsx)(Ie.A,{title:j?"Copied!":"Copy referral link",children:(0,Z.jsx)(he.A,{onClick:te,children:(0,Z.jsx)(bn.A,{})})})},sx:{mb:{xs:1,sm:0}}}),(0,Z.jsx)(X.A,{variant:"contained",startIcon:(0,Z.jsx)(vn.A,{}),onClick:te,sx:{width:{xs:"100%",sm:"auto"},py:1},children:"Share"})]})]})})}),1===a&&(0,Z.jsx)(p.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=[...v].sort(((e,s)=>(s.isPrimary?1:0)-(e.isPrimary?1:0)));return(0,Z.jsx)(ye.A,{sx:{height:"100%"},children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h6",children:"My Addresses"}),(0,Z.jsx)(X.A,{variant:"contained",startIcon:(0,Z.jsx)(Ce.A,{}),onClick:()=>D(!0),children:"Add Address"})]}),w?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",p:4},children:(0,Z.jsx)(A.A,{})}):e.length>0?(0,Z.jsx)(je.Ay,{container:!0,spacing:2,children:e.map((e=>(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:6,children:(0,Z.jsxs)(ae.A,{elevation:2,sx:{p:2,position:"relative",border:e.isPrimary?"2px solid":"1px solid",borderColor:e.isPrimary?"primary.main":"divider"},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",color:"primary",children:e.isPrimary?"Primary Address":"Secondary Address"}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(he.A,{size:"small",onClick:()=>(e=>{$(e),R(e.address),W(e.isPrimary),D(!0)})(e),children:(0,Z.jsx)(hr.A,{fontSize:"small"})}),(0,Z.jsx)(he.A,{size:"small",onClick:()=>{return s=e.id,G(s),void V(!0);var s},children:(0,Z.jsx)(fr.A,{fontSize:"small"})})]})]}),(0,Z.jsx)(m.A,{variant:"body2",children:e.address})]})},e.id)))}):(0,Z.jsx)(ne.A,{severity:"info",sx:{mt:2},children:"You don't have any addresses yet. Add one to get started!"})]})})})()}),2===a&&(0,Z.jsx)(p.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,Z.jsx)(ye.A,{sx:{height:"100%"},children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Account Settings"}),(0,Z.jsxs)(ps.A,{spacing:3,children:[(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Notification Preferences"}),(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(nn.A,{defaultChecked:!0}),label:"Email notifications for orders"}),(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(nn.A,{defaultChecked:!0}),label:"SMS notifications for delivery updates"})]}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Privacy Settings"}),(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(nn.A,{defaultChecked:!0}),label:"Share order history with delivery partners"})]}),(0,Z.jsx)(p.A,{children:(0,Z.jsx)(X.A,{variant:"outlined",color:"error",startIcon:(0,Z.jsx)(rr.A,{}),onClick:J,sx:{mt:2},children:"Logout"})})]})]})})})]})})]}),(0,Z.jsxs)(Qe.A,{open:E,onClose:()=>D(!1),fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:L?"Edit Address":"Add Address"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(ps.A,{spacing:2,mt:1,children:[(0,Z.jsx)(qt,{value:z,onChange:R,onValidAddress:U}),(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(nn.A,{checked:T,onChange:e=>W(e.target.checked)}),label:"Set as Primary Address"})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{D(!1),R(""),U(!1)},children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:async()=>{if(Q?.id){O(!0);try{if(!B)return;if(L)if(T){for(const e of v)e.id!==L.id&&e.isPrimary&&await k(e.id,e.address,!1);await k(L.id,z,!0),M({open:!0,message:"Address updated as primary",severity:"success"})}else{L.isPrimary&&1===v.filter((e=>e.isPrimary)).length?(await k(L.id,z,!0),M({open:!0,message:"At least one address must be primary",severity:"warning"})):(await k(L.id,z,!1),M({open:!0,message:"Address updated as secondary",severity:"success"}))}else if(0===v.length)await P(z,Q.id,!0),M({open:!0,message:"Address added successfully",severity:"success"});else if(T){for(const e of v)e.isPrimary&&await k(e.id,e.address,!1);await P(z,Q.id,!0),M({open:!0,message:"Address added as primary",severity:"success"})}else await P(z,Q.id,!1),M({open:!0,message:"Address added as secondary",severity:"success"});await C(Q.id),D(!1),$(null),R(""),W(!1),U(!1)}catch(e){M({open:!0,message:"Failed to save address. Please try again.",severity:"error"})}finally{O(!1)}}else M({open:!0,message:"Could not save address: user information not available",severity:"error"})},variant:"contained",disabled:!z||q||!B,children:q?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(A.A,{size:20,sx:{mr:1}})," Saving..."]}):"Save"})]})]}),(0,Z.jsxs)(Qe.A,{open:_,onClose:()=>V(!1),children:[(0,Z.jsx)(Ze.A,{children:"Delete Address"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(m.A,{children:"Are you sure you want to delete this address? This action cannot be undone."})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>V(!1),disabled:w,children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:async()=>{try{await F(H),M({open:!0,message:"Address deleted successfully",severity:"success"})}catch(e){M({open:!0,message:"Failed to delete address. Please try again.",severity:"error"})}finally{V(!1),G(null)}},color:"error",variant:"contained",disabled:w,startIcon:w?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:w?"Deleting...":"Delete"})]})]}),(0,Z.jsx)(mr.A,{open:N.open,autoHideDuration:3e3,onClose:()=>M({...N,open:!1}),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,Z.jsx)(ne.A,{onClose:()=>M({...N,open:!1}),severity:N.severity,sx:{width:"100%"},children:N.message})})]})},Cn=()=>{const e=(0,d.Zp)();return(0,Z.jsx)(h.A,{maxWidth:"md",children:(0,Z.jsx)(p.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,Z.jsx)(m.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,Z.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,Z.jsx)(X.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(Ks),children:"Go to Dashboard"})]})})})},wn=()=>{const e=(0,d.Zp)();return(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{maxWidth:"md",children:(0,Z.jsx)(p.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,Z.jsx)(m.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,Z.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,Z.jsx)(X.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(Ks),children:"Go to Dashboard"})]})})})})},Pn=e=>{let{open:s,onClose:t,selectedFee:r,onUpdate:n,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,l]=(0,x.useState)(a);(0,x.useEffect)((()=>{r?l({feeCurrency:r.feeCurrency||"",feeRate:r.feeRate?.toString()||"",limit:r.limit?.toString()||"",type:r.type?.toUpperCase()||"DELIVERY"}):s&&l(a)}),[r,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,Z.jsxs)(Qe.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:r?"Edit Fee":"Add New Fee"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(p.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Z.jsxs)(Cs.A,{fullWidth:!0,children:[(0,Z.jsx)(ur.A,{children:"Fee Type"}),(0,Z.jsxs)(Oe.A,{name:"type",value:o.type,onChange:d,label:"Fee Type",children:[(0,Z.jsx)(Ae.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,Z.jsx)(Ae.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,Z.jsx)(se.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:d,fullWidth:!0,placeholder:"e.g., USD"}),(0,Z.jsx)(se.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,Z.jsx)(se.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:t,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>{n({id:r?.id,...o,feeRate:parseFloat(o.feeRate),limit:parseFloat(o.limit)}),r||l(a)},disabled:i,startIcon:i?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},kn=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:r}=K(),[n,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,g]=(0,x.useState)(""),[j,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,rt.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await C("\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&&r(s.getUserProfile),s},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,u.I)({queryKey:["storeWithFees",t?.id],queryFn:()=>C("\n query GetStoreWithFees($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:t.id}),enabled:!!t?.id}),w=v?.storesByManager?.[0],{data:P,isLoading:k,error:F,refetch:E}=(0,u.I)({queryKey:["getFeesByStore",w?.id],queryFn:()=>C("\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:w?.id}),enabled:!!w?.id}),D=P?.getFeesByStore||[],L=(0,Is.n)({mutationFn:e=>C("\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(),o(!1),i(null),y("Fee updated successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error updating fee: ${e.message}`)}}),$=(0,Is.n)({mutationFn:e=>C("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{E(),d(!1),i(null),y("Fee deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error deleting fee: ${e.message}`)}}),z=(0,Is.n)({mutationFn:e=>C("\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:w?.id}}),onSuccess:()=>{E(),o(!1),i(null),y("Fee added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error adding fee: ${e.message}`)}});return b||I||k?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})})}):S||F?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4},children:(0,Z.jsxs)(ne.A,{severity:"error",children:["Error loading data: ",S?.message||F?.message]})})}):(0,Z.jsx)(mn,{children:(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Delivery Fees Management"}),j&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:j}),c&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:c}),(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",children:"Fees"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:z.isPending||z.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):(0,Z.jsx)(Ce.A,{}),onClick:()=>{i(null),o(!0)},disabled:z.isPending||z.isLoading,children:z.isPending||z.isLoading?"Adding...":"Add Fee"})]}),(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Type"}),(0,Z.jsx)(cr.A,{children:"Currency"}),(0,Z.jsx)(cr.A,{children:"Rate"}),(0,Z.jsx)(cr.A,{children:"Limit"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:D.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.type}),(0,Z.jsx)(cr.A,{children:e.feeCurrency}),(0,Z.jsx)(cr.A,{children:e.feeRate}),(0,Z.jsx)(cr.A,{children:e.limit}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||z.isPending||z.isLoading,children:(0,Z.jsx)(hr.A,{})}),(0,Z.jsx)(he.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||z.isPending||z.isLoading,children:(0,Z.jsx)(fr.A,{})})]})]},e.id)))})]})})]}),(0,Z.jsx)(Pn,{open:a,onClose:()=>{o(!1),i(null),g("")},selectedFee:n,onUpdate:e=>{n?L.mutate(e):z.mutate(e)},isLoading:L.isPending||L.isLoading||z.isPending||z.isLoading}),(0,Z.jsxs)(Qe.A,{open:l,onClose:()=>{d(!1),i(null),g("")},children:[(0,Z.jsx)(Ze.A,{children:"Delete Fee"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(m.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{d(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:n.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})})};var Fn=t(95952);const En=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:r}=K(),[n,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,g]=(0,x.useState)(null),[j,y]=(0,x.useState)("info");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,rt.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 C(k,{userId:e});return s?.getUserProfile&&r(s.getUserProfile),s},enabled:!!e}),{data:v,isLoading:I,error:S,refetch:w}=(0,u.I)({queryKey:["storeInfo",t?.id],queryFn:()=>C("\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}),P=v?.storesByManager?.[0],{data:F,isLoading:E,error:D,refetch:L}=(0,u.I)({queryKey:["storeSquareStatus",P?.id],queryFn:()=>C("\n query StoreSquareStatus($storeId: Int!) {\n storeSquareStatus(storeId: $storeId) {\n storeId\n storeName\n isConnected\n merchantId\n }\n }\n",{storeId:P?.id}),enabled:!!P?.id}),$=F?.storeSquareStatus,z=(0,Is.n)({mutationFn:e=>C("\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"),g(e.connectSquare?.message||"Failed to generate authorization URL"))},onError:e=>{y("error"),g(e.message||"Failed to initiate Square connection")}}),R=(0,Is.n)({mutationFn:e=>C("\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"),g("Square account disconnected successfully"),L()):(y("error"),g(e.disconnectSquare?.message||"Failed to disconnect Square"))},onError:e=>{i(!1),y("error"),g(e.message||"Failed to disconnect Square account")}}),T=(0,Is.n)({mutationFn:e=>C("\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"),g(e.toggleCod.codEnabled?"Cash on Delivery enabled successfully":"Cash on Delivery disabled successfully"),L(),w()):(y("error"),g("Failed to update COD settings"))},onError:e=>{y("error"),g(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"),g("Square account connected successfully"),L(),window.history.replaceState({},"","/store_manager/payment-settings")):t&&(y("error"),g(`OAuth error: ${decodeURIComponent(t)}`),window.history.replaceState({},"","/store_manager/payment-settings"))}),[L]),(0,x.useEffect)((()=>{if(c&&"success"===j){const e=setTimeout((()=>{g(null)}),5e3);return()=>clearTimeout(e)}}),[c,j]);const W=()=>{i(!1)},q=()=>{o(!1)};return b||I||E?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})})}):S||D?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4},children:(0,Z.jsxs)(ne.A,{severity:"error",children:["Error loading data: ",S?.message||D?.message]})})}):P?(0,Z.jsx)(mn,{children:(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Payment Settings"}),(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Z.jsx)(gs.A,{sx:{mr:1,fontSize:32}}),(0,Z.jsx)(m.A,{variant:"h5",children:"Square Payment Connection"})]}),c&&(0,Z.jsx)(ne.A,{severity:j,sx:{mb:3},onClose:()=>g(null),children:c}),(0,Z.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,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1},children:[(0,Z.jsx)("strong",{children:"Store:"})," ",P.name]}),(0,Z.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2},children:[(0,Z.jsx)("strong",{children:"Connection Status:"})," ",$?.isConnected?(0,Z.jsx)(Fe.A,{label:"Connected",color:"success",size:"small",icon:(0,Z.jsx)(qr.A,{})}):(0,Z.jsx)(Fe.A,{label:"Not Connected",color:"default",size:"small",icon:(0,Z.jsx)(Or.A,{})})]}),$?.isConnected&&$?.merchantId&&(0,Z.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2},children:[(0,Z.jsx)("strong",{children:"Merchant ID:"})," ",$.merchantId]})]}),(0,Z.jsx)(p.A,{children:$?.isConnected?(0,Z.jsx)(X.A,{variant:"outlined",color:"error",onClick:()=>{i(!0)},disabled:R.isPending,startIcon:R.isPending&&(0,Z.jsx)(A.A,{size:16}),children:R.isPending?"Disconnecting...":"Disconnect Square"}):(0,Z.jsx)(X.A,{variant:"contained",color:"primary",onClick:()=>{P?.id&&z.mutate(P.id)},disabled:z.isPending,startIcon:z.isPending&&(0,Z.jsx)(A.A,{size:16}),children:z.isPending?"Connecting...":"Connect Square Account"})})]}),(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mt:3},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,Z.jsx)(Fn.A,{sx:{mr:1,fontSize:32}}),(0,Z.jsx)(m.A,{variant:"h5",children:"Cash on Delivery"})]}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Accept cash payments when orders are delivered"}),(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(Ne.A,{checked:P?.codEnabled||!1,onChange:e=>{d(e.target.checked),o(!0)},disabled:T.isPending,color:"primary"}),label:P?.codEnabled?"Enabled":"Disabled"})]}),(0,Z.jsxs)(Qe.A,{open:n,onClose:W,children:[(0,Z.jsx)(Ze.A,{children:"Disconnect Square?"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(Wr.A,{children:["Are you sure you want to disconnect Square for ",(0,Z.jsx)("strong",{children:P.name}),"?",(0,Z.jsx)("br",{}),(0,Z.jsx)("br",{}),"Customers will not be able to make card payments until you reconnect."]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:W,disabled:R.isPending,children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{P?.id&&R.mutate(P.id)},color:"error",variant:"contained",disabled:R.isPending,startIcon:R.isPending&&(0,Z.jsx)(A.A,{size:16}),children:R.isPending?"Disconnecting...":"Disconnect"})]})]}),(0,Z.jsxs)(Qe.A,{open:a,onClose:q,children:[(0,Z.jsxs)(Ze.A,{children:[l?"Enable":"Disable"," Cash on Delivery?"]}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(Wr.A,{children:l?`Customers will be able to pay with cash when their orders from ${P?.name} are delivered.`:`Customers will no longer see Cash on Delivery as a payment option for ${P?.name}. Orders already in progress will not be affected.`})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:q,disabled:T.isPending,children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:()=>{P?.id&&T.mutate({storeId:P.id,enabled:l}),o(!1)},variant:"contained",color:l?"primary":"error",disabled:T.isPending,startIcon:T.isPending&&(0,Z.jsx)(A.A,{size:16}),children:T.isPending?"Saving...":"Confirm"})]})]})]})}):(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4},children:(0,Z.jsx)(ne.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})},Dn=()=>{const e=(0,d.Zp)(),{user:s,setUser:t}=K(),[r,i]=(0,x.useState)(!0),a=(0,ke.A)();return(0,x.useEffect)((()=>{(async()=>{try{const s=await(0,y.$)();if(s?.tokens?.idToken){const r=s.tokens.idToken.payload.sub,n=s.tokens.idToken.payload["custom:role"]?.toLowerCase();t({id:r,role:n}),e(`/${n}`)}}catch(e){}finally{i(!1)}})()}),[t,e]),r?(0,Z.jsx)(le,{}):(0,Z.jsx)(p.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,Z.jsxs)(ae.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,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,Z.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,Z.jsx)(m.A,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"Sign in to continue your journey with us"})]}),(0,Z.jsx)(lt,{}),(0,Z.jsxs)(p.A,{sx:{mt:4,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:[(0,Z.jsx)(n.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,Z.jsxs)(m.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:["Don't have an account?"," ",(0,Z.jsx)(n.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 Ln=(0,t(11848).Ay)(se.A)((e=>{let{theme:s}=e;return{"& .MuiInputBase-root":{minHeight:"120px"}}})),$n=e=>{let{sectionHeaders:s,answers:t={},onChangeAnswers:r,onSubmit:n}=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,Z.jsxs)(p.A,{sx:{width:"100%"},children:[(0,Z.jsx)(je.Ay,{container:!0,spacing:3,children:s.map(((e,s)=>(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(ae.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,Z.jsx)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,color:"primary.main",letterSpacing:.2},children:e}),(0,Z.jsx)(Ln,{fullWidth:!0,multiline:!0,minRows:5,placeholder:`Enter items for ${e.toLowerCase()}`,variant:"outlined",value:t[s]||"",onChange:e=>((e,s)=>{const n={...t,[e]:s};r(n)})(s,e.target.value),sx:{"& .MuiOutlinedInput-root":{backgroundColor:"background.paper"}}})]})},s)))}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"flex-end",mt:4},children:(0,Z.jsx)(X.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,r)=>{const n=t[r]?t[r].trim():"";n&&(e.push(s),n.split("\n").forEach((s=>{const t=s.trim();t&&e.push(` • ${t}`)})),e.push(""))})),e.join("\n").trim()})();n(e),l(Object.values(t).some((e=>""!==e.trim()))),a(!0),(()=>{const e={};s.forEach(((s,t)=>{e[t]=""})),r(e)})(),setTimeout((()=>{a(!1)}),3e3)},children:"Submit List"})}),(0,Z.jsxs)(Qe.A,{open:i,onClose:()=>a(!1),PaperProps:{sx:{borderRadius:2,minWidth:"300px"}},children:[(0,Z.jsxs)(Ze.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Dr.A,{color:"success",sx:{fontSize:28}}),(0,Z.jsx)(m.A,{variant:"h6",sx:{fontWeight:600},children:o?"Items Edited":"Items Added"})]}),(0,Z.jsx)(he.A,{onClick:()=>a(!1),size:"small",sx:{color:"text.secondary"},children:(0,Z.jsx)(js.A,{})})]}),(0,Z.jsx)(Je.A,{children:(0,Z.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,Z.jsx)(Xe.A,{sx:{px:3,pb:2},children:(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>a(!1),sx:{borderRadius:2,textTransform:"none",px:3},children:"Okay"})})]})]})};function zn(e){if(!e)return!0;const s=e.cart&&Object.keys(e.cart).length>0,t=!!e.customOrder,r=e.listInputAnswers&&Object.keys(e.listInputAnswers).length>0;return!s&&!t&&!r}const Rn=()=>{const[e,s]=(0,x.useState)(!1),[t,r]=(0,x.useState)(!1),[n,i]=(0,x.useState)(!1),{selectedStore:a,setAvailableStores:o,setSelectedStore:l,pickupAddress:d,deliveryType:c,deliveryAddressString:m,setCustomOrder:h,listInputAnswers:p,setListInputAnswers:A}=Q();!function(){const e=K((e=>e.userProfile)),s=Q((e=>e.selectedStore)),t=Q((e=>e.restoreCart)),r=Q((e=>e.getCartState)),n=(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(n.current=!1);const e=i.current!==d,s=a.current!==c;if(i.current=d,a.current=c,!e&&!s&&n.current)return;let o=!1;return async function(){try{const e=await C("\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,n=r(),i=zn(n);if(i&&s?.cartData){t(s.cartData);try{localStorage.setItem(`indimitra-cart-store-${c}`,JSON.stringify(s.cartData))}catch(e){}}else i||await C(R,{userId:d,storeId:c,cartData:n})}catch(e){}finally{o||(n.current=!0)}}(),()=>{o=!0}}),[d,c]),(0,x.useEffect)((()=>{if(!d||!c)return;const e=Q.subscribe(((e,s)=>{n.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=Q.getState().getCartState(),s=i.current,t=a.current;if(!s||!t)return;try{localStorage.setItem(`indimitra-cart-store-${t}`,JSON.stringify(e))}catch(e){}zn(e)?await C(T,{userId:s,storeId:t}):await C(R,{userId:s,storeId:t,cartData:e})}catch(e){}finally{l.current=!1}}}),1e3))}));return()=>{e(),o.current&&clearTimeout(o.current)}}),[d,c])}();const{data:g,isLoading:j,error:y}=(0,u.I)({queryKey:["stores"],queryFn:async()=>await C(L)});(0,x.useEffect)((()=>{if(g?.stores&&g.stores.length>0){o(g.stores);const e=localStorage.getItem("selectedStoreId");if(e){const t=g.stores.find((s=>String(s.id)===e));a&&a.id===t?.id||(t?l(t):(localStorage.removeItem("selectedStoreId"),s(!0)))}else a||s(!0)}}),[g,a,o]);if(j)return(0,Z.jsx)(J,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:(0,Z.jsx)(le,{})});const f=a?.sectionHeaders?.length>0;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ut,{open:e,onClose:()=>s(!1)}),a&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ut,{open:t,onClose:()=>r(!1),forceStep:"pickup",initialStore:a}),(0,Z.jsx)(me,{children:(0,Z.jsx)(J,{sx:{mt:{xs:1,sm:2}},children:(0,Z.jsx)(hs,{images:a?.images,storeAddress:a.address,storeDescription:a.description,deliveryLabel:d||m?"delivery"===c?"Change Delivery Address":"Change Pickup Location":void 0,deliverySubtext:d||m?"delivery"===c?m||"No address selected":d?.address||"No pickup location selected":void 0,onChangeAddress:d||m?()=>r(!0):void 0})})}),(0,Z.jsxs)(me,{children:[f&&(0,Z.jsx)(ae.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,Z.jsxs)(J,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},gap:{xs:1,sm:0}},children:[(0,Z.jsx)(re,{variant:"h6",sx:{fontWeight:600,fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:n?"Browse Products":"Quick List Entry"}),(0,Z.jsx)(J,{sx:{minWidth:{xs:0,sm:200},display:"flex",alignItems:"center",justifyContent:{xs:"flex-start",sm:"flex-end"},width:{xs:"100%",sm:"auto"}},children:(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(Ne.A,{checked:n,onChange:()=>{i(!n)},color:"primary"}),label:(0,Z.jsx)(re,{variant:"body2",color:"text.secondary",sx:{width:140,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:{xs:"0.95rem",sm:"1rem"}},children:n?"Manual Browse":"Quick List"}),labelPlacement:"end",sx:{marginLeft:{xs:0,sm:2}}})})]})}),f&&!n?(0,Z.jsx)($n,{sectionHeaders:a.sectionHeaders,answers:p,onChangeAnswers:A,onSubmit:h}):(0,Z.jsx)($s,{})]})]})]})};var Tn=t(37483),Wn=t(28211);const qn=e=>{let{open:s,onClose:t,orderCode:r,onNavigate:n,onViewOrder:i}=e;const[a,o]=(0,x.useState)(3);(0,x.useEffect)((()=>{s&&o(3)}),[s]);const l=()=>{t(),n&&n()};return(0,x.useEffect)((()=>{if(s&&a>0){const e=setTimeout((()=>{o(a-1)}),1e3);return()=>clearTimeout(e)}s&&0===a&&l()}),[s,a,t,n]),(0,Z.jsx)(Qe.A,{open:s,onClose:l,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:3,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.12)"}},children:(0,Z.jsx)(Je.A,{sx:{p:4},children:(0,Z.jsxs)(p.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",py:2,gap:2},children:[(0,Z.jsx)(Dr.A,{sx:{fontSize:80,color:"success.main"}}),(0,Z.jsx)(m.A,{variant:"h5",fontWeight:"bold",color:"success.main",textAlign:"center",children:"Order Placed Successfully!"}),r&&(0,Z.jsxs)(m.A,{variant:"body1",color:"text.secondary",children:["Order #",r]}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",textAlign:"center",sx:{mt:1},children:"Thank you for your purchase. Your order is being processed and you'll receive an update soon!"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",sx:{mt:1},children:a>0?`Redirecting in ${a} seconds...`:"Redirecting..."}),(0,Z.jsxs)(ps.A,{direction:"row",spacing:2,sx:{mt:3,width:"100%",justifyContent:"center"},children:[(0,Z.jsx)(X.A,{variant:"outlined",color:"primary",onClick:()=>{t(),i&&i()},sx:{px:4,py:1.2,borderRadius:2,fontWeight:600,textTransform:"none",flex:1,maxWidth:200},children:"View Order"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",onClick:l,sx:{px:4,py:1.2,borderRadius:2,fontWeight:600,textTransform:"none",flex:1,maxWidth:200},children:"OK"})]})]})})})};var On=t(51694),Bn=t(85916),Un=t(11692),Nn=t(2183);const Mn=e=>{let{size:s=24,sx:t}=e;return(0,Z.jsx)(A.A,{size:s,sx:{color:"inherit",...t}})},_n=e=>{let{userProfile:s,onPhoneUpdate:t}=e;const[r,n]=(0,x.useState)(!1),[i,a]=(0,x.useState)(""),[o,l]=(0,x.useState)(""),{mutate:d,isPending:c}=(0,Is.n)({mutationFn:e=>C("\n mutation UpdateSecondaryPhone($userId: Int!, $secondaryPhone: String) {\n updateSecondaryPhone(userId: $userId, secondaryPhone: $secondaryPhone) {\n active\n }\n }\n",e),onSuccess:()=>{t(),n(!1),a(""),l("")},onError:e=>{l("Failed to update phone number. Please try again.")}});return s?(0,Z.jsx)(p.A,{sx:{mb:3},children:r?(0,Z.jsxs)(ae.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(vr.A,{color:"primary"}),(0,Z.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:s.secondaryPhone?"Update Number":"Add Number"})]}),(0,Z.jsx)(se.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,Z.jsx)(m.A,{sx:{mr:1},children:"+1"})}}),(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:1},children:[(0,Z.jsx)(X.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,Z.jsx)(Mn,{size:20}):(0,Z.jsx)(vr.A,{}),children:c?"Saving...":"Save"}),(0,Z.jsx)(X.A,{variant:"outlined",size:"small",onClick:()=>{n(!1),a(""),l("")},children:"Cancel"})]})]}):(0,Z.jsxs)(ae.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(vr.A,{color:"primary"}),(0,Z.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Secondary Contact"}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"(Update if you want to change)"})]}),s.secondaryPhone?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(m.A,{variant:"body1",children:["+1 ",s.secondaryPhone]}),(0,Z.jsx)(X.A,{variant:"outlined",size:"small",onClick:()=>n(!0),startIcon:(0,Z.jsx)(vr.A,{}),sx:{alignSelf:"flex-start"},children:"Change Number"})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"No secondary number added"}),(0,Z.jsx)(X.A,{variant:"outlined",size:"small",onClick:()=>n(!0),startIcon:(0,Z.jsx)(vr.A,{}),sx:{alignSelf:"flex-start"},children:"Add Number"})]})]})}):null},Vn=()=>{const{cart:e,removeFromCart:s,addToCart:t,cartTotal:r,clearCart:i,selectedStore:o,getCartTotals:l,setTipAmount:c,customOrder:h,setCustomOrder:g,pickupAddress:j,setPickupAddress:f,deliveryType:b,setDeliveryType:v,tipAmount:I,setListInputAnswers:S}=Q(),[w,P]=(0,x.useState)(""),[k,F]=(0,x.useState)(!1),[E,D]=(0,x.useState)(null),[L,$]=(0,x.useState)(""),{user:z,userProfile:R,fetchUserProfile:W,isProfileLoading:q,setModalOpen:O,setCurrentForm:B}=K(),U=(0,d.Zp)(),N=(0,a.jE)(),[M,_]=(0,x.useState)(0),[V,H]=(0,x.useState)(""),[G,J]=(0,x.useState)(j?String(j.id):null),[ee,te]=(0,x.useState)(!1),[re,ne]=(0,x.useState)(!1),[ie,oe]=(0,x.useState)(null),[le,de]=(0,x.useState)(!(!j&&"delivery"!==b)),ce=(0,x.useCallback)((async()=>{if(i(),g(""),S({}),o?.id)try{localStorage.removeItem(`indimitra-cart-store-${o.id}`)}catch(e){}if(R?.id&&o?.id)try{await C(T,{userId:R.id,storeId:o.id}),await new Promise((e=>setTimeout(e,100)))}catch(e){}}),[i,g,S,o,R]);(0,x.useEffect)((()=>{(async()=>{const e=await(0,y.$)(),s=e?.tokens?.idToken?.payload?.sub;s&&await W(s)})()}),[W,z]);const{addresses:ue,selectedAddressId:me,setSelectedAddressId:pe,fetchAddresses:ge,isLoading:fe,createAddress:ve}=Y(),{data:Ie,isLoading:we}=(0,u.I)({queryKey:["storePaymentConfig",o?.id],queryFn:async()=>C("\n query StorePaymentConfig($storeId: Int!) {\n storePaymentConfig(storeId: $storeId) {\n storeId\n isSquareConnected\n codEnabled\n squareApplicationId\n squareLocationId\n }\n }\n",{storeId:o.id}),enabled:!!o?.id}),Pe=Ie?.storePaymentConfig||null,[ke,Fe]=(0,x.useState)(!1),[Ee,De]=(0,x.useState)(""),[Le,$e]=(0,x.useState)(!1),[ze,Re]=(0,x.useState)(!1),[Te,We]=(0,x.useState)(!1),[qe,Ne]=(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)((()=>{R?.id&&ge(R.id)}),[R?.id,ge]),(0,x.useEffect)((()=>{j&&(J(String(j.id)),v("pickup"),pe(null),de(!0))}),[j,v,pe]),(0,x.useEffect)((()=>{const e=l();Ne(e)}),[b,e,l,I]);const{subtotal:Me,deliveryFee:_e,taxAmount:Ve,taxPercentage:He,tipAmount:Ge,total:Ke}=qe;(0,x.useEffect)((()=>{if(!le){if(o?.pickupAddresses?.edges?.length>0&&!G&&!me){const e=o.pickupAddresses.edges[0].node;return J(String(e.id)),v("pickup"),void pe(null)}if(ue&&ue.length>0&&!G&&!me){const e=ue.find((e=>e.isPrimary))||ue[0];return pe(e.id),v("delivery"),void J(null)}o?.pickupAddresses?.edges?.length&&0!==o?.pickupAddresses?.edges?.length||ue&&0!==ue.length||G||me||v("delivery")}}),[o?.pickupAddresses?.edges,ue,le]);const{mutate:Ye,isPending:Qe}=(0,Is.n)({mutationKey:["createOrder"],mutationFn:async e=>{const s=Q.getState().selectedStore;return C("\n mutation CreateOrder(\n $userId: Int!\n $storeId: Int!\n $productItems: [OrderItemInput!]!\n $totalAmount: Float!\n $orderTotalAmount: Float!\n $pickupOrDelivery: String!\n $addressId: Int\n $pickupId: Int\n $deliveryFee: Float\n $tipAmount: Float\n $taxAmount: Float\n $deliveryInstructions: String\n $customOrder: String\n ) {\n createOrder(\n userId: $userId\n storeId: $storeId\n productItems: $productItems\n totalAmount: $totalAmount\n orderTotalAmount: $orderTotalAmount\n pickupOrDelivery: $pickupOrDelivery\n addressId: $addressId\n pickupId: $pickupId\n deliveryFee: $deliveryFee\n tipAmount: $tipAmount\n taxAmount: $taxAmount\n deliveryInstructions: $deliveryInstructions\n customOrder: $customOrder\n ) {\n id\n status\n totalAmount\n orderTotalAmount\n deliveryFee\n tipAmount\n taxAmount\n deliveryInstructions\n deliveryDate\n address {\n id\n address\n }\n orderItems {\n edges {\n node {\n id\n quantity\n orderAmount\n product {\n id\n name\n }\n }\n }\n }\n }\n }\n",{...e,storeId:s.id})},onSuccess:async e=>{const s=e?.createOrder;if(s&&s.id)try{await ce(),D(s.displayCode||`#${s.id}`),F(!0),$(""),N.invalidateQueries(["userAddresses",R.id])}catch(e){D(s.displayCode||`#${s.id}`),F(!0)}else $("Order creation failed. Your cart has been preserved. Please try again.")},onError:e=>{$(e?.message||e?.response?.errors?.[0]?.message||e?.graphQLErrors?.[0]?.message||"Failed to place order. Please try again.")}}),{mutate:Ze,isPending:Je}=(0,Is.n)({mutationFn:async e=>C("\n mutation CreateOrderWithCod(\n $userId: Int!\n $storeId: Int!\n $productItems: [OrderItemInput!]!\n $pickupOrDelivery: String!\n $addressId: Int\n $pickupId: Int\n $tipAmount: Float\n $deliveryInstructions: String\n $customOrder: String\n ) {\n createOrderWithCod(\n userId: $userId\n storeId: $storeId\n productItems: $productItems\n pickupOrDelivery: $pickupOrDelivery\n addressId: $addressId\n pickupId: $pickupId\n tipAmount: $tipAmount\n deliveryInstructions: $deliveryInstructions\n customOrder: $customOrder\n ) {\n id\n displayCode\n status\n orderTotalAmount\n }\n }\n",e),onSuccess:async e=>{const s=e?.createOrderWithCod;if(s&&s.id)try{await ce(),D(s.displayCode||`#${s.id}`),F(!0),$("")}catch(e){D(s.displayCode||`#${s.id}`),F(!0)}else $("Order creation failed. Your cart has been preserved. Please try again.")},onError:e=>{$(e?.message||e?.response?.errors?.[0]?.message||e?.graphQLErrors?.[0]?.message||"Failed to place order. Please try again.")}}),Xe=(0,x.useCallback)((()=>{ne(!1)}),[]),es=(0,x.useCallback)((async e=>{if(e)if(e.id)try{await ce(),D(e.displayCode||`#${e.id}`),F(!0),$("")}catch(s){D(e.displayCode||`#${e.id}`),F(!0)}else{const s=e.error||"Order creation failed. Your cart has been preserved. Please try again.";$(s)}else $("Order creation failed. Your cart has been preserved. Please try again.")}),[ce]),ss=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity})));return(0,Z.jsxs)(p.A,{sx:{padding:3},children:[(0,Z.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,Z.jsx)(Us.A,{})," Your Shopping Cart"]}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:3,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:8,children:(0,Z.jsxs)(ae.A,{elevation:2,sx:{p:3,mb:3},children:[L&&(0,Z.jsx)(ds,{error:L,title:"Order Error",severity:"error"}),Object.values(e).length>0||h?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(m.A,{variant:"h6",sx:{mb:2,fontWeight:500},children:"Cart Items"}),Object.values(e).map((e=>(0,Z.jsx)(ye.A,{sx:{mb:2,position:"relative"},children:(0,Z.jsx)(be.A,{children:(0,Z.jsxs)(je.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:4,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:2,flexDirection:{xs:"column",sm:"row"},justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,Z.jsx)("img",{src:e.image,alt:e.name,style:{width:"48px",height:"48px",objectFit:"cover",borderRadius:8,marginBottom:4}}),(0,Z.jsx)(m.A,{variant:"subtitle1",sx:{fontWeight:500,textAlign:{xs:"center",sm:"left"},fontSize:{xs:"1rem",sm:"1.1rem"}},children:e.name})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,sm:3,children:(0,Z.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,Z.jsx)(je.Ay,{item:!0,xs:6,sm:3,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:1,justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,Z.jsx)(he.A,{size:"small",onClick:()=>s(e.id),sx:{border:"1px solid",borderColor:"divider",width:32,height:32},children:(0,Z.jsx)(Se.A,{fontSize:"small"})}),(0,Z.jsx)(m.A,{sx:{minWidth:32,textAlign:"center",fontSize:{xs:"1rem",sm:"1.1rem"}},children:e.quantity}),(0,Z.jsx)(he.A,{size:"small",onClick:()=>t(e),sx:{border:"1px solid",borderColor:"divider",width:32,height:32},children:(0,Z.jsx)(Ce.A,{fontSize:"small"})})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:2,children:(0,Z.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,Z.jsx)(ye.A,{sx:{mb:2,position:"relative",bgcolor:"primary.lighter"},children:(0,Z.jsxs)(be.A,{children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:2,mb:2},children:[(0,Z.jsx)(Us.A,{color:"primary"}),(0,Z.jsx)(m.A,{variant:"h6",sx:{fontWeight:600,color:"primary.main"},children:"Custom Shopping List"})]}),(0,Z.jsx)(p.A,{sx:{p:2,bgcolor:"background.paper",borderRadius:1,border:"1px solid",borderColor:"divider"},children:(0,Z.jsx)(m.A,{variant:"body1",sx:{whiteSpace:"pre-line",fontFamily:"monospace",lineHeight:1.6},children:h})}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"flex-end",mt:2},children:(0,Z.jsx)(X.A,{variant:"outlined",color:"error",size:"small",onClick:()=>g(""),startIcon:(0,Z.jsx)(Se.A,{}),children:"Remove List"})})]})})]}):(0,Z.jsxs)(p.A,{sx:{textAlign:"center",py:4},children:[(0,Z.jsx)(Us.A,{sx:{fontSize:60,color:"text.secondary",mb:2}}),(0,Z.jsx)(m.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"Your cart is empty"}),(0,Z.jsx)(X.A,{variant:"contained",component:n.N_,to:"/",startIcon:(0,Z.jsx)(Us.A,{}),children:"Continue Shopping"})]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(ae.A,{elevation:2,sx:{p:3,position:"sticky",top:24},children:[(0,Z.jsx)(m.A,{variant:"h6",sx:{mb:3,fontWeight:500},children:"Order Summary"}),R&&(0,Z.jsx)(p.A,{sx:{mb:3},children:(0,Z.jsx)(_n,{userProfile:R,onPhoneUpdate:()=>{(async()=>{const e=await(0,y.$)(),s=e?.tokens?.idToken?.payload?.sub;s&&await W(s)})()}})}),(0,Z.jsx)(p.A,{sx:{mt:3},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,Z.jsx)(m.A,{children:"Subtotal"}),(0,Z.jsxs)(m.A,{children:["$",Me.toFixed(2)]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,Z.jsx)(m.A,{children:"Delivery Fee"}),(0,Z.jsxs)(m.A,{children:["$",_e.toFixed(2)]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Tax Rate"}),(0,Z.jsxs)(m.A,{children:[He.toFixed(1),"%"]})]}),(0,Z.jsxs)(p.A,{sx:{textAlign:"right"},children:[(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:"Tax Amount"}),(0,Z.jsxs)(m.A,{children:["$",Ve.toFixed(2)]})]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{mb:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,children:"Add Tip"}),(0,Z.jsxs)(Tn.A,{value:M,exclusive:!0,onChange:(e,s)=>{if(null!==s){_(s),H("");c(Me*s/100)}},"aria-label":"tip percentage",size:"small",fullWidth:!0,sx:{mb:1},children:[(0,Z.jsx)(Wn.A,{value:0,"aria-label":"no tip",children:"No Tip"}),(0,Z.jsx)(Wn.A,{value:10,"aria-label":"10%",children:"10%"}),(0,Z.jsx)(Wn.A,{value:15,"aria-label":"15%",children:"15%"}),(0,Z.jsx)(Wn.A,{value:20,"aria-label":"20%",children:"20%"})]}),(0,Z.jsx)(se.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,Z.jsx)(m.A,{sx:{mr:1},children:"$"})},placeholder:"Enter custom amount",sx:{mt:1}})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",bgcolor:"grey.50",p:1,borderRadius:1},children:[(0,Z.jsx)(m.A,{children:"Tip Amount"}),(0,Z.jsxs)(m.A,{children:["$",Ge.toFixed(2)]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(As.A,{})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,Z.jsx)(m.A,{variant:"h6",children:"Total"}),(0,Z.jsxs)(m.A,{variant:"h6",children:["$",Ke.toFixed(2)]})]})})]})}),h&&(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Us.A,{})," Custom Order Details"]}),(0,Z.jsx)(ae.A,{elevation:0,sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:2,backgroundColor:"background.paper"},children:(0,Z.jsx)(m.A,{variant:"body2",sx:{whiteSpace:"pre-line",color:"text.secondary",fontFamily:"monospace"},children:h})})]}),R&&(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsxs)(m.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Es.A,{})," Delivery/Pickup Options"]}),q?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,Z.jsx)(Mn,{size:24})}):(0,Z.jsxs)(ps.A,{spacing:3,children:[o?.pickupAddresses?.edges?.length>0&&(0,Z.jsxs)(ae.A,{elevation:"pickup"===b?4:1,sx:{p:2,bgcolor:"pickup"===b?"primary.lighter":"grey.50",opacity:"delivery"===b&&me?.5:1,border:"pickup"===b?"2px solid #1976d2":"1px solid #eee",transition:"all 0.2s"},children:[(0,Z.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Rt.A,{fontSize:"small",color:"primary"})," Pickup Address"]}),(0,Z.jsx)(Ps.A,{value:G||"",onChange:e=>{const s=e.target.value;J(s),v("pickup"),pe(null),de(!0);const t=o.pickupAddresses.edges.map((e=>e.node)),r=t.find((e=>String(e.id)===String(s)));r&&f(r)},children:o.pickupAddresses.edges.map((e=>{let{node:s}=e;return(0,Z.jsx)(Ue.A,{value:String(s.id),control:(0,Z.jsx)(ks.A,{color:"primary"}),label:s.address},s.id)}))})]}),(0,Z.jsxs)(ae.A,{elevation:"delivery"===b?4:1,sx:{p:2,bgcolor:"delivery"===b?"secondary.lighter":"grey.50",opacity:"pickup"===b&&G?.5:1,border:"delivery"===b?"2px solid #9c27b0":"1px solid #eee",transition:"all 0.2s"},children:[(0,Z.jsxs)(m.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(On.A,{fontSize:"small",color:"secondary"})," Home Delivery Address"]}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsxs)(Cs.A,{fullWidth:!0,sx:{mb:2},children:[(0,Z.jsx)(ur.A,{children:"Select Address"}),fe?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,Z.jsx)(Mn,{size:24})}):(0,Z.jsx)(Oe.A,{value:me||"",onChange:e=>{pe(e.target.value),v("delivery"),J(null),de(!0)},label:"Select Address",inputProps:{},InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(Nn.A,{})})},children:ue&&ue.length>0?ue.map((e=>(0,Z.jsxs)(Ae.A,{value:e.id,children:[e.address," ",e.isPrimary?"(Primary)":""]},e.id))):(0,Z.jsx)(Ae.A,{disabled:!0,children:"No addresses available"})})]}),(0,Z.jsx)(X.A,{fullWidth:!0,variant:"outlined",startIcon:ke?(0,Z.jsx)(Bn.A,{}):(0,Z.jsx)(Un.A,{}),onClick:()=>Fe(!ke),sx:{mb:2},children:ke?"Cancel":"Add New Address"}),(0,Z.jsx)(Be.A,{in:ke,children:(0,Z.jsx)(p.A,{sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:1},children:(0,Z.jsxs)(ps.A,{spacing:2,children:[(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(qt,{value:Ee,onChange:e=>{De(e),(e=>{if(!e.trim()||!ue)return void te(!1);const s=e.toLowerCase().trim(),t=ue.some((e=>e.address.toLowerCase().trim()===s));te(t)})(e)},onValidAddress:We}),ee&&(0,Z.jsx)(m.A,{variant:"body2",color:"error",sx:{mt:.5,fontSize:"0.875rem"},children:"⚠️ This address already exists in your address book"})]}),(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(nn.A,{checked:Le,onChange:e=>$e(e.target.checked)}),label:"Set as Primary Address"}),(0,Z.jsx)(X.A,{variant:"contained",onClick:async()=>{if(!Ee.trim())return void $("Please enter a valid address");const e=Ee.trim().toLowerCase(),s=ue?.some((s=>s.address.toLowerCase().trim()===e));if(s)$("This address already exists in your address book");else{Re(!0),$("");try{await ve(Ee,R.id,Le),Fe(!1),De(""),$e(!1),N.invalidateQueries(["userAddresses",R.id])}catch(e){$("Failed to add address. Please try again.")}finally{Re(!1)}}},disabled:!Ee.trim()||ze||!Te||ee,startIcon:ze?(0,Z.jsx)(Mn,{size:20}):(0,Z.jsx)(cs.A,{}),children:ze?"Adding...":"Add Address"})]})})})]})]})]})]}),R&&(0,Z.jsxs)(p.A,{sx:{mb:3},children:[(0,Z.jsx)(m.A,{variant:"subtitle1",sx:{mb:2},children:"Delivery Instructions"}),(0,Z.jsx)(se.A,{fullWidth:!0,multiline:!0,rows:2,value:w,onChange:e=>P(e.target.value),placeholder:"Add any special instructions for delivery..."})]}),R&&(0,Z.jsx)(Z.Fragment,{children:we?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",mb:3},children:(0,Z.jsx)(A.A,{size:24})}):(0,Z.jsx)(Ds,{paymentConfig:Pe,selectedMethod:ie,onMethodChange:oe})}),R?(0,Z.jsx)(X.A,{fullWidth:!0,variant:"contained",size:"large",onClick:"cod"===ie?()=>{if($(""),!R||!R.id)return $("Please log in to place an order"),O(!0),void B("login");if(!o||!o.id)return void $("Please select a store");if(0===Object.values(e).length&&!h)return void $("Your cart is empty. Please add items before placing an order");if(!G&&!me)return void $("Please select either a pickup location or delivery address");const s=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity})));Ze({userId:R.id,storeId:o.id,productItems:s,pickupOrDelivery:b,addressId:me,pickupId:G?parseInt(G,10):null,tipAmount:I||0,deliveryInstructions:"pickup"===b?null:w,customOrder:h||null})}:()=>{ne(!0)},disabled:q||we||!ie||!me&&!G||0===Object.values(e).length&&!h?.trim()||Je,startIcon:"cod"===ie?(0,Z.jsx)(Es.A,{}):(0,Z.jsx)(gs.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"cod"===ie?"Place Order":"Pay Now"}):(0,Z.jsx)(X.A,{fullWidth:!0,variant:"contained",size:"large",onClick:()=>{O(!0),B("login")},startIcon:(0,Z.jsx)(Us.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"Login to Continue"})]})})]}),(0,Z.jsx)(Ss,{open:re,onClose:Xe,cartTotal:Ke,orderItems:ss,deliveryType:b,selectedAddressId:me,selectedPickupId:G?parseInt(G,10):null,userProfile:R,selectedStore:o,tipAmount:I,deliveryInstructions:w,customOrder:h,onSuccess:es,paymentConfig:Pe}),(0,Z.jsx)(qn,{open:k,onClose:()=>F(!1),orderCode:E,onNavigate:()=>U("/"),onViewOrder:()=>U("/orders")})]})};var Hn=t(16099),Gn=t(98821),Kn=t(1309);const Yn=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(e);var Qn=t(25737),Zn=t(55463),Jn=t(67046),Xn=t(4213);(0,Qn.D)();const ei="\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",si=()=>{const{userProfile:e}=K(),[s,t]=(0,x.useState)(""),[r,n]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),[o,l]=(0,x.useState)(!1),[d,c]=(0,x.useState)(null),[h,j]=(0,x.useState)(""),[y,f]=(0,x.useState)(""),[b,v]=(0,x.useState)(""),[I,S]=(0,x.useState)("ALL"),[w,L]=(0,x.useState)("createdAt"),[$,z]=(0,x.useState)("desc"),[R,T]=(0,x.useState)(0),[W,q]=(0,x.useState)(10),[O,B]=(0,x.useState)(""),[U,N]=(0,x.useState)(""),[M,_]=(0,x.useState)(""),[V,H]=(0,x.useState)(""),[G,Y]=(0,x.useState)({open:!1,message:"",severity:"info"}),[Q,J]=(0,x.useState)(!1),[ee,te]=(0,x.useState)(null),[re,ie]=(0,x.useState)(1),[oe,le]=(0,x.useState)(!1),[de,ce]=(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,rt.T)();t(e.sub)}catch(e){}})()}),[]);const{data:pe,isLoading:ge}=(0,u.I)({queryKey:["getUserProfile",s],queryFn:async()=>await C(k,{userId:s}),enabled:!!s}),fe=pe?.getUserProfile?.stores?.edges?.[0]?.node?.id,ve=pe?.getUserProfile?.id,{data:Se,isLoading:Ce,error:we,refetch:Pe}=(0,u.I)({queryKey:["storeDrivers",fe],queryFn:async()=>await C(E,{storeId:fe}),enabled:!!fe}),{data:ke,isLoading:Ee,error:De,refetch:Le}=(0,u.I)({queryKey:["storeOrders",fe],queryFn:async()=>(await C(F,{storeId:fe})).getOrdersByStore||[],enabled:!!fe}),$e=(0,Is.n)({mutationFn:async e=>await C(P,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onSuccess:()=>{Le(),a(!1),c(null),j(""),N(""),_(""),H("")},onError:e=>{f(e.message)}}),ze=(0,Is.n)({mutationFn:async e=>{const{orderId:s,itemId:t,quantity:r,price:n}=e,i=ke.find((e=>e.id===s));if(!i)throw new Error("Order not found");const a=pe?.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)?r>0:e.quantity>0)))return await C(ei,{orderId:parseInt(s),orderItemUpdates:[{orderItemId:parseInt(t),quantityChange:r-ee.quantity}],totalAmount:0,orderTotalAmount:0,taxAmount:0});let l=0;o.forEach((e=>{if(e.id===parseInt(t))l+=r*n;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=r-ee.quantity;return await C(ei,{orderId:parseInt(s),orderItemUpdates:[{orderItemId:parseInt(t),quantityChange:x}],totalAmount:l,orderTotalAmount:c,taxAmount:d})},onSuccess:()=>{Le(),J(!1),te(null),ie(1)},onError:e=>{f(e.message)}}),Re=(0,Is.n)({mutationFn:async e=>await C(D,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:e.cancelledByUserId}),onSuccess:()=>{Le(),l(!1),B(""),c(null),Y({open:!0,message:"Order cancelled successfully",severity:"success"})},onError:e=>{f(e.message),Y({open:!0,message:"Failed to cancel order. Please try again.",severity:"error"})}}),Te=e=>{w===e?z("asc"===$?"desc":"asc"):(L(e),z("asc"))},We=x.useMemo((()=>{if(!ke)return[];let e=[...ke];return b&&(e=e.filter((e=>e.id.toString().includes(b)||(e.deliveryInstructions||"").toLowerCase().includes(b.toLowerCase())))),"ALL"!==I&&(e=e.filter((e=>e.status===I))),e.sort(((e,s)=>{let t=0;return t="totalAmount"===w?e[w]-s[w]:String(e[w]||"").localeCompare(String(s[w]||"")),"asc"===$?t:-t})),e}),[ke,b,I,w,$]),qe=x.useMemo((()=>{const e=R*W;return We.slice(e,e+W)}),[We,R,W]),Be=e=>{if(!e?.edges?.length)return null;const s=new Map;e.edges.forEach((e=>{let{node:t}=e;const r=t.productId;(!s.has(r)||t.id>s.get(r).id)&&s.set(r,t)}));return Array.from(s.values())},Ue=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e),Ne=async(e,s)=>{try{if("pdf"===s){const s=(e=>{const s=new Zn.uE;let t=20;const r=20;return s.internal.pageSize.width,s.setFontSize(16),s.text("Orders Report",r,t),t+=14,s.setFontSize(10),b&&(s.text(`Search Term: ${b}`,r,t),t+=7),"ALL"!==I&&(s.text(`Status Filter: ${I}`,r,t),t+=7),t+=7,e.forEach(((e,n)=>{t>s.internal.pageSize.height-40&&(s.addPage(),t=20),s.setFontSize(12),s.text(`Order #${e.id}`,r,t),t+=7,s.text(`Order Code: ${e.displayCode||"N/A"}`,r,t),t+=10.5,s.setFontSize(10),["Type: "+("PICKUP"===e.type?"Pickup":"Delivery"),`Status: ${Rr.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[r,...n]=e.split("\n");r&&n.length>0&&(s.setFontSize(10),s.text(`Q: ${r}`,30,t),t+=7,n.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:r}=e;const n=r.product?.inventoryItems?.edges[0]?.node?.price||0,i=`${r.product?.name||"N/A"} - Qty: ${r.quantity} - Price: $${n} - Total: $${r.quantity*n}`;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 Jn.yoT({sections:[{properties:{},children:[new Jn.fzL({children:[new Jn.NTc({text:"Orders Report",bold:!0,size:32})]}),new Jn.fzL({children:[new Jn.NTc({text:b?`Search Term: ${b}`:"",size:24})]}),new Jn.fzL({children:[new Jn.NTc({text:"ALL"!==I?`Status Filter: ${I}`:"",size:24})]}),...e.map((e=>[new Jn.fzL({children:[new Jn.NTc({text:`Order #${e.id}`,bold:!0,size:28})]}),new Jn.fzL({children:[new Jn.NTc({text:`Order Code: ${e.displayCode||"N/A"}`,size:24})]}),new Jn.XIK({width:{size:100,type:Jn.PsV.PERCENTAGE},rows:[new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL("Type")],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL("PICKUP"===e.type?"Pickup":"Delivery")],width:{size:80,type:Jn.PsV.PERCENTAGE}})]}),new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL("Status")],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL(Rr.find((s=>s.value===e.status))?.label||e.status)],width:{size:80,type:Jn.PsV.PERCENTAGE}})]}),new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL("Total")],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL(`$${e.orderTotalAmount}`)],width:{size:80,type:Jn.PsV.PERCENTAGE}})]}),new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL("Customer")],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL(e.creator?.email||"N/A")],width:{size:80,type:Jn.PsV.PERCENTAGE}})]}),new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL("Phone")],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL(e.creator?.mobile||"N/A")],width:{size:80,type:Jn.PsV.PERCENTAGE}})]}),new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL("Address")],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL("PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A")],width:{size:80,type:Jn.PsV.PERCENTAGE}})]})]}),...e.customOrder?[new Jn.fzL({children:[new Jn.NTc({text:"Custom Order Details",bold:!0,size:24})]}),new Jn.XIK({width:{size:100,type:Jn.PsV.PERCENTAGE},rows:e.customOrder.split("\n\n").map((e=>{const[s,...t]=e.split("\n");return s&&t.length>0?new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL(s)],width:{size:30,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL({children:t.map(((e,s)=>[new Jn.NTc(e),...s0?[new Jn.fzL({children:[new Jn.NTc({text:"Items",bold:!0,size:24})]}),new Jn.XIK({width:{size:100,type:Jn.PsV.PERCENTAGE},rows:[new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL("Product")],width:{size:40,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL("Quantity")],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL("Price")],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL("Total")],width:{size:20,type:Jn.PsV.PERCENTAGE}})]}),...e.orderItems.edges.map((e=>{let{node:s}=e;const t=s.product?.inventoryItems?.edges[0]?.node?.price||0;return new Jn.Hjg({children:[new Jn.nA6({children:[new Jn.fzL(s.product?.name||"N/A")],width:{size:40,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL(s.quantity.toString())],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL(`$${t}`)],width:{size:20,type:Jn.PsV.PERCENTAGE}}),new Jn.nA6({children:[new Jn.fzL("$"+s.quantity*t)],width:{size:20,type:Jn.PsV.PERCENTAGE}})]})}))]})]:[],new Jn.fzL({})])).flat()]}]}))(e),t=await Jn.ND6.toBlob(s);(0,Xn.saveAs)(t,`orders_${(new Date).toISOString().replace(/[-:]/g,"").replace("T","_").replace("Z","")}.docx`)}Y({open:!0,message:`Orders downloaded successfully in ${s.toUpperCase()} format!`,severity:"success"})}catch(e){Y({open:!0,message:"Failed to download orders. Please try again.",severity:"error"})}le(!1)};return ge||Ee||Ce||ue?(0,Z.jsx)(mn,{children:(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,Z.jsx)(A.A,{})})}):!De&&!we||ue?(0,Z.jsx)(mn,{children:(0,Z.jsxs)(p.A,{sx:{p:3},children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Orders"}),y&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:y}),(0,Z.jsx)(ye.A,{sx:{mb:3},children:(0,Z.jsx)(be.A,{children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:3,children:(0,Z.jsx)(se.A,{fullWidth:!0,placeholder:"Search orders...",value:b,onChange:e=>v(e.target.value),InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(pr.A,{})})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:3,children:(0,Z.jsxs)(se.A,{select:!0,fullWidth:!0,label:"Filter by Status",value:I,onChange:e=>S(e.target.value),InputProps:{startAdornment:(0,Z.jsx)(xe.A,{position:"start",children:(0,Z.jsx)(Hn.A,{})})},children:[(0,Z.jsx)(Ae.A,{value:"ALL",children:"All Statuses"}),Rr.map((e=>(0,Z.jsx)(Ae.A,{value:e.value,children:e.label},e.value)))]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:3,children:(0,Z.jsxs)(m.A,{variant:"body2",color:"textSecondary",children:["Total Orders: ",We.length]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:3,children:(0,Z.jsx)(X.A,{fullWidth:!0,variant:"contained",startIcon:(0,Z.jsx)(Gn.A,{}),onClick:()=>le(!0),disabled:0===We.length,children:"Download Orders"})})]})})}),0===We.length?(0,Z.jsx)(ne.A,{severity:"info",sx:{mb:2},children:"No orders found."}):(0,Z.jsxs)(ar.A,{component:ae.A,children:[(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>Te("id"),children:["Order ID",(0,Z.jsx)(Kn.A,{sx:{ml:1,transform:"id"===w&&"desc"===$?"rotate(180deg)":"none"}})]})}),(0,Z.jsx)(cr.A,{children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>Te("totalAmount"),children:["Total",(0,Z.jsx)(Kn.A,{sx:{ml:1,transform:"totalAmount"===w&&"desc"===$?"rotate(180deg)":"none"}})]})}),(0,Z.jsx)(cr.A,{children:"Status"}),(0,Z.jsx)(cr.A,{children:"Actions"}),(0,Z.jsx)(cr.A,{})]})}),(0,Z.jsx)(xr.A,{children:qe.map((e=>{return(0,Z.jsxs)(x.Fragment,{children:[(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.id}),(0,Z.jsxs)(cr.A,{children:["$",e.orderTotalAmount]}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:Rr.find((s=>s.value===e.status))?.label||e.status,color:(s=e.status,Rr.find((e=>e.value===s))?.color||"default"),size:"small"})}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(Ie.A,{title:"Edit Order",children:(0,Z.jsx)(he.A,{size:"small",onClick:()=>(e=>{c(e),j(e.status),N(e.deliveryInstructions||""),a(!0)})(e),disabled:!Ue(e.status),children:(0,Z.jsx)(hr.A,{})})}),(0,Z.jsx)(Ie.A,{title:"Cancel Order",children:(0,Z.jsx)(he.A,{size:"small",onClick:()=>(e=>{c(e),l(!0)})(e),disabled:!Ue(e.status),children:(0,Z.jsx)(Lr.A,{})})}),(0,Z.jsx)(Ie.A,{title:"Upload File",children:(0,Z.jsx)(he.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 r=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",n=await fetch(`${r}/s3/generate-upload-url?file_name=${encodeURIComponent(t.name)}&order_id=${e.id}`);if(!n.ok)throw new Error("Failed to get upload URL");const{upload_url:i,content_type:a,file_name:o,key:l}=await n.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(`${r}/orders/${e.id}/set-bill-url?file_name=${encodeURIComponent(o)}`,{method:"POST"})).ok)throw new Error("Failed to update bill URL");(await fetch(`${r}/s3/generate-view-url?bill_key=${encodeURIComponent(l)}`)).ok?Y({open:!0,message:"File uploaded and verified successfully!",severity:"success"}):Y({open:!0,message:"File uploaded but verification failed. Please try viewing the file.",severity:"warning"})}catch(e){Y({open:!0,message:"Failed to upload file. Please try again.",severity:"error"})}},s.click()})(e),disabled:!Ue(e.status),children:(0,Z.jsx)(Fr.A,{})})}),(0,Z.jsx)(Ie.A,{title:"View File",children:(0,Z.jsx)(he.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,r=null;if(e.bill_url){const n=await fetch(`${s}/s3/generate-view-url?bill_key=${encodeURIComponent(e.bill_url)}`);if(n.ok){const e=await n.json();t=e.view_url,r=e.file_name}}if(!t){const n=[".pdf",".jpg",".jpeg",".png",".docx"];for(const i of n){const n=await fetch(`${s}/s3/generate-view-url?order_id=${e.id}&file_name=receipt${i}`);if(n.ok){const e=await n.json();t=e.view_url,r=e.file_name;break}}}if(!t)return void Y({open:!0,message:"No file found for this order.",severity:"warning"});const n=document.createElement("a");n.href=t,n.target="_blank",n.rel="noopener noreferrer",document.body.appendChild(n),n.click(),document.body.removeChild(n)}catch(e){Y({open:!0,message:"Failed to view file. Please try again.",severity:"error"})}})(e),children:(0,Z.jsx)(zr.A,{})})})]}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(he.A,{size:"small",onClick:()=>n(r===e.id?null:e.id),children:r===e.id?(0,Z.jsx)(Bn.A,{}):(0,Z.jsx)(Un.A,{})})})]}),r===e.id&&(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:6,children:(0,Z.jsx)(p.A,{sx:{p:2},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Information"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(m.A,{children:[(0,Z.jsx)("strong",{children:"Order Code:"})," ",e.displayCode||"N/A"]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(m.A,{children:[(0,Z.jsx)("strong",{children:"Type:"})," ","PICKUP"===e.type?(0,Z.jsxs)(p.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Us.A,{fontSize:"small"}),"Pickup Order"]}):(0,Z.jsxs)(p.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,Z.jsx)(Es.A,{fontSize:"small"}),"Delivery Order"]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsxs)(m.A,{children:[(0,Z.jsx)("strong",{children:"Address:"})," ","PICKUP"===e.type?e.pickupAddress?.address||"No pickup address":e.address?.address||"No delivery address"]})})]})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Customer Information"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{children:["Email: ",e?.creator?.email||"N/A"]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(m.A,{children:["Phone: ",e?.creator?.mobile||"N/A"]})})]})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Items"}),(0,Z.jsxs)(or.A,{size:"small",children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Product"}),(0,Z.jsx)(cr.A,{children:"Quantity"}),(0,Z.jsx)(cr.A,{children:"Price"}),(0,Z.jsx)(cr.A,{children:"Total"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:e.orderItems?.edges?.length>0?Be(e.orderItems)?.map((s=>{const t=(r=s,n=e.orderItems.edges,r&&n?n.map((e=>{let{node:s}=e;return s})).filter((e=>e.productId===r.productId)).sort(((e,s)=>e.id-s.id)):[r]);var r,n;const i=s.product?.inventoryItems?.edges[0]?.node?.price||0;return(0,Z.jsxs)(x.Fragment,{children:[(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:s.product?.name||"N/A"}),(0,Z.jsx)(cr.A,{children:s.quantity}),(0,Z.jsx)(cr.A,{children:Yn(i)}),(0,Z.jsx)(cr.A,{children:Yn(s.quantity*i)}),(0,Z.jsx)(cr.A,{children:Ue(e.status)&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(he.A,{size:"small",onClick:()=>{return t=s,r=e.id,te({...t,orderId:r}),ie(t.quantity),void J(!0);var t,r},sx:{mr:1},children:(0,Z.jsx)(hr.A,{fontSize:"small"})}),(0,Z.jsx)(he.A,{size:"small",onClick:()=>{return t=s,r=e.id,te({...t,orderId:r}),ie(0),void J(!0);var t,r},color:"error",children:(0,Z.jsx)(fr.A,{fontSize:"small"})})]})})]}),t.length>1&&(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:5,children:(0,Z.jsxs)(p.A,{sx:{pl:2,py:1},children:[(0,Z.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,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1,borderRadius:1,mb:1},children:[(0,Z.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"100px"},children:["Change ",s+1]}),(0,Z.jsxs)(p.A,{sx:{display:"flex",gap:3},children:[(0,Z.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,Z.jsxs)(m.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount:"," ",Yn(e.orderAmount)]})]})]},e.id)))]})})})]},s.id)})):(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:5,align:"center",children:"No items found for this order"})})})]})]}),e.customOrder&&(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Custom Order Details"}),(0,Z.jsx)(p.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:e.customOrder.split("\n\n").map(((e,s)=>{const[t,...r]=e.split("\n");return t&&r.length>0?(0,Z.jsxs)(p.A,{sx:{mb:2},children:[(0,Z.jsx)(m.A,{variant:"subtitle2",sx:{color:"text.secondary",mb:.5},children:t}),(0,Z.jsx)(p.A,{sx:{pl:2},children:r.map(((e,s)=>(0,Z.jsx)(m.A,{variant:"body2",sx:{mb:.5},children:e},s)))})]},s):null}))})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Summary"}),(0,Z.jsx)(p.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:1,children:[(0,Z.jsx)(je.Ay,{item:!0,xs:6,children:(0,Z.jsx)(m.A,{children:"Subtotal:"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Z.jsx)(m.A,{children:Yn(e.totalAmount)})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,children:(0,Z.jsx)(m.A,{children:"Delivery Fee:"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Z.jsx)(m.A,{children:Yn(e.deliveryFee)})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,children:(0,Z.jsx)(m.A,{children:"Tax:"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Z.jsx)(m.A,{children:Yn(e.taxAmount)})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,children:(0,Z.jsx)(m.A,{children:"Tip:"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Z.jsx)(m.A,{children:Yn(e.tipAmount)})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(As.A,{sx:{my:1}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,children:(0,Z.jsx)(m.A,{sx:{fontWeight:"bold"},children:"Total Amount:"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,Z.jsx)(m.A,{sx:{fontWeight:"bold"},children:Yn(e.orderTotalAmount)})})]})})]}),e.deliveryInstructions&&(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(m.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Delivery Instructions"}),(0,Z.jsx)(m.A,{children:e.deliveryInstructions})]})]})})})})]},e.id);var s}))})]}),(0,Z.jsx)(g.A,{component:"div",count:We.length,page:R,onPageChange:(e,s)=>{T(s)},rowsPerPage:W,onRowsPerPageChange:e=>{q(parseInt(e.target.value,10)),T(0)},rowsPerPageOptions:[5,10,25,50]})]}),(0,Z.jsxs)(Qe.A,{open:i,onClose:()=>a(!1),maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:"Update Order Status"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{select:!0,fullWidth:!0,label:"Status",value:h,onChange:e=>j(e.target.value),children:Rr.map((e=>(0,Z.jsx)(Ae.A,{value:e.value,children:e.label},e.value)))})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Delivery Instructions",value:U,onChange:e=>N(e.target.value),multiline:!0,rows:3})}),"READY_FOR_DELIVERY"===h&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,required:!0,children:[(0,Z.jsx)(ur.A,{children:"Delivery Agent"}),(0,Z.jsx)(Oe.A,{value:M,onChange:e=>_(e.target.value),label:"Delivery Agent",children:Se?.getStoreDrivers?.map((e=>(0,Z.jsxs)(Ae.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId)))})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:6,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Schedule Time",value:V,onChange:e=>H(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>a(!1),children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:async()=>{try{const e={orderId:d.id,status:h,deliveryInstructions:U};if("READY"===h||"READY_FOR_DELIVERY"===h){if(!M)return void f("Driver ID is required for this status");if(!V)return void f("Schedule time is required for this status");e.driverId=parseInt(M),e.scheduleTime=V}await $e.mutateAsync(e)}catch(e){f(e.message)}},variant:"contained",color:"primary",disabled:$e.isPending,children:$e.isPending?"Updating...":"Update"})]})]}),(0,Z.jsxs)(Qe.A,{open:o,onClose:()=>l(!1),children:[(0,Z.jsx)(Ze.A,{children:"Cancel Order"}),(0,Z.jsxs)(Je.A,{children:[(0,Z.jsx)(m.A,{children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,Z.jsx)(se.A,{fullWidth:!0,label:"Cancellation Reason",value:O,onChange:e=>B(e.target.value),multiline:!0,rows:3,sx:{mt:2},required:!0})]}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>l(!1),disabled:Re.isPending||Re.isLoading,children:"No"}),(0,Z.jsx)(X.A,{onClick:async()=>{try{if(!ve)return void f("User profile not found. Please try again.");Re.mutate({orderId:d.id,cancelMessage:O,cancelledByUserId:ve})}catch(e){f(e.message)}},variant:"contained",color:"error",disabled:!O.trim()||Re.isPending||Re.isLoading,startIcon:Re.isPending||Re.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:Re.isPending||Re.isLoading?"Cancelling...":"Yes, Cancel Order"})]})]}),(0,Z.jsxs)(Qe.A,{open:Q,onClose:()=>J(!1),maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:0===re?"Delete Order Item":"Edit Order Item"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsxs)(m.A,{variant:"subtitle1",children:["Product: ",ee?.product?.name||"N/A"]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,children:(0,Z.jsx)(se.A,{fullWidth:!0,label:"Quantity",type:"number",value:re,onChange:e=>ie(parseInt(e.target.value)||0),inputProps:{min:0}})})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>J(!1),children:"Cancel"}),(0,Z.jsx)(X.A,{onClick:async()=>{try{await ze.mutateAsync({orderId:ee.orderId,itemId:ee.id,quantity:re,price:ee.product?.inventoryItems?.edges[0]?.node?.price||0})}catch(e){f(e.message)}},variant:"contained",color:0===re?"error":"primary",disabled:ze.isLoading,children:ze.isLoading?"Updating...":0===re?"Delete":"Update"})]})]}),(0,Z.jsxs)(Qe.A,{open:oe,onClose:()=>le(!1),maxWidth:"xs",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:"Download Orders"}),(0,Z.jsxs)(Je.A,{children:[(0,Z.jsxs)(m.A,{variant:"body1",gutterBottom:!0,children:["Download ",We.length," filtered orders"]}),(0,Z.jsxs)(m.A,{variant:"body2",color:"textSecondary",gutterBottom:!0,children:[b&&`Search term: ${b}`,"ALL"!==I&&`\nStatus: ${I}`]}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,Z.jsx)(je.Ay,{item:!0,xs:6,children:(0,Z.jsx)(X.A,{fullWidth:!0,variant:"outlined",onClick:()=>Ne(We,"pdf"),startIcon:(0,Z.jsx)(Gn.A,{}),children:"PDF"})}),(0,Z.jsx)(je.Ay,{item:!0,xs:6,children:(0,Z.jsx)(X.A,{fullWidth:!0,variant:"outlined",onClick:()=>Ne(We,"docx"),startIcon:(0,Z.jsx)(Gn.A,{}),children:"DOCX"})})]})]}),(0,Z.jsx)(Xe.A,{children:(0,Z.jsx)(X.A,{onClick:()=>le(!1),children:"Cancel"})})]}),(0,Z.jsx)(mr.A,{open:G.open,autoHideDuration:6e3,onClose:()=>Y({...G,open:!1}),children:(0,Z.jsx)(ne.A,{onClose:()=>Y({...G,open:!1}),severity:G.severity,sx:{width:"100%"},children:G.message})})]})}):(0,Z.jsx)(mn,{children:(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:De?.message||we?.message||"An error occurred"})})},ti=[{value:"ACTIVE",label:"Active"},{value:"INACTIVE",label:"Inactive"}],ri=()=>{const{userProfile:e,setUserProfile:s}=K(),[t,r]=(0,x.useState)(""),[n,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,rt.T)();r(e.sub)}catch(e){}})()}),[]);const{data:g,isLoading:j}=(0,u.I)({queryKey:["getUserProfile",t],queryFn:async()=>{const e=await C(k,{userId:t});return e?.getUserProfile&&s(e.getUserProfile),e},enabled:!!t}),y=g?.getUserProfile?.stores?.edges?.[0]?.node?.id,{data:f,isLoading:b,error:v,refetch:I}=(0,u.I)({queryKey:["driversByStore",y],queryFn:()=>C("\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:y}),enabled:!!y&&l}),{data:S,isLoading:w,error:P,refetch:E}=(0,u.I)({queryKey:["storeOrders",y],queryFn:async()=>(await C(F,{storeId:y})).getOrdersByStore||[],enabled:!!y}),D=(e,s)=>{o((t=>({...t,[e]:s})))},L=e=>({PENDING:"warning",PROCESSING:"info",READY_FOR_DELIVERY:"primary",OUT_FOR_DELIVERY:"secondary",DELIVERED:"success",CANCELLED:"error",ACTIVE:"success",INACTIVE:"error",BUSY:"warning"}[e]||"default"),$=(e,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 r=new Date(s);return r.setMonth(r.getMonth()-1),t>=r;default:return!0}}))}return t},z=e=>e?a.driverStatus?e.filter((e=>e.status===a.driverStatus)):e:[],R=b||w||j,T=v||P||c;return(0,Z.jsx)(mn,{children:(0,Z.jsxs)(p.A,{sx:{p:3},children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Delivery Partners"}),c&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:c}),j&&(0,Z.jsx)(ne.A,{severity:"info",sx:{mb:2},children:"Loading user profile..."}),(0,Z.jsxs)(ae.A,{sx:{p:3,mb:3},children:[(0,Z.jsx)(m.A,{variant:"h6",gutterBottom:!0,children:"Filters"}),(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:4,children:(0,Z.jsxs)(se.A,{select:!0,fullWidth:!0,label:"Driver Status",value:a.driverStatus,onChange:e=>D("driverStatus",e.target.value),children:[(0,Z.jsx)(Ae.A,{value:"",children:"All Statuses"}),ti.map((e=>(0,Z.jsx)(Ae.A,{value:e.value,children:e.label},e.value)))]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:4,children:(0,Z.jsxs)(se.A,{select:!0,fullWidth:!0,label:"Order Status",value:a.orderStatus,onChange:e=>D("orderStatus",e.target.value),children:[(0,Z.jsx)(Ae.A,{value:"",children:"All Statuses"}),Rr.map((e=>(0,Z.jsx)(Ae.A,{value:e.value,children:e.label},e.value)))]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,sm:4,children:(0,Z.jsxs)(se.A,{select:!0,fullWidth:!0,label:"Date Range",value:a.dateRange,onChange:e=>D("dateRange",e.target.value),children:[(0,Z.jsx)(Ae.A,{value:"all",children:"All Time"}),(0,Z.jsx)(Ae.A,{value:"today",children:"Today"}),(0,Z.jsx)(Ae.A,{value:"week",children:"Last 7 Days"}),(0,Z.jsx)(Ae.A,{value:"month",children:"Last 30 Days"})]})}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,children:[(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:(0,Z.jsx)(pr.A,{}),onClick:()=>{d(!0),I(),E()},disabled:!y||j,children:j?"Loading Profile...":"Get Data"}),!y&&!j&&(0,Z.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,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",p:3},children:(0,Z.jsx)(A.A,{})}):T?(0,Z.jsx)(ne.A,{severity:"error",children:v?.message||P?.message||"An error occurred while fetching data"}):l?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(m.A,{variant:"h6",gutterBottom:!0,children:["Delivery Partners (",z(f?.getStoreDrivers||[]).length,")"]}),(0,Z.jsx)(ar.A,{component:ae.A,children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Driver ID"}),(0,Z.jsx)(cr.A,{children:"Name"}),(0,Z.jsx)(cr.A,{children:"Email"}),(0,Z.jsx)(cr.A,{children:"Phone"}),(0,Z.jsx)(cr.A,{children:"Status"}),(0,Z.jsx)(cr.A,{children:"Orders"}),(0,Z.jsx)(cr.A,{})]})}),(0,Z.jsxs)(xr.A,{children:[z(f?.getStoreDrivers||[]).map((e=>(0,Z.jsxs)(x.Fragment,{children:[(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e?.userId}),(0,Z.jsx)(cr.A,{children:e.name}),(0,Z.jsx)(cr.A,{children:e?.driver?.email}),(0,Z.jsx)(cr.A,{children:e?.driver?.mobile}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:e?.driver?.active?"Active":"Inactive",color:L(e?.driver?.active),size:"small"})}),(0,Z.jsx)(cr.A,{children:$(S||[],e?.userId).length}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(he.A,{size:"small",onClick:()=>i(n===e?.userId?null:e?.userId),children:n===e?.userId?(0,Z.jsx)(An.A,{}):(0,Z.jsx)(gn.A,{})})})]}),n===e?.userId&&(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:7,children:(0,Z.jsxs)(p.A,{sx:{p:2},children:[(0,Z.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:["Orders for ",e.name,":"]}),(0,Z.jsxs)(or.A,{size:"small",children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Order ID"}),(0,Z.jsx)(cr.A,{children:"Date"}),(0,Z.jsx)(cr.A,{children:"Customer"}),(0,Z.jsx)(cr.A,{children:"Total"}),(0,Z.jsx)(cr.A,{children:"Status"})]})}),(0,Z.jsx)(xr.A,{children:$(S||[],e?.userId).length>0?$(S||[],e?.userId).map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.id}),(0,Z.jsx)(cr.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,Z.jsx)(cr.A,{children:e.user?.name}),(0,Z.jsxs)(cr.A,{children:["₹",e.totalAmount]}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(Fe.A,{label:Rr.find((s=>s.value===e.status))?.label||e.status,color:L(e.status),size:"small"})})]},e.id))):(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:5,align:"center",children:"No orders found for this driver with the current filters."})})})]})]})})})]},e?.userId))),0===z(f?.getStoreDrivers||[]).length&&(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:7,align:"center",children:"No delivery partners found with the current filters."})})]})]})})]}):(0,Z.jsx)(ne.A,{severity:"info",children:'Click the "Get Data" button to fetch delivery partners and their orders.'})]})})};var ni=t(69279);const ii=x.memo((e=>{let{open:s,onClose:t,selectedItem:r,onUpdate:n,isLoading:i}=e;const[a,o]=x.useState(""),[l,d]=x.useState(""),[c,u]=x.useState(!0),[h,g]=x.useState(!0),[j,y]=x.useState("");x.useEffect((()=>{r&&(o(r.price?r.price.toString():""),d(r.quantity?r.quantity.toString():""),u(void 0===r.isAvailable||r.isAvailable),g(void 0===r.isListed||r.isListed))}),[r]);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,Z.jsxs)(Qe.A,{open:s,onClose:()=>{y(""),t()},maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:"Edit Inventory Item"}),(0,Z.jsxs)(Je.A,{children:[r&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[r.product?.image&&(0,Z.jsx)(fe.A,{component:"img",sx:{width:80,height:80,objectFit:"contain",mr:2},image:r.product.image,alt:r.product.name}),(0,Z.jsxs)(p.A,{children:[(0,Z.jsx)(m.A,{variant:"subtitle1",children:(0,Z.jsx)("strong",{children:r.product?.name})}),(0,Z.jsx)(m.A,{variant:"body2",color:"text.secondary",children:r.product?.category?.name||"Uncategorized"})]})]}),(0,Z.jsx)(As.A,{sx:{my:2}}),(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsx)("label",{htmlFor:"edit-price-input",style:b,children:"Price ($)"}),(0,Z.jsx)("input",{id:"edit-price-input",type:"number",value:a,onChange:e=>o(e.target.value),min:"0",step:"0.01",style:f}),(0,Z.jsx)("label",{htmlFor:"edit-quantity-input",style:b,children:"Quantity"}),(0,Z.jsx)("input",{id:"edit-quantity-input",type:"number",value:l,onChange:e=>d(e.target.value),min:"0",style:f}),(0,Z.jsxs)(p.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(Ne.A,{checked:c,onChange:e=>u(e.target.checked),color:"primary"}),label:"Available (In Stock)"}),(0,Z.jsx)(Ue.A,{control:(0,Z.jsx)(Ne.A,{checked:h,onChange:e=>g(e.target.checked),color:"primary"}),label:"Listed (Visible to Customers)"})]})]})]}),j&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mt:2},children:j})]}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{y(""),t()},disabled:i,children:"Cancel"}),(0,Z.jsx)(X.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(""),n({inventoryId:r.id,price:a,quantity:l,isAvailable:c,isListed:h}))},disabled:i,startIcon:i?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:i?"Updating...":"Update"})]})]})})),ai=x.memo((e=>{let{open:s,onClose:t,storeId:r,availableProducts:n,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),g=(0,x.useRef)(null),j=e=>{const{name:s,value:t}=e.target;u((e=>({...e,[s]:t})))},y=x.useMemo((()=>n.filter((e=>e.name.toLowerCase().includes(c.searchInput.toLowerCase())))),[n,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,Z.jsxs)(Qe.A,{open:s,onClose:()=>{t(),f()},maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:"Add Product to Inventory"}),(0,Z.jsxs)(Je.A,{children:[(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsx)("label",{htmlFor:"searchInput",style:v,children:"Search Product"}),(0,Z.jsxs)("div",{style:{position:"relative"},children:[(0,Z.jsx)("input",{id:"searchInput",name:"searchInput",type:"text",placeholder:"Start typing to search...",value:c.searchInput,onChange:e=>{j(e),h(!0)},onFocus:()=>h(!0),style:b,ref:g}),a&&(0,Z.jsx)(A.A,{size:20,style:{position:"absolute",right:"10px",top:"50%",transform:"translateY(-50%)"}})]}),m&&y.length>0&&(0,Z.jsx)("div",{style:{position:"absolute",width:g.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,Z.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,Z.jsx)("div",{children:e.name}),(0,Z.jsx)("div",{style:{fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)"},children:e.category.name})]},e.id)))})]}),(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsx)("label",{htmlFor:"price",style:v,children:"Price ($)"}),(0,Z.jsx)("input",{id:"price",name:"price",type:"number",value:c.price,onChange:j,min:"0",step:"0.01",style:b})]}),(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsx)("label",{htmlFor:"quantity",style:v,children:"Quantity"}),(0,Z.jsx)("input",{id:"quantity",name:"quantity",type:"number",value:c.quantity,onChange:j,min:"0",style:b})]}),(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsx)("label",{htmlFor:"measurement",style:v,children:"Measurement"}),(0,Z.jsx)("input",{id:"measurement",name:"measurement",type:"number",value:c.measurement,onChange:j,min:"0",style:b})]}),(0,Z.jsxs)(p.A,{sx:{mt:2},children:[(0,Z.jsx)("label",{htmlFor:"unit",style:v,children:"Unit"}),(0,Z.jsxs)("select",{id:"unit",name:"unit",value:c.unit,onChange:j,style:{...b,backgroundColor:"transparent",appearance:"auto",height:"40px"},children:[(0,Z.jsx)("option",{value:"",children:"None"}),(0,Z.jsx)("option",{value:"1",children:"Grams (g)"}),(0,Z.jsx)("option",{value:"2",children:"Kilograms (kg)"}),(0,Z.jsx)("option",{value:"3",children:"Milliliters (ml)"}),(0,Z.jsx)("option",{value:"4",children:"Liters (L)"}),(0,Z.jsx)("option",{value:"5",children:"Pieces (pcs)"})]})]}),o&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mt:2},children:o})]}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{t(),f()},disabled:a,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",onClick:()=>{l&&i({storeId:r,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,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:a?"Adding Product...":"Add Product"})]})]})})),oi=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:r}=K(),[n,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(null),[c,g]=(0,x.useState)(""),[j,y]=(0,x.useState)(""),[f,b]=(0,x.useState)(""),[v,I]=(0,x.useState)(!1),[S,w]=(0,x.useState)(10),[P,k]=(0,x.useState)(1),[F]=(0,x.useState)(10),[E,D]=(0,x.useState)("all"),[L,$]=(0,x.useState)([]),[z,R]=(0,x.useState)(!1),[T,W]=(0,x.useState)(!0);(0,x.useRef)(null),(0,x.useRef)(null);(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,rt.T)();s(e.sub)}catch(e){}})()}),[]);const{data:q,isLoading:O}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await C("\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&&r(s.getUserProfile),s},enabled:!!e}),{data:B,isLoading:U,error:N,refetch:M}=(0,u.I)({queryKey:["storeWithInventory",t?.id],queryFn:()=>C("\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)((()=>{B&&B.products&&W(!1)}),[B]);const _=B?.storesByManager&&B.storesByManager[0],V=_?.inventory?.edges?.map((e=>e.node))||[],H=B?.products||[],G=x.useMemo((()=>V.filter((e=>{const s=""===f||e.product?.name?.toLowerCase().includes(f.toLowerCase())||e.product?.description?.toLowerCase().includes(f.toLowerCase()),t=!v||e.quantity<=S,r="all"===E||e.product?.category?.name===E;return s&&t&&r}))),[V,f,v,S,E]),Y=x.useMemo((()=>G.slice((P-1)*F,P*F)),[G,P,F]);(0,x.useEffect)((()=>{const e=[...new Set(V.map((e=>e.product?.category?.name||"Uncategorized")).filter(Boolean))].sort();JSON.stringify(e)!==JSON.stringify(L)&&$(e)}),[V]);const Q=(0,Is.n)({mutationFn:e=>{let{inventoryId:s,price:t,quantity:r,isAvailable:n,isListed:i}=e;return C("\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(r,10),isAvailable:void 0!==n?n:null,isListed:void 0!==i?i:null})},onSuccess:()=>{M(),o(!1),i(null),y("Inventory item updated successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error updating inventory: ${e.message}`)}}),J=(0,Is.n)({mutationFn:e=>{let{storeId:s,productId:t,price:r,quantity:n,measurement:i,unit:a}=e;return C("\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(r),quantity:parseInt(n,10),measurement:i?parseInt(i,10):null,unit:a||null})},onSuccess:()=>{M(),R(!1),y("Product added to inventory successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error adding product: ${e.message}`)}}),ee=x.memo((e=>{let{searchTerm:s,setSearchTerm:t,filterCategory:r,setFilterCategory:n,lowStockOnly:i,setLowStockOnly:a,lowStockThreshold:o,setLowStockThreshold:l,categories:d}=e;return(0,Z.jsx)(ae.A,{elevation:3,sx:{p:3,mb:4},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:4,children:(0,Z.jsx)(se.A,{label:"Search Products",variant:"outlined",size:"small",value:s,onChange:e=>t(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,Z.jsx)(pr.A,{sx:{mr:1,color:"text.secondary"}})}})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:3,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,size:"small",children:[(0,Z.jsx)(ur.A,{id:"category-select-label",children:"Category"}),(0,Z.jsxs)(Oe.A,{labelId:"category-select-label",id:"category-select",value:r,label:"Category",onChange:e=>n(e.target.value),children:[(0,Z.jsx)(Ae.A,{value:"all",children:"All Categories"}),d.map((e=>(0,Z.jsx)(Ae.A,{value:e,children:e},e)))]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:3,children:(0,Z.jsxs)(Cs.A,{fullWidth:!0,size:"small",children:[(0,Z.jsx)(ur.A,{id:"stock-filter-label",children:"Stock Filter"}),(0,Z.jsxs)(Oe.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,Z.jsx)(Ae.A,{value:"false",children:"All Items"}),(0,Z.jsx)(Ae.A,{value:"true",children:"Low Stock Only"})]})]})}),(0,Z.jsx)(je.Ay,{item:!0,xs:12,md:2,children:(0,Z.jsx)(se.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 O||U?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})})}):N?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4},children:(0,Z.jsxs)(ne.A,{severity:"error",children:["Error loading inventory data: ",N.message]})})}):(0,Z.jsx)(mn,{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Inventory Management"}),(0,Z.jsx)(ee,{searchTerm:f,setSearchTerm:b,filterCategory:E,setFilterCategory:D,lowStockOnly:v,setLowStockOnly:I,lowStockThreshold:S,setLowStockThreshold:w,categories:L}),j&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:j}),c&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:c}),(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",children:"Inventory Items"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:J.isPending||J.isPending?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):(0,Z.jsx)(Ce.A,{}),onClick:()=>R(!0),disabled:J.isPending||J.isPending,children:J.isPending||J.isPending?"Adding...":"Add Product"})]}),T?(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,Z.jsx)(A.A,{})}):0===G.length?(0,Z.jsx)(ne.A,{severity:"info",sx:{my:2},children:"No inventory items match your filters."}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ar.A,{component:ae.A,variant:"outlined",children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{}),(0,Z.jsx)(cr.A,{children:"Product"}),(0,Z.jsx)(cr.A,{children:"Category"}),(0,Z.jsx)(cr.A,{children:"Price"}),(0,Z.jsx)(cr.A,{children:"Quantity"}),(0,Z.jsx)(cr.A,{children:"Available"}),(0,Z.jsx)(cr.A,{children:"Listed"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:Y.map((e=>(0,Z.jsxs)(x.Fragment,{children:[(0,Z.jsxs)(dr.A,{sx:{backgroundColor:e?.isAvailable?"inherit":"rgba(255, 0, 0, 0.1)"},children:[(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(he.A,{size:"small",onClick:()=>{return s=e.id,void d(l===s?null:s);var s},children:l===e.id?(0,Z.jsx)(An.A,{}):(0,Z.jsx)(gn.A,{})})}),(0,Z.jsx)(cr.A,{children:(0,Z.jsxs)(p.A,{sx:{display:"flex",alignItems:"center"},children:[e.product?.image&&(0,Z.jsx)(fe.A,{component:"img",sx:{width:50,height:50,objectFit:"contain",mr:2},image:e.product.image,alt:e.product.name}),(0,Z.jsx)(m.A,{children:e.product?.name})]})}),(0,Z.jsx)(cr.A,{children:e.product?.category?.name||"Uncategorized"}),(0,Z.jsxs)(cr.A,{children:["$",e.price.toFixed(2)]}),(0,Z.jsx)(cr.A,{children:e.quantity}),(0,Z.jsx)(cr.A,{children:e?.isAvailable?(0,Z.jsx)(Fe.A,{label:"In Stock",color:"success",size:"small"}):(0,Z.jsx)(Fe.A,{label:"Low Stock",color:"error",size:"small"})}),(0,Z.jsx)(cr.A,{children:e?.isListed?(0,Z.jsx)(Fe.A,{label:"Listed",color:"success",size:"small"}):(0,Z.jsx)(Fe.A,{label:"Not Listed",color:"error",size:"small"})}),(0,Z.jsx)(cr.A,{children:(0,Z.jsx)(he.A,{onClick:()=>(e=>{e&&(i(e),o(!0))})(e),size:"small",color:"primary",disabled:Q.isPending||Q.isLoading||J.isPending||J.isLoading,children:(0,Z.jsx)(hr.A,{})})})]}),(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{sx:{p:0},colSpan:7,children:(0,Z.jsx)(Be.A,{in:l===e.id,timeout:"auto",unmountOnExit:!0,children:(0,Z.jsx)(p.A,{sx:{p:3,backgroundColor:"rgba(0, 0, 0, 0.03)"},children:(0,Z.jsxs)(je.Ay,{container:!0,spacing:2,children:[(0,Z.jsxs)(je.Ay,{item:!0,xs:12,md:6,children:[(0,Z.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,Z.jsx)("strong",{children:"Description:"})," ",e.product?.description||"No description available"]}),(0,Z.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,Z.jsx)("strong",{children:"Product ID:"})," ",e.product?.id]})]}),(0,Z.jsxs)(je.Ay,{item:!0,xs:12,md:6,children:[(0,Z.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,Z.jsx)("strong",{children:"Last Updated:"})," ",e.updatedAt?new Date(e.updatedAt).toLocaleString():"N/A"]}),(0,Z.jsxs)(m.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,Z.jsx)("strong",{children:"Measurement:"})," ",e.measurement&&e.unit?`${e.measurement} ${e.unit}`:"N/A"]})]})]})})})})})]},e.id)))})]})}),(0,Z.jsx)(p.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,Z.jsx)(ni.A,{count:Math.ceil(G.length/F),page:P,onChange:(e,s)=>k(s),color:"primary"})})]})]}),(0,Z.jsx)(ii,{open:a,onClose:()=>{o(!1),g("")},selectedItem:n,onUpdate:e=>Q.mutate(e),isLoading:Q.isPending}),(0,Z.jsx)(ai,{open:z,onClose:()=>R(!1),storeId:_?.id,availableProducts:H,onAdd:J.mutate,isLoading:J.isPending,errorMessage:c})]})})},li=e=>{let{open:s,onClose:t,selectedLocationCode:r,onUpdate:n,isLoading:i,existingCodes:a}=e;const[o,l]=(0,x.useState)({location:"",code:""}),[d,c]=(0,x.useState)("");(0,x.useEffect)((()=>{l(r?{location:r.location||"",code:r.code||""}:{location:"",code:""}),c("")}),[r,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,Z.jsxs)(Qe.A,{open:s,onClose:u,maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:r?"Edit Location Code":"Add New Location Code"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(p.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Z.jsx)(se.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,Z.jsx)(se.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,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:u,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>{(o.location.trim()?o.code.trim()?!a.some((e=>e.code.toLowerCase()===o.code.toLowerCase()&&(!r||e.id!==r.id)))||(c("This code already exists for this store"),0):(c("Code is required"),0):(c("Location is required"),0))&&n({id:r?.id,...o})},disabled:i,startIcon:i?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},di=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:r}=K(),[n,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,g]=(0,x.useState)(""),[j,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,rt.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await C("\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&&r(s.getUserProfile),s},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,u.I)({queryKey:["storeWithLocationCodes",t?.id],queryFn:()=>C("\n query GetStoreWithLocationCodes($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:t?.id}),enabled:!!t?.id}),w=v?.storesByManager&&v.storesByManager[0],{data:P,isLoading:k,error:F,refetch:E}=(0,u.I)({queryKey:["getStoreLocationCodesByStore",w?.id],queryFn:()=>C("\n query GetStoreLocationCodesByStore($storeId: Int!) {\n getStoreLocationCodesByStore(storeId: $storeId) {\n id\n location\n code\n }\n }\n",{storeId:w?.id}),enabled:!!w?.id}),D=P?.getStoreLocationCodesByStore||[],L=(0,Is.n)({mutationFn:e=>{if(!w?.id)throw new Error("Store not found");return C("\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:()=>{E(),o(!1),i(null),y("Location code updated successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error updating location code: ${e.message}`),setTimeout((()=>g("")),5e3)}}),$=(0,Is.n)({mutationFn:e=>C("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{E(),d(!1),i(null),y("Location code deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error deleting location code: ${e.message}`)}}),z=(0,Is.n)({mutationFn:e=>C("\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:w.id}}),onSuccess:()=>{E(),o(!1),i(null),y("Location code added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error adding location code: ${e.message}`)}});return b||I||k?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})})}):S||F?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4},children:(0,Z.jsxs)(ne.A,{severity:"error",children:["Error loading data: ",S?.message||F?.message]})})}):(0,Z.jsx)(mn,{children:(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),j&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:j}),c&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:c}),(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",children:"Location Codes"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:z.isPending||z.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):(0,Z.jsx)(Ce.A,{}),onClick:()=>{i(null),o(!0)},disabled:z.isPending||z.isLoading,children:z.isPending||z.isLoading?"Adding...":"Add Location Code"})]}),0===D.length?(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Location"}),(0,Z.jsx)(cr.A,{children:"Code"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:(0,Z.jsx)(dr.A,{children:(0,Z.jsx)(cr.A,{colSpan:3,align:"center",children:(0,Z.jsx)(ne.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})}):(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Location"}),(0,Z.jsx)(cr.A,{children:"Code"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:D.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.location}),(0,Z.jsx)(cr.A,{children:e.code}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||z.isPending||z.isLoading,children:(0,Z.jsx)(hr.A,{})}),(0,Z.jsx)(he.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||z.isPending||z.isLoading,children:(0,Z.jsx)(fr.A,{})})]})]},e.id)))})]})})]}),(0,Z.jsx)(li,{open:a,onClose:()=>{o(!1),i(null),g("")},selectedLocationCode:n,onUpdate:e=>{n?L.mutate(e):z.mutate(e)},isLoading:L.isPending||L.isLoading||z.isPending||z.isLoading,existingCodes:D}),(0,Z.jsxs)(Qe.A,{open:l,onClose:()=>{d(!1),i(null),g("")},children:[(0,Z.jsx)(Ze.A,{children:"Delete Location Code"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(m.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{d(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:n.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})})},ci=e=>{let{open:s,onClose:t,selectedPickupAddress:r,onUpdate:n,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)((()=>{r?(l({address:r.address||""}),h(!0)):(l({address:""}),h(!1)),c("")}),[r]);return(0,Z.jsxs)(Qe.A,{open:s,onClose:t,maxWidth:"sm",fullWidth:!0,children:[(0,Z.jsx)(Ze.A,{children:r?"Edit Pickup Address":"Add New Pickup Address"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsxs)(p.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,Z.jsx)(qt,{value:o.address,onChange:e=>{l((s=>({...s,address:e}))),c("")},onValidAddress:h}),d&&(0,Z.jsx)(m.A,{color:"error",variant:"caption",children:d})]})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:t,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",onClick:()=>{(o.address.trim()?u?!a.some((e=>e.address.toLowerCase()===o.address.toLowerCase()&&(!r||e.id!==r.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))&&n({id:r?.id,...o})},disabled:i||!u,startIcon:i?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},xi=()=>{const[e,s]=(0,x.useState)(""),{userProfile:t,setUserProfile:r}=K(),[n,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[l,d]=(0,x.useState)(!1),[c,g]=(0,x.useState)(""),[j,y]=(0,x.useState)("");(0,x.useEffect)((()=>{(async()=>{try{const e=await(0,rt.T)();s(e.sub)}catch(e){}})()}),[]);const{data:f,isLoading:b}=(0,u.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const s=await C("\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&&r(s.getUserProfile),s},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,u.I)({queryKey:["storeWithPickupAddresses",t?.id],queryFn:()=>C("\n query GetStoreWithPickupAddresses($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:t?.id}),enabled:!!t?.id}),w=v?.storesByManager&&v.storesByManager[0],{data:P,isLoading:k,error:F,refetch:E}=(0,u.I)({queryKey:["getPickupAddressesByStore",w?.id],queryFn:()=>C("\n query GetPickupAddressesByStore($storeId: Int!) {\n getPickupAddressesByStore(storeId: $storeId) {\n id\n storeId\n address\n }\n }\n",{storeId:w?.id}),enabled:!!w?.id}),D=P?.getPickupAddressesByStore||[],L=(0,Is.n)({mutationFn:e=>C("\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(),o(!1),i(null),y("Pickup address updated successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error updating pickup address: ${e.message}`)}}),$=(0,Is.n)({mutationFn:e=>C("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{E(),d(!1),i(null),y("Pickup address deleted successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error deleting pickup address: ${e.message}`)}}),z=(0,Is.n)({mutationFn:e=>C("\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:w.id}}),onSuccess:()=>{E(),o(!1),i(null),y("Pickup address added successfully"),setTimeout((()=>y("")),3e3)},onError:e=>{g(`Error adding pickup address: ${e.message}`)}});return b||I||k?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,Z.jsx)(A.A,{})})}):S||F?(0,Z.jsx)(mn,{children:(0,Z.jsx)(h.A,{sx:{mt:4},children:(0,Z.jsxs)(ne.A,{severity:"error",children:["Error loading data: ",S?.message||F?.message]})})}):(0,Z.jsx)(mn,{children:(0,Z.jsxs)(h.A,{children:[(0,Z.jsx)(m.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),j&&(0,Z.jsx)(ne.A,{severity:"success",sx:{mb:2},children:j}),c&&(0,Z.jsx)(ne.A,{severity:"error",sx:{mb:2},children:c}),(0,Z.jsxs)(ae.A,{elevation:3,sx:{p:3,mb:4},children:[(0,Z.jsxs)(p.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,Z.jsx)(m.A,{variant:"h5",children:"Pickup Addresses"}),(0,Z.jsx)(X.A,{variant:"contained",color:"primary",startIcon:z.isPending||z.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):(0,Z.jsx)(Ce.A,{}),onClick:()=>{i(null),o(!0)},disabled:z.isPending||z.isLoading,children:z.isPending||z.isLoading?"Adding...":"Add Pickup Address"})]}),0===D.length?(0,Z.jsx)(ne.A,{severity:"info",sx:{my:2},children:"No pickup addresses found. Add your first pickup address to get started."}):(0,Z.jsx)(ar.A,{children:(0,Z.jsxs)(or.A,{children:[(0,Z.jsx)(lr.A,{children:(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:"Address"}),(0,Z.jsx)(cr.A,{children:"Actions"})]})}),(0,Z.jsx)(xr.A,{children:D.map((e=>(0,Z.jsxs)(dr.A,{children:[(0,Z.jsx)(cr.A,{children:e.address}),(0,Z.jsxs)(cr.A,{children:[(0,Z.jsx)(he.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||z.isPending||z.isLoading,children:(0,Z.jsx)(hr.A,{})}),(0,Z.jsx)(he.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:L.isPending||L.isLoading||$.isPending||$.isLoading||z.isPending||z.isLoading,children:(0,Z.jsx)(fr.A,{})})]})]},e.id)))})]})})]}),(0,Z.jsx)(ci,{open:a,onClose:()=>{o(!1),i(null),g("")},selectedPickupAddress:n,onUpdate:e=>{n?L.mutate(e):z.mutate(e)},isLoading:L.isPending||L.isLoading||z.isPending||z.isLoading,existingAddresses:D}),(0,Z.jsxs)(Qe.A,{open:l,onClose:()=>{d(!1),i(null),g("")},children:[(0,Z.jsx)(Ze.A,{children:"Delete Pickup Address"}),(0,Z.jsx)(Je.A,{children:(0,Z.jsx)(m.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,Z.jsxs)(Xe.A,{children:[(0,Z.jsx)(X.A,{onClick:()=>{d(!1),i(null)},disabled:$.isPending||$.isLoading,children:"Cancel"}),(0,Z.jsx)(X.A,{variant:"contained",color:"error",onClick:()=>$.mutate({id:n.id}),disabled:$.isPending||$.isLoading,startIcon:$.isPending||$.isLoading?(0,Z.jsx)(A.A,{size:18,color:"inherit"}):null,children:$.isPending||$.isLoading?"Deleting...":"Delete"})]})]})]})})},ui=()=>{const{user:e}=K();return(0,Z.jsxs)(o.A,{theme:c,children:[(0,Z.jsx)(l.Ay,{}),(0,Z.jsxs)(d.BV,{children:[(0,Z.jsx)(d.qh,{path:Ms,element:(0,Z.jsx)(Dn,{})}),(0,Z.jsx)(d.qh,{path:Js,element:(0,Z.jsx)(Zt,{})}),(0,Z.jsx)(d.qh,{path:_s,element:(0,Z.jsx)(pt,{})}),(0,Z.jsx)(d.qh,{path:"/",element:(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsx)(Yt,{children:(0,Z.jsx)(Rn,{})})})}),(0,Z.jsx)(d.qh,{path:Xs,element:(0,Z.jsx)(Yt,{children:(0,Z.jsx)(Vn,{})})}),(0,Z.jsx)(d.qh,{path:`${Vs}/*`,element:(0,Z.jsx)(Qt,{role:"admin",children:(0,Z.jsx)(rn,{})})}),(0,Z.jsx)(d.qh,{path:Hs,element:(0,Z.jsx)(Qt,{role:"user",children:(0,Z.jsx)(Rn,{})})}),(0,Z.jsx)(d.qh,{path:Gs,element:(0,Z.jsx)(Qt,{role:"delivery_agent",children:(0,Z.jsx)(on,{})})}),(0,Z.jsx)(d.qh,{path:Qs,element:(0,Z.jsx)(Qt,{role:"user",children:(0,Z.jsx)(fn,{})})}),(0,Z.jsx)(d.qh,{path:Zs,element:(0,Z.jsx)(Qt,{children:(0,Z.jsx)(Sn,{})})}),(0,Z.jsx)(d.qh,{path:Ks,element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(hn,{})})}),(0,Z.jsx)(d.qh,{path:`${Ks}/orders`,element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(si,{})})}),(0,Z.jsx)(d.qh,{path:"/store_manager/delivery-partners",element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(ri,{})})}),(0,Z.jsx)(d.qh,{path:"/store_manager/inventory",element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(oi,{})})}),(0,Z.jsx)(d.qh,{path:"/store_manager/delivery-fees",element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(kn,{})})}),(0,Z.jsx)(d.qh,{path:"/store_manager/location-codes",element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(di,{})})}),(0,Z.jsx)(d.qh,{path:"/store_manager/pickup-addresses",element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(xi,{})})}),(0,Z.jsx)(d.qh,{path:"/store_manager/payment-settings",element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(En,{})})}),(0,Z.jsx)(d.qh,{path:`${Ks}/*`,element:(0,Z.jsx)(Qt,{role:"store_manager",children:(0,Z.jsx)(wn,{})})}),(0,Z.jsx)(d.qh,{path:"*",element:(0,Z.jsx)(Cn,{})})]})]})};var mi=t(85072),hi=t.n(mi),pi=t(97825),Ai=t.n(pi),gi=t(77659),ji=t.n(gi),yi=t(55056),fi=t.n(yi),bi=t(10540),vi=t.n(bi),Ii=t(41113),Si=t.n(Ii),Ci=t(14767),wi={};wi.styleTagTransform=Si(),wi.setAttributes=fi(),wi.insert=ji().bind(null,"head"),wi.domAPI=Ai(),wi.insertStyleElement=vi();hi()(Ci.A,wi);Ci.A&&Ci.A.locals&&Ci.A.locals;const Pi=window.location.href?.includes("http://localhost");let ki="us-east-1_6NtAulnkj",Fi="1361ghg1fpt2grmchv7ttf8bbj";Pi&&(ki="us-east-1_ehhI7OmUk",Fi="1okaltgd288h6sjgc5cedlth45");const Ei={Auth:{Cognito:{region:"us-east-1",userPoolId:ki,userPoolClientId:Fi,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(Ei);const Di=new i.E({defaultOptions:{queries:{retry:3,refetchOnWindowFocus:!1},mutations:{retry:0}}});(0,r.createRoot)(document.getElementById("root")).render((0,Z.jsx)(a.Ht,{client:Di,children:(0,Z.jsx)(n.Kd,{children:(0,Z.jsx)(ui,{})})}))},14767:(e,s,t)=>{t.d(s,{A:()=>o});var r=t(71354),n=t.n(r),i=t(76314),a=t.n(i)()(n());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,r,n)=>{if(!t){var i=1/0;for(c=0;c=n)&&Object.keys(o.O).every((e=>o.O[e](t[l])))?t.splice(l--,1):(a=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[t,r,n]},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,r){if(1&r&&(e=this(e)),8&r)return e;if("object"==typeof e&&e){if(4&r&&e.__esModule)return e;if(16&r&&"function"==typeof e.then)return e}var n=Object.create(null);o.r(n);var i={};s=s||[null,t({}),t([]),t(t)];for(var a=2&r&&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(n,i),n},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),r={},n="indimitra-web:",o.l=(e,s,t,i)=>{if(r[e])r[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 n=r[e];if(delete r[e],a.parentNode&&a.parentNode.removeChild(a),n&&n.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 r=o.o(e,s)?e[s]:void 0;if(0!==r)if(r)t.push(r[2]);else{var n=new Promise(((t,n)=>r=e[s]=[t,n]));t.push(r[2]=n);var i=o.p+o.u(s),a=new Error;o.l(i,(t=>{if(o.o(e,s)&&(0!==(r=e[s])&&(e[s]=void 0),r)){var n=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;a.message="Loading chunk "+s+" failed.\n("+n+": "+i+")",a.name="ChunkLoadError",a.type=n,a.request=i,r[1](a)}}),"chunk-"+s,s)}},o.O.j=s=>0===e[s];var s=(s,t)=>{var r,n,[i,a,l]=t,d=0;if(i.some((s=>0!==e[s]))){for(r in a)o.o(a,r)&&(o.m[r]=a[r]);if(l)var c=l(o)}for(s&&s(t);do(49384)));l=o.O(l)})(); //# sourceMappingURL=bundle.23ee45e62272efdfb558.js.map