import { Button, Popconfirm } from "antd";
import { useTranslation } from "react-i18next";

import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";

const mapStateToProps = createStructuredSelector({
  bodyshop: selectBodyshop
});
const mapDispatchToProps = () => ({});
export default connect(mapStateToProps, mapDispatchToProps)(JobsDetailRatesProfileOVerride);

export function JobsDetailRatesProfileOVerride({ bodyshop, form }) {
  const { t } = useTranslation();
  return (
    <Popconfirm
      onConfirm={() => {
        form.setFieldsValue({
          cieca_pft: {
            ...bodyshop.md_responsibility_centers.taxes.tax_ty1,
            ...bodyshop.md_responsibility_centers.taxes.tax_ty2,
            ...bodyshop.md_responsibility_centers.taxes.tax_ty3,
            ...bodyshop.md_responsibility_centers.taxes.tax_ty4,
            ...bodyshop.md_responsibility_centers.taxes.tax_ty5
          },
          materials: bodyshop.md_responsibility_centers.cieca_pfm,
          cieca_pfl: bodyshop.md_responsibility_centers.cieca_pfl,
          parts_tax_rates: bodyshop.md_responsibility_centers.parts_tax_rates
        });
      }}
      title={t("jobs.actions.taxprofileoverride_confirm")}
    >
      <Button type="link">{t("jobs.actions.taxprofileoverride")}</Button>
    </Popconfirm>
  );
}
