import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import JobDetailCards from "../../components/job-detail-cards/job-detail-cards.component";
import JobsList from "../../components/jobs-list/jobs-list.component";
import { setBreadcrumbs } from "../../redux/application/application.actions";
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";

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

export function JobsPage({ setBreadcrumbs }) {
  const { t } = useTranslation();

  useEffect(() => {
    document.title = t("titles.jobs");
    setBreadcrumbs([
      { link: "/manage/jobs", label: t("titles.bc.jobs-active") },
    ]);
  }, [t, setBreadcrumbs]);

  return (
    <RbacWrapper action="jobs:list-active">
      <div className="jobs-list-container">
        <JobsList />
        <JobDetailCards />
      </div>
    </RbacWrapper>
  );
}

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