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 ExportLogsPage from "./export-logs.page.component";
import FeatureWrapperComponent from "../../components/feature-wrapper/feature-wrapper.component";
import InstanceRenderManager from "../../utils/instanceRenderMgr";
import { Card } from "antd";
import UpsellComponent, { upsellEnum } from "../../components/upsell/upsell.component";

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

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

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

  return (
    <FeatureWrapperComponent
      featureName="export"
      noauth={
        <Card>
          <UpsellComponent upsell={upsellEnum().accounting.receivables} />
        </Card>
      }
    >
      <RbacWrapper action="accounting:exportlogs">
        <ExportLogsPage />
      </RbacWrapper>
    </FeatureWrapperComponent>
  );
}

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