import { ThemeColorsContext } from 'Components/utils/colors' import { EngineContext } from 'Components/utils/EngineContext' import useDisplayOnIntersecting from 'Components/utils/useDisplayOnIntersecting' import { formatValue } from 'Engine/format' import { add, max } from 'ramda' import React, { useContext } from 'react' import emoji from 'react-easy-emoji' import { useTranslation } from 'react-i18next' import { useSelector } from 'react-redux' import { animated, config, useSpring } from 'react-spring' import { DottedName } from 'Rules' import { targetUnitSelector } from 'Selectors/simulationSelectors' import './Distribution.css' import './PaySlip' import { getCotisationsBySection } from './PaySlip' import RuleLink from './RuleLink' export default function Distribution() { const targetUnit = useSelector(targetUnitSelector) const engine = useContext(EngineContext) const distribution = (getCotisationsBySection( useContext(EngineContext).getParsedRules() ).map(([section, cotisations]) => [ section, cotisations .map(c => engine.evaluate(c, { unit: targetUnit })) .reduce( (acc, evaluation) => acc + ((evaluation?.nodeValue as number) || 0), 0 ) ]) as Array<[DottedName, number]>) .filter(([, value]) => value > 0) .sort(([, a], [, b]) => b - a) const maximum = distribution.map(([, value]) => value).reduce(max, 0) const total = distribution.map(([, value]) => value).reduce(add, 0) return ( <>
{branche.summary}