module.exports=[19107,a=>{"use strict";let b=(0,a.i(64831).default)("arrow-left",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);a.s(["ArrowLeft",0,b],19107)},91603,a=>{"use strict";var b=a.i(50944),c=a.i(3629);a.s(["useAppRouter",0,function(){let a=(0,b.useRouter)(),{startLoading:d}=(0,c.useLoader)();return{...a,push:(b,c)=>{console.log("[Loader] Navigation started:",b),d&&d(),a.push(b,c)},replace:(b,c)=>{console.log("[Loader] Navigation started:",b),d&&d(),a.replace(b,c)}}}])},40315,a=>{"use strict";var b=a.i(29562);let c=new class{async fetchCoupons(a){let{data:c,error:d}=await b.supabase.from("coupons").select("*").eq("vendor_id",a).order("created_at",{ascending:!1});if(d)throw console.error("Error fetching coupons:",d),d;return c||[]}async fetchCouponDetails(a){let{data:c,error:d}=await b.supabase.from("coupons").select("*").eq("id",a).single();if(d)throw d;let e=[],f=[];if("category"===c.apply_type){let{data:c}=await b.supabase.from("coupon_categories").select(`
          category_id,
          categories (
            name
          )
        `).eq("coupon_id",a);e=c||[]}else if("product"===c.apply_type){let{data:c}=await b.supabase.from("coupon_products").select(`
          product_id,
          products (
            product_name
          )
        `).eq("coupon_id",a);f=c||[]}return{...c,selectedCategories:e,selectedProducts:f}}async createCoupon(a,c){let{data:d,error:e}=await b.supabase.from("coupons").insert([a]).select().single();if(e){if("23505"===e.code)throw Error("This coupon code has already been created. Please try a different code or generate a new one.");throw e}let f=d.id;if("category"===a.apply_type&&c.categories?.length>0){let a=c.categories.map(a=>({coupon_id:f,category_id:a}));await b.supabase.from("coupon_categories").insert(a)}else if("product"===a.apply_type&&c.products?.length>0){let a=c.products.map(a=>({coupon_id:f,product_id:a}));await b.supabase.from("coupon_products").insert(a)}return d}async updateCouponStatus(a,c){let{data:d,error:e}=await b.supabase.from("coupons").update({is_active:c}).eq("id",a).select().single();if(e)throw e;return d}async deleteCoupon(a){let{error:c}=await b.supabase.from("coupons").delete().eq("id",a);if(c)throw c;return!0}async fetchVendorProducts(a){let{data:c,error:d}=await b.supabase.from("products").select("id, product_name, category_id").eq("vendor_id",a).order("product_name");return d?(console.warn("Failed to fetch products:",d.message),[]):c||[]}async fetchCategories(){let{data:a,error:c}=await b.supabase.from("categories").select("id, name").order("name");return c?(console.warn("Failed to fetch categories:",c.message),[]):a||[]}async validateCoupon(a,c,d){let{subtotal:e,products:f}=c,{data:g,error:h}=await b.supabase.from("coupons").select("*").eq("code",a).single();if(h||!g)return{isValid:!1,error:"Invalid coupon code"};if(!g.is_active)return{isValid:!1,error:"This coupon is no longer active"};let i=new Date;if(new Date(g.start_date)>i)return{isValid:!1,error:"This coupon is not yet valid"};if(new Date(g.end_date)<i)return{isValid:!1,error:"This coupon has expired"};if(g.usage_limit>0&&g.used_count>=g.usage_limit)return{isValid:!1,error:"Coupon usage limit has been reached"};if(d){let{count:a}=await b.supabase.from("coupon_usages").select("*",{count:"exact",head:!0}).eq("coupon_id",g.id).eq("user_id",d);if(a>=g.per_user_limit)return{isValid:!1,error:"You have reached your usage limit for this coupon"}}if(g.min_order_amount&&e<g.min_order_amount)return{isValid:!1,error:`Minimum order amount is ₹${g.min_order_amount}`};let j=!1,k=0;if("all"===g.apply_type)k=e,j=!0;else if("category"===g.apply_type){let{data:a}=await b.supabase.from("coupon_categories").select("category_id").eq("coupon_id",g.id),c=a.map(a=>a.category_id);for(let a of f)c.includes(a.category_id)&&(k+=a.price*a.quantity,j=!0)}else if("product"===g.apply_type){let{data:a}=await b.supabase.from("coupon_products").select("product_id").eq("coupon_id",g.id),c=a.map(a=>a.product_id);for(let a of f)c.includes(a.id)&&(k+=a.price*a.quantity,j=!0)}if(!j)return{isValid:!1,error:"Your cart does not contain any items eligible for this coupon."};let l=0;return"percentage"===g.type?(l=k*(g.value/100),g.max_discount&&l>g.max_discount&&(l=g.max_discount)):"fixed"===g.type&&(l=g.value),l=Math.min(l,k),{isValid:!0,couponId:g.id,discountAmount:l}}};a.s(["couponsRepository",0,c])},45122,a=>{a.v({actionLink:"coupons-module__6TITaa__actionLink",actionLinks:"coupons-module__6TITaa__actionLinks",actionsBar:"coupons-module__6TITaa__actionsBar",analyticsCard:"coupons-module__6TITaa__analyticsCard",analyticsGrid:"coupons-module__6TITaa__analyticsGrid",cardTitle:"coupons-module__6TITaa__cardTitle",cardValue:"coupons-module__6TITaa__cardValue",container:"coupons-module__6TITaa__container",deleteLink:"coupons-module__6TITaa__deleteLink",errorText:"coupons-module__6TITaa__errorText",formControl:"coupons-module__6TITaa__formControl",formGrid:"coupons-module__6TITaa__formGrid",formGroup:"coupons-module__6TITaa__formGroup",formLabel:"coupons-module__6TITaa__formLabel",formSection:"coupons-module__6TITaa__formSection",header:"coupons-module__6TITaa__header",inputAddon:"coupons-module__6TITaa__inputAddon",inputWithAddon:"coupons-module__6TITaa__inputWithAddon",pageButton:"coupons-module__6TITaa__pageButton",pageControls:"coupons-module__6TITaa__pageControls",pagination:"coupons-module__6TITaa__pagination",primaryButton:"coupons-module__6TITaa__primaryButton",searchInput:"coupons-module__6TITaa__searchInput",secondaryButton:"coupons-module__6TITaa__secondaryButton",sectionTitle:"coupons-module__6TITaa__sectionTitle",selectInput:"coupons-module__6TITaa__selectInput",statusActive:"coupons-module__6TITaa__statusActive",statusBadge:"coupons-module__6TITaa__statusBadge",statusExpired:"coupons-module__6TITaa__statusExpired",statusInactive:"coupons-module__6TITaa__statusInactive",table:"coupons-module__6TITaa__table",tableContainer:"coupons-module__6TITaa__tableContainer",title:"coupons-module__6TITaa__title"})}];

//# sourceMappingURL=_1ntwdxc._.js.map