import TaskListContainer from "../../components/task-list/task-list.container.jsx";
import { QUERY_ALL_TASKS_PAGINATED, QUERY_MY_TASKS_PAGINATED } from "../../graphql/tasks.queries.js";
import taskPageTypes from "./taskPageTypes.jsx";
import { createStructuredSelector } from "reselect";
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors.js";
import { connect } from "react-redux";

const mapStateToProps = createStructuredSelector({
  currentUser: selectCurrentUser,
  bodyshop: selectBodyshop
});
const mapDispatchToProps = () => ({});

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

export function TasksPageComponent({ bodyshop, currentUser, type }) {
  switch (type) {
    case taskPageTypes.MY_TASKS:
      return (
        <TaskListContainer
          onlyMine={true}
          relationshipId={bodyshop?.employees?.find((e) => e.user_email === currentUser.email)?.id}
          relationshipType={"assigned_to"}
          query={{ QUERY_MY_TASKS_PAGINATED }}
          titleTranslation={"tasks.titles.my_tasks"}
          disableJobRefetch={true}
        />
      );
    case taskPageTypes.ALL_TASKS:
      return (
        <TaskListContainer
          query={{ QUERY_ALL_TASKS_PAGINATED }}
          titleTranslation={"tasks.titles.all_tasks"}
          disableJobRefetch={true}
        />
      );
    default:
      return <></>;
  }
}
