/* @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/repartitionSelector' import './Distribution.css' import Montant from './Montant' import './PaySlip' import RuleLink from './RuleLink' import type { Répartition, Branche } from 'Types/ResultViewTypes.js' const brancheToEmoji: { [Branche]: string } = { retraite: '👵', santé: '🏥', famille: '👶', formation: '👩‍🎓', logement: '🏡', 'accidents du travail / maladies professionnelles': '☣️', 'assurance chômage': '💸', transport: '🚌', autres: '🔧' } const brancheToCounterparts: { [Branche]: string } = { retraite: 'Guarantees on average 60%-70% of your last activity income.', santé: 'Covers most of everyday-life health care needs and 100% for serious illnesses, e.g. hospital stays.', famille: 'Offers a balanced work and family life. Finances day nurseries and various child care. ', formation: 'Gives access to professional training for employees.', logement: 'Helps build new and affordable housing.', 'accidents du travail / maladies professionnelles': 'Offers full coverage of occupational illnesses or accidents.', 'assurance chômage': "Gives income to former employees while they're in search of a new job.", transport: 'Helps keep the price of a public transportation ticket low.', autres: 'Other contributions to the social system.' } const brancheToLabel: { [Branche]: string } = { 'accidents du travail / maladies professionnelles': 'accidents', 'assurance chômage': 'chômage' } 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 { répartition, cotisationMaximum, total, salaireChargé, salaireNet, colours: { colour } } = this.props return ( <>
{répartition.map(([branche, { partPatronale, partSalariale }]) => { const brancheInViewport = this.state.branchesInViewport.indexOf(branche) !== -1 const montant = brancheInViewport ? partPatronale + partSalariale : 0 return ( {styles => (

{brancheToLabel[branche] || branche} {'. '} {brancheToCounterparts[branche]}

)}
) })}
{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 ChartItemLegend = ({ branche }) => (
{emoji(brancheToEmoji[branche])}
)