import { createSelector } from 'reselect'; import format from 'app/shared/pipes/date.pipe'; import { StoreState } from 'app/common/store/store.types'; const bunkerAdjustmentStateSlice = (state: StoreState) => state.bunkerAdjustment; export const selectPeriods = (state: StoreState) => bunkerAdjustmentStateSlice(state).periods; export const selectCurrentPeriod = (state: StoreState) => bunkerAdjustmentStateSlice(state).currentPeriod; export const selectCalculationsConsumption = (state: StoreState) => bunkerAdjustmentStateSlice(state).calculations.consumption; export const selectCalculationsSummary = (state: StoreState) => bunkerAdjustmentStateSlice(state).calculations.summary; export const selectCurrentPeriodName = createSelector(selectCurrentPeriod, period => period ? format.formatLongMonthWithYear(period) : ''); export const selectCurrentPeriodShortName = createSelector(selectCurrentPeriod, period => period ? format.formatShortMonthWithYear(period) : ''); export const selectKeyFigures = (state: StoreState) => bunkerAdjustmentStateSlice(state).keyFigures; export const selectTrends = (state: StoreState) => bunkerAdjustmentStateSlice(state).trends; export const selectPeriodOptions = createSelector(selectPeriods, (periods) => periods.map(period => ({ name: format.formatLongMonthWithYear(period.date), value: period.date, isActive: period.isActive, })));