import { createSelector } from 'reselect'; import { selectTrends } from 'app/modules/bunkerAdjustment/store/bunkerAdjustment.selectors'; import format from 'app/shared/pipes/date.pipe'; const prefixValueWithZero = (value) => value.toString().length === 1 ? `0${value}` : value; export const selectConsumptionTrends = createSelector( selectTrends, (trends) => { return trends?.map(item => { const month = prefixValueWithZero(item.month); const date = `${item.year}-${month}-01`; return { name: format.formatShortMonth(date).toUpperCase(), date: format.formatShortMonthWithYear(date), vesselConsumption: item.consumptionActual, consumptionSimulated: item.consumptionSimulated, }; }); } ); export const selectBasketPricesTrends = createSelector( selectTrends, (trends) => trends?.map((item) => { const month = prefixValueWithZero(item.month); const date = `${item.year}-${month}-01`; return { name: format.formatShortMonth(date).toUpperCase(), date: format.formatShortMonthWithYear(date), bunkerPriceCompliant: item.bunkerPriceCompliant, bunkerPriceNonCompliant: item.bunkerPriceNonCompliant, }; }) );