import React from 'react'
import ReactApexChart from 'react-apexcharts'
import './styles.css'

const ApexChart = () => {
  const [state, setState] = React.useState({
    series: [
      {
        name: 'Headcount',
        data: [
          {
            x: 'Opening',
            y: 412,
          },
          {
            x: 'Graduate intake',
            y: 68,
          },
          {
            x: 'Lateral hires',
            y: 41,
          },
          {
            x: 'Voluntary exits',
            y: -57,
          },
          {
            x: 'Restructuring',
            y: -34,
          },
          {
            x: 'Closing',
            isTotal: true,
          },
        ],
      },
    ],
    options: {
      chart: {
        type: 'waterfall',
        height: 400,
      },
      plotOptions: {
        bar: {
          horizontal: true,
        },
      },
      title: {
        text: 'What moved headcount this year',
        align: 'left',
      },
      xaxis: {
        labels: {
          formatter: function (val) {
            return Math.round(val)
          },
        },
      },
      dataLabels: {
        formatter: function (val) {
          return (val > 0 ? '+' : '') + val
        },
      },
    },
  })

  return (
    <div>
      <div id="chart">
        <ReactApexChart
          options={state.options}
          series={state.series}
          type="waterfall"
          height={400}
        />
      </div>
    </div>
  )
}

export default ApexChart