1import{c as N}from"./chunk-EEREY6TG.js";import{a as w}from"./chunk-XAAKPWGS.js";import{a as F}from"./chunk-XZBHOAEY.js";import{a as v}from"./chunk-QJPQKQAU.js";import{c as O}from"./chunk-UFNZXUZG.js";import{a as M}from"./chunk-IHJCQUK6.js";import{a as _}from"./chunk-HRGIHHFE.js";import{a as E}from"./chunk-FJMQYAVB.js";import{l as x,m as I}from"./chunk-UFD3WH34.js";import{Ca as S,H as y,Ha as A,W as D,Z as f,ba as C,bd as i,dd as T,ga as u,n as b,qa as R,sa as P,za as n}from"./chunk-WOGKWOFI.js";import{a as p,b as g}from"./chunk-QJI7QS7F.js";var a={myBucket:{path:"user/cart/mybucket/",method:"GET"},addBucketItem:{path:"user/cart/",method:"POST"},removeBucketItem:{path:"user/cart/remove_item/",method:"POST"},listCoupon:{path:"promotion/coupons/",method:"GET"},applyCoupon:{path:"promotion/coupons/apply_coupon/",method:"POST"},removeCoupon:{path:"promotion/coupons/remove_coupon/",method:"POST"},listAddress:{path:"user/address/",method:"GET"},addAddress:{path:"user/address/",method:"POST"},updateAddress:{path:"user/address/:id/",method:"PUT"},deleteAddress:{path:"user/address/:id/",method:"DELETE"},proceedToPayment:{path:"user/order/proceed_checkout/",method:"POST"},getOrderById:{path:"user/order/order_details/",method:"GET"},getOrders:{path:"user/order/my_orders/",method:"GET"},reactivateAutoRenewal:{path:"promotion/subscription/reactivate/",method:"POST"},cancelAutoRenewal:{path:"promotion/subscription/cancel/",method:"POST"},forcePurchase:{path:"stripe/force-subscription/",method:"POST"},retryPayment:{path:"user/order/create_customer_portal/",method:"POST"},checkAndSubscribe:{path:"lms/check-and-subscribe/",method:"GET"},navigateToStripeCustomerDashboard:{path:"user/order/create_customer_portal/",method:"POST"},getSubscriptionPlans:{path:"promotion/subscription/",method:"GET"}};var k="payment.subscriptionPlans",L="payment.recommendedPlans",B=class h{logger=u(E);notification=u(F);http=u(M);dialog=u(w);injector=u(R);transferState=u(A);platformId=u(S);auth=u(O);destroyRef=u(P);analytics=u(N);cartItemRemoved=n(null);cartData=n(null);orderData=n(null);ordersData=n([]);ordersLoading=n(!1);ordersError=n(null);loading=n(!1);error=n(null);cartFetched=n(!1);billingAddress=n([]);selectedAddressId=T({source:this.billingAddress,computation:(e,t)=>{let r=t?.value??null;return r!=null&&e.some(o=>o.id===r)?r:e[0]?.id??null}});isEditingAddress=n(!1);subscriptionPlans=n([]);plansLoading=n(!1);plansError=n(null);recommendedPlans=n([]);recommendedPlansLoading=n(!1);recommendedPlansError=n(null);hasCartItems=i(()=>{let e=this.cartData();return e?e.cartitem_data.length>0:!1});invoiceItems=i(()=>this.orderData()?.order_items??[]);invoiceItemCount=i(()=>this.invoiceItems().length);invoiceBillingAddress=i(()=>this.orderData()?.billing_address??null);invoiceFormattedAddress=i(()=>{let e=this.invoiceBillingAddress();return e?[e.address1,e.locality,e.landmark,e.city,e.state,e.country,e.zipcode].filter(Boolean).join(", "):""});invoiceUserData=i(()=>{let e=this.invoiceBillingAddress();return{name:e?.email_id??"",email:e?.email_id??"",mobile:e?.phone_no??""}});invoiceCurrency=i(()=>this.orderData()?.country_details?.currency??"USD");invoiceCurrencySymbol=i(()=>this.orderData()?.country_details?.currency_symbol??"$");invoicePaymentStatus=i(()=>this.orderData()?.payment_status??null);invoiceTransactionDetails=i(()=>this.orderData()?.transcation_details??null);invoiceSubTotal=i(()=>this.orderData()?.sub_total??0);invoiceTotalDiscount=i(()=>this.orderData()?.total_discount??0);invoiceTotalDiscountPercent=i(()=>this.orderData()?.total_discount_percent??0);invoiceGrandTotal=i(()=>this.orderData()?.adjusted_total_amount??0);invoiceTaxAmount=i(()=>this.orderData()?.total_tax??0);invoiceCouponDetails=i(()=>this.orderData()?.coupon_details??null);invoiceProductDiscount=i(()=>{let e=this.invoiceItems();if(!e.length)return 0;let t=0,r=0;for(let o of e)t+=o.base_price,r+=o.selling_price;return t-r});cartState=i(()=>{let e=this.cartData();if(!e)return{hasCourses:!1,hasSubscription:!1,isMixedCart:!1};let t=!1,r=!1;for(let o of e.cartitem_data)if(o.item_details.delivery_mode==="subscription"?r=!0:t=!0,t&&r)break;return{hasCourses:t,hasSubscription:r,isMixedCart:t&&r}});setCartData(e){e?.cartitem_data&&(e=g(p({},e),{cartitem_data:e.cartitem_data.map(t=>t)})),this.cartData.set(e)}loadMyBucket(e={}){!e.force&&(this.loading()||this.cartFetched())||(this.loading.set(!0),this.error.set(null),this.http.get(a.myBucket.path).subscribe({next:t=>{this.setCartData(t?.data??null),this.cartFetched.set(!0),this.loading.set(!1)},error:t=>{this.logger.error("Failed to load my bucket",t),this.setCartData(null),this.cartFetched.set(!0),this.error.set("Failed to load my bucket"),this.loading.set(!1)}}))}loadBillingAddress(){if(this.cartState().isMixedCart){this.notification.info("Cart contains a subscription along with other courses.","After purchasing a subscription, most courses will be accessible at no additional cost. Please remove either all courses or the subscription to proceed.");return}this.http.get(a.listAddress.path).subscribe({next:e=>{this.billingAddress.set(e?.data??[])},error:e=>{this.logger.error("Failed to load billing address",e)}})}saveBillingAddress(e){this.http.post(a.addAddress.path,e).subscribe({next:t=>{this.notification.success("Success","Address saved successfully");let r=this.billingAddress()||[];t?.data&&this.billingAddress.set([...r,t.data])},error:t=>{this.logger.error("Failed to save address",t)}})}updateBillingAddress(e,t){let r=a.updateAddress.path.replace(":id",String(e));this.http.put(r,t).subscribe({next:o=>{this.notification.success("Success","Address updated successfully"),o?.data&&this.billingAddress.update(s=>s.map(d=>d.id===e?o.data:d))},error:o=>{this.logger.error("Failed to update address",o)}})}deleteAddress(e){let t=a.deleteAddress.path.replace(":id",String(e));this.http.delete(t).subscribe({next:()=>{this.billingAddress.update(r=>r.filter(o=>o.id!==e)),this.notification.success("Success","Address deleted successfully")},error:r=>{this.logger.error("Failed to delete address",r)}})}
1removeCoursesFromCart(){}removeCartItem(e){let t=this.cartData()?.cartitem_data?.find(r=>r.id===e);this.http.post(a.removeBucketItem.path,{cartitem_id:e}).subscribe({next:r=>{this.setCartData(r?.data??null),this.notification.success("Success","Item removed from cart"),t&&this.cartItemRemoved.set(t.item_details.id),this.subscriptionPlans.update(o=>o.map(s=>s.is_added_to_cart?g(p({},s),{is_added_to_cart:!1}):s))},error:r=>{this.logger.error("Failed to remove cart item",r)}})}getCoupons(){return this.http.get(a.listCoupon.path)}coupons=n([]);couponsLoaded=!1;loadCoupons(){this.couponsLoaded||(this.couponsLoaded=!0,this.getCoupons().subscribe({next:e=>this.coupons.set(e.data??[]),error:()=>this.coupons.set([])}))}applyCoupon(e){return this.http.post(a.applyCoupon.path,{coupon_code:e}).pipe(f({next:t=>{this.setCartData(t?.data??null),this.notification.success("Coupon Applied","The coupon has been applied to your cart.")},error:t=>{this.logger.error("Failed to apply coupon",t)}}))}removeCoupon(e){this.http.post(a.removeCoupon.path,{coupon_code:e}).subscribe({next:t=>{this.setCartData(t?.data??null),this.notification.success("Success","Coupon removed successfully")},error:t=>{this.logger.error("Failed to remove coupon",t)}})}async openCouponDialog(){let e=this.cartData();if(!e)return;let{CouponDialog:t}=await import("./chunk-XQV3EOLC.js");this.dialog.open(t,{width:"460px",maxWidth:"95vw",ariaLabel:"All Coupons",data:{cartData:e},injector:this.injector}).afterClosed$.subscribe(o=>{o&&this.setCartData(o)})}async openFirmSponsorshipDialog(e,t="yearly"){let{FirmSponsorshipDialog:r}=await import("./chunk-ZO25FWEW.js");this.dialog.open(r,{maxWidth:"95vw",ariaLabel:"Firm Sponsorship",data:{planId:e.id,planName:e.subscription_name},injector:this.injector}).afterClosed$.pipe(_(this.destroyRef)).subscribe(s=>{if(!s)return;if(s.skipped){this.addToCart(e.id,"subscription",e.price_detail,t);return}let d=this.auth.currentUser()?.company?.[0]?.id??null,m=!!s.companyId&&s.companyId!==d;this.http.post(v.applyFirmSponsorship.path,{company_id:s.companyId,consent_given:s.consent,subscription_id:e.id,ld_spoc_email:s.spocEmail}).pipe(y(l=>(this.logger.error("Failed to submit firm sponsorship",l),this.notification.error("Sponsorship Failed","We could not submit your sponsorship request. Please try again."),b)),f(()=>this.notification.success("Sponsorship Request Submitted","We'll reach out to your firm's L&D team on your behalf.")),D(()=>{if(!m)return b;let l={company_id:s.companyId};return this.http.patch(v.saveProfile.path,l).pipe(y(c=>(this.logger.error("Profile update after sponsorship failed",c),b)))}),_(this.destroyRef)).subscribe(l=>{l?.status&&l.user&&this.auth.setAuthenticated(l.user)})})}proceedToPayment(e=!1){let t=this.cartData()?.cart_id,r=this.selectedAddressId();if(!t||!r){this.notification.error("Error","Please select a billing address to proceed.");return}this.loading.set(!0),this.http.post(a.proceedToPayment.path,{cart_id:t,address_id:r,is_trial:e}).subscribe({next:o=>{this.loading.set(!1),o?.data?.approval_url?(this.analytics.trackEvent("begin_checkout",p({cart_id:t,is_trial:e},this.cartAnalyticsParams())),window.location.href=o.data.approval_url):this.notification.error("Error","Payment URL not available. Please try again.")},error:o=>{this.loading.set(!1),this.logger.error("Failed to proceed to payment",o)}})}addToCart(e,t,r,o="yearly",s){this.http.post(a.addBucketItem.path,{item_id:e,item_type:t,pay_method:o}).subscribe({next:d=>{let m=d?.data??null;this.setCartData(m),this.notification.success("Success","Item added to cart"),this.analytics.trackEvent("add_to_cart",{course_id:e,course_type:t,base_price:r?.base_price,selling_price:r?.selling_price,product_discount:r?.discount,items:[{course_id:String(e),course_type:t,price:r?.selling_price}]}),this.subscriptionPlans.update(l=>l.map(c=>c.id===e?g(p({},c),{is_added_to_cart:!0}):c)),this.loadMyBucket({force:!0}),s?s():this.openCartDrawer()},error:d=>{this.logger.error("Failed to add item to cart",d)}})}cartAnalyticsParams(e){let t=this.cartData(),r=t?.cartitem_data??[];return g(p({},e?{page_name:e}:{}),{base_price:r.reduce((o,s)=>o+(s.base_price??0),0),selling_price:r.reduce((o,s)=>o+(s.selling_price??0),0),product_discount:t?.total_discount_amount??0,items:r.map(o=>({course_id:String(o.id),course_type:o.item_type??"",price:o.selling_price}))})}trackCartView(e){this.analytics.trackEvent("cart_view",this.cartAnalyticsParams(e))}async openCartDrawer(){let{CartDrawerDialog:e}=await import("./chunk-BMKRE4OQ.js");this.dialog.open(e,{width:"500px",maxWidth:"90vw",height:"100vh",position:"right",ariaLabel:"Cart",data:{},injector:this.injector})}async promptPartnerCodeOrSubscribe(e,t={}){let r=t.paymentType??"yearly";if(e.is_added_to_cart){this.loadMyBucket({force:!0}),t.onAdded?t.onAdded():this.openCartDrawer();return}
1if(e.is_partner_code_applied||this.auth.hasActivePlan()){this.addToCart(e.id,"subscription",e.price_detail,r,t.onAdded);return}let{PartnerCodePromptDialog:o}=await import("./chunk-IKD2KFVG.js");this.dialog.open(o,{maxWidth:"95vw",ariaLabel:"Continue to subscribe or apply a partner code",injector:this.injector}).afterClosed$.pipe(_(this.destroyRef)).subscribe(d=>{d?.action==="subscribe"?this.addToCart(e.id,"subscription",e.price_detail,r,t.onAdded):d?.action==="partner-code-applied"&&t.refreshPlansOnApply&&this.loadSubscriptionPlans()})}loadSubscriptionPlans(e={}){let t=!!e.recommendedOnly,r=t?this.recommendedPlans:this.subscriptionPlans,o=t?this.recommendedPlansLoading:this.plansLoading,s=t?this.recommendedPlansError:this.plansError,d=t?L:k;if(x(this.platformId)&&this.transferState.hasKey(d)){r.set(this.transferState.get(d,[])),this.transferState.remove(d);return}o.set(!0),s.set(null);let m=t?{is_recommended:"true"}:void 0;this.http.get(a.getSubscriptionPlans.path,{params:m}).subscribe({next:l=>{let c=l?.data??[];r.set(c),o.set(!1),I(this.platformId)&&this.transferState.set(d,c)},error:l=>{this.logger.error("Failed to load subscription plans",l),r.set([]),s.set("Failed to load subscription plans"),o.set(!1)}})}ordersCount=i(()=>this.ordersData().length);loadOrders(){this.ordersLoading.set(!0),this.ordersError.set(null),this.http.get(a.getOrders.path).subscribe({next:e=>{this.ordersData.set(e?.data??[]),this.ordersLoading.set(!1)},error:e=>{this.logger.error("Failed to load orders",e),this.ordersData.set([]),this.ordersError.set("Failed to load order history"),this.ordersLoading.set(!1)}})}loadOrderById(e){this.loading.set(!0),this.error.set(null);let t=`${a.getOrderById.path}?order_id=${e}`;this.http.get(t).subscribe({next:r=>{this.orderData.set(r?.data??null),this.loading.set(!1)},error:r=>{this.logger.error("Failed to load order details",r),this.orderData.set(null),this.error.set("Failed to load order details"),this.loading.set(!1)}})}cancelAutoRenewal(e){this.http.post(a.cancelAutoRenewal.path,{order_id:e}).subscribe({next:t=>{this.notification.success("Success",t?.message??"Auto renewal has been cancelled."),this.loadOrders()},error:t=>
1{this.logger.error("Failed to cancel auto renewal",t)}})}reactivateAutoRenewal(e){this.http.post(a.reactivateAutoRenewal.path,{order_id:e}).subscribe({next:t=>{this.notification.success("Success",t?.message??"Auto renewal has been reactivated."),this.loadOrders()},error:t=>{this.logger.error("Failed to reactivate auto renewal",t)}})}navigateToStripeCustomerDashboard(e){this.http.post(a.navigateToStripeCustomerDashboard.path,{order_id:e}).subscribe({next:t=>{t?.session_url?window.open(t.session_url,"_blank"):this.notification.error("Error","Could not open Stripe dashboard.")},error:t=>{this.logger.error("Failed to open Stripe customer dashboard",t)}})}openStripeCustomerPortal(){this.http.post(a.navigateToStripeCustomerDashboard.path,{}).subscribe({next:e=>{e?.session_url?window.open(e.session_url,"_blank"):this.notification.error("Error","Could not open Stripe dashboard.")},error:e=>{this.logger.error("Failed to open Stripe customer portal",e)}})}static \u0275fac=function(t){return new(t||h)};static \u0275prov=C({token:h,factory:h.\u0275fac,providedIn:"root"})};export{a,B as b};
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.