import { CommonModule } from '@angular/common'; import { Component, Input, OnInit } from '@angular/core'; // modules import { AngularSvgIconModule } from 'angular-svg-icon'; // svg routes import { LastFuelPriceSvgRoutes } from './utils/svg-routes'; // constants import { LastFuelPriceProgressConstants } from './utils/constants'; // helpers import { LastFuelPriceProgressHelper } from './utils/helpers'; // enums import { eLastFuelPriceProgress } from './enums'; import { eStringPlaceholder, eUnit } from '../../enums'; // interfaces import { ILastFuelPriceProgressConfig, ILastFuelPriceProgressData, } from './interfaces'; @Component({ selector: 'app-ca-last-fuel-price-progress', templateUrl: './ca-last-fuel-price-progress.component.html', styleUrl: './ca-last-fuel-price-progress.component.scss', imports: [ // modules CommonModule, AngularSvgIconModule, ] }) export class CaLastFuelPriceProgressComponent implements OnInit { @Input() set lastFuelPriceData(data: ILastFuelPriceProgressData) { this.createLastFuelPriceCardData(data); } // svg routes public lastFuelPriceSvgRoutes = LastFuelPriceSvgRoutes; // enums public eStringPlaceholder = eStringPlaceholder; public eUnit = eUnit; // config public lastFuelPriceConfig: ILastFuelPriceProgressConfig[] = []; public lastFuelPriceColors: string[] = []; public isMapView: boolean = false; constructor() {} ngOnInit(): void { this.getConstantData(); } private getConstantData(): void { this.lastFuelPriceColors = LastFuelPriceProgressConstants.LAST_FUEL_PRICE_COLORS; } private createLastFuelPriceCardData( data: ILastFuelPriceProgressData ): void { const { pricePerGallon, lowestPricePerGallon, highestPricePerGallon, priceOutDated, defPrice, defLowestPrice, defHighestPrice, defPriceOutDated, isMapView, } = data; const gallonSvgData = LastFuelPriceProgressHelper.calculateSvgPosition( lowestPricePerGallon, highestPricePerGallon, pricePerGallon, priceOutDated, ); const defSvgData = LastFuelPriceProgressHelper.calculateSvgPosition( defLowestPrice, defHighestPrice, defPrice ); this.isMapView = isMapView; let fuelPriceConfig = [ { title: eLastFuelPriceProgress.DIESEL, totalValue: pricePerGallon, minValue: lowestPricePerGallon, maxValue: highestPricePerGallon, isOutdated: priceOutDated, isMapView, ...gallonSvgData, }, ]; if (!isMapView) fuelPriceConfig = [ ...fuelPriceConfig, { title: eLastFuelPriceProgress.DEF, totalValue: defPrice, minValue: defLowestPrice, maxValue: defHighestPrice, isOutdated: defPriceOutDated, isMapView, ...defSvgData, }, ]; this.lastFuelPriceConfig = [...fuelPriceConfig]; } }