import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import DashboardGridComponent from "../../components/dashboard-grid/dashboard-grid.component";
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
import FeatureWrapper 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.dashboard", {
      app: InstanceRenderManager({
        imex: "$t(titles.imexonline)",
        rome: "$t(titles.romeonline)"
      })
    });
    setSelectedHeader("dashboard");
    setBreadcrumbs([
      {
        link: "/manage/accounting/exportlogs",
        label: t("titles.bc.dashboard")
      }
    ]);
  }, [setBreadcrumbs, t, setSelectedHeader]);

  return (
    <FeatureWrapper
      featureName="dashboard"
      noauth={
        <Card>
          <UpsellComponent upsell={upsellEnum().dashboard.general} />
        </Card>
      }
    >
      <RbacWrapper action="shop:dashboard">
        <DashboardGridComponent />
      </RbacWrapper>
    </FeatureWrapper>
  );
}

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