import { Button } from "antd";
import axios from "axios";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import {
  selectBodyshop,
  selectCurrentUser,
} from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
  currentUser: selectCurrentUser,
  bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
  //setUserLanguage: language => dispatch(setUserLanguage(language))
});
export default connect(mapStateToProps, mapDispatchToProps)(DmsCdkMakesRefetch);

export function DmsCdkMakesRefetch({ currentUser, bodyshop, form, socket }) {
  const [loading, setLoading] = useState(false);
  const { t } = useTranslation();

  if (!currentUser.email.includes("@imex.")) return null;

  const handleRefetch = async () => {
    setLoading(true);
    await axios.post("/cdk/getvehicles", {
      cdk_dealerid: bodyshop.cdk_dealerid,
      bodyshopid: bodyshop.id,
    });

    setLoading(false);
  };
  return (
    <Button loading={loading} onClick={handleRefetch}>
      {t("jobs.actions.dms.refetchmakesmodels")}
    </Button>
  );
}
