import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
import {
  setBreadcrumbs,
  setSelectedHeader,
} from "../../redux/application/application.actions";
import { selectBodyshop } from "../../redux/user/user.selectors";
import ProductionBoardComponent from "./production-board.component";
import FeatureWrapper from "../../components/feature-wrapper/feature-wrapper.component";

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

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

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

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

  return (
    <FeatureWrapper featureName="production-board">
      <RbacWrapper action="production:board">
        <ProductionBoardComponent />
      </RbacWrapper>
    </FeatureWrapper>
  );
}
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(ProductionBoardContainer);
