/* @flow */ import Observer from '@researchgate/react-intersection-observer' import withColours from 'Components/utils/withColours' import React, { Component } from 'react' import emoji from 'react-easy-emoji' import { Trans } from 'react-i18next' import { connect } from 'react-redux' import { config, Spring } from 'react-spring' import { compose } from 'redux' import répartitionSelector from 'Selectors/repartitionSelectors' import { flatRulesSelector } from 'Selectors/analyseSelectors' import Montant from 'Ui/Montant' import { isIE } from '../utils' import './Distribution.css' import './PaySlip' import RuleLink from './RuleLink' import type { ThemeColours } from 'Components/utils/withColours' import type { Répartition } from 'Types/ResultViewTypes.js' import { findRuleByDottedName } from 'Engine/rules' type Props = ?Répartition & { colours: ThemeColours } type State = { branchesInViewport: Array } const ANIMATION_SPRING = config.gentle class Distribution extends Component { elementRef = null state = { branchesInViewport: [] } handleBrancheInViewport = branche => (event, unobserve) => { if (!event.isIntersecting) { return } unobserve() this.setState(({ branchesInViewport }) => ({ branchesInViewport: [branche, ...branchesInViewport] })) } render() { const { colours: { colour }, rules, // $FlowFixMe ...distribution } = this.props if (!Object.values(distribution).length) { return null } const { répartition, cotisationMaximum, total, salaireChargé, salaireNet } = distribution return ( <>
{répartition.map( ([brancheDottedName, { partPatronale, partSalariale }]) => { const branche = findRuleByDottedName(rules, brancheDottedName), brancheInViewport = this.state.branchesInViewport.indexOf(brancheDottedName) !== -1 const montant = brancheInViewport ? partPatronale + partSalariale : 0 return ( {styles => (


{branche.shortDescription}

)}
) } )}
{salaireNet.montant} + Cotisations {total.partPatronale + total.partSalariale}
= {salaireChargé.montant}
) } } export default compose( withColours, connect(state => ({ ...répartitionSelector(state), rules: flatRulesSelector(state) })) )(Distribution) let ChartItemBar = ({ styles, colour, montant, total }) => (
{montant} {montant / (total.partPatronale + total.partSalariale)}
) let BranchIcône = ({ icône }) => (
{emoji(icône)}
)