import { Card } from "antd";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import FeatureWrapper from "../../components/feature-wrapper/feature-wrapper.component";
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
import UpsellComponent, { upsellEnum } from "../../components/upsell/upsell.component";
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
import InstanceRenderManager from "../../utils/instanceRenderMgr";
import ProductionBoardComponent from "./production-board.component";

const mapStateToProps = createStructuredSelector({});

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

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

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

  return (
    <FeatureWrapper
      featureName="visualboard"
      noauth={
        <Card>
          <UpsellComponent upsell={upsellEnum().visualboard.general} />
        </Card>
      }
    >
      <RbacWrapper action="production:board">
        <ProductionBoardComponent />
      </RbacWrapper>
    </FeatureWrapper>
  );
}

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