import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import QboAuthorizeComponent from "../../components/qbo-authorize/qbo-authorize.component";
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
import { selectBodyshop } from "../../redux/user/user.selectors";

const mapStateToProps = createStructuredSelector({
  bodyshop: selectBodyshop
});

const mapDispatchToProps = (dispatch) => ({
  setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
  setSelectedHeader: (key) => dispatch(setSelectedHeader(key))
});

export function AccountingReceivablesContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
  const { t } = useTranslation();

  useEffect(() => {
    document.title = t("titles.accounting-qbo");
    setSelectedHeader("qbo");
    setBreadcrumbs([
      {
        link: "/manage/accounting/qbo",
        label: t("titles.bc.accounting-qbo")
      }
    ]);
  }, [t, setBreadcrumbs, setSelectedHeader]);

  return (
    <div>
      <QboAuthorizeComponent />
    </div>
  );
}

export default connect(mapStateToProps, mapDispatchToProps)(AccountingReceivablesContainer);
