import { UserDataState } from '../../common/state/UserDataState'; import { QuoteService } from '../../common/services/QuoteService'; import { AnalyticsService } from '../../common/services/AnalyticsService'; import { Quote, Tariff, Bundle, TariffWithId } from '../../common/entities/Quote'; import { BundleName, BoltonName, Utility, TariffId } from '../../common/entities/Enums'; import { LayoutState } from "../../common/state/LayoutState"; import { ModalService } from '../../common/services/ModalService'; import tilModalOptions from '../../common/modals/TILModal'; export class PlanEVController implements ng.IController { loading: Boolean; quote: Quote; tariff: Tariff; bundle: Bundle; boltons: QuoteBolton[]; serviceType: string; standardTariff: Tariff; constructor(private $state: ng.ui.IStateService, private $window: ng.IWindowService, private layoutState: LayoutState, private userDataState: UserDataState, private quoteService: QuoteService, private analyticsService: AnalyticsService, private modal: ModalService) { this.loading = true; this.layoutState.layoutClass = 'layout-has-cart'; this.layoutState.back = () => this.$window.history.back(); } $onInit() { return this.quoteService.getQuote().then(this.quoteHandler, error => this.$state.go("^.get-quote")); } private quoteHandler = (quote: Quote) => { this.quote = quote; this.bundle = this.quote.bundles.find(bundle => bundle.name === "EV"); this.tariff = this.quote.tariffs[this.bundle.tariff]; this.standardTariff = this.quote.tariffs["Variable"]; this.boltons = this.getBoltonsFromQuote(this.quote, this.bundle); this.layoutState.title = this.bundle.displayName; this.analyticsService.push({event:'ViewPlan', tariff: this.bundle.tariff, bundle: this.bundle.name, cost: this.bundle.expectedAnnualSpend }); this.loading = false; } getBoltonsFromQuote(quote: Quote, bundle: Bundle): QuoteBolton[] { return !bundle ? [] : bundle.boltons.map(bundleBolton => { const quoteBolton = quote.boltons.find(quoteBolton => bundleBolton.name === quoteBolton.name); return { name: bundleBolton.name, displayName: quoteBolton.displayName, cost: quoteBolton.cost, description: quoteBolton.description, discountPercentage: bundleBolton.discountPercentage }; }); } switchToPlan() { this.userDataState.bundleName = this.bundle.name; this.userDataState.tariffId = this.bundle.tariff; return this.$state.go('^.switch'); } openTilModal(tariffId: TariffId, utility: Utility) { this.modal.open(tilModalOptions({ tariff: this.quote.tariffs[tariffId], til: this.quote.tariffs[tariffId].tils[utility], serviceType: this.quote.serviceType, utility: utility })); } openTilModalForEV(tariffId: TariffId, utility: Utility) { let tariffEV = { ... this.tariff }; delete tariffEV.renewableFuelPercentage; this.modal.open(tilModalOptions({ tariff: tariffEV, til: this.quote.tariffs[tariffId].tils[utility], serviceType: this.quote.serviceType, utility: utility })); } } interface QuoteBolton { name: BoltonName, displayName: string, cost: number, description: string, discountPercentage: number }