(()=>{"use strict";var e,t,s,r,n,i={39663:(e,t,s)=>{var r=s(5338),n=s(84976),i=s(15072),a=s(97665),o=s(65793),l=s(14519),d=s(47767),c=s(24279),x=s(76544);const u={main:"#FF6B6B",light:"#FF8E8E",dark:"#FF4848",contrastText:"#FFFFFF"},m={50:"#FAFAFA",100:"#F5F5F5",200:"#EEEEEE",300:"#E0E0E0",400:"#BDBDBD",500:"#9E9E9E",600:"#757575",700:"#616161",800:"#424242",900:"#212121"},h={gradientPrimary:"linear-gradient(108.73deg, #F9881F 23.73%, #FF774C 79.34%)",gradientCoral:`linear-gradient(45deg, ${u.main} 30%, #FF8E53 90%)`,gradientCoralHover:`linear-gradient(45deg, #FF8E53 30%, ${u.main} 90%)`,primarySoft:(0,c.X4)(u.main,.08),primarySoftHover:(0,c.X4)(u.main,.12),primarySoftActive:(0,c.X4)(u.main,.16),primaryGlow:`0 4px 14px ${(0,c.X4)(u.main,.4)}`,primaryGlowHover:`0 6px 20px ${(0,c.X4)(u.main,.5)}`,whatsapp:{main:"#25D366",dark:"#128C7E",contrastText:"#FFFFFF"},menuHover:"rgba(145, 127, 179, 0.1)"},p=(0,x.A)({palette:{mode:"light",primary:u,secondary:{main:"#4ECDC4",light:"#71D7D0",dark:"#2BC4B8",contrastText:"#FFFFFF"},error:{main:"#E53935",light:"#EF5350",dark:"#C62828",contrastText:"#FFFFFF"},warning:{main:"#F9A825",light:"#FFCA28",dark:"#F57F17",contrastText:"#FFFFFF"},success:{main:"#25D366",light:"#4CE38A",dark:"#128C7E",contrastText:"#FFFFFF"},info:{main:"#1976D2",light:"#42A5F5",dark:"#1565C0",contrastText:"#FFFFFF"},grey:m,text:{primary:"#212121",secondary:"#616161",disabled:"#9E9E9E"},background:{default:"#F7F7F7",paper:"#FFFFFF",subtle:"#FAFAFA"},divider:m[300],custom:h},shape:{borderRadius:8},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 A=s(96540),g=s(59270),y=s(14073),j=s(97834),f=s(69067),b=s(73357),v=s(93959),I=s(56908),S=s(10548);const C="undefined"!=typeof window&&window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000/graphql":`${window.location.origin}/graphql`,w=new I.l4(C,{headers:{"Content-Type":"application/json"}}),P=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=await(async()=>{try{const e=await(0,S.$)(),t=e.tokens?.accessToken?.toString();return t?{Authorization:`Bearer ${t}`}:{}}catch(e){return{}}})();return w.request(e,t,{...w.requestConfig.headers,...s})},k={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."},E=e=>{if(e.response?.errors){return e.response.errors.map((e=>{if(e.extensions?.code){const t=e.extensions.code;if(k[t])return k[t]}return e.message?.includes("Pickup address ID is required for pickup orders")?"Please select a valid address to deliver.":e.message?.includes("validation")?k.VALIDATION_ERROR:e.message?.includes("not found")?"The requested item was not found.":e.message?.includes("permission")?k.FORBIDDEN:e.message?.includes("already exists")?"This item already exists.":e.message||k.GENERIC_ERROR})).join(". ")}if(e.message?.includes("Network request failed"))return k.NETWORK_ERROR;if(e.message?.includes("timeout"))return k.TIMEOUT_ERROR;if(e.response?.status)switch(e.response.status){case 401:return k.UNAUTHENTICATED;case 403:return k.FORBIDDEN;case 404:return"The requested resource was not found.";case 500:return k.INTERNAL_SERVER_ERROR;case 503:return k.SERVICE_UNAVAILABLE;default:return`Server error (${e.response.status}). Please try again.`}return e.message||k.GENERIC_ERROR},$=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{const s=await P(e,t);if(s.errors){const e=E({response:s});throw new Error(e)}return s}catch(e){const t=E(e),s=new Error(t);throw s.originalError=e,s.isGraphQLError=!0,s}},L="query getAllUsers {\n getAllUsers {\n id\n email\n mobile\n type\n cognitoId\n }\n}",F="\n mutation UpdateOrderStatus($input: UpdateOrderStatusInput!) {\n updateOrderStatus(input: $input) {\n id\n status\n deliveryDate\n deliveryInstructions\n }\n }\n",D="\n query GetUserProfile($userId: String!) {\n getUserProfile(userId: $userId) {\n active\n createdAt\n email\n id\n mobile\n referralId\n secondaryPhone\n type\n updatedAt\n stores {\n edges {\n node {\n id\n name\n taxPercentage\n }\n }\n }\n }\n }\n",z="\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 instructions\n allowSubstitute\n product {\n id\n name\n description\n inventoryItems {\n edges {\n node {\n price\n measurement\n unit\n }\n }\n }\n }\n }\n }\n }\n }\n }\n",T="\n query GetStoreDrivers($storeId: Int!) {\n getStoreDrivers(storeId: $storeId) {\n id\n storeId\n userId\n driver {\n active\n email\n mobile\n referralId\n referredBy\n type\n }\n }\n }\n",R="\n mutation CancelOrder($orderId: Int!, $cancelMessage: String!, $cancelledByUserId: Int!) {\n cancelOrderById(\n orderId: $orderId, \n cancelMessage: $cancelMessage, \n cancelledByUserId: $cancelledByUserId\n ) {\n id\n status\n }\n }\n",W="\n query 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",q="\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",O="\n query GetProducts {\n products {\n id\n name\n description\n categoryId\n image\n category {\n id\n name\n }\n inventoryItems {\n edges {\n node {\n id\n }\n }\n }\n }\n }\n",U="\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",N="\n mutation DeleteSavedCart($userId: Int!, $storeId: Int!) {\n deleteSavedCart(userId: $userId, storeId: $storeId)\n }\n";var B=s(71511),M=s(87134),_=s(18496);const V="admin",H="user",G="delivery_agent",K="store_manager",Y="orders",X="userStatus",Q=e=>(0,_.ms)((t=>{e=e?.toLowerCase().trim(),e===V&&(t("view",V),t("view",X)),e===H&&(t("view",H),t("view",Y),t("view","cart")),e===G&&t("view",G),e===K&&(t("view",K),t("manage","inventory"))})),Z=e=>`${e?.id??e?.productId}::${e?.selectedCut?.id??"none"}`,J=e=>{if(!e||"object"!=typeof e)return{};const t={};for(const[s,r]of Object.entries(e)){if("string"==typeof s&&s.includes("::")){t[s]=r;continue}t[Z(r||{id:s})]=r}return t},ee=(0,B.v)((0,M.Zr)(((e,t)=>({cart:{},selectedStore:null,availableStores:[],setAvailableStores:t=>e({availableStores:t}),setSelectedStore:s=>{const r=t(),n=r.selectedStore?.id,i=s?.id;if(n&&i&&String(n)===String(i))return void e({selectedStore:s});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){}}let a=null;if(i)try{const e=localStorage.getItem(`indimitra-cart-store-${i}`);e&&(a=JSON.parse(e))}catch(e){}e({selectedStore:s,cart:J(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:()=>t().selectedStore,pickupAddress:null,setPickupAddress:t=>e({pickupAddress:t}),deliveryAddressString:null,setDeliveryAddressString:t=>e({deliveryAddressString:t}),deliveryType:"pickup",setDeliveryType:t=>e({deliveryType:t}),addToCart:t=>e((e=>{const s=Z(t),r=e.cart[s];return{cart:{...e.cart,[s]:{...r||t,selectedCut:t.selectedCut??r?.selectedCut??null,quantity:(r?.quantity||0)+1,instructions:r?.instructions??"",allowSubstitute:r?.allowSubstitute??!1}}}})),setCartItemInstructions:(t,s)=>e((e=>{const r="string"==typeof t&&t.includes("::")?t:Z(t);return e.cart[r]?{cart:{...e.cart,[r]:{...e.cart[r],instructions:s}}}:e})),setCartItemAllowSubstitute:(t,s)=>e((e=>{const r="string"==typeof t&&t.includes("::")?t:Z(t);return e.cart[r]?{cart:{...e.cart,[r]:{...e.cart[r],allowSubstitute:!!s}}}:e})),removeFromCart:t=>e((e=>{const s="string"==typeof t&&t.includes("::")?t:Z(t);if(!e.cart[s])return e;const r={...e.cart};return r[s].quantity>1?r[s]={...r[s],quantity:r[s].quantity-1}:delete r[s],{cart:r}})),cartCount:()=>{const e=t();return Object.values(e.cart).reduce(((e,t)=>e+(t.quantity||0)),0)+(e.customOrder?1:0)},cartTotal:()=>Object.values(t().cart).reduce(((e,t)=>e+(t?.price||0)*(t?.quantity||0)),0),deleteCartLine:t=>e((e=>{const s="string"==typeof t&&t.includes("::")?t:Z(t);if(!e.cart[s])return e;const r={...e.cart};return delete r[s],{cart:r}})),clearCart:()=>e({cart:{}}),calculateDeliveryFee:(e,t,s)=>{if(!t||!t.fees||!t.fees.edges||0===t.fees.edges.length)return 0;const r=t.fees.edges.map((e=>e.node)).filter((e=>e.type===s.toUpperCase()));if(0===r.length)return 0;const n=r.sort(((e,t)=>e.limit-t.limit));let i=null;for(const t of n)if(e<=t.limit){i=t;break}if(!i&&n.length>0&&(i=n[n.length-1]),!i)return 0;return i.feeRate},getCartTotals:()=>{const e=t(),s=e.cart,r=e.selectedStore,n=e.deliveryType,i=Object.values(s).reduce(((e,t)=>e+(t.price*t.quantity||0)),0),a=t().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:t=>e({tipAmount:t}),customOrder:"",setCustomOrder:t=>e({customOrder:t}),listInputAnswers:{},setListInputAnswers:t=>e({listInputAnswers:t}),restoreCart:t=>{t&&e({...void 0!==t.cart&&{cart:t.cart},...void 0!==t.customOrder&&{customOrder:t.customOrder},...void 0!==t.listInputAnswers&&{listInputAnswers:t.listInputAnswers},...void 0!==t.deliveryType&&{deliveryType:t.deliveryType},...void 0!==t.tipAmount&&{tipAmount:t.tipAmount},...void 0!==t.pickupAddress&&{pickupAddress:t.pickupAddress}})},getCartState:()=>{const e=t();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,M.KU)((()=>localStorage)),version:2,migrate:(e,t)=>(e?.cart&&(e.cart=J(e.cart)),e),onRehydrateStorage:()=>e=>{e?.cart&&(e.cart=J(e.cart))},partialize:e=>({cart:e.cart,selectedStore:e.selectedStore,customOrder:e.customOrder,listInputAnswers:e.listInputAnswers,deliveryType:e.deliveryType,tipAmount:e.tipAmount,pickupAddress:e.pickupAddress,deliveryAddressString:e.deliveryAddressString})})),te=(0,B.v)(((e,t)=>({user:null,userProfile:null,ability:null,isProfileLoading:!1,profileError:null,modalOpen:!1,currentForm:"login",skipNavigateOnLogin:!1,setAbility:t=>{e({ability:t})},setUser:t=>{e({user:t})},setUserProfile:t=>{if(!t)return;const s=JSON.parse(JSON.stringify(t));e((e=>({...e,userProfile:s})))},setModalOpen:t=>{e(t?{modalOpen:!0}:{modalOpen:!1,skipNavigateOnLogin:!1})},setSkipNavigateOnLogin:t=>{e({skipNavigateOnLogin:t})},getUserProfile:()=>t().userProfile,setCurrentForm:t=>{e({currentForm:t})},setAbility:t=>e({ability:t}),logout:()=>{e({user:null,userProfile:null,ability:Q(null)})},fetchUserProfile:async t=>{if(t){e({isProfileLoading:!0});try{const s=await $(D,{userId:t});if(s.errors)return void e({isProfileLoading:!1});const r=s.getUserProfile||s.data?.getUserProfile;if(!r)return void e({isProfileLoading:!1});e({userProfile:r,isProfileLoading:!1,ability:Q(r.role)})}catch(t){e({isProfileLoading:!1})}}},isProfileLoaded:()=>!!t().userProfile}))),se=(0,B.v)(((e,t)=>({addresses:[],isLoading:!1,error:null,selectedAddressId:null,setSelectedAddressId:t=>e({selectedAddressId:t}),fetchAddresses:async s=>{if(!s)return[];e({isLoading:!0,error:null});try{const r="string"==typeof s?parseInt(s,10):s,n=await $("\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&&!t().selectedAddressId?i[0].id:t().selectedAddressId}),i}catch(t){return e({error:t.message||"Failed to fetch addresses",isLoading:!1}),[]}},createAddress:async function(t,s){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!s||!t)return null;e({isLoading:!0,error:null});try{const n="string"==typeof s?parseInt(s,10):s,i=await $("\n mutation CreateAddress($address: String!, $userId: Int!, $isPrimary: Boolean) {\n createAddress(address: $address, userId: $userId, isPrimary: $isPrimary) {\n id\n address\n isPrimary\n }\n }\n",{address:t,userId: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(t){return e({error:t.message||"Failed to create address",isLoading:!1}),null}},updateAddress:async(t,s,r)=>{if(!t)return null;e({isLoading:!0,error:null});try{const n=await $("\n mutation UpdateAddress($addressId: Int!, $address: String, $isPrimary: Boolean) {\n updateAddress(addressId: $addressId, address: $address, isPrimary: $isPrimary) {\n id\n address\n isPrimary\n }\n }\n",{addressId:t,address:s,isPrimary:r});if(n?.updateAddress)return e((e=>({addresses:e.addresses.map((e=>e.id===t?n.updateAddress:e)),isLoading:!1}))),n.updateAddress;throw new Error("Failed to update address")}catch(t){return e({error:t.message||"Failed to update address",isLoading:!1}),null}},deleteAddress:async t=>{if(!t)return!1;e({isLoading:!0,error:null});try{const s=await $("\n mutation DeleteAddress($addressId: Int!) {\n deleteAddress(addressId: $addressId)\n }\n",{addressId:t});if(s?.deleteAddress)return e((e=>({addresses:e.addresses.filter((e=>e.id!==t)),isLoading:!1,selectedAddressId:e.selectedAddressId===t?null:e.selectedAddressId}))),!0;throw new Error("Failed to delete address")}catch(t){return e({error:t.message||"Failed to delete address",isLoading:!1}),!1}},getSelectedAddress:()=>{const{addresses:e,selectedAddressId:s}=t();return e.find((e=>e.id===s))||null}}))),re=ee;var ne=s(74848);const ie=e=>(0,ne.jsx)(f.A,{...e});var ae=s(86990);const oe=e=>(0,ne.jsx)(ae.A,{...e});var le=s(42471);const de=e=>(0,ne.jsx)(le.A,{...e}),ce=e=>(0,ne.jsx)(y.A,{...e});var xe=s(36632);const ue=e=>(0,ne.jsx)(xe.A,{...e});var me=s(60538);const he=e=>(0,ne.jsx)(me.A,{...e}),pe=e=>{let{size:t=40,thickness:s=3.6,sx:r={}}=e;return(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",...r},children:(0,ne.jsx)(b.A,{size:t,thickness:s})})};var Ae=s(50790),ge=s(29898),ye=s(25239);const je=e=>{let{fields:t,onSubmit:s,buttonLabel:r,loading:n,error:i,success:a}=e;const o=e=>{switch(e){case"email":return(0,ne.jsx)(Ae.A,{sx:{color:"primary.main"}});case"password":return(0,ne.jsx)(ge.A,{sx:{color:"primary.main"}});default:return null}};return(0,ne.jsxs)("form",{onSubmit:s,children:[t.map(((e,t)=>(0,ne.jsx)(de,{label:e.label,type:e.type,fullWidth:!0,margin:"normal",value:e.value,onChange:t=>e.onChange(t.target.value),required:!0,InputProps:{startAdornment:e.type&&(0,ne.jsx)(ye.A,{position:"start",children:o(e.type)})}},t))),i&&(0,ne.jsx)(ue,{severity:"error",sx:{mt:2},children:i}),a&&(0,ne.jsx)(ue,{severity:"success",sx:{mt:2},children:a}),(0,ne.jsx)(oe,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:n,sx:{mt:2},children:n?(0,ne.jsx)(pe,{size:24,sx:{color:"primary.contrastText"}}):r})]})},fe=e=>(0,ne.jsx)(j.A,{...e});var be=s(11641);const ve=e=>(0,ne.jsx)(be.A,{...e});var Ie=s(73896);const Se=e=>(0,ne.jsx)(Ie.A,{...e});var Ce=s(8239),we=s(14977),Pe=s(87393),ke=s(37636),Ee=s(50779),$e=s(29571),Le=s(2071),Fe=s(56826),De=s(47839),ze=s(1649),Te=s(99682),Re=s(11235);const We={"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 qe=s(44675),Oe=s(82022);const Ue=e=>{let{categoryName:t}=e;return t?(0,ne.jsx)(Oe.A,{label:t,size:"small",sx:{position:"absolute",top:12,right:12,zIndex:1,backgroundColor:"rgba(255, 255, 255, 0.9)",fontWeight:600,fontSize:"0.7rem",borderRadius:"12px",boxShadow:"0 2px 5px rgba(0,0,0,0.1)"}}):null},Ne="grey",Be=e=>{let{product:t}=e;const s=(0,qe.A)(),{cart:r,addToCart:n,removeFromCart:i}=re(),{id:a,name:o,price:l,description:d,image:x,categoryName:u,isAvailable:m,cutTypes:h}=t,p=Array.isArray(h)&&h.length>0,[g,j]=(0,A.useState)(""),b=p&&h.find((e=>e.id===g))||null,v=!p||null!==b,I=Z({id:a,selectedCut:b}),S=r[I]?.quantity||0,C=x||(u?(e=>{if(e&&We[e.toLowerCase()]){const t=We[e.toLowerCase()];return t[Math.floor(Math.random()*t.length)]}return We.default})(u):"https://picsum.photos/200");return(0,ne.jsxs)(we.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",...!m&&{opacity:.5,pointerEvents:"none"}},children:[(0,ne.jsx)(Ue,{categoryName:u}),(0,ne.jsx)(Pe.A,{component:"img",height:"140",image:C,alt:o,sx:{padding:"10px 0 0 0",objectFit:"contain",transition:"transform 0.5s","&:hover":{transform:"scale(1.05)"}}}),!m&&(0,ne.jsx)(f.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,ne.jsx)(y.A,{variant:"body1",children:"Sold out"})}),(0,ne.jsxs)(ke.A,{sx:{flexGrow:1,p:2.5,pb:0,display:"flex",flexDirection:"column"},children:[(0,ne.jsx)(y.A,{gutterBottom:!0,variant:"h6",sx:{fontWeight:600,fontSize:"1.1rem",mb:1,lineHeight:1.3},children:o}),d&&(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:1.5,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:"0.85rem",lineHeight:1.4},children:d}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:"auto",mb:2},children:[(0,ne.jsxs)(y.A,{variant:"h6",sx:{fontWeight:700,color:"primary.main",fontSize:"1.2rem"},children:["$",l.toFixed(2)]}),void 0!==t.quantity&&(0,ne.jsxs)(y.A,{variant:"body2",color:"text.secondary",sx:{ml:2,fontWeight:500},children:["Qty: ",t.quantity]})]})]}),p&&(0,ne.jsxs)(f.A,{sx:{px:2.5,pb:1.5},children:[(0,ne.jsxs)(Ee.A,{fullWidth:!0,size:"small",disabled:!m,children:[(0,ne.jsx)($e.A,{id:`cut-select-label-${a}`,children:"Select cut"}),(0,ne.jsx)(Le.A,{labelId:`cut-select-label-${a}`,value:g,label:"Select cut",onChange:e=>j(e.target.value),children:h.map((e=>(0,ne.jsx)(Ie.A,{value:e.id,children:e.label},e.id)))})]}),!v&&(0,ne.jsx)(y.A,{variant:"caption",sx:{display:"block",mt:.5,color:"text.secondary"},children:"Please select a cut to continue"})]}),(0,ne.jsx)(Fe.A,{sx:{justifyContent:"center",pb:2.5,px:2.5},children:S>0?(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"48px",borderRadius:"8px",background:(0,c.X4)(s.palette.primary.main,.15),border:`2px solid ${s.palette.primary.main}`,boxShadow:`0 2px 8px ${(0,c.X4)(s.palette.primary.main,.15)}`,transition:"all 0.2s ease","&:hover":{background:(0,c.X4)(s.palette.primary.main,.15),boxShadow:`0 4px 12px ${(0,c.X4)(s.palette.primary.main,.2)}`}},children:[(0,ne.jsx)(De.A,{title:"Remove from cart",children:(0,ne.jsx)(be.A,{onClick:()=>{i(I)},sx:{color:"primary.main",p:1,"&:hover":{backgroundColor:(0,c.X4)(s.palette.primary.main,.2),transform:"scale(1.1)"},transition:"all 0.2s ease"},children:(0,ne.jsx)(ze.A,{fontSize:"small"})})}),(0,ne.jsx)(y.A,{variant:"body1",sx:{color:"primary.main",fontWeight:700,mx:2,minWidth:"24px",textAlign:"center",fontSize:"1.1rem"},children:S}),(0,ne.jsx)(De.A,{title:"Add to cart",children:(0,ne.jsx)(be.A,{onClick:()=>{n({...t,selectedCut:b})},sx:{color:"primary.main",p:1,"&:hover":{backgroundColor:(0,c.X4)(s.palette.primary.main,.2),transform:"scale(1.1)"},transition:"all 0.2s ease"},children:(0,ne.jsx)(Te.A,{fontSize:"small"})})})]}):(0,ne.jsx)(ae.A,{size:"medium",sx:{width:"100%",height:"48px",background:"transparent",color:m?s.palette.primary.main:Ne,borderRadius:"8px",fontWeight:600,fontSize:"0.95rem",textTransform:"none",position:"relative",overflow:"hidden",border:`2px solid ${m?s.palette.primary.main:Ne}`,transition:"all 0.2s ease","&:hover":{background:"transparent","& .MuiButton-startIcon":{transform:"translateX(2px)"}},"& .MuiButton-startIcon":{transition:"transform 0.2s ease",marginRight:"8px"}},startIcon:(0,ne.jsx)(Re.A,{sx:{fontSize:"1.1rem"}}),onClick:()=>{n({...t,selectedCut:b})},disabled:!m||!v,children:m?v?"Add to Cart":"Select a cut":"Unavailable"})})]})},Me=e=>{let{products:t,title:s}=e;return 0===t.length?(0,ne.jsx)(f.A,{sx:{py:8,textAlign:"center"},children:(0,ne.jsx)(y.A,{variant:"h6",color:"text.secondary",children:"No products available."})}):(0,ne.jsxs)(j.A,{maxWidth:"xl",children:[s&&(0,ne.jsx)(y.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:e=>e.palette.custom.gradientCoral,borderRadius:"3px"}},children:s}),(0,ne.jsx)(Ce.Ay,{container:!0,spacing:3,children:t.map((e=>(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,ne.jsx)(Be,{product:e})},e.id)))})]})};var _e=s(8451),Ve=s(27562),He=s(64569);const Ge=e=>{let{categories:t,selectedCategoryId:s,onSelectCategory:r}=e;const n=(0,qe.A)(),i=(0,A.useRef)(null),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(!1),x=(0,A.useCallback)((()=>{const e=i.current;if(!e)return;const{scrollLeft:t,scrollWidth:s,clientWidth:r}=e,n=s-r;o(t>4),d(n>4&&t{x()}),[t,x]),(0,A.useEffect)((()=>{const e=i.current;if(!e)return;x(),e.addEventListener("scroll",x,{passive:!0});const t=new ResizeObserver(x);return t.observe(e),()=>{e.removeEventListener("scroll",x),t.disconnect()}}),[x]);const u=e=>{const t=i.current;t&&t.scrollBy({left:.75*t.clientWidth*e,behavior:"smooth"})},m=[{id:null,name:"All",isAll:!0},...t.map((e=>{let[t,s]=e;return{id:t,name:s,isAll:!1}}))],h={width:36,height:36,bgcolor:"background.paper",color:"primary.main",border:`2px solid ${n.palette.primary.main}`,boxShadow:"0 2px 8px rgba(0,0,0,0.15)",zIndex:2,transition:"all 0.2s ease","&:hover":{bgcolor:"primary.main",color:"primary.contrastText",transform:"scale(1.15)",boxShadow:`0 4px 12px ${(0,c.X4)(n.palette.primary.main,.4)}`},"&.Mui-disabled":{bgcolor:"grey.100",color:"grey.400",border:`2px solid ${n.palette.grey[300]}`,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"}};return(0,ne.jsxs)(f.A,{sx:{position:"relative",mb:3},children:[(0,ne.jsx)(y.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,ne.jsxs)(f.A,{sx:{position:"relative"},children:[(0,ne.jsx)(be.A,{onClick:()=>u(-1),disabled:!a,"aria-label":"Scroll categories left",sx:{...h,position:"absolute",left:-4,top:"50%",transform:"translateY(-50%)"},children:(0,ne.jsx)(_e.A,{})}),(0,ne.jsx)(f.A,{ref:i,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:m.map((e=>{let{id:t,name:i,isAll:a}=e;const o=a?null===s:s===t,l=a?null:function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(e&&We[e.toLowerCase()]){const s=We[e.toLowerCase()];return s[t%s.length]}return We.default}(i,0);return(0,ne.jsxs)(f.A,{component:"button",type:"button",onClick:()=>r(t),role:"tab","aria-selected":o,"aria-label":a?"Show all categories":`Category: ${i}`,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:o?"primary.main":"transparent",cursor:"pointer",position:"relative",overflow:"hidden",p:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-end",background:a?n.palette.custom.gradientCoral:"none",boxShadow:o?`0 4px 16px ${(0,c.X4)(n.palette.primary.main,.3)}`:"0 2px 8px rgba(0,0,0,0.08)",transform:"scale(1)",transition:"all 0.25s ease","&:hover":{transform:"scale(1.05)",boxShadow:o?`0 8px 24px ${(0,c.X4)(n.palette.primary.main,.35)}`:"0 6px 20px rgba(0,0,0,0.12)"},"&:focus-visible":{outline:`2px solid ${n.palette.primary.main}`,outlineOffset:2}},children:[!a&&l&&(0,ne.jsx)(f.A,{sx:{position:"absolute",inset:0,backgroundImage:`url(${l})`,backgroundSize:"cover",backgroundPosition:"center",filter:o?"brightness(0.75)":"brightness(0.85)",transition:"filter 0.25s ease"}}),!a&&(0,ne.jsx)(f.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%)"}}),a&&(0,ne.jsx)(He.A,{sx:{color:"common.white",fontSize:{xs:"1.6rem",md:"2rem"},mb:.5,zIndex:1,filter:"drop-shadow(0 1px 2px rgba(0,0,0,0.2))"}}),(0,ne.jsx)(y.A,{variant:"caption",component:"span",sx:{position:"relative",zIndex:1,color:"common.white",fontWeight:o?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:a?"All":i}),o&&(0,ne.jsx)(f.A,{sx:{position:"absolute",bottom:0,left:"15%",right:"15%",height:3,borderRadius:"3px 3px 0 0",background:n.palette.custom.gradientCoral}})]},a?"all":t)}))}),(0,ne.jsx)(be.A,{onClick:()=>u(1),disabled:!l,"aria-label":"Scroll categories right",sx:{...h,position:"absolute",right:-4,top:"50%",transform:"translateY(-50%)"},children:(0,ne.jsx)(Ve.A,{})})]})]})};var Ke=s(15327),Ye=s(52848),Xe=s(68864),Qe=s(1405),Ze=s(69486),Je=s(64745),et=s(55759),tt=s(65697),st=s(39781);const rt=[{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"}],nt=e=>{let{search:t,onSearchChange:s,sortBy:r,onSortChange:n,inStockOnly:i,onInStockOnlyChange:a,priceRange:o,onPriceRangeChange:l,priceBounds:d,activeFilterCount:x,onClearFilters:u}=e;const m=(0,qe.A)(),[h,p]=(0,A.useState)(!1),g=(0,Ke.A)("(max-width: 600px)"),j=d[0],b=d[1],v=b>j;return(0,ne.jsxs)(f.A,{sx:{mb:2},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,ne.jsx)(le.A,{size:"small",placeholder:"Search products…",value:t,onChange:e=>s(e.target.value),InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Je.A,{sx:{color:"text.secondary",fontSize:20}})})},sx:{flex:1,"& .MuiOutlinedInput-root":{borderRadius:"12px",backgroundColor:"grey.50",fontSize:"0.9rem","&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:2}}}}),(0,ne.jsx)(Le.A,{value:r,onChange:e=>n(e.target.value),size:"small",displayEmpty:!0,renderValue:e=>{if(g)return(0,ne.jsx)(tt.A,{sx:{fontSize:20,color:"text.secondary",mt:.3}});const t=rt.find((t=>t.value===e));return(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:.5},children:[(0,ne.jsx)(tt.A,{sx:{fontSize:18,color:"text.secondary"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{fontSize:"0.85rem"},children:t?.label||"Sort"})]})},sx:{minWidth:g?48:180,borderRadius:"12px",backgroundColor:"grey.50",fontSize:"0.85rem","& .MuiOutlinedInput-notchedOutline":{borderColor:"default"!==r?m.palette.primary.main:void 0},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:2}},MenuProps:{PaperProps:{sx:{borderRadius:"12px",mt:.5}}},children:rt.map((e=>(0,ne.jsx)(Ie.A,{value:e.value,sx:{fontSize:"0.9rem"},children:e.label},e.value)))}),(0,ne.jsx)(De.A,{title:h?"Hide filters":"Show filters",children:(0,ne.jsxs)(be.A,{onClick:()=>p((e=>!e)),sx:{width:40,height:40,borderRadius:"12px",border:"1px solid",borderColor:h||x>0?"primary.main":"divider",backgroundColor:h?(0,c.X4)(m.palette.primary.main,.08):m.palette.grey[50],position:"relative",transition:"all 0.2s ease","&:hover":{backgroundColor:(0,c.X4)(m.palette.primary.main,.12),borderColor:"primary.main"}},children:[(0,ne.jsx)(et.A,{sx:{fontSize:20,color:h||x>0?"primary.main":"text.secondary"}}),x>0&&(0,ne.jsx)(f.A,{sx:{position:"absolute",top:-4,right:-4,width:18,height:18,borderRadius:"50%",backgroundColor:"primary.main",color:"primary.contrastText",fontSize:"0.65rem",fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center"},children:x})]})})]}),(0,ne.jsx)(Ye.A,{in:h,timeout:250,children:(0,ne.jsx)(f.A,{sx:{mt:1.5,p:{xs:1.5,sm:2},borderRadius:"14px",backgroundColor:"grey.50",border:"1px solid",borderColor:"divider"},children:(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},gap:{xs:2,sm:3},alignItems:{xs:"stretch",sm:"center"}},children:[(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(Qe.A,{checked:i,onChange:e=>a(e.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{backgroundColor:"primary.main"}}}),label:(0,ne.jsx)(y.A,{variant:"body2",sx:{fontSize:"0.85rem",fontWeight:500},children:"In stock only"}),sx:{m:0}}),v&&(0,ne.jsxs)(f.A,{sx:{flex:1,minWidth:160},children:[(0,ne.jsxs)(y.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,ne.jsx)(Ze.Ay,{value:o,onChange:(e,t)=>l(t),min:j,max:b,step:.5,valueLabelDisplay:"auto",valueLabelFormat:e=>`$${e.toFixed(0)}`,size:"small",sx:{color:"primary.main","& .MuiSlider-thumb":{width:16,height:16,"&:hover, &.Mui-focusVisible":{boxShadow:`0 0 0 6px ${(0,c.X4)(m.palette.primary.main,.16)}`}},"& .MuiSlider-valueLabel":{backgroundColor:"primary.main",borderRadius:"8px",fontSize:"0.7rem"}}})]}),x>0&&(0,ne.jsx)(Oe.A,{label:"Clear filters",size:"small",onDelete:u,deleteIcon:(0,ne.jsx)(st.A,{sx:{fontSize:14}}),onClick:u,sx:{borderRadius:"8px",fontWeight:600,fontSize:"0.78rem",color:"primary.main",borderColor:"primary.main","& .MuiChip-deleteIcon":{color:"primary.main"}},variant:"outlined"})]})})}),!h&&x>0&&(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:.75,mt:1,flexWrap:"wrap",alignItems:"center"},children:[i&&(0,ne.jsx)(Oe.A,{label:"In stock",size:"small",onDelete:()=>a(!1),sx:{borderRadius:"8px",fontSize:"0.75rem",fontWeight:600,backgroundColor:(0,c.X4)(m.palette.primary.main,.1),color:"primary.main","& .MuiChip-deleteIcon":{color:"primary.main",fontSize:16}}}),v&&(o[0]>j||o[1]l([j,b]),sx:{borderRadius:"8px",fontSize:"0.75rem",fontWeight:600,backgroundColor:(0,c.X4)(m.palette.primary.main,.1),color:"primary.main","& .MuiChip-deleteIcon":{color:"primary.main",fontSize:16}}}),"default"!==r&&(0,ne.jsx)(Oe.A,{label:rt.find((e=>e.value===r))?.label,size:"small",onDelete:()=>n("default"),sx:{borderRadius:"8px",fontSize:"0.75rem",fontWeight:600,backgroundColor:(0,c.X4)(m.palette.primary.main,.1),color:"primary.main","& .MuiChip-deleteIcon":{color:"primary.main",fontSize:16}}}),(0,ne.jsx)(Oe.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 it=s(58031),at=s(46831),ot=s(22477),lt=s(58763);const dt=e=>{let{open:t,onClose:s,children:r,title:n,footer:i,hideClose:a=!1,maxWidth:o="sm",height:l,contentSx:d,...c}=e;const x={borderRadius:2,boxShadow:"0 12px 40px rgba(0, 0, 0, 0.08)",border:"1px solid",borderColor:"divider",display:"flex",flexDirection:"column",overflow:"hidden"};return l?x.height=`min(${l}, 90vh)`:x.maxHeight="min(85vh, 720px)",(0,ne.jsxs)(it.A,{open:t,maxWidth:o,fullWidth:!0,onClose:a?void 0:s,PaperProps:{sx:x},...c,children:[n&&(0,ne.jsxs)(at.A,{component:"div",sx:{px:3,py:2,borderBottom:"1px solid",borderColor:"divider",backgroundColor:"background.paper",display:"flex",alignItems:"center",justifyContent:"space-between",gap:2,flexShrink:0},children:[(0,ne.jsx)(f.A,{sx:{flex:1,minWidth:0,color:"text.primary"},children:n}),!a&&(0,ne.jsx)(be.A,{"aria-label":"close",onClick:s,size:"small",sx:{color:"text.secondary","&:hover":{color:"text.primary",backgroundColor:"action.hover"}},children:(0,ne.jsx)(st.A,{fontSize:"small"})})]}),(0,ne.jsx)(ot.A,{sx:{flex:1,minHeight:0,overflowY:"auto",px:3,pt:3,pb:3,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-thumb":{backgroundColor:"rgba(0,0,0,0.15)",borderRadius:3},...d},children:r}),i&&(0,ne.jsx)(lt.A,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",flexShrink:0},children:i})]})};var ct=s(8532);const xt=e=>(0,ne.jsx)(ct.A,{...e,sx:{minHeight:{xs:"64px",sm:"70px"},px:{xs:2,sm:4},...e.sx}}),ut=e=>(0,ne.jsx)(De.A,{...e,sx:{"& .MuiTooltip-tooltip":{backgroundColor:"rgba(42, 47, 79, 0.9)",fontSize:"0.875rem",borderRadius:"8px",padding:"8px 16px"},...e.sx}});var mt=s(11154);const ht=e=>(0,ne.jsx)(mt.A,{...e,sx:{"& .MuiBadge-badge":{backgroundColor:"error.main",color:"error.contrastText",minWidth:"20px",height:"20px",padding:"0 6px",fontSize:"0.75rem",fontWeight:600,...e.sx?.["& .MuiBadge-badge"]},...e.sx}});var pt=s(97190);const At=e=>(0,ne.jsx)(pt.A,{...e,sx:{"& .MuiPaper-root":{mt:2,minWidth:"200px",borderRadius:"12px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.1)",border:e=>`1px solid ${e.palette.custom.menuHover}`,overflow:"hidden"},"& .MuiList-root":{padding:"8px 0"},"& .MuiMenuItem-root":{padding:"12px 24px","&:hover":{backgroundColor:e=>e.palette.custom.menuHover}},...e.sx}});var gt=s(54937);const yt=e=>{let{error:t,title:s="Error",severity:r="error"}=e;return(0,ne.jsx)(f.A,{sx:{p:2},children:(0,ne.jsxs)(xe.A,{severity:r,children:[(0,ne.jsx)(gt.A,{sx:{fontWeight:"bold"},children:s}),t]})})};var jt=s(47027),ft=s(99631),bt=s(82935),vt=s(83574);const It=e=>{let{images:t=[],storeAddress:s,storeDescription:r,deliveryLabel:n,deliverySubtext:i,onChangeAddress:a}=e;const[o,l]=(0,A.useState)(0),[d,c]=(0,A.useState)(!1),[x,u]=(0,A.useState)("next"),[m,h]=(0,A.useState)(!1),p=(0,A.useRef)(null),g=t&&t.length>0?t:[],j=g.length>0,b=(0,A.useCallback)((()=>{p.current&&clearInterval(p.current),!j||g.length<=1||(p.current=setInterval((()=>{u("next"),h(!0),setTimeout((()=>{l((e=>e===g.length-1?0:e+1)),h(!1)}),300)}),4e3))}),[j,g.length]);(0,A.useEffect)((()=>(d?p.current&&clearInterval(p.current):b(),()=>{p.current&&clearInterval(p.current)})),[d,b]);const v=e=>{u(e),h(!0),setTimeout((()=>{l((t=>"next"===e?t===g.length-1?0:t+1:0===t?g.length-1:t-1)),h(!1)}),300),d||b()},I=(0,ne.jsxs)(f.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,ne.jsxs)(f.A,{sx:{minWidth:0,flex:1},children:[s&&(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.25},children:[(0,ne.jsx)(jt.A,{sx:{color:"rgba(255,255,255,0.8)",fontSize:"0.9rem"}}),(0,ne.jsx)(y.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:s})]}),r&&(0,ne.jsx)(y.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,ne.jsxs)(ae.A,{variant:"contained",size:"small",onClick:a,sx:{flexShrink:0,bgcolor:"rgba(255,255,255,0.2)",color:"common.white",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,ne.jsx)("span",{children:n}),i&&(0,ne.jsx)(y.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 j?(0,ne.jsx)(me.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,ne.jsxs)(f.A,{sx:{width:"100%",height:"100%",position:"relative"},children:[(0,ne.jsx)("img",{src:g[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:m?0:1,transform:m?`translateX(${"next"===x?"30px":"-30px"})`:"translateX(0)"},onError:e=>{e.target.style.display="none"}}),I,g.length>1&&(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(be.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,ne.jsx)(bt.A,{fontSize:"small"})}),(0,ne.jsx)(be.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,ne.jsx)(vt.A,{fontSize:"small"})})]}),g.length>1&&(0,ne.jsx)(f.A,{sx:{position:"absolute",bottom:{xs:40,sm:48},left:"50%",transform:"translateX(-50%)",display:"flex",gap:.75,zIndex:4},children:g.map(((e,t)=>(0,ne.jsx)(f.A,{onClick:()=>(e=>{e!==o&&(u(e>o?"next":"prev"),h(!0),setTimeout((()=>{l(e),h(!1)}),300),d||b())})(t),sx:{width:o===t?16:6,height:6,borderRadius:3,backgroundColor:o===t?"common.white":"rgba(255, 255, 255, 0.5)",cursor:"pointer",transition:"all 0.3s ease","&:hover":{backgroundColor:o===t?"common.white":"rgba(255, 255, 255, 0.75)"}}},t)))})]})}):(0,ne.jsx)(me.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:e=>`linear-gradient(135deg, ${e.palette.grey[50]} 0%, ${e.palette.grey[300]} 100%)`},children:s||r||n&&a?(0,ne.jsxs)(f.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,ne.jsxs)(f.A,{sx:{minWidth:0,flex:1},children:[s&&(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.25},children:[(0,ne.jsx)(jt.A,{sx:{color:"rgba(255,255,255,0.8)",fontSize:"0.9rem"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{color:"rgba(255,255,255,0.9)",fontSize:{xs:"0.8rem",sm:"0.88rem"}},children:s})]}),r&&(0,ne.jsx)(y.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,ne.jsxs)(ae.A,{variant:"contained",size:"small",onClick:a,sx:{flexShrink:0,bgcolor:"rgba(255,255,255,0.2)",color:"common.white",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,ne.jsx)("span",{children:n}),i&&(0,ne.jsx)(y.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,ne.jsxs)(f.A,{sx:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},children:[(0,ne.jsx)(ft.A,{sx:{fontSize:40,color:"rgba(0,0,0,0.2)",mb:.5}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{color:"rgba(0,0,0,0.35)"},children:"Offers & promotions coming soon"})]})})};var St=s(30995),Ct=s(71543),wt=s(50215),Pt=s(17809),kt=s(90509),Et=s(68806),$t=s(30425),Lt=s(21357),Ft=s(57097);const Dt=e=>{let{open:t,onClose:s,cartTotal:r,orderItems:n,deliveryType:i,selectedAddressId:a,selectedPickupId:o,userProfile:l,selectedStore:d,tipAmount:c,deliveryInstructions:x,customOrder:u,onSuccess:m,paymentConfig:h}=e;const[p]=(0,A.useState)((()=>crypto.randomUUID())),[g,j]=(0,A.useState)(null),[v,I]=(0,A.useState)(null);(0,A.useEffect)((()=>{j(null),I(null)}),[t]);const S=h?.isSquareConnected&&h?.squareApplicationId&&h?.squareLocationId,{mutate:C,isPending:w,isSuccess:P}=(0,Ft.n)({mutationFn:async e=>await $("\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 t=e?.createOrderWithPayment;t&&t.id?(I(t),j(null)):j("Your payment was processed but we encountered an error creating your order. Please contact support. Your cart has been preserved.")},onError:e=>{j(e?.message||e?.response?.errors?.[0]?.message||"Payment failed. Please try again.")}});(0,A.useEffect)((()=>{P&&v&&(s(),m&&m(v))}),[P,v,s,m]);const k=e=>{if(e&&e.length>0){const t=e[0],s={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=t.code||"UNKNOWN_ERROR";j(s[r]||t.message||"Payment processing failed. Please try again.")}else j("Payment processing failed. Please try again.")},E=n.reduce(((e,t)=>e+t.quantity),0);return(0,ne.jsxs)(it.A,{open:t,onClose:w?void 0:s,disableEscapeKeyDown:w,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:2,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.1)"}},children:[(0,ne.jsxs)(at.A,{sx:{textAlign:"center",background:e=>e.palette.custom.gradientPrimary,color:"common.white",py:2.5,mb:2,position:"relative"},children:[(0,ne.jsx)(wt.A,{sx:{mr:1,verticalAlign:"middle"}}),"Complete Payment",!w&&!P&&(0,ne.jsx)(be.A,{"aria-label":"close",onClick:s,sx:{position:"absolute",right:8,top:8,color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},children:(0,ne.jsx)(Pt.A,{})})]}),(0,ne.jsx)(ot.A,{children:w?(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",py:4,gap:2},children:[(0,ne.jsx)(b.A,{size:60}),(0,ne.jsx)(y.A,{variant:"body1",color:"text.secondary",children:"Processing payment..."})]}):(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsxs)(f.A,{sx:{mb:3,p:2,bgcolor:"grey.50",borderRadius:1},children:[(0,ne.jsxs)(y.A,{variant:"body2",color:"text.secondary",children:[E," ",1===E?"item":"items"," • ","delivery"===i?"Delivery":"Pickup"]}),(0,ne.jsxs)(y.A,{variant:"h5",fontWeight:"bold",sx:{mt:1},children:["$",r.toFixed(2)]})]}),g&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:g}),S?(0,ne.jsx)(kt.A,{applicationId:h?.squareApplicationId,locationId:h?.squareLocationId,cardTokenizeResponseReceived:async(e,t)=>{if(j(null),!e)return void j("Payment tokenization failed. Please try again.");if(e.errors&&e.errors.length>0)return void k(e.errors);if(!e.token)return void j("Payment tokenization failed. Please try again.");const s=n.map((e=>({productId:e.productId,quantity:e.quantity,meatCutId:e.meatCutId??null})));l?.id&&d?.id?C({userId:l.id,storeId:d.id,productItems:s,payment:{paymentToken:e.token,idempotencyKey:p,clientCalculatedAmount:r},pickupOrDelivery:i,addressId:a,pickupId:o,tipAmount:c||0,deliveryInstructions:x||null,customOrder:u||null}):j("Missing required information. Please refresh and try again.")},createPaymentRequest:()=>({countryCode:"US",currencyCode:"USD",total:{amount:r.toFixed(2),label:"Total"}}),onError:k,children:(0,ne.jsxs)(St.A,{spacing:2,children:[(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(Et.A,{}),(0,ne.jsx)(f.A,{sx:{mt:1},children:(0,ne.jsx)($t.A,{})})]}),(0,ne.jsx)(Ct.A,{sx:{my:2},children:(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"OR"})}),(0,ne.jsx)(Lt.A,{}),w&&(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:2,py:2},children:[(0,ne.jsx)(b.A,{size:24}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Processing payment..."})]})]})}):(0,ne.jsxs)(St.A,{spacing:2,children:[(0,ne.jsxs)(xe.A,{severity:"info",sx:{mb:2},children:[(0,ne.jsx)("strong",{children:"Preview Mode:"})," Square credentials not configured. This is a UI preview only.",(0,ne.jsx)("br",{}),(0,ne.jsx)(y.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,ne.jsxs)(f.A,{children:[(0,ne.jsxs)(ae.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,ne.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,ne.jsxs)(ae.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,ne.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",style:{marginRight:8},children:(0,ne.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,ne.jsx)(Ct.A,{sx:{my:2},children:(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"OR"})}),(0,ne.jsxs)(f.A,{sx:{border:"1px solid",borderColor:"grey.300",borderRadius:1,p:2},children:[(0,ne.jsx)(y.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"Card Number"}),(0,ne.jsx)(f.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1,mb:2},children:(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"•••• •••• •••• ••••"})}),(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:2},children:[(0,ne.jsxs)(f.A,{sx:{flex:1},children:[(0,ne.jsx)(y.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"Expiration"}),(0,ne.jsx)(f.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1},children:(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"MM/YY"})})]}),(0,ne.jsxs)(f.A,{sx:{flex:1},children:[(0,ne.jsx)(y.A,{variant:"caption",color:"text.secondary",sx:{mb:1,display:"block"},children:"CVV"}),(0,ne.jsx)(f.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1},children:(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"•••"})})]})]}),(0,ne.jsx)(y.A,{variant:"caption",color:"text.secondary",sx:{mt:2,display:"block"},children:"Postal Code"}),(0,ne.jsx)(f.A,{sx:{bgcolor:"grey.100",p:1.5,borderRadius:1,mt:1},children:(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"12345"})})]}),(0,ne.jsx)(y.A,{variant:"caption",color:"text.secondary",sx:{textAlign:"center",fontStyle:"italic"},children:"Payment form will be interactive once Square credentials are configured"})]})]})}),!P&&!w&&(0,ne.jsx)(lt.A,{sx:{px:3,pb:2},children:(0,ne.jsx)(ae.A,{onClick:s,color:"inherit",children:"Cancel"})})]})};var zt=s(69307),Tt=s(29428),Rt=s(53215),Wt=s(7578),qt=s(89388);const Ot=e=>{let{paymentConfig:t,selectedMethod:s,onMethodChange:r}=e;const n=t?.isSquareConnected&&t?.squareApplicationId&&t?.squareLocationId,i=t?.codEnabled;return(0,A.useEffect)((()=>{s||(n?r("square"):i&&r("cod"))}),[n,i,s,r]),n||i?(0,ne.jsxs)(Ee.A,{component:"fieldset",fullWidth:!0,sx:{mb:3},children:[(0,ne.jsx)(zt.A,{component:"legend",sx:{mb:2,fontWeight:500},children:"Select Payment Method"}),(0,ne.jsxs)(Tt.A,{value:s||"",onChange:e=>r(e.target.value),children:[n&&(0,ne.jsx)(Xe.A,{value:"square",control:(0,ne.jsx)(Rt.A,{color:"primary"}),label:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Wt.A,{color:"primary"}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"body1",sx:{fontWeight:600},children:"Pay with Card"}),(0,ne.jsx)(y.A,{variant:"caption",color:"text.secondary",children:"Credit/Debit, Apple Pay, Google Pay"})]})]}),sx:{border:"1px solid",borderColor:"square"===s?"primary.main":"divider",borderRadius:1,px:2,py:1.5,mb:1,"&:hover":{bgcolor:"action.hover"}}}),i&&(0,ne.jsx)(Xe.A,{value:"cod",control:(0,ne.jsx)(Rt.A,{color:"primary"}),label:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(qt.A,{color:"primary"}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"body1",sx:{fontWeight:600},children:"Cash on Delivery"}),(0,ne.jsx)(y.A,{variant:"caption",color:"text.secondary",children:"Pay when you receive your order"})]})]}),sx:{border:"1px solid",borderColor:"cod"===s?"primary.main":"divider",borderRadius:1,px:2,py:1.5,mb:1,"&:hover":{bgcolor:"action.hover"}}})]})]}):(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:"Store payment system unavailable. Please contact store or try again later."})},Ut={1:{2:s.p+"9eb9fe16cf24f64648f4.jpg",3:s.p+"97d88e9949ad49749160.jpg",4:s.p+"1b6333e925b3879a2984.jpg",5:s.p+"d35b1aa413caca3d6aa2.png",6:s.p+"5c2c140bb8e65ee1aa94.png",7:s.p+"0a359809026b5022f2d5.jpg"}};const Nt=()=>{const[e,t]=(0,A.useState)(""),[s,r]=(0,A.useState)(0),[n,i]=(0,A.useState)(12),[a,o]=(0,A.useState)(null),[l,d]=(0,A.useState)("default"),[c,x]=(0,A.useState)(!1),[u,m]=(0,A.useState)([0,0]),{selectedStore:h}=re(),p=function(e,t){const[s,r]=(0,A.useState)(e);return(0,A.useEffect)((()=>{const s=setTimeout((()=>{r(e)}),t);return()=>{clearTimeout(s)}}),[e,t]),s}(e,300),{data:I,isLoading:S,error:C}=(0,g.I)({queryKey:["storeInventory",h?.id],queryFn:async()=>await $("\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 cutTypes {\n id\n label\n text\n }\n product {\n id\n name\n image\n description\n category {\n id\n name\n }\n }\n }\n }\n",{storeId:h.id,isListed:!0}),enabled:!!h?.id}),w=(0,A.useMemo)((()=>I?.getInventoryByStore?.map((e=>{const t=h?.id,s=e.productId,r=Ut[t]||{};return{id:e.productId,name:e.product.name,image:e.product.image||r[s]||"https://picsum.photos/200",price:e.price,description:e.product.description,categoryId:e.product.category.id,categoryName:e.product.category.name,inventoryId:e.id,quantity:e.quantity,measurement:e.measurement,unit:e.unit,isAvailable:e.isAvailable,isListed:e.isListed,cutTypes:Array.isArray(e.cutTypes)?e.cutTypes:[]}}))||[]),[I,h?.id]),P=(0,A.useMemo)((()=>{const e=new Map;return w.forEach((t=>{null!=t.categoryId&&t.categoryName&&e.set(t.categoryId,t.categoryName)})),Array.from(e.entries()).sort(((e,t)=>e[1].localeCompare(t[1],void 0,{sensitivity:"base"})))}),[w]),k=(0,A.useMemo)((()=>{if(0===w.length)return[0,0];const e=w.map((e=>e.price));return[Math.floor(Math.min(...e)),Math.ceil(Math.max(...e))]}),[w]);(0,A.useEffect)((()=>{m(k)}),[k]),(0,A.useEffect)((()=>{o(null),d("default"),x(!1),r(0)}),[h?.id]),(0,A.useEffect)((()=>{r(0)}),[p,a,l,c,u]);const E=(0,A.useMemo)((()=>{let e=0;return c&&(e+=1),k[1]>k[0]&&(u[0]>k[0]||u[1]{d("default"),x(!1),m(k)}),[k]),F=(0,A.useMemo)((()=>{const e=p.trim().toLowerCase();return w.filter((t=>(null===a||t.categoryId===a)&&(!(c&&!t.isAvailable)&&(!(t.priceu[1])&&(!e||(t.name.toLowerCase().includes(e)||t.categoryName?.toLowerCase().includes(e))))))).sort(((e,t)=>{switch(l){case"price_asc":return e.price-t.price;case"price_desc":return t.price-e.price;case"name_asc":return e.name.localeCompare(t.name,void 0,{sensitivity:"base"});case"name_desc":return t.name.localeCompare(e.name,void 0,{sensitivity:"base"});default:return e.isAvailable===t.isAvailable?0:e.isAvailable?-1:1}}))}),[w,p,a,l,c,u]),D=(0,A.useMemo)((()=>F.slice(s*n,s*n+n)),[F,s,n]);return C?(0,ne.jsxs)(y.A,{children:["Error fetching products: ",C.message]}):(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(nt,{search:e,onSearchChange:t,sortBy:l,onSortChange:d,inStockOnly:c,onInStockOnlyChange:x,priceRange:u,onPriceRangeChange:m,priceBounds:k,activeFilterCount:E,onClearFilters:L}),!S&&w.length>0&&(0,ne.jsx)(Ge,{categories:P,selectedCategoryId:a,onSelectCategory:o}),S?(0,ne.jsx)(f.A,{display:"flex",justifyContent:"center",my:4,children:(0,ne.jsx)(b.A,{})}):0===w.length?(0,ne.jsx)(y.A,{variant:"h6",align:"center",sx:{mt:4},children:"No products available in this store."}):0===F.length?(0,ne.jsx)(y.A,{variant:"body1",align:"center",sx:{mt:4,color:"text.secondary"},children:"No products match your filters. Try adjusting your search or filters."}):(0,ne.jsx)(Me,{products:D}),F.length>0&&(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,ne.jsx)(v.A,{rowsPerPageOptions:[8,12,24],component:"div",count:F.length,rowsPerPage:n,page:s,onPageChange:(e,t)=>{r(t)},onRowsPerPageChange:e=>{i(parseInt(e.target.value,10)),r(0)}})})]})};var Bt=s(49799),Mt=s(44090),_t=s(57873),Vt=s(82241),Ht=s(58620),Gt=s(78325),Kt=s(92183),Yt=s(87980),Xt=s(54415),Qt=s(84201);const Zt="/login",Jt="/forgot-password",es="/admin",ts="/user",ss="/delivery_agent",rs="/store_manager",ns="/store_manager/orders",is="/orders",as="/profile",os="/signup",ls="/cart";var ds=s(28939),cs=s(48393),xs=s(80437),us=s(58438),ms=s(62594);const hs=e=>{let{email:t,onComplete:s,onSuccess:r}=e;const n=(0,d.Zp)(),[i,a]=(0,A.useState)(""),[o,l]=(0,A.useState)(!1),[c,x]=(0,A.useState)(""),[u,m]=(0,A.useState)("");return(0,ne.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),l(!0),x(""),m("");try{await(0,ms.z)({username:t,confirmationCode:i}),m("Account verified successfully! Redirecting to login..."),setTimeout((()=>{n("/")}),2e3),r&&r(),s&&s()}catch(e){x(e.message||"OTP verification failed. Please try again.")}finally{l(!1)}},children:[(0,ne.jsx)(y.A,{variant:"h4",component:"h1",gutterBottom:!0,children:"Verify OTP"}),(0,ne.jsx)(le.A,{label:"Enter OTP",variant:"outlined",fullWidth:!0,margin:"normal",value:i,onChange:e=>a(e.target.value),required:!0}),c&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mt:2},children:c}),u&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mt:2},children:u}),(0,ne.jsx)(ae.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,ne.jsx)(b.A,{size:24,sx:{color:"primary.contrastText"}}):"Verify OTP"})]})};var ps=s(5673),As=s(76768);const gs=e=>{let{onSuccess:t,onError:s}=e;const r=(0,d.Zp)(),{setUser:n,setAbility:i,setModalOpen:a,skipNavigateOnLogin:o}=te(),[l,c]=(0,A.useState)(""),[x,u]=(0,A.useState)(""),[m,h]=(0,A.useState)(!1),[p,g]=(0,A.useState)(""),[y,j]=(0,A.useState)(!1),[v,I]=(0,A.useState)(!1);return(0,ne.jsx)(f.A,{children:y?(0,ne.jsx)(hs,{email:l,onSuccess:()=>r("/"),onComplete:()=>j(!1)}):(0,ne.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),h(!0),g("");try{const e=await(0,cs.J)({username:l,password:x});if("CONFIRM_SIGN_UP"===e.nextStep?.signInStep)return await(0,xs.h)({username:l}),void j(!0);const s=await(0,us.T)(),d=s["custom:role"].toLowerCase();n({email:s.email,role:d});const c=Q(d);i(c);const u=o;a(!1),t&&t(),u||r(`/${d}`)}catch(e){if(e.message.includes("User is not confirmed"))try{await(0,xs.h)({username:l}),j(!0)}catch(e){g(e.message||"Error resending OTP.")}else g(e.message||"Login failed. Please try again.")}finally{h(!1)}},children:[(0,ne.jsx)(le.A,{label:"Email",variant:"outlined",fullWidth:!0,value:l,onChange:e=>c(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Ae.A,{sx:{color:"primary.main"}})})}}),(0,ne.jsx)(le.A,{label:"Password",variant:"outlined",type:v?"text":"password",fullWidth:!0,value:x,onChange:e=>u(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(ge.A,{sx:{color:"primary.main"}})}),endAdornment:(0,ne.jsx)(ye.A,{position:"end",children:(0,ne.jsx)(be.A,{onClick:()=>I((e=>!e)),edge:"end",children:v?(0,ne.jsx)(As.A,{}):(0,ne.jsx)(ps.A,{})})})}}),p&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:p}),(0,ne.jsx)(ae.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:m,sx:{py:1.2,borderRadius:"8px",textTransform:"none",fontSize:"1rem"},children:m?(0,ne.jsx)(b.A,{size:24,sx:{color:"primary.contrastText"}}):"Login"})]})})};var ys=s(83728),js=s(71432),fs=s(19873);const bs=e=>{let{referredBy:t="",onSuccess:s}=e;const[r,n]=(0,A.useState)(""),[i,a]=(0,A.useState)(""),[o,l]=(0,A.useState)(""),[d,c]=(0,A.useState)(""),[x,u]=(0,A.useState)(""),[m,h]=(0,A.useState)(t),[p,g]=(0,A.useState)(!1),[y,j]=(0,A.useState)(""),[b,v]=(0,A.useState)(""),[I,S]=(0,A.useState)(!1);return(0,ne.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),g(!0),j(""),v("");try{await(0,ys.H)({username:r,password:d,options:{userAttributes:{"custom:given_name":i,"custom:family_name":o,"custom:phone_number":x,"custom:referredBy":m}}}),v("Signup successful! Enter the OTP sent to your email."),s&&s(r)}catch(e){if(e.message.includes("User already exists"))try{await(0,xs.h)({username:r}),v("OTP resent. Please check your email."),s&&s(r)}catch(e){j(e.message||"Error resending OTP.")}else j(e.message||"Signup failed. Please try again.")}finally{g(!1)}},children:[(0,ne.jsx)(le.A,{label:"First Name",variant:"outlined",fullWidth:!0,value:i,onChange:e=>a(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(js.A,{sx:{color:"primary.main"}})})}}),(0,ne.jsx)(le.A,{label:"Last Name",variant:"outlined",fullWidth:!0,value:o,onChange:e=>l(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(js.A,{sx:{color:"primary.main"}})})}}),(0,ne.jsx)(le.A,{label:"Email",variant:"outlined",fullWidth:!0,value:r,onChange:e=>n(e.target.value),required:!0,sx:{mb:2},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Ae.A,{sx:{color:"primary.main"}})})}}),(0,ne.jsx)(le.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,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(ge.A,{sx:{color:"primary.main"}})}),endAdornment:(0,ne.jsx)(ye.A,{position:"end",children:(0,ne.jsx)(be.A,{onClick:()=>S((e=>!e)),edge:"end",children:I?(0,ne.jsx)(As.A,{}):(0,ne.jsx)(ps.A,{})})})}}),(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:1,mb:2},children:[(0,ne.jsx)(le.A,{label:"Country Code",variant:"outlined",value:"+1",disabled:!0,sx:{width:"120px"},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(fs.A,{sx:{color:"primary.main"}})})}}),(0,ne.jsx)(le.A,{label:"Phone Number",variant:"outlined",fullWidth:!0,value:x,onChange:e=>u(e.target.value),required:!0,InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(fs.A,{sx:{color:"primary.main"}})})}})]}),(0,ne.jsx)(le.A,{label:"Referral Code",variant:"outlined",fullWidth:!0,value:m,onChange:e=>h(e.target.value),disabled:!!t,sx:{mb:2},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Ae.A,{sx:{color:"primary.main"}})})}}),y&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:y}),b&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:b}),(0,ne.jsx)(ae.A,{type:"submit",variant:"contained",color:"primary",fullWidth:!0,disabled:p,sx:{mt:1,mb:2},children:p?"Processing...":"Sign Up"})]})};var vs=s(15061),Is=s(7888);const Ss=e=>{let{onSuccess:t}=e;const[s,r]=(0,A.useState)(""),[n,i]=(0,A.useState)(""),[a,o]=(0,A.useState)(""),[l,x]=(0,A.useState)(!1),[u,m]=(0,A.useState)(""),[h,p]=(0,A.useState)(""),[g,y]=(0,A.useState)(1),j=(0,d.Zp)();return(0,ne.jsx)(ie,{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:e=>`linear-gradient(135deg, ${(0,c.X4)(e.palette.primary.main,.1)} 0%, ${(0,c.X4)(e.palette.primary.main,.05)} 100%)`,zIndex:0}},children:(0,ne.jsxs)(he,{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,ne.jsxs)(ie,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,ne.jsx)(ce,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:1===g?"Forgot Password":"Reset Password"}),(0,ne.jsx)(ce,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:1===g?"Enter your email address to receive a reset code":"Enter the OTP sent to your email and your new password"})]}),1===g?(0,ne.jsx)(je,{fields:[{label:"Email",type:"email",value:s,onChange:r}],onSubmit:async e=>{e.preventDefault(),x(!0),m(""),p("");try{await(0,vs.x)({username:s}),y(2),p("OTP sent successfully! Check your email.")}catch(e){m(e.message||"Failed to send OTP. Try again.")}finally{x(!1)}},buttonLabel:"Send OTP",loading:l,error:u,success:h}):(0,ne.jsx)(je,{fields:[{label:"OTP",type:"text",value:n,onChange:i},{label:"New Password",type:"password",value:a,onChange:o}],onSubmit:async e=>{e.preventDefault(),x(!0),m(""),p("");try{await(0,Is.P)({username:s,confirmationCode:n,newPassword:a}),p("Password reset successfully! Redirecting to login..."),setTimeout((()=>{t?t():j("/")}),2e3)}catch(e){m(e.message||"Failed to reset password. Try again.")}finally{x(!1)}},buttonLabel:"Reset Password",loading:l,error:u,success:h})]})})},Cs=e=>{let{open:t,onClose:s,initialForm:r="login"}=e;const[n,i]=(0,A.useState)(r),[a,o]=(0,A.useState)(""),[l,d]=(0,A.useState)(!1),c=(0,A.useRef)(0),x=(0,qe.A)();(0,A.useEffect)((()=>{t&&(i("login"),d(!1),o(""),c.current+=1)}),[t]);const u=e=>{i(e),d(!1)};return(0,ne.jsx)(ds.A,{open:t,onClose:s,"aria-labelledby":"modal-modal-title","aria-describedby":"modal-modal-description",sx:{display:"flex",alignItems:"center",justifyContent:"center"},children:(0,ne.jsxs)(f.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,ne.jsx)(ae.A,{onClick:s,sx:{position:"absolute",top:8,right:8,minWidth:0,p:.5},children:(0,ne.jsx)(st.A,{})}),(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.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,ne.jsx)(y.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,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:"Email verified successfully! Please login to continue."}),"login"===n?(0,ne.jsx)(gs,{onSuccess:s},`login-form-${c.current}`):"signup"===n?(0,ne.jsx)(bs,{onSuccess:e=>{o(e),i("otp")}}):"otp"===n?(0,ne.jsx)(hs,{email:a,onSuccess:()=>{d(!0),i("login")}}):(0,ne.jsx)(Ss,{onSuccess:()=>u("login")}),(0,ne.jsxs)(f.A,{sx:{mt:3,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:["login"===n&&(0,ne.jsx)(ae.A,{onClick:()=>u("forgotPassword"),sx:{color:x.palette.primary.main,textTransform:"none"},children:"Forgot Password?"}),"otp"!==n&&(0,ne.jsxs)(y.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,ne.jsx)(ae.A,{color:"primary",onClick:()=>u("login"===n?"signup":"login"),sx:{textTransform:"none"},children:"login"===n?"Sign Up":"Login"})]})]})]})})};var ws=s(17532),Ps=s(10423),ks=s(10420),Es=s(74202),$s=s(92659),Ls=s(37856),Fs=s(42702),Ds=s(28800),zs=s(58407),Ts=s(72048),Rs=s(2223),Ws=s(2882),qs=s(10364),Os=s(20889),Us=s(85873);const Ns=e=>{let{store:t,isSelected:s,onSelect:r}=e;const n=t.isActive;return(0,ne.jsxs)(f.A,{role:"button",tabIndex:n?0:-1,onClick:()=>n&&r(t),onKeyDown:e=>{!n||"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),r(t))},"aria-disabled":!n,"aria-pressed":s,sx:{display:"flex",gap:2,alignItems:"flex-start",px:2.25,py:2.25,borderRadius:2,border:"1px solid",borderColor:s?"primary.main":"divider",backgroundColor:s?"primary.lighter":"background.paper",cursor:n?"pointer":"not-allowed",opacity:n?1:.6,transition:"border-color 120ms ease, background-color 120ms ease","&:hover":n?{borderColor:s?"primary.main":"text.primary",backgroundColor:s?"primary.lighter":"action.hover"}:{},"&:focus-visible":{outline:"2px solid",outlineColor:"primary.main",outlineOffset:2}},children:[(0,ne.jsx)(f.A,{sx:{width:36,height:36,borderRadius:1.25,backgroundColor:s?"primary.lighter":"grey.100",color:s?"primary.main":"text.secondary",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,mt:.25},children:n?(0,ne.jsx)(ks.A,{sx:{fontSize:19}}):(0,ne.jsx)(Us.A,{sx:{fontSize:19}})}),(0,ne.jsxs)(f.A,{sx:{flex:1,minWidth:0},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"wrap"},children:[(0,ne.jsx)(y.A,{sx:{fontWeight:600,fontSize:"1rem",color:"text.primary"},children:t.name}),!n&&(0,ne.jsx)(Oe.A,{label:"Closed",size:"small",sx:{height:20,fontSize:"0.7rem",fontWeight:600,color:"error.main",backgroundColor:"error.lighter",border:"1px solid",borderColor:"error.light"}})]}),t.description&&(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:.75,mt:.75},children:[(0,ne.jsx)(Ws.A,{sx:{fontSize:14,color:"text.secondary"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.82rem",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.description})]}),t.address&&(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:.75,mt:.75},children:[(0,ne.jsx)(Rs.A,{sx:{fontSize:14,color:"text.secondary"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.82rem",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.address})]}),t.radius&&(0,ne.jsx)(f.A,{sx:{mt:1.5},children:(0,ne.jsx)(Oe.A,{icon:(0,ne.jsx)(qs.A,{sx:{fontSize:12}}),label:`${t.radius} mi radius`,size:"small",variant:"outlined",sx:{height:22,fontSize:"0.7rem",fontWeight:500,borderColor:"grey.300",color:"text.secondary","& .MuiChip-icon":{color:"text.secondary",ml:"6px"}}})})]}),s&&(0,ne.jsx)(Os.A,{sx:{color:"primary.main",fontSize:20,flexShrink:0,mt:.625}})]})},Bs=e=>{let{availableStores:t,selectedStore:s,handleStoreSelect:r}=e;return(0,ne.jsx)(St.A,{spacing:1.5,children:t.map((e=>(0,ne.jsx)(Ns,{store:e,isSelected:s?.id===e.id,onSelect:r},e.id)))})},Ms=e=>{let{subtitle:t}=e;return(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{sx:{fontWeight:600,fontSize:"1.1rem",color:"text.primary",lineHeight:1.3},children:"Select a store"}),t&&(0,ne.jsx)(y.A,{sx:{mt:.5,fontSize:"0.82rem",color:"text.secondary",lineHeight:1.35},children:t})]})},_s=()=>(0,ne.jsx)(me.A,{elevation:0,sx:{p:3,textAlign:"center",backgroundColor:e=>(0,c.X4)(e.palette.info.main,.1),borderRadius:2},children:(0,ne.jsx)(y.A,{sx:{fontWeight:500,color:"info.main"},children:"No stores available at the moment."})}),Vs=e=>{let{value:t,onChange:s,onValidAddress:r}=e;const n=(0,A.useRef)(null),i=(0,A.useRef)(null),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(null);(0,A.useEffect)((()=>{const e=setTimeout((()=>{try{if("undefined"!=typeof window&&window.google&&window.google.maps&&window.google.maps.places&&i.current){d(!0);const e=i.current;if(!e)return void d(!1);const t=new window.google.maps.places.Autocomplete(e,{types:["address"],componentRestrictions:{country:"us"}});n.current=t;const a=document.querySelector(".pac-container");a&&(document.body.appendChild(a),a.style.zIndex="99999"),t.addListener("place_changed",(()=>{const e=t.getPlace();e&&e.formatted_address?(x(e),s(e.formatted_address),o(!0),r(!0)):(x(null),o(!1),r(!1))}))}else d(!1),t&&t.trim().length>10?(o(!0),r(!0)):(o(!1),r(!1))}catch(e){d(!1),t&&t.trim().length>10?(o(!0),r(!0)):(o(!1),r(!1))}}),300);return()=>clearTimeout(e)}),[s,r,t]),(0,A.useEffect)((()=>{""===t?(o(!1),r(!1),x(null)):!l&&t.trim().length>10&&(o(!0),r(!0))}),[t,r,l]);return(0,ne.jsx)(le.A,{inputRef:i,label:"Address",fullWidth:!0,multiline:!0,rows:3,value:t,error:!a&&""!==t,helperText:l?a||""===t?l&&!c?"Start typing to see address suggestions...":"":"Please select a valid address from the suggestions above.":"Enter your complete address (street, city, state, zip code)",onChange:e=>{const t=e.target.value;s(t),l&&c&&t!==c.formatted_address?(o(!1),r(!1),x(null)):l||(t.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)"})},Hs=e=>{let{size:t=24,sx:s}=e;return(0,ne.jsx)(b.A,{size:t,sx:{color:"inherit",...s}})},Gs=e=>{let{pincodes:t=[]}=e;const[s,r]=(0,A.useState)(!1),[n,i]=(0,A.useState)(""),a=(0,A.useMemo)((()=>[...t].map((e=>String(e).trim())).filter(Boolean).sort(((e,t)=>e.localeCompare(t)))),[t]),o=(0,A.useMemo)((()=>{if(!n.trim())return a;const e=n.trim();return a.filter((t=>t.includes(e)))}),[a,n]),l=a.length>30;return 0===a.length?null:(0,ne.jsxs)(me.A,{elevation:0,sx:{border:"1px solid",borderColor:"divider",borderRadius:2,overflow:"hidden"},children:[(0,ne.jsxs)(f.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,ne.jsx)(Ls.A,{sx:{fontSize:18,color:"text.secondary"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{flex:1,fontWeight:600,fontSize:"0.85rem"},children:"Serviceable pincodes"}),(0,ne.jsx)(Oe.A,{label:a.length,size:"small",sx:{height:22,fontSize:"0.72rem",fontWeight:700,bgcolor:"rgba(0,0,0,0.06)"}}),(0,ne.jsx)(Ts.A,{sx:{fontSize:20,color:"text.secondary",transition:"transform 0.25s",transform:s?"rotate(180deg)":"rotate(0deg)"}})]}),(0,ne.jsxs)(Ye.A,{in:s,timeout:250,children:[(0,ne.jsx)(Ct.A,{}),(0,ne.jsxs)(f.A,{sx:{px:2,py:1.5},children:[l&&(0,ne.jsx)(le.A,{size:"small",placeholder:"Search pincode…",value:n,onChange:e=>i(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Je.A,{sx:{fontSize:18,color:"text.disabled"}})})},sx:{mb:1.5,"& .MuiOutlinedInput-root":{borderRadius:"10px",fontSize:"0.85rem",height:36}}}),0===o.length?(0,ne.jsxs)(y.A,{variant:"body2",color:"text.disabled",sx:{textAlign:"center",py:1,fontSize:"0.82rem"},children:['No pincodes match "',n,'"']}):(0,ne.jsx)(f.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,ne.jsx)(Oe.A,{label:e,size:"small",variant:"outlined",sx:{fontSize:"0.75rem",fontWeight:500,height:26,borderRadius:"8px",borderColor:"grey.300"}},e)))})]})]})]})},Ks=e=>{let{open:t,onClose:s,forceStep:r,initialStore:n}=e;const{selectedStore:i,setSelectedStore:o,availableStores:l,setPickupAddress:d,deliveryType:c,setDeliveryType:x,setDeliveryAddressString:u}=re(),{user:m,userProfile:h,fetchUserProfile:p,isProfileLoading:g,setModalOpen:j,setCurrentForm:b,setSkipNavigateOnLogin:v}=te(),I=(0,a.jE)(),{addresses:C,selectedAddressId:w,setSelectedAddressId:P,fetchAddresses:k,isLoading:E,createAddress:$}=se(),[L,F]=(0,A.useState)("store"),[D,z]=(0,A.useState)(null),[T,R]=(0,A.useState)(null),[W,q]=(0,A.useState)(null),[O,U]=(0,A.useState)(""),[N,B]=(0,A.useState)(!1),[M,_]=(0,A.useState)(""),[V,H]=(0,A.useState)(!1),[G,K]=(0,A.useState)(!1),[Y,X]=(0,A.useState)(!1),[Q,Z]=(0,A.useState)(""),[J,ee]=(0,A.useState)(0),[ie,oe]=(0,A.useState)([]),[de,ce]=(0,A.useState)(""),[ue,he]=(0,A.useState)(null),pe=h?C:ie,Ae=h?w:de;(0,A.useEffect)((()=>{const e=!!h;!1===ue&&!0===e&&(oe([]),ce(""),h?.id&&"pickup"===L&&D&&k(h.id),q(null),U("")),!0===ue&&!1===e&&P(null),he(e)}),[h,L,D,k,P,ue]),(0,A.useEffect)((()=>{"pickup"===L&&D&&h?.id&&k(h.id)}),[L,D,h?.id,k]),(0,A.useEffect)((()=>{if(!("pickup"===L&&(1===J||!D?.pickupAddresses?.edges?.length))||h)return;let e=!1;return(async()=>{try{const t=await(0,S.$)(),s=t?.tokens?.idToken?.payload?.sub;s&&!e&&await p(s)}catch{}})(),()=>{e=!0}}),[L,J,h,m,p,D]),(0,A.useEffect)((()=>{t&&r&&(F(r),n&&z(n)),t||(F("store"),z(null),ge())}),[t,r,n]);const ge=()=>{h?P(null):ce(""),_(""),H(!1),K(!1),X(!1),q(null),U(""),R(null),ee(0),Z("")},je=e=>{if(!e||!D)return q(null),U(""),!1;const t=e.match(/\b(\d{5})(?:-\d{4})?\b/g),s=t?t[t.length-1]:null,r=(D?.pincodes||[]).map((e=>String(e).trim())),n=s?String(s).trim():"";return n&&r.includes(n)?(q("success"),U("Store delivers here"),!0):(q("error"),U("Store does not deliver here."),!1)},fe=()=>{if("success"===W&&Q){let e=Q;if(h&&w&&C&&C.length>0){const t=C.find((e=>e.id===w));t&&t.address&&(e=t.address)}if(!e||!e.trim())return;o(D),setTimeout((()=>{d(null),x("delivery"),u(e.trim())}),10),setTimeout((()=>{F("store"),z(null),ge(),s()}),1200)}},ve=!i,[Ie,Se]=(0,A.useState)(""),Ce=(0,A.useMemo)((()=>{const e=Ie.trim().toLowerCase();return e?l.filter((t=>[t.name,t.address,t.description].filter(Boolean).some((t=>String(t).toLowerCase().includes(e))))):l}),[l,Ie]),we="pickup"===L,Pe=l.length>5,ke=D?.pickupAddresses?.edges?.map((e=>e.node))||[],Ee=ke.length>0,$e=we?(0,ne.jsx)(Ms,{subtitle:D?`Choose how you'd like to receive your order from ${D.name}`:void 0}):(0,ne.jsx)(Ms,{subtitle:"Choose where you'd like to shop. You can switch at any time."}),Le=we?(0,ne.jsx)(ae.A,{onClick:()=>{F("store"),z(null),ge()},variant:"text",color:"inherit",size:"small",startIcon:(0,ne.jsx)($s.A,{}),sx:{fontWeight:500},children:"Back to stores"}):null;return(0,ne.jsxs)(dt,{open:t,onClose:s,title:$e,footer:Le,hideClose:ve,height:"640px",contentSx:{px:0,pt:0,pb:0},children:[!we&&(0,ne.jsx)(f.A,{sx:{px:3,pt:3.5,pb:3},children:0===l.length?(0,ne.jsx)(_s,{}):(0,ne.jsxs)(ne.Fragment,{children:[Pe&&(0,ne.jsx)(le.A,{size:"small",placeholder:"Search stores by name or address…",value:Ie,onChange:e=>Se(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Je.A,{sx:{fontSize:18,color:"text.disabled"}})})},sx:{mb:2,"& .MuiOutlinedInput-root":{borderRadius:"10px",fontSize:"0.9rem"}}}),0===Ce.length?(0,ne.jsx)(f.A,{sx:{textAlign:"center",py:4},children:(0,ne.jsxs)(y.A,{variant:"body2",color:"text.secondary",children:['No stores match "',Ie,'".']})}):(0,ne.jsx)(Bs,{availableStores:Ce,selectedStore:i,handleStoreSelect:e=>{localStorage.setItem("selectedStoreId",String(e.id)),z(e),F("pickup")}})]})}),we&&(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,ne.jsx)(f.A,{sx:{borderBottom:1,borderColor:"divider",flexShrink:0},children:(0,ne.jsxs)(ws.A,{value:J,onChange:(e,t)=>ee(t),variant:"fullWidth",sx:{minHeight:46,"& .MuiTabs-indicator":{height:3,borderRadius:"3px 3px 0 0"}},children:[(0,ne.jsx)(Ps.A,{icon:(0,ne.jsx)(ks.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Pickup",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:46,py:0}}),(0,ne.jsx)(Ps.A,{icon:(0,ne.jsx)(Es.A,{sx:{fontSize:18}}),iconPosition:"start",label:"Delivery",sx:{fontWeight:600,textTransform:"none",fontSize:"0.9rem",minHeight:46,py:0}})]})}),(0,ne.jsxs)(f.A,{sx:{flex:1,minHeight:0,overflowY:"auto",px:3,pt:2.5,pb:2.5,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-thumb":{backgroundColor:"rgba(0,0,0,0.15)",borderRadius:3}},children:[0===J&&(0,ne.jsx)(St.A,{spacing:2,children:Ee?(0,ne.jsxs)(ne.Fragment,{children:[ke.map((e=>(0,ne.jsxs)(me.A,{elevation:0,onClick:()=>{return t={target:{value:String(e.id)}},R(t.target.value),x("pickup"),u(null),h?P(null):ce(""),q(null),void U("");var t},sx:{p:2,cursor:"pointer",border:"1.5px solid",borderColor:String(T)===String(e.id)?"primary.main":"grey.200",borderRadius:2,bgcolor:String(T)===String(e.id)?"primary.50":"transparent",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:"grey.50"},display:"flex",alignItems:"center",gap:1.5},children:[(0,ne.jsx)(Rt.A,{checked:String(T)===String(e.id),value:String(e.id),color:"primary",size:"small",sx:{p:0}}),(0,ne.jsx)(y.A,{variant:"body2",children:e.address})]},e.id))),(0,ne.jsx)(ae.A,{onClick:()=>{if(!D||!T)return;const e=(D.pickupAddresses?.edges?.map((e=>e.node))||[]).find((e=>String(e.id)===String(T)));o(D),d(e),x("pickup"),u(null),F("store"),z(null),R(null),ge(),s()},variant:"contained",color:"primary",fullWidth:!0,startIcon:(0,ne.jsx)(Ls.A,{}),disabled:!T,sx:{mt:1,fontWeight:600,py:1.2,fontSize:"0.95rem",borderRadius:2},children:"Confirm Pickup"})]}):(0,ne.jsx)(xe.A,{severity:"info",sx:{mt:2},children:(0,ne.jsx)(y.A,{variant:"body2",children:"No pickup points available for this store."})})}),1===J&&(0,ne.jsxs)(St.A,{spacing:2,children:[(0,ne.jsx)(Gs,{pincodes:D?.pincodes}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:-1},children:"Enter your delivery address to check availability"}),(0,ne.jsx)(Vs,{value:M,onChange:e=>{_(e),Q&&(q(null),U(""),Z(""))},onValidAddress:X}),W&&(0,ne.jsx)(xe.A,{severity:W,sx:{borderRadius:1.5},icon:"success"===W?(0,ne.jsx)(zs.A,{}):void 0,children:O}),h?(0,ne.jsx)(ne.Fragment,{children:pe.length>0&&(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(Ct.A,{sx:{my:1},children:(0,ne.jsx)(Oe.A,{label:"Your Saved Addresses",size:"small",variant:"outlined"})}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"flex-end"},children:(0,ne.jsx)(De.A,{title:"Refresh addresses",children:(0,ne.jsx)(be.A,{size:"small",onClick:async()=>{B(!0);try{const e=await(0,S.$)(),t=e?.tokens?.idToken?.payload?.sub;if(t){if(h||await p(t),h?.id||t){const e=h?.id;e&&(await k(e),oe([]),ce(""))}}else P(null);q(null),U("")}catch(e){}finally{B(!1)}},disabled:N,sx:{border:"1px solid",borderColor:"divider",width:28,height:28},children:N?(0,ne.jsx)(Hs,{size:14}):(0,ne.jsx)(Fs.A,{sx:{fontSize:16}})})})}),E||N?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,ne.jsx)(Hs,{size:24})}):(0,ne.jsx)(St.A,{spacing:1.5,children:pe.map((e=>(0,ne.jsxs)(me.A,{elevation:0,onClick:()=>(e=>{h?P(e.id):ce(e.id),Z(e.address),_(""),X(!1),je(e.address),x("delivery"),R(null)})(e),sx:{p:1.5,cursor:"pointer",border:"1.5px solid",borderColor:Ae===e.id?"secondary.main":"grey.200",borderRadius:2,bgcolor:Ae===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,ne.jsx)(Rt.A,{checked:Ae===e.id,color:"secondary",size:"small",sx:{p:0}}),(0,ne.jsxs)(f.A,{sx:{flex:1,minWidth:0},children:[(0,ne.jsx)(y.A,{variant:"body2",noWrap:!0,children:e.address}),e.isPrimary&&(0,ne.jsx)(Oe.A,{label:"Primary",size:"small",color:"secondary",variant:"outlined",sx:{mt:.5,height:20,fontSize:"0.7rem"}})]})]},e.id)))})]})}):(0,ne.jsx)(xe.A,{severity:"info",icon:(0,ne.jsx)(Ds.A,{fontSize:"small"}),action:(0,ne.jsx)(ae.A,{color:"inherit",size:"small",onClick:()=>{v(!0),j(!0),b("login")},sx:{fontWeight:600},children:"Login"}),sx:{borderRadius:1.5},children:"Sign in to use your saved addresses"}),(0,ne.jsx)(ae.A,{onClick:async()=>{if("success"===W&&Q)return void fe();if(!M.trim()||!Y)return q("error"),void U("Please enter a valid address to continue.");await(async()=>{if(!M.trim()||!Y)return!1;const e=je(M);if(Z(M),x("delivery"),R(null),h?P(null):ce(""),h?.id){if(!C.some((e=>e.address.toLowerCase().trim()===M.toLowerCase().trim()))){K(!0);try{await $(M,h.id,V);const e=(await k(h.id)).find((e=>e.address.toLowerCase().trim()===M.toLowerCase().trim()));e&&P(e.id),I.invalidateQueries(["userAddresses",h.id])}catch(e){}finally{K(!1)}}}else if(!ie.some((e=>e.address.toLowerCase().trim()===M.toLowerCase().trim()))){const e={id:`temp_${Date.now()}`,address:M,isPrimary:0===ie.length};oe((t=>[...t,e])),ce(e.id)}return e})()&&fe()},variant:"contained",color:"secondary",fullWidth:!0,startIcon:G?(0,ne.jsx)(Hs,{size:18}):(0,ne.jsx)(Es.A,{}),disabled:G||!Q&&(!M.trim()||!Y),sx:{fontWeight:600,py:1.2,fontSize:"0.95rem",borderRadius:2},children:G?"Validating Address...":"success"===W&&Q?"Confirm Delivery":"Validate & Confirm Delivery"})]})]})]})]})};var Ys=s(62274);const Xs=e=>{let{storeName:t,canSwitch:s,onSwitch:r}=e;const n=t||"Select a store",i={display:"inline-flex",alignItems:"center",gap:1,maxWidth:{xs:200,sm:320,md:"none"},px:{xs:1.25,sm:1.75},py:.75,borderRadius:9999,border:"1px solid",borderColor:"divider",backgroundColor:"background.paper",color:"text.primary",textTransform:"none",fontWeight:600,fontSize:{xs:"0.92rem",sm:"1rem"},letterSpacing:0,transition:"border-color 120ms ease, background-color 120ms ease"};return s?(0,ne.jsxs)(oe,{onClick:r,disableRipple:!1,sx:{...i,cursor:"pointer","&:hover":{borderColor:"text.primary",backgroundColor:"action.hover"}},children:[(0,ne.jsx)(Gt.A,{sx:{fontSize:18,color:"text.secondary"}}),(0,ne.jsx)(ce,{component:"span",sx:{fontWeight:600,fontSize:"inherit",color:t?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n}),(0,ne.jsx)(Kt.A,{sx:{fontSize:18,color:"text.secondary",ml:-.25}})]}):(0,ne.jsxs)(ie,{sx:i,children:[(0,ne.jsx)(Gt.A,{sx:{fontSize:18,color:"text.secondary"}}),(0,ne.jsx)(ce,{sx:{fontWeight:600,fontSize:"inherit",color:t?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n})]})},Qs=()=>{const e=(0,d.Zp)(),[t,s]=(0,A.useState)(null),r=(0,Ke.A)("(max-width: 600px)"),n=re((e=>e.cartCount())),i=re((e=>e.selectedStore)),{user:a,ability:o,logout:l}=te(),[x,u]=A.useState(null),{modalOpen:m,setModalOpen:h,currentForm:p,setCurrentForm:g}=te(),[y,j]=(0,A.useState)(null),[f,b]=(0,A.useState)(!1),[v,I]=(0,A.useState)(!1);(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,S.$)(),t=await(0,us.T)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;j(t)}const r=t["custom:role"]?.toLowerCase();s(r)}catch(e){j(null),s(null)}})()}),[a]);const C=()=>{h(!0),g("login")},w=async()=>{let s=t;if(!s)try{const e=await(0,S.$)();e?.tokens?.idToken&&(s=e.tokens.idToken.payload["custom:role"]?.toLowerCase())}catch(e){}e(s?`/${s}`:"/")},P=async()=>{try{await(0,Qt.C)(),l(),j(null),s(null),e("/")}catch(e){}},k=()=>u(null),E=Q(a?.role||"user");(0,A.useEffect)((()=>{!r&&v&&I(!1)}),[r,v]);const $=(0,ne.jsxs)(ie,{sx:{width:270,height:"100%",bgcolor:"background.paper",boxShadow:3,display:"flex",flexDirection:"column"},role:"presentation",onClick:()=>I(!1),children:[(0,ne.jsx)(ie,{sx:{display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",px:2,py:2.5,minHeight:64,boxShadow:1},children:(0,ne.jsx)(ce,{variant:"h6",sx:{fontWeight:800,letterSpacing:1,fontSize:"1.35rem",color:"primary.contrastText",textAlign:"center"},children:"Menu"})}),(0,ne.jsx)(Ct.A,{}),(0,ne.jsxs)(Bt.A,{sx:{flex:1,py:1},children:[(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:w,sx:{py:2},children:[(0,ne.jsx)(_t.A,{sx:{color:"primary.main",minWidth:40},children:(0,ne.jsx)(Gt.A,{})}),(0,ne.jsx)(Vt.A,{primary:(0,ne.jsx)(ce,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Home"})})]}),!y&&(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:C,sx:{py:2},children:[(0,ne.jsx)(_t.A,{sx:{color:"primary.main",minWidth:40},children:(0,ne.jsx)(Yt.A,{})}),(0,ne.jsx)(Vt.A,{primary:(0,ne.jsx)(ce,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Sign In"})})]}),t!==V&&t!==K&&t!==G&&(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:()=>b(!0),sx:{py:2},children:[(0,ne.jsx)(_t.A,{sx:{color:"primary.main",minWidth:40},children:(0,ne.jsx)(Gt.A,{})}),(0,ne.jsx)(Vt.A,{primary:(0,ne.jsx)(ce,{sx:{fontWeight:600,fontSize:"1.1rem"},children:i?"Change Store":"Select Store"})})]}),(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:()=>e(ls),sx:{py:2},children:[(0,ne.jsx)(_t.A,{sx:{color:"primary.main",minWidth:40},children:(0,ne.jsx)(Re.A,{})}),(0,ne.jsx)(Vt.A,{primary:(0,ne.jsx)(ce,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Cart"})})]}),y&&E?.can("view","orders")&&(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:()=>e(is),sx:{py:2},children:[(0,ne.jsx)(_t.A,{sx:{color:"primary.main",minWidth:40},children:(0,ne.jsx)(Xt.A,{})}),(0,ne.jsx)(Vt.A,{primary:(0,ne.jsx)(ce,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Orders"})})]}),y&&(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(Ct.A,{sx:{my:1.5}}),(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:()=>{e(as)},sx:{py:2},children:[(0,ne.jsx)(_t.A,{sx:{color:"primary.main",minWidth:40},children:(0,ne.jsx)(Yt.A,{})}),(0,ne.jsx)(Vt.A,{primary:(0,ne.jsx)(ce,{sx:{fontWeight:600,fontSize:"1.1rem"},children:"Profile"})})]}),(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:P,sx:{py:2},children:[(0,ne.jsx)(_t.A,{sx:{color:"error.main",minWidth:40},children:(0,ne.jsx)(Yt.A,{})}),(0,ne.jsx)(Vt.A,{primary:(0,ne.jsx)(ce,{sx:{fontWeight:600,fontSize:"1.1rem",color:"error.main"},children:"Logout"})})]})]})]}),(0,ne.jsx)(Ct.A,{}),(0,ne.jsxs)(ie,{sx:{p:2,textAlign:"center",color:"text.secondary",fontSize:"0.95rem"},children:["© ",(new Date).getFullYear()," Indimitra"]})]});return(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(ie,{sx:{position:"fixed",top:0,left:0,right:0,zIndex:1100,backgroundColor:"background.paper",borderBottom:"1px solid",borderColor:"divider"},children:(0,ne.jsxs)(xt,{sx:{minHeight:{xs:"56px",sm:"64px",md:"68px"},px:{xs:1.5,sm:3,md:4},gap:{xs:1,sm:2}},children:[(0,ne.jsx)(ie,{sx:{display:"flex",alignItems:"center",gap:{xs:1.25,sm:1.75},minWidth:0},children:(0,ne.jsx)(Xs,{storeName:i?.name,canSwitch:t!==V&&t!==K&&t!==G,onSwitch:()=>b(!0)})}),(0,ne.jsx)(ie,{sx:{flexGrow:1}}),r?(0,ne.jsx)(ve,{edge:"end","aria-label":"menu",onClick:()=>I(!0),sx:{ml:1,color:"text.primary"},children:(0,ne.jsx)(Ys.A,{})}):(0,ne.jsxs)(ie,{sx:{display:"flex",alignItems:"center",gap:{sm:.5,md:1}},children:[(0,ne.jsx)(oe,{onClick:w,sx:{color:"text.primary",textTransform:"none",fontSize:"0.95rem",fontWeight:500,px:2,py:1,borderRadius:1.5,"&:hover":{backgroundColor:"action.hover"}},children:"Home"}),!y&&(0,ne.jsx)(oe,{onClick:C,sx:{color:"text.primary",textTransform:"none",fontSize:"0.95rem",fontWeight:500,px:2,py:1,borderRadius:1.5,"&:hover":{backgroundColor:"action.hover"}},children:"Sign In"}),y&&E&&E.can("view","orders")&&(0,ne.jsx)(oe,{onClick:()=>e(is),sx:{color:"text.primary",textTransform:"none",fontSize:"0.95rem",fontWeight:500,px:2,py:1,borderRadius:1.5,"&:hover":{backgroundColor:"action.hover"}},children:"Orders"}),(!a||E?.can("view","cart"))&&(0,ne.jsx)(ut,{title:"Cart",children:(0,ne.jsx)(ve,{onClick:()=>e(ls),sx:{color:"text.primary",width:40,height:40,borderRadius:1.5,"&:hover":{backgroundColor:"action.hover"}},children:(0,ne.jsx)(ht,{badgeContent:n,color:"primary",overlap:"circular",sx:{"& .MuiBadge-badge":{fontWeight:700,fontSize:"0.7rem",minWidth:18,height:18,padding:"0 5px"}},children:(0,ne.jsx)(Re.A,{sx:{fontSize:22}})})})}),y&&(0,ne.jsx)(ut,{title:"Profile",children:(0,ne.jsx)(ve,{onClick:e=>u(e.currentTarget),sx:{color:"text.primary",width:40,height:40,borderRadius:1.5,"&:hover":{backgroundColor:"action.hover"}},children:(0,ne.jsx)(Yt.A,{sx:{fontSize:22}})})})]})]})}),(0,ne.jsx)(Ht.Ay,{anchor:"right",open:v,onClose:()=>I(!1),children:$}),(0,ne.jsxs)(At,{anchorEl:x,open:Boolean(x),onClose:k,PaperProps:{elevation:3,sx:{mt:2,minWidth:"200px",borderRadius:"12px",overflow:"hidden"}},children:[r&&E?.can("view","orders")&&(0,ne.jsx)(Se,{onClick:()=>{e(is),k()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:e=>e.palette.custom.menuHover}},children:(0,ne.jsx)(ce,{variant:"body1",children:"Orders"})}),(0,ne.jsx)(Se,{onClick:()=>{e(as),k()},sx:{py:1.5,px:3,"&:hover":{backgroundColor:e=>e.palette.custom.menuHover}},children:(0,ne.jsx)(ce,{variant:"body1",children:"Profile"})}),(0,ne.jsx)(Se,{onClick:()=>{P(),k()},sx:{py:1.5,px:3,color:"error.main","&:hover":{backgroundColor:e=>(0,c.X4)(e.palette.error.main,.1)}},children:(0,ne.jsx)(ce,{variant:"body1",children:"Logout"})})]}),(0,ne.jsx)(Ks,{open:f,onClose:()=>b(!1)}),(0,ne.jsx)(ie,{sx:{height:{xs:"56px",sm:"64px",md:"68px"}}}),(0,ne.jsx)(Cs,{open:m,onClose:()=>h(!1),currentForm:p,setCurrentForm:g})]})};var Zs=s(87992),Js=s(61451);const er=()=>{const e=re((e=>e.selectedStore));return(0,ne.jsx)(Zs.A,{color:"success","aria-label":"WhatsApp",onClick:()=>{const t=`https://wa.me/${e?.whatsappNumber||"+15627872535"}?text=${encodeURIComponent(`Hello! I have a question about ${e?.name||"your services"}.`)}`;window.open(t,"_blank")},sx:{position:"fixed",bottom:20,right:20,zIndex:1e3,backgroundColor:e=>e.palette.custom.whatsapp.main,"&:hover":{backgroundColor:e=>e.palette.custom.whatsapp.dark}},children:(0,ne.jsx)(Js.A,{sx:{fontSize:32}})})},tr=()=>{const e=(0,d.Zp)(),t=(0,qe.A)(),s=(0,Ke.A)("(max-width: 600px)"),r=re((e=>e.cartCount()));return s?(0,ne.jsx)(Zs.A,{"aria-label":"Cart",onClick:()=>e(ls),sx:{position:"fixed",bottom:84,right:20,zIndex:1e3,width:52,height:52,background:t.palette.custom.gradientCoral,color:t.palette.primary.contrastText,boxShadow:t.palette.custom.primaryGlow,"&:hover":{background:t.palette.custom.gradientCoralHover,boxShadow:t.palette.custom.primaryGlowHover}},children:(0,ne.jsx)(mt.A,{badgeContent:r,sx:{"& .MuiBadge-badge":{backgroundColor:"background.paper",color:"primary.main",fontWeight:700,fontSize:"0.7rem",minWidth:18,height:18,top:-4,right:-4}},children:(0,ne.jsx)(Re.A,{sx:{fontSize:26}})})}):null};function sr(e){if(!e)return!0;const t=e.cart&&Object.keys(e.cart).length>0,s=!!e.customOrder,r=e.listInputAnswers&&Object.keys(e.listInputAnswers).length>0;return!t&&!s&&!r}const rr=e=>{let{children:t}=e;return function(){const e=te((e=>e.userProfile)),t=re((e=>e.selectedStore)),s=re((e=>e.restoreCart)),r=re((e=>e.getCartState)),n=(0,A.useRef)(!1),i=(0,A.useRef)(null),a=(0,A.useRef)(null),o=(0,A.useRef)(null),l=(0,A.useRef)(!1),d=e?.id,c=t?.id;(0,A.useEffect)((()=>{if(!d||!c)return void(n.current=!1);const e=i.current!==d,t=a.current!==c;if(i.current=d,a.current=c,!e&&!t&&n.current)return;let o=!1;return async function(){try{const e=await $("\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 t=e?.getSavedCart,n=r(),i=sr(n);if(i&&t?.cartData){s(t.cartData);try{localStorage.setItem(`indimitra-cart-store-${c}`,JSON.stringify(t.cartData))}catch(e){}}else i||await $(U,{userId:d,storeId:c,cartData:n})}catch(e){}finally{o||(n.current=!0)}}(),()=>{o=!0}}),[d,c]),(0,A.useEffect)((()=>{if(!d||!c)return;const e=re.subscribe(((e,t)=>{n.current&&(e.cart!==t.cart||e.customOrder!==t.customOrder||e.listInputAnswers!==t.listInputAnswers||e.deliveryType!==t.deliveryType||e.tipAmount!==t.tipAmount||e.pickupAddress!==t.pickupAddress)&&(o.current&&clearTimeout(o.current),o.current=setTimeout((async()=>{if(!l.current){l.current=!0;try{const e=re.getState().getCartState(),t=i.current,s=a.current;if(!t||!s)return;try{localStorage.setItem(`indimitra-cart-store-${s}`,JSON.stringify(e))}catch(e){}sr(e)?await $(N,{userId:t,storeId:s}):await $(U,{userId:t,storeId:s,cartData:e})}catch(e){}finally{l.current=!1}}}),1e3))}));return()=>{e(),o.current&&clearTimeout(o.current)}}),[d,c])}(),(0,ne.jsxs)(ie,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh"},children:[(0,ne.jsx)(Qs,{}),t,(0,ne.jsx)(tr,{}),(0,ne.jsx)(er,{})]})},nr=e=>{let{children:t,role:s}=e;const{user:r,setUser:n,ability:i,setAbility:a}=te(),[o,l]=(0,A.useState)(!0),[c,x]=(0,A.useState)(!1),[u,m]=(0,A.useState)(null),h=(0,d.zy)();if((0,A.useEffect)((()=>{(async()=>{try{const e=await(0,S.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload["custom:role"]?.toLowerCase();r||n({role:t});const s=Q(t);a(s),m(s),x(!0)}else x(!1)}catch(e){x(!1)}finally{l(!1)}})()}),[r,n,a]),o)return(0,ne.jsx)(pe,{});if(!c)return(0,ne.jsx)(d.C5,{to:"/",replace:!0});if(h.pathname===as)return(0,ne.jsx)(rr,{children:t});const p=(Array.isArray(s)?s:[s]).map((e=>e.toLowerCase()));return u&&p.some((e=>u.can("view",e)))?(0,ne.jsx)(rr,{children:t}):(0,ne.jsx)(d.C5,{to:"/not-authorized",replace:!0})},ir=()=>{const[e,t]=(0,A.useState)(!1),[s,r]=(0,A.useState)(""),[i]=(0,n.ok)(),a=i.get("referredby")||"";return(0,ne.jsx)(f.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:e=>`linear-gradient(135deg, ${(0,c.X4)(e.palette.primary.main,.1)} 0%, ${(0,c.X4)(e.palette.primary.main,.05)} 100%)`,zIndex:0}},children:(0,ne.jsxs)(me.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,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,ne.jsx)(y.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,ne.jsx)(y.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,ne.jsx)(f.A,{sx:{minHeight:300},children:e?(0,ne.jsx)(hs,{email:s,onComplete:()=>t(!1)}):(0,ne.jsx)(bs,{referredBy:a,onOtpStep:e=>{r(e),t(!0)}})})]})})};var ar=s(31117),or=s(1984),lr=s(69377),dr=s(85685),cr=s(69634),xr=s(28130),ur=s(94654),mr=s(17451);const hr=e=>{let{title:t,value:s,icon:r,color:n}=e;const i=(0,qe.A)(),a=(0,Ke.A)(i.breakpoints.down("sm"));return(0,ne.jsx)(we.A,{sx:{height:"100%"},children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ne.jsx)(f.A,{sx:{backgroundColor:`${n}15`,borderRadius:"50%",p:1,mr:2,display:"flex",alignItems:"center",justifyContent:"center"},children:A.cloneElement(r,{sx:{color:n}})}),(0,ne.jsx)(y.A,{variant:"h6",color:"text.secondary",children:t})]}),(0,ne.jsx)(y.A,{variant:a?"h5":"h4",component:"div",sx:{fontWeight:"bold"},children:s})]})})},pr=()=>{const e=(0,qe.A)(),t=(0,Ke.A)(e.breakpoints.down("sm")),{data:s,isLoading:r,error:n}=(0,g.I)({queryKey:["dashboardStats"],queryFn:async()=>await $("\n query GetDashboardStats {\n getDashboardStats {\n totalUsers\n activeUsers\n deliveryAgents\n usersByType\n }\n }\n")}),{data:i,isLoading:a,error:o}=(0,g.I)({queryKey:["orderStats"],queryFn:async()=>await $("\n query GetOrderStats {\n getOrderStats {\n totalOrders\n recentOrders\n ordersByStatus\n ordersByType\n }\n }\n")}),{data:l,isLoading:d,error:c}=(0,g.I)({queryKey:["stores"],queryFn:async()=>await $(W)}),{data:x,isLoading:u,error:m}=(0,g.I)({queryKey:["allStoresSquareStatus"],queryFn:async()=>await $("\n query AllStoresSquareStatus {\n allStoresSquareStatus {\n storeId\n storeName\n isConnected\n }\n }\n")}),h=s?.getDashboardStats||{},p=i?.getOrderStats||{},A=l?.stores||[],j=x?.allStoresSquareStatus||[],v=h.totalUsers||0,I=A.length||0,S=h.deliveryAgents||0,C=p.totalOrders||0,w=j.filter((e=>e.isConnected)).length,P=j.length||I,k=A.filter((e=>e.codEnabled)).length;if(r||a||d||u)return(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:(0,ne.jsx)(b.A,{})});if(n||o||c||m){const e=n?.message||o?.message||c?.message||m?.message||"Error loading dashboard data. Please try again later.";return(0,ne.jsx)(f.A,{sx:{p:t?2:3},children:(0,ne.jsx)(yt,{error:e,title:"Dashboard Error",severity:"error"})})}return(0,ne.jsxs)(f.A,{sx:{p:t?2:3},children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,sx:{mb:4},children:"Dashboard Overview"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Total Users",value:v.toLocaleString(),icon:(0,ne.jsx)(cr.A,{}),color:e.palette.primary.main})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Total Stores",value:I.toLocaleString(),icon:(0,ne.jsx)(or.A,{}),color:e.palette.success.main})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Square Connected",value:`${w} / ${P}`,icon:(0,ne.jsx)(wt.A,{}),color:e.palette.success.main})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Cash on Delivery",value:`${k} / ${I}`,icon:(0,ne.jsx)(wt.A,{}),color:e.palette.info.main})})]}),(0,ne.jsx)(f.A,{sx:{mt:4},children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Active Drivers",value:S.toLocaleString(),icon:(0,ne.jsx)(qt.A,{}),color:e.palette.info.main})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Total Orders",value:C.toLocaleString(),icon:(0,ne.jsx)(Re.A,{}),color:e.palette.warning.main})})]})}),(0,ne.jsxs)(f.A,{sx:{mt:4},children:[(0,ne.jsx)(y.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"Detailed Statistics"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Active Users",value:(h.activeUsers||0).toLocaleString(),icon:(0,ne.jsx)(cr.A,{}),color:e.palette.success.main})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Recent Orders (30 days)",value:(p.recentOrders||0).toLocaleString(),icon:(0,ne.jsx)(Re.A,{}),color:e.palette.info.main})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Delivery Orders",value:(p.ordersByType?.DELIVERY||0).toLocaleString(),icon:(0,ne.jsx)(qt.A,{}),color:e.palette.secondary.main})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(hr,{title:"Pickup Orders",value:(p.ordersByType?.PICKUP||0).toLocaleString(),icon:(0,ne.jsx)(or.A,{}),color:e.palette.warning.main})})]})]}),h.usersByType&&Object.keys(h.usersByType).length>0&&(0,ne.jsxs)(f.A,{sx:{mt:4},children:[(0,ne.jsx)(y.A,{variant:"h5",gutterBottom:!0,sx:{mb:3},children:"User Type Breakdown"}),(0,ne.jsx)(Ce.Ay,{container:!0,spacing:2,children:Object.entries(h.usersByType).map((e=>{let[t,s]=e;return(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:3,children:(0,ne.jsx)(we.A,{sx:{height:"100%"},children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}),(0,ne.jsx)(y.A,{variant:"h4",component:"div",sx:{fontWeight:"bold"},children:s.toLocaleString()})]})})},t)}))})]})]})};var Ar=s(33198),gr=s(64137),yr=s(96627),jr=s(86798),fr=s(14774),br=s(43884),vr=s(95557),Ir=s(72297),Sr=s(68125);const Cr=()=>{const e=(0,qe.A)(),t=(0,Ke.A)(e.breakpoints.down("sm")),[s,r]=(0,A.useState)(0),[n,i]=(0,A.useState)(""),[a,o]=(0,A.useState)(0),[l,d]=(0,A.useState)(10),[c,x]=(0,A.useState)(!1),[u,m]=(0,A.useState)(""),[h,p]=(0,A.useState)(null),[j,I]=(0,A.useState)(!1),[S,C]=(0,A.useState)(""),[w,P]=(0,A.useState)({open:!1,message:"",severity:"success"}),[k,E]=(0,A.useState)(null),[F,D]=(0,A.useState)(!1),[z,T]=(0,A.useState)(""),[R,W]=(0,A.useState)([]),{data:O,isLoading:U,error:N,refetch:B}=(0,g.I)({queryKey:["users"],queryFn:async()=>{const e=await $(L);return e?.getAllUsers||[]},enabled:!0}),{data:M,isLoading:_,error:V,refetch:H}=(0,g.I)({queryKey:["stores"],queryFn:async()=>{try{const e=await $(q);let t=[];return e?.stores&&(Array.isArray(e.stores)?t=e.stores:e.stores.edges&&Array.isArray(e.stores.edges)?t=e.stores.edges.map((e=>e.node)):e.stores.nodes&&Array.isArray(e.stores.nodes)?t=e.stores.nodes:"object"!=typeof e.stores||Array.isArray(e.stores)||(t=[e.stores])),t}catch(e){return[]}},enabled:!0}),G=(0,Ft.n)({mutationFn:e=>$("\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,t)=>{const s=e?.updateUserType;s?.user&&(O&&O.forEach((e=>{e.cognitoId===t.targetUserId&&(e.type=t.newType)})),P({open:!0,message:`Successfully updated user role to ${s.user.type}`,severity:"success"})),I(!1)},onError:e=>{P({open:!0,message:"Error updating user role: "+e.message,severity:"error"})}}),K=(0,Ft.n)({mutationFn:e=>$("\n mutation AssignDriverToStore($storeId: Int!, $userId: Int!) {\n assignDriverToStore(storeId: $storeId, userId: $userId) {\n id\n userId\n store {\n name\n drivers {\n edges {\n node {\n driver {\n email\n }\n }\n }\n }\n }\n }\n }\n",e),onSuccess:e=>{const t=e?.assignDriverToStore;t&&(P({open:!0,message:`Successfully assigned driver to ${t.store.name}`,severity:"success"}),H()),D(!1)},onError:e=>{P({open:!0,message:"Error assigning driver to store: "+e.message,severity:"error"})}});(0,A.useEffect)((()=>{O&&(async()=>{try{if(O&&Array.isArray(O)){const e=O.find((e=>"ADMIN"===e.type));e&&E(e.cognitoId)}}catch(e){}})()}),[O]),(0,A.useEffect)((()=>{M&&Array.isArray(M)?W(M):W([])}),[M]);const Y=e=>{p(e),C(e.type),I(!0)},X=e=>{p(e),T(""),D(!0)},Q=()=>{P({...w,open:!1})},Z=()=>{if(!O||!Array.isArray(O))return[];let e=O;return 1===s?e=O.filter((e=>"USER"===e.type)):2===s?e=O.filter((e=>"DELIVERY"===e.type)):3===s&&(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},J=()=>z&&Array.isArray(R)?R.find((e=>e.id===parseInt(z))):null;return(0,ne.jsxs)(f.A,{sx:{p:t?2:3},children:[(0,ne.jsxs)(me.A,{sx:{p:3,mb:3},children:[(0,ne.jsx)(y.A,{variant:"h5",gutterBottom:!0,children:"User Management"}),(0,ne.jsxs)(ws.A,{value:s,onChange:(e,t)=>{r(t),o(0)},sx:{mb:3},variant:t?"fullWidth":"standard",children:[(0,ne.jsx)(Ps.A,{label:"All"}),(0,ne.jsx)(Ps.A,{label:"Users"}),(0,ne.jsx)(Ps.A,{label:"Delivery Partners"}),(0,ne.jsx)(Ps.A,{label:"Store Managers"})]}),(0,ne.jsx)(f.A,{sx:{mb:3,display:"flex",gap:2,flexWrap:"wrap"},children:(0,ne.jsx)(le.A,{size:"small",placeholder:"Search...",value:n,onChange:e=>{i(e.target.value),o(0)},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Sr.A,{})})},sx:{flexGrow:1,minWidth:200}})}),N&&(0,ne.jsxs)(xe.A,{severity:"error",sx:{mb:3},children:["Error loading users: ",N.message]}),U?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):(0,ne.jsxs)(ne.Fragment,{children:[0===s&&(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"ID"}),(0,ne.jsx)(fr.A,{children:"Email"}),(0,ne.jsx)(fr.A,{children:"Mobile"}),(0,ne.jsx)(fr.A,{children:"Type"}),(0,ne.jsx)(fr.A,{children:"Status"}),(0,ne.jsx)(fr.A,{children:"Referral ID"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:Z().slice(a*l,a*l+l).map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.id}),(0,ne.jsx)(fr.A,{children:e.email}),(0,ne.jsx)(fr.A,{children:e.mobile||"N/A"}),(0,ne.jsx)(fr.A,{children:e.type}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,ne.jsx)(fr.A,{children:e.referralId||"N/A"}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{size:"small",color:"primary",onClick:()=>Y(e),children:(0,ne.jsx)(Ir.A,{})}),"DELIVERY"===e.type&&(0,ne.jsx)(be.A,{size:"small",color:"secondary",onClick:()=>X(e),title:"Assign to Store",children:(0,ne.jsx)(qt.A,{})})]})]},e.id)))})]})}),1===s&&(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"ID"}),(0,ne.jsx)(fr.A,{children:"Email"}),(0,ne.jsx)(fr.A,{children:"Mobile"}),(0,ne.jsx)(fr.A,{children:"Status"}),(0,ne.jsx)(fr.A,{children:"Referral ID"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:Z().slice(a*l,a*l+l).map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.id}),(0,ne.jsx)(fr.A,{children:e.email}),(0,ne.jsx)(fr.A,{children:e.mobile||"N/A"}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,ne.jsx)(fr.A,{children:e.referralId||"N/A"}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(be.A,{size:"small",color:"primary",onClick:()=>Y(e),children:(0,ne.jsx)(Ir.A,{})})})]},e.id)))})]})}),2===s&&(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"ID"}),(0,ne.jsx)(fr.A,{children:"Email"}),(0,ne.jsx)(fr.A,{children:"Mobile"}),(0,ne.jsx)(fr.A,{children:"Status"}),(0,ne.jsx)(fr.A,{children:"Referral ID"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:Z().slice(a*l,a*l+l).map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.id}),(0,ne.jsx)(fr.A,{children:e.email}),(0,ne.jsx)(fr.A,{children:e.mobile||"N/A"}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,ne.jsx)(fr.A,{children:e.referralId||"N/A"}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{size:"small",color:"primary",onClick:()=>Y(e),children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{size:"small",color:"secondary",onClick:()=>X(e),title:"Assign to Store",children:(0,ne.jsx)(qt.A,{})})]})]},e.id)))})]})}),3===s&&(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"ID"}),(0,ne.jsx)(fr.A,{children:"Email"}),(0,ne.jsx)(fr.A,{children:"Mobile"}),(0,ne.jsx)(fr.A,{children:"Status"}),(0,ne.jsx)(fr.A,{children:"Referral ID"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:Z().slice(a*l,a*l+l).map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.id}),(0,ne.jsx)(fr.A,{children:e.email}),(0,ne.jsx)(fr.A,{children:e.mobile||"N/A"}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:e.active?"Active":"Inactive",color:e.active?"success":"default",size:"small"})}),(0,ne.jsx)(fr.A,{children:e.referralId||"N/A"}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(be.A,{size:"small",color:"primary",onClick:()=>Y(e),children:(0,ne.jsx)(Ir.A,{})})})]},e.id)))})]})}),(0,ne.jsx)(v.A,{component:"div",count:Z().length,page:a,onPageChange:(e,t)=>{o(t)},rowsPerPage:l,onRowsPerPageChange:e=>{d(parseInt(e.target.value,10)),o(0)},sx:{mt:2}})]})]}),(0,ne.jsxs)(it.A,{open:j,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,ne.jsx)(at.A,{sx:{pb:1},children:"Update User Role"}),(0,ne.jsx)(ot.A,{children:h&&(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsxs)(y.A,{variant:"subtitle1",gutterBottom:!0,children:["User: ",h.email]}),(0,ne.jsxs)(y.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",h.id]}),(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mt:2},children:[(0,ne.jsx)($e.A,{children:"Role"}),(0,ne.jsxs)(Le.A,{value:S,onChange:e=>{C(e.target.value)},label:"Role",sx:{mb:2},children:[(0,ne.jsx)(Ie.A,{value:"USER",children:"User"}),(0,ne.jsx)(Ie.A,{value:"ADMIN",children:"Admin"}),(0,ne.jsx)(Ie.A,{value:"DELIVERY",children:"Delivery Partner"}),(0,ne.jsx)(Ie.A,{value:"STORE_MANAGER",children:"Store Manager"})]})]})]})}),(0,ne.jsxs)(lt.A,{sx:{px:3,py:2},children:[(0,ne.jsx)(ae.A,{onClick:()=>I(!1),children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{if(!k)return void P({open:!0,message:"Admin ID not available. Please try again.",severity:"error"});G.mutate({targetUserId:h.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,ne.jsxs)(it.A,{open:F,onClose:()=>D(!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,ne.jsx)(at.A,{sx:{pb:1},children:"Assign Driver to Store"}),(0,ne.jsx)(ot.A,{children:h&&(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsxs)(y.A,{variant:"subtitle1",gutterBottom:!0,children:["Driver: ",h.email]}),(0,ne.jsxs)(y.A,{variant:"body2",color:"text.secondary",gutterBottom:!0,sx:{mb:3},children:["ID: ",h.id]}),(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsx)(y.A,{variant:"subtitle2",gutterBottom:!0,sx:{mt:2},children:"Select Store"}),_?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:2},children:(0,ne.jsx)(b.A,{size:24})}):V?(0,ne.jsxs)(xe.A,{severity:"error",sx:{mb:2},children:["Error loading stores: ",V.message]}):Array.isArray(R)&&0!==R.length?(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mt:1},children:[(0,ne.jsx)($e.A,{children:"Store"}),(0,ne.jsx)(Le.A,{value:z,onChange:e=>{T(e.target.value)},label:"Store",sx:{mb:2},children:R.map((e=>(0,ne.jsxs)(Ie.A,{value:e.id,children:[e.name," - ",e.address]},e.id)))})]}):(0,ne.jsx)(xe.A,{severity:"info",sx:{mb:2},children:"No stores available"}),z&&J()&&(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",gutterBottom:!0,children:"Current Drivers"}),J()?.drivers?.edges?.length>0?(0,ne.jsx)(f.A,{sx:{mt:1},children:J().drivers.edges.map(((e,t)=>(0,ne.jsx)(Oe.A,{label:e.node.driver.email,size:"small",sx:{mr:1,mb:1}},t)))}):(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"No drivers assigned to this store yet"})]})]})}),(0,ne.jsxs)(lt.A,{sx:{px:3,py:2},children:[(0,ne.jsx)(ae.A,{onClick:()=>D(!1),children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{z&&h?K.mutate({storeId:parseInt(z),userId:parseInt(h.id)}):P({open:!0,message:"Please select a store",severity:"error"})},variant:"contained",color:"primary",disabled:!z||K.isPending,children:K.isPending?"Assigning...":"Assign to Store"})]})]}),(0,ne.jsx)(vr.A,{open:w.open,autoHideDuration:6e3,onClose:Q,message:w.message,children:(0,ne.jsx)(xe.A,{onClose:Q,severity:w.severity,children:w.message})})]})};var wr=s(39738),Pr=s(82997),kr=s(47363),Er=s(67110),$r=s(40250),Lr=s(70765),Fr=s(34337),Dr=s(72306),zr=s(79432),Tr=s(35520);const Rr=["Store Information","Inventory","Drivers","Store Managers","Review"],Wr=()=>{const[e,t]=(0,A.useState)(0),[s,r]=(0,A.useState)(""),[n,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(null),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)({}),u=(0,qe.A)(),[m,h]=((0,Ke.A)(u.breakpoints.down("sm")),(0,A.useState)(0)),[p,j]=(0,A.useState)({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",displayField:"",sectionHeaders:[],inventory:[],drivers:[],storeManagers:[],pincodes:"",images:[],codEnabled:!1,whatsappNumber:""}),[v,I]=(0,A.useState)(null),[C,w]=(0,A.useState)([]),[P,k]=(0,A.useState)(!1),[E,F]=(0,A.useState)({open:!1,message:"",severity:"success"}),{data:D,isLoading:z,refetch:T}=(0,g.I)({queryKey:["stores"],queryFn:()=>$(q),enabled:n}),{data:R,isLoading:W}=(0,g.I)({queryKey:["users"],queryFn:async()=>{const e=await $(L);return e?.getAllUsers||[]},enabled:!0}),O=(0,A.useMemo)((()=>R&&Array.isArray(R)?R.filter((e=>{if(!e.type)return!1;const t=e.type.trim().toUpperCase();return"STORE_MANAGER"===t||"STOREMANAGER"===t||t.includes("STORE")&&t.includes("MANAGER")})):[]),[R]),U=(0,A.useMemo)((()=>D?.stores&&Array.isArray(D.stores)?D.stores.map((e=>e.managerUserId)).filter((e=>null!=e)):[]),[D]),N=(0,A.useMemo)((()=>{if(!O.length)return[];return O.filter((e=>!U.includes(e.id)))}),[O,U]),B=(0,A.useMemo)((()=>{if(!O.length||!v)return N;const e=U.filter((e=>e!==v.managerUserId));return O.filter((t=>!e.includes(t.id)))}),[O,U,v,N]);(0,A.useEffect)((()=>{if(1===e&&!v){const e=N.find((e=>String(e.id)===String(p.managerUserId)));e?j((t=>({...t,email:e.email||"",mobile:e.mobile||""}))):p.managerUserId&&!e&&j((e=>({...e,managerUserId:"",email:"",mobile:""})))}}),[p.managerUserId,N,e,v]);const M=(0,Ft.n)({mutationFn:e=>$("\n mutation CreateStore(\n $name: String!\n $address: String!\n $managerUserId: Int!\n $radius: Float!\n $email: String!\n $mobile: String!\n $description: String\n $storeDeliveryFee: Float\n $taxPercentage: Float\n $tnc: String\n $displayField: String!\n $sectionHeaders: [String!]\n $pincodes: [String!]\n $images: [String!]\n $codEnabled: Boolean\n $whatsappNumber: String\n ) {\n createStore(\n name: $name\n address: $address\n managerUserId: $managerUserId\n radius: $radius\n email: $email\n mobile: $mobile\n description: $description\n storeDeliveryFee: $storeDeliveryFee\n taxPercentage: $taxPercentage\n tnc: $tnc\n displayField: $displayField\n sectionHeaders: $sectionHeaders\n pincodes: $pincodes\n images: $images\n codEnabled: $codEnabled\n whatsappNumber: $whatsappNumber\n ) {\n id\n name\n address\n email\n mobile\n managerUserId\n radius\n description\n storeDeliveryFee\n taxPercentage\n tnc\n displayField\n sectionHeaders\n pincodes\n images\n codEnabled\n whatsappNumber\n }\n }\n",{name:e.name,address:e.address,managerUserId:parseInt(e.managerUserId,10),radius:parseFloat(e.radius),email:e.email,mobile:e.mobile,description:e.description||null,storeDeliveryFee:e.storeDeliveryFee?parseFloat(e.storeDeliveryFee):null,taxPercentage:e.taxPercentage?parseFloat(e.taxPercentage):null,tnc:e.tnc||null,displayField:e.displayField||null,sectionHeaders:e.sectionHeaders||null,pincodes:e.pincodes||null,images:e.images||[],codEnabled:e.codEnabled??!1,whatsappNumber:e.whatsappNumber||null}),onSuccess:()=>{d(!0),o(null),j({name:"",address:"",managerUserId:"",radius:"",email:"",mobile:"",description:"",storeDeliveryFee:"",taxPercentage:"",tnc:"",displayField:"",sectionHeaders:[],inventory:[],drivers:[],storeManagers:[],pincodes:"",images:[],codEnabled:!1,whatsappNumber:""}),h(0),T()},onError:e=>{o(e.message||"Failed to create store"),d(!1)}}),_=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateStore(\n $storeId: Int!\n $name: String\n $address: String\n $email: String\n $mobile: String\n $managerUserId: Int\n $radius: Float\n $isActive: Boolean\n $disabled: Boolean\n $description: String\n $pincodes: [String!]\n $tnc: String\n $storeDeliveryFee: Float\n $taxPercentage: Float\n $displayField: String\n $sectionHeaders: [String!]\n $images: [String!]\n $whatsappNumber: String\n ) {\n updateStore(\n storeId: $storeId\n name: $name\n address: $address\n email: $email\n mobile: $mobile\n managerUserId: $managerUserId\n radius: $radius\n isActive: $isActive\n disabled: $disabled\n description: $description\n pincodes: $pincodes\n tnc: $tnc\n storeDeliveryFee: $storeDeliveryFee\n taxPercentage: $taxPercentage\n displayField: $displayField\n sectionHeaders: $sectionHeaders\n images: $images\n whatsappNumber: $whatsappNumber\n ) {\n id\n name\n address\n email\n mobile\n managerUserId\n radius\n isActive\n disabled\n description\n pincodes\n tnc\n storeDeliveryFee\n taxPercentage\n displayField\n sectionHeaders\n images\n whatsappNumber\n }\n }\n",e),onSuccess:(e,t)=>{D&&D.stores&&D.stores.forEach((e=>{e.id===t.storeId&&Object.assign(e,t)})),F({open:!0,message:"Store updated successfully",severity:"success"}),I(null)},onError:e=>{F({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),V=()=>{i(!0),T()},H=e=>{const{name:t,value:s}=e.target;j((e=>({...e,[t]:s}))),c[t]&&x((e=>({...e,[t]:null}))),a&&o(null)},G=()=>{j((e=>({...e,sectionHeaders:[...e.sectionHeaders,""]})))},K=async function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return;const s=t?v?.id:null;if(!t||s){k(!0);try{const r=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",n=await(0,S.$)(),i=n.tokens?.accessToken?.toString(),a={"Content-Type":"application/json"};i&&(a.Authorization=`Bearer ${i}`);const o=s?s.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 t=await l.json();e=t.detail||t.message||e}catch(t){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];t?w((e=>[...e,u])):j((e=>({...e,images:[...e.images,u]}))),F({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){F({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{k(!1)}}else F({open:!0,message:"Store ID is required for image upload",severity:"error"})},Y=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?w((t=>t.filter(((t,s)=>s!==e)))):j((t=>({...t,images:t.images.filter(((t,s)=>s!==e))})))},X=()=>{const e={};return p.name.trim()||(e.name="Store name is required"),p.address.trim()||(e.address="Address is required"),p.email.trim()||(e.email="Manager email is required"),p.mobile.trim()||(e.mobile="Manager mobile is required"),p.managerUserId||(e.managerUserId="Manager User ID is required"),p.radius&&!isNaN(parseFloat(p.radius))||(e.radius="Delivery radius is required"),p.displayField.trim()||(e.displayField="Display Field is required"),x(e),0===Object.keys(e).length},Q=()=>{I(null),w([])},Z=D?.stores?.filter((e=>e.name.toLowerCase().includes(s.toLowerCase())||e.address.toLowerCase().includes(s.toLowerCase())))||[];return(0,A.useEffect)((()=>{let e;return l&&(e=setTimeout((()=>{d(!1)}),5e3)),()=>{e&&clearTimeout(e)}}),[l]),(0,ne.jsxs)(f.A,{children:[(0,ne.jsxs)(me.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,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ne.jsx)(or.A,{sx:{mr:1}}),(0,ne.jsx)(y.A,{variant:"h5",children:"Store Management"})]}),(0,ne.jsxs)(ws.A,{value:e,onChange:(e,s)=>{t(s)},sx:{mb:3},children:[(0,ne.jsx)(Ps.A,{label:"Store List"}),(0,ne.jsx)(Ps.A,{label:"Add New Store"})]}),a&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:3},children:a}),l&&(0,ne.jsx)(xe.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,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(f.A,{sx:{mb:3},children:(0,ne.jsx)(le.A,{fullWidth:!0,variant:"outlined",placeholder:"Search stores...",value:s,onChange:e=>r(e.target.value),InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Sr.A,{})})}})}),n?z?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,ne.jsx)(b.A,{})}):0===Z.length?(0,ne.jsx)(xe.A,{severity:"info",sx:{mb:3},children:"No stores found matching your criteria"}):(0,ne.jsx)(Ce.Ay,{container:!0,spacing:3,children:Z.map((e=>(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(me.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,ne.jsx)(f.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,ne.jsxs)(Ce.Ay,{container:!0,alignItems:"center",spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ne.jsx)(or.A,{sx:{mr:2,color:"white",fontSize:"2rem"}}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{className:"store-name",variant:"h6",sx:{color:"white",fontWeight:600,transition:"color 0.3s ease-in-out"},children:e.name}),(0,ne.jsxs)(y.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,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",md:"flex-end"},gap:2},children:[(0,ne.jsx)(Oe.A,{label:e.isActive?"Active":"Inactive",color:e.isActive?"success":"error",sx:{fontWeight:600,boxShadow:2,"& .MuiChip-label":{px:1}}}),(0,ne.jsx)(f.A,{className:"action-buttons",sx:{display:"flex",gap:1,opacity:.9},children:(0,ne.jsx)(ae.A,{size:"small",startIcon:(0,ne.jsx)(Ir.A,{}),sx:{fontWeight:600,textTransform:"none",color:"white","&:hover":{backgroundColor:"rgba(255, 255, 255, 0.1)"}},onClick:()=>(e=>{I(e),w(e.images||[])})(e),children:"Edit"})})]})})]})}),(0,ne.jsx)(f.A,{sx:{p:3},children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.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,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,ne.jsx)(jt.A,{sx:{mr:1.5,color:"primary.main",mt:.3,flexShrink:0,fontSize:"1.2rem"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.address})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ne.jsx)(Lr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.mobile||"No contact info"})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ne.jsx)(Fr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.email||"No email info"})]})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.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,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ne.jsx)(qt.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Radius: ",e.radius," mi"]})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ne.jsx)(Dr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:"text.primary",fontWeight:500},children:["Delivery Fee: $",e.storeDeliveryFee?.toFixed(2)||"0.00"]})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ne.jsx)(zr.A,{sx:{mr:1.5,color:"primary.main",flexShrink:0,fontSize:"1.2rem"}}),(0,ne.jsxs)(y.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,ne.jsx)(f.A,{sx:{display:"flex",flexWrap:"wrap",gap:.8},children:e.pincodes.map((e=>(0,ne.jsx)(Oe.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,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(f.A,{children:[e.description&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.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,ne.jsx)(y.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.description})]}),e.tnc&&(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.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,ne.jsx)(y.A,{variant:"body2",sx:{wordBreak:"break-word",color:"text.primary",fontWeight:500},children:e.tnc})]})]})}),e.images&&e.images.length>0&&(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(Ct.A,{sx:{mb:2}}),(0,ne.jsxs)(y.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,ne.jsx)(Tr.A,{sx:{fontSize:"1rem",mr:.5}}),"Store Images (",e.images.length,")"]}),(0,ne.jsx)(f.A,{sx:{display:"flex",gap:1.5,overflowX:"auto",pb:1,scrollbarWidth:"thin"},children:e.images.map(((e,t)=>(0,ne.jsx)(f.A,{sx:{flex:"0 0 auto",width:120,height:80,borderRadius:2,overflow:"hidden",border:"1px solid",borderColor:"divider"},children:(0,ne.jsx)("img",{src:e,alt:`Store image ${t+1}`,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},t)))})]})]})})]})},e.id)))}):(0,ne.jsxs)(we.A,{sx:{mb:3},children:[(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Stores" to load store data'}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]}),(0,ne.jsx)(Fe.A,{sx:{justifyContent:"center"},children:(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:(0,ne.jsx)($r.A,{}),onClick:V,children:"Fetch Stores"})})]})]}):1!==e||D?.stores||n?(0,ne.jsxs)(f.A,{sx:{maxWidth:{xs:"100%",sm:600,md:800},mx:"auto",p:{xs:1,sm:2}},children:[(0,ne.jsx)(f.A,{sx:{overflowX:{xs:"auto",sm:"visible"},mb:{xs:2,sm:4}},children:(0,ne.jsx)(wr.A,{activeStep:m,sx:{minWidth:500},children:Rr.map((e=>(0,ne.jsx)(Pr.A,{children:(0,ne.jsx)(kr.A,{children:(0,ne.jsx)(y.A,{sx:{fontSize:{xs:"0.95rem",sm:"1rem"}},children:e})})},e)))})}),(0,ne.jsx)(f.A,{sx:{px:{xs:.5,sm:0}},children:(e=>{switch(e){case 0:return(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:"Basic Store Information"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{required:!0,fullWidth:!0,label:"Store Name",name:"name",value:p.name,onChange:H,error:!!c.name,helperText:c.name})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{required:!0,fullWidth:!0,label:"Address",name:"address",value:p.address,onChange:H,error:!!c.address,helperText:c.address})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(Ee.A,{required:!0,fullWidth:!0,error:!!c.managerUserId,children:[(0,ne.jsx)($e.A,{children:"Manager User ID"}),(0,ne.jsx)(Le.A,{label:"Manager User ID",name:"managerUserId",value:p.managerUserId,onChange:H,children:W?(0,ne.jsx)(Ie.A,{value:"",disabled:!0,children:(0,ne.jsx)("em",{children:"Loading..."})}):0===N.length?(0,ne.jsx)(Ie.A,{value:"",disabled:!0,children:(0,ne.jsx)("em",{children:"No available managers (all managers are assigned)"})}):N.map((e=>(0,ne.jsxs)(Ie.A,{value:e.id,children:[e.id," - ",e.email," ",e.name?`(${e.name})`:""]},e.id)))}),(0,ne.jsx)(y.A,{variant:"caption",color:"error",children:c.managerUserId}),0===N.length&&!W&&(0,ne.jsx)(y.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,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{required:!0,fullWidth:!0,label:"Manager Email",name:"email",type:"email",value:p.email,InputProps:{readOnly:!0},error:!!c.email,helperText:c.email})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{required:!0,fullWidth:!0,label:"Manager Mobile",name:"mobile",value:p.mobile,InputProps:{readOnly:!0},error:!!c.mobile,helperText:c.mobile})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{required:!0,fullWidth:!0,label:"Delivery Radius (mi)",name:"radius",type:"number",value:p.radius,onChange:H,inputProps:{step:"0.1"},error:!!c.radius,helperText:c.radius})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Delivery Fee ($)",name:"storeDeliveryFee",type:"number",value:p.storeDeliveryFee,onChange:H,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:"$"})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Tax Rate (%)",name:"taxPercentage",type:"number",value:p.taxPercentage,onChange:H,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,ne.jsx)(ye.A,{position:"end",children:"%"})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Description",name:"description",value:p.description,onChange:H,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Terms & Conditions",name:"tnc",value:p.tnc,onChange:H,multiline:!0,rows:3})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Delivery Pincodes",name:"pincodes",value:p.pincodes,onChange:H,helperText:"Enter pincodes separated by commas"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{required:!0,fullWidth:!0,label:"Display Field",name:"displayField",value:p.displayField,onChange:H,error:!!c.displayField,helperText:c.displayField||"Unique identifier for the store"})}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,ne.jsxs)(f.A,{sx:{mb:2},children:[p.sectionHeaders.map(((e,t)=>(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,ne.jsx)(le.A,{fullWidth:!0,label:`Question ${t+1}`,value:e,onChange:e=>((e,t)=>{const s=[...p.sectionHeaders];s[e]=t,j((e=>({...e,sectionHeaders:s})))})(t,e.target.value),placeholder:"Enter question text"}),(0,ne.jsx)(be.A,{color:"error",onClick:()=>(e=>{const t=p.sectionHeaders.filter(((t,s)=>s!==e));j((e=>({...e,sectionHeaders:t})))})(t),sx:{alignSelf:"center"},children:(0,ne.jsx)(Er.A,{})})]},t))),(0,ne.jsx)(ae.A,{startIcon:(0,ne.jsx)(Te.A,{}),onClick:G,variant:"outlined",sx:{mt:1},children:"Add Question"})]})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Images"}),(0,ne.jsxs)(f.A,{sx:{mb:2},children:[(0,ne.jsx)("input",{accept:"image/*",style:{display:"none"},id:"store-image-upload",type:"file",onChange:e=>{const t=e.target.files[0];t&&K(t,!1),e.target.value=""}}),(0,ne.jsx)("label",{htmlFor:"store-image-upload",children:(0,ne.jsx)(ae.A,{variant:"outlined",component:"span",startIcon:(0,ne.jsx)(Te.A,{}),disabled:P,sx:{mb:2},children:P?"Uploading...":"Upload Image"})}),p.images&&p.images.length>0&&(0,ne.jsx)(f.A,{sx:{display:"flex",flexWrap:"wrap",gap:2,mt:2},children:p.images.map(((e,t)=>(0,ne.jsxs)(f.A,{sx:{position:"relative",width:150,height:150},children:[(0,ne.jsx)("img",{src:e,alt:`Store image ${t+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,ne.jsx)(be.A,{size:"small",color:"error",onClick:()=>Y(t,!1),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,ne.jsx)(Er.A,{fontSize:"small"})})]},t)))})]})]}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:2,border:"1px solid",borderColor:"divider",borderRadius:1,bgcolor:"background.paper"},children:[(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Cash on Delivery"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Accept cash payments when orders are delivered"})]}),(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(Qe.A,{checked:p.codEnabled,onChange:e=>j((t=>({...t,codEnabled:e.target.checked}))),color:"primary"}),label:p.codEnabled?"Enabled":"Disabled",labelPlacement:"start"})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{label:"WhatsApp Support Number",placeholder:"+1234567890",value:p.whatsappNumber,onChange:e=>j((t=>({...t,whatsappNumber:e.target.value}))),fullWidth:!0,helperText:"Include country code (e.g., +1 for US). Optional."})})]});case 1:return(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:"Inventory Management"}),(0,ne.jsx)(y.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,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsxs)(me.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Inventory Items"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ne.jsx)(we.A,{variant:"outlined",children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",children:"Product 1"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Category: Grocery"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Price: $9.99"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Stock: 50"})]})})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ne.jsx)(we.A,{variant:"outlined",children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",children:"Product 2"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Category: Electronics"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Price: $49.99"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Stock: 25"})]})})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ne.jsx)(we.A,{variant:"outlined",children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",children:"Product 3"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Category: Clothing"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Price: $19.99"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Stock: 100"})]})})})]})]}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,ne.jsx)(ae.A,{variant:"outlined",startIcon:(0,ne.jsx)(Te.A,{}),children:"Add Inventory Item"})})]})]});case 2:return(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:"Driver Management"}),(0,ne.jsx)(y.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,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsxs)(me.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Drivers"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ne.jsx)(we.A,{variant:"outlined",children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",children:"John Doe"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Email: john.doe@example.com"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 123-4567"}),(0,ne.jsx)(Oe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ne.jsx)(we.A,{variant:"outlined",children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",children:"Jane Smith"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Email: jane.smith@example.com"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 987-6543"}),(0,ne.jsx)(Oe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ne.jsx)(we.A,{variant:"outlined",children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",children:"Mike Johnson"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Email: mike.johnson@example.com"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 456-7890"}),(0,ne.jsx)(Oe.A,{label:"Inactive",color:"error",size:"small",sx:{mt:1}})]})})})]})]}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,ne.jsx)(ae.A,{variant:"outlined",startIcon:(0,ne.jsx)(Te.A,{}),children:"Add Driver"})})]})]});case 3:return(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:"Store Manager Management"}),(0,ne.jsx)(y.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,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsxs)(me.A,{variant:"outlined",sx:{p:2,mb:2},children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Sample Store Managers"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,children:(0,ne.jsx)(we.A,{variant:"outlined",children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",children:"Sarah Williams"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Email: sarah.williams@example.com"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 234-5678"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Role: Store Manager"}),(0,ne.jsx)(Oe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,children:(0,ne.jsx)(we.A,{variant:"outlined",children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",children:"Robert Brown"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Email: robert.brown@example.com"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Phone: (555) 876-5432"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"Role: Assistant Manager"}),(0,ne.jsx)(Oe.A,{label:"Active",color:"success",size:"small",sx:{mt:1}})]})})})]})]}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",mt:2},children:(0,ne.jsx)(ae.A,{variant:"outlined",startIcon:(0,ne.jsx)(Te.A,{}),children:"Add Store Manager"})})]})]});case 4:return(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:"Review Store Information"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(me.A,{variant:"outlined",sx:{p:2},children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Details"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"Name:"})," ",p.name]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"Address:"})," ",p.address]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"Manager User ID:"})," ",p.managerUserId]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"Delivery Radius:"})," ",p.radius," km"]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"Cash on Delivery:"})," ",p.codEnabled?"Enabled":"Disabled"]})}),p.whatsappNumber&&(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"WhatsApp:"})," ",p.whatsappNumber]})})]}),(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Additional Information (Placeholder)"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"Inventory Items:"})," 3 sample items"]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"Drivers:"})," 3 sample drivers"]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"body2",children:[(0,ne.jsx)("strong",{children:"Store Managers:"})," 2 sample managers"]})})]})]})})]});default:return null}})(m)}),(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",mt:3,gap:2},children:[(0,ne.jsx)(ae.A,{fullWidth:!0,disabled:0===m,onClick:()=>{h((e=>e-1))},sx:{py:1,fontSize:{xs:"1rem",sm:"1.05rem"}},children:"Back"}),(0,ne.jsx)(ae.A,{fullWidth:!0,variant:"contained",color:"primary",onClick:m===Rr.length-1?()=>{if(!X())return void o("Please fill in all required fields");const e=p.pincodes,t=e?e.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],s={name:p.name,address:p.address,managerUserId:parseInt(p.managerUserId,10),radius:parseFloat(p.radius),email:p.email,mobile:p.mobile,description:p.description||null,storeDeliveryFee:p.storeDeliveryFee?parseFloat(p.storeDeliveryFee):null,taxPercentage:p.taxPercentage?parseFloat(p.taxPercentage):null,tnc:p.tnc||null,displayField:p.displayField,sectionHeaders:p.sectionHeaders.filter((e=>e.trim().length>0)),pincodes:t,images:p.images||[],is_active:!0,disabled:!1,codEnabled:p.codEnabled,whatsappNumber:p.whatsappNumber||null};M.mutate(s)}:()=>{0!==m||X()?h((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,ne.jsx)(b.A,{size:24}):m===Rr.length-1?"Submit":"Next"})]})]}):(0,ne.jsxs)(we.A,{sx:{mb:3},children:[(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",align:"center",gutterBottom:!0,children:"Loading store data for manager availability check..."}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",align:"center",children:"We need to check which managers are already assigned before showing available options."})]}),(0,ne.jsx)(Fe.A,{sx:{justifyContent:"center"},children:(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:(0,ne.jsx)($r.A,{}),onClick:V,children:"Load Store Data"})})]})]}),(0,ne.jsxs)(it.A,{open:!!v,onClose:Q,maxWidth:"md",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(or.A,{}),(0,ne.jsx)(y.A,{variant:"h6",children:"Edit Store"})]})}),(0,ne.jsxs)("form",{onSubmit:e=>{e.preventDefault();const t=new FormData(e.target),s=t.get("pincodes"),r=s?s.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],n=t.get("sectionHeaders"),i=n?n.split("\n").map((e=>e.trim())).filter((e=>e.length>0)):[],a={storeId:v.id,name:t.get("name"),address:t.get("address"),email:t.get("email"),mobile:t.get("mobile")||null,managerUserId:parseInt(t.get("managerUserId")),radius:parseFloat(t.get("radius")),isActive:"true"===t.get("isActive"),disabled:"true"===t.get("disabled"),description:t.get("description")||null,pincodes:r,tnc:t.get("tnc")||null,storeDeliveryFee:parseFloat(t.get("storeDeliveryFee"))||null,taxPercentage:parseFloat(t.get("taxPercentage"))||null,displayField:t.get("displayField"),sectionHeaders:i,images:C,whatsappNumber:t.get("whatsappNumber")||null};_.mutate(a)},children:[(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"name",label:"Store Name",defaultValue:v?.name,required:!0,fullWidth:!0})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"email",label:"Email",type:"email",defaultValue:v?.email,required:!0,fullWidth:!0})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"mobile",label:"Mobile Number",defaultValue:v?.mobile,fullWidth:!0})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(Ee.A,{required:!0,fullWidth:!0,children:[(0,ne.jsx)($e.A,{children:"Manager User ID"}),(0,ne.jsx)(Le.A,{name:"managerUserId",label:"Manager User ID",defaultValue:v?.managerUserId,children:W?(0,ne.jsx)(Ie.A,{value:"",disabled:!0,children:(0,ne.jsx)("em",{children:"Loading..."})}):0===B.length?(0,ne.jsx)(Ie.A,{value:"",disabled:!0,children:(0,ne.jsx)("em",{children:"No available managers"})}):B.map((e=>(0,ne.jsxs)(Ie.A,{value:e.id,children:[e.id," - ",e.email," ",e.name?`(${e.name})`:""]},e.id)))})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"displayField",label:"Display Field",defaultValue:v?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"sectionHeaders",label:"Section Headers",defaultValue:v?.sectionHeaders?.join("\n"),fullWidth:!0,multiline:!0,rows:3,helperText:"Enter each section header on a new line"})}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Store Images"}),(0,ne.jsxs)(f.A,{sx:{mb:2},children:[(0,ne.jsx)("input",{accept:"image/*",style:{display:"none"},id:"edit-store-image-upload",type:"file",onChange:e=>{const t=e.target.files[0];t&&K(t,!0),e.target.value=""}}),(0,ne.jsx)("label",{htmlFor:"edit-store-image-upload",children:(0,ne.jsx)(ae.A,{variant:"outlined",component:"span",startIcon:(0,ne.jsx)(Te.A,{}),disabled:P,sx:{mb:2},children:P?"Uploading...":"Upload Image"})}),C&&C.length>0&&(0,ne.jsx)(f.A,{sx:{display:"flex",flexWrap:"wrap",gap:2,mt:2},children:C.map(((e,t)=>(0,ne.jsxs)(f.A,{sx:{position:"relative",width:150,height:150},children:[(0,ne.jsx)("img",{src:e,alt:`Store image ${t+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,ne.jsx)(be.A,{size:"small",color:"error",onClick:()=>Y(t,!0),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,ne.jsx)(Er.A,{fontSize:"small"})})]},t)))})]})]}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"address",label:"Address",defaultValue:v?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:v?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:v?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:"$"})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:v?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,ne.jsx)(ye.A,{position:"end",children:"%"})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:v?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"description",label:"Description",defaultValue:v?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"tnc",label:"Terms & Conditions",defaultValue:v?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"whatsappNumber",label:"WhatsApp Support Number",placeholder:"+1234567890",defaultValue:v?.whatsappNumber,fullWidth:!0,helperText:"Include country code. Optional."})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,children:[(0,ne.jsx)($e.A,{children:"Store Status"}),(0,ne.jsxs)(Le.A,{name:"isActive",label:"Store Status",defaultValue:v?.isActive,children:[(0,ne.jsx)(Ie.A,{value:!0,children:"Active"}),(0,ne.jsx)(Ie.A,{value:!1,children:"Inactive"})]})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,children:[(0,ne.jsx)($e.A,{children:"Disabled Status"}),(0,ne.jsxs)(Le.A,{name:"disabled",label:"Disabled Status",defaultValue:v?.disabled,children:[(0,ne.jsx)(Ie.A,{value:!0,children:"Disabled"}),(0,ne.jsx)(Ie.A,{value:!1,children:"Enabled"})]})]})})]})}),(0,ne.jsxs)(lt.A,{sx:{p:3,pt:0},children:[(0,ne.jsx)(ae.A,{onClick:Q,children:"Cancel"}),(0,ne.jsx)(ae.A,{type:"submit",variant:"contained",disabled:_.isPending,startIcon:_.isPending?(0,ne.jsx)(b.A,{size:20}):null,children:_.isPending?"Updating...":"Update Store"})]})]})]}),(0,ne.jsx)(vr.A,{open:E.open,autoHideDuration:6e3,onClose:()=>F({...E,open:!1}),children:(0,ne.jsx)(xe.A,{onClose:()=>F({...E,open:!1}),severity:E.severity,sx:{width:"100%"},children:E.message})})]})};var qr=s(15068);const Or=()=>{const[e,t]=(0,A.useState)(""),[s,r]=(0,A.useState)(!1),[n,i]=(0,A.useState)(null),[a,o]=(0,A.useState)({name:"",description:"",categoryId:"",image:""}),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(!1),[u,m]=(0,A.useState)(null),[h,p]=(0,A.useState)(!1),[j,I]=(0,A.useState)(""),[C,w]=(0,A.useState)(""),[P,k]=(0,A.useState)(0),[E,L]=(0,A.useState)(10),[F,D]=(0,A.useState)([]),[z,T]=(0,A.useState)(""),[R,W]=(0,A.useState)(!1),[q,U]=(0,A.useState)({open:!1,message:"",severity:"info"}),[N,B]=(0,A.useState)(""),M=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":window.location.origin,{data:_,refetch:V}=(0,g.I)({queryKey:["products",e],queryFn:()=>$(O),enabled:!1}),{data:H,refetch:G}=(0,g.I)({queryKey:["categories"],queryFn:async()=>(await $("\n query GetCategories {\n categories {\n id\n name\n }\n }\n")).categories||[]}),K=(0,Ft.n)({mutationFn:e=>$("\n mutation CreateProduct($name: String!, $description: String!, $categoryId: Int!, $image: String) {\n createProduct(name: $name, description: $description, categoryId: $categoryId, image: $image) {\n id\n name\n description\n categoryId\n image\n }\n }\n",{name:e.name,description:e.description,categoryId:e.categoryId,image:e.image}),onSuccess:()=>{te(),J(),U({open:!0,message:"Product added successfully!",severity:"success"})}}),Y=(0,Ft.n)({mutationFn:e=>{let{productId:t,name:s,description:r,categoryId:n,image:i}=e;return $("\n mutation UpdateProduct(\n $productId: Int!,\n $name: String!,\n $description: String!,\n $categoryId: Int!,\n $image: String\n ) {\n updateProduct(\n productId: $productId,\n name: $name,\n description: $description,\n categoryId: $categoryId,\n image: $image\n ) {\n id\n name\n description\n categoryId\n image\n }\n }\n",{productId:t,name:s,description:r,categoryId:parseInt(n,10),image:i||null})},onSuccess:(e,t)=>{D((e=>e.map((e=>e.id===t.productId?{...e,name:t.name,description:t.description,categoryId:t.categoryId,image:t.image}:e)))),J(),U({open:!0,message:"Product updated successfully!",severity:"success"})},onError:e=>{U({open:!0,message:`Failed to update product: ${e.message}`,severity:"error"})}}),X=((0,Ft.n)({mutationFn:e=>$("\n mutation DeleteProduct($productId: Int!) {\n deleteProduct(productId: $productId)\n }\n",{productId:e}),onSuccess:()=>{V()}}),(0,Ft.n)({mutationFn:e=>$("\n mutation CreateCategory($name: String!) {\n createCategory(name: $name) {\n category {\n id\n name\n }\n }\n }\n",{name:e}),onSuccess:()=>{p(!1),I(""),w(""),G()},onError:e=>{w(e.message||"Failed to create category")}})),Q=(0,A.useMemo)((()=>H?H.reduce(((e,t)=>(e[t.id]=t.name,e)),{}):{}),[H]),Z=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(i(e),o({name:e.name,description:e.description,categoryId:e.categoryId,image:e.image})):(i(null),o({name:"",description:"",categoryId:"",image:""})),r(!0)},J=()=>{r(!1),i(null),o({name:"",description:"",categoryId:"",image:""})},ee=e=>{const{name:t,value:s}=e.target;"categoryId"!==t||"new"!==s?(o((e=>({...e,[t]:s}))),B("")):p(!0)},te=()=>{x(!0),m(null),V().then((e=>{e.data?.products&&D(e.data.products),d(!0),x(!1)})).catch((e=>{m("Failed to load products. Please try again."),x(!1)}))},se=()=>{j.trim()?X.mutate(j.trim()):w("Category name is required")},re=(0,A.useMemo)((()=>e?F.filter((t=>t.categoryId===parseInt(e))):F),[F,e]),ie=(0,A.useMemo)((()=>{const e=P*E;return re.slice(e,e+E)}),[re,P,E]),oe=()=>{U((e=>({...e,open:!1})))};return(0,ne.jsxs)(f.A,{children:[(0,ne.jsxs)(me.A,{sx:{p:3,mb:3},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ne.jsx)(Te.A,{sx:{mr:1}}),(0,ne.jsx)(y.A,{variant:"h5",children:"Product Management"})]}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,children:[(0,ne.jsx)($e.A,{children:"Category"}),(0,ne.jsxs)(Le.A,{value:e,onChange:e=>t(e.target.value),label:"Category",children:[(0,ne.jsx)(Ie.A,{value:"",children:"All Categories"}),Object.entries(Q).map((e=>{let[t,s]=e;return(0,ne.jsx)(Ie.A,{value:t,children:s},t)}))]})]})}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,md:8,sx:{display:"flex",alignItems:"center",gap:2},children:[(0,ne.jsx)(ae.A,{variant:"contained",startIcon:(0,ne.jsx)($r.A,{}),onClick:te,disabled:c,sx:{minWidth:150},children:c?(0,ne.jsx)(b.A,{size:24}):"Fetch Products"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:(0,ne.jsx)(Te.A,{}),onClick:()=>Z(),children:"Add Product"})]})]}),u&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:3},children:u}),l?c?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):(0,ne.jsx)(ne.Fragment,{children:(0,ne.jsxs)(Ar.A,{component:me.A,children:[(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Image"}),(0,ne.jsx)(fr.A,{children:"Name"}),(0,ne.jsx)(fr.A,{children:"Category"}),(0,ne.jsx)(fr.A,{children:"Description"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:ie.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:(0,ne.jsx)("img",{src:e.image,alt:e.name,style:{width:"50px",height:"50px",objectFit:"cover"}})}),(0,ne.jsx)(fr.A,{children:e.name}),(0,ne.jsx)(fr.A,{children:Q[e.categoryId]||"Unknown"}),(0,ne.jsx)(fr.A,{children:e.description}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(be.A,{size:"small",onClick:()=>Z(e),children:(0,ne.jsx)(Ir.A,{})})})]},e.id)))})]}),(0,ne.jsx)(v.A,{component:"div",count:re.length,page:P,onPageChange:(e,t)=>{k(t)},rowsPerPage:E,onRowsPerPageChange:e=>{L(parseInt(e.target.value,10)),k(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,ne.jsxs)(f.A,{sx:{textAlign:"center",py:4},children:[(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Products" to load product information'}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,ne.jsxs)(it.A,{open:s,onClose:J,maxWidth:"md",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:n?"Edit Product":"Add New Product"}),(0,ne.jsxs)(ot.A,{children:[N&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:N}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{required:!0,fullWidth:!0,label:"Product Name",name:"name",value:a.name,onChange:ee})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,required:!0,children:[(0,ne.jsx)($e.A,{children:"Category"}),(0,ne.jsxs)(Le.A,{name:"categoryId",value:a.categoryId,onChange:ee,label:"Category",children:[(0,ne.jsx)(Ie.A,{value:"",children:(0,ne.jsx)("em",{children:"Select a category"})}),Object.entries(Q).map((e=>{let[t,s]=e;return(0,ne.jsx)(Ie.A,{value:t,children:s},t)})),(0,ne.jsx)(Ie.A,{value:"new",sx:{borderTop:1,borderColor:"divider",mt:1},children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",color:"primary.main"},children:[(0,ne.jsx)(Te.A,{sx:{mr:1}}),"Add New Category"]})})]})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{required:!0,fullWidth:!0,multiline:!0,rows:3,label:"Description",name:"description",value:a.description,onChange:ee})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:"column",gap:1},children:[(0,ne.jsx)(le.A,{fullWidth:!0,label:"Image URL",name:"image",value:a.image,onChange:ee,placeholder:"https://example.com/image.jpg",disabled:R,error:!!z,helperText:z}),(0,ne.jsxs)(ae.A,{variant:"outlined",component:"label",startIcon:(0,ne.jsx)(qr.A,{}),disabled:R||!a.name||!a.categoryId,children:[R?"Uploading...":"Upload Image",(0,ne.jsx)("input",{type:"file",hidden:!0,accept:"image/*",onChange:async e=>{const t=e.target.files[0];if(!t)return;if(["image/jpeg","image/png","image/gif","image/webp"].includes(t.type))if(t.size>5242880)T("Image size should be less than 5MB");else try{W(!0),T("");const e=Q[a.categoryId]||"uncategorized",s=await(0,S.$)(),r=s?.tokens?.idToken?.toString?.()||s?.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(t.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:t})).ok)throw new Error("Failed to upload image");const c=i.split("?")[0]+`?t=${Date.now()}`;o((e=>({...e,image:c}))),U({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){T("Failed to upload image. Please try again."),U({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{W(!1)}else T("Please upload a valid image file (JPEG, PNG, GIF, or WebP)")},disabled:R})]}),a.image&&(0,ne.jsx)(f.A,{sx:{mt:1},children:(0,ne.jsx)("img",{src:a.image,alt:"Product preview",style:{maxWidth:"200px",maxHeight:"200px",objectFit:"contain"}})})]})})]})]}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:J,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",onClick:()=>{if(a.name.trim()&&a.description.trim()&&a.categoryId&&a.image)if(B(""),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 B("Please fill in all required fields, including an image.")},disabled:K.isPending||K.isLoading||Y.isPending||Y.isLoading,startIcon:K.isPending||K.isLoading||Y.isPending||Y.isLoading?(0,ne.jsx)(b.A,{size:20,color:"inherit"}):null,children:K.isPending||K.isLoading||Y.isPending||Y.isLoading?n?"Updating...":"Creating...":n?"Update":"Add"})]})]}),(0,ne.jsxs)(it.A,{open:h,onClose:()=>p(!1),children:[(0,ne.jsx)(at.A,{children:"Add New Category"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(le.A,{autoFocus:!0,margin:"dense",label:"Category Name",fullWidth:!0,value:j,onChange:e=>I(e.target.value),error:!!C,helperText:C,onKeyPress:e=>{"Enter"===e.key&&se()}})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>p(!1),children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:se,variant:"contained",disabled:X.isPending,children:X.isPending?"Creating...":"Create"})]})]}),(0,ne.jsx)(vr.A,{open:q.open,autoHideDuration:6e3,onClose:oe,anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,ne.jsx)(xe.A,{onClose:oe,severity:q.severity,sx:{width:"100%"},children:q.message})})]})};var Ur=s(75813),Nr=s(8047),Br=s(89966),Mr=s(52653);const _r=[{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"}],Vr=("sandbox-preview-mode"?.startsWith("sandbox-"),()=>{const[e,t]=(0,A.useState)(""),[s,r]=(0,A.useState)(""),[n,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(null),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(null),[u,m]=(0,A.useState)(!1),[h,p]=(0,A.useState)(""),[j,v]=(0,A.useState)(""),[I,S]=(0,A.useState)(""),[C,w]=(0,A.useState)(""),[P,k]=(0,A.useState)(!1),[E,L]=(0,A.useState)({open:!1,message:"",severity:"info"}),[D,z]=(0,A.useState)(!1);(0,A.useEffect)((()=>{if(c){z(!0);const e=setTimeout((()=>{z(!1),x(null)}),4e3);return()=>clearTimeout(e)}}),[c]);const{data:R,isLoading:W,refetch:O}=(0,g.I)({queryKey:["orders",s,e],queryFn:()=>$("\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 instructions\n allowSubstitute\n }\n }\n }\n }\n}\n"),enabled:l}),{data:U}=(0,g.I)({queryKey:["storeDrivers",a?.storeId],queryFn:async()=>a?.storeId?await $(T,{storeId:a.storeId}):null,enabled:!!a?.storeId}),{data:N={stores:[]},isLoading:B}=(0,g.I)({queryKey:["stores"],queryFn:()=>$(q),enabled:l}),M=A.useMemo((()=>{const e={};return(N.stores||[]).forEach((t=>{e[t.id]=t})),e}),[N]),_=(0,Ft.n)({mutationFn:async e=>await $(F,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onMutate:()=>{k(!0)},onSuccess:(e,t)=>{k(!1),R&&R.getAllOrders&&R.getAllOrders.forEach((e=>{e.id===t.orderId&&Object.assign(e,t)})),m(!1),o(null),p(""),v(""),S(""),w(""),L({open:!0,message:"Order status updated successfully!",severity:"success"})},onError:e=>{k(!1),x(e.message),m(!1),L({open:!0,message:`Failed to update order status: ${e.message}`,severity:"error"})}}),V=()=>{i(!1),o(null)},H=e=>{const{name:s,value:n}=e.target;"searchTerm"===s?t(n):"statusFilter"===s&&r(n)},G=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,ne.jsx)(Ur.A,{});case"CANCELLED":return(0,ne.jsx)(Nr.A,{});case"PENDING":return(0,ne.jsx)(Br.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),X=R?.getAllOrders?.filter((t=>{const r="PICKUP"===t.type?t.pickupAddress?.address:t.address?.address,n=""===e||r?.toLowerCase().includes(e.toLowerCase())||t.id.toString().includes(e),i=""===s||t.status===s;return n&&i}));return(0,ne.jsxs)(f.A,{children:[(0,ne.jsxs)(me.A,{sx:{p:3,mb:3},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ne.jsx)(Xt.A,{sx:{mr:1}}),(0,ne.jsx)(y.A,{variant:"h5",children:"Orders Management"})]}),c&&D&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:3},onClose:()=>z(!1),children:c}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,sx:{mb:3},children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsx)(le.A,{fullWidth:!0,placeholder:"Search by address or order ID",name:"searchTerm",value:e,onChange:H,InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Sr.A,{})})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,children:[(0,ne.jsx)($e.A,{children:"Status"}),(0,ne.jsxs)(Le.A,{name:"statusFilter",value:s,onChange:H,label:"Status",children:[(0,ne.jsx)(Ie.A,{value:"",children:"All Status"}),(0,ne.jsx)(Ie.A,{value:"PENDING",children:"Pending"}),(0,ne.jsx)(Ie.A,{value:"ACCEPTED",children:"Accepted"}),(0,ne.jsx)(Ie.A,{value:"READY_FOR_DELIVERY",children:"Ready for Delivery"}),(0,ne.jsx)(Ie.A,{value:"PICKED_UP",children:"Picked Up"}),(0,ne.jsx)(Ie.A,{value:"DELIVERED",children:"Delivered"}),(0,ne.jsx)(Ie.A,{value:"CANCELLED",children:"Cancelled"})]})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:(0,ne.jsx)($r.A,{}),onClick:()=>{d(!0),O()},fullWidth:!0,sx:{height:"56px"},children:"Fetch Orders"})})]}),l?W?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,ne.jsx)(b.A,{})}):0===X?.length?(0,ne.jsx)(xe.A,{severity:"info",sx:{mb:3},children:"No orders found matching your criteria"}):(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Order ID"}),(0,ne.jsx)(fr.A,{children:"Type"}),(0,ne.jsx)(fr.A,{children:"Address"}),(0,ne.jsx)(fr.A,{children:"Store"}),(0,ne.jsx)(fr.A,{children:"Status"}),(0,ne.jsx)(fr.A,{children:"Total Amount"}),(0,ne.jsx)(fr.A,{children:"Delivery Date"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:X.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsxs)(fr.A,{children:["#",e.id]}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:"PICKUP"===e.type?"Pickup":"Delivery",color:"PICKUP"===e.type?"secondary":"primary",size:"small"})}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(y.A,{variant:"body2",children:"PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A"})}),(0,ne.jsx)(fr.A,{children:M[e.storeId]?.name||"N/A"}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{icon:G(e.status),label:_r.find((t=>t.value===e.status))?.label||e.status.replace(/_/g," "),color:_r.find((t=>t.value===e.status))?.color||"default",size:"small"})}),(0,ne.jsx)(fr.A,{children:Y(e.totalAmount)}),(0,ne.jsx)(fr.A,{children:K(e.deliveryDate)}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{size:"small",onClick:()=>(e=>{o(e),i(!0)})(e),children:(0,ne.jsx)(Mr.A,{})}),(0,ne.jsx)(be.A,{size:"small",onClick:()=>(e=>{o(e),p(e.status),v(e.deliveryInstructions||""),m(!0)})(e),disabled:"CANCELLED"===e.status||"DELIVERED"===e.status,children:(0,ne.jsx)(Ir.A,{})})]})]},e.id)))})]})}):(0,ne.jsx)(we.A,{sx:{mb:3},children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",align:"center",gutterBottom:!0,children:'Click "Fetch Orders" to load order data'}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",align:"center",children:"This helps save resources by only loading data when needed"})]})})]}),(0,ne.jsxs)(it.A,{open:n,onClose:V,maxWidth:"md",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:"Order Details"}),(0,ne.jsx)(ot.A,{children:a&&(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsxs)(y.A,{variant:"h6",gutterBottom:!0,children:["Order #",a.id]}),(0,ne.jsx)(Oe.A,{label:"PICKUP"===a.type?"Pickup":"Delivery",color:"PICKUP"===a.type?"secondary":"primary",sx:{mb:2}}),(0,ne.jsx)(Oe.A,{icon:G(a.status),label:_r.find((e=>e.value===a.status))?.label||a.status.replace(/_/g," "),color:_r.find((e=>e.value===a.status))?.color||"default",sx:{mb:2}})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Information"}),(0,ne.jsxs)(y.A,{variant:"body2",children:["Address: ","PICKUP"===a.type?a.pickupAddress?.address:a.address?.address||"N/A"]}),(0,ne.jsxs)(y.A,{variant:"body2",children:["Store: ",M[a.storeId]?.name||"N/A"," (",M[a.storeId]?.address||"",")"]}),(0,ne.jsxs)(y.A,{variant:"body2",children:["Total Amount: ",Y(a.totalAmount)]}),(0,ne.jsxs)(y.A,{variant:"body2",children:["Delivery Date: ",K(a.deliveryDate)]}),a.deliveryInstructions&&(0,ne.jsxs)(y.A,{variant:"body2",children:["Delivery Instructions: ",a.deliveryInstructions]})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Order Items"}),(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{size:"small",children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Product"}),(0,ne.jsx)(fr.A,{children:"Quantity"}),(0,ne.jsx)(fr.A,{children:"Amount"})]})}),(0,ne.jsx)(br.A,{children:a.orderItems?.edges?.map((e=>{let{node:t}=e;return(0,ne.jsxs)(A.Fragment,{children:[(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:t.product?.name||"N/A"}),(0,ne.jsx)(fr.A,{children:t.quantity}),(0,ne.jsx)(fr.A,{children:Y(t.orderAmount)})]}),(t.instructions||null!==t.allowSubstitute)&&(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:3,sx:{py:1,borderBottom:"none"},children:(0,ne.jsxs)(f.A,{sx:{pl:2,display:"flex",flexDirection:"column",gap:.5},children:[t.instructions&&(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:"text.secondary"},children:[(0,ne.jsx)("strong",{children:"Instructions:"})," ",(0,ne.jsx)("em",{children:t.instructions})]}),(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:t.allowSubstitute?"warning.dark":"error.main",fontWeight:500},children:[(0,ne.jsx)("strong",{children:"If unavailable:"})," ",t.allowSubstitute?"Replace with a similar item":"Cancel this item"]})]})})})]},t.id)}))})]})})]})]})}),(0,ne.jsx)(lt.A,{children:(0,ne.jsx)(ae.A,{onClick:V,children:"Close"})})]}),(0,ne.jsxs)(it.A,{open:u,onClose:()=>m(!1),maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:"Update Order Status"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{select:!0,fullWidth:!0,label:"Status",value:h,onChange:e=>p(e.target.value),children:_r.map((e=>(0,ne.jsx)(Ie.A,{value:e.value,children:e.label},e.value)))})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Delivery Instructions",value:j,onChange:e=>v(e.target.value),multiline:!0,rows:3})}),("READY"===h||"READY_FOR_DELIVERY"===h)&&(0,ne.jsxs)(ne.Fragment,{children:[0===U?.getStoreDrivers?.length&&(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(xe.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,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,required:!0,children:[(0,ne.jsx)($e.A,{children:"Delivery Agent"}),(0,ne.jsx)(Le.A,{value:I,onChange:e=>S(e.target.value),label:"Delivery Agent",children:U?.getStoreDrivers?.length>0?U.getStoreDrivers.map((e=>(0,ne.jsxs)(Ie.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId))):(0,ne.jsx)(Ie.A,{disabled:!0,children:"No delivery agents available for this store"})})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Schedule Time",value:C,onChange:e=>w(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>m(!1),children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{if(!a)return;const e="DELIVERY"===a.type,t=a.address?.address,s=t&&""!==t.trim(),r=Array.isArray(a.orderItems?.edges)&&a.orderItems.edges.some((e=>{let{node:t}=e;return t.quantity>0}));if(e&&!s||!r)return x("Order must have a valid address and at least one product to update status."),void m(!1);const n={orderId:a.id,status:h,deliveryInstructions:j};if("READY"===h||"READY_FOR_DELIVERY"===h){if(!I)return void L({open:!0,message:"Driver ID is required for this status",severity:"error"});if(!C)return void L({open:!0,message:"Schedule time is required for this status",severity:"error"});n.driverId=parseInt(I),n.scheduleTime=C}_.mutate(n)},variant:"contained",color:"primary",disabled:P||("READY"===h||"READY_FOR_DELIVERY"===h)&&(!I||0===U?.getStoreDrivers?.length),children:P?"Updating...":"Update"})]})]}),(0,ne.jsx)(vr.A,{open:E.open,autoHideDuration:6e3,onClose:()=>L((e=>({...e,open:!1}))),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,ne.jsx)(xe.A,{onClose:()=>L((e=>({...e,open:!1}))),severity:E.severity,sx:{width:"100%"},children:E.message})})]})});var Hr=s(77867),Gr=s(74229),Kr=s(39804);const Yr=()=>{const[e,t]=(0,A.useState)(!1),[s,r]=(0,A.useState)(!1),[n,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(null),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(null),[u,m]=(0,A.useState)("info"),{data:h,isLoading:p,error:j,refetch:v}=(0,g.I)({queryKey:["allStoresSquareStatus"],queryFn:()=>$("\n query AllStoresSquareStatus {\n allStoresSquareStatus {\n storeId\n storeName\n isConnected\n merchantId\n }\n }\n")}),{data:I,refetch:S}=(0,g.I)({queryKey:["allStoresCod"],queryFn:()=>$("\n query AllStores {\n stores {\n id\n name\n codEnabled\n }\n }\n")}),C=(0,Ft.n)({mutationFn:e=>$("\n mutation ConnectSquare($storeId: Int!) {\n connectSquare(storeId: $storeId) {\n authorizationUrl\n message\n }\n }\n",{storeId:e}),onSuccess:e=>{const t=e.connectSquare?.authorizationUrl;t?window.location.href=t:(m("error"),x(e.connectSquare?.message||"Failed to generate authorization URL"))},onError:e=>{m("error"),x(e.message||"Failed to initiate Square connection")}}),w=(0,Ft.n)({mutationFn:e=>$("\n mutation DisconnectSquare($storeId: Int!) {\n disconnectSquare(storeId: $storeId) {\n success\n message\n }\n }\n",{storeId:e}),onSuccess:e=>{t(!1),i(null),e.disconnectSquare?.success?(m("success"),x("Square account disconnected successfully"),v()):(m("error"),x(e.disconnectSquare?.message||"Failed to disconnect Square"))},onError:e=>{t(!1),i(null),m("error"),x(e.message||"Failed to disconnect Square account")}}),P=(0,Ft.n)({mutationFn:e=>$("\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&&(m("success"),x(e.toggleCod.codEnabled?"Cash on Delivery enabled":"Cash on Delivery disabled"),S())},onError:e=>{r(!1),o(null),m("error"),x(e.message||"Failed to update COD settings")}});(0,A.useEffect)((()=>{const e=new URLSearchParams(window.location.search),t=e.get("oauth_success"),s=e.get("oauth_error"),r=e.get("store_id");"true"===t?(m("success"),x("Square account connected successfully"+(r?` for store ID ${r}`:"")),v(),window.history.replaceState({},"","/admin/payment-settings")):s&&(m("error"),x(`OAuth error: ${decodeURIComponent(s)}`),window.history.replaceState({},"","/admin/payment-settings"))}),[v]),(0,A.useEffect)((()=>{if(c){const e=setTimeout((()=>{x(null)}),5e3);return()=>clearTimeout(e)}}),[c]);const k=()=>{t(!1),i(null)},E=h?.allStoresSquareStatus||[],L=Object.fromEntries((I?.stores||[]).map((e=>[e.id,e.codEnabled])));return(0,ne.jsxs)(f.A,{children:[(0,ne.jsxs)(me.A,{sx:{p:3},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ne.jsx)(wt.A,{sx:{mr:1,fontSize:32}}),(0,ne.jsx)(y.A,{variant:"h5",children:"Square Payment Settings"})]}),c&&(0,ne.jsx)(xe.A,{severity:u,sx:{mb:3},onClose:()=>x(null),children:c}),j&&(0,ne.jsxs)(xe.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",j.message]}),(0,ne.jsx)(y.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."}),p?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Store Name"}),(0,ne.jsx)(fr.A,{children:"Connection Status"}),(0,ne.jsx)(fr.A,{children:"Merchant ID"}),(0,ne.jsx)(fr.A,{children:"COD"}),(0,ne.jsx)(fr.A,{align:"right",children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:0===E.length?(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:5,align:"center",children:"No stores found"})}):E.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(y.A,{variant:"body2",fontWeight:"medium",children:e.storeName})}),(0,ne.jsx)(fr.A,{children:e.isConnected?(0,ne.jsx)(Oe.A,{label:"Connected",color:"success",size:"small",icon:(0,ne.jsx)(Gr.A,{})}):(0,ne.jsx)(Oe.A,{label:"Not Connected",color:"default",size:"small",icon:(0,ne.jsx)(Kr.A,{})})}),(0,ne.jsx)(fr.A,{children:e.merchantId||(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"—"})}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Qe.A,{checked:L[e.storeId]||!1,onChange:t=>{o(e),d(t.target.checked),r(!0)},size:"small",disabled:P.isPending})}),(0,ne.jsx)(fr.A,{align:"right",children:e.isConnected?(0,ne.jsx)(ae.A,{variant:"outlined",color:"error",size:"small",onClick:()=>(e=>{i(e),t(!0)})(e),disabled:w.isLoading,children:"Disconnect"}):(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",size:"small",onClick:()=>{return t=e.storeId,void C.mutate(t);var t},disabled:C.isLoading,startIcon:C.isLoading&&(0,ne.jsx)(b.A,{size:16}),children:"Connect Square"})})]},e.storeId)))})]})})]}),(0,ne.jsxs)(it.A,{open:e,onClose:k,children:[(0,ne.jsx)(at.A,{children:"Disconnect Square?"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(Hr.A,{children:["Are you sure you want to disconnect Square for ",(0,ne.jsx)("strong",{children:n?.storeName}),"?",(0,ne.jsx)("br",{}),(0,ne.jsx)("br",{}),"Customers will not be able to make card payments until you reconnect."]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:k,disabled:w.isLoading,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{n&&w.mutate(n.storeId)},color:"error",variant:"contained",disabled:w.isLoading,startIcon:w.isLoading&&(0,ne.jsx)(b.A,{size:16}),children:"Disconnect"})]})]}),(0,ne.jsxs)(it.A,{open:s,onClose:()=>{r(!1),o(null)},children:[(0,ne.jsxs)(at.A,{children:[l?"Enable":"Disable"," Cash on Delivery?"]}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(Hr.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,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{r(!1),o(null)},disabled:P.isPending,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{a&&P.mutate({storeId:a.storeId,enabled:l})},variant:"contained",color:l?"primary":"error",disabled:P.isPending,startIcon:P.isPending&&(0,ne.jsx)(b.A,{size:16}),children:P.isPending?"Saving...":"Confirm"})]})]})]})};var Xr=s(98564),Qr=s(87558),Zr=s(1275),Jr=s(88116),en=s(98708),tn=s(60181);const sn=["meat","poultry","seafood","fish"],rn=e=>{if(!e)return!1;const t=e.toLowerCase();return sn.some((e=>t.includes(e)))},nn=()=>{const[e,t]=(0,A.useState)(0),[s,r]=(0,A.useState)(10),[n,i]=(0,A.useState)(""),[a,o]=(0,A.useState)(""),[l,d]=(0,A.useState)(null),[c,x]=(0,A.useState)(!1),[u,m]=(0,A.useState)(!1),[h,p]=(0,A.useState)(""),[j,I]=(0,A.useState)(""),[S,C]=(0,A.useState)(!0),[w,P]=(0,A.useState)(!0),[k,E]=(0,A.useState)({open:!1,message:"",severity:"success"}),[L,F]=(0,A.useState)("table"),[D,z]=(0,A.useState)(null),[T,R]=(0,A.useState)(""),[W,U]=(0,A.useState)(!1),[N,B]=(0,A.useState)({price:"",quantity:"",measurement:"",unit:""}),[M,_]=(0,A.useState)([]),[V,H]=(0,A.useState)([]),G=(0,A.useRef)(null),{data:K=[],isLoading:Y,error:X,refetch:Q}=(0,g.I)({queryKey:["stores"],queryFn:async()=>{const e=await $(q);return e?.stores||[]},enabled:!0}),{data:Z,isLoading:J}=(0,g.I)({queryKey:["products"],queryFn:async()=>{const e=await $(O);return e?.products||[]},enabled:u}),{data:ee=[],isLoading:te}=(0,g.I)({queryKey:["meatCuts"],queryFn:async()=>{const e=await $("\n query GetMeatCuts {\n meatCuts {\n id\n label\n text\n }\n }\n");return e?.meatCuts||[]},enabled:u||c}),{data:se,isLoading:re,error:ie,refetch:oe}=(0,g.I)({queryKey:["storeInventory",a],queryFn:async()=>{if(!a)return[];const e=await $("\n query GetInventoryByStore($storeId: Int!) {\n getInventoryByStore(storeId: $storeId) {\n id\n quantity\n price\n updatedAt\n isAvailable\n isListed\n cutTypes {\n id\n label\n text\n }\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}),de=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateInventoryItem(\n $inventoryId: Int!\n $price: Float\n $quantity: Int\n $isAvailable: Boolean\n $isListed: Boolean\n $meatCutIds: [Int!]\n ) {\n updateInventoryItem(\n inventoryId: $inventoryId\n price: $price\n quantity: $quantity\n isAvailable: $isAvailable\n isListed: $isListed\n meatCutIds: $meatCutIds\n ) {\n id\n isAvailable\n isListed\n measurement\n price\n productId\n quantity\n storeId\n unit\n updatedAt\n cutTypes {\n id\n label\n text\n }\n }\n }\n",e),onSuccess:()=>{E({open:!0,message:"Inventory item updated successfully",severity:"success"}),x(!1),oe()},onError:e=>{E({open:!0,message:`Error updating inventory: ${e.message}`,severity:"error"})}}),ce=(0,Ft.n)({mutationFn:e=>$("\n mutation AddProductToInventory(\n $productId: Int!\n $storeId: Int!\n $price: Float!\n $quantity: Int!\n $measurement: Int\n $unit: String\n $meatCutIds: [Int!]\n ) {\n addProductToInventory(\n productId: $productId\n storeId: $storeId\n price: $price\n quantity: $quantity\n measurement: $measurement\n unit: $unit\n meatCutIds: $meatCutIds\n ) {\n id\n measurement\n price\n productId\n quantity\n storeId\n unit\n cutTypes {\n id\n label\n text\n }\n }\n }\n",e),onSuccess:()=>{E({open:!0,message:"Product added to inventory successfully",severity:"success"}),oe(),m(!1),Ae()},onError:e=>{E({open:!0,message:`Error adding product to inventory: ${e.message}`,severity:"error"})}}),ue=e=>{d(e),p(e.quantity.toString()),I(e.price.toString()),C(e.isAvailable),P(e.isListed),_((e=>Array.isArray(e?.cutTypes)?e.cutTypes.filter(Boolean):[])(e)),x(!0)},he=()=>{E({...k,open:!1})},pe=()=>{m(!1),Ae()},Ae=()=>{z(null),R(""),B({price:"",quantity:"",measurement:"",unit:""}),H([])},ge=e=>{const{name:t,value:s}=e.target;B((e=>({...e,[t]:s})))},je=()=>{if(!D)return null;if(D.category?.name)return D.category.name;const e=Z?.find((e=>e.id===D.id));return e?.category?.name||null},fe=()=>se?se.filter((e=>e.product.name.toLowerCase().includes(n.toLowerCase()))):[],ve=Z?.filter((e=>e.name.toLowerCase().includes(T.toLowerCase())))||[],Se=(0,A.useRef)(null),Fe=(0,A.useCallback)((()=>{if("grid"!==L||!Se.current)return;const e=Se.current.offsetWidth,t=window.innerHeight-Se.current.getBoundingClientRect().top-150,n=Math.max(1,Math.floor(e/270))*Math.max(1,Math.floor(t/260));n!==s&&r(n)}),[L,s]);(0,A.useEffect)((()=>{if("grid"===L)return Fe(),window.addEventListener("resize",Fe),()=>window.removeEventListener("resize",Fe)}),[L,Fe]),(0,A.useEffect)((()=>{"table"===L&&10!==s&&r(10)}),[L,s]);return(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Inventory Management"}),(0,ne.jsxs)(me.A,{sx:{p:3,mb:3},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",mb:3,flexWrap:"wrap",gap:2},children:[(0,ne.jsxs)(Ee.A,{sx:{minWidth:200},children:[(0,ne.jsx)($e.A,{children:"Select Store"}),(0,ne.jsx)(Le.A,{value:a,onChange:e=>{o(e.target.value),t(0)},label:"Select Store",children:Array.isArray(K)&&K?.map((e=>(0,ne.jsx)(Ie.A,{value:e.id,children:e.name},e.id)))})]}),(0,ne.jsx)(le.A,{placeholder:"Search products...",value:n,onChange:e=>{i(e.target.value),t(0)},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Sr.A,{})})},sx:{width:300}}),(0,ne.jsx)(ae.A,{variant:"outlined",startIcon:"table"===L?(0,ne.jsx)(en.A,{}):(0,ne.jsx)(tn.A,{}),onClick:()=>{F("table"===L?"grid":"table")},children:"table"===L?"Grid View":"Table View"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:(0,ne.jsx)(Te.A,{}),onClick:()=>{a?m(!0):E({open:!0,message:"Please select a store first",severity:"warning"})},disabled:!a,children:"Add Product"})]}),X&&(0,ne.jsxs)(xe.A,{severity:"error",sx:{mb:3},children:["Error loading stores: ",X.message]}),ie&&(0,ne.jsxs)(xe.A,{severity:"error",sx:{mb:3},children:["Error loading inventory: ",ie.message]}),a?re?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):0===fe().length?(0,ne.jsx)(xe.A,{severity:"info",sx:{my:4},children:"No inventory found for this store."}):(0,ne.jsxs)(ne.Fragment,{children:["table"===L?(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Product"}),(0,ne.jsx)(fr.A,{children:"Category"}),(0,ne.jsx)(fr.A,{children:"Available"}),(0,ne.jsx)(fr.A,{children:"Listed"}),(0,ne.jsx)(fr.A,{children:"Price"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:fe().slice(e*s,e*s+s).map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[e.product.image&&(0,ne.jsx)(f.A,{component:"img",src:e.product.image,alt:e.product.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"body1",children:e.product.name}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:e.product.description})]})]})}),(0,ne.jsx)(fr.A,{children:e.product.category?.name||"N/A"}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:e.isAvailable?"Available":"Not Available",color:e.isAvailable?"success":"error",size:"small"})}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:e.isListed?"Listed":"Not Listed",color:e.isListed?"success":"error",size:"small"})}),(0,ne.jsxs)(fr.A,{children:["$",e.price.toFixed(2)]}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(be.A,{size:"small",color:"primary",onClick:()=>ue(e),children:(0,ne.jsx)(Ir.A,{})})})]},e.id)))})]})}):(0,ne.jsx)(Ce.Ay,{container:!0,spacing:3,ref:Se,children:fe().slice(e*s,e*s+s).map((e=>(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,lg:3,children:(0,ne.jsxs)(we.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,ne.jsx)(Pe.A,{component:"img",height:"140",image:e.product.image||"https://via.placeholder.com/140",alt:e.product.name}),(0,ne.jsxs)(ke.A,{sx:{flexGrow:1},children:[(0,ne.jsx)(y.A,{gutterBottom:!0,variant:"h6",component:"div",noWrap:!0,children:e.product.name}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:1},children:e.product.category?.name||"N/A"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:1},noWrap:!0,children:e.product.description}),(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:2},children:[(0,ne.jsx)(Oe.A,{label:`Qty: ${e.quantity}`,color:e.quantity<10?"error":"success",size:"small"}),(0,ne.jsxs)(y.A,{variant:"h6",color:"primary",children:["$",e.price.toFixed(2)]})]}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"space-between",mt:2},children:(0,ne.jsx)(ae.A,{size:"small",startIcon:(0,ne.jsx)(Ir.A,{}),onClick:()=>ue(e),children:"Edit"})})]})]})},e.id)))}),(0,ne.jsx)(v.A,{component:"div",count:fe().length,page:e,onPageChange:(e,s)=>{t(s)},rowsPerPage:s,onRowsPerPageChange:e=>{r(parseInt(e.target.value,10)),t(0)},rowsPerPageOptions:(()=>{if("grid"===L&&Se.current){const e=Se.current.offsetWidth,t=window.innerHeight-Se.current.getBoundingClientRect().top-150,s=270,r=260,n=Math.max(1,Math.floor(e/s));Math.max(1,Math.floor(t/r));return[...[1*n,2*n,3*n,4*n,5*n].filter((e=>ex(!1),fullWidth:!0,maxWidth:"sm",children:[(0,ne.jsx)(at.A,{children:"Edit Inventory Item"}),(0,ne.jsx)(ot.A,{children:l&&(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[l.product.image&&(0,ne.jsx)(f.A,{component:"img",src:l.product.image,alt:l.product.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"subtitle1",children:l.product.name}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:l.product.category?.name||"N/A"})]})]}),(0,ne.jsx)(le.A,{label:"Quantity",type:"number",fullWidth:!0,value:h,onChange:e=>p(e.target.value),sx:{mb:2}}),(0,ne.jsx)(le.A,{label:"Price ($)",type:"number",fullWidth:!0,value:j,onChange:e=>I(e.target.value),sx:{mb:2}}),(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mb:2},children:[(0,ne.jsx)($e.A,{children:"Availability"}),(0,ne.jsxs)(Le.A,{value:S,onChange:e=>C(e.target.value),label:"Availability",children:[(0,ne.jsx)(Ie.A,{value:!0,children:"Available"}),(0,ne.jsx)(Ie.A,{value:!1,children:"Not Available"})]})]}),(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mb:2},children:[(0,ne.jsx)($e.A,{children:"Listing Status"}),(0,ne.jsxs)(Le.A,{value:w,onChange:e=>P(e.target.value),label:"Listing Status",children:[(0,ne.jsx)(Ie.A,{value:!0,children:"Listed"}),(0,ne.jsx)(Ie.A,{value:!1,children:"Not Listed"})]})]}),rn(l.product?.category?.name)&&(0,ne.jsx)(Xr.A,{multiple:!0,options:ee,loading:te,value:M,onChange:(e,t)=>_(t),getOptionLabel:e=>e.label||"",isOptionEqualToValue:(e,t)=>e.id===t.id,renderInput:e=>(0,ne.jsx)(le.A,{...e,label:"Meat Cuts",placeholder:"Assign cut types",helperText:"Leave empty for no specific cuts. You may select one or multiple."}),sx:{mb:2}})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>x(!1),children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{if(!l)return;const e={inventoryId:l.id,price:parseFloat(j),quantity:parseInt(h),isAvailable:S,isListed:w};rn(l.product?.category?.name)&&(e.meatCutIds=M.map((e=>parseInt(e.id)))),de.mutate(e)},variant:"contained",color:"primary",disabled:de.isPending,children:de.isPending?"Updating...":"Update"})]})]}),(0,ne.jsxs)(it.A,{open:u,onClose:pe,fullWidth:!0,maxWidth:"md",children:[(0,ne.jsx)(at.A,{children:"Add Product to Inventory"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Select a product to add to the store's inventory"}),(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mt:2,mb:3},children:[(0,ne.jsx)(le.A,{ref:G,label:"Search Product",placeholder:"Start typing to search...",value:T,onChange:e=>{R(e.target.value),U(!0)},onFocus:()=>U(!0),onClick:()=>U(!0),fullWidth:!0,InputProps:{endAdornment:J?(0,ne.jsx)(b.A,{color:"inherit",size:20}):null}}),(0,ne.jsx)(Qr.A,{open:W&&ve.length>0,anchorEl:G.current,placement:"bottom-start",style:{width:G.current?.offsetWidth,zIndex:1300},children:(0,ne.jsx)(Zr.x,{onClickAway:()=>{U(!1)},children:(0,ne.jsx)(me.A,{elevation:3,children:(0,ne.jsx)(Jr.A,{sx:{maxHeight:300,overflow:"auto"},children:ve.map((e=>(0,ne.jsx)(Ie.A,{onClick:()=>(e=>{z(e),R(e.name),U(!1),H([])})(e),selected:D?.id===e.id,children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[e.image&&(0,ne.jsx)(f.A,{component:"img",src:e.image,alt:e.name,sx:{width:40,height:40,mr:2,objectFit:"cover",borderRadius:1}}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"body1",children:e.name}),(0,ne.jsx)(y.A,{variant:"caption",color:"textSecondary",children:e.categoryId?`Category ID: ${e.categoryId}`:"No category"})]})]})},e.id)))})})})})]}),D&&(0,ne.jsxs)(f.A,{sx:{mb:3,p:2,bgcolor:"background.paper",borderRadius:1},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",gutterBottom:!0,children:"Selected Product:"}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[D.image&&(0,ne.jsx)(f.A,{component:"img",src:D.image,alt:D.name,sx:{width:60,height:60,mr:2,objectFit:"cover",borderRadius:1}}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"body1",children:D.name}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:D.description})]})]})]}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,children:(0,ne.jsx)(le.A,{label:"Price ($)",type:"number",name:"price",fullWidth:!0,value:N.price,onChange:ge,required:!0,inputProps:{min:0,step:.01}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,children:(0,ne.jsx)(le.A,{label:"Quantity",type:"number",name:"quantity",fullWidth:!0,value:N.quantity,onChange:ge,required:!0,inputProps:{min:0}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,children:(0,ne.jsx)(le.A,{label:"Measurement (optional)",type:"number",name:"measurement",fullWidth:!0,value:N.measurement,onChange:ge,inputProps:{min:0,step:.01}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,children:(0,ne.jsx)(le.A,{label:"Unit (optional)",name:"unit",fullWidth:!0,value:N.unit,onChange:ge,placeholder:"e.g., kg, g, L, ml"})}),D&&rn(je())&&(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(Xr.A,{multiple:!0,options:ee,loading:te,value:V,onChange:(e,t)=>H(t),getOptionLabel:e=>e.label||"",isOptionEqualToValue:(e,t)=>e.id===t.id,renderInput:e=>(0,ne.jsx)(le.A,{...e,label:"Meat Cuts",placeholder:"Assign cut types",helperText:"Leave empty for no specific cuts. You may select one or multiple."})})})]})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:pe,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{if(!D)return void E({open:!0,message:"Please select a product",severity:"warning"});if(!N.price||!N.quantity)return void E({open:!0,message:"Please fill in all required fields",severity:"warning"});const e={productId:D.id,storeId:parseInt(a),price:parseFloat(N.price),quantity:parseInt(N.quantity),measurement:N.measurement?parseInt(N.measurement):null,unit:N.unit||""};rn(je())&&(e.meatCutIds=V.map((e=>parseInt(e.id)))),ce.mutate(e)},variant:"contained",color:"primary",disabled:ce.isPending||!D,children:ce.isPending?"Adding...":"Add to Inventory"})]})]}),(0,ne.jsx)(vr.A,{open:k.open,autoHideDuration:6e3,onClose:he,message:k.message,children:(0,ne.jsx)(xe.A,{onClose:he,severity:k.severity,children:k.message})})]})},an=()=>{const[e,t]=(0,A.useState)(0),[s,r]=(0,A.useState)(10),[n,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(null),[l,d]=(0,A.useState)(""),[c,x]=(0,A.useState)(null),[u,m]=(0,A.useState)(!1),[h,p]=(0,A.useState)(!1),[j,I]=(0,A.useState)(null),[S,C]=(0,A.useState)(null),[w,P]=(0,A.useState)(!1),{data:k,refetch:E}=(0,g.I)({queryKey:["categories"],queryFn:async()=>(await $("\n query GetCategories {\n categories {\n id\n name\n createdAt\n }\n }\n")).categories||[],enabled:!1}),L=(0,Ft.n)({mutationFn:e=>$("\n mutation CreateCategory($name: String!) {\n createCategory(name: $name) {\n category {\n id\n name\n }\n }\n }\n",{name:e}),onSuccess:()=>{T(),E()},onError:e=>{x(e.message||"Failed to create category")}}),F=(0,Ft.n)({mutationFn:e=>{let{id:t,name:s}=e;return $("\n mutation UpdateCategory($categoryId: Int!, $name: String!) {\n updateCategory(categoryId: $categoryId, name: $name) {\n category {\n id\n name\n }\n }\n }\n",{categoryId:t,name:s})},onSuccess:(e,t)=>{k&&k.forEach((e=>{e.id===t.id&&(e.name=t.name)})),T(),I("Category updated successfully")},onError:e=>{x(e.message||"Failed to update category")}}),D=(0,Ft.n)({mutationFn:e=>$("\n mutation DeleteCategory($categoryId: Int!) {\n deleteCategory(categoryId: $categoryId) {\n success\n }\n }\n",e),onSuccess:()=>{I("Category deleted successfully"),P(!1),E()},onError:e=>{x(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)},T=()=>{i(!1),o(null),d(""),x(null)},R=()=>{l.trim()?a?F.mutate({id:a.id,name:l.trim()}):L.mutate(l.trim()):x("Category name is required")},W=k?.slice(e*s,e*s+s);return(0,ne.jsxs)(f.A,{children:[(0,ne.jsxs)(me.A,{sx:{p:3,mb:3},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ne.jsx)(Te.A,{sx:{mr:1}}),(0,ne.jsx)(y.A,{variant:"h5",children:"Category Management"})]}),(0,ne.jsx)(Ce.Ay,{container:!0,spacing:2,sx:{mb:3},children:(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,sx:{display:"flex",gap:2},children:[(0,ne.jsx)(ae.A,{variant:"contained",startIcon:(0,ne.jsx)($r.A,{}),onClick:()=>{m(!0),x(null),E().then((()=>{p(!0),m(!1)})).catch((e=>{x("Failed to load categories. Please try again."),m(!1)}))},disabled:u,sx:{minWidth:150},children:u?(0,ne.jsx)(b.A,{size:24}):"Fetch Categories"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:(0,ne.jsx)(Te.A,{}),onClick:()=>z(),children:"Add Category"})]})}),c&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:3},children:c}),h?u?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):(0,ne.jsx)(ne.Fragment,{children:(0,ne.jsxs)(Ar.A,{children:[(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"ID"}),(0,ne.jsx)(fr.A,{children:"Name"}),(0,ne.jsx)(fr.A,{children:"Created At"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:0===W?.length?(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:4,align:"center",children:"No categories found"})}):W?.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.id}),(0,ne.jsx)(fr.A,{children:e.name}),(0,ne.jsx)(fr.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{size:"small",onClick:()=>z(e),children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{size:"small",onClick:()=>(e=>{C(e),P(!0)})(e),children:(0,ne.jsx)(Er.A,{})})]})]},e.id)))})]}),(0,ne.jsx)(v.A,{component:"div",count:k?.length||0,page:e,onPageChange:(e,s)=>{t(s)},rowsPerPage:s,onRowsPerPageChange:e=>{r(parseInt(e.target.value,10)),t(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,ne.jsxs)(f.A,{sx:{textAlign:"center",py:4},children:[(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Categories" to load category information'}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,ne.jsxs)(it.A,{open:n,onClose:T,children:[(0,ne.jsx)(at.A,{children:a?"Edit Category":"Add New Category"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(le.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&&R()}})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:T,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:R,variant:"contained",disabled:L.isPending||F.isPending,children:L.isPending||F.isPending?(0,ne.jsx)(b.A,{size:24}):a?"Update":"Create"})]})]}),(0,ne.jsxs)(it.A,{open:w,onClose:()=>P(!1),children:[(0,ne.jsx)(at.A,{children:"Delete Category"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this category?"})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>P(!1),disabled:D.isPending||D.isLoading,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{S&&D.mutate({categoryId:S.id})},variant:"contained",color:"error",disabled:D.isPending||D.isLoading,startIcon:D.isPending||D.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:D.isPending||D.isLoading?"Deleting...":"Delete"})]})]})]})},on=e=>{let{open:t,onClose:s,selectedFee:r,onUpdate:n,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,l]=(0,A.useState)(a);(0,A.useEffect)((()=>{r?l({feeCurrency:r.feeCurrency||"",feeRate:r.feeRate?.toString()||"",limit:r.limit?.toString()||"",type:r.type?.toUpperCase()||"DELIVERY"}):t&&l(a)}),[r,t]),(0,A.useEffect)((()=>{t||l(a)}),[t]);const d=e=>{const{name:t,value:s}=e.target;l((e=>({...e,[t]:s})))};return(0,ne.jsxs)(it.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:r?"Edit Fee":"Add New Fee"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(f.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ne.jsxs)(Ee.A,{fullWidth:!0,children:[(0,ne.jsx)($e.A,{children:"Fee Type"}),(0,ne.jsxs)(Le.A,{name:"type",value:o.type,onChange:d,label:"Fee Type",children:[(0,ne.jsx)(Ie.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,ne.jsx)(Ie.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,ne.jsx)(le.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:d,fullWidth:!0,placeholder:"e.g., USD"}),(0,ne.jsx)(le.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,ne.jsx)(le.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:s,children:"Cancel"}),(0,ne.jsx)(ae.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,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},ln=()=>{const[e,t]=(0,A.useState)(""),[s,r]=(0,A.useState)(null),[n,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(""),[c,x]=(0,A.useState)(""),{data:u,isLoading:m}=(0,g.I)({queryKey:["getAllStores"],queryFn:()=>$("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),h=u?.stores||[],{data:p,isLoading:v,refetch:I}=(0,g.I)({queryKey:["getFeesByStore",e],queryFn:()=>$("\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=p?.getFeesByStore||[],C=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateFee($input: UpdateFeeInput!) {\n updateFee(input: $input) {\n fee {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:(e,t)=>{p&&p.getFeesByStore&&p.getFeesByStore.forEach((e=>{e.id===t.id&&Object.assign(e,t)})),i(!1),r(null),x("Fee updated successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error updating fee: ${e.message}`)}}),w=(0,Ft.n)({mutationFn:e=>$("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),r(null),x("Fee deleted successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error deleting fee: ${e.message}`)}}),P=(0,Ft.n)({mutationFn:t=>$("\n mutation CreateFee($input: CreateFeeInput!) {\n createFee(input: $input) {\n fee {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n error {\n message\n }\n }\n }\n",{input:{...t,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),r(null),x("Fee added successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error adding fee: ${e.message}`)}});return m?(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})}):(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Fees Management"}),(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mb:3},children:[(0,ne.jsx)($e.A,{children:"Select Store"}),(0,ne.jsx)(Le.A,{value:e,onChange:e=>t(e.target.value),label:"Select Store",children:h.map((e=>(0,ne.jsx)(Ie.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,ne.jsx)(xe.A,{severity:"info",sx:{mb:4},children:(0,ne.jsx)(y.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its fees."})}),e&&(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.A,{variant:"h5",children:"Fees"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):(0,ne.jsx)(Te.A,{}),onClick:()=>{r(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Fee"})]}),v?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):0===S.length?(0,ne.jsx)(xe.A,{severity:"info",sx:{my:2},children:"No fees found for this store. Add your first fee to get started."}):(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Type"}),(0,ne.jsx)(fr.A,{children:"Currency"}),(0,ne.jsx)(fr.A,{children:"Rate"}),(0,ne.jsx)(fr.A,{children:"Limit"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:0!==S.length||v?S.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.type}),(0,ne.jsx)(fr.A,{children:e.feeCurrency}),(0,ne.jsx)(fr.A,{children:e.feeRate}),(0,ne.jsx)(fr.A,{children:e.limit}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{onClick:()=>(e=>{r(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{onClick:()=>(e=>{r(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ne.jsx)(Er.A,{})})]})]},e.id))):(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:5,align:"center",children:(0,ne.jsx)(xe.A,{severity:"info",sx:{my:2},children:"No fees found for this store."})})})})]})})]}),(0,ne.jsx)(on,{open:n,onClose:()=>{i(!1),r(null),d("")},selectedFee:s,onUpdate:e=>{s?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading}),(0,ne.jsxs)(it.A,{open:a,onClose:()=>{o(!1),r(null),d("")},children:[(0,ne.jsx)(at.A,{children:"Delete Fee"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{o(!1),r(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:s.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},dn=e=>{let{open:t,onClose:s,selectedLocationCode:r,onUpdate:n,isLoading:i,existingCodes:a}=e;const[o,l]=(0,A.useState)({location:"",code:""}),[d,c]=(0,A.useState)("");(0,A.useEffect)((()=>{l(r?{location:r.location||"",code:r.code||""}:{location:"",code:""}),c("")}),[r,t]);const x=()=>{l({location:"",code:""}),c(""),s()},u=e=>{const{name:t,value:s}=e.target;l((e=>({...e,[t]:s}))),c("")};return(0,ne.jsxs)(it.A,{open:t,onClose:x,maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:r?"Edit Location Code":"Add New Location Code"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(f.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ne.jsx)(le.A,{name:"location",label:"Location",value:o.location,onChange:u,fullWidth:!0,placeholder:"e.g., Main Branch",error:!!d&&d.includes("Location"),helperText:d&&d.includes("Location")?d:""}),(0,ne.jsx)(le.A,{name:"code",label:"Code",value:o.code,onChange:u,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,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:x,children:"Cancel"}),(0,ne.jsx)(ae.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,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},cn=()=>{const[e,t]=(0,A.useState)(""),[s,r]=(0,A.useState)(null),[n,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(""),[c,x]=(0,A.useState)(""),{data:u,isLoading:m}=(0,g.I)({queryKey:["getAllStores"],queryFn:()=>$("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),h=u?.stores||[],{data:p,isLoading:v,refetch:I}=(0,g.I)({queryKey:["getStoreLocationCodesByStore",e],queryFn:()=>$("\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=p?.getStoreLocationCodesByStore||[],C=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateStoreLocationCode($input: UpdateStoreLocationCodeInput!) {\n updateStoreLocationCode(input: $input) {\n locationCode {\n id\n storeId\n location\n code\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:(e,t)=>{p&&p.getStoreLocationCodesByStore&&p.getStoreLocationCodesByStore.forEach((e=>{e.id===t.id&&Object.assign(e,t)})),i(!1),r(null),x("Location code updated successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error updating location code: ${e.message}`)}}),w=(0,Ft.n)({mutationFn:e=>$("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),r(null),x("Location code deleted successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error deleting location code: ${e.message}`)}}),P=(0,Ft.n)({mutationFn:t=>$("\n mutation CreateStoreLocationCode($input: CreateStoreLocationCodeInput!) {\n createStoreLocationCode(input: $input) {\n locationCode {\n id\n storeId\n location\n code\n }\n error {\n message\n }\n }\n }\n",{input:{...t,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),r(null),x("Location code added successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error adding location code: ${e.message}`)}});return m?(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})}):(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mb:3},children:[(0,ne.jsx)($e.A,{children:"Select Store"}),(0,ne.jsx)(Le.A,{value:e,onChange:e=>t(e.target.value),label:"Select Store",children:h.map((e=>(0,ne.jsx)(Ie.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,ne.jsx)(xe.A,{severity:"info",sx:{mb:4},children:(0,ne.jsx)(y.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its location codes."})}),e&&(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.A,{variant:"h5",children:"Location Codes"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):(0,ne.jsx)(Te.A,{}),onClick:()=>{r(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Location Code"})]}),v?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):0===S.length?(0,ne.jsx)(xe.A,{severity:"info",sx:{my:2},children:"No location codes found for this store. Add your first location code to get started."}):(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Location"}),(0,ne.jsx)(fr.A,{children:"Code"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:0!==S.length||v?S.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.location}),(0,ne.jsx)(fr.A,{children:e.code}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{onClick:()=>(e=>{r(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{onClick:()=>(e=>{r(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ne.jsx)(Er.A,{})})]})]},e.id))):(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:3,align:"center",children:(0,ne.jsx)(xe.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})})]}),(0,ne.jsx)(dn,{open:n,onClose:()=>{i(!1),r(null),d("")},selectedLocationCode:s,onUpdate:e=>{s?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading,existingCodes:S}),(0,ne.jsxs)(it.A,{open:a,onClose:()=>{o(!1),r(null),d("")},children:[(0,ne.jsx)(at.A,{children:"Delete Location Code"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{o(!1),r(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:s.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},xn=e=>{let{open:t,onClose:s,selectedPickupAddress:r,onUpdate:n,isLoading:i,existingAddresses:a}=e;const[o,l]=(0,A.useState)({address:""}),[d,c]=(0,A.useState)(""),[x,u]=(0,A.useState)(!1);A.useEffect((()=>{r?(l({address:r.address||""}),u(!0)):(l({address:""}),u(!1)),c("")}),[r]);return(0,ne.jsxs)(it.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:r?"Edit Pickup Address":"Add New Pickup Address"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(f.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ne.jsx)(Vs,{value:o.address,onChange:e=>{l((t=>({...t,address:e}))),c("")},onValidAddress:u}),d&&(0,ne.jsx)(y.A,{color:"error",variant:"caption",children:d})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:s,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",onClick:()=>{(o.address.trim()?x?!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||!x,startIcon:i?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},un=()=>{const[e,t]=(0,A.useState)(""),[s,r]=(0,A.useState)(null),[n,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(""),[c,x]=(0,A.useState)(""),{data:u,isLoading:m}=(0,g.I)({queryKey:["getAllStores"],queryFn:()=>$("\n query GetAllStores {\n stores {\n id\n name\n }\n }\n")}),h=u?.stores||[],{data:p,isLoading:v,refetch:I}=(0,g.I)({queryKey:["getPickupAddressesByStore",e],queryFn:()=>$("\n query GetPickupAddressesByStore($storeId: Int!) {\n getPickupAddressesByStore(storeId: $storeId) {\n id\n storeId\n address\n }\n }\n",{storeId:parseInt(e)}),enabled:!!e}),S=p?.getPickupAddressesByStore||[],C=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdatePickupAddress($input: UpdatePickupAddressInput!) {\n updatePickupAddress(input: $input) {\n pickupAddress {\n id\n storeId\n address\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:(e,t)=>{p&&p.getPickupAddressesByStore&&p.getPickupAddressesByStore.forEach((e=>{e.id===t.id&&Object.assign(e,t)})),i(!1),r(null),x("Pickup address updated successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error updating pickup address: ${e.message}`)}}),w=(0,Ft.n)({mutationFn:e=>$("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{I(),o(!1),r(null),x("Pickup address deleted successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error deleting pickup address: ${e.message}`)}}),P=(0,Ft.n)({mutationFn:t=>$("\n mutation CreatePickupAddress($input: PickupAddressInput!) {\n createPickupAddress(input: $input) {\n pickupAddress {\n id\n storeId\n address\n }\n error {\n message\n }\n }\n }\n",{input:{...t,storeId:parseInt(e)}}),onSuccess:()=>{I(),i(!1),r(null),x("Pickup address added successfully"),setTimeout((()=>x("")),3e3)},onError:e=>{d(`Error adding pickup address: ${e.message}`)}});return m?(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})}):(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mb:3},children:[(0,ne.jsx)($e.A,{children:"Select Store"}),(0,ne.jsx)(Le.A,{value:e,onChange:e=>t(e.target.value),label:"Select Store",children:h.map((e=>(0,ne.jsx)(Ie.A,{value:e.id,children:e.name},e.id)))})]}),c&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:c}),l&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:l}),!e&&(0,ne.jsx)(xe.A,{severity:"info",sx:{mb:4},children:(0,ne.jsx)(y.A,{variant:"body1",children:"Please select a store from the dropdown above to view and manage its pickup addresses."})}),e&&(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.A,{variant:"h5",children:"Pickup Addresses"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:P.isPending||P.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):(0,ne.jsx)(Te.A,{}),onClick:()=>{r(null),i(!0)},disabled:P.isPending||P.isLoading,children:P.isPending||P.isLoading?"Adding...":"Add Pickup Address"})]}),v?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):0===S.length?(0,ne.jsx)(xe.A,{severity:"info",sx:{my:2},children:"No pickup addresses found for this store. Add your first pickup address to get started."}):(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Address"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:S.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.address}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{onClick:()=>(e=>{r(e),i(!0)})(e),color:"primary",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{onClick:()=>(e=>{r(e),o(!0)})(e),color:"error",disabled:C.isPending||C.isLoading||w.isPending||w.isLoading,children:(0,ne.jsx)(Er.A,{})})]})]},e.id)))})]})})]}),(0,ne.jsx)(xn,{open:n,onClose:()=>{i(!1),r(null),d("")},selectedPickupAddress:s,onUpdate:e=>{s?C.mutate(e):P.mutate(e)},isLoading:C.isPending||C.isLoading||P.isPending||P.isLoading,existingAddresses:S}),(0,ne.jsxs)(it.A,{open:a,onClose:()=>{o(!1),r(null),d("")},children:[(0,ne.jsx)(at.A,{children:"Delete Pickup Address"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{o(!1),r(null)},disabled:w.isPending||w.isLoading,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"error",onClick:()=>w.mutate({id:s.id}),disabled:w.isPending||w.isLoading,startIcon:w.isPending||w.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:w.isPending||w.isLoading?"Deleting...":"Delete"})]})]})]})},mn=()=>{const[e,t]=(0,A.useState)(0),[s,r]=(0,A.useState)(10),[n,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(null),[l,d]=(0,A.useState)(""),[c,x]=(0,A.useState)(""),[u,m]=(0,A.useState)(null),[h,p]=(0,A.useState)(!1),[j,I]=(0,A.useState)(!1),[S,C]=(0,A.useState)(null),[w,P]=(0,A.useState)(null),[k,E]=(0,A.useState)(!1),{data:L,refetch:F}=(0,g.I)({queryKey:["meatCuts"],queryFn:async()=>(await $("\n query GetMeatCuts {\n meatCuts {\n id\n label\n text\n }\n }\n")).meatCuts||[],enabled:!1}),D=(0,Ft.n)({mutationFn:e=>$("\n mutation CreateMeatCut($label: String!, $text: String!) {\n createMeatCut(label: $label, text: $text) {\n meatCut {\n id\n label\n text\n }\n error {\n message\n }\n }\n }\n",e),onSuccess:e=>{e?.createMeatCut?.error?m(e.createMeatCut.error.message):(W(),C("Meat cut created successfully"),F())},onError:e=>{m(e.message||"Failed to create meat cut")}}),z=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateMeatCut($meatCutId: Int!, $label: String!, $text: String!) {\n updateMeatCut(meatCutId: $meatCutId, label: $label, text: $text) {\n meatCut {\n id\n label\n text\n }\n error {\n message\n }\n }\n }\n",e),onSuccess:e=>{e?.updateMeatCut?.error?m(e.updateMeatCut.error.message):(W(),C("Meat cut updated successfully"),F())},onError:e=>{m(e.message||"Failed to update meat cut")}}),T=(0,Ft.n)({mutationFn:e=>$("\n mutation DeleteMeatCut($meatCutId: Int!) {\n deleteMeatCut(meatCutId: $meatCutId) {\n success\n error {\n message\n }\n }\n }\n",e),onSuccess:e=>{e?.deleteMeatCut?.error?m(e.deleteMeatCut.error.message):(C("Meat cut deleted successfully"),E(!1),F())},onError:e=>{m(e.message)}}),R=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(o(e),d(e.label),x(e.text)):(o(null),d(""),x("")),m(null),i(!0)},W=()=>{i(!1),o(null),d(""),x(""),m(null)},q=L?.slice(e*s,e*s+s);return(0,ne.jsxs)(f.A,{children:[(0,ne.jsxs)(me.A,{sx:{p:3,mb:3},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ne.jsx)(Te.A,{sx:{mr:1}}),(0,ne.jsx)(y.A,{variant:"h5",children:"Meat Cut Management"})]}),(0,ne.jsx)(Ce.Ay,{container:!0,spacing:2,sx:{mb:3},children:(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,sx:{display:"flex",gap:2},children:[(0,ne.jsx)(ae.A,{variant:"contained",startIcon:(0,ne.jsx)($r.A,{}),onClick:()=>{p(!0),m(null),F().then((()=>{I(!0),p(!1)})).catch((()=>{m("Failed to load meat cuts. Please try again."),p(!1)}))},disabled:h,sx:{minWidth:150},children:h?(0,ne.jsx)(b.A,{size:24}):"Fetch Meat Cuts"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:(0,ne.jsx)(Te.A,{}),onClick:()=>R(),children:"Add Meat Cut"})]})}),u&&!n&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:3},onClose:()=>m(null),children:u}),S&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:3},onClose:()=>C(null),children:S}),j?h?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",py:4},children:(0,ne.jsx)(b.A,{})}):(0,ne.jsx)(ne.Fragment,{children:(0,ne.jsxs)(Ar.A,{children:[(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"ID"}),(0,ne.jsx)(fr.A,{children:"Label"}),(0,ne.jsx)(fr.A,{children:"Text"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:0===q?.length?(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:4,align:"center",children:"No meat cuts found"})}):q?.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.id}),(0,ne.jsx)(fr.A,{children:e.label}),(0,ne.jsx)(fr.A,{children:e.text}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{size:"small",onClick:()=>R(e),children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{size:"small",onClick:()=>(e=>{P(e),E(!0)})(e),children:(0,ne.jsx)(Er.A,{})})]})]},e.id)))})]}),(0,ne.jsx)(v.A,{component:"div",count:L?.length||0,page:e,onPageChange:(e,s)=>{t(s)},rowsPerPage:s,onRowsPerPageChange:e=>{r(parseInt(e.target.value,10)),t(0)},rowsPerPageOptions:[5,10,25,50]})]})}):(0,ne.jsxs)(f.A,{sx:{textAlign:"center",py:4},children:[(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:'Click "Fetch Meat Cuts" to load meat cut information'}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"This helps save resources by only loading data when needed"})]})]}),(0,ne.jsxs)(it.A,{open:n,onClose:W,fullWidth:!0,maxWidth:"sm",children:[(0,ne.jsx)(at.A,{children:a?"Edit Meat Cut":"Add New Meat Cut"}),(0,ne.jsxs)(ot.A,{children:[u&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:u}),(0,ne.jsx)(le.A,{autoFocus:!0,margin:"dense",label:"Label",fullWidth:!0,value:l,onChange:e=>d(e.target.value)}),(0,ne.jsx)(le.A,{margin:"dense",label:"Text",fullWidth:!0,multiline:!0,minRows:2,value:c,onChange:e=>x(e.target.value)})]}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:W,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{l.trim()?c.trim()?a?z.mutate({meatCutId:a.id,label:l.trim(),text:c.trim()}):D.mutate({label:l.trim(),text:c.trim()}):m("Text is required"):m("Label is required")},variant:"contained",disabled:D.isPending||z.isPending,children:D.isPending||z.isPending?(0,ne.jsx)(b.A,{size:24}):a?"Update":"Create"})]})]}),(0,ne.jsxs)(it.A,{open:k,onClose:()=>E(!1),children:[(0,ne.jsx)(at.A,{children:"Delete Meat Cut"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this meat cut?"})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>E(!1),disabled:T.isPending,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{w&&T.mutate({meatCutId:w.id})},variant:"contained",color:"error",disabled:T.isPending,startIcon:T.isPending?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:T.isPending?"Deleting...":"Delete"})]})]})]})},hn=240,pn=65,An=[{text:"Dashboard",icon:(0,ne.jsx)(ar.A,{}),path:"/admin/dashboard"},{text:"Stores",icon:(0,ne.jsx)(or.A,{}),path:"/admin/stores"},{text:"Product Management",icon:(0,ne.jsx)(lr.A,{}),path:"/admin/products"},{text:"Inventory Management",icon:(0,ne.jsx)(dr.A,{}),path:"/admin/inventory"},{text:"Orders",icon:(0,ne.jsx)(Re.A,{}),path:"/admin/orders"},{text:"Users",icon:(0,ne.jsx)(cr.A,{}),path:"/admin/users"},{text:"Payment Settings",icon:(0,ne.jsx)(wt.A,{}),path:"/admin/payment-settings"},{text:"Categories",icon:(0,ne.jsx)(dr.A,{}),path:"/admin/categories"},{text:"Meat Cuts",icon:(0,ne.jsx)(xr.A,{}),path:"/admin/meat-cuts"},{text:"Fees Management",icon:(0,ne.jsx)(wt.A,{}),path:"/admin/fees"},{text:"Location Codes",icon:(0,ne.jsx)(jt.A,{}),path:"/admin/location-codes"},{text:"Pickup Addresses",icon:(0,ne.jsx)(qt.A,{}),path:"/admin/pickup-addresses"}],gn=()=>{const e=(0,qe.A)(),t=(0,Ke.A)(e.breakpoints.down("sm")),[s,r]=(0,A.useState)(!0),{user:n,ability:i,logout:a}=te(),o=(0,d.Zp)(),l=(0,d.zy)(),c=(0,ne.jsxs)(f.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",justifyContent:s&&!t?"space-between":"center",p:2,minHeight:64},children:[s&&!t&&(0,ne.jsx)(y.A,{variant:"h6",noWrap:!0,component:"div",children:"Admin Panel"}),!t&&(0,ne.jsx)(be.A,{onClick:()=>{r(!s)},children:s?(0,ne.jsx)(bt.A,{}):(0,ne.jsx)(ur.A,{})})]}),(0,ne.jsx)(Ct.A,{}),(0,ne.jsxs)(Bt.A,{children:[An.map((r=>(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:()=>{return e=r.path,void o(e);var e},selected:l.pathname===r.path,sx:{minHeight:48,justifyContent:s&&!t?"initial":"center",px:2.5,"&.Mui-selected":{background:e.palette.custom.gradientCoral,color:"white","&:hover":{background:e.palette.custom.gradientCoral,opacity:.9},"& .MuiListItemIcon-root":{color:"white"}}},children:[(0,ne.jsx)(_t.A,{sx:{minWidth:0,mr:s&&!t?3:"auto",justifyContent:"center",color:l.pathname===r.path?"white":"inherit"},children:r.icon}),(0,ne.jsx)(Vt.A,{primary:r.text,sx:{opacity:s&&!t?1:0}})]},r.text))),(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:()=>{(async()=>{try{await(0,Qt.C)(),a(),o("/")}catch(e){}})()},sx:{minHeight:48,justifyContent:s&&!t?"initial":"center",px:2.5},children:[(0,ne.jsx)(_t.A,{sx:{minWidth:0,mr:s&&!t?3:"auto",justifyContent:"center"},children:(0,ne.jsx)(mr.A,{})}),(0,ne.jsx)(Vt.A,{primary:"Logout",sx:{opacity:s&&!t?1:0}})]})]})]});return(0,ne.jsxs)(f.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,ne.jsx)(Qs,{}),(0,ne.jsx)(f.A,{component:"nav",sx:{width:t?pn:s?hn:pn,flexShrink:0,position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,ne.jsx)(Ht.Ay,{variant:"persistent",open:!0,sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:t?pn:s?hn:pn,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,ne.jsx)(f.A,{component:"main",sx:{flexGrow:1,p:{xs:0,sm:3},width:{xs:"calc(100% - 65px)",sm:`calc(100% - ${s?hn:pn}px)`},ml:{xs:"65px",sm:`${s?hn:pn}px`},mt:{xs:"64px",sm:"70px"},transition:e.transitions.create(["width","margin"],{easing:e.transitions.easing.sharp,duration:e.transitions.duration.leavingScreen})},children:(0,ne.jsxs)(d.BV,{children:[(0,ne.jsx)(d.qh,{path:"/",element:(0,ne.jsx)(d.C5,{to:"dashboard",replace:!0})}),(0,ne.jsx)(d.qh,{path:"dashboard",element:(0,ne.jsx)(pr,{})}),(0,ne.jsx)(d.qh,{path:"users/*",element:(0,ne.jsx)(Cr,{})}),(0,ne.jsx)(d.qh,{path:"stores/*",element:(0,ne.jsx)(Wr,{})}),(0,ne.jsx)(d.qh,{path:"products",element:(0,ne.jsx)(Or,{})}),(0,ne.jsx)(d.qh,{path:"inventory",element:(0,ne.jsx)(nn,{})}),(0,ne.jsx)(d.qh,{path:"orders",element:(0,ne.jsx)(Vr,{})}),(0,ne.jsx)(d.qh,{path:"payment-settings",element:(0,ne.jsx)(Yr,{})}),(0,ne.jsx)(d.qh,{path:"categories",element:(0,ne.jsx)(an,{})}),(0,ne.jsx)(d.qh,{path:"meat-cuts",element:(0,ne.jsx)(mn,{})}),(0,ne.jsx)(d.qh,{path:"fees",element:(0,ne.jsx)(ln,{})}),(0,ne.jsx)(d.qh,{path:"location-codes",element:(0,ne.jsx)(cn,{})}),(0,ne.jsx)(d.qh,{path:"pickup-addresses",element:(0,ne.jsx)(un,{})})]})})]})};var yn=s(27558),jn=s(76030);const fn=()=>{const[,e]=(0,A.useReducer)((e=>e+1),0),[t,s]=(0,A.useState)(null),[r,n]=(0,A.useState)(!1),[i,a]=(0,A.useState)(null),[o,l]=(0,A.useState)(""),[d,c]=(0,A.useState)(""),[x,u]=(0,A.useState)("ALL"),[m,h]=(0,A.useState)(""),[p,v]=(0,A.useState)(!1),[I,C]=(0,A.useState)(0),[w,P]=(0,A.useState)({}),[k,E]=(0,A.useState)(!1),{userProfile:L,setUserProfile:z}=te();(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,S.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;a(t)}}catch(e){}})()}),[]);const{data:T,isLoading:W,error:q}=(0,g.I)({queryKey:["getUserProfile",i],queryFn:async()=>{const t=await $(D,{userId:i});return t?.getUserProfile&&(z(t.getUserProfile),setTimeout((()=>{e()}),200)),t},enabled:!!i,onError:e=>{}}),O=te.getState().userProfile||L||T?.getUserProfile,{data:U,isLoading:N,error:B,refetch:M}=(0,g.I)({queryKey:["driverDeliveries",O?.id],queryFn:()=>O?.id?$("\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,Ft.n)({mutationFn:e=>$(F,{input:{orderId:e.orderId,status:e.status}}),onSuccess:()=>{M(),n(!1),h(""),v(!1)},onError:e=>{}}),V=(0,Ft.n)({mutationFn:e=>$(R,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:O?.id}),onSuccess:()=>{M(),n(!1),h(""),v(!1)},onError:e=>{}}),H=e=>!!e?.edges?.length&&e.edges.every((e=>w[e.node.id])),G=A.useMemo((()=>U?.getDeliveriesByDriver?U.getDeliveriesByDriver.filter((e=>{if("ALL"!==x&&e.status!==x)return!1;if(d){const t=d.toLowerCase(),s=e.orderId.toString().includes(t),r=e.address?.toLowerCase().includes(t);return s||r}return!0})):[]),[U?.getDeliveriesByDriver,x,d]);if(W||N&&O?.id)return(0,ne.jsx)(b.A,{sx:{display:"block",mx:"auto",mt:4}});if(q)return(0,ne.jsx)(y.A,{color:"error",children:"Error fetching user profile!"});if(B&&O?.id)return(0,ne.jsx)(y.A,{color:"error",children:"Error fetching deliveries!"});const K=U?.getDeliveriesByDriver||[],Y=e=>{switch(e){case"READY_FOR_DELIVERY":return"primary";case"PICKED_UP":return"info";case"DELIVERED":return"success";case"CANCELLED":return"error";default:return"default"}},X=e=>{switch(e){case"READY_FOR_DELIVERY":return(0,ne.jsx)(Br.A,{});case"PICKED_UP":return(0,ne.jsx)(qt.A,{});case"DELIVERED":return(0,ne.jsx)(Ur.A,{});case"CANCELLED":return(0,ne.jsx)(Nr.A,{});default:return null}},Q=e=>U?.getDeliveriesByDriver?U.getDeliveriesByDriver.filter((t=>t.status===e)).length:0;return(0,ne.jsxs)(j.A,{maxWidth:"lg",sx:{mt:4,mb:6},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:4,flexDirection:{xs:"column",sm:"row"},gap:{xs:2,sm:0}},children:[(0,ne.jsx)(y.A,{variant:"h4",fontWeight:"500",sx:{fontSize:{xs:"1.5rem",sm:"2rem"}},children:"Delivery Partner Dashboard"}),(0,ne.jsx)(le.A,{size:"small",placeholder:"Search orders...",value:d,onChange:e=>c(e.target.value),InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Sr.A,{fontSize:"small"})})},sx:{width:{xs:"100%",sm:250},"& .MuiOutlinedInput-root":{borderRadius:2}}})]}),(0,ne.jsx)(f.A,{sx:{mb:4},children:(0,ne.jsxs)(ws.A,{value:I,onChange:(e,t)=>{C(t),0===t?u("ALL"):1===t?u("READY_FOR_DELIVERY"):2===t?u("PICKED_UP"):3===t&&u("DELIVERED")},variant:"scrollable",scrollButtons:"auto",sx:{borderBottom:1,borderColor:"divider","& .MuiTab-root":{minWidth:120,textTransform:"none",fontSize:"0.875rem"}},children:[(0,ne.jsx)(Ps.A,{label:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:["All Orders",(0,ne.jsx)(mt.A,{badgeContent:K.length,color:"primary",sx:{ml:2}})]})}),(0,ne.jsx)(Ps.A,{label:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:["Ready",(0,ne.jsx)(mt.A,{badgeContent:Q("READY_FOR_DELIVERY"),color:"primary",sx:{ml:2}})]})}),(0,ne.jsx)(Ps.A,{label:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:["In Transit",(0,ne.jsx)(mt.A,{badgeContent:Q("PICKED_UP"),color:"info",sx:{ml:2}})]})}),(0,ne.jsx)(Ps.A,{label:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:["Delivered",(0,ne.jsx)(mt.A,{badgeContent:Q("DELIVERED"),color:"success",sx:{ml:2}})]})})]})}),(0,ne.jsx)(Ce.Ay,{container:!0,spacing:{xs:2,sm:3},children:G.length>0?G.map((e=>(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,md:4,children:(0,ne.jsx)(we.A,{sx:{cursor:"pointer",height:"100%",display:"flex",flexDirection:"column",borderRadius:2,boxShadow:"0 2px 8px rgba(0,0,0,0.05)",transition:"all 0.2s ease-in-out","&:hover":{boxShadow:"0 4px 12px rgba(0,0,0,0.1)",transform:"translateY(-2px)"}},onClick:()=>(e=>{s(e),l(e.orderStatus||e.status),n(!0),v(!1),h("")})(e),children:(0,ne.jsxs)(ke.A,{sx:{flexGrow:1,p:{xs:2,sm:2.5}},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,ne.jsxs)(y.A,{variant:"h6",sx:{fontSize:{xs:"1rem",sm:"1.25rem"},fontWeight:500},children:["Order #",e.orderId]}),(0,ne.jsx)(Oe.A,{icon:X(e.status),label:e.status.replace(/_/g," "),color:Y(e.status),size:"small",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},height:{xs:24,sm:28},borderRadius:1.5}})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[(0,ne.jsx)(jn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:new Date(e.schedule).toLocaleString()})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"flex-start",mb:2},children:[(0,ne.jsx)(jt.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,ne.jsx)(y.A,{variant:"body2",sx:{flexGrow:1,fontSize:{xs:"0.75rem",sm:"0.875rem"}},children:e?.order?.address?.address||"No address provided"})]}),e.pickedUpTime&&(0,ne.jsxs)(y.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,ne.jsxs)(y.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,ne.jsx)(f.A,{sx:{mt:1},children:(0,ne.jsxs)(y.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,ne.jsx)(Nr.A,{fontSize:"small",sx:{mr:.5,flexShrink:0}}),(0,ne.jsxs)("span",{style:{lineHeight:1},children:['Cancellation Reason: "',e.order.cancelMessage,'"']})]})}),e.comments&&"CANCELLED"!==e.status&&(0,ne.jsx)(f.A,{sx:{mt:1},children:(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{fontSize:{xs:"0.7rem",sm:"0.75rem"},fontStyle:"italic",display:"flex",alignItems:"flex-start"},children:(0,ne.jsxs)("span",{children:['"',e.comments,'"']})})})]})})},e.id))):(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(me.A,{sx:{p:{xs:3,sm:4},borderRadius:2,textAlign:"center"},children:[(0,ne.jsx)(y.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"No Deliveries Found"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:d||"ALL"!==x?"No deliveries match your search criteria.":"You have no deliveries assigned at this time."})]})})}),(0,ne.jsx)(ds.A,{open:r,onClose:()=>n(!1),"aria-labelledby":"delivery-details-modal",children:(0,ne.jsx)(f.A,{sx:{width:{xs:"95%",sm:"90%",md:500},bgcolor:"background.paper",p:{xs:2,sm:3},mx:"auto",mt:{xs:2,sm:5},borderRadius:2,boxShadow:3,maxHeight:"90vh",overflow:"auto"},children:t&&(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,ne.jsxs)(y.A,{variant:"h5",fontWeight:"500",sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"}},children:["Order #",t.orderId]}),(0,ne.jsx)(be.A,{edge:"end","aria-label":"close",onClick:()=>n(!1),size:"small",children:(0,ne.jsx)(Pt.A,{})})]}),(0,ne.jsx)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:(0,ne.jsx)(Oe.A,{icon:X(t.status),label:t.status.replace(/_/g," "),color:Y(t.status),sx:{fontSize:{xs:"0.75rem",sm:"0.875rem"}}})}),(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY ADDRESS"}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"flex-start"},children:[(0,ne.jsx)(jt.A,{fontSize:"small",sx:{mr:1,color:"text.secondary",mt:.5}}),(0,ne.jsx)(y.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.order?.pickupAddress?.address||t.order?.address?.address||t.address||"No address provided"})]})]}),(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"SCHEDULED DELIVERY"}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ne.jsx)(jn.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,ne.jsx)(y.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.schedule).toLocaleString()})]})]}),t.pickedUpTime&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"PICKED UP"}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ne.jsx)(qt.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,ne.jsx)(y.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.pickedUpTime).toLocaleString()})]})]}),t.deliveredTime&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERED"}),(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[(0,ne.jsx)(Ur.A,{fontSize:"small",sx:{mr:1,color:"text.secondary"}}),(0,ne.jsx)(y.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:new Date(t.deliveredTime).toLocaleString()})]})]}),"CANCELLED"===t.status&&t.order?.cancelMessage&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"error",gutterBottom:!0,children:"CANCELLATION REASON"}),(0,ne.jsxs)(f.A,{sx:{p:2,bgcolor:"error.lightest",borderRadius:1,borderLeft:"3px solid",borderColor:"error.main",display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Nr.A,{color:"error",sx:{flexShrink:0}}),(0,ne.jsx)(y.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"},color:"error.main",lineHeight:1.2},children:t.order.cancelMessage})]})]}),t.comments&&"CANCELLED"!==t.status&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"COMMENTS"}),(0,ne.jsx)(f.A,{sx:{p:2,bgcolor:"rgba(0, 0, 0, 0.03)",borderRadius:1,borderLeft:"3px solid",borderColor:"primary.main"},children:(0,ne.jsx)(y.A,{variant:"body1",sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.comments})})]}),t.photo&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"DELIVERY PROOF"}),(0,ne.jsx)("img",{src:t.photo,alt:"Delivery Proof",style:{width:"100%",borderRadius:4}})]}),k&&t?.order?.orderItems&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"VERIFY ITEMS TO BE PICKED UP"}),(0,ne.jsx)(me.A,{sx:{p:2,maxHeight:300,overflow:"auto"},children:t.order.orderItems.edges.filter((e=>{let{node:t}=e;return null===t.updatedOrderitemsId&&t.quantity>0})).map((e=>{let{node:t}=e;return(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:1,p:1,borderRadius:1,bgcolor:"background.default"},children:[(0,ne.jsx)(yn.A,{checked:!!w[t.id],onChange:()=>{return e=t.id,void P((t=>({...t,[e]:!t[e]})));var e},color:"primary"}),(0,ne.jsxs)(f.A,{sx:{ml:2,flex:1},children:[(0,ne.jsx)(y.A,{variant:"body2",fontWeight:"500",children:t.product.name}),(0,ne.jsxs)(y.A,{variant:"caption",color:"text.secondary",children:["Quantity: ",t.quantity," × $",t.orderAmount.toFixed(2)]})]})]},t.id)}))}),!H(t.order.orderItems)&&(0,ne.jsx)(xe.A,{severity:"warning",sx:{mt:1},children:"Please verify all items before updating status"})]}),(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"UPDATE STATUS"}),(0,ne.jsx)(Ee.A,{fullWidth:!0,sx:{mb:2},children:(0,ne.jsxs)(Le.A,{value:o,onChange:e=>{const s=e.target.value;l(s),"READY_FOR_DELIVERY"===t?.status&&"READY_FOR_DELIVERY"!==s?(E(!0),P({})):E(!1),v("CANCELLED"===s)},size:"small",children:[(0,ne.jsx)(Ie.A,{value:"PICKED_UP",children:"Picked Up"}),(0,ne.jsx)(Ie.A,{value:"DELIVERED",children:"Delivered"}),(0,ne.jsx)(Ie.A,{value:"CANCELLED",children:"Cancelled"})]})}),p&&(0,ne.jsx)(le.A,{fullWidth:!0,label:"Cancellation Reason",multiline:!0,rows:3,value:m,onChange:e=>h(e.target.value),sx:{mb:2},required:!0,size:"small"}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"flex-end",mt:3},children:(0,ne.jsx)(ae.A,{onClick:()=>{t&&o&&("READY_FOR_DELIVERY"!==t.status||"READY_FOR_DELIVERY"===o||H(t.order.orderItems))&&("CANCELLED"===o?V.mutate({orderId:t.orderId,cancelMessage:m}):_.mutate({orderId:t.orderId,status:o}))},variant:"contained",color:"primary",disabled:("CANCELLED"===o?V.isPending||V.isLoading:_.isPending||_.isLoading)||o===t.orderStatus||"CANCELLED"===o&&!m||k&&!H(t.order.orderItems),startIcon:("CANCELLED"===o?V.isPending||V.isLoading:_.isPending||_.isLoading)?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,sx:{minWidth:120},children:("CANCELLED"===o?V.isPending||V.isLoading:_.isPending||_.isLoading)?"Updating...":"Update"})})]})})})]})};var bn=s(80669),vn=s(47922);const In=[{text:"Dashboard",icon:(0,ne.jsx)(ar.A,{}),path:rs},{text:"Orders",icon:(0,ne.jsx)(Re.A,{}),path:ns},{text:"Delivery Partners",icon:(0,ne.jsx)(qt.A,{}),path:"/store_manager/delivery-partners"},{text:"Inventory",icon:(0,ne.jsx)(lr.A,{}),path:"/store_manager/inventory"},{text:"Delivery Fees",icon:(0,ne.jsx)(vn.A,{}),path:"/store_manager/delivery-fees"},{text:"Location Codes",icon:(0,ne.jsx)(jt.A,{}),path:"/store_manager/location-codes"},{text:"Pickup Addresses",icon:(0,ne.jsx)(qt.A,{}),path:"/store_manager/pickup-addresses"},{text:"Payment Settings",icon:(0,ne.jsx)(vn.A,{}),path:"/store_manager/payment-settings"}],Sn=()=>{const e=(0,qe.A)(),t=(0,Ke.A)(e.breakpoints.down("sm")),s=(0,d.Zp)(),r=(0,d.zy)(),{open:n,setOpen:i}=A.useContext(Cn),a=(0,ne.jsxs)(f.A,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",justifyContent:n&&!t?"space-between":"center",p:2,minHeight:64},children:[n&&!t&&(0,ne.jsx)(y.A,{variant:"h6",noWrap:!0,component:"div",children:"Store Manager"}),!t&&(0,ne.jsx)(be.A,{onClick:()=>{i(!n)},children:n?(0,ne.jsx)(bt.A,{}):(0,ne.jsx)(ur.A,{})})]}),(0,ne.jsx)(Ct.A,{}),(0,ne.jsx)(Bt.A,{children:In.map((e=>(0,ne.jsxs)(Mt.Ay,{button:!0,onClick:()=>{return t=e.path,void s(t);var t},selected:r.pathname===e.path,sx:{minHeight:48,justifyContent:n&&!t?"initial":"center",px:2.5,"&.Mui-selected":{backgroundColor:"primary.light","&:hover":{backgroundColor:"primary.light"}}},children:[(0,ne.jsx)(_t.A,{sx:{minWidth:0,mr:n&&!t?3:"auto",justifyContent:"center",color:r.pathname===e.path?"primary.main":"inherit"},children:e.icon}),(0,ne.jsx)(Vt.A,{primary:e.text,sx:{opacity:n&&!t?1:0}})]},e.text)))})]});return(0,ne.jsx)(f.A,{component:"nav",sx:{width:t?65:n?240:65,flexShrink:0,position:"fixed",top:{xs:"64px",sm:"70px"},bottom:0,left:0,zIndex:1e3},children:(0,ne.jsx)(Ht.Ay,{variant:"persistent",open:!0,sx:{"& .MuiDrawer-paper":{boxSizing:"border-box",width:t?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})})},Cn=(0,A.createContext)({open:!0,setOpen:()=>{}}),wn=e=>{let{children:t}=e;const s=(0,qe.A)(),[r,n]=((0,Ke.A)(s.breakpoints.down("sm")),(0,A.useState)(!0));return(0,ne.jsx)(Cn.Provider,{value:{open:r,setOpen:n},children:(0,ne.jsxs)(f.A,{sx:{display:"flex",minHeight:"100vh"},children:[(0,ne.jsx)(l.Ay,{}),(0,ne.jsx)(Qs,{}),(0,ne.jsx)(Sn,{}),(0,ne.jsx)(f.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:s.transitions.create(["width","margin"],{easing:s.transitions.easing.sharp,duration:s.transitions.duration.leavingScreen}),display:"flex",flexDirection:"column",alignItems:"center",maxWidth:"100%",overflow:"hidden"},children:(0,ne.jsx)(f.A,{sx:{width:"100%"},children:t})})]})})},Pn=()=>{const[e,t]=(0,A.useState)(""),{userProfile:s,setUserProfile:r}=te(),[n,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(null),[u,m]=(0,A.useState)(""),[h,p]=(0,A.useState)(""),[v,I]=(0,A.useState)(""),[C,w]=(0,A.useState)(""),[P,k]=(0,A.useState)(""),[E,L]=(0,A.useState)(""),[F,z]=(0,A.useState)(""),[T,R]=(0,A.useState)(""),[W,q]=(0,A.useState)(""),[O,U]=(0,A.useState)(!1),[N,B]=(0,A.useState)(10),[M,_]=(0,A.useState)(""),[V,H]=(0,A.useState)([]),[G,K]=(0,A.useState)(!1),[Y,X]=((0,A.useRef)(null),(0,A.useState)(0)),[Q,Z]=(0,A.useState)(10),[J,ee]=(0,A.useState)(!0),[se,re]=(0,A.useState)(null),[ie,oe]=(0,A.useState)({open:!1,message:"",severity:"success"}),[de,ce]=(0,A.useState)([]),[ue,he]=(0,A.useState)(!0),[pe,Ae]=(0,A.useState)([]),[ge,je]=(0,A.useState)(!1);(0,A.useEffect)((()=>{let e=!0;return(async()=>{try{const s=await(0,us.T)();e&&t(s.sub)}catch(e){}})(),()=>{e=!1}}),[]),(0,A.useEffect)((()=>{const e=setTimeout((()=>{ee(!1)}),1e3);return()=>clearTimeout(e)}),[]);const{data:fe,isLoading:ve}=(0,g.I)({queryKey:["getUserProfile",e],queryFn:async()=>{if(!e)return null;return await $(D,{userId:e})},enabled:!!e});(0,A.useEffect)((()=>{fe?.getUserProfile&&!s&&r(fe.getUserProfile)}),[fe,s,r]);const{data:Se,isLoading:we,error:Pe,refetch:ke}=(0,g.I)({queryKey:["storeWithInventory",s?.id],queryFn:async()=>s?.id?$("\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:s.id}):null,enabled:!!s?.id}),Fe=Se?.storesByManager?.[0]||null,De=Fe?.inventory?.edges?.map((e=>e.node))||[],ze=Se?.products||[],{data:Re,isLoading:We}=(0,g.I)({queryKey:["storeSquareStatus",Fe?.id],queryFn:()=>$("\n query StoreSquareStatus($storeId: Int!) {\n storeSquareStatus(storeId: $storeId) {\n storeId\n storeName\n isConnected\n }\n }\n",{storeId:Fe?.id}),enabled:!!Fe?.id}),qe=Re?.storeSquareStatus?.isConnected||!1;(0,A.useEffect)((()=>{if(ze.length)if(""===M.trim())H(ze);else{const e=ze.filter((e=>e.name.toLowerCase().includes(M.toLowerCase())));H(e)}}),[M,ze]);const Ue=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateStore(\n $storeId: Int!\n $name: String\n $address: String\n $email: String\n $mobile: String\n $radius: Float\n $isActive: Boolean\n $description: String\n $pincodes: [String!]\n $tnc: String\n $storeDeliveryFee: Float\n $taxPercentage: Float\n $displayField: String\n $sectionHeaders: [String!]\n $images: [String!]\n $whatsappNumber: String\n ) {\n updateStore(\n storeId: $storeId\n name: $name\n address: $address\n email: $email\n mobile: $mobile\n radius: $radius\n isActive: $isActive\n description: $description\n pincodes: $pincodes\n tnc: $tnc\n storeDeliveryFee: $storeDeliveryFee\n taxPercentage: $taxPercentage\n displayField: $displayField\n sectionHeaders: $sectionHeaders\n images: $images\n whatsappNumber: $whatsappNumber\n ) {\n id\n name\n address\n email\n mobile\n radius\n isActive\n description\n pincodes\n tnc\n storeDeliveryFee\n taxPercentage\n displayField\n sectionHeaders\n images\n whatsappNumber\n }\n }\n",e),onSuccess:()=>{oe({open:!0,message:"Store updated successfully",severity:"success"}),re(null),ke()},onError:e=>{oe({open:!0,message:"Failed to update store: "+e.message,severity:"error"})}}),Ne=()=>{re(null),ce([]),Ae([]),he(!0)};return ve||we||J||!Fe?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})})}):Pe?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4},children:(0,ne.jsxs)(xe.A,{severity:"error",children:["Error loading store data: ",Pe.message]})})}):Fe||J?(0,ne.jsx)(wn,{children:(0,ne.jsxs)(j.A,{sx:{mb:4},children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Store Manager Dashboard"}),(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[(0,ne.jsx)(y.A,{variant:"h5",children:"Store Information"}),(0,ne.jsx)(ae.A,{variant:"outlined",startIcon:(0,ne.jsx)(Ir.A,{}),onClick:()=>{Fe&&(re(Fe),ce(Fe.sectionHeaders||[]),Ae(Fe.images||[]),he(Fe.isActive))},sx:{textTransform:"none"},children:"Edit Store"})]}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Name:"})," ",Fe.name]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Address:"})," ",Fe.address]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Delivery Radius:"})," ",Fe.radius||"Not set"," ",Fe.radius?"mi":""]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Delivery Fee:"})," $",Fe.storeDeliveryFee?.toFixed(2)||"0.00"]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Tax Rate:"})," ",Fe.taxPercentage?.toFixed(1)||"0.0","%"]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Total Products:"})," ",De.filter((e=>e.isListed)).length]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Display Field:"})," ",Fe.displayField]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Square Payment:"})," ",(0,ne.jsx)(Oe.A,{size:"small",label:qe?"Connected":"Not Connected",color:qe?"success":"default"})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Cash on Delivery:"})," ",(0,ne.jsx)(Oe.A,{size:"small",label:Fe?.codEnabled?"Enabled":"Disabled",color:Fe?.codEnabled?"success":"default"})]})}),Fe.whatsappNumber&&(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"WhatsApp:"})," ",Fe.whatsappNumber]})}),Fe.description&&(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Description:"})," ",Fe.description]})}),Fe.pincodes&&Fe.pincodes.length>0&&(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:[(0,ne.jsx)("strong",{children:"Delivery Pincodes:"})," ",Fe.pincodes.join(", ")]})}),Fe.sectionHeaders&&Fe.sectionHeaders.length>0&&(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:(0,ne.jsx)("strong",{children:"Section Headers:"})}),(0,ne.jsx)(f.A,{sx:{pl:2},children:Fe.sectionHeaders.map(((e,t)=>(0,ne.jsxs)(y.A,{variant:"body2",sx:{mb:1},children:["• ",e]},t)))})]})]})]}),(0,ne.jsxs)(it.A,{open:!!se,onClose:Ne,maxWidth:"md",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(or.A,{}),(0,ne.jsx)(y.A,{variant:"h6",children:"Edit Store"})]})}),(0,ne.jsxs)("form",{onSubmit:e=>{if(e.preventDefault(),!se)return;const t=new FormData(e.target),s=t.get("pincodes"),r=s?s.split(",").map((e=>e.trim())).filter((e=>e.length>0)):[],n={storeId:se.id,name:t.get("name"),address:t.get("address"),email:t.get("email"),mobile:t.get("mobile")||null,radius:parseFloat(t.get("radius")),isActive:"true"===t.get("isActive"),description:t.get("description")||null,pincodes:r,tnc:t.get("tnc")||null,storeDeliveryFee:parseFloat(t.get("storeDeliveryFee"))||null,taxPercentage:parseFloat(t.get("taxPercentage"))||null,displayField:t.get("displayField"),sectionHeaders:de.filter((e=>e.trim().length>0)),images:pe,whatsappNumber:t.get("whatsappNumber")||null};Ue.mutate(n)},children:[(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600},children:"Basic Information"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"name",label:"Store Name",defaultValue:se?.name,required:!0,fullWidth:!0})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"email",label:"Email",type:"email",defaultValue:se?.email,required:!0,fullWidth:!0})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"mobile",label:"Mobile Number",defaultValue:se?.mobile,fullWidth:!0})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Location & Delivery"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"address",label:"Address",defaultValue:se?.address,required:!0,fullWidth:!0,multiline:!0,rows:2})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"radius",label:"Delivery Radius (mi)",type:"number",defaultValue:se?.radius,required:!0,fullWidth:!0,inputProps:{step:.1}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"storeDeliveryFee",label:"Delivery Fee ($)",type:"number",defaultValue:se?.storeDeliveryFee,fullWidth:!0,inputProps:{step:"0.01",min:0},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:"$"})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"taxPercentage",label:"Tax Rate (%)",type:"number",defaultValue:se?.taxPercentage,fullWidth:!0,inputProps:{step:"0.1",min:0},InputProps:{endAdornment:(0,ne.jsx)(ye.A,{position:"end",children:"%"})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"pincodes",label:"Delivery Pincodes",defaultValue:se?.pincodes?.join(", "),fullWidth:!0,helperText:"Enter pincodes separated by commas"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Additional Information"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"description",label:"Description",defaultValue:se?.description,fullWidth:!0,multiline:!0,rows:2,helperText:"Store timings and other details"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"tnc",label:"Terms & Conditions",defaultValue:se?.tnc,fullWidth:!0,multiline:!0,rows:3})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{name:"whatsappNumber",label:"WhatsApp Support Number",placeholder:"+1234567890",defaultValue:se?.whatsappNumber,fullWidth:!0,helperText:"Include country code. Optional."})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{name:"displayField",label:"Display Field",defaultValue:se?.displayField,required:!0,fullWidth:!0,helperText:"Unique identifier for the store"})}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Section Headers"}),(0,ne.jsxs)(f.A,{sx:{mb:2},children:[de.map(((e,t)=>(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:1,mb:1},children:[(0,ne.jsx)(le.A,{fullWidth:!0,label:`Question ${t+1}`,value:e,onChange:e=>((e,t)=>{ce((s=>{const r=[...s];return r[e]=t,r}))})(t,e.target.value),placeholder:"Enter question text",inputProps:{"aria-label":`Question ${t+1}`}}),(0,ne.jsx)(be.A,{color:"error",onClick:()=>(e=>{ce((t=>t.filter(((t,s)=>s!==e))))})(t),sx:{alignSelf:"center"},"aria-label":"Remove question",children:(0,ne.jsx)(Er.A,{})})]},t))),(0,ne.jsx)(ae.A,{startIcon:(0,ne.jsx)(Te.A,{}),onClick:()=>{ce((e=>[...e,""]))},variant:"outlined",sx:{mt:1},"aria-label":"Add question",children:"Add Question"})]})]}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Images / Offers Banner"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(f.A,{sx:{mb:2},children:[(0,ne.jsx)("input",{accept:"image/*",style:{display:"none"},id:"edit-store-image-upload",type:"file",onChange:e=>{const t=e.target.files[0];t&&(async e=>{if(e&&se?.id){je(!0);try{const t=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",s=await(0,S.$)(),r=s.tokens?.accessToken?.toString(),n={"Content-Type":"application/json"};r&&(n.Authorization=`Bearer ${r}`);const i=await fetch(`${t}/s3/generate-store-upload-url?store_id=${se.id}&file_name=${encodeURIComponent(e.name)}`,{method:"GET",headers:n});if(!i.ok){let e="Failed to get upload URL";try{const t=await i.json();e=t.detail||t.message||e}catch(t){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];Ae((e=>[...e,d])),oe({open:!0,message:"Image uploaded successfully!",severity:"success"})}catch(e){oe({open:!0,message:"Failed to upload image. Please try again.",severity:"error"})}finally{je(!1)}}})(t),e.target.value=""}}),(0,ne.jsx)("label",{htmlFor:"edit-store-image-upload",children:(0,ne.jsx)(ae.A,{variant:"outlined",component:"span",startIcon:ge?(0,ne.jsx)(b.A,{size:16}):(0,ne.jsx)(bn.A,{}),disabled:ge,sx:{mb:2},children:ge?"Uploading...":"Upload Image"})}),pe.length>0&&(0,ne.jsx)(f.A,{sx:{display:"flex",flexWrap:"wrap",gap:2},children:pe.map(((e,t)=>(0,ne.jsxs)(f.A,{sx:{position:"relative",width:150,height:150},children:[(0,ne.jsx)("img",{src:e,alt:`Store image ${t+1}`,style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:4}}),(0,ne.jsx)(be.A,{size:"small",color:"error",onClick:()=>(e=>{Ae((t=>t.filter(((t,s)=>s!==e))))})(t),sx:{position:"absolute",top:4,right:4,backgroundColor:"rgba(255, 255, 255, 0.8)"},children:(0,ne.jsx)(Er.A,{fontSize:"small"})})]},t)))})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(y.A,{variant:"subtitle1",color:"primary",sx:{mb:2,fontWeight:600,mt:2},children:"Store Status"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,children:[(0,ne.jsx)($e.A,{children:"Store Status"}),(0,ne.jsxs)(Le.A,{name:"isActive",label:"Store Status",value:ue,onChange:e=>{he(e.target.value)},children:[(0,ne.jsx)(Ie.A,{value:!0,children:"Active"}),(0,ne.jsx)(Ie.A,{value:!1,children:"Inactive"})]})]})})]})}),(0,ne.jsxs)(lt.A,{sx:{p:3,pt:0},children:[(0,ne.jsx)(ae.A,{onClick:Ne,children:"Cancel"}),(0,ne.jsx)(ae.A,{type:"submit",variant:"contained",disabled:Ue.isPending,startIcon:Ue.isPending?(0,ne.jsx)(b.A,{size:20}):null,children:Ue.isPending?"Updating...":"Update Store"})]})]})]}),(0,ne.jsx)(vr.A,{open:ie.open,autoHideDuration:6e3,onClose:()=>oe({...ie,open:!1}),children:(0,ne.jsx)(xe.A,{onClose:()=>oe({...ie,open:!1}),severity:ie.severity,sx:{width:"100%"},children:ie.message})})]})}):(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4},children:(0,ne.jsx)(xe.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})};var kn=s(79381),En=s(29682),$n=s(69149),Ln=s(51365);const Fn=()=>{const[,e]=(0,A.useReducer)((e=>e+1),0),[t,s]=(0,A.useState)(null),[r,n]=(0,A.useState)(!1),[i,a]=(0,A.useState)(null),[o,l]=(0,A.useState)(null),[d,c]=(0,A.useState)(""),[x,u]=(0,A.useState)(!1),[m,h]=(0,A.useState)(null),[p,v]=(0,A.useState)(null),[I,C]=(0,A.useState)({open:!1,title:"",message:"",onConfirm:null}),w=(0,qe.A)(),P=(0,Ke.A)(w.breakpoints.down("sm")),{userProfile:k,setUserProfile:E}=te();(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,S.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;s(t)}}catch(e){}})()}),[]);const{data:L,isLoading:F,error:z}=(0,g.I)({queryKey:["getUserProfile",t],queryFn:async()=>{const s=await $(D,{userId:t});return s?.getUserProfile&&(E(s.getUserProfile),setTimeout((()=>{e()}),200)),s},enabled:!!t,onError:e=>{}}),T=te.getState().userProfile||k||L?.getUserProfile,{data:W,isLoading:q,error:O,refetch:U}=(0,g.I)({queryKey:["userOrders",T?.id],queryFn:()=>$("\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 instructions\n allowSubstitute\n product {\n id\n name\n description\n category {\n id\n name\n }\n inventoryItems {\n edges {\n node {\n id\n price\n quantity\n measurement\n unit\n storeId\n productId\n }\n }\n }\n }\n }\n }\n }\n }\n }\n",{userId:T.id}),enabled:!!T?.id}),N=(0,Ft.n)({mutationFn:e=>$(R,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:T.id}),onSuccess:()=>{U(),M(),c("")}}),B=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateOrderItems(\n $orderId: Int!\n $orderItemUpdates: [OrderItemUpdateInput!]!\n $totalAmount: Float!\n $orderTotalAmount: Float!\n $taxAmount: Float\n ) {\n updateOrderItems(\n orderId: $orderId\n orderItemUpdates: $orderItemUpdates\n totalAmount: $totalAmount\n orderTotalAmount: $orderTotalAmount\n taxAmount: $taxAmount\n ) {\n id\n totalAmount\n orderTotalAmount\n taxAmount\n orderItems {\n edges {\n node {\n id\n quantity\n orderAmount\n product {\n id\n name\n category {\n name\n }\n inventoryItems {\n edges {\n node {\n price\n measurement\n unit\n }\n }\n }\n }\n }\n }\n }\n }\n }\n",{orderId:e.orderId,orderItemUpdates:e.orderItemUpdates,totalAmount:e.totalAmount,orderTotalAmount:e.orderTotalAmount,taxAmount:e.taxAmount}),onSuccess:()=>{U()}}),M=()=>{n(!1),a(null)},_=e=>{l(o===e?null:e)},V=(e,t,s)=>{if(!t||!t.id)return;const r=s-t.quantity,n=(t.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(t.id,10),quantityChange:r}],totalAmount:i,orderTotalAmount:o,taxAmount:a};B.mutate(l)},H=e=>{if(!e?.edges?.length)return null;const t=new Map;e.edges.forEach((e=>{let{node:s}=e;t.set(s.id,s)}));return e.edges.map((e=>{let{node:t}=e;return t})).filter((e=>null===e.updatedOrderitemsId))},G=()=>{h(null),v(null)},K=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e);if(F||q&&T?.id)return(0,ne.jsx)(b.A,{sx:{display:"block",mx:"auto",mt:4}});if(z)return(0,ne.jsx)(y.A,{color:"error",children:"Error fetching user profile!"});if(O&&T?.id)return(0,ne.jsx)(y.A,{color:"error",children:"Error fetching orders!"});const Y=[...W?.getOrdersByUser||[]].sort(((e,t)=>t.id-e.id));return(0,ne.jsxs)(j.A,{maxWidth:"xl",sx:{mt:4,px:{xs:1,sm:2,md:3}},children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,sx:{fontSize:{xs:"1.5rem",sm:"2rem",md:"2.125rem"},mb:{xs:2,sm:3}},children:"My Orders"}),0===Y.length?(0,ne.jsx)(y.A,{children:"No orders found!"}):(0,ne.jsx)(Ar.A,{component:me.A,sx:{mt:2,overflowX:"auto","& .MuiTableCell-root":{px:{xs:1,sm:2},py:{xs:1.5,sm:2},whiteSpace:"nowrap"}},children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{sx:{display:{xs:"none",md:"table-cell"}},children:"Order ID"}),(0,ne.jsx)(fr.A,{children:"Address"}),(0,ne.jsx)(fr.A,{children:"Status"}),(0,ne.jsx)(fr.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Total"}),(0,ne.jsx)(fr.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:"Delivery Date"}),(0,ne.jsx)(fr.A,{children:"Bill"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:Y.map((e=>(0,ne.jsxs)(A.Fragment,{children:[(0,ne.jsxs)(jr.A,{onClick:()=>_(e.id),sx:{cursor:"pointer"},children:[(0,ne.jsx)(fr.A,{sx:{display:{xs:"none",md:"table-cell"}},children:e.id}),(0,ne.jsxs)(fr.A,{children:[P&&(0,ne.jsxs)(y.A,{variant:"caption",sx:{fontWeight:700,color:"primary.main",display:"block",mb:.5},children:["Order #",e.id]}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"PICKUP"===e.type?(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Xt.A,{fontSize:"small"}),e.pickupAddress?.address||"Pickup location not specified"]}):(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(qt.A,{fontSize:"small"}),e.address?.address||"No address provided"]})})]}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:_r.find((t=>t.value===e.status))?.label||e.status,size:P?"small":"medium",color:_r.find((t=>t.value===e.status))?.color||"default"})}),(0,ne.jsxs)(fr.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:["$",e.totalAmount.toFixed(2)]}),(0,ne.jsx)(fr.A,{sx:{display:{xs:"none",sm:"table-cell"}},children:e.deliveryDate?new Date(e.deliveryDate).toLocaleDateString():"N/A"}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(f.A,{sx:{display:"flex",gap:1},children:(0,ne.jsx)(De.A,{title:"Download Bill",children:(0,ne.jsx)(be.A,{size:"small",onClick:t=>{t.stopPropagation(),(async e=>{if(!x)try{u(!0);const t=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com",s=await fetch(`${t}/s3/generate-view-url?order_id=${e}&file_name=order_${e}.jpeg`);if(200===s.status){const e=await s.json();if(e?.view_url){const t=document.createElement("a");return t.href=e.view_url,t.download=e.file_name,t.target="_blank",document.body.appendChild(t),t.click(),void document.body.removeChild(t)}}alert("No bill available for this order")}catch(e){alert("Error downloading the bill. Please try again.")}finally{u(!1)}})(e.id)},children:(0,ne.jsx)(kn.A,{})})})})}),(0,ne.jsx)(fr.A,{children:(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:1,alignItems:"center"},children:[(0,ne.jsx)(ae.A,{variant:"contained",color:"error",size:P?"small":"medium",onClick:t=>{var s;t.stopPropagation(),s=e.id,a(s),n(!0)},disabled:!K(e.status),children:"Cancel"}),(0,ne.jsx)(be.A,{onClick:t=>{t.stopPropagation(),_(e.id)},size:"small",children:o===e.id?(0,ne.jsx)(En.A,{}):(0,ne.jsx)(Kt.A,{})})]})})]}),(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{style:{paddingBottom:0,paddingTop:0},colSpan:7,children:(0,ne.jsx)(Ye.A,{in:o===e.id,timeout:"auto",unmountOnExit:!0,children:(0,ne.jsx)(f.A,{sx:{margin:{xs:1,sm:2}},children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsxs)(y.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,ne.jsx)(Xt.A,{})," Order Items"]}),(0,ne.jsx)(me.A,{sx:{p:{xs:1.5,sm:2}},children:e.orderItems?.edges?.length>0?(0,ne.jsx)(Ce.Ay,{container:!0,spacing:{xs:1,sm:2},children:H(e.orderItems).map((t=>{const s=t.product.inventoryItems?.edges[0]?.node,r=((e,t)=>{const s=new Map;t.forEach((e=>{let{node:t}=e;s.set(t.id,t)}));const r=[e];let n=e.id;for(;;){const e=Array.from(s.values()).find((e=>e.updatedOrderitemsId===n));if(!e)break;r.push(e),n=e.id}return r.reverse()})(t,e.orderItems.edges);return(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(we.A,{variant:"outlined",sx:{p:{xs:1.5,sm:2},"&:hover":{bgcolor:"grey.50"}},children:[(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:{xs:1,sm:2},alignItems:"center",children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,sm:4,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",fontWeight:600,sx:{fontSize:{xs:"0.875rem",sm:"1rem"}},children:t.product.name}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",fontWeight:500,children:t.product.category.name}),r.length>1&&(0,ne.jsxs)(y.A,{variant:"caption",color:"primary",sx:{display:"block",mt:.5},children:[r.length-1," previous version",r.length>2?"s":""]})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:6,sm:2,children:[(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Unit Price"}),(0,ne.jsxs)(y.A,{variant:"body1",fontWeight:500,children:["$",s?.price.toFixed(2)]}),s&&(0,ne.jsxs)(y.A,{variant:"caption",color:"text.secondary",fontWeight:500,children:[s.measurement," ",s.unit]})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:6,sm:2,children:[(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Quantity"}),m===t.id?(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(le.A,{type:"number",size:"small",value:p,onChange:e=>v(parseInt(e.target.value)||0),inputProps:{min:0},sx:{width:"80px"}}),(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:.5},children:[(0,ne.jsx)(be.A,{size:"small",color:"primary",onClick:()=>((e,t)=>{0===p?C({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{V(e,t,0),h(null),v(null),C({open:!1,title:"",message:"",onConfirm:null})}}):p>0&&(V(e,t,p),h(null),v(null))})(e,t),disabled:null===p||p<0,children:(0,ne.jsx)($n.A,{fontSize:"small"})}),(0,ne.jsx)(be.A,{size:"small",color:"error",onClick:G,children:(0,ne.jsx)(Pt.A,{fontSize:"small"})})]})]}):(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(y.A,{variant:"body1",fontWeight:500,children:t.quantity}),K(e.status)&&(0,ne.jsx)(be.A,{size:"small",onClick:()=>{return h((e=t).id),void v(e.quantity);var e},children:(0,ne.jsx)(Ir.A,{fontSize:"small"})})]})]}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:4,children:(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:{xs:"flex-start",sm:"flex-end"},alignItems:"center",gap:1,mt:{xs:1,sm:0}},children:[(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",fontWeight:600,children:"Total:"}),(0,ne.jsxs)(y.A,{variant:"h6",color:"primary",fontWeight:700,sx:{fontSize:{xs:"1rem",sm:"1.25rem"}},children:["$",(t.quantity*(t.product.inventoryItems?.edges[0]?.node?.price||0)).toFixed(2)]}),K(e.status)&&(0,ne.jsx)(be.A,{size:"small",color:"error",onClick:s=>{s.stopPropagation(),((e,t)=>{C({open:!0,title:"Remove Item",message:"Are you sure you want to remove this item from the order?",onConfirm:()=>{V(e,t,0),C({open:!1,title:"",message:"",onConfirm:null})}})})(e,t)},children:(0,ne.jsx)(Er.A,{fontSize:"small"})})]})})]}),(t.instructions||null!==t.allowSubstitute)&&(0,ne.jsxs)(f.A,{sx:{mt:1.5,pt:1.5,borderTop:"1px dashed",borderColor:"divider",display:"flex",flexDirection:"column",gap:.5},children:[t.instructions&&(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:"text.secondary",fontStyle:"italic"},children:[(0,ne.jsx)("strong",{children:"Instructions:"})," ",t.instructions]}),(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:"text.secondary"},children:[(0,ne.jsx)("strong",{children:"If unavailable:"})," ",t.allowSubstitute?"Replace with a similar item":"Cancel this item"]})]}),r.length>1&&(0,ne.jsxs)(f.A,{sx:{mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[(0,ne.jsxs)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Ln.A,{fontSize:"small"}),"Order Change History (",r.length-1," ","changes)"]}),(0,ne.jsx)(f.A,{sx:{pl:2},children:r.slice(0,-1).map(((e,t)=>(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1.5,borderRadius:1,mb:1},children:[(0,ne.jsxs)(y.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"120px",fontWeight:500},children:["Change ",t+1]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:3},children:[(0,ne.jsxs)(y.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,ne.jsxs)(y.A,{variant:"body2",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount: $",e.orderAmount.toFixed(2)]})]})]},e.id)))})]})]})},t.id)}))}):(0,ne.jsx)(f.A,{sx:{textAlign:"center",py:3,color:"text.secondary"},children:(0,ne.jsx)(y.A,{fontWeight:500,children:"No items found for this order."})})})]}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(me.A,{sx:{p:{xs:1.5,sm:2},mb:3},children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:{xs:2,sm:3},children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,md:6,children:[(0,ne.jsxs)(y.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,ne.jsx)(kn.A,{})," Order Details"]}),(0,ne.jsxs)(f.A,{sx:{pl:1},children:[e.customOrder&&(0,ne.jsxs)(f.A,{sx:{mb:2},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Custom Order Instructions"}),(0,ne.jsx)(y.A,{variant:"body2",fontWeight:500,sx:{whiteSpace:"pre-line",bgcolor:"grey.50",p:1.5,borderRadius:1,mt:.5},children:e.customOrder})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Subtotal"}),(0,ne.jsxs)(y.A,{fontWeight:500,children:["$",e.totalAmount?e.totalAmount.toFixed(2):"0.00"]})]}),void 0!==e.deliveryFee&&(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Fee"}),(0,ne.jsxs)(y.A,{fontWeight:500,children:["$",e.deliveryFee?e.deliveryFee.toFixed(2):"0.00"]})]}),void 0!==e.taxAmount&&(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tax"}),(0,ne.jsxs)(y.A,{fontWeight:500,children:["$",e.taxAmount?e.taxAmount.toFixed(2):"0.00"]})]}),void 0!==e.tipAmount&&(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Tip"}),(0,ne.jsxs)(y.A,{fontWeight:500,children:["$",e.tipAmount?e.tipAmount.toFixed(2):"0.00"]})]}),(0,ne.jsx)(Ct.A,{sx:{my:1}}),(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Total Amount"}),(0,ne.jsxs)(y.A,{variant:"subtitle1",color:"primary",fontWeight:700,children:["$",e.orderTotalAmount?e.orderTotalAmount.toFixed(2):"0.00"]})]})]})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,md:6,children:[(0,ne.jsxs)(y.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,ne.jsx)(qt.A,{})," Delivery Information"]}),(0,ne.jsxs)(f.A,{sx:{pl:1},children:[(0,ne.jsxs)(f.A,{sx:{mb:1},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"PICKUP"===e.type?"Pickup Location":"Delivery Address"}),(0,ne.jsx)(y.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,ne.jsxs)(f.A,{sx:{mb:1},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:700,children:"Delivery Instructions"}),(0,ne.jsx)(y.A,{variant:"body2",fontWeight:500,children:e.deliveryInstructions})]}),e.deliveryDate&&(0,ne.jsxs)(f.A,{sx:{mb:1},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"text.secondary",fontWeight:600,children:"Expected Delivery Date"}),(0,ne.jsx)(y.A,{variant:"body2",fontWeight:500,children:new Date(e.deliveryDate).toLocaleDateString()})]}),e.cancelMessage&&(0,ne.jsxs)(f.A,{sx:{mb:1},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"error",fontWeight:700,children:"Cancellation Reason"}),(0,ne.jsx)(y.A,{variant:"body2",color:"error",fontWeight:500,children:e.cancelMessage})]})]})]})]})})})]})})})})})]},e.id)))})]})}),(0,ne.jsxs)(it.A,{open:r,onClose:M,fullWidth:!0,maxWidth:"sm",children:[(0,ne.jsx)(at.A,{children:"Cancel Order"}),(0,ne.jsxs)(ot.A,{children:[(0,ne.jsx)(Hr.A,{gutterBottom:!0,children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,ne.jsx)(le.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,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:M,color:"primary",children:"No, Keep Order"}),(0,ne.jsx)(ae.A,{onClick:()=>{i&&d.trim()&&N.mutate({orderId:i,cancelMessage:d.trim()})},color:"error",variant:"contained",disabled:!d.trim()||N.isPending,startIcon:N.isPending?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:N.isPending?"Cancelling...":"Yes, Cancel Order"})]})]}),(0,ne.jsxs)(it.A,{open:I.open,onClose:()=>C({open:!1,title:"",message:"",onConfirm:null}),children:[(0,ne.jsx)(at.A,{children:I.title}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(Hr.A,{children:I.message})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>C({open:!1,title:"",message:"",onConfirm:null}),color:"primary",children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:I.onConfirm,color:"error",variant:"contained",children:"Remove"})]})]})]})};var Dn=s(81385),zn=s(37211),Tn=s(55629),Rn=s(45402),Wn=s(55764);const qn=()=>{const{userProfile:e,setUserProfile:t,fetchUserProfile:s,isProfileLoading:r,profileError:n}=te(),i=(0,d.Zp)(),[a,o]=(0,A.useState)(0),[l,x]=(0,A.useState)(null),[u,m]=(0,A.useState)(null),[h,p]=(0,A.useState)(!1),g=window.location.origin,{addresses:v,selectedAddressId:I,setSelectedAddressId:C,fetchAddresses:w,isLoading:P,createAddress:k,updateAddress:E,deleteAddress:$}=se(),[L,F]=(0,A.useState)(!1),[D,z]=(0,A.useState)(null),[T,R]=(0,A.useState)(""),[W,q]=(0,A.useState)(!1),[O,U]=(0,A.useState)(!1),[N,B]=(0,A.useState)(!1),[M,_]=(0,A.useState)({open:!1,message:"",severity:"success"}),[V,H]=(0,A.useState)(!1),[G,K]=(0,A.useState)(null);(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,S.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;m(t),await s(t)}}catch(e){}})()}),[s]);const Y=e||l;(0,A.useEffect)((()=>{Y?.id&&w(Y.id)}),[Y?.id,w]);const X=async()=>{try{await(0,Qt.C)(),i("/")}catch(e){}},Q=`${g}/signup?referredby=${e?.referralId}`,Z=async()=>{try{await navigator.clipboard.writeText(Q),p(!0),setTimeout((()=>p(!1)),2e3)}catch(e){}};if(r)return(0,ne.jsx)(j.A,{children:(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"50vh"},children:[(0,ne.jsx)(b.A,{}),(0,ne.jsx)(y.A,{sx:{ml:2},children:"Loading profile..."})]})});if(n)return(0,ne.jsxs)(j.A,{children:[(0,ne.jsxs)(xe.A,{severity:"error",sx:{mt:4},children:["Error loading profile: ",n]}),(0,ne.jsx)(ae.A,{variant:"contained",onClick:()=>s(),sx:{mt:2},children:"Retry"})]});if(!e)return(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(xe.A,{severity:"warning",sx:{mt:4},children:"No profile data available. Please try again."}),(0,ne.jsx)(ae.A,{variant:"contained",onClick:async()=>{try{const e=await(0,S.$)();if(e?.tokens?.idToken){const t=e.tokens.idToken.payload.sub;await s(t)}}catch(e){}},sx:{mt:2},children:"Load Profile"})]});return(0,ne.jsxs)(j.A,{maxWidth:"xl",sx:{py:{xs:1,sm:4},px:{xs:.5,sm:2}},children:[(0,ne.jsxs)(f.A,{sx:{display:{xs:"block",md:"flex"},gap:{xs:0,md:3}},children:[(0,ne.jsxs)(f.A,{sx:{width:{xs:"100%",md:280},mb:{xs:2,md:0}},children:[(0,ne.jsxs)(me.A,{elevation:0,sx:{borderRadius:2,overflow:"hidden",boxShadow:1,mb:0,display:{xs:"none",md:"block"}},children:[(0,ne.jsx)(f.A,{sx:{p:2,bgcolor:"primary.main",color:"white",textAlign:"left"},children:(0,ne.jsx)(y.A,{variant:"h6",sx:{fontSize:"1.25rem"},children:"My Account"})}),(0,ne.jsx)(Bt.A,{component:"nav",sx:{pt:0},children:[{label:"Profile",icon:(0,ne.jsx)(Yt.A,{}),idx:0},{label:"Addresses",icon:(0,ne.jsx)(jt.A,{}),idx:1},{label:"Settings",icon:(0,ne.jsx)(Wn.A,{}),idx:2}].map((e=>(0,ne.jsxs)(zn.A,{selected:a===e.idx,onClick:()=>o(e.idx),sx:{borderRadius:0,"&.Mui-selected":{bgcolor:e=>(0,c.X4)(e.palette.info.main,.08),borderLeft:"4px solid",borderColor:"primary.main"}},children:[(0,ne.jsx)(_t.A,{sx:{minWidth:0,mr:2,justifyContent:"center"},children:A.cloneElement(e.icon,{color:a===e.idx?"primary":"inherit"})}),(0,ne.jsx)(Vt.A,{primary:e.label})]},e.label)))})]}),(0,ne.jsxs)(me.A,{elevation:0,sx:{borderRadius:0,overflow:"hidden",boxShadow:0,mb:1,display:{xs:"block",md:"none"}},children:[(0,ne.jsx)(f.A,{sx:{p:2,bgcolor:"primary.main",color:"white",textAlign:"center"},children:(0,ne.jsx)(y.A,{variant:"h6",sx:{fontSize:"1.1rem"},children:"My Account"})}),(0,ne.jsx)(Bt.A,{component:"nav",sx:{pt:0,display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center"},children:[{label:"Profile",icon:Yt.A,idx:0},{label:"Addresses",icon:jt.A,idx:1},{label:"Settings",icon:Wn.A,idx:2}].map((e=>(0,ne.jsx)(zn.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,ne.jsx)(_t.A,{sx:{minWidth:0,mr:0,justifyContent:"center"},children:(0,ne.jsx)(e.icon,{sx:{fontSize:28,color:a===e.idx?"primary.main":"text.secondary"}})})},e.label)))})]})]}),(0,ne.jsx)(f.A,{sx:{flexGrow:1,width:{xs:"100%",md:"auto"}},children:(0,ne.jsxs)(f.A,{sx:{height:"100%"},children:[0===a&&(0,ne.jsx)(f.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,ne.jsx)(we.A,{sx:{height:"100%",width:{xs:"100%",sm:"auto"},p:{xs:1,sm:0},boxShadow:{xs:2,sm:1}},children:(0,ne.jsxs)(ke.A,{sx:{p:{xs:1,sm:2}},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"center",sm:"center"},mb:3,gap:{xs:2,sm:0}},children:[(0,ne.jsx)(Dn.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,ne.jsxs)(f.A,{sx:{textAlign:{xs:"center",sm:"left"},width:"100%"},children:[(0,ne.jsxs)(y.A,{variant:"h5",gutterBottom:!0,sx:{fontSize:{xs:"1.25rem",sm:"1.5rem"},fontWeight:700},children:[e?.firstName," ",e?.lastName]}),(0,ne.jsxs)(St.A,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",flexWrap:"wrap",sx:{rowGap:1,justifyContent:{xs:"center",sm:"flex-start"}},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",bgcolor:e=>e.palette.custom.primarySoft,px:1.5,py:.5,borderRadius:2,mb:{xs:1,sm:0},justifyContent:"center"},children:[(0,ne.jsx)(Fr.A,{sx:{mr:1,color:"primary.main",fontSize:22}}),(0,ne.jsx)(y.A,{sx:{color:"text.primary",fontWeight:600,fontSize:{xs:"1.12rem",sm:"1.1rem"},wordBreak:"break-all"},children:e?.email})]}),e?.mobile&&(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",bgcolor:e=>(0,c.X4)(e.palette.secondary.main,.08),px:1.5,py:.5,borderRadius:2,justifyContent:"center"},children:[(0,ne.jsx)(Lr.A,{sx:{mr:1,color:"secondary.main",fontSize:22}}),(0,ne.jsx)(y.A,{sx:{color:"text.primary",fontWeight:500,fontSize:{xs:"1.1rem",sm:"1.08rem"}},children:e.mobile})]})]})]})]}),(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,sx:{textAlign:{xs:"center",sm:"left"},fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:"Referral Program"}),(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"stretch",sm:"center"},gap:2},children:[(0,ne.jsx)(le.A,{fullWidth:!0,value:Q,InputProps:{readOnly:!0,endAdornment:(0,ne.jsx)(De.A,{title:h?"Copied!":"Copy referral link",children:(0,ne.jsx)(be.A,{onClick:Z,children:(0,ne.jsx)(Tn.A,{})})})},sx:{mb:{xs:1,sm:0}}}),(0,ne.jsx)(ae.A,{variant:"contained",startIcon:(0,ne.jsx)(Rn.A,{}),onClick:Z,sx:{width:{xs:"100%",sm:"auto"},py:1},children:"Share"})]})]})})}),1===a&&(0,ne.jsx)(f.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,t)=>(t.isPrimary?1:0)-(e.isPrimary?1:0)));return(0,ne.jsx)(we.A,{sx:{height:"100%"},children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.A,{variant:"h6",children:"My Addresses"}),(0,ne.jsx)(ae.A,{variant:"contained",startIcon:(0,ne.jsx)(Te.A,{}),onClick:()=>F(!0),children:"Add Address"})]}),P?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",p:4},children:(0,ne.jsx)(b.A,{})}):e.length>0?(0,ne.jsx)(Ce.Ay,{container:!0,spacing:2,children:e.map((e=>(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:6,children:(0,ne.jsxs)(me.A,{elevation:2,sx:{p:2,position:"relative",border:e.isPrimary?"2px solid":"1px solid",borderColor:e.isPrimary?"primary.main":"divider"},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",color:"primary",children:e.isPrimary?"Primary Address":"Secondary Address"}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(be.A,{size:"small",onClick:()=>(e=>{z(e),R(e.address),q(e.isPrimary),F(!0)})(e),children:(0,ne.jsx)(Ir.A,{fontSize:"small"})}),(0,ne.jsx)(be.A,{size:"small",onClick:()=>{return t=e.id,K(t),void H(!0);var t},children:(0,ne.jsx)(Er.A,{fontSize:"small"})})]})]}),(0,ne.jsx)(y.A,{variant:"body2",children:e.address})]})},e.id)))}):(0,ne.jsx)(xe.A,{severity:"info",sx:{mt:2},children:"You don't have any addresses yet. Add one to get started!"})]})})})()}),2===a&&(0,ne.jsx)(f.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,ne.jsx)(we.A,{sx:{height:"100%"},children:(0,ne.jsxs)(ke.A,{children:[(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:"Account Settings"}),(0,ne.jsxs)(St.A,{spacing:3,children:[(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Notification Preferences"}),(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(yn.A,{defaultChecked:!0}),label:"Email notifications for orders"}),(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(yn.A,{defaultChecked:!0}),label:"SMS notifications for delivery updates"})]}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,children:"Privacy Settings"}),(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(yn.A,{defaultChecked:!0}),label:"Share order history with delivery partners"})]}),(0,ne.jsx)(f.A,{children:(0,ne.jsx)(ae.A,{variant:"outlined",color:"error",startIcon:(0,ne.jsx)(mr.A,{}),onClick:X,sx:{mt:2},children:"Logout"})})]})]})})})]})})]}),(0,ne.jsxs)(it.A,{open:L,onClose:()=>F(!1),fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:D?"Edit Address":"Add Address"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(St.A,{spacing:2,mt:1,children:[(0,ne.jsx)(Vs,{value:T,onChange:R,onValidAddress:B}),(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(yn.A,{checked:W,onChange:e=>q(e.target.checked)}),label:"Set as Primary Address"})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{F(!1),R(""),B(!1)},children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:async()=>{if(Y?.id){U(!0);try{if(!N)return;if(D)if(W){for(const e of v)e.id!==D.id&&e.isPrimary&&await E(e.id,e.address,!1);await E(D.id,T,!0),_({open:!0,message:"Address updated as primary",severity:"success"})}else{D.isPrimary&&1===v.filter((e=>e.isPrimary)).length?(await E(D.id,T,!0),_({open:!0,message:"At least one address must be primary",severity:"warning"})):(await E(D.id,T,!1),_({open:!0,message:"Address updated as secondary",severity:"success"}))}else if(0===v.length)await k(T,Y.id,!0),_({open:!0,message:"Address added successfully",severity:"success"});else if(W){for(const e of v)e.isPrimary&&await E(e.id,e.address,!1);await k(T,Y.id,!0),_({open:!0,message:"Address added as primary",severity:"success"})}else await k(T,Y.id,!1),_({open:!0,message:"Address added as secondary",severity:"success"});await w(Y.id),F(!1),z(null),R(""),q(!1),B(!1)}catch(e){_({open:!0,message:"Failed to save address. Please try again.",severity:"error"})}finally{U(!1)}}else _({open:!0,message:"Could not save address: user information not available",severity:"error"})},variant:"contained",disabled:!T||O||!N,children:O?(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(b.A,{size:20,sx:{mr:1}})," Saving..."]}):"Save"})]})]}),(0,ne.jsxs)(it.A,{open:V,onClose:()=>H(!1),children:[(0,ne.jsx)(at.A,{children:"Delete Address"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this address? This action cannot be undone."})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>H(!1),disabled:P,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:async()=>{try{await $(G),_({open:!0,message:"Address deleted successfully",severity:"success"})}catch(e){_({open:!0,message:"Failed to delete address. Please try again.",severity:"error"})}finally{H(!1),K(null)}},color:"error",variant:"contained",disabled:P,startIcon:P?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:P?"Deleting...":"Delete"})]})]}),(0,ne.jsx)(vr.A,{open:M.open,autoHideDuration:3e3,onClose:()=>_({...M,open:!1}),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:(0,ne.jsx)(xe.A,{onClose:()=>_({...M,open:!1}),severity:M.severity,sx:{width:"100%"},children:M.message})})]})},On=()=>{const e=(0,d.Zp)();return(0,ne.jsx)(j.A,{maxWidth:"md",children:(0,ne.jsx)(f.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,ne.jsxs)(me.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,ne.jsx)(y.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,ne.jsx)(y.A,{variant:"body1",color:"text.secondary",paragraph:!0,children:"The page you are looking for does not exist or is not available."}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(rs),children:"Go to Dashboard"})]})})})},Un=()=>{const e=(0,d.Zp)();return(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{maxWidth:"md",children:(0,ne.jsx)(f.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"80vh",textAlign:"center"},children:(0,ne.jsxs)(me.A,{elevation:3,sx:{p:5,borderRadius:2,maxWidth:600,width:"100%"},children:[(0,ne.jsx)(y.A,{variant:"h1",color:"primary",gutterBottom:!0,children:"404"}),(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Page Not Found"}),(0,ne.jsx)(y.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,ne.jsx)(ae.A,{variant:"contained",color:"primary",size:"large",onClick:()=>e(rs),children:"Go to Dashboard"})]})})})})},Nn=e=>{let{open:t,onClose:s,selectedFee:r,onUpdate:n,isLoading:i}=e;const a={feeCurrency:"",feeRate:"",limit:"",type:"DELIVERY"},[o,l]=(0,A.useState)(a);(0,A.useEffect)((()=>{r?l({feeCurrency:r.feeCurrency||"",feeRate:r.feeRate?.toString()||"",limit:r.limit?.toString()||"",type:r.type?.toUpperCase()||"DELIVERY"}):t&&l(a)}),[r,t]),(0,A.useEffect)((()=>{t||l(a)}),[t]);const d=e=>{const{name:t,value:s}=e.target;l((e=>({...e,[t]:s})))};return(0,ne.jsxs)(it.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:r?"Edit Fee":"Add New Fee"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(f.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ne.jsxs)(Ee.A,{fullWidth:!0,children:[(0,ne.jsx)($e.A,{children:"Fee Type"}),(0,ne.jsxs)(Le.A,{name:"type",value:o.type,onChange:d,label:"Fee Type",children:[(0,ne.jsx)(Ie.A,{value:"DELIVERY",children:"Delivery Fee"}),(0,ne.jsx)(Ie.A,{value:"PICKUP",children:"Pickup Fee"})]})]}),(0,ne.jsx)(le.A,{name:"feeCurrency",label:"Currency",value:o.feeCurrency,onChange:d,fullWidth:!0,placeholder:"e.g., USD"}),(0,ne.jsx)(le.A,{name:"feeRate",label:"Fee Rate",type:"number",value:o.feeRate,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}}),(0,ne.jsx)(le.A,{name:"limit",label:"Limit",type:"number",value:o.limit,onChange:d,fullWidth:!0,inputProps:{step:"0.01",min:"0"}})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:s,children:"Cancel"}),(0,ne.jsx)(ae.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,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},Bn=()=>{const[e,t]=(0,A.useState)(""),{userProfile:s,setUserProfile:r}=te(),[n,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(""),[u,m]=(0,A.useState)("");(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,us.T)();t(e.sub)}catch(e){}})()}),[]);const{data:h,isLoading:p}=(0,g.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const t=await $("\n query GetUserProfile($userId: String!) {\n getUserProfile(userId: $userId) {\n id\n email\n mobile\n active\n type\n referralId\n }\n }\n",{userId:e});return t?.getUserProfile&&r(t.getUserProfile),t},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,g.I)({queryKey:["storeWithFees",s?.id],queryFn:()=>$("\n query GetStoreWithFees($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:s.id}),enabled:!!s?.id}),C=v?.storesByManager?.[0],{data:w,isLoading:P,error:k,refetch:E}=(0,g.I)({queryKey:["getFeesByStore",C?.id],queryFn:()=>$("\n query GetFeesByStore($storeId: Int!) {\n getFeesByStore(storeId: $storeId) {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n }\n",{storeId:C?.id}),enabled:!!C?.id}),L=w?.getFeesByStore||[],F=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateFee($input: UpdateFeeInput!) {\n updateFee(input: $input) {\n fee {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:()=>{E(),o(!1),i(null),m("Fee updated successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error updating fee: ${e.message}`)}}),D=(0,Ft.n)({mutationFn:e=>$("\n mutation DeleteFee($id: Int!) {\n deleteFee(id: $id)\n }\n",e),onSuccess:()=>{E(),d(!1),i(null),m("Fee deleted successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error deleting fee: ${e.message}`)}}),z=(0,Ft.n)({mutationFn:e=>$("\n mutation CreateFee($input: CreateFeeInput!) {\n createFee(input: $input) {\n fee {\n id\n feeCurrency\n feeRate\n limit\n storeId\n type\n }\n error {\n message\n }\n }\n }\n",{input:{...e,storeId:C?.id}}),onSuccess:()=>{E(),o(!1),i(null),m("Fee added successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error adding fee: ${e.message}`)}});return p||I||P?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})})}):S||k?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4},children:(0,ne.jsxs)(xe.A,{severity:"error",children:["Error loading data: ",S?.message||k?.message]})})}):(0,ne.jsx)(wn,{children:(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Delivery Fees Management"}),u&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:u}),c&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:c}),(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.A,{variant:"h5",children:"Fees"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:z.isPending||z.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):(0,ne.jsx)(Te.A,{}),onClick:()=>{i(null),o(!0)},disabled:z.isPending||z.isLoading,children:z.isPending||z.isLoading?"Adding...":"Add Fee"})]}),(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Type"}),(0,ne.jsx)(fr.A,{children:"Currency"}),(0,ne.jsx)(fr.A,{children:"Rate"}),(0,ne.jsx)(fr.A,{children:"Limit"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:L.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.type}),(0,ne.jsx)(fr.A,{children:e.feeCurrency}),(0,ne.jsx)(fr.A,{children:e.feeRate}),(0,ne.jsx)(fr.A,{children:e.limit}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:F.isPending||F.isLoading||D.isPending||D.isLoading||z.isPending||z.isLoading,children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:F.isPending||F.isLoading||D.isPending||D.isLoading||z.isPending||z.isLoading,children:(0,ne.jsx)(Er.A,{})})]})]},e.id)))})]})})]}),(0,ne.jsx)(Nn,{open:a,onClose:()=>{o(!1),i(null),x("")},selectedFee:n,onUpdate:e=>{n?F.mutate(e):z.mutate(e)},isLoading:F.isPending||F.isLoading||z.isPending||z.isLoading}),(0,ne.jsxs)(it.A,{open:l,onClose:()=>{d(!1),i(null),x("")},children:[(0,ne.jsx)(at.A,{children:"Delete Fee"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this fee? This action cannot be undone."})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{d(!1),i(null)},disabled:D.isPending||D.isLoading,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"error",onClick:()=>D.mutate({id:n.id}),disabled:D.isPending||D.isLoading,startIcon:D.isPending||D.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:D.isPending||D.isLoading?"Deleting...":"Delete"})]})]})]})})};var Mn=s(95952);const _n=()=>{const[e,t]=(0,A.useState)(""),{userProfile:s,setUserProfile:r}=te(),[n,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(null),[u,m]=(0,A.useState)("info");(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,us.T)();t(e.sub)}catch(e){}})()}),[]);const{data:h,isLoading:p}=(0,g.I)({queryKey:["getUserProfile",e],queryFn:async()=>{if(!e)return null;const t=await $(D,{userId:e});return t?.getUserProfile&&r(t.getUserProfile),t},enabled:!!e}),{data:v,isLoading:I,error:S,refetch:C}=(0,g.I)({queryKey:["storeInfo",s?.id],queryFn:()=>$("\n query GetStoreInfo($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n address\n radius\n codEnabled\n }\n }\n",{managerId:s.id}),enabled:!!s?.id}),w=v?.storesByManager?.[0],{data:P,isLoading:k,error:E,refetch:L}=(0,g.I)({queryKey:["storeSquareStatus",w?.id],queryFn:()=>$("\n query StoreSquareStatus($storeId: Int!) {\n storeSquareStatus(storeId: $storeId) {\n storeId\n storeName\n isConnected\n merchantId\n }\n }\n",{storeId:w?.id}),enabled:!!w?.id}),F=P?.storeSquareStatus,z=(0,Ft.n)({mutationFn:e=>$("\n mutation ConnectSquare($storeId: Int!) {\n connectSquare(storeId: $storeId) {\n authorizationUrl\n message\n }\n }\n",{storeId:e}),onSuccess:e=>{const t=e.connectSquare?.authorizationUrl;t?window.location.href=t:(m("error"),x(e.connectSquare?.message||"Failed to generate authorization URL"))},onError:e=>{m("error"),x(e.message||"Failed to initiate Square connection")}}),T=(0,Ft.n)({mutationFn:e=>$("\n mutation DisconnectSquare($storeId: Int!) {\n disconnectSquare(storeId: $storeId) {\n success\n message\n }\n }\n",{storeId:e}),onSuccess:e=>{i(!1),e.disconnectSquare?.success?(m("success"),x("Square account disconnected successfully"),L()):(m("error"),x(e.disconnectSquare?.message||"Failed to disconnect Square"))},onError:e=>{i(!1),m("error"),x(e.message||"Failed to disconnect Square account")}}),R=(0,Ft.n)({mutationFn:e=>$("\n mutation ToggleCod($storeId: Int!, $enabled: Boolean!) {\n toggleCod(storeId: $storeId, enabled: $enabled) {\n id\n codEnabled\n }\n }\n",e),onSuccess:e=>{e.toggleCod?(m("success"),x(e.toggleCod.codEnabled?"Cash on Delivery enabled successfully":"Cash on Delivery disabled successfully"),L(),C()):(m("error"),x("Failed to update COD settings"))},onError:e=>{m("error"),x(e.message||"Failed to update COD settings")}});(0,A.useEffect)((()=>{const e=new URLSearchParams(window.location.search),t=e.get("oauth_success"),s=e.get("oauth_error");"true"===t?(m("success"),x("Square account connected successfully"),L(),window.history.replaceState({},"","/store_manager/payment-settings")):s&&(m("error"),x(`OAuth error: ${decodeURIComponent(s)}`),window.history.replaceState({},"","/store_manager/payment-settings"))}),[L]),(0,A.useEffect)((()=>{if(c&&"success"===u){const e=setTimeout((()=>{x(null)}),5e3);return()=>clearTimeout(e)}}),[c,u]);const W=()=>{i(!1)},q=()=>{o(!1)};return p||I||k?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})})}):S||E?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4},children:(0,ne.jsxs)(xe.A,{severity:"error",children:["Error loading data: ",S?.message||E?.message]})})}):w?(0,ne.jsx)(wn,{children:(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Payment Settings"}),(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ne.jsx)(wt.A,{sx:{mr:1,fontSize:32}}),(0,ne.jsx)(y.A,{variant:"h5",children:"Square Payment Connection"})]}),c&&(0,ne.jsx)(xe.A,{severity:u,sx:{mb:3},onClose:()=>x(null),children:c}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Connect your store to Square to enable online card payments for your customers."}),(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsxs)(y.A,{variant:"subtitle1",sx:{mb:1},children:[(0,ne.jsx)("strong",{children:"Store:"})," ",w.name]}),(0,ne.jsxs)(y.A,{variant:"subtitle1",sx:{mb:2},children:[(0,ne.jsx)("strong",{children:"Connection Status:"})," ",F?.isConnected?(0,ne.jsx)(Oe.A,{label:"Connected",color:"success",size:"small",icon:(0,ne.jsx)(Gr.A,{})}):(0,ne.jsx)(Oe.A,{label:"Not Connected",color:"default",size:"small",icon:(0,ne.jsx)(Kr.A,{})})]}),F?.isConnected&&F?.merchantId&&(0,ne.jsxs)(y.A,{variant:"subtitle1",sx:{mb:2},children:[(0,ne.jsx)("strong",{children:"Merchant ID:"})," ",F.merchantId]})]}),(0,ne.jsx)(f.A,{children:F?.isConnected?(0,ne.jsx)(ae.A,{variant:"outlined",color:"error",onClick:()=>{i(!0)},disabled:T.isPending,startIcon:T.isPending&&(0,ne.jsx)(b.A,{size:16}),children:T.isPending?"Disconnecting...":"Disconnect Square"}):(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",onClick:()=>{w?.id&&z.mutate(w.id)},disabled:z.isPending,startIcon:z.isPending&&(0,ne.jsx)(b.A,{size:16}),children:z.isPending?"Connecting...":"Connect Square Account"})})]}),(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mt:3},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:3},children:[(0,ne.jsx)(Mn.A,{sx:{mr:1,fontSize:32}}),(0,ne.jsx)(y.A,{variant:"h5",children:"Cash on Delivery"})]}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:3},children:"Accept cash payments when orders are delivered"}),(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(Qe.A,{checked:w?.codEnabled||!1,onChange:e=>{d(e.target.checked),o(!0)},disabled:R.isPending,color:"primary"}),label:w?.codEnabled?"Enabled":"Disabled"})]}),(0,ne.jsxs)(it.A,{open:n,onClose:W,children:[(0,ne.jsx)(at.A,{children:"Disconnect Square?"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(Hr.A,{children:["Are you sure you want to disconnect Square for ",(0,ne.jsx)("strong",{children:w.name}),"?",(0,ne.jsx)("br",{}),(0,ne.jsx)("br",{}),"Customers will not be able to make card payments until you reconnect."]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:W,disabled:T.isPending,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{w?.id&&T.mutate(w.id)},color:"error",variant:"contained",disabled:T.isPending,startIcon:T.isPending&&(0,ne.jsx)(b.A,{size:16}),children:T.isPending?"Disconnecting...":"Disconnect"})]})]}),(0,ne.jsxs)(it.A,{open:a,onClose:q,children:[(0,ne.jsxs)(at.A,{children:[l?"Enable":"Disable"," Cash on Delivery?"]}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(Hr.A,{children:l?`Customers will be able to pay with cash when their orders from ${w?.name} are delivered.`:`Customers will no longer see Cash on Delivery as a payment option for ${w?.name}. Orders already in progress will not be affected.`})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:q,disabled:R.isPending,children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:()=>{w?.id&&R.mutate({storeId:w.id,enabled:l}),o(!1)},variant:"contained",color:l?"primary":"error",disabled:R.isPending,startIcon:R.isPending&&(0,ne.jsx)(b.A,{size:16}),children:R.isPending?"Saving...":"Confirm"})]})]})]})}):(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4},children:(0,ne.jsx)(xe.A,{severity:"warning",children:"No store found. You are not assigned as a manager to any store."})})})},Vn=()=>{const e=(0,d.Zp)(),{user:t,setUser:s}=te(),[r,i]=(0,A.useState)(!0),a=(0,qe.A)();return(0,A.useEffect)((()=>{(async()=>{try{const t=await(0,S.$)();if(t?.tokens?.idToken){const r=t.tokens.idToken.payload.sub,n=t.tokens.idToken.payload["custom:role"]?.toLowerCase();s({id:r,role:n}),e(`/${n}`)}}catch(e){}finally{i(!1)}})()}),[s,e]),r?(0,ne.jsx)(pe,{}):(0,ne.jsx)(f.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, ${(0,c.X4)(a.palette.primary.main,.1)} 0%, ${(0,c.X4)(a.palette.primary.main,.05)} 100%)`,zIndex:0}},children:(0,ne.jsxs)(me.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,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",mb:4},children:[(0,ne.jsx)(y.A,{variant:"h4",sx:{fontWeight:"bold",color:"primary.main",mb:1,textAlign:"center",fontSize:{xs:"1.75rem",sm:"2rem"}},children:"Welcome Back"}),(0,ne.jsx)(y.A,{variant:"body1",sx:{color:"text.secondary",textAlign:"center",maxWidth:"80%"},children:"Sign in to continue your journey with us"})]}),(0,ne.jsx)(gs,{}),(0,ne.jsxs)(f.A,{sx:{mt:4,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:[(0,ne.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,ne.jsxs)(y.A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:["Don't have an account?"," ",(0,ne.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 Hn=(0,s(11848).Ay)(le.A)((e=>{let{theme:t}=e;return{"& .MuiInputBase-root":{minHeight:"120px"}}})),Gn=e=>{let{sectionHeaders:t,answers:s={},onChangeAnswers:r,onSubmit:n}=e;const[i,a]=(0,A.useState)(!1),[o,l]=(0,A.useState)(!1),d=()=>Object.values(s).some((e=>e&&""!==e.trim()));return(0,ne.jsxs)(f.A,{sx:{width:"100%"},children:[(0,ne.jsx)(Ce.Ay,{container:!0,spacing:3,children:t.map(((e,t)=>(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(me.A,{elevation:1,sx:{p:3,height:"100%",border:"1px solid",borderColor:"divider",borderRadius:2,boxShadow:2,display:"flex",flexDirection:"column",gap:2,background:e=>`linear-gradient(135deg, ${e.palette.grey[50]} 0%, ${e.palette.grey[200]} 100%)`},children:[(0,ne.jsx)(y.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,color:"primary.main",letterSpacing:.2},children:e}),(0,ne.jsx)(Hn,{fullWidth:!0,multiline:!0,minRows:5,placeholder:`Enter items for ${e.toLowerCase()}`,variant:"outlined",value:s[t]||"",onChange:e=>((e,t)=>{const n={...s,[e]:t};r(n)})(t,e.target.value),sx:{"& .MuiOutlinedInput-root":{backgroundColor:"background.paper"}}})]})},t)))}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"flex-end",mt:4},children:(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",size:"large",disabled:!d(),sx:{px:5,py:1.5,fontWeight:600,borderRadius:2,boxShadow:1,opacity:d()?1:.6},onClick:()=>{if(!d())return;const e=(()=>{if(!t||0===t.length)return"";const e=[];return t.forEach(((t,r)=>{const n=s[r]?s[r].trim():"";n&&(e.push(t),n.split("\n").forEach((t=>{const s=t.trim();s&&e.push(` • ${s}`)})),e.push(""))})),e.join("\n").trim()})();n(e),l(Object.values(s).some((e=>""!==e.trim()))),a(!0),(()=>{const e={};t.forEach(((t,s)=>{e[s]=""})),r(e)})(),setTimeout((()=>{a(!1)}),3e3)},children:"Submit List"})}),(0,ne.jsxs)(it.A,{open:i,onClose:()=>a(!1),PaperProps:{sx:{borderRadius:2,minWidth:"300px"}},children:[(0,ne.jsxs)(at.A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Ur.A,{color:"success",sx:{fontSize:28}}),(0,ne.jsx)(y.A,{variant:"h6",sx:{fontWeight:600},children:o?"Items Edited":"Items Added"})]}),(0,ne.jsx)(be.A,{onClick:()=>a(!1),size:"small",sx:{color:"text.secondary"},children:(0,ne.jsx)(Pt.A,{})})]}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.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,ne.jsx)(lt.A,{sx:{px:3,pb:2},children:(0,ne.jsx)(ae.A,{variant:"contained",onClick:()=>a(!1),sx:{borderRadius:2,textTransform:"none",px:3},children:"Okay"})})]})]})},Kn=()=>{const[e,t]=(0,A.useState)(!1),[s,r]=(0,A.useState)(!1),[n,i]=(0,A.useState)(!1),{selectedStore:a,setAvailableStores:o,setSelectedStore:l,pickupAddress:d,deliveryType:c,deliveryAddressString:x,setCustomOrder:u,listInputAnswers:m,setListInputAnswers:h}=re(),{data:p,isLoading:y,error:j}=(0,g.I)({queryKey:["stores"],queryFn:async()=>await $(W)});(0,A.useEffect)((()=>{if(p?.stores&&p.stores.length>0){o(p.stores);const e=localStorage.getItem("selectedStoreId");if(e){const s=p.stores.find((t=>String(t.id)===e));a&&a.id===s?.id||(s?l(s):(localStorage.removeItem("selectedStoreId"),t(!0)))}else a||t(!0)}}),[p,a,o]);if(y)return(0,ne.jsx)(ie,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:(0,ne.jsx)(pe,{})});const f=a?.sectionHeaders?.length>0;return(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(Ks,{open:e,onClose:()=>t(!1)}),a&&(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(Ks,{open:s,onClose:()=>r(!1),forceStep:"pickup",initialStore:a}),(0,ne.jsx)(fe,{children:(0,ne.jsx)(ie,{sx:{mt:{xs:1,sm:2}},children:(0,ne.jsx)(It,{images:a?.images,storeAddress:a.address,storeDescription:a.description,deliveryLabel:d||x?"delivery"===c?"Change Delivery Address":"Change Pickup Location":void 0,deliverySubtext:d||x?"delivery"===c?x||"No address selected":d?.address||"No pickup location selected":void 0,onChangeAddress:d||x?()=>r(!0):void 0})})}),(0,ne.jsxs)(fe,{children:[f&&(0,ne.jsx)(me.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,ne.jsxs)(ie,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},gap:{xs:1,sm:0}},children:[(0,ne.jsx)(ce,{variant:"h6",sx:{fontWeight:600,fontSize:{xs:"1.1rem",sm:"1.25rem"}},children:n?"Browse Products":"Quick List Entry"}),(0,ne.jsx)(ie,{sx:{minWidth:{xs:0,sm:200},display:"flex",alignItems:"center",justifyContent:{xs:"flex-start",sm:"flex-end"},width:{xs:"100%",sm:"auto"}},children:(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(Qe.A,{checked:n,onChange:()=>{i(!n)},color:"primary"}),label:(0,ne.jsx)(ce,{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,ne.jsx)(Gn,{sectionHeaders:a.sectionHeaders,answers:m,onChangeAnswers:h,onSubmit:u}):(0,ne.jsx)(Nt,{})]})]})]})};var Yn=s(37483),Xn=s(54790);const Qn=e=>{let{open:t,onClose:s,orderCode:r,onNavigate:n,onViewOrder:i}=e;const[a,o]=(0,A.useState)(3);(0,A.useEffect)((()=>{t&&o(3)}),[t]);const l=()=>{s(),n&&n()};return(0,A.useEffect)((()=>{if(t&&a>0){const e=setTimeout((()=>{o(a-1)}),1e3);return()=>clearTimeout(e)}t&&0===a&&l()}),[t,a,s,n]),(0,ne.jsx)(it.A,{open:t,onClose:l,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:3,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.12)"}},children:(0,ne.jsx)(ot.A,{sx:{p:4},children:(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:"column",alignItems:"center",py:2,gap:2},children:[(0,ne.jsx)(Ur.A,{sx:{fontSize:80,color:"success.main"}}),(0,ne.jsx)(y.A,{variant:"h5",fontWeight:"bold",color:"success.main",textAlign:"center",children:"Order Placed Successfully!"}),r&&(0,ne.jsxs)(y.A,{variant:"body1",color:"text.secondary",children:["Order #",r]}),(0,ne.jsx)(y.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,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mt:1},children:a>0?`Redirecting in ${a} seconds...`:"Redirecting..."}),(0,ne.jsxs)(St.A,{direction:"row",spacing:2,sx:{mt:3,width:"100%",justifyContent:"center"},children:[(0,ne.jsx)(ae.A,{variant:"outlined",color:"primary",onClick:()=>{s(),i&&i()},sx:{px:4,py:1.2,borderRadius:2,fontWeight:600,textTransform:"none",flex:1,maxWidth:200},children:"View Order"}),(0,ne.jsx)(ae.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 Zn=s(12310),Jn=s(25831),ei=s(51694),ti=s(85916),si=s(11692),ri=s(2183);const ni=e=>{let{size:t=24,sx:s}=e;return(0,ne.jsx)(b.A,{size:t,sx:{color:"inherit",...s}})},ii=e=>{let{userProfile:t,onPhoneUpdate:s}=e;const[r,n]=(0,A.useState)(!1),[i,a]=(0,A.useState)(""),[o,l]=(0,A.useState)(""),{mutate:d,isPending:c}=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdateSecondaryPhone($userId: Int!, $secondaryPhone: String) {\n updateSecondaryPhone(userId: $userId, secondaryPhone: $secondaryPhone) {\n active\n }\n }\n",e),onSuccess:()=>{s(),n(!1),a(""),l("")},onError:e=>{l("Failed to update phone number. Please try again.")}});return t?(0,ne.jsx)(f.A,{sx:{mb:3},children:r?(0,ne.jsxs)(me.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Lr.A,{color:"primary"}),(0,ne.jsx)(y.A,{variant:"subtitle1",sx:{fontWeight:500},children:t.secondaryPhone?"Update Number":"Add Number"})]}),(0,ne.jsx)(le.A,{size:"small",value:i,onChange:e=>{const t=e.target.value.replace(/\D/g,"").slice(0,10);a(t),l("")},placeholder:"Enter 10-digit number",error:!!o,helperText:o,InputProps:{startAdornment:(0,ne.jsx)(y.A,{sx:{mr:1},children:"+1"})}}),(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:1},children:[(0,ne.jsx)(ae.A,{variant:"contained",size:"small",onClick:()=>{10===i.length?d({userId:t.id,secondaryPhone:i}):l("Please enter a valid 10-digit phone number")},disabled:c||10!==i.length,startIcon:c?(0,ne.jsx)(ni,{size:20}):(0,ne.jsx)(Lr.A,{}),children:c?"Saving...":"Save"}),(0,ne.jsx)(ae.A,{variant:"outlined",size:"small",onClick:()=>{n(!1),a(""),l("")},children:"Cancel"})]})]}):(0,ne.jsxs)(me.A,{elevation:0,sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,border:"1px solid",borderColor:"divider",borderRadius:2},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Lr.A,{color:"primary"}),(0,ne.jsx)(y.A,{variant:"subtitle1",sx:{fontWeight:500},children:"Secondary Contact"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"(Update if you want to change)"})]}),t.secondaryPhone?(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsxs)(y.A,{variant:"body1",children:["+1 ",t.secondaryPhone]}),(0,ne.jsx)(ae.A,{variant:"outlined",size:"small",onClick:()=>n(!0),startIcon:(0,ne.jsx)(Lr.A,{}),sx:{alignSelf:"flex-start"},children:"Change Number"})]}):(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:"No secondary number added"}),(0,ne.jsx)(ae.A,{variant:"outlined",size:"small",onClick:()=>n(!0),startIcon:(0,ne.jsx)(Lr.A,{}),sx:{alignSelf:"flex-start"},children:"Add Number"})]})]})}):null},ai=()=>{const{cart:e,removeFromCart:t,addToCart:s,deleteCartLine:r,cartTotal:i,clearCart:o,selectedStore:l,getCartTotals:c,setTipAmount:x,customOrder:u,setCustomOrder:m,pickupAddress:h,setPickupAddress:p,deliveryType:j,setDeliveryType:v,tipAmount:I,setListInputAnswers:C,setCartItemInstructions:w,setCartItemAllowSubstitute:P}=re(),[k,E]=(0,A.useState)(""),[L,F]=(0,A.useState)(!1),[D,z]=(0,A.useState)(null),[T,R]=(0,A.useState)(""),{user:W,userProfile:q,fetchUserProfile:O,isProfileLoading:U,setModalOpen:B,setCurrentForm:M,setSkipNavigateOnLogin:_}=te(),V=(0,d.Zp)(),H=(0,a.jE)(),[G,K]=(0,A.useState)(0),[Y,X]=(0,A.useState)(""),[Q,J]=(0,A.useState)(h?String(h.id):null),[ee,ie]=(0,A.useState)(!1),[oe,de]=(0,A.useState)(!1),[ce,xe]=(0,A.useState)(null),[ue,he]=(0,A.useState)(!(!h&&"delivery"!==j)),pe=(0,A.useCallback)((async()=>{if(o(),m(""),C({}),l?.id)try{localStorage.removeItem(`indimitra-cart-store-${l.id}`)}catch(e){}if(q?.id&&l?.id)try{await $(N,{userId:q.id,storeId:l.id}),await new Promise((e=>setTimeout(e,100)))}catch(e){}}),[o,m,C,l,q]);(0,A.useEffect)((()=>{(async()=>{const e=await(0,S.$)(),t=e?.tokens?.idToken?.payload?.sub;t&&await O(t)})()}),[O,W]);const{addresses:Ae,selectedAddressId:ge,setSelectedAddressId:je,fetchAddresses:fe,isLoading:ve,createAddress:Se}=se(),{data:we,isLoading:Pe}=(0,g.I)({queryKey:["storePaymentConfig",l?.id],queryFn:async()=>$("\n query StorePaymentConfig($storeId: Int!) {\n storePaymentConfig(storeId: $storeId) {\n storeId\n isSquareConnected\n codEnabled\n squareApplicationId\n squareLocationId\n }\n }\n",{storeId:l.id}),enabled:!!l?.id}),ke=we?.storePaymentConfig||null,[Fe,Re]=(0,A.useState)(!1),[We,qe]=(0,A.useState)(""),[Ue,Ne]=(0,A.useState)(!1),[Be,Me]=(0,A.useState)(!1),[_e,Ve]=(0,A.useState)(!1),[He,Ge]=(Object.values(e).reduce(((e,t)=>e+(t.quantity||0)),0),(0,A.useState)({subtotal:0,deliveryFee:0,taxAmount:0,taxPercentage:0,tipAmount:0,total:0}));(0,A.useEffect)((()=>{q?.id&&fe(q.id)}),[q?.id,fe]),(0,A.useEffect)((()=>{h&&(J(String(h.id)),v("pickup"),je(null),he(!0))}),[h,v,je]),(0,A.useEffect)((()=>{const e=c();Ge(e)}),[j,e,c,I]);const{subtotal:Ke,deliveryFee:Qe,taxAmount:Ze,taxPercentage:Je,tipAmount:et,total:tt}=He;(0,A.useEffect)((()=>{if(!ue){if(l?.pickupAddresses?.edges?.length>0&&!Q&&!ge){const e=l.pickupAddresses.edges[0].node;return J(String(e.id)),v("pickup"),void je(null)}if(Ae&&Ae.length>0&&!Q&&!ge){const e=Ae.find((e=>e.isPrimary))||Ae[0];return je(e.id),v("delivery"),void J(null)}l?.pickupAddresses?.edges?.length&&0!==l?.pickupAddresses?.edges?.length||Ae&&0!==Ae.length||Q||ge||v("delivery")}}),[l?.pickupAddresses?.edges,Ae,ue]);const{mutate:st,isPending:rt}=(0,Ft.n)({mutationKey:["createOrder"],mutationFn:async e=>{const t=re.getState().selectedStore;return $("\n mutation CreateOrder(\n $userId: Int!\n $storeId: Int!\n $productItems: [OrderItemInput!]!\n $totalAmount: Float!\n $orderTotalAmount: Float!\n $pickupOrDelivery: String!\n $addressId: Int\n $pickupId: Int\n $deliveryFee: Float\n $tipAmount: Float\n $taxAmount: Float\n $deliveryInstructions: String\n $customOrder: String\n ) {\n createOrder(\n userId: $userId\n storeId: $storeId\n productItems: $productItems\n totalAmount: $totalAmount\n orderTotalAmount: $orderTotalAmount\n pickupOrDelivery: $pickupOrDelivery\n addressId: $addressId\n pickupId: $pickupId\n deliveryFee: $deliveryFee\n tipAmount: $tipAmount\n taxAmount: $taxAmount\n deliveryInstructions: $deliveryInstructions\n customOrder: $customOrder\n ) {\n id\n status\n totalAmount\n orderTotalAmount\n deliveryFee\n tipAmount\n taxAmount\n deliveryInstructions\n deliveryDate\n address {\n id\n address\n }\n orderItems {\n edges {\n node {\n id\n quantity\n orderAmount\n product {\n id\n name\n }\n }\n }\n }\n }\n }\n",{...e,storeId:t.id})},onSuccess:async e=>{const t=e?.createOrder;if(t&&t.id)try{await pe(),z(t.displayCode||`#${t.id}`),F(!0),R(""),H.invalidateQueries(["userAddresses",q.id])}catch(e){z(t.displayCode||`#${t.id}`),F(!0)}else R("Order creation failed. Your cart has been preserved. Please try again.")},onError:e=>{R(e?.message||e?.response?.errors?.[0]?.message||e?.graphQLErrors?.[0]?.message||"Failed to place order. Please try again.")}}),{mutate:nt,isPending:it}=(0,Ft.n)({mutationFn:async e=>$("\n mutation CreateOrderWithCod(\n $userId: Int!\n $storeId: Int!\n $productItems: [OrderItemInput!]!\n $pickupOrDelivery: String!\n $addressId: Int\n $pickupId: Int\n $tipAmount: Float\n $deliveryInstructions: String\n $customOrder: String\n ) {\n createOrderWithCod(\n userId: $userId\n storeId: $storeId\n productItems: $productItems\n pickupOrDelivery: $pickupOrDelivery\n addressId: $addressId\n pickupId: $pickupId\n tipAmount: $tipAmount\n deliveryInstructions: $deliveryInstructions\n customOrder: $customOrder\n ) {\n id\n displayCode\n status\n orderTotalAmount\n }\n }\n",e),onSuccess:async e=>{const t=e?.createOrderWithCod;if(t&&t.id)try{await pe(),z(t.displayCode||`#${t.id}`),F(!0),R("")}catch(e){z(t.displayCode||`#${t.id}`),F(!0)}else R("Order creation failed. Your cart has been preserved. Please try again.")},onError:e=>{R(e?.message||e?.response?.errors?.[0]?.message||e?.graphQLErrors?.[0]?.message||"Failed to place order. Please try again.")}}),at=(0,A.useCallback)((()=>{de(!1)}),[]),ot=(0,A.useCallback)((async e=>{if(e)if(e.id)try{await pe(),z(e.displayCode||`#${e.id}`),F(!0),R("")}catch(t){z(e.displayCode||`#${e.id}`),F(!0)}else{const t=e.error||"Order creation failed. Your cart has been preserved. Please try again.";R(t)}else R("Order creation failed. Your cart has been preserved. Please try again.")}),[pe]),lt=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity,meatCutId:e.selectedCut?.id??null,selectedCut:e.selectedCut??null})));return(0,ne.jsxs)(f.A,{sx:{padding:3},children:[(0,ne.jsxs)(f.A,{sx:{mb:4,display:"flex",alignItems:{xs:"flex-start",sm:"flex-end"},justifyContent:"space-between",flexDirection:{xs:"column",sm:"row"},gap:2},children:[(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",component:"h1",sx:{fontWeight:700,color:"text.primary",fontSize:{xs:"1.6rem",sm:"1.9rem"},lineHeight:1.2,letterSpacing:"-0.01em"},children:"Your Cart"}),(Object.values(e).length>0||u)&&(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:"text.secondary",mt:.5,fontSize:"0.9rem"},children:[Object.values(e).reduce(((e,t)=>e+(t.quantity||0)),0)," ",1===Object.values(e).reduce(((e,t)=>e+(t.quantity||0)),0)?"item":"items",l?.name?` · ${l.name}`:""]})]}),(0,ne.jsx)(ae.A,{component:n.N_,to:"/",variant:"text",size:"small",sx:{color:"text.secondary",textTransform:"none",fontWeight:500,fontSize:"0.9rem","&:hover":{color:"primary.main",backgroundColor:"transparent"}},children:"← Continue shopping"})]}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:3,children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,md:8,children:[T&&(0,ne.jsx)(f.A,{sx:{mb:2},children:(0,ne.jsx)(yt,{error:T,title:"Order Error",severity:"error"})}),Object.values(e).length>0||u?(0,ne.jsxs)(me.A,{variant:"outlined",sx:{mb:3,borderRadius:2,overflow:"hidden",borderColor:"divider"},children:[(0,ne.jsxs)(f.A,{sx:{px:{xs:2,sm:3},py:2,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[(0,ne.jsx)(y.A,{sx:{fontWeight:600,fontSize:"1.05rem"},children:"Cart Items"}),Object.values(e).length>0&&(0,ne.jsxs)(y.A,{variant:"body2",color:"text.secondary",children:[Object.values(e).reduce(((e,t)=>e+(t.quantity||0)),0)," ",1===Object.values(e).reduce(((e,t)=>e+(t.quantity||0)),0)?"item":"items"]})]}),Object.values(e).map(((e,n,i)=>{const a=Z(e);return(0,ne.jsxs)(f.A,{sx:{px:{xs:2,sm:3},py:{xs:2,sm:2.25},display:"flex",flexDirection:"column",gap:1.5,borderBottom:nt(e),sx:{width:28,height:28,color:"text.secondary","&:hover":{color:"primary.main",backgroundColor:"transparent"}},children:(0,ne.jsx)(ze.A,{sx:{fontSize:16}})}),(0,ne.jsx)(y.A,{sx:{minWidth:24,textAlign:"center",fontWeight:600,fontSize:"0.9rem",color:"text.primary",userSelect:"none"},children:e.quantity}),(0,ne.jsx)(be.A,{size:"small",onClick:()=>s(e),sx:{width:28,height:28,color:"text.secondary","&:hover":{color:"primary.main",backgroundColor:"transparent"}},children:(0,ne.jsx)(Te.A,{sx:{fontSize:16}})})]}),(0,ne.jsxs)(y.A,{sx:{fontWeight:700,fontSize:{xs:"0.95rem",sm:"1rem"},minWidth:{xs:"auto",sm:80},textAlign:"right",color:"text.primary",flexShrink:0},children:["$",(e.price*e.quantity).toFixed(2)]}),(0,ne.jsx)(De.A,{title:"Remove item",children:(0,ne.jsx)(be.A,{className:"cart-row-delete",size:"small",onClick:()=>r(e),sx:{opacity:{xs:1,sm:0},transition:"opacity 120ms ease, color 120ms ease",color:"text.disabled","&:hover":{color:"error.main",backgroundColor:"transparent"}},children:(0,ne.jsx)(Zn.A,{sx:{fontSize:20}})})})]})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"stretch",sm:"flex-start"},gap:{xs:1,sm:2},pl:{xs:0,sm:9}},children:[(0,ne.jsx)(le.A,{size:"small",fullWidth:!0,multiline:!0,maxRows:3,placeholder:"Instructions for this item (optional)",value:e.instructions||"",onChange:e=>w(a,e.target.value),inputProps:{maxLength:500},sx:{flex:1}}),(0,ne.jsx)(Xe.A,{sx:{m:0,whiteSpace:"nowrap",alignSelf:{xs:"flex-start",sm:"center"}},control:(0,ne.jsx)(yn.A,{size:"small",checked:!!e.allowSubstitute,onChange:e=>P(a,e.target.checked)}),label:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:.5},children:[(0,ne.jsx)(y.A,{variant:"body2",sx:{color:"text.secondary"},children:"Replace if unavailable"}),(0,ne.jsx)(De.A,{title:"If checked, the store will replace this item with a similar product of a different brand when unavailable. If unchecked, the item will be cancelled.",placement:"top",arrow:!0,children:(0,ne.jsx)(Jn.A,{sx:{fontSize:16,color:"text.disabled",cursor:"help"}})})]})})]})]},a)})),u&&(0,ne.jsxs)(f.A,{sx:{px:{xs:2,sm:3},py:2.5,borderTop:"1px solid",borderColor:"divider",backgroundColor:"primary.lighter"},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:1.25,mb:1.5},children:[(0,ne.jsx)(Xt.A,{sx:{color:"primary.main",fontSize:20}}),(0,ne.jsx)(y.A,{sx:{fontWeight:600,color:"primary.main",fontSize:"0.95rem"},children:"Custom Shopping List"})]}),(0,ne.jsx)(f.A,{sx:{p:2,bgcolor:"background.paper",borderRadius:1,border:"1px solid",borderColor:"divider"},children:(0,ne.jsx)(y.A,{variant:"body1",sx:{whiteSpace:"pre-line",fontFamily:"monospace",lineHeight:1.6},children:u})}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"flex-end",mt:1.5},children:(0,ne.jsx)(ae.A,{variant:"text",color:"error",size:"small",onClick:()=>m(""),startIcon:(0,ne.jsx)(Zn.A,{}),children:"Remove List"})})]})]}):(0,ne.jsxs)(me.A,{variant:"outlined",sx:{mb:3,borderRadius:2,borderColor:"divider",px:3,py:6,textAlign:"center"},children:[(0,ne.jsx)(Xt.A,{sx:{fontSize:56,color:"text.disabled",mb:1.5}}),(0,ne.jsx)(y.A,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"Your cart is empty"}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mb:2.5},children:"Browse items and add them to your cart to get started."}),(0,ne.jsx)(ae.A,{variant:"contained",component:n.N_,to:"/",startIcon:(0,ne.jsx)(Xt.A,{}),children:"Continue Shopping"})]})]}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(me.A,{variant:"outlined",sx:{position:"sticky",top:24,borderRadius:2,borderColor:"divider",overflow:"hidden"},children:[(0,ne.jsx)(f.A,{sx:{px:3,py:2,borderBottom:"1px solid",borderColor:"divider"},children:(0,ne.jsx)(y.A,{sx:{fontWeight:600,fontSize:"1.05rem"},children:"Order Summary"})}),(0,ne.jsxs)(f.A,{sx:{p:3},children:[q&&(0,ne.jsx)(f.A,{sx:{mb:3},children:(0,ne.jsx)(ii,{userProfile:q,onPhoneUpdate:()=>{(async()=>{const e=await(0,S.$)(),t=e?.tokens?.idToken?.payload?.sub;t&&await O(t)})()}})}),(0,ne.jsxs)(St.A,{spacing:1.25,children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ne.jsx)(y.A,{sx:{color:"text.secondary",fontSize:"0.92rem"},children:"Subtotal"}),(0,ne.jsxs)(y.A,{sx:{fontWeight:500,fontSize:"0.92rem"},children:["$",Ke.toFixed(2)]})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ne.jsx)(y.A,{sx:{color:"text.secondary",fontSize:"0.92rem"},children:"Delivery Fee"}),(0,ne.jsxs)(y.A,{sx:{fontWeight:500,fontSize:"0.92rem"},children:["$",Qe.toFixed(2)]})]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ne.jsxs)(y.A,{sx:{color:"text.secondary",fontSize:"0.92rem"},children:["Tax",Je>0?` (${Je.toFixed(1)}%)`:""]}),(0,ne.jsxs)(y.A,{sx:{fontWeight:500,fontSize:"0.92rem"},children:["$",Ze.toFixed(2)]})]}),et>0&&(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between"},children:[(0,ne.jsx)(y.A,{sx:{color:"text.secondary",fontSize:"0.92rem"},children:"Tip"}),(0,ne.jsxs)(y.A,{sx:{fontWeight:500,fontSize:"0.92rem"},children:["$",et.toFixed(2)]})]})]}),(0,ne.jsxs)(f.A,{sx:{mt:2.5,pt:2.5,borderTop:"1px dashed",borderColor:"divider"},children:[(0,ne.jsx)(y.A,{sx:{fontWeight:600,fontSize:"0.82rem",color:"text.secondary",textTransform:"uppercase",letterSpacing:.6,mb:1.25},children:"Add a tip"}),(0,ne.jsxs)(Yn.A,{value:G,exclusive:!0,onChange:(e,t)=>{if(null!==t){K(t),X("");x(Ke*t/100)}},"aria-label":"tip percentage",size:"small",fullWidth:!0,sx:{mb:1.25,"& .MuiToggleButton-root":{borderColor:"divider",color:"text.secondary",fontWeight:500,fontSize:"0.82rem",textTransform:"none",py:.75,"&.Mui-selected":{backgroundColor:"primary.main",color:"common.white",borderColor:"primary.main","&:hover":{backgroundColor:"primary.dark"}}}},children:[(0,ne.jsx)(Xn.A,{value:0,"aria-label":"no tip",children:"No Tip"}),(0,ne.jsx)(Xn.A,{value:10,"aria-label":"10%",children:"10%"}),(0,ne.jsx)(Xn.A,{value:15,"aria-label":"15%",children:"15%"}),(0,ne.jsx)(Xn.A,{value:20,"aria-label":"20%",children:"20%"})]}),(0,ne.jsx)(le.A,{fullWidth:!0,size:"small",placeholder:"Custom amount",type:"number",value:Y,onChange:e=>{const t=e.target.value;X(t),K(0);const s=parseFloat(t)||0;x(s)},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(y.A,{sx:{color:"text.secondary"},children:"$"})})}})]}),(0,ne.jsxs)(f.A,{sx:{mt:2.5,pt:2,borderTop:"1px solid",borderColor:"divider",display:"flex",justifyContent:"space-between",alignItems:"baseline"},children:[(0,ne.jsx)(y.A,{sx:{fontWeight:700,fontSize:"1.05rem"},children:"Total"}),(0,ne.jsxs)(y.A,{sx:{fontWeight:700,fontSize:"1.35rem"},children:["$",tt.toFixed(2)]})]}),u&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsxs)(y.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Xt.A,{})," Custom Order Details"]}),(0,ne.jsx)(me.A,{elevation:0,sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:2,backgroundColor:"background.paper"},children:(0,ne.jsx)(y.A,{variant:"body2",sx:{whiteSpace:"pre-line",color:"text.secondary",fontFamily:"monospace"},children:u})})]}),q&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsxs)(y.A,{variant:"subtitle1",sx:{mb:2,display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(qt.A,{})," Delivery/Pickup Options"]}),U?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,ne.jsx)(ni,{size:24})}):(0,ne.jsxs)(St.A,{spacing:3,children:[l?.pickupAddresses?.edges?.length>0&&(0,ne.jsxs)(me.A,{elevation:"pickup"===j?4:1,sx:{p:2,bgcolor:"pickup"===j?"primary.lighter":"grey.50",opacity:"delivery"===j&&ge?.5:1,border:e=>"pickup"===j?`2px solid ${e.palette.info.main}`:`1px solid ${e.palette.divider}`,transition:"all 0.2s"},children:[(0,ne.jsxs)(y.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(or.A,{fontSize:"small",color:"primary"})," Pickup Address"]}),(0,ne.jsx)(Tt.A,{value:Q||"",onChange:e=>{const t=e.target.value;J(t),v("pickup"),je(null),he(!0);const s=l.pickupAddresses.edges.map((e=>e.node)),r=s.find((e=>String(e.id)===String(t)));r&&p(r)},children:l.pickupAddresses.edges.map((e=>{let{node:t}=e;return(0,ne.jsx)(Xe.A,{value:String(t.id),control:(0,ne.jsx)(Rt.A,{color:"primary"}),label:t.address},t.id)}))})]}),(0,ne.jsxs)(me.A,{elevation:"delivery"===j?4:1,sx:{p:2,bgcolor:"delivery"===j?"secondary.lighter":"grey.50",opacity:"pickup"===j&&Q?.5:1,border:e=>"delivery"===j?`2px solid ${e.palette.secondary.main}`:`1px solid ${e.palette.divider}`,transition:"all 0.2s"},children:[(0,ne.jsxs)(y.A,{variant:"subtitle1",sx:{mb:1,fontWeight:600,display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(ei.A,{fontSize:"small",color:"secondary"})," Home Delivery Address"]}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsxs)(Ee.A,{fullWidth:!0,sx:{mb:2},children:[(0,ne.jsx)($e.A,{children:"Select Address"}),ve?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",p:2},children:(0,ne.jsx)(ni,{size:24})}):(0,ne.jsx)(Le.A,{value:ge||"",onChange:e=>{je(e.target.value),v("delivery"),J(null),he(!0)},label:"Select Address",inputProps:{},InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(ri.A,{})})},children:Ae&&Ae.length>0?Ae.map((e=>(0,ne.jsxs)(Ie.A,{value:e.id,children:[e.address," ",e.isPrimary?"(Primary)":""]},e.id))):(0,ne.jsx)(Ie.A,{disabled:!0,children:"No addresses available"})})]}),(0,ne.jsx)(ae.A,{fullWidth:!0,variant:"outlined",startIcon:Fe?(0,ne.jsx)(ti.A,{}):(0,ne.jsx)(si.A,{}),onClick:()=>Re(!Fe),sx:{mb:2},children:Fe?"Cancel":"Add New Address"}),(0,ne.jsx)(Ye.A,{in:Fe,children:(0,ne.jsx)(f.A,{sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:1},children:(0,ne.jsxs)(St.A,{spacing:2,children:[(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(Vs,{value:We,onChange:e=>{qe(e),(e=>{if(!e.trim()||!Ae)return void ie(!1);const t=e.toLowerCase().trim(),s=Ae.some((e=>e.address.toLowerCase().trim()===t));ie(s)})(e)},onValidAddress:Ve}),ee&&(0,ne.jsx)(y.A,{variant:"body2",color:"error",sx:{mt:.5,fontSize:"0.875rem"},children:"⚠️ This address already exists in your address book"})]}),(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(yn.A,{checked:Ue,onChange:e=>Ne(e.target.checked)}),label:"Set as Primary Address"}),(0,ne.jsx)(ae.A,{variant:"contained",onClick:async()=>{if(!We.trim())return void R("Please enter a valid address");const e=We.trim().toLowerCase(),t=Ae?.some((t=>t.address.toLowerCase().trim()===e));if(t)R("This address already exists in your address book");else{Me(!0),R("");try{await Se(We,q.id,Ue),Re(!1),qe(""),Ne(!1),H.invalidateQueries(["userAddresses",q.id])}catch(e){R("Failed to add address. Please try again.")}finally{Me(!1)}}},disabled:!We.trim()||Be||!_e||ee,startIcon:Be?(0,ne.jsx)(ni,{size:20}):(0,ne.jsx)(jt.A,{}),children:Be?"Adding...":"Add Address"})]})})})]})]})]})]}),q&&(0,ne.jsxs)(f.A,{sx:{mb:3},children:[(0,ne.jsx)(y.A,{variant:"subtitle1",sx:{mb:2},children:"Delivery Instructions"}),(0,ne.jsx)(le.A,{fullWidth:!0,multiline:!0,rows:2,value:k,onChange:e=>E(e.target.value),placeholder:"Add any special instructions for delivery..."})]}),q&&(0,ne.jsx)(ne.Fragment,{children:Pe?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",mb:3},children:(0,ne.jsx)(b.A,{size:24})}):(0,ne.jsx)(Ot,{paymentConfig:ke,selectedMethod:ce,onMethodChange:xe})}),q?(0,ne.jsx)(ae.A,{fullWidth:!0,variant:"contained",size:"large",onClick:"cod"===ce?()=>{if(R(""),!q||!q.id)return R("Please log in to place an order"),_(!0),B(!0),void M("login");if(!l||!l.id)return void R("Please select a store");if(0===Object.values(e).length&&!u)return void R("Your cart is empty. Please add items before placing an order");if(!Q&&!ge)return void R("Please select either a pickup location or delivery address");const t=Object.values(e).map((e=>({productId:e.id,quantity:e.quantity,meatCutId:e.selectedCut?.id??null,instructions:e.instructions?.trim()?e.instructions.trim():null,allowSubstitute:!!e.allowSubstitute})));nt({userId:q.id,storeId:l.id,productItems:t,pickupOrDelivery:j,addressId:ge,pickupId:Q?parseInt(Q,10):null,tipAmount:I||0,deliveryInstructions:"pickup"===j?null:k,customOrder:u||null})}:()=>{de(!0)},disabled:U||Pe||!ce||!ge&&!Q||0===Object.values(e).length&&!u?.trim()||it,startIcon:"cod"===ce?(0,ne.jsx)(qt.A,{}):(0,ne.jsx)(wt.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"cod"===ce?"Place Order":"Pay Now"}):(0,ne.jsx)(ae.A,{fullWidth:!0,variant:"contained",size:"large",onClick:()=>{_(!0),B(!0),M("login")},startIcon:(0,ne.jsx)(Xt.A,{}),sx:{py:1.5,fontSize:"1.1rem",fontWeight:600},children:"Login to Continue"})]})]})})]}),(0,ne.jsx)(Dt,{open:oe,onClose:at,cartTotal:tt,orderItems:lt,deliveryType:j,selectedAddressId:ge,selectedPickupId:Q?parseInt(Q,10):null,userProfile:q,selectedStore:l,tipAmount:I,deliveryInstructions:k,customOrder:u,onSuccess:ot,paymentConfig:ke}),(0,ne.jsx)(Qn,{open:L,onClose:()=>F(!1),orderCode:D,onNavigate:()=>V("/"),onViewOrder:()=>V("/orders")})]})};var oi=s(16099),li=s(98821),di=s(1309);const ci=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(e);var xi=s(25737),ui=s(55463),mi=s(67046),hi=s(4213);(0,xi.D)();const pi="\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",Ai=()=>{const{userProfile:e}=te(),[t,s]=(0,A.useState)(""),[r,n]=(0,A.useState)(null),[i,a]=(0,A.useState)(!1),[o,l]=(0,A.useState)(!1),[d,c]=(0,A.useState)(null),[x,u]=(0,A.useState)(""),[m,h]=(0,A.useState)(""),[p,j]=(0,A.useState)(""),[I,S]=(0,A.useState)("ALL"),[C,w]=(0,A.useState)("createdAt"),[P,k]=(0,A.useState)("desc"),[E,L]=(0,A.useState)(0),[W,q]=(0,A.useState)(10),[O,U]=(0,A.useState)(""),[N,B]=(0,A.useState)(""),[M,_]=(0,A.useState)(""),[V,H]=(0,A.useState)(""),[G,K]=(0,A.useState)({open:!1,message:"",severity:"info"}),[Y,X]=(0,A.useState)(!1),[Q,Z]=(0,A.useState)(null),[J,ee]=(0,A.useState)(1),[se,re]=(0,A.useState)(!1),[ie,oe]=(0,A.useState)(null),[de,ce]=(0,A.useState)(!0);(0,A.useEffect)((()=>{const e=setTimeout((()=>{ce(!1)}),1e3);return()=>clearTimeout(e)}),[]),(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,us.T)();s(e.sub)}catch(e){}})()}),[]);const{data:ue,isLoading:he}=(0,g.I)({queryKey:["getUserProfile",t],queryFn:async()=>await $(D,{userId:t}),enabled:!!t}),pe=ue?.getUserProfile?.stores?.edges?.[0]?.node?.id,Ae=ue?.getUserProfile?.id,{data:ge,isLoading:je,error:fe,refetch:ve}=(0,g.I)({queryKey:["storeDrivers",pe],queryFn:async()=>await $(T,{storeId:pe}),enabled:!!pe}),{data:Se,isLoading:Pe,error:Fe,refetch:ze}=(0,g.I)({queryKey:["storeOrders",pe],queryFn:async()=>(await $(z,{storeId:pe})).getOrdersByStore||[],enabled:!!pe}),Te=(0,Ft.n)({mutationFn:async e=>await $(F,{input:{orderId:e.orderId,status:e.status,deliveryInstructions:e.deliveryInstructions||"",driverId:e.driverId||null,scheduleTime:e.scheduleTime||null}}),onSuccess:()=>{ze(),a(!1),c(null),u(""),B(""),_(""),H("")},onError:e=>{h(e.message)}}),Re=(0,Ft.n)({mutationFn:async e=>{const{orderId:t,itemId:s,quantity:r,price:n}=e,i=Se.find((e=>e.id===t));if(!i)throw new Error("Order not found");const a=ue?.getUserProfile?.stores?.edges?.[0]?.node?.taxPercentage||0,o=new Map;i.orderItems.edges.forEach((e=>{let{node:t}=e;const s=t.productId;(!o.has(s)||t.id>o.get(s).id)&&o.set(s,t)}));if(!Array.from(o.values()).some((e=>e.id===parseInt(s)?r>0:e.quantity>0)))return await $(pi,{orderId:parseInt(t),orderItemUpdates:[{orderItemId:parseInt(s),quantityChange:r-Q.quantity}],totalAmount:0,orderTotalAmount:0,taxAmount:0});let l=0;o.forEach((e=>{if(e.id===parseInt(s))l+=r*n;else{const t=e.product?.inventoryItems?.edges[0]?.node?.price||0;l+=e.quantity*t}}));const d=l*a/100,c=l+d+(i.deliveryFee||0)+(i.tipAmount||0),x=r-Q.quantity;return await $(pi,{orderId:parseInt(t),orderItemUpdates:[{orderItemId:parseInt(s),quantityChange:x}],totalAmount:l,orderTotalAmount:c,taxAmount:d})},onSuccess:()=>{ze(),X(!1),Z(null),ee(1)},onError:e=>{h(e.message)}}),We=(0,Ft.n)({mutationFn:async e=>await $(R,{orderId:e.orderId,cancelMessage:e.cancelMessage,cancelledByUserId:e.cancelledByUserId}),onSuccess:()=>{ze(),l(!1),U(""),c(null),K({open:!0,message:"Order cancelled successfully",severity:"success"})},onError:e=>{h(e.message),K({open:!0,message:"Failed to cancel order. Please try again.",severity:"error"})}}),qe=e=>{C===e?k("asc"===P?"desc":"asc"):(w(e),k("asc"))},Ue=A.useMemo((()=>{if(!Se)return[];let e=[...Se];return p&&(e=e.filter((e=>e.id.toString().includes(p)||(e.deliveryInstructions||"").toLowerCase().includes(p.toLowerCase())))),"ALL"!==I&&(e=e.filter((e=>e.status===I))),e.sort(((e,t)=>{let s=0;return s="totalAmount"===C?e[C]-t[C]:String(e[C]||"").localeCompare(String(t[C]||"")),"asc"===P?s:-s})),e}),[Se,p,I,C,P]),Ne=A.useMemo((()=>{const e=E*W;return Ue.slice(e,e+W)}),[Ue,E,W]),Be=e=>{if(!e?.edges?.length)return null;const t=new Map;e.edges.forEach((e=>{let{node:s}=e;const r=s.productId;(!t.has(r)||s.id>t.get(r).id)&&t.set(r,s)}));return Array.from(t.values())},Me=e=>["PENDING","ORDER_PLACED","ACCEPTED"].includes(e),_e=async(e,t)=>{try{if("pdf"===t){const t=(e=>{const t=new ui.uE;let s=20;const r=20;return t.internal.pageSize.width,t.setFontSize(16),t.text("Orders Report",r,s),s+=14,t.setFontSize(10),p&&(t.text(`Search Term: ${p}`,r,s),s+=7),"ALL"!==I&&(t.text(`Status Filter: ${I}`,r,s),s+=7),s+=7,e.forEach(((e,n)=>{s>t.internal.pageSize.height-40&&(t.addPage(),s=20),t.setFontSize(12),t.text(`Order #${e.id}`,r,s),s+=7,t.text(`Order Code: ${e.displayCode||"N/A"}`,r,s),s+=10.5,t.setFontSize(10),["Type: "+("PICKUP"===e.type?"Pickup":"Delivery"),`Status: ${_r.find((t=>t.value===e.status))?.label||e.status}`,`Total: $${e.orderTotalAmount}`,`Customer: ${e.creator?.email||"N/A"}`,`Phone: ${e.creator?.mobile||"N/A"}`,`Address: ${"PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A"}`].forEach((e=>{t.text(e,25,s),s+=7})),e.customOrder&&(s+=7,t.setFontSize(11),t.text("Custom Order Details:",25,s),s+=7,e.customOrder.split("\n\n").forEach((e=>{const[r,...n]=e.split("\n");r&&n.length>0&&(t.setFontSize(10),t.text(`Q: ${r}`,30,s),s+=7,n.forEach((e=>{t.text(`A: ${e}`,35,s),s+=7})),s+=3.5)}))),e.orderItems?.edges?.length>0&&(s+=7,t.setFontSize(11),t.text("Items:",25,s),s+=7,e.orderItems.edges.forEach((e=>{let{node: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}`;t.text(i,30,s),s+=7}))),s+=14})),t})(e);t.save(`orders_${(new Date).toISOString().replace(/[-:]/g,"").replace("T","_").replace("Z","")}.pdf`)}else{const t=(e=>new mi.yoT({sections:[{properties:{},children:[new mi.fzL({children:[new mi.NTc({text:"Orders Report",bold:!0,size:32})]}),new mi.fzL({children:[new mi.NTc({text:p?`Search Term: ${p}`:"",size:24})]}),new mi.fzL({children:[new mi.NTc({text:"ALL"!==I?`Status Filter: ${I}`:"",size:24})]}),...e.map((e=>[new mi.fzL({children:[new mi.NTc({text:`Order #${e.id}`,bold:!0,size:28})]}),new mi.fzL({children:[new mi.NTc({text:`Order Code: ${e.displayCode||"N/A"}`,size:24})]}),new mi.XIK({width:{size:100,type:mi.PsV.PERCENTAGE},rows:[new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL("Type")],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL("PICKUP"===e.type?"Pickup":"Delivery")],width:{size:80,type:mi.PsV.PERCENTAGE}})]}),new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL("Status")],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL(_r.find((t=>t.value===e.status))?.label||e.status)],width:{size:80,type:mi.PsV.PERCENTAGE}})]}),new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL("Total")],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL(`$${e.orderTotalAmount}`)],width:{size:80,type:mi.PsV.PERCENTAGE}})]}),new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL("Customer")],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL(e.creator?.email||"N/A")],width:{size:80,type:mi.PsV.PERCENTAGE}})]}),new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL("Phone")],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL(e.creator?.mobile||"N/A")],width:{size:80,type:mi.PsV.PERCENTAGE}})]}),new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL("Address")],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL("PICKUP"===e.type?e.pickupAddress?.address:e.address?.address||"N/A")],width:{size:80,type:mi.PsV.PERCENTAGE}})]})]}),...e.customOrder?[new mi.fzL({children:[new mi.NTc({text:"Custom Order Details",bold:!0,size:24})]}),new mi.XIK({width:{size:100,type:mi.PsV.PERCENTAGE},rows:e.customOrder.split("\n\n").map((e=>{const[t,...s]=e.split("\n");return t&&s.length>0?new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL(t)],width:{size:30,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL({children:s.map(((e,t)=>[new mi.NTc(e),...t0?[new mi.fzL({children:[new mi.NTc({text:"Items",bold:!0,size:24})]}),new mi.XIK({width:{size:100,type:mi.PsV.PERCENTAGE},rows:[new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL("Product")],width:{size:40,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL("Quantity")],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL("Price")],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL("Total")],width:{size:20,type:mi.PsV.PERCENTAGE}})]}),...e.orderItems.edges.map((e=>{let{node:t}=e;const s=t.product?.inventoryItems?.edges[0]?.node?.price||0;return new mi.Hjg({children:[new mi.nA6({children:[new mi.fzL(t.product?.name||"N/A")],width:{size:40,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL(t.quantity.toString())],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL(`$${s}`)],width:{size:20,type:mi.PsV.PERCENTAGE}}),new mi.nA6({children:[new mi.fzL("$"+t.quantity*s)],width:{size:20,type:mi.PsV.PERCENTAGE}})]})}))]})]:[],new mi.fzL({})])).flat()]}]}))(e),s=await mi.ND6.toBlob(t);(0,hi.saveAs)(s,`orders_${(new Date).toISOString().replace(/[-:]/g,"").replace("T","_").replace("Z","")}.docx`)}K({open:!0,message:`Orders downloaded successfully in ${t.toUpperCase()} format!`,severity:"success"})}catch(e){K({open:!0,message:"Failed to download orders. Please try again.",severity:"error"})}re(!1)};return he||Pe||je||de?(0,ne.jsx)(wn,{children:(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,ne.jsx)(b.A,{})})}):!Fe&&!fe||de?(0,ne.jsx)(wn,{children:(0,ne.jsxs)(f.A,{sx:{p:3},children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Store Orders"}),m&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:m}),(0,ne.jsx)(we.A,{sx:{mb:3},children:(0,ne.jsx)(ke.A,{children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:3,children:(0,ne.jsx)(le.A,{fullWidth:!0,placeholder:"Search orders...",value:p,onChange:e=>j(e.target.value),InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(Sr.A,{})})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:3,children:(0,ne.jsxs)(le.A,{select:!0,fullWidth:!0,label:"Filter by Status",value:I,onChange:e=>S(e.target.value),InputProps:{startAdornment:(0,ne.jsx)(ye.A,{position:"start",children:(0,ne.jsx)(oi.A,{})})},children:[(0,ne.jsx)(Ie.A,{value:"ALL",children:"All Statuses"}),_r.map((e=>(0,ne.jsx)(Ie.A,{value:e.value,children:e.label},e.value)))]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:3,children:(0,ne.jsxs)(y.A,{variant:"body2",color:"textSecondary",children:["Total Orders: ",Ue.length]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:3,children:(0,ne.jsx)(ae.A,{fullWidth:!0,variant:"contained",startIcon:(0,ne.jsx)(li.A,{}),onClick:()=>re(!0),disabled:0===Ue.length,children:"Download Orders"})})]})})}),0===Ue.length?(0,ne.jsx)(xe.A,{severity:"info",sx:{mb:2},children:"No orders found."}):(0,ne.jsxs)(Ar.A,{component:me.A,children:[(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>qe("id"),children:["Order ID",(0,ne.jsx)(di.A,{sx:{ml:1,transform:"id"===C&&"desc"===P?"rotate(180deg)":"none"}})]})}),(0,ne.jsx)(fr.A,{children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",cursor:"pointer"},onClick:()=>qe("totalAmount"),children:["Total",(0,ne.jsx)(di.A,{sx:{ml:1,transform:"totalAmount"===C&&"desc"===P?"rotate(180deg)":"none"}})]})}),(0,ne.jsx)(fr.A,{children:"Status"}),(0,ne.jsx)(fr.A,{children:"Actions"}),(0,ne.jsx)(fr.A,{})]})}),(0,ne.jsx)(br.A,{children:Ne.map((e=>{return(0,ne.jsxs)(A.Fragment,{children:[(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.id}),(0,ne.jsxs)(fr.A,{children:["$",e.orderTotalAmount]}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:_r.find((t=>t.value===e.status))?.label||e.status,color:(t=e.status,_r.find((e=>e.value===t))?.color||"default"),size:"small"})}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(De.A,{title:"Edit Order",children:(0,ne.jsx)(be.A,{size:"small",onClick:()=>(e=>{c(e),u(e.status),B(e.deliveryInstructions||""),a(!0)})(e),disabled:!Me(e.status),children:(0,ne.jsx)(Ir.A,{})})}),(0,ne.jsx)(De.A,{title:"Cancel Order",children:(0,ne.jsx)(be.A,{size:"small",onClick:()=>(e=>{c(e),l(!0)})(e),disabled:!Me(e.status),children:(0,ne.jsx)(Nr.A,{})})}),(0,ne.jsx)(De.A,{title:"Upload File",children:(0,ne.jsx)(be.A,{size:"small",onClick:()=>(async e=>{const t=document.createElement("input");t.type="file",t.accept="*/*",t.onchange=async()=>{try{const s=t.files[0];if(!s)return;const 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(s.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:s});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?K({open:!0,message:"File uploaded and verified successfully!",severity:"success"}):K({open:!0,message:"File uploaded but verification failed. Please try viewing the file.",severity:"warning"})}catch(e){K({open:!0,message:"Failed to upload file. Please try again.",severity:"error"})}},t.click()})(e),disabled:!Me(e.status),children:(0,ne.jsx)(qr.A,{})})}),(0,ne.jsx)(De.A,{title:"View File",children:(0,ne.jsx)(be.A,{size:"small",onClick:()=>(async e=>{try{const t=window.location.href?.includes("http://localhost")?"http://127.0.0.1:8000":"https://indimitra.com";let s=null,r=null;if(e.bill_url){const n=await fetch(`${t}/s3/generate-view-url?bill_key=${encodeURIComponent(e.bill_url)}`);if(n.ok){const e=await n.json();s=e.view_url,r=e.file_name}}if(!s){const n=[".pdf",".jpg",".jpeg",".png",".docx"];for(const i of n){const n=await fetch(`${t}/s3/generate-view-url?order_id=${e.id}&file_name=receipt${i}`);if(n.ok){const e=await n.json();s=e.view_url,r=e.file_name;break}}}if(!s)return void K({open:!0,message:"No file found for this order.",severity:"warning"});const n=document.createElement("a");n.href=s,n.target="_blank",n.rel="noopener noreferrer",document.body.appendChild(n),n.click(),document.body.removeChild(n)}catch(e){K({open:!0,message:"Failed to view file. Please try again.",severity:"error"})}})(e),children:(0,ne.jsx)(Mr.A,{})})})]}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(be.A,{size:"small",onClick:()=>n(r===e.id?null:e.id),children:r===e.id?(0,ne.jsx)(ti.A,{}):(0,ne.jsx)(si.A,{})})})]}),r===e.id&&(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:6,children:(0,ne.jsx)(f.A,{sx:{p:2},children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Information"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(y.A,{children:[(0,ne.jsx)("strong",{children:"Order Code:"})," ",e.displayCode||"N/A"]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(y.A,{children:[(0,ne.jsx)("strong",{children:"Type:"})," ","PICKUP"===e.type?(0,ne.jsxs)(f.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(Xt.A,{fontSize:"small"}),"Pickup Order"]}):(0,ne.jsxs)(f.A,{component:"span",sx:{display:"flex",alignItems:"center",gap:1},children:[(0,ne.jsx)(qt.A,{fontSize:"small"}),"Delivery Order"]})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsxs)(y.A,{children:[(0,ne.jsx)("strong",{children:"Address:"})," ","PICKUP"===e.type?e.pickupAddress?.address||"No pickup address":e.address?.address||"No delivery address"]})})]})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Customer Information"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{children:["Email: ",e?.creator?.email||"N/A"]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(y.A,{children:["Phone: ",e?.creator?.mobile||"N/A"]})})]})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Items"}),(0,ne.jsxs)(gr.A,{size:"small",children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Product"}),(0,ne.jsx)(fr.A,{children:"Quantity"}),(0,ne.jsx)(fr.A,{children:"Price"}),(0,ne.jsx)(fr.A,{children:"Total"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:e.orderItems?.edges?.length>0?Be(e.orderItems)?.map((t=>{const s=(r=t,n=e.orderItems.edges,r&&n?n.map((e=>{let{node:t}=e;return t})).filter((e=>e.productId===r.productId)).sort(((e,t)=>e.id-t.id)):[r]);var r,n;const i=t.product?.inventoryItems?.edges[0]?.node?.price||0;return(0,ne.jsxs)(A.Fragment,{children:[(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:t.product?.name||"N/A"}),(0,ne.jsx)(fr.A,{children:t.quantity}),(0,ne.jsx)(fr.A,{children:ci(i)}),(0,ne.jsx)(fr.A,{children:ci(t.quantity*i)}),(0,ne.jsx)(fr.A,{children:Me(e.status)&&(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(be.A,{size:"small",onClick:()=>{return s=t,r=e.id,Z({...s,orderId:r}),ee(s.quantity),void X(!0);var s,r},sx:{mr:1},children:(0,ne.jsx)(Ir.A,{fontSize:"small"})}),(0,ne.jsx)(be.A,{size:"small",onClick:()=>{return s=t,r=e.id,Z({...s,orderId:r}),ee(0),void X(!0);var s,r},color:"error",children:(0,ne.jsx)(Er.A,{fontSize:"small"})})]})})]}),(t.instructions||null!==t.allowSubstitute)&&(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:5,sx:{py:1,borderBottom:"none"},children:(0,ne.jsxs)(f.A,{sx:{pl:2,display:"flex",flexDirection:"column",gap:.5},children:[t.instructions&&(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:"text.secondary"},children:[(0,ne.jsx)("strong",{children:"Instructions:"})," ",(0,ne.jsx)("em",{children:t.instructions})]}),(0,ne.jsxs)(y.A,{variant:"body2",sx:{color:t.allowSubstitute?"warning.dark":"error.main",fontWeight:500},children:[(0,ne.jsx)("strong",{children:"If unavailable:"})," ",t.allowSubstitute?"Replace with a similar item":"Cancel this item"]})]})})}),s.length>1&&(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:5,children:(0,ne.jsxs)(f.A,{sx:{pl:2,py:1},children:[(0,ne.jsxs)(y.A,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1},children:["Order Change History (",s.length-1," ","changes)"]}),s.slice(0,-1).map(((e,t)=>(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",gap:2,color:"text.secondary",bgcolor:"grey.50",p:1,borderRadius:1,mb:1},children:[(0,ne.jsxs)(y.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary",minWidth:"100px"},children:["Change ",t+1]}),(0,ne.jsxs)(f.A,{sx:{display:"flex",gap:3},children:[(0,ne.jsxs)(y.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Quantity: ",e.quantity]}),(0,ne.jsxs)(y.A,{variant:"caption",sx:{textDecoration:"line-through",color:"text.secondary"},children:["Amount:"," ",ci(e.orderAmount)]})]})]},e.id)))]})})})]},t.id)})):(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:5,align:"center",children:"No items found for this order"})})})]})]}),e.customOrder&&(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Custom Order Details"}),(0,ne.jsx)(f.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:e.customOrder.split("\n\n").map(((e,t)=>{const[s,...r]=e.split("\n");return s&&r.length>0?(0,ne.jsxs)(f.A,{sx:{mb:2},children:[(0,ne.jsx)(y.A,{variant:"subtitle2",sx:{color:"text.secondary",mb:.5},children:s}),(0,ne.jsx)(f.A,{sx:{pl:2},children:r.map(((e,t)=>(0,ne.jsx)(y.A,{variant:"body2",sx:{mb:.5},children:e},t)))})]},t):null}))})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Order Summary"}),(0,ne.jsx)(f.A,{sx:{bgcolor:"grey.50",p:2,borderRadius:1},children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:1,children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,children:(0,ne.jsx)(y.A,{children:"Subtotal:"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ne.jsx)(y.A,{children:ci(e.totalAmount)})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,children:(0,ne.jsx)(y.A,{children:"Delivery Fee:"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ne.jsx)(y.A,{children:ci(e.deliveryFee)})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,children:(0,ne.jsx)(y.A,{children:"Tax:"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ne.jsx)(y.A,{children:ci(e.taxAmount)})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,children:(0,ne.jsx)(y.A,{children:"Tip:"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ne.jsx)(y.A,{children:ci(e.tipAmount)})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(Ct.A,{sx:{my:1}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,children:(0,ne.jsx)(y.A,{sx:{fontWeight:"bold"},children:"Total Amount:"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,sx:{textAlign:"right"},children:(0,ne.jsx)(y.A,{sx:{fontWeight:"bold"},children:ci(e.orderTotalAmount)})})]})})]}),e.deliveryInstructions&&(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(y.A,{variant:"subtitle1",gutterBottom:!0,sx:{fontWeight:"bold"},children:"Delivery Instructions"}),(0,ne.jsx)(y.A,{children:e.deliveryInstructions})]})]})})})})]},e.id);var t}))})]}),(0,ne.jsx)(v.A,{component:"div",count:Ue.length,page:E,onPageChange:(e,t)=>{L(t)},rowsPerPage:W,onRowsPerPageChange:e=>{q(parseInt(e.target.value,10)),L(0)},rowsPerPageOptions:[5,10,25,50]})]}),(0,ne.jsxs)(it.A,{open:i,onClose:()=>a(!1),maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:"Update Order Status"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{select:!0,fullWidth:!0,label:"Status",value:x,onChange:e=>u(e.target.value),children:_r.map((e=>(0,ne.jsx)(Ie.A,{value:e.value,children:e.label},e.value)))})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Delivery Instructions",value:N,onChange:e=>B(e.target.value),multiline:!0,rows:3})}),"READY_FOR_DELIVERY"===x&&(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,required:!0,children:[(0,ne.jsx)($e.A,{children:"Delivery Agent"}),(0,ne.jsx)(Le.A,{value:M,onChange:e=>_(e.target.value),label:"Delivery Agent",children:ge?.getStoreDrivers?.map((e=>(0,ne.jsxs)(Ie.A,{value:e.userId,children:[e.driver.email," (",e.driver.mobile,")"]},e.userId)))})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:6,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Schedule Time",value:V,onChange:e=>H(e.target.value),type:"datetime-local",required:!0,InputLabelProps:{shrink:!0}})})]})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>a(!1),children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:async()=>{try{const e={orderId:d.id,status:x,deliveryInstructions:N};if("READY"===x||"READY_FOR_DELIVERY"===x){if(!M)return void h("Driver ID is required for this status");if(!V)return void h("Schedule time is required for this status");e.driverId=parseInt(M),e.scheduleTime=V}await Te.mutateAsync(e)}catch(e){h(e.message)}},variant:"contained",color:"primary",disabled:Te.isPending,children:Te.isPending?"Updating...":"Update"})]})]}),(0,ne.jsxs)(it.A,{open:o,onClose:()=>l(!1),children:[(0,ne.jsx)(at.A,{children:"Cancel Order"}),(0,ne.jsxs)(ot.A,{children:[(0,ne.jsx)(y.A,{children:"Are you sure you want to cancel this order? This action cannot be undone."}),(0,ne.jsx)(le.A,{fullWidth:!0,label:"Cancellation Reason",value:O,onChange:e=>U(e.target.value),multiline:!0,rows:3,sx:{mt:2},required:!0})]}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>l(!1),disabled:We.isPending||We.isLoading,children:"No"}),(0,ne.jsx)(ae.A,{onClick:async()=>{try{if(!Ae)return void h("User profile not found. Please try again.");We.mutate({orderId:d.id,cancelMessage:O,cancelledByUserId:Ae})}catch(e){h(e.message)}},variant:"contained",color:"error",disabled:!O.trim()||We.isPending||We.isLoading,startIcon:We.isPending||We.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:We.isPending||We.isLoading?"Cancelling...":"Yes, Cancel Order"})]})]}),(0,ne.jsxs)(it.A,{open:Y,onClose:()=>X(!1),maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:0===J?"Delete Order Item":"Edit Order Item"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsxs)(y.A,{variant:"subtitle1",children:["Product: ",Q?.product?.name||"N/A"]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,children:(0,ne.jsx)(le.A,{fullWidth:!0,label:"Quantity",type:"number",value:J,onChange:e=>ee(parseInt(e.target.value)||0),inputProps:{min:0}})})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>X(!1),children:"Cancel"}),(0,ne.jsx)(ae.A,{onClick:async()=>{try{await Re.mutateAsync({orderId:Q.orderId,itemId:Q.id,quantity:J,price:Q.product?.inventoryItems?.edges[0]?.node?.price||0})}catch(e){h(e.message)}},variant:"contained",color:0===J?"error":"primary",disabled:Re.isLoading,children:Re.isLoading?"Updating...":0===J?"Delete":"Update"})]})]}),(0,ne.jsxs)(it.A,{open:se,onClose:()=>re(!1),maxWidth:"xs",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:"Download Orders"}),(0,ne.jsxs)(ot.A,{children:[(0,ne.jsxs)(y.A,{variant:"body1",gutterBottom:!0,children:["Download ",Ue.length," filtered orders"]}),(0,ne.jsxs)(y.A,{variant:"body2",color:"textSecondary",gutterBottom:!0,children:[p&&`Search term: ${p}`,"ALL"!==I&&`\nStatus: ${I}`]}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,sx:{mt:1},children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,children:(0,ne.jsx)(ae.A,{fullWidth:!0,variant:"outlined",onClick:()=>_e(Ue,"pdf"),startIcon:(0,ne.jsx)(li.A,{}),children:"PDF"})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:6,children:(0,ne.jsx)(ae.A,{fullWidth:!0,variant:"outlined",onClick:()=>_e(Ue,"docx"),startIcon:(0,ne.jsx)(li.A,{}),children:"DOCX"})})]})]}),(0,ne.jsx)(lt.A,{children:(0,ne.jsx)(ae.A,{onClick:()=>re(!1),children:"Cancel"})})]}),(0,ne.jsx)(vr.A,{open:G.open,autoHideDuration:6e3,onClose:()=>K({...G,open:!1}),children:(0,ne.jsx)(xe.A,{onClose:()=>K({...G,open:!1}),severity:G.severity,sx:{width:"100%"},children:G.message})})]})}):(0,ne.jsx)(wn,{children:(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:Fe?.message||fe?.message||"An error occurred"})})},gi=[{value:"ACTIVE",label:"Active"},{value:"INACTIVE",label:"Inactive"}],yi=()=>{const{userProfile:e,setUserProfile:t}=te(),[s,r]=(0,A.useState)(""),[n,i]=(0,A.useState)(null),[a,o]=(0,A.useState)({driverStatus:"",orderStatus:"",dateRange:"all"}),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(null);(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,us.T)();r(e.sub)}catch(e){}})()}),[]);const{data:u,isLoading:m}=(0,g.I)({queryKey:["getUserProfile",s],queryFn:async()=>{const e=await $(D,{userId:s});return e?.getUserProfile&&t(e.getUserProfile),e},enabled:!!s}),h=u?.getUserProfile?.stores?.edges?.[0]?.node?.id,{data:p,isLoading:j,error:v,refetch:I}=(0,g.I)({queryKey:["driversByStore",h],queryFn:()=>$("\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:h}),enabled:!!h&&l}),{data:S,isLoading:C,error:w,refetch:P}=(0,g.I)({queryKey:["storeOrders",h],queryFn:async()=>(await $(z,{storeId:h})).getOrdersByStore||[],enabled:!!h}),k=(e,t)=>{o((s=>({...s,[e]:t})))},E=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"),L=(e,t)=>{if(!e)return[];let s=e.filter((e=>e?.delivery?.driverId===t));if(a.orderStatus&&(s=s.filter((e=>e.status===a.orderStatus))),"all"!==a.dateRange){const e=new Date,t=new Date(e.getFullYear(),e.getMonth(),e.getDate());s=s.filter((e=>{const s=new Date(e.createdAt);switch(a.dateRange){case"today":return s>=t;case"week":const e=new Date(t);return e.setDate(e.getDate()-7),s>=e;case"month":const r=new Date(t);return r.setMonth(r.getMonth()-1),s>=r;default:return!0}}))}return s},F=e=>e?a.driverStatus?e.filter((e=>e.status===a.driverStatus)):e:[],T=j||C||m,R=v||w||c;return(0,ne.jsx)(wn,{children:(0,ne.jsxs)(f.A,{sx:{p:3},children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Delivery Partners"}),c&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:c}),m&&(0,ne.jsx)(xe.A,{severity:"info",sx:{mb:2},children:"Loading user profile..."}),(0,ne.jsxs)(me.A,{sx:{p:3,mb:3},children:[(0,ne.jsx)(y.A,{variant:"h6",gutterBottom:!0,children:"Filters"}),(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:4,children:(0,ne.jsxs)(le.A,{select:!0,fullWidth:!0,label:"Driver Status",value:a.driverStatus,onChange:e=>k("driverStatus",e.target.value),children:[(0,ne.jsx)(Ie.A,{value:"",children:"All Statuses"}),gi.map((e=>(0,ne.jsx)(Ie.A,{value:e.value,children:e.label},e.value)))]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:4,children:(0,ne.jsxs)(le.A,{select:!0,fullWidth:!0,label:"Order Status",value:a.orderStatus,onChange:e=>k("orderStatus",e.target.value),children:[(0,ne.jsx)(Ie.A,{value:"",children:"All Statuses"}),_r.map((e=>(0,ne.jsx)(Ie.A,{value:e.value,children:e.label},e.value)))]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,sm:4,children:(0,ne.jsxs)(le.A,{select:!0,fullWidth:!0,label:"Date Range",value:a.dateRange,onChange:e=>k("dateRange",e.target.value),children:[(0,ne.jsx)(Ie.A,{value:"all",children:"All Time"}),(0,ne.jsx)(Ie.A,{value:"today",children:"Today"}),(0,ne.jsx)(Ie.A,{value:"week",children:"Last 7 Days"}),(0,ne.jsx)(Ie.A,{value:"month",children:"Last 30 Days"})]})}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,children:[(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:(0,ne.jsx)(Sr.A,{}),onClick:()=>{d(!0),I(),P()},disabled:!h||m,children:m?"Loading Profile...":"Get Data"}),!h&&!m&&(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",sx:{mt:1},children:"Store ID not available. Please check if you have a store assigned."})]})]})]}),T?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",p:3},children:(0,ne.jsx)(b.A,{})}):R?(0,ne.jsx)(xe.A,{severity:"error",children:v?.message||w?.message||"An error occurred while fetching data"}):l?(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsxs)(y.A,{variant:"h6",gutterBottom:!0,children:["Delivery Partners (",F(p?.getStoreDrivers||[]).length,")"]}),(0,ne.jsx)(Ar.A,{component:me.A,children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Driver ID"}),(0,ne.jsx)(fr.A,{children:"Name"}),(0,ne.jsx)(fr.A,{children:"Email"}),(0,ne.jsx)(fr.A,{children:"Phone"}),(0,ne.jsx)(fr.A,{children:"Status"}),(0,ne.jsx)(fr.A,{children:"Orders"}),(0,ne.jsx)(fr.A,{})]})}),(0,ne.jsxs)(br.A,{children:[F(p?.getStoreDrivers||[]).map((e=>(0,ne.jsxs)(A.Fragment,{children:[(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e?.userId}),(0,ne.jsx)(fr.A,{children:e.name}),(0,ne.jsx)(fr.A,{children:e?.driver?.email}),(0,ne.jsx)(fr.A,{children:e?.driver?.mobile}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:e?.driver?.active?"Active":"Inactive",color:E(e?.driver?.active),size:"small"})}),(0,ne.jsx)(fr.A,{children:L(S||[],e?.userId).length}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(be.A,{size:"small",onClick:()=>i(n===e?.userId?null:e?.userId),children:n===e?.userId?(0,ne.jsx)(En.A,{}):(0,ne.jsx)(Kt.A,{})})})]}),n===e?.userId&&(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:7,children:(0,ne.jsxs)(f.A,{sx:{p:2},children:[(0,ne.jsxs)(y.A,{variant:"subtitle2",gutterBottom:!0,children:["Orders for ",e.name,":"]}),(0,ne.jsxs)(gr.A,{size:"small",children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Order ID"}),(0,ne.jsx)(fr.A,{children:"Date"}),(0,ne.jsx)(fr.A,{children:"Customer"}),(0,ne.jsx)(fr.A,{children:"Total"}),(0,ne.jsx)(fr.A,{children:"Status"})]})}),(0,ne.jsx)(br.A,{children:L(S||[],e?.userId).length>0?L(S||[],e?.userId).map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.id}),(0,ne.jsx)(fr.A,{children:new Date(e.createdAt).toLocaleDateString()}),(0,ne.jsx)(fr.A,{children:e.user?.name}),(0,ne.jsxs)(fr.A,{children:["₹",e.totalAmount]}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(Oe.A,{label:_r.find((t=>t.value===e.status))?.label||e.status,color:E(e.status),size:"small"})})]},e.id))):(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:5,align:"center",children:"No orders found for this driver with the current filters."})})})]})]})})})]},e?.userId))),0===F(p?.getStoreDrivers||[]).length&&(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:7,align:"center",children:"No delivery partners found with the current filters."})})]})]})})]}):(0,ne.jsx)(xe.A,{severity:"info",children:'Click the "Get Data" button to fetch delivery partners and their orders.'})]})})};var ji=s(69279);const fi=["meat","poultry","seafood","fish"],bi=e=>{if(!e)return!1;const t=e.toLowerCase();return fi.some((e=>t.includes(e)))},vi=A.memo((e=>{let{open:t,onClose:s,selectedItem:r,onUpdate:n,isLoading:i,meatCuts:a,isLoadingMeatCuts:o}=e;const l=(0,qe.A)(),[d,c]=A.useState(""),[x,u]=A.useState(""),[m,h]=A.useState(!0),[p,g]=A.useState(!0),[j,v]=A.useState([]),[I,S]=A.useState(""),C=bi(r?.product?.category?.name);A.useEffect((()=>{var e;r&&(c(r.price?r.price.toString():""),u(r.quantity?r.quantity.toString():""),h(void 0===r.isAvailable||r.isAvailable),g(void 0===r.isListed||r.isListed),v((e=r,Array.isArray(e?.cutTypes)?e.cutTypes.filter(Boolean):[])))}),[r]);const w={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:l.palette.info.main,borderWidth:"2px"}},P={fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)",marginBottom:"4px",display:"block"};return(0,ne.jsxs)(it.A,{open:t,onClose:()=>{S(""),s()},maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:"Edit Inventory Item"}),(0,ne.jsxs)(ot.A,{children:[r&&(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center",mb:2},children:[r.product?.image&&(0,ne.jsx)(Pe.A,{component:"img",sx:{width:80,height:80,objectFit:"contain",mr:2},image:r.product.image,alt:r.product.name}),(0,ne.jsxs)(f.A,{children:[(0,ne.jsx)(y.A,{variant:"subtitle1",children:(0,ne.jsx)("strong",{children:r.product?.name})}),(0,ne.jsx)(y.A,{variant:"body2",color:"text.secondary",children:r.product?.category?.name||"Uncategorized"})]})]}),(0,ne.jsx)(Ct.A,{sx:{my:2}}),(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsx)("label",{htmlFor:"edit-price-input",style:P,children:"Price ($)"}),(0,ne.jsx)("input",{id:"edit-price-input",type:"number",value:d,onChange:e=>c(e.target.value),min:"0",step:"0.01",style:w}),(0,ne.jsx)("label",{htmlFor:"edit-quantity-input",style:P,children:"Quantity"}),(0,ne.jsx)("input",{id:"edit-quantity-input",type:"number",value:x,onChange:e=>u(e.target.value),min:"0",style:w}),(0,ne.jsxs)(f.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(Qe.A,{checked:m,onChange:e=>h(e.target.checked),color:"primary"}),label:"Available (In Stock)"}),(0,ne.jsx)(Xe.A,{control:(0,ne.jsx)(Qe.A,{checked:p,onChange:e=>g(e.target.checked),color:"primary"}),label:"Listed (Visible to Customers)"})]}),C&&(0,ne.jsx)(f.A,{sx:{mt:3},children:(0,ne.jsx)(Xr.A,{multiple:!0,options:a||[],loading:o,value:j,onChange:(e,t)=>v(t),getOptionLabel:e=>e.label||"",isOptionEqualToValue:(e,t)=>e.id===t.id,renderInput:e=>(0,ne.jsx)(le.A,{...e,label:"Meat Cuts",placeholder:"Assign cut types",helperText:"Leave empty for no specific cuts. You may select one or multiple."})})})]})]}),I&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mt:2},children:I})]}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{S(""),s()},disabled:i,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",onClick:()=>{if(!d||isNaN(parseFloat(d))||parseFloat(d)<=0)return void S("Please enter a valid price greater than zero.");if(!x||isNaN(parseInt(x,10))||parseInt(x,10)<0)return void S("Please enter a valid quantity (0 or greater).");S("");const e={inventoryId:r.id,price:d,quantity:x,isAvailable:m,isListed:p};C&&(e.meatCutIds=j.map((e=>parseInt(e.id,10)))),n(e)},disabled:i,startIcon:i?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:i?"Updating...":"Update"})]})]})})),Ii=A.memo((e=>{let{open:t,onClose:s,storeId:r,availableProducts:n,onAdd:i,isLoading:a,errorMessage:o,meatCuts:l,isLoadingMeatCuts:d}=e;const c=(0,qe.A)(),[x,u]=(0,A.useState)(null),[m,h]=(0,A.useState)({price:"",quantity:"",measurement:"",unit:"",searchInput:""}),[p,g]=(0,A.useState)([]),[y,j]=(0,A.useState)(!1),v=(0,A.useRef)(null),I=bi(x?.category?.name),S=e=>{const{name:t,value:s}=e.target;h((e=>({...e,[t]:s})))},C=A.useMemo((()=>n.filter((e=>e.name.toLowerCase().includes(m.searchInput.toLowerCase())))),[n,m.searchInput]),w=()=>{u(null),h({price:"",quantity:"",measurement:"",unit:"",searchInput:""}),g([])};A.useEffect((()=>{t||w()}),[t]);const P={width:"100%",padding:"8.5px 14px",fontSize:"1rem",borderRadius:"4px",border:"1px solid rgba(0, 0, 0, 0.23)",marginBottom:"16px",outline:"none"},k={fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)",marginBottom:"4px",display:"block"};return(0,ne.jsxs)(it.A,{open:t,onClose:()=>{s(),w()},maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:"Add Product to Inventory"}),(0,ne.jsxs)(ot.A,{children:[(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsx)("label",{htmlFor:"searchInput",style:k,children:"Search Product"}),(0,ne.jsxs)("div",{style:{position:"relative"},children:[(0,ne.jsx)("input",{id:"searchInput",name:"searchInput",type:"text",placeholder:"Start typing to search...",value:m.searchInput,onChange:e=>{S(e),j(!0)},onFocus:()=>j(!0),style:P,ref:v}),a&&(0,ne.jsx)(b.A,{size:20,style:{position:"absolute",right:"10px",top:"50%",transform:"translateY(-50%)"}})]}),y&&C.length>0&&(0,ne.jsx)("div",{style:{position:"absolute",width:v.current?.offsetWidth,zIndex:1300,backgroundColor:c.palette.background.paper,border:"1px solid rgba(0, 0, 0, 0.23)",borderRadius:"4px",maxHeight:"300px",overflow:"auto"},children:C.map((e=>(0,ne.jsxs)("div",{onClick:()=>(e=>{u(e),h((t=>({...t,searchInput:e.name}))),g([]),j(!1)})(e),style:{padding:"8px 16px",cursor:"pointer",backgroundColor:x?.id===e.id?"rgba(0, 0, 0, 0.04)":"transparent","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.08)"}},children:[(0,ne.jsx)("div",{children:e.name}),(0,ne.jsx)("div",{style:{fontSize:"0.875rem",color:"rgba(0, 0, 0, 0.6)"},children:e.category.name})]},e.id)))})]}),(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsx)("label",{htmlFor:"price",style:k,children:"Price ($)"}),(0,ne.jsx)("input",{id:"price",name:"price",type:"number",value:m.price,onChange:S,min:"0",step:"0.01",style:P})]}),(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsx)("label",{htmlFor:"quantity",style:k,children:"Quantity"}),(0,ne.jsx)("input",{id:"quantity",name:"quantity",type:"number",value:m.quantity,onChange:S,min:"0",style:P})]}),(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsx)("label",{htmlFor:"measurement",style:k,children:"Measurement"}),(0,ne.jsx)("input",{id:"measurement",name:"measurement",type:"number",value:m.measurement,onChange:S,min:"0",style:P})]}),(0,ne.jsxs)(f.A,{sx:{mt:2},children:[(0,ne.jsx)("label",{htmlFor:"unit",style:k,children:"Unit"}),(0,ne.jsxs)("select",{id:"unit",name:"unit",value:m.unit,onChange:S,style:{...P,backgroundColor:"transparent",appearance:"auto",height:"40px"},children:[(0,ne.jsx)("option",{value:"",children:"None"}),(0,ne.jsx)("option",{value:"1",children:"Grams (g)"}),(0,ne.jsx)("option",{value:"2",children:"Kilograms (kg)"}),(0,ne.jsx)("option",{value:"3",children:"Milliliters (ml)"}),(0,ne.jsx)("option",{value:"4",children:"Liters (L)"}),(0,ne.jsx)("option",{value:"5",children:"Pieces (pcs)"})]})]}),I&&(0,ne.jsx)(f.A,{sx:{mt:2},children:(0,ne.jsx)(Xr.A,{multiple:!0,options:l||[],loading:d,value:p,onChange:(e,t)=>g(t),getOptionLabel:e=>e.label||"",isOptionEqualToValue:(e,t)=>e.id===t.id,renderInput:e=>(0,ne.jsx)(le.A,{...e,label:"Meat Cuts",placeholder:"Assign cut types",helperText:"Leave empty for no specific cuts. You may select one or multiple."})})}),o&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mt:2},children:o})]}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{s(),w()},disabled:a,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",onClick:()=>{if(!x)return;const e={storeId:r,productId:x.id,price:m.price,quantity:m.quantity,measurement:m.measurement||null,unit:m.unit||null};I&&(e.meatCutIds=p.map((e=>parseInt(e.id,10)))),i(e)},disabled:a||!x||!m.price||!m.quantity,startIcon:a?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:a?"Adding Product...":"Add Product"})]})]})})),Si=()=>{const[e,t]=(0,A.useState)(""),{userProfile:s,setUserProfile:r}=te(),[n,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(null),[c,x]=(0,A.useState)(""),[u,m]=(0,A.useState)(""),[h,p]=(0,A.useState)(""),[v,I]=(0,A.useState)(!1),[S,C]=(0,A.useState)(10),[w,P]=(0,A.useState)(1),[k]=(0,A.useState)(10),[E,L]=(0,A.useState)("all"),[F,D]=(0,A.useState)([]),[z,T]=(0,A.useState)(!1),[R,W]=(0,A.useState)(!0);(0,A.useRef)(null),(0,A.useRef)(null);(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,us.T)();t(e.sub)}catch(e){}})()}),[]);const{data:q,isLoading:O}=(0,g.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const t=await $("\n query GetUserProfile($userId: String!) {\n getUserProfile(userId: $userId) {\n id\n email\n mobile\n active\n type\n referralId\n }\n }\n",{userId:e});return t?.getUserProfile&&r(t.getUserProfile),t},enabled:!!e}),{data:U,isLoading:N,error:B,refetch:M}=(0,g.I)({queryKey:["storeWithInventory",s?.id],queryFn:()=>$("\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 cutTypes {\n id\n label\n text\n }\n product {\n id\n name\n description\n category {\n id\n name\n }\n image\n }\n }\n }\n }\n }\n products {\n id\n name\n description\n category {\n id\n name\n }\n }\n }\n",{managerId:s?.id}),enabled:!!s?.id});(0,A.useEffect)((()=>{U&&U.products&&W(!1)}),[U]);const{data:_=[],isLoading:V}=(0,g.I)({queryKey:["meatCuts"],queryFn:async()=>{const e=await $("\n query GetMeatCuts {\n meatCuts {\n id\n label\n text\n }\n }\n");return e?.meatCuts||[]},enabled:z||a}),H=U?.storesByManager&&U.storesByManager[0],G=H?.inventory?.edges?.map((e=>e.node))||[],K=U?.products||[],Y=A.useMemo((()=>G.filter((e=>{const t=""===h||e.product?.name?.toLowerCase().includes(h.toLowerCase())||e.product?.description?.toLowerCase().includes(h.toLowerCase()),s=!v||e.quantity<=S,r="all"===E||e.product?.category?.name===E;return t&&s&&r}))),[G,h,v,S,E]),X=A.useMemo((()=>Y.slice((w-1)*k,w*k)),[Y,w,k]);(0,A.useEffect)((()=>{const e=[...new Set(G.map((e=>e.product?.category?.name||"Uncategorized")).filter(Boolean))].sort();JSON.stringify(e)!==JSON.stringify(F)&&D(e)}),[G]);const Q=(0,Ft.n)({mutationFn:e=>{let{inventoryId:t,price:s,quantity:r,isAvailable:n,isListed:i,meatCutIds:a}=e;return $("\n mutation UpdateInventoryItem(\n $inventoryId: Int!\n $price: Float!\n $quantity: Int!\n $isAvailable: Boolean\n $isListed: Boolean\n $meatCutIds: [Int!]\n ) {\n updateInventoryItem(\n inventoryId: $inventoryId\n price: $price\n quantity: $quantity\n isAvailable: $isAvailable\n isListed: $isListed\n meatCutIds: $meatCutIds\n ) {\n id\n price\n quantity\n isAvailable\n isListed\n updatedAt\n cutTypes {\n id\n label\n text\n }\n }\n }\n",{inventoryId:t,price:parseFloat(s),quantity:parseInt(r,10),isAvailable:void 0!==n?n:null,isListed:void 0!==i?i:null,meatCutIds:void 0!==a?a:null})},onSuccess:()=>{M(),o(!1),i(null),m("Inventory item updated successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error updating inventory: ${e.message}`)}}),Z=(0,Ft.n)({mutationFn:e=>{let{storeId:t,productId:s,price:r,quantity:n,measurement:i,unit:a,meatCutIds:o}=e;return $("\n mutation AddProductToInventory(\n $productId: Int!\n $storeId: Int!\n $price: Float!\n $quantity: Int!\n $measurement: Int\n $unit: String\n $meatCutIds: [Int!]\n ) {\n addProductToInventory(\n productId: $productId\n storeId: $storeId\n price: $price\n quantity: $quantity\n measurement: $measurement\n unit: $unit\n meatCutIds: $meatCutIds\n ) {\n id\n measurement\n price\n productId\n quantity\n storeId\n unit\n updatedAt\n cutTypes {\n id\n label\n text\n }\n product {\n id\n name\n description\n category {\n id\n name\n }\n image\n }\n }\n }\n",{storeId:parseInt(t,10),productId:parseInt(s,10),price:parseFloat(r),quantity:parseInt(n,10),measurement:i?parseInt(i,10):null,unit:a||null,meatCutIds:void 0!==o?o:null})},onSuccess:()=>{M(),T(!1),m("Product added to inventory successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error adding product: ${e.message}`)}}),J=A.memo((e=>{let{searchTerm:t,setSearchTerm:s,filterCategory:r,setFilterCategory:n,lowStockOnly:i,setLowStockOnly:a,lowStockThreshold:o,setLowStockThreshold:l,categories:d}=e;return(0,ne.jsx)(me.A,{elevation:3,sx:{p:3,mb:4},children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,alignItems:"center",children:[(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:4,children:(0,ne.jsx)(le.A,{label:"Search Products",variant:"outlined",size:"small",value:t,onChange:e=>s(e.target.value),fullWidth:!0,InputProps:{startAdornment:(0,ne.jsx)(Sr.A,{sx:{mr:1,color:"text.secondary"}})}})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:3,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,size:"small",children:[(0,ne.jsx)($e.A,{id:"category-select-label",children:"Category"}),(0,ne.jsxs)(Le.A,{labelId:"category-select-label",id:"category-select",value:r,label:"Category",onChange:e=>n(e.target.value),children:[(0,ne.jsx)(Ie.A,{value:"all",children:"All Categories"}),d.map((e=>(0,ne.jsx)(Ie.A,{value:e,children:e},e)))]})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:3,children:(0,ne.jsxs)(Ee.A,{fullWidth:!0,size:"small",children:[(0,ne.jsx)($e.A,{id:"stock-filter-label",children:"Stock Filter"}),(0,ne.jsxs)(Le.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,ne.jsx)(Ie.A,{value:"false",children:"All Items"}),(0,ne.jsx)(Ie.A,{value:"true",children:"Low Stock Only"})]})]})}),(0,ne.jsx)(Ce.Ay,{item:!0,xs:12,md:2,children:(0,ne.jsx)(le.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||N?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})})}):B?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4},children:(0,ne.jsxs)(xe.A,{severity:"error",children:["Error loading inventory data: ",B.message]})})}):(0,ne.jsx)(wn,{children:(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Store Inventory Management"}),(0,ne.jsx)(J,{searchTerm:h,setSearchTerm:p,filterCategory:E,setFilterCategory:L,lowStockOnly:v,setLowStockOnly:I,lowStockThreshold:S,setLowStockThreshold:C,categories:F}),u&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:u}),c&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:c}),(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.A,{variant:"h5",children:"Inventory Items"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:Z.isPending||Z.isPending?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):(0,ne.jsx)(Te.A,{}),onClick:()=>T(!0),disabled:Z.isPending||Z.isPending,children:Z.isPending||Z.isPending?"Adding...":"Add Product"})]}),R?(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",my:4},children:(0,ne.jsx)(b.A,{})}):0===Y.length?(0,ne.jsx)(xe.A,{severity:"info",sx:{my:2},children:"No inventory items match your filters."}):(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsx)(Ar.A,{component:me.A,variant:"outlined",children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{}),(0,ne.jsx)(fr.A,{children:"Product"}),(0,ne.jsx)(fr.A,{children:"Category"}),(0,ne.jsx)(fr.A,{children:"Price"}),(0,ne.jsx)(fr.A,{children:"Quantity"}),(0,ne.jsx)(fr.A,{children:"Available"}),(0,ne.jsx)(fr.A,{children:"Listed"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:X.map((e=>(0,ne.jsxs)(A.Fragment,{children:[(0,ne.jsxs)(jr.A,{sx:{backgroundColor:e?.isAvailable?"inherit":"rgba(255, 0, 0, 0.1)"},children:[(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(be.A,{size:"small",onClick:()=>{return t=e.id,void d(l===t?null:t);var t},children:l===e.id?(0,ne.jsx)(En.A,{}):(0,ne.jsx)(Kt.A,{})})}),(0,ne.jsx)(fr.A,{children:(0,ne.jsxs)(f.A,{sx:{display:"flex",alignItems:"center"},children:[e.product?.image&&(0,ne.jsx)(Pe.A,{component:"img",sx:{width:50,height:50,objectFit:"contain",mr:2},image:e.product.image,alt:e.product.name}),(0,ne.jsx)(y.A,{children:e.product?.name})]})}),(0,ne.jsx)(fr.A,{children:e.product?.category?.name||"Uncategorized"}),(0,ne.jsxs)(fr.A,{children:["$",e.price.toFixed(2)]}),(0,ne.jsx)(fr.A,{children:e.quantity}),(0,ne.jsx)(fr.A,{children:e?.isAvailable?(0,ne.jsx)(Oe.A,{label:"In Stock",color:"success",size:"small"}):(0,ne.jsx)(Oe.A,{label:"Low Stock",color:"error",size:"small"})}),(0,ne.jsx)(fr.A,{children:e?.isListed?(0,ne.jsx)(Oe.A,{label:"Listed",color:"success",size:"small"}):(0,ne.jsx)(Oe.A,{label:"Not Listed",color:"error",size:"small"})}),(0,ne.jsx)(fr.A,{children:(0,ne.jsx)(be.A,{onClick:()=>(e=>{e&&(i(e),o(!0))})(e),size:"small",color:"primary",disabled:Q.isPending||Q.isLoading||Z.isPending||Z.isLoading,children:(0,ne.jsx)(Ir.A,{})})})]}),(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{sx:{p:0},colSpan:7,children:(0,ne.jsx)(Ye.A,{in:l===e.id,timeout:"auto",unmountOnExit:!0,children:(0,ne.jsx)(f.A,{sx:{p:3,backgroundColor:"rgba(0, 0, 0, 0.03)"},children:(0,ne.jsxs)(Ce.Ay,{container:!0,spacing:2,children:[(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,md:6,children:[(0,ne.jsxs)(y.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,ne.jsx)("strong",{children:"Description:"})," ",e.product?.description||"No description available"]}),(0,ne.jsxs)(y.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,ne.jsx)("strong",{children:"Product ID:"})," ",e.product?.id]})]}),(0,ne.jsxs)(Ce.Ay,{item:!0,xs:12,md:6,children:[(0,ne.jsxs)(y.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,ne.jsx)("strong",{children:"Last Updated:"})," ",e.updatedAt?new Date(e.updatedAt).toLocaleString():"N/A"]}),(0,ne.jsxs)(y.A,{variant:"subtitle2",gutterBottom:!0,children:[(0,ne.jsx)("strong",{children:"Measurement:"})," ",e.measurement&&e.unit?`${e.measurement} ${e.unit}`:"N/A"]})]})]})})})})})]},e.id)))})]})}),(0,ne.jsx)(f.A,{sx:{display:"flex",justifyContent:"center",mt:3},children:(0,ne.jsx)(ji.A,{count:Math.ceil(Y.length/k),page:w,onChange:(e,t)=>P(t),color:"primary"})})]})]}),(0,ne.jsx)(vi,{open:a,onClose:()=>{o(!1),x("")},selectedItem:n,onUpdate:e=>Q.mutate(e),isLoading:Q.isPending,meatCuts:_,isLoadingMeatCuts:V}),(0,ne.jsx)(Ii,{open:z,onClose:()=>T(!1),storeId:H?.id,availableProducts:K,onAdd:Z.mutate,isLoading:Z.isPending,errorMessage:c,meatCuts:_,isLoadingMeatCuts:V})]})})},Ci=e=>{let{open:t,onClose:s,selectedLocationCode:r,onUpdate:n,isLoading:i,existingCodes:a}=e;const[o,l]=(0,A.useState)({location:"",code:""}),[d,c]=(0,A.useState)("");(0,A.useEffect)((()=>{l(r?{location:r.location||"",code:r.code||""}:{location:"",code:""}),c("")}),[r,t]);const x=()=>{l({location:"",code:""}),c(""),s()},u=e=>{const{name:t,value:s}=e.target;l((e=>({...e,[t]:s}))),c("")};return(0,ne.jsxs)(it.A,{open:t,onClose:x,maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:r?"Edit Location Code":"Add New Location Code"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(f.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ne.jsx)(le.A,{name:"location",label:"Location",value:o.location,onChange:u,fullWidth:!0,placeholder:"e.g., Main Branch",error:!!d&&d.includes("Location"),helperText:d&&d.includes("Location")?d:""}),(0,ne.jsx)(le.A,{name:"code",label:"Code",value:o.code,onChange:u,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,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:x,children:"Cancel"}),(0,ne.jsx)(ae.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,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},wi=()=>{const[e,t]=(0,A.useState)(""),{userProfile:s,setUserProfile:r}=te(),[n,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(""),[u,m]=(0,A.useState)("");(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,us.T)();t(e.sub)}catch(e){}})()}),[]);const{data:h,isLoading:p}=(0,g.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const t=await $("\n query GetUserProfile($userId: String!) {\n getUserProfile(userId: $userId) {\n id\n email\n mobile\n active\n type\n referralId\n }\n }\n",{userId:e});return t?.getUserProfile&&r(t.getUserProfile),t},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,g.I)({queryKey:["storeWithLocationCodes",s?.id],queryFn:()=>$("\n query GetStoreWithLocationCodes($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:s?.id}),enabled:!!s?.id}),C=v?.storesByManager&&v.storesByManager[0],{data:w,isLoading:P,error:k,refetch:E}=(0,g.I)({queryKey:["getStoreLocationCodesByStore",C?.id],queryFn:()=>$("\n query GetStoreLocationCodesByStore($storeId: Int!) {\n getStoreLocationCodesByStore(storeId: $storeId) {\n id\n location\n code\n }\n }\n",{storeId:C?.id}),enabled:!!C?.id}),L=w?.getStoreLocationCodesByStore||[],F=(0,Ft.n)({mutationFn:e=>{if(!C?.id)throw new Error("Store not found");return $("\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),m("Location code updated successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error updating location code: ${e.message}`),setTimeout((()=>x("")),5e3)}}),D=(0,Ft.n)({mutationFn:e=>$("\n mutation DeleteStoreLocationCode($id: Int!) {\n deleteStoreLocationCode(id: $id)\n }\n",e),onSuccess:()=>{E(),d(!1),i(null),m("Location code deleted successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error deleting location code: ${e.message}`)}}),z=(0,Ft.n)({mutationFn:e=>$("\n mutation CreateStoreLocationCode($input: CreateStoreLocationCodeInput!) {\n createStoreLocationCode(input: $input) {\n locationCode {\n id\n location\n code\n }\n error {\n message\n }\n }\n }\n",{input:{...e,storeId:C.id}}),onSuccess:()=>{E(),o(!1),i(null),m("Location code added successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error adding location code: ${e.message}`)}});return p||I||P?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})})}):S||k?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4},children:(0,ne.jsxs)(xe.A,{severity:"error",children:["Error loading data: ",S?.message||k?.message]})})}):(0,ne.jsx)(wn,{children:(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Store Location Codes Management"}),u&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:u}),c&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:c}),(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.A,{variant:"h5",children:"Location Codes"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:z.isPending||z.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):(0,ne.jsx)(Te.A,{}),onClick:()=>{i(null),o(!0)},disabled:z.isPending||z.isLoading,children:z.isPending||z.isLoading?"Adding...":"Add Location Code"})]}),0===L.length?(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Location"}),(0,ne.jsx)(fr.A,{children:"Code"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:(0,ne.jsx)(jr.A,{children:(0,ne.jsx)(fr.A,{colSpan:3,align:"center",children:(0,ne.jsx)(xe.A,{severity:"info",sx:{my:2},children:"No location codes found for this store."})})})})]})}):(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Location"}),(0,ne.jsx)(fr.A,{children:"Code"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:L.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.location}),(0,ne.jsx)(fr.A,{children:e.code}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:F.isPending||F.isLoading||D.isPending||D.isLoading||z.isPending||z.isLoading,children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:F.isPending||F.isLoading||D.isPending||D.isLoading||z.isPending||z.isLoading,children:(0,ne.jsx)(Er.A,{})})]})]},e.id)))})]})})]}),(0,ne.jsx)(Ci,{open:a,onClose:()=>{o(!1),i(null),x("")},selectedLocationCode:n,onUpdate:e=>{n?F.mutate(e):z.mutate(e)},isLoading:F.isPending||F.isLoading||z.isPending||z.isLoading,existingCodes:L}),(0,ne.jsxs)(it.A,{open:l,onClose:()=>{d(!1),i(null),x("")},children:[(0,ne.jsx)(at.A,{children:"Delete Location Code"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this location code? This action cannot be undone."})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{d(!1),i(null)},disabled:D.isPending||D.isLoading,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"error",onClick:()=>D.mutate({id:n.id}),disabled:D.isPending||D.isLoading,startIcon:D.isPending||D.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:D.isPending||D.isLoading?"Deleting...":"Delete"})]})]})]})})},Pi=e=>{let{open:t,onClose:s,selectedPickupAddress:r,onUpdate:n,isLoading:i,existingAddresses:a}=e;const[o,l]=(0,A.useState)({address:""}),[d,c]=(0,A.useState)(""),[x,u]=(0,A.useState)(!1);(0,A.useEffect)((()=>{r?(l({address:r.address||""}),u(!0)):(l({address:""}),u(!1)),c("")}),[r]);return(0,ne.jsxs)(it.A,{open:t,onClose:s,maxWidth:"sm",fullWidth:!0,children:[(0,ne.jsx)(at.A,{children:r?"Edit Pickup Address":"Add New Pickup Address"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsxs)(f.A,{sx:{mt:2,display:"flex",flexDirection:"column",gap:2},children:[(0,ne.jsx)(Vs,{value:o.address,onChange:e=>{l((t=>({...t,address:e}))),c("")},onValidAddress:u}),d&&(0,ne.jsx)(y.A,{color:"error",variant:"caption",children:d})]})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:s,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",onClick:()=>{(o.address.trim()?x?!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||!x,startIcon:i?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:i?r?"Updating...":"Adding...":"Save"})]})]})},ki=()=>{const[e,t]=(0,A.useState)(""),{userProfile:s,setUserProfile:r}=te(),[n,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(!1),[l,d]=(0,A.useState)(!1),[c,x]=(0,A.useState)(""),[u,m]=(0,A.useState)("");(0,A.useEffect)((()=>{(async()=>{try{const e=await(0,us.T)();t(e.sub)}catch(e){}})()}),[]);const{data:h,isLoading:p}=(0,g.I)({queryKey:["getUserProfile",e],queryFn:async()=>{const t=await $("\n query GetUserProfile($userId: String!) {\n getUserProfile(userId: $userId) {\n id\n email\n mobile\n active\n type\n referralId\n }\n }\n",{userId:e});return t?.getUserProfile&&r(t.getUserProfile),t},enabled:!!e}),{data:v,isLoading:I,error:S}=(0,g.I)({queryKey:["storeWithPickupAddresses",s?.id],queryFn:()=>$("\n query GetStoreWithPickupAddresses($managerId: Int!) {\n storesByManager(managerUserId: $managerId) {\n id\n name\n }\n }\n",{managerId:s?.id}),enabled:!!s?.id}),C=v?.storesByManager&&v.storesByManager[0],{data:w,isLoading:P,error:k,refetch:E}=(0,g.I)({queryKey:["getPickupAddressesByStore",C?.id],queryFn:()=>$("\n query GetPickupAddressesByStore($storeId: Int!) {\n getPickupAddressesByStore(storeId: $storeId) {\n id\n storeId\n address\n }\n }\n",{storeId:C?.id}),enabled:!!C?.id}),L=w?.getPickupAddressesByStore||[],F=(0,Ft.n)({mutationFn:e=>$("\n mutation UpdatePickupAddress($input: UpdatePickupAddressInput!) {\n updatePickupAddress(input: $input) {\n pickupAddress {\n id\n storeId\n address\n }\n error {\n message\n }\n }\n }\n",{input:e}),onSuccess:()=>{E(),o(!1),i(null),m("Pickup address updated successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error updating pickup address: ${e.message}`)}}),D=(0,Ft.n)({mutationFn:e=>$("\n mutation DeletePickupAddress($id: Int!) {\n deletePickupAddress(id: $id)\n }\n",e),onSuccess:()=>{E(),d(!1),i(null),m("Pickup address deleted successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error deleting pickup address: ${e.message}`)}}),z=(0,Ft.n)({mutationFn:e=>$("\n mutation CreatePickupAddress($input: PickupAddressInput!) {\n createPickupAddress(input: $input) {\n pickupAddress {\n id\n storeId\n address\n }\n error {\n message\n }\n }\n }\n",{input:{...e,storeId:C.id}}),onSuccess:()=>{E(),o(!1),i(null),m("Pickup address added successfully"),setTimeout((()=>m("")),3e3)},onError:e=>{x(`Error adding pickup address: ${e.message}`)}});return p||I||P?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4,display:"flex",justifyContent:"center"},children:(0,ne.jsx)(b.A,{})})}):S||k?(0,ne.jsx)(wn,{children:(0,ne.jsx)(j.A,{sx:{mt:4},children:(0,ne.jsxs)(xe.A,{severity:"error",children:["Error loading data: ",S?.message||k?.message]})})}):(0,ne.jsx)(wn,{children:(0,ne.jsxs)(j.A,{children:[(0,ne.jsx)(y.A,{variant:"h4",gutterBottom:!0,children:"Store Pickup Addresses Management"}),u&&(0,ne.jsx)(xe.A,{severity:"success",sx:{mb:2},children:u}),c&&(0,ne.jsx)(xe.A,{severity:"error",sx:{mb:2},children:c}),(0,ne.jsxs)(me.A,{elevation:3,sx:{p:3,mb:4},children:[(0,ne.jsxs)(f.A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[(0,ne.jsx)(y.A,{variant:"h5",children:"Pickup Addresses"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"primary",startIcon:z.isPending||z.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):(0,ne.jsx)(Te.A,{}),onClick:()=>{i(null),o(!0)},disabled:z.isPending||z.isLoading,children:z.isPending||z.isLoading?"Adding...":"Add Pickup Address"})]}),0===L.length?(0,ne.jsx)(xe.A,{severity:"info",sx:{my:2},children:"No pickup addresses found. Add your first pickup address to get started."}):(0,ne.jsx)(Ar.A,{children:(0,ne.jsxs)(gr.A,{children:[(0,ne.jsx)(yr.A,{children:(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:"Address"}),(0,ne.jsx)(fr.A,{children:"Actions"})]})}),(0,ne.jsx)(br.A,{children:L.map((e=>(0,ne.jsxs)(jr.A,{children:[(0,ne.jsx)(fr.A,{children:e.address}),(0,ne.jsxs)(fr.A,{children:[(0,ne.jsx)(be.A,{onClick:()=>(e=>{i(e),o(!0)})(e),color:"primary",disabled:F.isPending||F.isLoading||D.isPending||D.isLoading||z.isPending||z.isLoading,children:(0,ne.jsx)(Ir.A,{})}),(0,ne.jsx)(be.A,{onClick:()=>(e=>{i(e),d(!0)})(e),color:"error",disabled:F.isPending||F.isLoading||D.isPending||D.isLoading||z.isPending||z.isLoading,children:(0,ne.jsx)(Er.A,{})})]})]},e.id)))})]})})]}),(0,ne.jsx)(Pi,{open:a,onClose:()=>{o(!1),i(null),x("")},selectedPickupAddress:n,onUpdate:e=>{n?F.mutate(e):z.mutate(e)},isLoading:F.isPending||F.isLoading||z.isPending||z.isLoading,existingAddresses:L}),(0,ne.jsxs)(it.A,{open:l,onClose:()=>{d(!1),i(null),x("")},children:[(0,ne.jsx)(at.A,{children:"Delete Pickup Address"}),(0,ne.jsx)(ot.A,{children:(0,ne.jsx)(y.A,{children:"Are you sure you want to delete this pickup address? This action cannot be undone."})}),(0,ne.jsxs)(lt.A,{children:[(0,ne.jsx)(ae.A,{onClick:()=>{d(!1),i(null)},disabled:D.isPending||D.isLoading,children:"Cancel"}),(0,ne.jsx)(ae.A,{variant:"contained",color:"error",onClick:()=>D.mutate({id:n.id}),disabled:D.isPending||D.isLoading,startIcon:D.isPending||D.isLoading?(0,ne.jsx)(b.A,{size:18,color:"inherit"}):null,children:D.isPending||D.isLoading?"Deleting...":"Delete"})]})]})]})})},Ei=()=>{const{user:e}=te();return(0,ne.jsxs)(o.A,{theme:p,children:[(0,ne.jsx)(l.Ay,{}),(0,ne.jsxs)(d.BV,{children:[(0,ne.jsx)(d.qh,{path:Zt,element:(0,ne.jsx)(Vn,{})}),(0,ne.jsx)(d.qh,{path:os,element:(0,ne.jsx)(ir,{})}),(0,ne.jsx)(d.qh,{path:Jt,element:(0,ne.jsx)(Ss,{})}),(0,ne.jsx)(d.qh,{path:"/",element:(0,ne.jsx)(ne.Fragment,{children:(0,ne.jsx)(rr,{children:(0,ne.jsx)(Kn,{})})})}),(0,ne.jsx)(d.qh,{path:ls,element:(0,ne.jsx)(rr,{children:(0,ne.jsx)(ai,{})})}),(0,ne.jsx)(d.qh,{path:`${es}/*`,element:(0,ne.jsx)(nr,{role:"admin",children:(0,ne.jsx)(gn,{})})}),(0,ne.jsx)(d.qh,{path:ts,element:(0,ne.jsx)(nr,{role:"user",children:(0,ne.jsx)(Kn,{})})}),(0,ne.jsx)(d.qh,{path:ss,element:(0,ne.jsx)(nr,{role:"delivery_agent",children:(0,ne.jsx)(fn,{})})}),(0,ne.jsx)(d.qh,{path:is,element:(0,ne.jsx)(nr,{role:"user",children:(0,ne.jsx)(Fn,{})})}),(0,ne.jsx)(d.qh,{path:as,element:(0,ne.jsx)(nr,{children:(0,ne.jsx)(qn,{})})}),(0,ne.jsx)(d.qh,{path:rs,element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(Pn,{})})}),(0,ne.jsx)(d.qh,{path:`${rs}/orders`,element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(Ai,{})})}),(0,ne.jsx)(d.qh,{path:"/store_manager/delivery-partners",element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(yi,{})})}),(0,ne.jsx)(d.qh,{path:"/store_manager/inventory",element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(Si,{})})}),(0,ne.jsx)(d.qh,{path:"/store_manager/delivery-fees",element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(Bn,{})})}),(0,ne.jsx)(d.qh,{path:"/store_manager/location-codes",element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(wi,{})})}),(0,ne.jsx)(d.qh,{path:"/store_manager/pickup-addresses",element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(ki,{})})}),(0,ne.jsx)(d.qh,{path:"/store_manager/payment-settings",element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(_n,{})})}),(0,ne.jsx)(d.qh,{path:`${rs}/*`,element:(0,ne.jsx)(nr,{role:"store_manager",children:(0,ne.jsx)(Un,{})})}),(0,ne.jsx)(d.qh,{path:"*",element:(0,ne.jsx)(On,{})})]})]})};var $i=s(85072),Li=s.n($i),Fi=s(97825),Di=s.n(Fi),zi=s(77659),Ti=s.n(zi),Ri=s(55056),Wi=s.n(Ri),qi=s(10540),Oi=s.n(qi),Ui=s(41113),Ni=s.n(Ui),Bi=s(14767),Mi={};Mi.styleTagTransform=Ni(),Mi.setAttributes=Wi(),Mi.insert=Ti().bind(null,"head"),Mi.domAPI=Di(),Mi.insertStyleElement=Oi();Li()(Bi.A,Mi);Bi.A&&Bi.A.locals&&Bi.A.locals;const _i=window.location.href?.includes("http://localhost");let Vi="us-east-1_6NtAulnkj",Hi="1361ghg1fpt2grmchv7ttf8bbj";_i&&(Vi="us-east-1_ehhI7OmUk",Hi="1okaltgd288h6sjgc5cedlth45");const Gi={Auth:{Cognito:{region:"us-east-1",userPoolId:Vi,userPoolClientId:Hi,loginWith:{email:!0},signUpVerificationMethod:"code",userAttributes:{email:{required:!0}},allowGuestAccess:!0,passwordFormat:{minLength:8,requireLowercase:!0,requireUppercase:!0,requireNumbers:!0,requireSpecialCharacters:!0}}}};s(9023).E.configure(Gi);const Ki=new i.E({defaultOptions:{queries:{retry:3,refetchOnWindowFocus:!1},mutations:{retry:0}}});(0,r.createRoot)(document.getElementById("root")).render((0,ne.jsx)(a.Ht,{client:Ki,children:(0,ne.jsx)(n.Kd,{children:(0,ne.jsx)(Ei,{})})}))},14767:(e,t,s)=>{s.d(t,{A:()=>o});var r=s(71354),n=s.n(r),i=s(76314),a=s.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 t=a[e];if(void 0!==t)return t.exports;var s=a[e]={id:e,exports:{}};return i[e].call(s.exports,s,s.exports,o),s.exports}o.m=i,e=[],o.O=(t,s,r,n)=>{if(!s){var i=1/0;for(c=0;c=n)&&Object.keys(o.O).every((e=>o.O[e](s[l])))?s.splice(l--,1):(a=!1,n0&&e[c-1][2]>n;c--)e[c]=e[c-1];e[c]=[s,r,n]},o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},s=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,o.t=function(e,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={};t=t||[null,s({}),s([]),s(s)];for(var a=2&r&&e;"object"==typeof a&&!~t.indexOf(a);a=s(a))Object.getOwnPropertyNames(a).forEach((t=>i[t]=()=>e[t]));return i.default=()=>e,o.d(n,i),n},o.d=(e,t)=>{for(var s in t)o.o(t,s)&&!o.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce(((t,s)=>(o.f[s](e,t),t)),[])),o.u=e=>"bundle."+{354:"f07ebc5e191c17036f0a",418:"f754bb6fc8d3e0eddb47",661:"e6dbe64eea25e53717de"}[e]+".js",o.miniCssF=e=>{},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r={},n="indimitra-web:",o.l=(e,t,s,i)=>{if(r[e])r[e].push(t);else{var a,l;if(void 0!==s)for(var d=document.getElementsByTagName("script"),c=0;c{a.onerror=a.onload=null,clearTimeout(m);var n=r[e];if(delete r[e],a.parentNode&&a.parentNode.removeChild(a),n&&n.forEach((e=>e(s))),t)return t(s)},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=(t,s)=>{var r=o.o(e,t)?e[t]:void 0;if(0!==r)if(r)s.push(r[2]);else{var n=new Promise(((s,n)=>r=e[t]=[s,n]));s.push(r[2]=n);var i=o.p+o.u(t),a=new Error;o.l(i,(s=>{if(o.o(e,t)&&(0!==(r=e[t])&&(e[t]=void 0),r)){var n=s&&("load"===s.type?"missing":s.type),i=s&&s.target&&s.target.src;a.message="Loading chunk "+t+" failed.\n("+n+": "+i+")",a.name="ChunkLoadError",a.type=n,a.request=i,r[1](a)}}),"chunk-"+t,t)}},o.O.j=t=>0===e[t];var t=(t,s)=>{var r,n,[i,a,l]=s,d=0;if(i.some((t=>0!==e[t]))){for(r in a)o.o(a,r)&&(o.m[r]=a[r]);if(l)var c=l(o)}for(t&&t(s);do(39663)));l=o.O(l)})(); //# sourceMappingURL=bundle.215c99476c8c56fee89c.js.map