import { Card, Statistic } from "antd";
import moment from "moment";
import React from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
  bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
  //setUserLanguage: language => dispatch(setUserLanguage(language))
});

export function ScoreboardDayStats({ bodyshop, date, entries }) {
  const { dailyPaintTarget, dailyBodyTarget } = bodyshop.scoreboard_target;

  //let totalHrs = 0;
  const paintHrs = entries.reduce((acc, value) => {
    // totalHrs = +value.painthrs;
    return acc + value.painthrs;
  }, 0);

  const bodyHrs = entries.reduce((acc, value) => {
    //totalHrs = +value.bodyhrs;
    return acc + value.bodyhrs;
  }, 0);

  return (
    <Card
      title={moment(date).format("D - ddd")}
      className="ant-card-grid-hoverable"
      style={{ height: "100%" }}
    >
      <Statistic
        valueStyle={{ color: dailyBodyTarget > bodyHrs ? "red" : "green" }}
        label="B"
        value={bodyHrs.toFixed(1)}
      />
      <Statistic
        valueStyle={{ color: dailyPaintTarget > paintHrs ? "red" : "green" }}
        label="P"
        value={paintHrs.toFixed(1)}
      />
    </Card>
  );
}
export default connect(mapStateToProps, mapDispatchToProps)(ScoreboardDayStats);
