import{d as x}from"./chunk-SFDJZTYR.js";import{b as u}from"./chunk-I6XJVXQ2.js";import{c as M,d as U}from"./chunk-UFF3QIQ4.js";import{a as B}from"./chunk-5L2Z4GZW.js";import{M as E,la as v}from"./chunk-OD6CMNJH.js";import{f as y,i as a}from"./chunk-UZOHO7NA.js";import{s as N}from"./chunk-QUA65JBC.js";import{c as _}from"./chunk-Z5BNBYBS.js";import{h as S}from"./chunk-SAGV4YDN.js";import{K as T,Ma as b,N as P,O as D,Sa as m,ba as A,va as g}from"./chunk-NRAZ4AKM.js";var h=function(e){return e.CanBuy="CAN_BUY",e.CannotBuy="CANNOT_BUY",e}(h||{}),d=function(e){return e.Basic="BASIC",e.Premium="PREMIUM",e}(d||{}),L=function(e){return e.Forbidden="FORBIDDEN",e.ImeiNotEligible="IMEI_NOT_ELIGIBLE",e.ImeiOrSerialNoNotValid="IMEI_OR_SERIAL_NO_NOT_VALID",e.InvalidProductDataFromTgw="INVALID_PRODUCT_DATA_FROM_TGW",e.NoEligibleCategories="NO_ELIGIBLE_CATEGORIES",e.NoExchangeRateAvailable="NO_EXCHANGE_RATE_AVAILABLE",e.NoInsuranceFound="NO_INSURANCE_FOUND",e.NoInsuranceTierAvailableToBuy="NO_INSURANCE_TIER_AVAILABLE_TO_BUY",e.NoRecentBoughtDevices="NO_RECENT_BOUGHT_DEVICES",e.NoRequestedCategories="NO_REQUESTED_CATEGORIES",e.NoSaleProductData="NO_SALE_PRODUCT_DATA",e.RequestedTierNotAvailableForPurchase="REQUESTED_TIER_NOT_AVAILABLE_FOR_PURCHASE",e}(L||{}),p=a`
    fragment Money on Money {
  currency
  displayValue
  value
  valueWithoutVat
}
    `,w=a`
    fragment InsuranceProductOfferedTierItem on InsuranceProductOfferedTierItem {
  tier
  startingPrice {
    ...Money
  }
  state
  isRequested
}
    ${p}`,j=a`
    fragment InsuranceOption on InsuranceOption {
  insuranceId
  tier
  fee {
    ...Money
  }
  state
}
    ${p}`,C=a`
    fragment InsuranceNotSellableReason on InsuranceNotSellableReason {
  reason
  message
}
    `,G=a`
    fragment InsurableProductItem on InsurableProductItem {
  imei
  oaCode
  categoryId
  displayName
  imageHref
  state
  standardPriceNoVat {
    ...Money
  }
  options {
    ...InsuranceOption
  }
  notSellableReason {
    ...InsuranceNotSellableReason
  }
}
    ${p}
${j}
${C}`,V=a`
    fragment InsuranceProductItem on InsuranceProductItem {
  deviceCategoryId
  requestedTier
  name
  insuranceId
  offeredTiers {
    ...InsuranceProductOfferedTierItem
  }
  insurableProducts {
    ...InsurableProductItem
  }
  price {
    ...Money
  }
  notSellableReason {
    ...InsuranceNotSellableReason
  }
}
    ${w}
${G}
${p}
${C}`,H=a`
    fragment CategoryMappedProducts on InsuranceProductCategorizedDetails {
  categoryId
  state
  product {
    ...InsuranceProductItem
  }
}
    ${V}`,Y=a`
    fragment InsuranceProductPersonalizedDetails on InsuranceProductPersonalizedDetails {
  categoryMappedProducts {
    ...CategoryMappedProducts
  }
  notSellableReason {
    ...InsuranceNotSellableReason
  }
}
    ${H}
${C}`,q=a`
    query GetInsuranceProductCustomDetails($request: InsuranceProductDetailsRequest) {
  getInsuranceProductCustomDetails(request: $request) {
    ...InsuranceProductPersonalizedDetails
  }
}
    ${Y}`;var l=function(e){return e.Custom="custom",e}(l||{});var Q=function(e){return e.Phone="Telefoane",e.Tablet="Tablete",e.Smartwatch="Smartwatches",e.ConnectedObject="Obiecte conectate",e}(Q||{}),k=function(e){return e.Phone="telefoane",e.Tablet="tablete",e.Smartwatch="smartwatches",e.ConnectedObject="obiecte-conectate",e}(k||{});var he=(()=>{let i=class i{constructor(){this.apollo=m(y),this.store=m(N),this.httpClient=m(S),this.insuranceCategoryOfferingsUrl=_.getInsuranceCategoryApi(),this.REQUEST_TIMEOUT=3e4,this.RETRY_COUNT=2}saveUserAgreement(t,r){let o=M(r.gdprConsents);this.store.dispatch(U({insuranceTermsAgreed:t,isAbove16:r.isAbove16,hasPaymentCommitment:r.hasPaymentCommitment,keepIdCard:r.keepIdCard,gdprConsents:o,notificationChannel:r.notificationChannel}))}fetchCategoryOfferings(){return this.httpClient.get(this.insuranceCategoryOfferingsUrl,{withCredentials:!0,headers:{Accept:"application/json","Content-Type":"application/json"}}).pipe(P(this.REQUEST_TIMEOUT),g(this.RETRY_COUNT),A(this.handleError))}buildInsuranceProductDetailsRequest(t,r,o,s,n,I,c){return r||console.error("Active MSISDN is required to build the insurance product details request."),{deviceCategoryId:void 0,deviceImei:t===l.Custom?n:void 0,deviceOaCode:I,msisdn:r,orderId:c,productCategoryIds:o?[o]:[],tier:s}}getInsuranceProductCustomDetails(t){return this.apollo.use(B).query({query:q,variables:{request:t},errorPolicy:"all",fetchPolicy:"cache-first"}).pipe(P(this.REQUEST_TIMEOUT),g(this.RETRY_COUNT),D(({data:r,errors:o,loading:s})=>{if(o&&o.length>0)return{success:!1,errors:o.map(c=>({message:c.message,code:c.extensions?.code||"GRAPHQL_ERROR",field:c.path?.join(".")||void 0})),metadata:{requestId:this.generateRequestId(),timestamp:new Date().toISOString()}};let n=r?.getInsuranceProductCustomDetails;return n?{success:!0,data:{getInsuranceProductCustomDetails:n},metadata:{requestId:this.generateRequestId(),timestamp:new Date().toISOString()}}:{success:!1,errors:[{message:"No product details returned from server",code:"EMPTY_RESPONSE"}],metadata:{requestId:this.generateRequestId(),timestamp:new Date().toISOString()}}}))}processInsuranceProductDetails(t){if(!t)return{categoryMappedProducts:[],notSellableReason:null,isAvailable:!1,availableProducts:[]};let r=(t.categoryMappedProducts||[]).filter(n=>n!=null),o=r.filter(n=>n.state===h.CanBuy),s=t.notSellableReason||null;return{categoryMappedProducts:r,notSellableReason:s,isAvailable:o.length>0&&!s,availableProducts:o}}addInsurance(t,r,o,s,n){if(!r||!o){console.error("Missing required fields: selectedProduct, selectedItem, or activeMsisdn");return}let c=t===l.Custom?s:r.imei,f=r.options?.[0]?.insuranceId,O=n===d.Basic?E.Basic:E.Premium,R=this.getInsuranceTerm(),F=this.getProductDetails(r,c);if(!f){console.error("Missing insuranceId");return}let $={productDetails:F,term:R,insuranceId:f,insuranceType:O,msisdn:o};this.dispatchAddInsuranceProduct($)}calculateLoggedInInsurableProduct(t,r){if(r===d.Basic){let o=t.options||[];return u(o)?.fee?.value||0}else{let o=t.options||[];return u(o)?.fee?.value||0}}calculateLoggedInItemPrice(t,r){if(r===d.Basic){let o=t.options?.BASIC||t.children?.find(n=>n?.options?.BASIC&&n.options.BASIC.length>0)?.options?.BASIC||[];return u(o)?.optionFee?.value||0}else{let o=t.options?.PREMIUM||t.children?.find(n=>n?.options?.PREMIUM&&n.options.PREMIUM.length>0)?.options?.PREMIUM||[];return u(o)?.optionFee?.value||0}}getProductDetails(t,r){return{oaCode:t.oaCode||"",imei:r||"",categoryId:t.categoryId||1,thumbnail:t.imageHref||""}}getInsuranceTerm(t=v.Months,r=24){return{unit:t,value:r}}dispatchAddInsuranceProduct(t){this.store.dispatch(x({insurance:t}))}handleError(t){return t.status===0?console.error("An error occurred:",t.error):console.error(`Backend returned code ${t.status}, body was: `,t.error),T(()=>new Error("Something bad happened; please try again later."))}generateRequestId(){return`req_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}};i.\u0275fac=function(r){return new(r||i)},i.\u0275prov=b({token:i,factory:i.\u0275fac,providedIn:"root"});let e=i;return e})();export{h as a,d as b,L as c,Q as d,k as e,l as f,he as g};