/* @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 Montant from 'Ui/Montant' import { isIE } from '../utils' import './Distribution.css' import './PaySlip' import RuleLink from './RuleLink' import type { Répartition } from 'Types/ResultViewTypes.js' type Props = ?Répartition & { colours: { colour: string } } 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 }, ...distribution } = this.props if (!Object.values(distribution).length) { return null } const { répartition, cotisationMaximum, total, salaireChargé, salaireNet } = distribution return ( <>
{répartition.map(([branche, { partPatronale, partSalariale }]) => { const brancheInViewport = this.state.branchesInViewport.indexOf(branche.id) !== -1 const montant = brancheInViewport ? partPatronale + partSalariale : 0 return ( {styles => (

{' : '} {branche.descriptionCourte}

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