import { useEffect } from "react";
import OwnersPageComponent from "./owners.page.component";
import { useTranslation } from "react-i18next";
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
import { connect } from "react-redux";
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
import InstanceRenderManager from "../../utils/instanceRenderMgr";

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

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

  return (
    <RbacWrapper action="owners:list">
      <OwnersPageComponent />
    </RbacWrapper>
  );
}

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