import React, { 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 PartsQueuePage from "./parts-queue.page.component";

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");
    setSelectedHeader("parts-queue");
    setBreadcrumbs([
      { link: "/manage/partsqueue", label: t("titles.bc.parts-queue") },
    ]);
  }, [setBreadcrumbs, t, setSelectedHeader]);

  return (
    <RbacWrapper action="jobs:partsqueue">
      <PartsQueuePage />
    </RbacWrapper>
  );
}
export default connect(null, mapDispatchToProps)(PartsQueuePageContainer);
