PageSourceSearch

https://www.shahiin.com/_next/static/chunks/3909-97d79b359e2e9ff0.js

js shahiin.com collected 2026-10-02 00:58:22 UTC 30,043 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3909],{3909:(t,e,r)=>{r.d(e,{Ek:()=>d,Rq:()=>i});var o=r(12849),a=r(94108);let n=(t,e)=>{if(!t||"string"!=typeof t)throw Error("Invalid SUPABASE_URL: ".concat(t));try{return new URL("".concat(t).concat(e))}catch(r){throw Error("Failed to construct URL from ".concat(t).concat(e,": ").concat(r))}},i={isForSale:t=>"for_sale"===t.availability_mode,isDisplayOnly:t=>"display_only"===t.availability_mode,getAvailableFulfillmentMethods:t=>{let e=[];return t.pickup_available&&e.push("pickup"),t.delivery_available&&e.push("delivery"),e},getAvailablePaymentMethods:(t,e)=>{let r=[];return t.payment_shamcash&&r.push("shamcash"),t.payment_goldmasters&&r.push("goldmasters"),t.payment_cash_on_delivery&&("delivery"===e||t.delivery_available)&&r.push("cash_on_delivery"),r},canAddToCart:t=>"for_sale"===t.availability_mode&&t.stock_count>0&&(t.pickup_available||t.delivery_available),getAvailabilityBadgeText:t=>"display_only"===t.availability_mode?"للعرض فقط":!t.pickup_available&&t.delivery_available?"توصيل فقط":t.pickup_available&&!t.delivery_available?"استلام فقط":null,getPaymentMethodIcons:t=>{let e=[];return t.payment_shamcash&&e.push({method:"shamcash",label:"شام كاش"}),t.payment_goldmasters&&e.push({method:"goldmasters",label:"جولد ماسترز"}),t.payment_cash_on_delivery&&e.push({method:"cod",label:"دفع عند التوصيل"}),e}};async function s(t){if(0===t.length)return t;let e=t.map(t=>t.id).filter(Boolean);if(0===e.length)return t;let{data:r,error:a}=await o.supabase.from("vendors").select("id, store_theme_id, store_palette_id").in("id",e);if(a||!(null==r?void 0:r.length))return t;let n=new Map(r.map(t=>[t.id,t]));return t.map(t=>{var e,r,o,a;let i=t.id?n.get(t.id):void 0;return i?{...t,store_theme_id:null!=(r=null!=(e=i.store_theme_id)?e:t.store_theme_id)?r:"classic",store_palette_id:null!=(a=null!=(o=i.store_palette_id)?o:t.store_palette_id)?a:null}:t})}async function l(t){let e=t.map(t=>t.vendor_profiles).filter(t=>!!(null==t?void 0:t.id));if(0===e.length)return t;let r=new Map((await s(e)).map(t=>[t.id,t]));return t.map(t=>{var e;let o=null==(e=t.vendor_profiles)?void 0:e.id;return o&&r.has(o)?{...t,vendor_profiles:{...t.vendor_profiles,...r.get(o)}}:t})}let d={async getVendors(t){var e,i;try{let{SUPABASE_URL:o}=await Promise.resolve().then(r.bind(r,12849)),i=n(o,"/functions/v1/vendors");(null==t?void 0:t.vendor_id)&&(i.pathname="".concat(i.pathname,"/").concat(t.vendor_id)),(null==t?void 0:t.include_products)&&i.searchParams.set("include_products","true");let l=(0,a.getSupabaseAnonKey)(),d=await fetch(i.toString(),{method:"GET",headers:{"Content-Type":"application/json",apikey:l,Authorization:"Bearer ".concat(l)}});if(!d.ok){let t=await d.text();throw Error("Edge function failed: ".concat(d.status," ").concat(t))}let c=await d.json(),u=null==c?void 0:c.data,_=(Array.isArray(u)?u:null!=u&&"object"==typeof u?[u]:[]).map(e=>({...e,custom_css:null,total_products:e.total_products||0,total_stock:e.total_stock||0,products:(null==t?void 0:t.include_products)?e.products||[]:void 0}));return{data:_=await s(_),meta:null!=(e=null==c?void 0:c.meta)?e:{total:_.length}}}catch(s){let e=o.supabase.from("vendors").select("\n          id,\n          vendor_name,\n          phone_number,\n          formatted_address,\n          latitude,\n          longitude,\n          delivery_radius_km,\n          shamcash_account,\n          goldmasters_account,\n          color_pattern,\n          layout_template,\n          store_theme_id,\n          store_palette_id,\n          brand_logo_url,\n          banner_image_url,\n          store_images (\n            id,\n            image_url,\n            display_order\n          ),\n          operating_hours (\n            day_of_week,\n            is_open,\n            is_24_hours,\n            open_time,\n            close_time\n          )\n        ");(null==t?void 0:t.vendor_id)&&(e=e.eq("id",t.vendor_id));let{data:r,error:a}=await e;if(a)throw a;let n=null!=(i=null==r?void 0:r.map(e=>({...e,custom_css:null,total_products:0,total_stock:0,products:(null==t?void 0:t.include_products)?[]:void 0})))?i:[];return{data:n,meta:{total:n.length}}}},async getProducts(t){var e,r,i;try{let{url:r,anonKey:o}=(0,a.getSupabaseConfig)(),i=n(r,"/functions/v1/products");(null==t?void 0:t.vendor_id)&&i.searchParams.set("vendor_id",t.vendor_id),(null==t?void 0:t.product_id)&&i.searchParams.set("product_id",t.product_id),(null==t?void 0:t.category)&&i.searchParams.set("category",t.category),(null==t?void 0:t.categories)&&i.searchParams.set("categories",t.categories),"number"==typeof(null==t?void 0:t.limit)&&i.searchParams.set("limit",String(t.limit)),"number"==typeof(null==t?void 0:t.offset)&&i.searchParams.set("offset",String(t.offset)),(null==t?void 0:t.q)&&i.searchParams.set("q",t.q),(null==t?void 0:t.search_in)&&i.searchParams.set("search_in",t.search_in),(null==t?void 0:t.fulfillment_method)&&i.searchParams.set("fulfillment_method",t.fulfillment_method),(null==t?void 0:t.shahiin_fulfilled_only)&&i.searchParams.set("shahiin_fulfilled_only","true"),"number"==typeof(null==t?void 0:t.shopper_lat)&&i.searchParams.set("shopper_lat",String(t.shopper_lat)),"number"==typeof(null==t?void 0:t.shopper_lng)&&i.searchParams.set("shopper_lng",String(t.shopper_lng)),(null==t?void 0:t.turbozone_only)&&i.searchParams.set("turbozone_only","true");let s=await fetch(i.toString(),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o),apikey:o}});if(!s.ok){let t=await s.text(),e="Edge function failed: ".concat(s.status," ").concat(s.statusText,". Response: ").concat(t.substring(0,200));throw console.error("\uD83D\uDECD️ [getProducts] Edge function error:",{status:s.status,statusText:s.statusText,url:i.toString(),responseText:t.substring(0,500)}),Error(e)}let d=await s.json();if(!d||"object"!=typeof d)throw console.error("\uD83D\uDECD️ [getProducts] Invalid response format:",d),Error("Invalid response format from edge function");!0!==d.success&&console.warn("\uD83D\uDECD️ [getProducts] Edge function returned success: false",d);let c=[];Array.isArray(null==d?void 0:d.data)?c=d.data:(null==d?void 0:d.data)&&"object"==typeof d.data?c=[d.data]:((null==d?void 0:d.data)===null||(null==d?void 0:d.data)===void 0)&&(c=[]),(null==t?void 0:t.product_id)&&0===c.length&&(console.warn("\uD83D\uDECD️ [getProducts] Product not found for product_id:",t.product_id),console.warn("\uD83D\uDECD️ [getProducts] Response:",{success:d.success,hasData:!!d.data,dataType:typeof d.data})),console.log("\uD83D\uDECD️ [getProducts] Edge function response:",{success:d.success,hasData:!!d.data,dataType:Array.isArray(null==d?void 0:d.data)?"array":typeof(null==d?void 0:d.data),totalProducts:c.length,meta:d.meta,vendorId:null==t?void 0:t.vendor_id,productId:null==t?void 0:t.product_id,firstProduct:c[0]?{id:c[0].id,name:c[0].name,vendor_id:c[0].vendor_id,stock_count:c[0].stock_count,total_stock:c[0].total_stock}:null});let u=c.map(t=>
1({...t,vendor_profiles:{...t.vendors,custom_css:null,store_images:[],operating_hours:[],total_products:0,total_stock:0},total_stock:("number"==typeof t.stock_count?t.stock_count:0)+(t.product_variants||[]).reduce((t,e)=>t+((null==e?void 0:e.stock_count)||0),0),has_variants:Array.isArray(t.product_variants)&&t.product_variants.length>0}));u=await l(u);let _=null!=(e=null==d?void 0:d.meta)?e:{total:u.length};return null==_.has_more&&"number"==typeof(null==t?void 0:t.limit)&&(_.has_more=u.length>=t.limit),{data:u,meta:_}}catch(e){if(console.error("\uD83D\uDECD️ [getProducts] Edge function failed:",{error:null==e?void 0:e.message,stack:null==e?void 0:e.stack,params:t}),(null==t?void 0:t.product_id)&&(null==e||null==(r=e.message)?void 0:r.includes("404")))throw Error("Product not found");if(null==t?void 0:t.product_id)throw e;console.warn("\uD83D\uDECD️ [getProducts] Falling back to direct query for non-product-id requests")}let s=o.supabase.from("products").select("\n        id,\n        name,\n        description,\n        base_price,\n        delivery_price,\n        currency,\n        stock_count,\n        product_category,\n        availability_mode,\n        pickup_available,\n        delivery_available,\n        payment_cash_on_delivery,\n        payment_shamcash,\n        payment_goldmasters,\n        vendor_id,\n        vendors (\n          id,\n          vendor_name,\n          phone_number,\n          formatted_address,\n          latitude,\n          longitude,\n          delivery_radius_km,\n          shamcash_account,\n          goldmasters_account,\n          color_pattern,\n          layout_template,\n          store_theme_id,\n          store_palette_id,\n          brand_logo_url,\n          banner_image_url\n        ),\n        product_images (\n          id,\n          image_url,\n          display_order\n        ),\n        product_variants (\n          id,\n          size,\n          color,\n          attributes,\n          price_adjustment,\n          stock_count\n        )\n      ");if((null==t?void 0:t.vendor_id)&&(s=s.eq("vendor_id",t.vendor_id)),(null==t?void 0:t.product_id)&&(s=s.eq("id",t.product_id)),null==t?void 0:t.categories){let e=t.categories.split(",").map(t=>t.trim()).filter(Boolean);e.length>0&&(s=s.in("product_category",e))}else(null==t?void 0:t.category)&&(s=s.eq("product_category",t.category));if(null==t?void 0:t.q){let e=t.search_in||"all";s="name"===e?s.ilike("name","%".concat(t.q,"%")):"category"===e?s.ilike("product_category","%".concat(t.q,"%")):"description"===e?s.ilike("description","%".concat(t.q,"%")):s.or("name.ilike.%".concat(t.q,"%,product_category.ilike.%").concat(t.q,"%,description.ilike.%").concat(t.q,"%"))}(null==t?void 0:t.offset)?s=s.range(t.offset,t.offset+((null==t?void 0:t.limit)||50)-1):(null==t?void 0:t.limit)&&(s=s.limit(t.limit));let{data:d,error:c}=await s;if(c)throw c;let u=null!=(i=null==d?void 0:d.map(t=>{var e,r;return{...t,vendor_profiles:{...t.vendors,custom_css:null,store_images:[],operating_hours:[],total_products:0,total_stock:0},total_stock:t.stock_count+((null==(e=t.product_variants)?void 0:e.reduce((t,e)=>t+e.stock_count,0))||0),has_variants:((null==(r=t.product_variants)?void 0:r.length)||0)>0}}))?i:[];return{data:u=await l(u),meta:{total:u.length}}},async getDiscountedProducts(t){try{let{SUPABASE_URL:o}=await Promise.resolve().then(r.bind(r,12849)),i=n(o,"/functions/v1/products/discounted");"number"==typeof(null==t?void 0:t.limit)&&i.searchParams.set("limit",String(t.limit));let s=(0,a.getSupabaseAnonKey)(),l=await fetch(i.toString(),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(s),apikey:s}});if(l.ok){var e;let t=await l.json(),r=((null==t?void 0:t.data)||[]).map(t=>({...t,vendor_profiles:{...t.vendors,custom_css:null,store_images:[],operating_hours:[],total_products:0,total_stock:0},total_stock:("number"==typeof t.stock_count?t.stock_count:0)+(t.product_variants||[]).reduce((t,e)=>t+((null==e?void 0:e.stock_count)||0),0),has_variants:Array.isArray(t.product_variants)&&t.product_variants.length>0}));return{data:r,meta:null!=(e=null==t?void 0:t.meta)?e:{total:r.length}}}throw Error("Endpoint not found: ".concat(l.status))}catch(e){console.warn("getDiscountedProducts via Edge failed, using fallback:",e);try{let e=await this.getProducts({limit:500}),r=e.data.filter(t=>t.discount_percentage&&t.discount_percentage>0||!0===t.is_discounted||null!==t.discount_percentage&&void 0!==t.discount_percentage&&t.discount_percentage>0);return console.log("[getDiscountedProducts] Found ".concat(r.length," discounted products out of ").concat(e.data.length," total")),{data:r.slice(0,(null==t?void 0:t.limit)||12),meta:{total:r.length}}}catch(t){return console.error("Fallback also failed:",t),{data:[],meta:{total:0}}}}},async getFeaturedProducts(t){try{let{SUPABASE_URL:o}=await Promise.resolve().then(r.bind(r,12849)),i=n(o,"/functions/v1/featured-products");"number"==typeof(null==t?void 0:t.limit)&&i.searchParams.set("limit",String(t.limit)),"number"==typeof(null==t?void 0:t.offset)&&i.searchParams.set("offset",String(t.offset));let s=(0,a.getSupabaseAnonKey)(),l=await fetch(i.toString(),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(s),apikey:s}});if(l.ok){var e;let t=await l.json(),r=(Array.isArray(null==t?void 0:t.data)?t.data:[]).map(t=>
1({...t,vendor_profiles:{...t.vendors,custom_css:null,store_images:[],operating_hours:[],total_products:0,total_stock:0},total_stock:("number"==typeof t.stock_count?t.stock_count:0)+(t.product_variants||[]).reduce((t,e)=>t+((null==e?void 0:e.stock_count)||0),0),has_variants:Array.isArray(t.product_variants)&&t.product_variants.length>0}));return{data:r,meta:null!=(e=null==t?void 0:t.meta)?e:{total:r.length}}}return{data:[],meta:{total:0}}}catch(t){return console.warn("getFeaturedProducts failed:",t),{data:[],meta:{total:0}}}},async getProductVideos(t){try{let{SUPABASE_URL:o}=await Promise.resolve().then(r.bind(r,12849)),i=n(o,"/functions/v1/product-videos");(null==t?void 0:t.vendor_id)&&i.searchParams.set("vendor_id",t.vendor_id),(null==t?void 0:t.product_id)&&i.searchParams.set("product_id",t.product_id),(null==t?void 0:t.category)&&i.searchParams.set("category",t.category),(null==t?void 0:t.q)&&i.searchParams.set("q",t.q),(null==t?void 0:t.search_in)&&i.searchParams.set("search_in",t.search_in),"number"==typeof(null==t?void 0:t.limit)&&i.searchParams.set("limit",String(t.limit)),"number"==typeof(null==t?void 0:t.offset)&&i.searchParams.set("offset",String(t.offset));let s=(0,a.getSupabaseAnonKey)(),l=await fetch(i.toString(),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(s),apikey:s}});if(l.ok){var e;let t=await l.json(),r=((null==t?void 0:t.data)||[]).map(t=>({id:t.id,video_url:t.videoUrl,thumbnail_url:t.thumbnailUrl,created_at:t.createdAt,products:{id:t.productId,name:t.productName,description:"",base_price:0,delivery_price:0,currency:"SYP",stock_count:0,product_category:t.productCategory,availability_mode:"for_sale",pickup_available:!1,delivery_available:!0,payment_cash_on_delivery:!1,payment_shamcash:!1,payment_goldmasters:!1,vendor_id:t.vendorId,vendor_profiles:{id:t.vendorId,vendor_name:"",custom_css:null,store_images:[],operating_hours:[],total_products:0,total_stock:0},product_images:[],product_variants:[],total_stock:0,has_variants:!1}}));return{data:r,meta:null!=(e=null==t?void 0:t.meta)?e:{total:r.length}}}}catch(t){console.warn("getProductVideos via Edge failed, falling back to direct query:",t)}let i=o.supabase.from("product_videos").select("\n        id,\n        video_url,\n        thumbnail_url,\n        created_at,\n        products (\n          id,\n          name,\n          description,\n          base_price,\n          delivery_price,\n          currency,\n          stock_count,\n          product_category,\n          availability_mode,\n          pickup_available,\n          delivery_available,\n          payment_cash_on_delivery,\n          payment_shamcash,\n          payment_goldmasters,\n          vendor_id,\n          vendors (\n            id,\n            vendor_name,\n            phone_number,\n            formatted_address,\n            latitude,\n            longitude,\n            delivery_radius_km,\n            shamcash_account,\n            goldmasters_account,\n            color_pattern,\n            layout_template,\n            brand_logo_url,\n            banner_image_url\n          ),\n          product_images (\n            id,\n            image_url,\n            display_order\n          ),\n          product_variants (\n            id,\n            size,\n            color,\n            attributes,\n            price_adjustment,\n            stock_count\n          )\n        )\n      ");(null==t?void 0:t.vendor_id)&&(i=i.eq("products.vendor_id",t.vendor_id)),(null==t?void 0:t.offset)?i=i.range(t.offset,t.offset+((null==t?void 0:t.limit)||50)-1):(null==t?void 0:t.limit)&&(i=i.limit(t.limit));let{data:s,error:l}=await i;if(l)throw l;let d=(null==s?void 0:s.map(t=>{var e,r,o,a,n,i;return{...t,products:{...t.products,vendor_profiles:{...null==(e=t.products)?void 0:e.vendors,custom_css:null,store_images:[],operating_hours:[],total_products:0,total_stock:0},total_stock:((null==(r=t.products)?void 0:r.stock_count)||0)+((null==(a=t.products)||null==(o=a.product_variants)?void 0:o.reduce((t,e)=>t+e.stock_count,0))||0),has_variants:((null==(i=t.products)||null==(n=i.product_variants)?void 0:n.length)||0)>0}}}))||[];return{data:d,meta:{total:d.length}}},async getProductVideoById(t){console.log("\uD83C\uDFAC [API] Getting video by ID via edge function:",t);try{let{data:e,error:i}=await o.supabase.from("product_videos").select("id, product_id, thumbnail_url").eq("id",t).single();if(i||!e)return console.error("\uD83C\uDFAC [API] Error getting video for product_id:",i),{data:null,error:"Video not found"};console.log("\uD83C\uDFAC [API] Found video with product_id:",e.product_id);let{SUPABASE_URL:s,SUPABASE_PUBLISHABLE_KEY:l}=await Promise.resolve().then(r.bind(r,12849)),d=n(s,"/functions/v1/product-videos");d.searchParams.set("product_id",e.product_id);let c=await fetch(d.toString(),{method:"GET",headers:{"Content-Type":"application/json",apikey:(0,a.getSupabaseAnonKey)()}});if(!c.ok){let t=await c.text();return console.error("\uD83C\uDFAC [API] Edge function failed:",c.status,t),{data:null,error:"Failed to fetch video details: ".concat(c.status)}}let u=await c.json(),_=((null==u?void 0:u.data)||[]).find(e=>e.id===t);if(!_)return console.log("\uD83C\uDFAC [API] Video not found in edge function response"),{data:null,error:"Video not found"};let p=n(s,"/functions/v1/products");p.searchParams.set("product_id",_.productId);let v=await fetch(p.toString(),{method:"GET",headers:{"Content-Type":"application/json",apikey:(0,a.getSupabaseAnonKey)()}});if(!v.ok)return console.error("\uD83C\uDFAC [API] Failed to get product details"),{data:null,error:"Failed to get product details"};let m=await v.json(),h=((null==m?void 0:m.data)||[])[0];if(!h)return console.error("\uD83C\uDFAC [API] Product not found"),{data:null,error:"Product not found"};let f={id:_.id,video_url:_.videoUrl,thumbnail_url:e.thumbnail_url,created_at:_.createdAt,products:{...h,vendor_profiles:{...h.vendors,custom_css:null,store_images:[],operating_hours:[],total_products:0,total_stock:0}}};return console.log("\uD83C\uDFAC [API] Successfully fetched video:",f.id,"URL:",f.video_url),{data:f}}catch(t){return console.error("\uD83C\uDFAC [API] Error in getProductVideoById:",t),{data:null,error:"Failed to fetch video"}}},async getCategories(t){let e=o.supabase.from("categories").select("*").order("sort_order");(null==t?void 0:t.include_inactive)||(e=e.eq("is_active",!0));let{data:r,error:a}=await e;if(a)throw a;return{success:!0,data:r||[]}},async createOrder(t){var e,i,s,l,d,c,u,_,p,v,m,h,f;try{let{AuthService:o}=await Promise.resolve().then(r.bind(r,96575)),v=o.getJwt();if(!v)throw Error("Authentication required. Please sign in to place an order.");let{SUPABASE_URL:m}=await Promise.resolve().then(r.bind(r,12849)),h=n(m,"/functions/v1/orders"),f=
1await fetch(h.toString(),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(v),apikey:(0,a.getSupabaseAnonKey)()},body:JSON.stringify(t)});if(!f.ok){let t=await f.text();throw Error("Edge function failed: ".concat(f.status," ").concat(t))}let g=await f.json(),y=null!=(d=null!=(l=null!=(s=null==g||null==(e=g.data)?void 0:e.id)?s:null==g||null==(i=g.data)?void 0:i.order_id)?l:null==g?void 0:g.order_id)?d:null==g?void 0:g.id,w=null!=(u=null!=(c=null==g?void 0:g.data)?c:null==g?void 0:g.order)?u:g;if((null==g?void 0:g.success)&&y||y)return{success:!0,order_id:String(y),order:w};throw Error(null!=(p=null!=(_=null==g?void 0:g.error)?_:null==g?void 0:g.message)?p:"Unexpected response format from orders edge function")}catch(s){console.warn("createOrder via Edge failed, falling back to direct query:",s);let e=null!=(m=null==(v=t.customer_contact_info)?void 0:v.id)?m:null,{data:r,error:a}=await o.supabase.from("orders").insert({vendor_id:t.vendor_id,customer_id:e,total_amount:t.total_amount,currency:t.currency,payment_method:t.payment_method,payment_receipt:t.payment_receipt,payment_via_shahiin:null!=(h=t.payment_via_shahiin)&&h,fulfillment_method:null!=(f=t.fulfillment_method)?f:"self_fulfillment",customer_contact_info:t.customer_contact_info,customer_snapshot:t.customer_contact_info,delivery_address:t.delivery_address,delivery_requested:t.delivery_requested,delivery_price:t.delivery_price,notes:t.notes,status:"pending"}).select().single();if(a)throw console.error("Create order failed:",a),Error("Failed to create order: ".concat(a.message));let n=t.order_items.map(t=>{var e;return{order_id:r.id,product_id:t.product_id,quantity:t.quantity,unit_price:t.unit_price,total_price:null!=(e=t.total_price)?e:t.unit_price*t.quantity,product_snapshot:t.product_snapshot}}),{error:i}=await o.supabase.from("order_items").insert(n);if(i)throw console.error("Create order items failed:",i),Error("Failed to create order items: ".concat(i.message));return console.log("Order created successfully:",r),{success:!0,order_id:r.id,order:r}}},async getVendorOrders(t,e){let r=o.supabase.from("orders").select("\n        *,\n        order_items (\n          id,\n          product_id,\n          quantity,\n          unit_price,\n          total_price,\n          product_snapshot\n        )\n      ").eq("vendor_id",t).order("created_at",{ascending:!1});e&&(r=r.eq("status",e));let{data:a,error:n}=await r;if(n)throw n;return{orders:a||[]}},async getCustomerOrders(t){try{let{AuthService:e}=await Promise.resolve().then(r.bind(r,96575)),o=e.getJwt();if(!o)throw Error("Authentication required. Please sign in to view orders.");let{SUPABASE_URL:i}=await Promise.resolve().then(r.bind(r,12849)),s=n(i,"/functions/v1/orders");s.searchParams.set("client_id",t);let l=await fetch(s.toString(),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o),apikey:(0,a.getSupabaseAnonKey)()}});if(!l.ok){let t=await l.text();throw Error("Edge function failed: ".concat(l.status," ").concat(t))}let d=await l.json();if((null==d?void 0:d.success)&&Array.isArray(null==d?void 0:d.data))return{orders:d.data||[]};return{orders:d.orders||[]}}catch(a){console.warn("getCustomerOrders via Edge failed, falling back to direct query:",a);let{data:e,error:r}=await o.supabase.from("orders").select("\n          *,\n          order_items (\n            id,\n            product_id,\n            quantity,\n            unit_price,\n            total_price,\n            product_snapshot\n          )\n        ").eq("customer_id",t).order("created_at",{ascending:!1});if(r)throw r;return{orders:e||[]}}},async updateOrderStatus(t,e,r){let{data:a,error:n}=await o.supabase.from("orders").update({status:e,updated_at:new Date().toISOString()}).eq("id",t).eq("vendor_id",r).select().single();if(n)throw n;return{success:!0,order:a}},async cancelOrder(t){let{AuthService:e}=await Promise.resolve().then(r.bind(r,96575)),o=e.getJwt();if(!o)throw Error("Authentication required. Please sign in to cancel orders.");let{SUPABASE_URL:i}=await Promise.resolve().then(r.bind(r,12849)),s=n(i,"/functions/v1/orders");s.searchParams.set("order_id",t);let l=await fetch(s.toString(),{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o),apikey:(0,a.getSupabaseAnonKey)()}}),d=await l.text();if(!l.ok)throw Error("Failed to cancel order: ".concat(l.status," ").concat(d));let c=d.trim();if(!c)return{success:!0};let u={};try{u=JSON.parse(c)}catch(t){return{success:!0}}if(!1===u.success)throw Error(u.error||u.message||"Failed to cancel order");return{success:!0}},async getClients(t){let e=o.supabase.from("clients").select("*").order("created_at",{ascending:!1});(null==t?void 0:t.client_id)&&(e=e.eq("id",t.client_id)),(null==t?void 0:t.offset)?e=e.range(t.offset,t.offset+((null==t?void 0:t.limit)||50)-1):(null==t?void 0:t.limit)&&(e=e.limit(t.limit));let{data:r,error:a}=await e;if(a)throw a;let n=(null==r?void 0:r.map(t=>({...t,address:"",latitude:void 0,longitude:void 0,formatted_address:void 0,delivery_notes:void 0})))||[];return{success:!0,data:n,meta:{total:n.length}}},async getFavorites(){let{AuthService:t}=await Promise.resolve().then(r.bind(r,96575)),e=t.getJwt();if(!e)throw Error("Authentication required. Please sign in to view favorites.");try{let{SUPABASE_URL:t}=await Promise.resolve().then(r.bind(r,12849)),o=n(t,"/functions/v1/favorites"),i=await fetch(o.toString(),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e),apikey:(0,a.getSupabaseAnonKey)()}});if(!i.ok){let t=await i.text();throw Error("Failed to fetch favorites: ".concat(i.status," ").concat(t))}let s=await i.json();if(!s.success)throw Error(s.error||"Failed to fetch favorites");return{data:s.data||[]}}catch(t){throw console.error("getFavorites error:",t),t}},async addToFavorites(t){let{AuthService:e}=await Promise.resolve().then(r.bind(r,96575)),o=e.getJwt();if(!o)throw Error("Authentication required. Please sign in to add favorites.");try{let{SUPABASE_URL:e}=await Promise.resolve().then(r.bind(r,12849)),i=n(e,"/functions/v1/favorites");i.searchParams.set("product_id",t);let s=await fetch(i.toString(),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o),apikey:(0,a.getSupabaseAnonKey)()}});if(!s.ok){let t=await s.text();throw Error("Failed to add to favorites: ".concat(s.status," ").concat(t))}return{success:(await s.json()).success||!1}}catch(t){throw console.error("addToFavorites error:",t),t}},async removeFromFavorites(t){let{AuthService:e}=await Promise.resolve().then(r.bind(r,96575)),o=e.getJwt();if(!o)throw Error("Authentication required. Please sign in to manage favorites.");try{let{SUPABASE_URL:e}=await Promise.resolve().then(r.bind(r,12849)),i=n(e,"/functions/v1/favorites");i.searchParams.set("product_id",t);let s=await fetch(i.toString(),{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o),apikey:(0,a.getSupabaseAnonKey)()}});if(!s.ok){let t=await s.text();throw Error("Failed to remove from favorites: ".concat(s.status," ").concat(t))}return{success:(await s.json()).success||!1}}catch(t){throw console.error("removeFromFavorites error:",t),t}},async getProductReviews(t,e){try{let{SUPABASE_URL:o}=await Promise.resolve().then(r.bind(r,12849)),i=n(o,"/functions/v1/product-reviews");i.searchParams.set("product_id",t),(null==e?void 0:e.limit)&&i.searchParams.set("limit",e.limit.toString()),(null==e?void 0:e.offset)&&i.searchParams.set("offset",e.offset.toString());let s=await fetch(i.toString(),{method:"GET",headers:{"Content-Type":"application/json",apikey:(0,a.getSupabaseAnonKey)()}});if(!s.ok){let t=await s.text();throw Error("Failed to fetch reviews: ".concat(s.status," ").concat(t))}let l=await s.json();if(l.success)return{reviews:l.data||[],meta:l.meta||{total:0,average_rating:0,total_reviews:0,limit:(null==e?void 0:e.limit)||50,offset:(null==e?void 0:e.offset)||0,has_more:!1}};throw Error(l.error||"Failed to fetch reviews")}catch(t){throw console.error("getProductReviews error:",t),t}},async createProductReview(t){let{AuthService:e}=await Promise.resolve().then(r.bind(r,96575)),o=e.getJwt();if(!o)throw Error("Authentication required. Please log in to submit a review.");try{let{SUPABASE_URL:e}=await Promise.resolve().then(r.bind(r,12849)),i=n(e,"/functions/v1/product-reviews"),s=await fetch(i.toString(),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o),apikey:(0,a.getSupabaseAnonKey)()},body:JSON.stringify(t)});if(!s.ok){let t=await s.json();throw Error(t.error||"Failed to create review: ".concat(s.status))}let l=await s.json();if(l.success)return{success:!0,review:l.data};throw Error(l.error||"Failed to create review")}catch(t){throw console.error("createProductReview error:",t),t}},async updateProductReview(t,e){let{AuthService:o}=await Promise.resolve().then(r.bind(r,96575)),i=o.getJwt();if(!i)throw Error("Authentication required. Please log in to update a review.");try{let{SUPABASE_URL:o}=await Promise.resolve().then(r.bind(r,12849)),s=n(o,"/functions/v1/product-reviews"),l=await fetch(s.toString(),{method:"PUT",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(i),apikey:(0,a.getSupabaseAnonKey)()},body:JSON.stringify({review_id:t,...e})});if(!l.ok){let t=await l.json();throw Error(t.error||"Failed to update review: ".concat(l.status))}let d=await l.json();if(d.success)return{success:!0,review:d.data};throw Error(d.error||"Failed to update review")}catch(t){throw console.error("updateProductReview error:",t),t}},async deleteProductReview(t){let{AuthService:e}=await Promise.resolve().then(r.bind(r,96575)),o=e.getJwt();if(!o)throw Error("Authentication required. Please log in to delete a review.");try{let{SUPABASE_URL:e}=await Promise.resolve().then(r.bind(r,12849)),i=n(e,"/functions/v1/product-reviews");i.searchParams.set("review_id",t);let s=await fetch(i.toString(),{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(o),apikey:(0,a.getSupabaseAnonKey)()}});if(!s.ok){let t=await s.json();throw Error(t.error||"Failed to delete review: ".concat(s.status))}return{success:(await s.json()).success||!1}}catch(t){throw console.error("deleteProductReview error:",t),t}}}},12849:(t,e,r)=>{r.d(e,{SUPABASE_PUBLISHABLE_KEY:()=>n,SUPABASE_URL:()=>a,supabase:()=>i});var o=r(23595);let a="https://ltlvngbcwvhelnvgmpnx.supabase.co",n="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imx0bHZuZ2Jjd3ZoZWxudmdtcG54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTI2Nzc5MDYsImV4cCI6MjA2ODI1MzkwNn0.c474MyTtCioxhcR1GI0wOG8_vypl6C5DIUFvWkzFeyU",i=(0,o.UU)(a,n,{auth:{storage:localStorage,persistSession:!0,autoRefreshToken:!0}})}}]);

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.