import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
import ProductionListComponent from "./production-list.component";
import InstanceRenderManager from "../../utils/instanceRenderMgr";

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

export function ProductionListContainer({
  setBreadcrumbs,

  setSelectedHeader
}) {
  const { t } = useTranslation();

  useEffect(() => {
    document.title = t("titles.productionlist", {
      app: InstanceRenderManager({
        imex: "$t(titles.imexonline)",
        rome: "$t(titles.romeonline)"
      })
    });
    setSelectedHeader("productionlist");
    setBreadcrumbs([{ link: "/manage/production/list", label: t("titles.bc.productionlist") }]);
  }, [t, setBreadcrumbs, setSelectedHeader]);

  return (
    <RbacWrapper action="production:list">
      <ProductionListComponent />
    </RbacWrapper>
  );
}

export default connect(null, mapDispatchToProps)(ProductionListContainer);
