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

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

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

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

  return (
    <RbacWrapper action="jobs:partsqueue">
      <PartsQueueList />
      <PartsQueueDetailCard />
    </RbacWrapper>
  );
}

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