1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4526],{4526:function(t,r,e){e.d(r,{GD:function(){return l},LV:function(){return c},dz:function(){return u}});var a=e(9842),n=e(1695),o=e(4117);let i="https://orderv2-g2p4s4ktsq-uc.a.run.app";async function s(t,r,e){if(!i)throw Error("NEXT_PUBLIC_CREATE_ORDER_API_BASE_URL environment variable is not defined.");let a="".concat(i).concat(t),n={method:r,headers:{"Content-Type":"application/json"}};e&&(n.body=JSON.stringify(e));try{let t;let r=await fetch(a,n),e=await r.text();try{t=JSON.parse(e)}catch(t){throw Error(e||"API request failed with status: ".concat(r.status))}return r.ok,t}catch(e){return console.error("Error in ".concat(r," request to ").concat(t,":"),e),{success:!1,error:"UNKNOWN_ERROR",message:e.message||"Unknown error"}}}async function c(t){try{let e=await s("/api/v2.0/partner/order/create","POST",t);if(e.success)return{success:!0,data:e.order};let a="An unexpected error occurred. Please try again later.";if("INSUFFICIENT_STOCK"===e.error&&e.message)try{let i=/variant (\w+)\. Available: (\d+), Requested: (\d+)/.exec(e.message);if(i){var r;let e=i[1],s=i[2],c=null===(r=t.cartItems)||void 0===r?void 0:r.find(t=>t.variantId===e),l="an item";if(c){let t=await (0,o.Cg)(n.db,c.productId,e);l=t.variantTitle?"".concat(t.productName,", ").concat(t.variantTitle):t.productName}a="We're sorry, \"".concat(l,'" has only ').concat(s," available. Please go back to your cart to adjust the quantity.")}else a="One of the items in your cart is out of stock. Please adjust quantities and try again."}catch(t){console.error("Error resolving product/variant title:",t),a="One of the items in your cart is out of stock. Please adjust quantities and try again."}else"PRICE_MISMATCH"===e.error?a="Order creation failed due to a price mismatch. Please refresh your cart.":"INTERNAL_ERROR"===e.error?a="An unexpected server error occurred. Please try again later.":e.message&&(a=e.message);return{success:!1,error:a}}catch(t){return console.error("createOrder unexpected error:",t),{success:!1,error:t.message||"Failed to create order. Please try again."}}}async function l(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:24;if(!t)return console.error("CustomerId is required to fetch orders."),{orders:[],totalPages:0,count:0};try{let a=await fetch("https://orderv2-g2p4s4ktsq-uc.a.run.app/api/v2.0/partner/order/order_v2/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:"",page:r,hitsPerPage:e,filters:{status:["all"],customerId:[t]}}),cache:"no-store"});if(!a.ok)throw Error("Order API responded with status: ".concat(a.status));let n=await a.json();if(n.success&&n.results)return{orders:n.results.hits.map(t=>({...t,orderId:t.orderId||t.objectID})),totalPages:n.results.nbPages||0,count:n.results.nbHits||0};return{orders:[],totalPages:0,count:0}}catch(r){return console.error("Error fetching orders via API for ".concat(t,":"),r),{orders:[],totalPages:0,count:0}}}async function u(t){if(!t)return console.error("OrderId is required to fetch details."),null;try{let r=(0,a.JU)(n.db,"orders_v2",t),e=await (0,a.QT)(r);if(!e.exists())return null;let i=e.data(),s=async()=>{let t=await (0,a.PL)((0,a.hJ)(r,"packages"));return Promise.all(t.docs.map(async t=>{var r;let e={...t.data(),packageId:t.id};if(null===(r=e.items)||void 0===r?void 0:r.length){let t=await Promise.all(e.items.map(async t=>{let{productName:r,variantTitle:e}=await (0,o.Cg)(n.db,t.productId,t.variantId);return{...t,productName:r,variantName:e}}));e.items=t}return e}))},c=async()=>{let t=await (0,a.PL)((0,a.hJ)(r,"cancellations"));return Promise.all(t.docs.map(async t=>{var r;let e={...t.data(),cancellationId:t.id};if(null===(r=e.items)||void 0===r?void 0:r.length){let t=await Promise.all(e.items.map(async t=>{let{productName:r,variantTitle:e}=await (0,o.Cg)(n.db,t.productId,t.variantId);return{...t,productName:r,variantName:e}}));e.items=t}return e}))},[l,u]=await Promise.all([s(),c()]),d=await Promise.all((i.items||[]).map(async t=>{let{productName:r,variantTitle:e}=await (0,o.Cg)(n.db,t.productId,t.variantId);return{...t,productName:r,variantName:e}}));return{...i,orderId:e.id,items:d,packages:l,cancellations:u}}catch(r){return console.error("Error fetching order detail for ID ".concat(t,":"),r),null}}},4117:function(t,r,e){e.d(r,{Cg:function(){return i},bv:function(){return o}});var a=e(9842);let n=t=>{if(!t)throw Error("Firestore instance is not available. Ensure Firebase is initialized.");return t};async function o(t,r){let e=n(t);try{let t=(0,a.JU)(e,"products_v2",r),n=await (0,a.QT)(t);if(!n.exists())return null;let{brandId:o}=n.data();if(!o)return null;let i=(0,a.JU)(e,"collections_v2",o),s=await (0,a.QT)(i);if(!s.exists())return null;let{partnerId:c}=s.data();if(!c)return null;return c}catch(t){return console.error("Failed to fetch sellerId for productId ".concat(r,":"),t),null}}async function i(t,r,e){try{let n=await (0,a.QT)((0,a.JU)(t,"products_v2",r));if(!n.exists())return{productName:"Unknown Product",variantTitle:""};let o=n.data(),i=o.productTitle||"Unknown Product (Title Field Empty)";if("single"===o.variantType)return{productName:i,variantTitle:""};let s=await (0,a.QT)((0,a.JU)(t,"products_v2/".concat(r,"/variants_v2"),e));if(!s.exists())return{productName:i,variantTitle:""};let c=s.data().combination||{},l="";return o.variantGroups&&(l=o.variantGroups.map(t=>{var r;let e=c[t.groupId],a=null===(r=t.items)||void 0===r?void 0:r.find(t=>t.itemId===e);return(null==a?void 0:a.itemName)||""}).filter(t=>t).join(", ")),{productName:i,variantTitle:l}}catch(t){return console.error("Error resolving product/variant title:",t),{productName:"Unknown Product",variantTitle:""}}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.