import React from "react";
import type {CurrentUser} from "@/models/user";
import {connect} from "umi";
import type {ConnectState} from "@/models/connect";
import {DualAxes, Line} from "@ant-design/charts";
import * as numeral from "numeral";


const carTrafficChart: React.FC<{ currentUser?: CurrentUser}> = (props) => {
  const  getSplitNumber= (value)=>{
    if (value){
      const num = value.toString().indexOf('.')=== -1 ? value.toString().length: value.toString().indexOf('.')
      const size = Math.pow(10,num-1)
      const number = (parseInt(value / size) + 1) * size
      if (value===0){
        return 3
      }
      // let sum = Number(value) + Number(value) *0.4
      return number

    }
  }

  console.log('props',props)
  const config = {
    data: props.data,
    height:400,
    xField: 'time',
    yField: ['value'],
    seriesField:'type',
    padding: [32, 20, 10, 30],
    yAxis: {
      // value: {
      //   min: 0,
      //   max: getSplitNumber(props.data.columnMax)
      // },
      // count: {
      //   min: 0,
      //   max: getSplitNumber(props.data.lineMax)
      // }
    },
    animation: false,
  }

  return (
    <div style={{width: '100%', height: '500px', boxSizing: 'border-box', padding: '16px'}}>
      <p>{props?.type===1?'实收金额':props?.type===2?'销售数量':props?.type===3?'客单数量':''}</p>
      <Line {...config} />
    </div>
  )
}

export default connect(({user}: ConnectState) => ({
  currentUser: user.currentUser
}))(carTrafficChart);
