import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import TasksPageComponent from "./tasks.page.component";

import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
import InstanceRenderManager from "../../utils/instanceRenderMgr.js";
import TaskPageTypes from "./taskPageTypes.jsx";

const mapStateToProps = createStructuredSelector({});

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

export function MyTasksPageContainer({ setBreadcrumbs, setSelectedHeader }) {
  const { t } = useTranslation();
  useEffect(() => {
    document.title = t("titles.my_tasks", {
      app: InstanceRenderManager({
        imex: "$t(titles.imexonline)",
        rome: "$t(titles.romeonline)"
      })
    });
    setSelectedHeader("my_tasks");
    setBreadcrumbs([
      {
        link: "/manage/tasks/mytasks",
        label: t("titles.bc.my_tasks")
      }
    ]);
  }, [t, setBreadcrumbs, setSelectedHeader]);

  return <TasksPageComponent type={TaskPageTypes.MY_TASKS} />;
}

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