import{a as Ae,b as I,c as z,d as v,e as O,f as x,z as Q}from"./chunk-6BOB6ZZM.js";import{a as m,b as _e,d as Me,f as xe,g as Ee}from"./chunk-I4IMW3RO.js";import{c as Be}from"./chunk-QAF4RSZW.js";import{f as ke}from"./chunk-RRWMTQIW.js";import{c as Re,e as De}from"./chunk-GYO3NTKL.js";import{oc as Ce}from"./chunk-VJMBWEKA.js";import{ia as je,ja as Ne}from"./chunk-3JG6DPSK.js";import{C as Oe,G as Te,H as we,U as J}from"./chunk-YFWLORNM.js";import{a as B}from"./chunk-MTSPOHEH.js";import{m as ye,o as K}from"./chunk-DAYGRJHR.js";import{D as l,a as ve,b as Pe,c as w}from"./chunk-VYUKN3XQ.js";import{f as Ie}from"./chunk-BRIVAFG5.js";import{Da as re,Ga as D,Hc as j,Ic as N,Jc as fe,K as F,L as le,M as ue,Na as M,Qa as de,Ta as d,Tc as q,Wd as a,Xd as be,Yd as X,_a as me,a as g,b as S,ca as V,fc as ge,fd as U,hb as he,m as C,od as Se,p as ie,pb as pe,rb as G,t as ce}from"./chunk-XNQ3RS5P.js";var Fe={title:"Protejeaz\u0103-\u021Bi deviceul cu o asigurare",description:"Po\u021Bi alege \xEEntre dou\u0103 tipuri de asigurare: Basic sau Premium \u0219i po\u021Bi activa asigurarea, oric\xE2nd, \xEEn primele 120 de zile calendaristice de la dat\u0103 achizi\u021Biei. Costul lunar al acesteia \u0219i valoarea asigurat\u0103 depind de pre\u021Bul standard al dispozitivului cump\u0103rat.",secondDescription:"\u021Aine cont c\u0103 asigurarea nu este purt\u0103toare de TVA, astfel c\u0103, tariful asigur\u0103rii alese, va fi inclus pe factura ta Orange lunar\u0103.",authBannerDescription:"Pentru a verifica dac\u0103 ai deviceuri ce pot fi asigurate, te rug\u0103m s\u0103 te autentifici.",errorMessage:"Ne pare r\u0103u dar a intervenit o eroare, te rug\u0103m revii mai t\xE2rziu.",emptyStateTitle:"Nu sunt disponibile oferte de asigur\u0103ri",emptyStateMessage:"\xCEn prezent, nu exist\u0103 oferte de asigurare disponibile. Te rug\u0103m s\u0103 revino mai t\xE2rziu."},Ke=["telefoane","tablete","smartwatches","obiecte-conectate"];var Xe={items:[],selectedItem:null,category:[],selectedCategoryItem:null,status:l.initial,selection:{selectedSlug:null,activeTab:I.Basic,products:[],selectedOption:null,imei:"",orderId:void 0,deviceOaCode:void 0,status:l.initial},insuranceProductCustomDetails:{categoryMappedProducts:null,notSellableReason:null},insurableProducts:null,product:null,error:null},se=new de("InsuranceState",{factory:()=>Xe});function Z(t,n){var u;n!=null&&n.injector||he(Z);let _=(u=n==null?void 0:n.injector)!=null?u:d(pe),e=_.get(G),i=new ce,r=t(i).subscribe();e.onDestroy(()=>r.unsubscribe());let o=c=>{let h;ge(c)?h=Pe(c,{injector:_}):ue(c)?h=c:h=F(c);let P=h.subscribe(p=>i.next(p));return r.add(P),P};return o.unsubscribe=r.unsubscribe.bind(r),o}var Ue=t=>t.replace(" ","-").toLowerCase();var E="https://storage.googleapis.com/orangero-assets/orange-eshop/insurance",L={phone:"".concat(E,"/phones-insurance.svg"),tablet:"".concat(E,"/tablet-insurance.svg"),watch:"".concat(E,"/watch-insurance.svg"),connectedObjects:"".concat(E,"/connected-object-insurance.svg")},W={phone:"".concat(E,"/phones-insurance-imei.svg"),tablet:"".concat(E,"/tablet-insurance-imei.svg"),watch:"".concat(E,"/watch-insurance-imei.svg"),connectedObjects:"".concat(E,"/connected-object-insurance-imei.svg")};var ze=t=>{switch(t){case v.Phone:return L.phone;case v.Tablet:return L.tablet;case v.Smartwatch:return L.watch;case v.ConnectedObject:return L.connectedObjects}},Le=t=>{switch(t){case v.Phone:return W.phone;case v.Tablet:return W.tablet;case v.Smartwatch:return W.watch;case v.ConnectedObject:return W.connectedObjects}};var oe=t=>({categoryId:t.categoryId,slug:Ue(t.title),icon:ze(t.title),imeiIcon:Le(t.title),subTitle:t.subTitle,title:t.title,startingPrice:t.startingPrice});var We=t=>{switch(t){case O.Phone:return v.Phone;case O.Tablet:return v.Tablet;case O.Smartwatch:return v.Smartwatch;case O.ConnectedObject:return v.ConnectedObject}},ft=t=>{switch(t){case B.phones:return O.Phone;case B.tablets:return O.Tablet;case B.connected:case B.modems:case B.tvs:return O.ConnectedObject}};var Ye=(()=>{let n=class n{checkImeiAndInitiatePurchase(e,i){return C(this,null,function*(){var r;try{let o=this.findInsurableProductByImei(e,i);return o?this.canInitiatePurchase(o)?this.getAvailableOption(o)?!0:(console.warn("No available purchase options for IMEI:",e),!1):(console.warn("Cannot initiate purchase for IMEI:",{imei:e,productState:o.state,availableOptions:((r=o.options)==null?void 0:r.filter(c=>(c==null?void 0:c.state)==="CAN_BUY").length)||0}),!1):(console.log("Current IMEI not found in processed data"),!1)}catch(o){throw console.error("Error in checkImeiAndInitiatePurchase:",{currentImei:e,error:o instanceof Error?o.message:"Unknown error"}),o}})}extractInsurableProductByImei(e,i){var r,o,u;if(!(e!=null&&e.trim()))return console.warn("No current IMEI provided for extraction"),null;if(!((r=i==null?void 0:i.categoryMappedProducts)!=null&&r.length))return console.warn("No category mapped products available for extraction"),null;for(let c of i.categoryMappedProducts){if(!((u=(o=c==null?void 0:c.product)==null?void 0:o.insurableProducts)!=null&&u.length))continue;let h=c==null?void 0:c.product.insurableProducts.find(P=>P.imei===e);if(h)return h}return null}findInsurableProductByImei(e,i){var r,o;if(!e||!(i!=null&&i.categoryMappedProducts))return null;for(let u of i.categoryMappedProducts){let c=(o=(r=u.product)==null?void 0:r.insurableProducts)==null?void 0:o.find(h=>h.imei===e);if(c)return c}return null}canInitiatePurchase(e){var i;return!!(e.state==="CAN_BUY"&&((i=e.options)!=null&&i.some(r=>(r==null?void 0:r.state)==="CAN_BUY")))}getAvailableOption(e){var i;return((i=e.options)==null?void 0:i.find(r=>(r==null?void 0:r.state)==="CAN_BUY"))||null}};n.\u0275fac=function(i){return new(i||n)},n.\u0275prov=M({token:n,factory:n.\u0275fac,providedIn:"root"});let t=n;return t})();var $e=_e({providedIn:"root"},Ee(()=>d(se)),Me(({items:t,selection:n,insuranceProductCustomDetails:_})=>{let e=a(()=>n().selectedSlug),i=a(()=>{let s=e();return s?We(s):null}),r=a(()=>{let s=i();return t().find(b=>b.title===s)}),o=a(()=>{let s=r();return s?oe(s):null}),u=a(()=>{var s;return((s=_())==null?void 0:s.categoryMappedProducts)||[]}),c=a(()=>{var y,f;let s=r();if(!s)return null;let b=(f=(y=u())==null?void 0:y.find(T=>(T==null?void 0:T.categoryId)===(s==null?void 0:s.categoryId)))==null?void 0:f.product;return b||null}),h=a(()=>{let s=c(),b=s==null?void 0:s.insurableProducts;return b||null}),P=a(()=>t().map(s=>oe(s))),p=a(()=>{let s=_();if(!s)return null;let b=(s.categoryMappedProducts||[]).filter(f=>f!=null),y=b.filter(f=>f.state===Ae.CanBuy);return{categoryMappedProducts:b,notSellableReason:s.notSellableReason||null,isAvailable:y.length>0&&!s.notSellableReason,availableProducts:y}}),A=a(()=>{let s=p();return(s==null?void 0:s.notSellableReason)||null}),Y=a(()=>A()!==null),$=a(()=>{let s=A();if(!s)return null;if(s.message)return s.message;switch(s.reason){case z.RequestedTierNotAvailableForPurchase:return"Nu s-a g\u0103sit nici o asigurare, pentru acest tip de asigurare.";case z.NoInsuranceFound:return"Nu s-a g\u0103sit nici o asigurare";default:return"A intervenit o eroare"}}),k=a(()=>{let s=p();return(s==null?void 0:s.availableProducts)||[]}),R=a(()=>k().length>0),H=a(()=>{var b,y;let s=r();return s?!!(s&&((b=s.options)!=null&&b.BASIC)&&s.options.BASIC.length>0||s&&((y=s.children)!=null&&y.some(f=>{var T;return((T=f==null?void 0:f.options)==null?void 0:T.BASIC)&&f.options.BASIC.length>0}))):!1}),ae=a(()=>{var b,y;let s=r();return s?!!(s&&((b=s.options)!=null&&b.PREMIUM)&&s.options.PREMIUM.length>0||s&&((y=s.children)!=null&&y.some(f=>{var T;return((T=f==null?void 0:f.options)==null?void 0:T.PREMIUM)&&f.options.PREMIUM.length>0}))):!1}),qe=a(()=>[H()?I.Basic:null,ae()?I.Premium:null]);return{selectedItem:r,selectedCategoryItem:o,product:c,category:P,insurableProducts:h,selectedSlug:e,processedProductDetails:p,notSellableReason:A,isNotSellable:Y,notSellableMessage:$,availableProducts:k,hasAvailableProducts:R,availableTiers:qe,hasBasicTier:H,hasPremiumTier:ae}}),xe((t,n=d(Q),_=d(Ye),e=d(K),i=w(e.getWithSelector(J)))=>({loadCategoryOfferings:Z(ie(D(()=>m(t,{status:l.loading,error:null})),re(()=>n.fetchCategoryOfferings().pipe(D({next:r=>{if(!r)throw new Error("Empty response received from server");let o=r.items;if(o.length===0){m(t,{items:[],status:l.success});return}m(t,{items:o,status:l.success,error:null})},error:r=>{m(t,{error:r,status:l.error})}}),V(r=>{let o={message:Fe.errorMessage||"Unable to load insurance offerings. Please try again.",code:"LOAD_OFFERINGS_FAILED",timestamp:new Date().toISOString()};return m(t,{error:o,status:l.error}),F(null)}))))),loadProductCustomDetails:Z(ie(D(r=>{m(t,{selection:S(g({},t.selection()),{status:l.loading}),error:null})}),re(r=>n.getInsuranceProductCustomDetails(r).pipe(D({next:o=>C(void 0,null,function*(){var p,A,Y,$,k;if(!o.success){let R=((A=(p=o.errors)==null?void 0:p[0])==null?void 0:A.message)||"Failed to load product details";m(t,{selection:S(g({},t.selection()),{status:l.error}),error:{message:R,code:(($=(Y=o.errors)==null?void 0:Y[0])==null?void 0:$.code)||"API_ERROR",timestamp:new Date().toISOString()},status:l.error});return}let u=(k=o.data)==null?void 0:k.getInsuranceProductCustomDetails,c=n.processInsuranceProductDetails(u),h=t.selection().imei,P=t.selection().selectedOption===x.Custom;if(m(t,{selection:S(g({},t.selection()),{status:l.success}),error:null,status:t.status()===l.loading?l.success:t.status(),insuranceProductCustomDetails:u||void 0}),P&&h&&c)try{if(yield _.checkImeiAndInitiatePurchase(h,c)){let H=_.extractInsurableProductByImei(h,u);n.addInsurance(t.selection().selectedOption,H,i(),h,t.selection().activeTab)}}catch(R){console.error("Auto-purchase failed:",R)}c.notSellableReason&&console.warn("\u26A0\uFE0F Product not sellable:",{reason:c.notSellableReason.reason,message:c.notSellableReason.message})}),error:o=>{var c,h,P,p;console.error("Failed to load product details:",o);let u=((h=(c=o.errors)==null?void 0:c[0])==null?void 0:h.message)||"Unable to load product details. Please try again.";m(t,{selection:S(g({},t.selection()),{status:l.error}),error:{message:u,code:((p=(P=o.errors)==null?void 0:P[0])==null?void 0:p.code)||"LOAD_FAILED",timestamp:new Date().toISOString()},status:l.error})}}),V(o=>(console.error("Unhandled error in loadProductCustomDetails:",o),m(t,{selection:S(g({},t.selection()),{status:l.error}),error:{message:"A ap\u0103rut o eroare nea\u0219teptat\u0103. Te rug\u0103m s\u0103 \xEEncerci din nou.",code:"UNEXPECTED_ERROR",timestamp:new Date().toISOString()},status:l.error}),F(null))))))),getInsuranceProductCustomDetails(r){return m(t,{selection:S(g({},t.selection()),{status:l.loading})}),n.getInsuranceProductCustomDetails(r).pipe(V(o=>(console.error("Error fetching insurance product details:",o),m(t,{error:o,status:l.error}),le(()=>o))),D(({data:o,errors:u})=>{let c=u?u[0].message:"A intervenit o eroare.";m(t,{selection:S(g({},t.selection()),{status:l.success}),error:u?c:null,status:u?l.error:t.status(),insuranceProductCustomDetails:(o==null?void 0:o.getInsuranceProductCustomDetails)||void 0})}))},setSelectedCategorySlug(r){m(t,{selection:S(g({},t.selection()),{selectedSlug:r})})},setActiveTab(r){m(t,{selection:S(g({},t.selection()),{activeTab:r})})},setSelectedOption(r){m(t,{selection:S(g({},t.selection()),{selectedOption:r})})},setImei(r){m(t,{selection:S(g({},t.selection()),{imei:r})})},setOrderId(r){m(t,{selection:S(g({},t.selection()),{orderId:r})})},setDeviceOaCodeId(r){m(t,{selection:S(g({},t.selection()),{deviceOaCode:r})})},goWithBasic(){m(t,{selection:S(g({},t.selection()),{activeTab:I.Basic})})},clearError:()=>m(t,{error:null}),resetStore:()=>{let r=d(se);m(t,r)}})));var ne=t=>t.length>=15&&t.length<=16,He=t=>t.length>=5&&t.length<=20;var Ve=(()=>{let n=class n{constructor(){this.dialogRef=d(Re),this.domSanitizer=d(Ie),this.matIconRegistry=d(je),this.loadIcons()}confirm(){this.dialogRef.close({action:"confirm"})}cancel(){this.dialogRef.close({action:"cancel"})}loadIcons(){this.matIconRegistry.addSvgIconLiteral("ico_close_icon",this.domSanitizer.bypassSecurityTrustHtml(Be))}};n.\u0275fac=function(i){return new(i||n)},n.\u0275cmp=me({type:n,selectors:[["oro-premium-option-unavailable-modal"]],standalone:!0,features:[Se],decls:14,vars:0,consts:[[1,"premium-option-unavailable"],[1,"premium-option-unavailable__header"],[1,"premium-option-unavailable__title"],["aria-label","Close",1,"premium-option-unavailable__close",3,"click"],["aria-hidden","false","svgIcon","ico_close_icon",1,"premium-option-unavailable__close-icon"],[1,"premium-option-unavailable__body"],[1,"premium-option-unavailable__text"],[1,"premium-option-unavailable__action"],[1,"premium-option-unavailable__action-button",3,"click"],[1,"premium-option-unavailable__action-button","premium-option-unavailable__action-button--primary",3,"click"]],template:function(i,r){i&1&&(j(0,"div",0)(1,"div",1)(2,"h3",2),U(3," Planul Premium nu este disponibil "),N(),j(4,"button",3),q("click",function(){return r.cancel()}),fe(5,"mat-icon",4),N()(),j(6,"div",5)(7,"p",6),U(8," Pentru acest produs planul Premium nu este disponibil. Po\u021Bi s\u0103 mergi mai departe folosind planul Basic. "),N()(),j(9,"div",7)(10,"button",8),q("click",function(){return r.cancel()}),U(11," \xCEnchide "),N(),j(12,"button",9),q("click",function(){return r.confirm()}),U(13," Continu\u0103 cu Basic "),N()()())},dependencies:[Ne],styles:[".premium-option-unavailable[_ngcontent-%COMP%]{display:flex;flex-direction:column}.premium-option-unavailable__header[_ngcontent-%COMP%]{border-bottom:1px solid rgb(224,224,224);display:flex;justify-content:space-between;align-items:center;padding-bottom:1rem}.premium-option-unavailable__title[_ngcontent-%COMP%]{color:#000;font-size:21px;font-weight:700;letter-spacing:-.26px;margin:0}.premium-option-unavailable__close[_ngcontent-%COMP%]{display:flex;justify-content:center;align-items:center;max-width:40px;max-height:40px;padding:0;margin:0;border:none;background:transparent}.premium-option-unavailable__close-icon[_ngcontent-%COMP%]{height:20px!important;width:20px!important}.premium-option-unavailable__body[_ngcontent-%COMP%]{border-bottom:1px solid rgb(224,224,224);padding:1rem 0}@media screen and (min-width: 768px){.premium-option-unavailable__body[_ngcontent-%COMP%]{padding:20px 0}}.premium-option-unavailable__text[_ngcontent-%COMP%]{font-size:17px;font-weight:400;letter-spacing:-.21px;margin:0}.premium-option-unavailable__number-wrap[_ngcontent-%COMP%]{display:flex;justify-content:center;align-items:center;gap:7px;padding:1rem 0;margin:0;list-style:none}.premium-option-unavailable__number[_ngcontent-%COMP%]{border-radius:100%;background:#d8d8d8;text-align:center;width:43px;height:43px;display:flex;justify-content:center;align-items:center;color:#000;font-size:40px;font-weight:700;letter-spacing:-.5px}.premium-option-unavailable__action[_ngcontent-%COMP%]{display:flex;justify-content:center;align-items:center;padding-top:1rem;margin-top:auto;gap:1rem}.premium-option-unavailable__action-button[_ngcontent-%COMP%]{display:flex;justify-content:center;align-items:center;border:2px solid rgb(0,0,0);font-size:14px;font-weight:700;text-align:center;line-height:32px;width:100%;max-width:150px;background:#fff}.premium-option-unavailable__action-button--primary[_ngcontent-%COMP%]{border-color:#ff7900;background:#ff7900;color:#fff}.premium-option-unavailable__action-button--primary[_ngcontent-%COMP%]:hover{border-color:#f16e00;background:#f16e00}"]});let t=n;return t})();var te=(()=>{let n=class n{constructor(){this.STORAGE_KEY="insurance_selection",this.EXPIRY_DURATION=24*60*60*1e3}saveSelection(e){var i,r,o,u;try{let c={selectedSlug:(i=e.selectedSlug)!=null?i:null,activeTab:(r=e.activeTab)!=null?r:I.Basic,selectedOption:(o=e.selectedOption)!=null?o:null,imei:(u=e.imei)!=null?u:"",orderId:e.orderId,deviceOaCode:e.deviceOaCode,timestamp:Date.now()};localStorage.setItem(this.STORAGE_KEY,JSON.stringify(c))}catch(c){console.warn(this.getErrorMessage("save"),c)}}loadSelection(){try{let e=localStorage.getItem(this.STORAGE_KEY);if(!e)return null;let i=JSON.parse(e);return this.isExpired(i.timestamp)?(this.clearSelection(),null):this.isValidSelection(i)?i:(this.clearSelection(),null)}catch(e){return console.warn(this.getErrorMessage("load"),e),this.clearSelection(),null}}clearSelection(){try{localStorage.removeItem(this.STORAGE_KEY)}catch(e){console.warn(this.getErrorMessage("clear"),e)}}shouldPersistSelection(e){return!!(e!=null&&e.selectedSlug||e!=null&&e.selectedOption||e!=null&&e.imei&&e.imei.length>0)}updatePartialSelection(e){let i=this.loadSelection();if(!i&&this.shouldPersistSelection(e))return;let r=S(g(g({},i),e),{timestamp:Date.now()});this.saveSelection(r)}isExpired(e){return Date.now()-e>this.EXPIRY_DURATION}isValidSelection(e){return e&&typeof e=="object"&&typeof e.timestamp=="number"&&(e.activeTab===I.Basic||e.activeTab===I.Premium)}getErrorMessage(e){switch(e){case"save":return"Failed to save insurance selection to localStorage:";case"load":return"Failed to load insurance selection from localStorage:";case"clear":return"Failed to clear insurance selection from localStorage:";default:return"Insurance localStorage error"}}};n.\u0275fac=function(i){return new(i||n)},n.\u0275prov=M({token:n,factory:n.\u0275fac,providedIn:"root"});let t=n;return t})();var Ge=(()=>{let n=class n{constructor(){this.persistenceService=d(te)}restorePersistedSelection(e){let i=this.persistenceService.loadSelection();if(!i)return!1;try{return be(()=>{i.selectedSlug&&e.setSelectedCategorySlug(i.selectedSlug),i.activeTab&&e.setActiveTab(i.activeTab),i.selectedOption&&e.setSelectedOption(i.selectedOption),i.imei&&e.setImei(i.imei),i.orderId&&e.setOrderId(i.orderId),i.deviceOaCode&&e.setDeviceOaCodeId(i.deviceOaCode)}),!0}catch(r){return console.error("Failed to restore persisted insurance selection:",r),this.persistenceService.clearSelection(),!1}}persistCurrentSelection(e){this.persistenceService.saveSelection(e)}clearPersistedData(){this.persistenceService.clearSelection()}};n.\u0275fac=function(i){return new(i||n)},n.\u0275prov=M({token:n,factory:n.\u0275fac,providedIn:"root"});let t=n;return t})();var Si=(()=>{let n=class n{constructor(){this.storeSelector=d(K),this.insuranceStore=d($e),this.dialog=d(De),this.destroyRef=d(G),this.snackBar=d(ke),this.insuranceService=d(Q),this.selectionSyncService=d(Ge),this.persistenceService=d(te),this.isAuthenticated=w(this.storeSelector.getWithSelector(ye)),this.cartIsLoading=w(this.storeSelector.getWithSelector(Ce)),this.activeMsisdn=w(this.storeSelector.getWithSelector(J)),this.activeProfileIsAdmin=w(this.storeSelector.getWithSelector(Oe)),this.activeProfileIsPrepay=w(this.storeSelector.getWithSelector(Te)),this.activeProfileIsExplorer=w(this.storeSelector.getWithSelector(we)),this.items=this.insuranceStore.items,this.status=this.insuranceStore.status,this.error=this.insuranceStore.error,this.isInitial=a(()=>this.status()===l.initial),this.isLoading=a(()=>this.status()===l.loading),this.hasError=a(()=>this.status()===l.error),this.isSuccess=a(()=>this.status()===l.success),this.isPhonePage=a(()=>this.selectedItemCategoryId()===1),this.isSmartWatchCategory=a(()=>this.selectedSlug()===O.Smartwatch),this.isConnectedObjectCategory=a(()=>this.selectedSlug()===O.ConnectedObject),this.hasAvailableCategoryOfferings=a(()=>this.categoryOfferings().length>0),this.shouldShowEmptyState=a(()=>this.isSuccess()&&!this.hasError()&&this.items().length===0),this.selection=this.insuranceStore.selection,this.selectedSlug=this.insuranceStore.selectedSlug,this.selectionStatus=this.insuranceStore.selection.status,this.activeTab=a(()=>this.isSmartWatchCategory()?I.Premium:this.selection().activeTab),this.selectedOption=a(()=>this.selection().selectedOption),this.imei=a(()=>this.selection().imei),this.orderId=a(()=>this.selection().orderId),this.deviceOaCode=a(()=>this.selection().deviceOaCode),this.selectionIsInitial=a(()=>this.selectionStatus()===l.initial),this.selectionIsLoading=a(()=>this.selectionStatus()===l.loading),this.selectionHasError=a(()=>this.selectionStatus()===l.error),this.selectionIsSuccess=a(()=>this.selectionStatus()===l.success),this.showFromPrice=a(()=>this.selectedOption()===null||this.selectedOption()===x.Custom),this.selectedItem=this.insuranceStore.selectedItem,this.selectedItemCategoryId=a(()=>{var e;return(e=this.selectedItem())==null?void 0:e.categoryId}),this.selectedCategoryItem=this.insuranceStore.selectedCategoryItem,this.product=this.insuranceStore.product,this.categoryOfferings=this.insuranceStore.category,this.insurableProducts=this.insuranceStore.insurableProducts,this.selectedInsurableProduct=a(()=>{var e;return((e=this.insurableProducts())==null?void 0:e.find(i=>i.oaCode===this.selectedOption()))||null}),this.insuranceProductCustomDetails=this.insuranceStore.insuranceProductCustomDetails,this.categoryMappedProducts=a(()=>{var e;return((e=this.insuranceProductCustomDetails())==null?void 0:e.categoryMappedProducts)||[]}),this.notSellableReason=this.insuranceStore.notSellableReason,this.reason=a(()=>{var e;return((e=this.notSellableReason())==null?void 0:e.reason)||null}),this.canViewDetails=a(()=>!!this.isAuthenticated()),this.isNotSellable=this.insuranceStore.isNotSellable,this.notSellableMessage=this.insuranceStore.notSellableMessage,this.availableProducts=this.insuranceStore.availableProducts,this.hasAvailableProducts=this.insuranceStore.hasAvailableProducts,this.availableTiers=this.insuranceStore.availableTiers,this.hasPremiumTier=this.insuranceStore.hasPremiumTier,this.hasBasicTier=this.insuranceStore.hasBasicTier,this.isTierNotAvailable=a(()=>this.isConnectedObjectCategory()&&this.selectedOption()===x.Custom&&this.reason()===z.RequestedTierNotAvailableForPurchase),this.isCurrentTierAvailable=a(()=>{let e=this.activeTab();return this.availableTiers().includes(e)}),this.shouldShowOtyPassword=a(()=>!this.activeProfileIsAdmin()&&!this.activeProfileIsPrepay()&&!this.activeProfileIsExplorer()),this.canNotProceedWithPurchase=a(()=>!!(this.isAuthenticated()&&this.selectedOption()===null||this.isAuthenticated()&&this.selectedOption()===x.Custom&&this.isPhonePage()&&!ne(this.imei())||this.isAuthenticated()&&this.selectedOption()===x.Custom&&!this.isPhonePage()&&!He(this.imei())||this.cartIsLoading())),this.purchaseBlockedReason=a(()=>this.isNotSellable()?this.selectedOption()?this.imei().length===0?"Te rug\u0103m s\u0103 introduci ".concat(this.isPhonePage()?"IMEI-ul":"SM-ul"," dispozitivului"):null:"Te rug\u0103m s\u0103 selectezi o op\u021Biune de asigurare":this.notSellableMessage()),this.persistSelectionEffect=X(()=>{let e=this.selection(),i={selectedSlug:this.selectedSlug(),activeTab:e.activeTab,selectedOption:e.selectedOption,imei:e.imei,orderId:e.orderId,deviceOaCode:e.deviceOaCode};this.persistenceService.shouldPersistSelection(i)&&this.persistenceService.saveSelection(i)},{allowSignalWrites:!0}),this.tierNotAvailableEffect=X(()=>{this.isTierNotAvailable()&&this.showTierNotAvailableAlert()}),this.autoClearErrorEffect=X(()=>{let e=this.isSuccess(),i=this.hasError();e&&i&&setTimeout(()=>{this.clearError()},3e3)})}initializeLoadInsuranceItems(){return C(this,null,function*(){try{this.restorePersistedSelection(),yield this.loadInsuranceItems()}catch(e){throw console.error("Failed to initialize Insurance Facade:",e),e}})}restorePersistedSelection(){return this.selectionSyncService.restorePersistedSelection(this.insuranceStore)}clearPersistedSelection(){this.selectionSyncService.clearPersistedData()}loadInsuranceItems(){return C(this,null,function*(){try{this.insuranceStore.loadCategoryOfferings()}catch(e){throw console.error("Failed to initiate insurance offerings load:",e),e}})}selectCategory(e){this.insuranceStore.setSelectedCategorySlug(e)}selectTier(e){if(!this.availableTiers().includes(e)){this.showTierNotAvailableAlert();return}this.insuranceStore.setActiveTab(e)}selectOption(e){this.insuranceStore.setSelectedOption(e)}setDeviceImei(e){this.insuranceStore.setImei(e)}setOrderId(e){this.insuranceStore.setOrderId(e)}setDeviceOaCode(e){this.insuranceStore.setDeviceOaCodeId(e)}selectBasicTier(){this.selectTier(I.Basic)}initiatePurchase(){return C(this,null,function*(){try{this.insuranceService.addInsurance(this.selectedOption(),this.selectedInsurableProduct(),this.activeMsisdn(),this.imei(),this.activeTab()),this.clearPersistedSelection()}catch(e){throw console.error("Purchase failed:",e),e}})}clearError(){this.insuranceStore.clearError()}resetSelection(){this.insuranceStore.setSelectedCategorySlug(null),this.insuranceStore.setActiveTab(I.Basic),this.insuranceStore.setSelectedOption(null),this.insuranceStore.setImei(""),this.insuranceStore.setOrderId(void 0),this.clearPersistedSelection()}initializeLoadProductDetails(){return C(this,null,function*(){try{this.restorePersistedSelection(),yield this.loadProductDetails()}catch(e){throw console.error("Failed to initialize Product Details Facade:",e),e}})}loadProductDetails(){return C(this,null,function*(){let e=this.selectedOption(),i=this.activeMsisdn(),r=this.selectedItemCategoryId(),o=this.activeTab(),u=this.imei(),c=this.deviceOaCode(),h=this.orderId();if(!o){console.warn("Cannot load product details: missing required parameters");return}let P={selectedOption:e,msisdn:i,deviceCategoryId:r,tier:o,imei:u,deviceOaCode:c,orderId:h};if(!this.canViewDetails()){let p=new Error("Insufficient permissions to view product details");throw console.warn("Permission denied for loading product details:",p),p}try{this.validateProductDetailsParams(P)}catch(p){throw console.error("Parameter validation failed:",p),p}try{let p=this.insuranceService.buildInsuranceProductDetailsRequest(e,i,r,o,u,c,h);this.insuranceStore.loadProductCustomDetails(p)}catch(p){throw console.error("Failed to load product details:",p),p}})}retryLoadProductDetails(){return C(this,null,function*(){try{yield this.loadProductDetails()}catch(e){throw e}})}preparePurchaseData(){return{deviceCategoryId:void 0,tier:this.activeTab(),deviceImei:void 0,imei:this.imei(),orderId:this.orderId(),userId:void 0}}showTierNotAvailableAlert(){this.dialog.open(Ve,{autoFocus:!1,disableClose:!1,minHeight:"170px",maxWidth:"650px"}).afterClosed().pipe(ve(this.destroyRef)).subscribe(i=>{(i==null?void 0:i.action)==="confirm"&&(this.selectOption(null),this.selectBasicTier(),this.loadProductDetails())})}showErrorAlert(e){this.snackBar.open(e,"Close",{duration:5e3,panelClass:["error-snackbar"]})}showSuccessAlert(e){this.snackBar.open(e,"Close",{duration:3e3,panelClass:["success-snackbar"]})}validateProductDetailsParams(e){if(e.selectedOption===x.Custom&&e.imei&&this.isPhonePage()&&!ne(e.imei))throw new Error("Invalid IMEI format for phone device")}};n.\u0275fac=function(i){return new(i||n)},n.\u0275prov=M({token:n,factory:n.\u0275fac,providedIn:"root"});let t=n;return t})();export{Fe as a,Ke as b,W as c,ft as d,Si as e};